Skip to content

Commit

Permalink
[embedlite] Don't dispatch NS_COMPOSITION_UPDATE to widget
Browse files Browse the repository at this point in the history
NS_COMPOSITION_UPDATE is supposed to be dispatched by TextComposition
upon changing a composition string with NS_COMPOSITION_CHANGE.
Otherwise an assertion in dom/events/IMEStateManager.cpp gets
triggered: "compositionupdate event shouldn't be dispatched manually".

Also according to https://developer.mozilla.org/en-US/docs/Mozilla/IME_handling_guide
WidgetCompositionEvent.mRanges must not be null when event message
is NS_COMPOSITION_CHANGE.

JB#25378
  • Loading branch information
rojkov committed Feb 3, 2015
1 parent 9a78e2e commit 596328b
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -827,12 +827,12 @@ EmbedLiteViewBaseChild::RecvHandleTextEvent(const nsString& commit, const nsStri
// probably logic here is over engineered, but clean enough
bool prevIsComposition = mIMEComposing;
bool StartComposite = !prevIsComposition && commit.IsEmpty() && !preEdit.IsEmpty();
bool UpdateComposite = prevIsComposition && commit.IsEmpty() && !preEdit.IsEmpty();
bool ChangeComposite = prevIsComposition && commit.IsEmpty() && !preEdit.IsEmpty();
bool EndComposite = prevIsComposition && preEdit.IsEmpty();
mIMEComposing = UpdateComposite || StartComposite;
mIMEComposing = ChangeComposite || StartComposite;
nsString pushStr = preEdit.IsEmpty() ? commit : preEdit;
if (!commit.IsEmpty() && !EndComposite) {
StartComposite = UpdateComposite = EndComposite = true;
StartComposite = ChangeComposite = EndComposite = true;
}

if (StartComposite) {
Expand All @@ -841,16 +841,25 @@ EmbedLiteViewBaseChild::RecvHandleTextEvent(const nsString& commit, const nsStri
mHelper->DispatchWidgetEvent(event);
}

if (StartComposite || UpdateComposite || EndComposite) {
WidgetCompositionEvent updateEvent(true, NS_COMPOSITION_UPDATE, widget);
InitEvent(updateEvent, nullptr);
updateEvent.mData = pushStr;
mHelper->DispatchWidgetEvent(updateEvent);
if (StartComposite || ChangeComposite || EndComposite) {

WidgetCompositionEvent event(true, NS_COMPOSITION_CHANGE, widget);
InitEvent(event, nullptr);
event.mData = pushStr;
mHelper->DispatchWidgetEvent(event);
{
WidgetCompositionEvent event(true, NS_COMPOSITION_CHANGE, widget);
InitEvent(event, nullptr);
event.mData = pushStr;

if (!EndComposite) {
// Because we're leaving the composition open, we need to
// include proper text ranges to make the editor happy.
TextRange range;
range.mStartOffset = 0;
range.mEndOffset = event.mData.Length();
range.mRangeType = NS_TEXTRANGE_RAWINPUT;
event.mRanges = new TextRangeArray();
event.mRanges->AppendElement(range);
}
mHelper->DispatchWidgetEvent(event);
}

nsCOMPtr<nsIPresShell> ps = mHelper->GetPresContext()->GetPresShell();
if (!ps) {
Expand Down

0 comments on commit 596328b

Please sign in to comment.