Bug 1376407 - part2: Emulate selection when committing composition as collapsed to the end of composition r=m_kato

When you start new composition during converting with Mozc in e10s mode, the following things occur:

1. Mozc commits previous composition.
2. Gecko dispatches eCompositionCommit event.
3. Mozc sets new composition string (skipping composition start signal).
4. Gecko dispatches eCompositionStart and eCompositionChange event.
5. Selection is changed asynchronously.
6. Gecko sets position of IME windows.

At #4, Gecko stores start of composition as selection start, then, trying to adjust it at #5. However, new selection is caret position in new composition string. Therefore, it's not used for the adjustment. This causes that stored composition start offset is always the start of the previous composition (if the previous patch didn't change EnsureToCacheSelection() behavior). So, IMContextWrapper needs to compute proper composition start offset in this case.

The simplest fix is, modifying selection at #2 as which will be occurred in focused editor.  So, this patch makes the selection cache collapsed to the end of committing string.

Note that actual selection may be different if JS changes selection and/or the text in the focused editor. However, it doesn't matter. IMContextWrapper should behave as expected while current composition is active.

MozReview-Commit-ID: 221mDUd8yRP

--HG--
extra : rebase_source : 571b2de85ed6ea1fdadea73b7f95507937cc60e9
This commit is contained in:
Masayuki Nakano 2017-06-27 03:11:25 -07:00
parent b67cd28522
commit a9fb7c2f23
2 changed files with 15 additions and 0 deletions

View File

@ -1559,10 +1559,18 @@ IMContextWrapper::DispatchCompositionCommitEvent(
RefPtr<nsWindow> lastFocusedWindow(mLastFocusedWindow);
// Emulate selection until receiving actual selection range.
mSelection.CollapseTo(
mCompositionStart +
(aCommitString ? aCommitString->Length() :
mDispatchedCompositionString.Length()),
mSelection.mWritingMode);
mCompositionState = eCompositionState_NotComposing;
mCompositionStart = UINT32_MAX;
mCompositionTargetRange.Clear();
mDispatchedCompositionString.Truncate();
mSelectedStringRemovedByComposition.Truncate();
nsEventStatus status;
rv = dispatcher->CommitComposition(status, aCommitString);

View File

@ -231,6 +231,13 @@ protected:
mOffset = UINT32_MAX;
mWritingMode = WritingMode();
}
void CollapseTo(uint32_t aOffset,
const WritingMode& aWritingMode)
{
mWritingMode = aWritingMode;
mOffset = aOffset;
mString.Truncate();
}
void Assign(const IMENotification& aIMENotification);
void Assign(const WidgetQueryContentEvent& aSelectedTextEvent);