From 4fd14a91038a23227773865551b1fb23732ac7b0 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 27 Jun 2017 03:11:25 -0700 Subject: [PATCH] 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 --- widget/gtk/IMContextWrapper.cpp | 8 ++++++++ widget/gtk/IMContextWrapper.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/widget/gtk/IMContextWrapper.cpp b/widget/gtk/IMContextWrapper.cpp index aa2f6cddb26d7..e14c2b37c4436 100644 --- a/widget/gtk/IMContextWrapper.cpp +++ b/widget/gtk/IMContextWrapper.cpp @@ -1559,10 +1559,18 @@ IMContextWrapper::DispatchCompositionCommitEvent( RefPtr 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); diff --git a/widget/gtk/IMContextWrapper.h b/widget/gtk/IMContextWrapper.h index c18ff9fdbf1b3..adcc02854d998 100644 --- a/widget/gtk/IMContextWrapper.h +++ b/widget/gtk/IMContextWrapper.h @@ -231,6 +231,13 @@ class IMContextWrapper final : public TextEventDispatcherListener 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);