Bug 1224994 part.10 Rename TSFTextStore::mSelection to TSFTextStore::mSelectionForTSF for making its meaning clearer r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 01 Jul 2016 14:01:26 +0900
changeset 383449 7e0b6fa324c4ecab47b519c876c367ff8c8d291a
parent 383448 d7165d02aec02b36192c1a9b00a3b8e7121034f9
child 383450 2f4ebb795bd6088b7cedb3c2535760fc4383054e
push id22031
push usermasayuki@d-toybox.com
push dateMon, 04 Jul 2016 06:55:01 +0000
reviewersm_kato
bugs1224994
milestone50.0a1
Bug 1224994 part.10 Rename TSFTextStore::mSelection to TSFTextStore::mSelectionForTSF for making its meaning clearer r?m_kato MozReview-Commit-ID: K9tVAw9aCaN
widget/windows/TSFTextStore.cpp
widget/windows/TSFTextStore.h
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -1179,17 +1179,17 @@ bool TSFTextStore::sHackQueryInsertForMS
 #define TEXTSTORE_DEFAULT_VIEW (1)
 
 TSFTextStore::TSFTextStore()
   : mEditCookie(0)
   , mSinkMask(0)
   , mLock(0)
   , mLockQueued(0)
   , mHandlingKeyMessage(0)
-  , mContentForTSF(mComposition, mSelection)
+  , mContentForTSF(mComposition, mSelectionForTSF)
   , mRequestedAttrValues(false)
   , mIsRecordingActionsWithoutLock(false)
   , mHasReturnedNoLayoutError(false)
   , mWaitingQueryLayout(false)
   , mPendingDestroy(false)
   , mDeferClearingContentForTSF(false)
   , mNativeCaretIsCreated(false)
   , mDeferNotifyingTSF(false)
