Bug 1267526 part.1 TSFTextStore shouldn't notify TSF of selectin change when the selection isn't actually changed r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 11 May 2016 18:18:51 +0900
changeset 366165 5d3ee4657a96694d0c3675418655a2fc0bf8ae1f
parent 366164 1fb42ec6f691760d3f8b04dbb3f8f64716d9855e
child 520710 e315899bae5765efd44ae87586de7b9362307c37
push id17911
push usermasayuki@d-toybox.com
push dateThu, 12 May 2016 03:12:40 +0000
reviewersm_kato
bugs1267526
milestone49.0a1
Bug 1267526 part.1 TSFTextStore shouldn't notify TSF of selectin change when the selection isn't actually changed r?m_kato MozReview-Commit-ID: 8HLz30lR2TH
widget/windows/TSFTextStore.cpp
widget/windows/TSFTextStore.h
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -4752,21 +4752,28 @@ TSFTextStore::OnSelectionChangeInternal(
       !selectionChangeData.mOccurredDuringComposition) {
     MOZ_LOG(sTextStoreLog, LogLevel::Warning,
            ("TSF: 0x%p   TSFTextStore::OnSelectionChangeInternal(), WARNING, "
             "ignoring selection change notification which occurred before "
             "composition start.", this));
     return NS_OK;
   }
 
-  mSelection.SetSelection(
-    selectionChangeData.mOffset,
-    selectionChangeData.Length(),
-    selectionChangeData.mReversed,
-    selectionChangeData.GetWritingMode());
+  // If selection range isn't actually changed, we don't need to notify TSF
+  // of this selection change.
+  if (!mSelection.SetSelection(
+                    selectionChangeData.mOffset,
+                    selectionChangeData.Length(),
+                    selectionChangeData.mReversed,
+                    selectionChangeData.GetWritingMode())) {
+    MOZ_LOG(sTextStoreLog, LogLevel::Debug,
+           ("TSF: 0x%p   TSFTextStore::OnSelectionChangeInternal(), selection "
+            "isn't actually changed.", this));
+    return NS_OK;
+  }
 
   if (!selectionChangeData.mCausedBySelectionEvent) {
     // Should be notified via MaybeFlushPendingNotifications() for keeping
     // the order of change notifications.
     mPendingOnSelectionChange = true;
     if (mIsRecordingActionsWithoutLock) {
       MOZ_LOG(sTextStoreLog, LogLevel::Info,
              ("TSF: 0x%p   TSFTextStore::OnSelectionChangeInternal(), putting "
--- a/widget/windows/TSFTextStore.h
+++ b/widget/windows/TSFTextStore.h
@@ -413,27 +413,33 @@ protected:
       if (mACP.style.ase != TS_AE_START) {
         mACP.style.ase = TS_AE_END;
       }
       // We're not support interim char selection for now.
       // XXX Probably, this is necessary for supporting South Asian languages.
       mACP.style.fInterimChar = FALSE;
     }
 
-    void SetSelection(uint32_t aStart,
+    bool SetSelection(uint32_t aStart,
                       uint32_t aLength,
                       bool aReversed,
                       WritingMode aWritingMode)
     {
+      bool changed = mDirty ||
+                     mACP.acpStart != static_cast<LONG>(aStart) ||
+                     mACP.acpEnd != static_cast<LONG>(aStart + aLength);
+
       mDirty = false;
       mACP.acpStart = static_cast<LONG>(aStart);
       mACP.acpEnd = static_cast<LONG>(aStart + aLength);
       mACP.style.ase = aReversed ? TS_AE_START : TS_AE_END;
       mACP.style.fInterimChar = FALSE;
       mWritingMode = aWritingMode;
+
+      return changed;
     }
 
     bool IsCollapsed() const
     {
       MOZ_ASSERT(!mDirty);
       return (mACP.acpStart == mACP.acpEnd);
     }