diff --git a/widget/windows/nsTextStore.cpp b/widget/windows/nsTextStore.cpp index ad48e794be7..cb583d90395 100644 --- a/widget/windows/nsTextStore.cpp +++ b/widget/windows/nsTextStore.cpp @@ -963,6 +963,15 @@ nsTextStore::DidLockGranted() 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(); + } + FlushPendingActions(); } @@ -1621,7 +1630,7 @@ nsTextStore::RecordCompositionUpdateAction() return E_FAIL; } - PendingAction* action = GetPendingCompositionUpdate(); + 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 @@ -1714,6 +1723,8 @@ nsTextStore::RecordCompositionUpdateAction() caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION; action->mRanges->AppendElement(caretRange); + action->mIncomplete = false; + PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() " "succeeded", this)); @@ -2925,6 +2936,8 @@ nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, // pRangeNew is null when the update is not complete if (!pRangeNew) { + PendingAction* action = LastOrNewPendingCompositionUpdate(); + action->mIncomplete = true; PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, ("TSF: 0x%p nsTextStore::OnUpdateComposition() succeeded but " "not complete", this)); diff --git a/widget/windows/nsTextStore.h b/widget/windows/nsTextStore.h index 43b2a2e0518..48aa3a464be 100644 --- a/widget/windows/nsTextStore.h +++ b/widget/windows/nsTextStore.h @@ -506,6 +506,8 @@ protected: nsRefPtr mRanges; // For selectionset bool mSelectionReversed; + // For compositionupdate + bool mIncomplete; }; // Items of mPendingActions are appended when TSF tells us to need to dispatch // DOM composition events. However, we cannot dispatch while the document is @@ -513,7 +515,7 @@ protected: // actions should be performed when document lock is unlocked. nsTArray mPendingActions; - PendingAction* GetPendingCompositionUpdate() + PendingAction* LastOrNewPendingCompositionUpdate() { if (!mPendingActions.IsEmpty()) { PendingAction& lastAction = mPendingActions.LastElement(); @@ -524,9 +526,20 @@ protected: PendingAction* newAction = mPendingActions.AppendElement(); newAction->mType = PendingAction::COMPOSITION_UPDATE; newAction->mRanges = new mozilla::TextRangeArray(); + newAction->mIncomplete = true; return newAction; } + bool IsPendingCompositionUpdateIncomplete() const + { + if (mPendingActions.IsEmpty()) { + return false; + } + const PendingAction& lastAction = mPendingActions.LastElement(); + return lastAction.mType == PendingAction::COMPOSITION_UPDATE && + lastAction.mIncomplete; + } + // 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.