@@ -1489,17 +1489,17 @@ TSFTextStore::RequestLock(DWORD dwLockFl
 
   if (!mSink) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
       ("TSF: 0x%p   TSFTextStore::RequestLock() FAILED due to "
        "any sink not stored", this));
     return E_FAIL;
   }
   if (mDestroyed &&
-      (!mContentForTSF.IsInitialized() || mSelection.IsDirty())) {
+      (!mContentForTSF.IsInitialized() || mSelectionForTSF.IsDirty())) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
       ("TSF: 0x%p   TSFTextStore::RequestLock() FAILED due to "
        "being destroyed and no information of the contents", this));
     return E_FAIL;
   }
   if (!phrSession) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
       ("TSF: 0x%p   TSFTextStore::RequestLock() FAILED due to "
@@ -2094,43 +2094,45 @@ TSFTextStore::GetCurrentText(nsAString& 
 
   aTextContent = queryText.mReply.mString;
   return true;
 }
 
 TSFTextStore::Selection&
 TSFTextStore::CurrentSelection()
 {
-  if (mSelection.IsDirty()) {
+  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();
     }
 
     WidgetQueryContentEvent querySelection(true, eQuerySelectedText, mWidget);
     mWidget->InitEvent(querySelection);
     DispatchEvent(querySelection);
-    NS_ENSURE_TRUE(querySelection.mSucceeded, mSelection);
-
-    mSelection.SetSelection(querySelection.mReply.mOffset,
-                            querySelection.mReply.mString.Length(),
-                            querySelection.mReply.mReversed,
-                            querySelection.GetWritingMode());
+    if (NS_WARN_IF(!querySelection.mSucceeded)) {
+      return mSelectionForTSF;
+    }
+
+    mSelectionForTSF.SetSelection(querySelection.mReply.mOffset,
+                                  querySelection.mReply.mString.Length(),
+                                  querySelection.mReply.mReversed,
+                                  querySelection.GetWritingMode());
   }
 
   MOZ_LOG(sTextStoreLog, LogLevel::Debug,
          ("TSF: 0x%p   TSFTextStore::CurrentSelection(): "
           "acpStart=%d, acpEnd=%d (length=%d), reverted=%s",
-          this, mSelection.StartOffset(), mSelection.EndOffset(),
-          mSelection.Length(),
-          GetBoolName(mSelection.IsReversed())));
-
-  return mSelection;
+          this, mSelectionForTSF.StartOffset(), mSelectionForTSF.EndOffset(),
+          mSelectionForTSF.Length(),
+          GetBoolName(mSelectionForTSF.IsReversed())));
+
+  return mSelectionForTSF;
 }
 
 static HRESULT
 GetRangeExtent(ITfRange* aRange, LONG* aStart, LONG* aLength)
 {
   RefPtr<ITfRangeACP> rangeACP;
   aRange->QueryInterface(IID_ITfRangeACP, getter_AddRefs(rangeACP));
   NS_ENSURE_TRUE(rangeACP, E_FAIL);
@@ -2750,17 +2752,17 @@ TSFTextStore::SetSelectionInternal(const
   CompleteLastActionIfStillIncomplete();
   PendingAction* action = mPendingActions.AppendElement();
   action->mType = PendingAction::SET_SELECTION;
   action->mSelectionStart = selectionInContent.acpStart;
   action->mSelectionLength =
     selectionInContent.acpEnd - selectionInContent.acpStart;
   action->mSelectionReversed = (selectionInContent.style.ase == TS_AE_START);
 
-  // Use TSF specified selection for updating mSelection.
+  // Use TSF specified selection for updating mSelectionForTSF.
   currentSel.SetSelection(*pSelection);
 
   return S_OK;
 }
 
 STDMETHODIMP
 TSFTextStore::SetSelection(ULONG ulCount,
                            const TS_SELECTION_ACP* pSelection)
@@ -4118,22 +4120,22 @@ TSFTextStore::RecordCompositionStartActi
       mPendingActions[mPendingActions.Length() - 2];
     contentForTSF.RestoreCommittedComposition(
       aComposition, pendingCompositionStart, pendingCompositionEnd);
     mPendingActions.RemoveElementAt(mPendingActions.Length() - 1);
     MOZ_LOG(sTextStoreLog, LogLevel::Info,
            ("TSF: 0x%p   TSFTextStore::RecordCompositionStartAction() "
             "succeeded: restoring the committed string as composing string, "
             "mComposition={ mStart=%ld, mString.Length()=%ld, "
-            "mSelection={ acpStart=%ld, acpEnd=%ld, style.ase=%s, "
+            "mSelectionForTSF={ acpStart=%ld, acpEnd=%ld, style.ase=%s, "
             "style.fInterimChar=%s } }",
             this, mComposition.mStart, mComposition.mString.Length(),
-            mSelection.StartOffset(), mSelection.EndOffset(),
-            GetActiveSelEndName(mSelection.ActiveSelEnd()),
-            GetBoolName(mSelection.IsInterimChar())));
+            mSelectionForTSF.StartOffset(), mSelectionForTSF.EndOffset(),
+            GetActiveSelEndName(mSelectionForTSF.ActiveSelEnd()),
+            GetBoolName(mSelectionForTSF.IsInterimChar())));
     return S_OK;
   }
 
   PendingAction* action = mPendingActions.AppendElement();
   action->mType = PendingAction::COMPOSITION_START;
   action->mSelectionStart = aStart;
   action->mSelectionLength = aLength;
 
