Bug 1224994 part.11 Rename TSFTextStore::CurrentSelection() to TSFTextStore::SelectionForTSF() r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 01 Jul 2016 14:09:52 +0900
changeset 303681 d7eefd29bfef62c47e5499aaac6f136ee8a05e73
parent 303680 fadd96dff61f493f8a2ab113b25d9103175168f0
child 303682 99a286cee6950fd9b11ddd0daa60ce2db41f6ae5
push id79141
push usercbook@mozilla.com
push dateTue, 05 Jul 2016 14:07:42 +0000
treeherdermozilla-inbound@f08c54971dd1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1224994
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1224994 part.11 Rename TSFTextStore::CurrentSelection() to TSFTextStore::SelectionForTSF() r=m_kato MozReview-Commit-ID: 9KVLN63NL9Z
widget/windows/TSFTextStore.cpp
widget/windows/TSFTextStore.h
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -1975,21 +1975,21 @@ TSFTextStore::GetSelection(ULONG ulIndex
   if (ulIndex != static_cast<ULONG>(TS_DEFAULT_SELECTION) &&
       ulIndex != 0) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::GetSelection() FAILED due to "
             "unsupported selection", this));
     return TS_E_NOSELECTION;
   }
 
-  Selection& currentSel = CurrentSelection();
+  Selection& currentSel = SelectionForTSFRef();
   if (currentSel.IsDirty()) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::GetSelection() FAILED due to "
-            "CurrentSelection() failure", this));
+            "SelectionForTSFRef() failure", this));
     return E_FAIL;
   }
   *pSelection = currentSel.ACP();
   *pcFetched = 1;
   MOZ_LOG(sTextStoreLog, LogLevel::Info,
          ("TSF: 0x%p   TSFTextStore::GetSelection() succeeded", this));
   return S_OK;
 }
@@ -2017,21 +2017,21 @@ TSFTextStore::ContentForTSFRef()
             "called wrong timing, IsReadLocked()=%s, "
             "mContentForTSF.IsInitialized()=%s",
             this, GetBoolName(IsReadLocked()),
             GetBoolName(mContentForTSF.IsInitialized())));
     mContentForTSF.Clear();
     return mContentForTSF;
   }
 
-  Selection& currentSel = CurrentSelection();
+  Selection& currentSel = SelectionForTSFRef();
   if (currentSel.IsDirty()) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::ContentForTSFRef(), FAILED, due to "
