Bug 1049768 If OnCompositionUpdate() is never called with new range, we should call RecordCompositionUpdateAction() forcibly before flushing pending actions r=emk

This commit is contained in:
Masayuki Nakano 2014-08-07 15:50:21 +09:00
parent 1603c30876
commit 37d322f441
2 changed files with 28 additions and 2 deletions

View File

@ -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));

View File

@ -506,6 +506,8 @@ protected:
nsRefPtr<mozilla::TextRangeArray> 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<PendingAction> 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.