@@ -4157,22 +4159,22 @@ TSFTextStore::RecordCompositionStartActi
   }
 
   contentForTSF.StartComposition(aComposition, *action, aPreserveSelection);
   action->mData = mComposition.mString;
 
   MOZ_LOG(sTextStoreLog, LogLevel::Info,
          ("TSF: 0x%p   TSFTextStore::RecordCompositionStartAction() succeeded: "
           "mComposition={ mStart=%ld, mString.Length()=%ld, "
-          "mSelection={ acpStart=%ld, acpEnd=%ld, style.ase=%s, "
+          "mSelectionForTSF={ acpStart=%ld, acpEnd=%ld, style.ase=%s, "
           "style.fInterimChar=%s } }",
           this, mComposition.mStart, mComposition.mString.Length(),
-          mSelection.StartOffset(), mSelection.EndOffset(),
-          GetActiveSelEndName(mSelection.ActiveSelEnd()),
-          GetBoolName(mSelection.IsInterimChar())));
+          mSelectionForTSF.StartOffset(), mSelectionForTSF.EndOffset(),
+          GetActiveSelEndName(mSelectionForTSF.ActiveSelEnd()),
+          GetBoolName(mSelectionForTSF.IsInterimChar())));
   return S_OK;
 }
 
 HRESULT
 TSFTextStore::RecordCompositionEndAction()
 {
   MOZ_LOG(sTextStoreLog, LogLevel::Debug,
          ("TSF: 0x%p   TSFTextStore::RecordCompositionEndAction(), "
@@ -4693,17 +4695,17 @@ TSFTextStore::NotifyTSFOfTextChange()
   // If the text changes are caused only by composition, we don't need to
   // notify TSF of the text changes.
   if (mPendingTextChangeData.mCausedOnlyByComposition) {
     mPendingTextChangeData.Clear();
     return;
   }
 
   // First, forget cached selection.
-  mSelection.MarkDirty();
+  mSelectionForTSF.MarkDirty();
 
   // For making it safer, we should check if there is a valid sink to receive
   // text change notification.
   if (NS_WARN_IF(!mSink) || NS_WARN_IF(!(mSinkMask & TS_AS_TEXT_CHANGE))) {
     MOZ_LOG(sTextStoreLog, LogLevel::Error,
            ("TSF: 0x%p   TSFTextStore::NotifyTSFOfTextChange() FAILED due to "
             "mSink is not ready to call ITextStoreACPSink::OnTextChange()...",
             this));
@@ -4767,17 +4769,17 @@ TSFTextStore::OnSelectionChangeInternal(
     // changes.
     return NS_OK;
   }
 
   mDeferNotifyingTSF = false;
 
   // Assign the new selection change data to the pending selection change data
   // because only the latest selection data is necessary.
-  // Note that this is necessary to update mSelection.  Therefore, even if
+  // Note that this is necessary to update mSelectionForTSF.  Therefore, even if
   // neither TSF nor TIP wants selection change notifications, we need to
   // store the selection information.
   mPendingSelectionChangeData.Assign(selectionChangeData);
 
   // Flush remaining pending notifications here if it's possible.
   MaybeFlushPendingNotifications();
 
   return NS_OK;
@@ -4788,20 +4790,21 @@ TSFTextStore::NotifyTSFOfSelectionChange
 {
   MOZ_ASSERT(!mDestroyed);
   MOZ_ASSERT(!IsReadLocked());
   MOZ_ASSERT(!mComposition.IsComposing());
   MOZ_ASSERT(mPendingSelectionChangeData.IsValid());
 
   // If selection range isn't actually changed, we don't need to notify TSF
   // of this selection change.
-  if (!mSelection.SetSelection(mPendingSelectionChangeData.mOffset,
-                               mPendingSelectionChangeData.Length(),
-                               mPendingSelectionChangeData.mReversed,
-                               mPendingSelectionChangeData.GetWritingMode())) {
+  if (!mSelectionForTSF.SetSelection(
+                          mPendingSelectionChangeData.mOffset,
+                          mPendingSelectionChangeData.Length(),
+                          mPendingSelectionChangeData.mReversed,
+                          mPendingSelectionChangeData.GetWritingMode())) {
     mPendingSelectionChangeData.Clear();
     MOZ_LOG(sTextStoreLog, LogLevel::Debug,
            ("TSF: 0x%p   TSFTextStore::NotifyTSFOfSelectionChange(), "
             "selection isn't actually changed.", this));
     return;
   }
 
   mPendingSelectionChangeData.Clear();
--- a/widget/windows/TSFTextStore.h
+++ b/widget/windows/TSFTextStore.h
@@ -565,19 +565,20 @@ protected:
     }
 
   private:
     TS_SELECTION_ACP mACP;
     WritingMode mWritingMode;
     bool mDirty;
   };
   // Don't access mSelection directly except at calling MarkDirty().
-  // Use CurrentSelection() instead.  This is marked as dirty when the
-  // selection or content is changed without document lock.
-  Selection mSelection;
+  // Use CurrentSelection() 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();