-            "CurrentSelection() failure", this));
+            "SelectionForTSFRef() failure", this));
     mContentForTSF.Clear();
     return mContentForTSF;
   }
 
   if (!mContentForTSF.IsInitialized()) {
     nsAutoString text;
     if (NS_WARN_IF(!GetCurrentText(text))) {
       MOZ_LOG(sTextStoreLog, LogLevel::Error,
@@ -2092,17 +2092,17 @@ TSFTextStore::GetCurrentText(nsAString& 
     return false;
   }
 
   aTextContent = queryText.mReply.mString;
   return true;
 }
 
 TSFTextStore::Selection&
-TSFTextStore::CurrentSelection()
+TSFTextStore::SelectionForTSFRef()
 {
   if (mSelectionForTSF.IsDirty()) {
     MOZ_ASSERT(!mDestroyed);
     // If the window has never been available, we should crash since working
     // with broken values may make TIP confused.
     if (!mWidget || mWidget->Destroyed()) {
       MOZ_CRASH();
     }
@@ -2116,17 +2116,17 @@ TSFTextStore::CurrentSelection()
 
     mSelectionForTSF.SetSelection(querySelection.mReply.mOffset,
                                   querySelection.mReply.mString.Length(),
                                   querySelection.mReply.mReversed,
                                   querySelection.GetWritingMode());
   }
 
   MOZ_LOG(sTextStoreLog, LogLevel::Debug,
-         ("TSF: 0x%p   TSFTextStore::CurrentSelection(): "
+         ("TSF: 0x%p   TSFTextStore::SelectionForTSFRef(): "
           "acpStart=%d, acpEnd=%d (length=%d), reverted=%s",
           this, mSelectionForTSF.StartOffset(), mSelectionForTSF.EndOffset(),
           mSelectionForTSF.Length(),
           GetBoolName(mSelectionForTSF.IsReversed())));
 
   return mSelectionForTSF;
 }
 
@@ -2292,17 +2292,17 @@ TSFTextStore::RestartCompositionIfNecess
           this));
   return S_OK;
 }
 
 HRESULT
 TSFTextStore::RestartComposition(ITfCompositionView* aCompositionView,
                                  ITfRange* aNewRange)
 {
-  Selection& currentSelection = CurrentSelection();
+  Selection& currentSelection = SelectionForTSFRef();
 
   LONG newStart, newLength;
   HRESULT hr = GetRangeExtent(aNewRange, &newStart, &newLength);
   LONG newEnd = newStart + newLength;
 
   MOZ_LOG(sTextStoreLog, LogLevel::Debug,
          ("TSF: 0x%p   TSFTextStore::RestartComposition(aCompositionView=0x%p, "
           "aNewRange=0x%p { newStart=%d, newLength=%d }), "
@@ -2311,17 +2311,17 @@ TSFTextStore::RestartComposition(ITfComp
           this, aCompositionView, aNewRange, newStart, newLength,
           mComposition.mStart, mComposition.mString.Length(),
           GetBoolName(currentSelection.IsDirty()),
           currentSelection.StartOffset(), currentSelection.Length()));
 
   if (currentSelection.IsDirty()) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::RestartComposition() FAILED "
-            "due to CurrentSelection() failure", this));
+            "due to SelectionForTSFRef() failure", this));
     return E_FAIL;
   }
 
   if (FAILED(hr)) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::RestartComposition() FAILED "
             "due to GetRangeExtent() failure", this));
     return hr;
@@ -2497,21 +2497,21 @@ TSFTextStore::RecordCompositionUpdateAct
   if (FAILED(hr) || !enumRanges) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::RecordCompositionUpdateAction() FAILED "
             "due to attrPropetry->EnumRanges() failure", this));
     return FAILED(hr) ? hr : E_FAIL;
   }
 
   // First, put the log of content and selection here.
-  Selection& currentSel = CurrentSelection();
+  Selection& currentSel = SelectionForTSFRef();
   if (currentSel.IsDirty()) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::RecordCompositionUpdateAction() FAILED "
-            "due to CurrentSelection() failure", this));
+            "due to SelectionForTSFRef() failure", this));
     return E_FAIL;
   }
 
   PendingAction* action = LastOrNewPendingCompositionUpdate();
   action->mData = mComposition.mString;
   // The ranges might already have been initialized, however, if this is
   // called again, that means we need to overwrite the ranges with current
   // information.
@@ -2659,21 +2659,21 @@ TSFTextStore::SetSelectionInternal(const
           this, pSelection->acpStart, pSelection->acpEnd,
           GetActiveSelEndName(pSelection->style.ase),
           GetBoolName(pSelection->style.fInterimChar),
           GetBoolName(aDispatchCompositionChangeEvent),
           GetBoolName(mComposition.IsComposing())));
 
   MOZ_ASSERT(IsReadWriteLocked());
 
-  Selection& currentSel = CurrentSelection();
+  Selection& currentSel = SelectionForTSFRef();
   if (currentSel.IsDirty()) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
        ("TSF: 0x%p   TSFTextStore::SetSelectionInternal() FAILED due to "
-        "CurrentSelection() failure", this));
+        "SelectionForTSFRef() failure", this));
     return E_FAIL;
   }
 
   // If actually the range is not changing, we should do nothing.
   // Perhaps, we can ignore the difference change because it must not be
   // important for following edit.
   if (currentSel.EqualsExceptDirection(*pSelection)) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
