Bug 1050703 Don't reset selection at starting composition if it's unnecessary r=emk

This commit is contained in:
Masayuki Nakano 2014-08-12 00:17:18 +09:00
parent 96ac6ce176
commit c59d657a01
2 changed files with 35 additions and 18 deletions

View File

@ -1006,18 +1006,20 @@ nsTextStore::FlushPendingActions()
MOZ_ASSERT(mComposition.mLastData.IsEmpty());
// Select composition range so the new composition replaces the range
WidgetSelectionEvent selectionSet(true, NS_SELECTION_SET, mWidget);
mWidget->InitEvent(selectionSet);
selectionSet.mOffset = static_cast<uint32_t>(action.mSelectionStart);
selectionSet.mLength = static_cast<uint32_t>(action.mSelectionLength);
selectionSet.mReversed = false;
mWidget->DispatchWindowEvent(&selectionSet);
if (!selectionSet.mSucceeded) {
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
("TSF: 0x%p nsTextStore::FlushPendingActions() "
"FAILED due to NS_SELECTION_SET failure", this));
break;
if (action.mAdjustSelection) {
// Select composition range so the new composition replaces the range
WidgetSelectionEvent selectionSet(true, NS_SELECTION_SET, mWidget);
mWidget->InitEvent(selectionSet);
selectionSet.mOffset = static_cast<uint32_t>(action.mSelectionStart);
selectionSet.mLength = static_cast<uint32_t>(action.mSelectionLength);
selectionSet.mReversed = false;
mWidget->DispatchWindowEvent(&selectionSet);
if (!selectionSet.mSucceeded) {
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
("TSF: 0x%p nsTextStore::FlushPendingActions() "
"FAILED due to NS_SELECTION_SET failure", this));
break;
}
}
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
("TSF: 0x%p nsTextStore::FlushPendingActions() "
@ -2817,7 +2819,22 @@ nsTextStore::RecordCompositionStartAction(ITfCompositionView* pComposition,
action->mSelectionStart = start;
action->mSelectionLength = length;
currentContent.StartComposition(pComposition, *action, aPreserveSelection);
if (aPreserveSelection) {
action->mAdjustSelection = false;
} else {
Selection& currentSel = CurrentSelection();
if (currentSel.IsDirty()) {
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
("TSF: 0x%p nsTextStore::RecordCompositionStartAction() FAILED "
"due to CurrentSelection() failure", this));
action->mAdjustSelection = true;
} else {
action->mAdjustSelection = currentSel.MinOffset() != start ||
currentSel.MaxOffset() != start + length;
}
}
currentContent.StartComposition(pComposition, *action);
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
("TSF: 0x%p nsTextStore::RecordCompositionStartAction() succeeded: "
@ -4050,8 +4067,7 @@ nsTextStore::Content::ReplaceTextWith(LONG aStart, LONG aLength,
void
nsTextStore::Content::StartComposition(ITfCompositionView* aCompositionView,
const PendingAction& aCompStart,
bool aPreserveSelection)
const PendingAction& aCompStart)
{
MOZ_ASSERT(mInitialized);
MOZ_ASSERT(aCompositionView);
@ -4061,7 +4077,7 @@ nsTextStore::Content::StartComposition(ITfCompositionView* aCompositionView,
mComposition.Start(aCompositionView, aCompStart.mSelectionStart,
GetSubstring(static_cast<uint32_t>(aCompStart.mSelectionStart),
static_cast<uint32_t>(aCompStart.mSelectionLength)));
if (!aPreserveSelection) {
if (aCompStart.mAdjustSelection) {
mSelection.SetSelection(mComposition.mStart, mComposition.mString.Length(),
false);
}

View File

@ -508,6 +508,8 @@ protected:
bool mSelectionReversed;
// For compositionupdate
bool mIncomplete;
// For compositionstart
bool mAdjustSelection;
};
// Items of mPendingActions are appended when TSF tells us to need to dispatch
// DOM composition events. However, we cannot dispatch while the document is
@ -610,8 +612,7 @@ protected:
void ReplaceTextWith(LONG aStart, LONG aLength, const nsAString& aString);
void StartComposition(ITfCompositionView* aCompositionView,
const PendingAction& aCompStart,
bool aPreserveSelection);
const PendingAction& aCompStart);
void EndComposition(const PendingAction& aCompEnd);
const nsString& Text() const