Skip to content

Commit

Permalink
Bug 1376407 - part2: Emulate selection when committing composition as…
Browse files Browse the repository at this point in the history
… 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 mozilla#4, Gecko stores start of composition as selection start, then, trying to adjust it at mozilla#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 mozilla#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
  • Loading branch information
masayuki-nakano committed Jun 27, 2017
1 parent 8fc34d5 commit 4fd14a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions widget/gtk/IMContextWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions widget/gtk/IMContextWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4fd14a9

Please sign in to comment.