@@ -3264,25 +3264,25 @@ TSFTextStore::RetrieveRequestedAttrs(ULO
       switch (i) {
         case eInputScope: {
           paAttrVals[count].varValue.vt = VT_UNKNOWN;
           RefPtr<IUnknown> inputScope = new InputScopeImpl(mInputScopes);
           paAttrVals[count].varValue.punkVal = inputScope.forget().take();
           break;
         }
         case eTextVerticalWriting: {
-          Selection& currentSelection = CurrentSelection();
+          Selection& currentSelection = SelectionForTSFRef();
           paAttrVals[count].varValue.vt = VT_BOOL;
           paAttrVals[count].varValue.boolVal =
             currentSelection.GetWritingMode().IsVertical()
             ? VARIANT_TRUE : VARIANT_FALSE;
           break;
         }
         case eTextOrientation: {
-          Selection& currentSelection = CurrentSelection();
+          Selection& currentSelection = SelectionForTSFRef();
           paAttrVals[count].varValue.vt = VT_I4;
           paAttrVals[count].varValue.lVal =
             currentSelection.GetWritingMode().IsVertical() ? 2700 : 0;
           break;
         }
         default:
           MOZ_CRASH("Invalid index? Or not implemented yet?");
           break;
@@ -3561,17 +3561,17 @@ TSFTextStore::GetTextExt(TsViewCookie vc
 
   // NOTE: TSF (at least on Win 8.1) doesn't return TS_E_NOLAYOUT to the
   // caller even if we return it.  It's converted to just E_FAIL.
   // However, this is fixed on Win 10.
 
   const TSFStaticSink* kSink = TSFStaticSink::GetInstance();
   if (mComposition.IsComposing() && mComposition.mStart < acpEnd &&
       mContentForTSF.IsLayoutChangedAfter(acpEnd)) {
-    const Selection& currentSel = CurrentSelection();
+    const Selection& currentSel = SelectionForTSFRef();
     // The bug of Microsoft Office IME 2010 for Japanese is similar to
     // MS-IME for Win 8.1 and Win 10.  Newer version of MS Office IME is not
     // released yet.  So, we can hack it without prefs  because there must be
     // no developers who want to disable this hack for tests.
     const bool kIsMSOfficeJapaneseIME2010 =
       kSink->IsMSOfficeJapaneseIME2010Active();
     // MS IME for Japanese doesn't support asynchronous handling at deciding
     // its suggest list window position.  The feature was implemented
@@ -3914,21 +3914,21 @@ TSFTextStore::InsertTextAtSelection(DWOR
     if (!pacpStart || !pacpEnd) {
       MOZ_LOG(sTextStoreLog, LogLevel::Error,
              ("TSF: 0x%p   TSFTextStore::InsertTextAtSelection() FAILED due to "
               "null argument", this));
       return E_INVALIDARG;
     }
 
     // Get selection first
-    Selection& currentSel = CurrentSelection();
+    Selection& currentSel = SelectionForTSFRef();
     if (currentSel.IsDirty()) {
       MOZ_LOG(sTextStoreLog, LogLevel::Error,
              ("TSF: 0x%p   TSFTextStore::InsertTextAtSelection() FAILED due to "
-              "CurrentSelection() failure", this));
+              "SelectionForTSFRef() failure", this));
       return E_FAIL;
     }
 
     // Simulate text insertion
     *pacpStart = currentSel.StartOffset();
     *pacpEnd = currentSel.EndOffset();
     if (pChange) {
       pChange->acpStart = currentSel.StartOffset();
@@ -4134,21 +4134,21 @@ TSFTextStore::RecordCompositionStartActi
     return S_OK;
   }
 
   PendingAction* action = mPendingActions.AppendElement();
   action->mType = PendingAction::COMPOSITION_START;
   action->mSelectionStart = aStart;
   action->mSelectionLength = aLength;
 
-  Selection& currentSel = CurrentSelection();
+  Selection& currentSel = SelectionForTSFRef();
   if (currentSel.IsDirty()) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::RecordCompositionStartAction() FAILED "
-            "due to CurrentSelection() failure", this));
+            "due to SelectionForTSFRef() failure", this));
     action->mAdjustSelection = true;
   } else if (currentSel.MinOffset() != aStart ||
              currentSel.MaxOffset() != aStart + aLength) {
     // If new composition range is different from current selection range,
     // we need to set selection before dispatching compositionstart event.
     action->mAdjustSelection = true;
   } else {
     // We shouldn't dispatch selection set event before dispatching
@@ -4326,27 +4326,27 @@ TSFTextStore::OnUpdateComposition(ITfCom
   if (FAILED(hr)) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::OnUpdateComposition() FAILED due to "
             "RecordCompositionUpdateAction() failure", this));
     return hr;
   }
 
   if (MOZ_LOG_TEST(sTextStoreLog, LogLevel::Info)) {
-    Selection& currentSel = CurrentSelection();
+    Selection& currentSel = SelectionForTSFRef();
     if (currentSel.IsDirty()) {
       MOZ_LOG(sTextStoreLog, LogLevel::Error,
              ("TSF: 0x%p   TSFTextStore::OnUpdateComposition() FAILED due to "
-              "CurrentSelection() failure", this));
+              "SelectionForTSFRef() failure", this));
       return E_FAIL;
     }
     MOZ_LOG(sTextStoreLog, LogLevel::Info,
            ("TSF: 0x%p   TSFTextStore::OnUpdateComposition() succeeded: "
             "mComposition={ mStart=%ld, mString=\"%s\" }, "
-            "CurrentSelection()={ acpStart=%ld, acpEnd=%ld, style.ase=%s }",
+            "SelectionForTSFRef()={ acpStart=%ld, acpEnd=%ld, style.ase=%s }",
             this, mComposition.mStart,
             NS_ConvertUTF16toUTF8(mComposition.mString).get(),
             currentSel.StartOffset(), currentSel.EndOffset(),
             GetActiveSelEndName(currentSel.ActiveSelEnd())));
   }
   return S_OK;
 }
 
