Bug 1051689 Ensure to complete the last pending action r=emk
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 12 Aug 2014 00:17:18 +0900
changeset 198855 873b1855df559f1cdfe6efde34b9e9abe1633387
parent 198854 e13efa1149a1068a2d45c309403f2891c814d447
child 198856 92d8430977c2dcdcebe8481222d2899cd438db2e
push id47511
push usermasayuki@d-toybox.com
push dateMon, 11 Aug 2014 15:23:30 +0000
treeherdermozilla-inbound@92d8430977c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1051689
milestone34.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 1051689 Ensure to complete the last pending action r=emk
widget/windows/nsTextStore.cpp
widget/windows/nsTextStore.h
--- a/widget/windows/nsTextStore.cpp
+++ b/widget/windows/nsTextStore.cpp
@@ -958,24 +958,22 @@ nsTextStore::RequestLock(DWORD dwLockFla
 void
 nsTextStore::DidLockGranted()
 {
   if (mNativeCaretIsCreated) {
     ::DestroyCaret();
     mNativeCaretIsCreated = false;
   }
   if (IsReadWriteLocked()) {
-    if (IsPendingCompositionUpdateIncomplete()) {
-      // FreeCJ (TIP for Traditional Chinese) calls SetSelection() to set caret
-      // to the start of composition string and insert a full width space for
-      // a placeholder with a call of SetText().  After that, it calls
-      // OnUpdateComposition() without new range.  Therefore, let's record the
-      // composition update information here.
-      RecordCompositionUpdateAction();
-    }
+    // FreeCJ (TIP for Traditional Chinese) calls SetSelection() to set caret
+    // to the start of composition string and insert a full width space for
+    // a placeholder with a call of SetText().  After that, it calls
+    // OnUpdateComposition() without new range.  Therefore, let's record the
+    // composition update information here.
+    CompleteLastActionIfStillIncomplete();
 
     FlushPendingActions();
   }
 
   // If the widget has gone, we don't need to notify anything.
   if (!mWidget || mWidget->Destroyed()) {
     mPendingOnSelectionChange = false;
     mPendingOnLayoutChange = false;
@@ -1782,16 +1780,17 @@ nsTextStore::SetSelectionInternal(const 
            ("TSF: 0x%p   nsTextStore::SetSelectionInternal() FAILED due to "
             "RecordCompositionUpdateAction() failure", this));
         return hr;
       }
     }
     return S_OK;
   }
 
+  CompleteLastActionIfStillIncomplete();
   PendingAction* action = mPendingActions.AppendElement();
   action->mType = PendingAction::SELECTION_SET;
   action->mSelectionStart = pSelection->acpStart;
   action->mSelectionLength = pSelection->acpEnd - pSelection->acpStart;
   action->mSelectionReversed = (pSelection->style.ase == TS_AE_START);
 
   currentSel.SetSelection(*pSelection);
 
@@ -2807,16 +2806,17 @@ nsTextStore::RecordCompositionStartActio
   Content& currentContent = CurrentContent();
   if (!currentContent.IsInitialized()) {
     PR_LOG(sTextStoreLog, PR_LOG_ERROR,
            ("TSF: 0x%p   nsTextStore::RecordCompositionStartAction() FAILED "
             "due to CurrentContent() failure", this));
     return E_FAIL;
   }
 
+  CompleteLastActionIfStillIncomplete();
   PendingAction* action = mPendingActions.AppendElement();
   action->mType = PendingAction::COMPOSITION_START;
   action->mSelectionStart = start;
   action->mSelectionLength = length;
 
   currentContent.StartComposition(pComposition, *action, aPreserveSelection);
 
   PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
@@ -2837,16 +2837,17 @@ nsTextStore::RecordCompositionEndAction(
   PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
          ("TSF: 0x%p nsTextStore::RecordCompositionEndAction(), "
           "mComposition={ mView=0x%p, mString=\"%s\" }",
           this, mComposition.mView.get(),
           NS_ConvertUTF16toUTF8(mComposition.mString).get()));
 
   MOZ_ASSERT(mComposition.IsComposing());
 
+  CompleteLastActionIfStillIncomplete();
   PendingAction* action = mPendingActions.AppendElement();
   action->mType = PendingAction::COMPOSITION_END;
   action->mData = mComposition.mString;
 
   Content& currentContent = CurrentContent();
   if (!currentContent.IsInitialized()) {
     PR_LOG(sTextStoreLog, PR_LOG_ERROR,
            ("TSF: 0x%p   nsTextStore::RecordCompositionEndAction() FAILED due "
--- a/widget/windows/nsTextStore.h
+++ b/widget/windows/nsTextStore.h
@@ -535,16 +535,24 @@ protected:
     if (mPendingActions.IsEmpty()) {
       return false;
     }
     const PendingAction& lastAction = mPendingActions.LastElement();
     return lastAction.mType == PendingAction::COMPOSITION_UPDATE &&
            lastAction.mIncomplete;
   }
 
+  void CompleteLastActionIfStillIncomplete()
+  {
+    if (!IsPendingCompositionUpdateIncomplete()) {
+      return;
+    }
+    RecordCompositionUpdateAction();
+  }
+
   // When On*Composition() is called without document lock, we need to flush
   // the recorded actions at quitting the method.
   // AutoPendingActionAndContentFlusher class is usedful for it.  
   class MOZ_STACK_CLASS AutoPendingActionAndContentFlusher MOZ_FINAL
   {
   public:
     AutoPendingActionAndContentFlusher(nsTextStore* aTextStore)
       : mTextStore(aTextStore)