@@ -5112,21 +5112,21 @@ TSFTextStore::CreateNativeCaret()
     return;
   }
 
   MOZ_LOG(sTextStoreLog, LogLevel::Debug,
          ("TSF: 0x%p   TSFTextStore::CreateNativeCaret(), "
           "mComposition.IsComposing()=%s",
           this, GetBoolName(mComposition.IsComposing())));
 
-  Selection& currentSel = CurrentSelection();
+  Selection& currentSel = SelectionForTSFRef();
   if (currentSel.IsDirty()) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::CreateNativeCaret() FAILED due to "
-            "CurrentSelection() failure", this));
+            "SelectionForTSFRef() failure", this));
     return;
   }
 
   WidgetQueryContentEvent queryCaretRect(true, eQueryCaretRect, mWidget);
   mWidget->InitEvent(queryCaretRect);
 
   WidgetQueryContentEvent::Options options;
   // XXX If this is called without composition and the selection isn't
--- a/widget/windows/TSFTextStore.h
+++ b/widget/windows/TSFTextStore.h
@@ -565,27 +565,29 @@ protected:
     }
 
   private:
     TS_SELECTION_ACP mACP;
     WritingMode mWritingMode;
     bool mDirty;
   };
   // Don't access mSelection directly except at calling MarkDirty().
-  // Use CurrentSelection() instead.  This is modified immediately when
+  // Use SelectionForTSFRef() instead.  This is modified immediately when
   // TSF requests to set selection and not updated by selection change in
   // content until mContentForTSF is cleared.
   Selection mSelectionForTSF;
 
-  // Get "current selection".  If the document is locked, this initializes
-  // mSelection with the selection at the first call during a lock and returns
-  // it.  However, mSelection is NOT modified immediately.  When pending
-  // changes are flushed at unlocking the document, cached mSelection is
-  // modified.  Note that this is also called by ContentForTSFRef().
-  Selection& CurrentSelection();
+  /**
+   * Get the selection expected by TSF.  If mSelectionForTSF is already valid,
+   * this just return the reference to it.  Otherwise, this initializes it
+   * with eQuerySelectedText.  Please check if the result is valid before
+   * actually using it.
+   * Note that this is also called by ContentForTSFRef().
+   */
+  Selection& SelectionForTSFRef();
 
   struct PendingAction final
   {
     enum ActionType : uint8_t
     {
       COMPOSITION_START,
       COMPOSITION_UPDATE,
       COMPOSITION_END,