From 9a6c0e03b6bfcb503724af20a39acdb51249d058 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 25 Nov 2014 14:02:30 +0900 Subject: [PATCH] Bug 1077345 part.3 Add WidgetCompositionEvent::CausesDOMTextEvent() and WidgetCompositionEvent::CausesDOMCompositionEndEvent() r=smaug --- dom/events/IMEStateManager.cpp | 2 +- dom/events/TextComposition.cpp | 10 +++++----- dom/ipc/TabParent.cpp | 5 +++-- widget/PuppetWidget.cpp | 3 ++- widget/TextEvents.h | 10 ++++++++++ 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/dom/events/IMEStateManager.cpp b/dom/events/IMEStateManager.cpp index 5e3722613f6a..fe2716630373 100644 --- a/dom/events/IMEStateManager.cpp +++ b/dom/events/IMEStateManager.cpp @@ -943,7 +943,7 @@ IMEStateManager::DispatchCompositionEvent( // destroy the TextComposition with synthesized compositionend event. if ((!aIsSynthesized || composition->WasNativeCompositionEndEventDiscarded()) && - aCompositionEvent->message == NS_COMPOSITION_END) { + aCompositionEvent->CausesDOMCompositionEndEvent()) { TextCompositionArray::index_type i = sTextCompositions->IndexOf(aCompositionEvent->widget); if (i != TextCompositionArray::NoIndex) { diff --git a/dom/events/TextComposition.cpp b/dom/events/TextComposition.cpp index 296105dacfc0..bce1e237d005 100644 --- a/dom/events/TextComposition.cpp +++ b/dom/events/TextComposition.cpp @@ -122,7 +122,7 @@ TextComposition::OnCompositionEventDiscarded( // runnable event? However, even if we do so, it might make native IME // confused due to async modification. Especially when native IME is // TSF. - if (aCompositionEvent->message != NS_COMPOSITION_END) { + if (!aCompositionEvent->CausesDOMCompositionEndEvent()) { return; } @@ -185,7 +185,7 @@ TextComposition::DispatchCompositionEvent( } } - if (aCompositionEvent->message == NS_COMPOSITION_CHANGE) { + if (aCompositionEvent->CausesDOMTextEvent()) { if (!MaybeDispatchCompositionUpdate(aCompositionEvent)) { return; } @@ -200,13 +200,13 @@ TextComposition::DispatchCompositionEvent( // Emulate editor behavior of compositionchange event (DOM text event) handler // if no editor handles composition events. - if (aCompositionEvent->message == NS_COMPOSITION_CHANGE && !HasEditor()) { + if (aCompositionEvent->CausesDOMTextEvent() && !HasEditor()) { EditorWillHandleCompositionChangeEvent(aCompositionEvent); EditorDidHandleCompositionChangeEvent(); } #ifdef DEBUG - else if (aCompositionEvent->message == NS_COMPOSITION_END) { + else if (aCompositionEvent->CausesDOMCompositionEndEvent()) { MOZ_ASSERT(!mIsComposing, "Why is the editor still composing?"); MOZ_ASSERT(!HasEditor(), "Why does the editor still keep to hold this?"); } @@ -240,7 +240,7 @@ TextComposition::NotityUpdateComposition( mCompositionStartOffset = 0; } mCompositionTargetOffset = mCompositionStartOffset; - } else if (aCompositionEvent->message == NS_COMPOSITION_CHANGE) { + } else if (aCompositionEvent->CausesDOMTextEvent()) { mCompositionTargetOffset = mCompositionStartOffset + aCompositionEvent->TargetClauseOffset(); } else { diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index 99ae72a66810..7f9f1b4e68ee 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1638,11 +1638,11 @@ TabParent::SendCompositionEvent(WidgetCompositionEvent& event) return false; } - if (event.message == NS_COMPOSITION_CHANGE) { + if (event.CausesDOMTextEvent()) { return SendCompositionChangeEvent(event); } - mIMEComposing = event.message != NS_COMPOSITION_END; + mIMEComposing = !event.CausesDOMCompositionEndEvent(); mIMECompositionStart = std::min(mIMESelectionAnchor, mIMESelectionFocus); if (mIMECompositionEnding) return true; @@ -1673,6 +1673,7 @@ TabParent::SendCompositionChangeEvent(WidgetCompositionEvent& event) } mIMESelectionAnchor = mIMESelectionFocus = mIMECompositionStart + event.mData.Length(); + mIMEComposing = !event.CausesDOMCompositionEndEvent(); event.mSeqno = ++mIMESeqno; return PBrowserParent::SendCompositionEvent(event); diff --git a/widget/PuppetWidget.cpp b/widget/PuppetWidget.cpp index 017fae5d9cb9..bc4d677a87e0 100644 --- a/widget/PuppetWidget.cpp +++ b/widget/PuppetWidget.cpp @@ -331,7 +331,8 @@ PuppetWidget::DispatchEvent(WidgetGUIEvent* event, nsEventStatus& aStatus) aStatus = mAttachedWidgetListener->HandleEvent(event, mUseAttachedEvents); } - if (event->message == NS_COMPOSITION_END) { + if (event->mClass == eCompositionEventClass && + event->AsCompositionEvent()->CausesDOMCompositionEndEvent()) { mIMEComposing = false; } diff --git a/widget/TextEvents.h b/widget/TextEvents.h index 61a89b4982de..0eb7872bfcaf 100644 --- a/widget/TextEvents.h +++ b/widget/TextEvents.h @@ -342,6 +342,16 @@ public: { return mRanges ? mRanges->Length() : 0; } + + bool CausesDOMTextEvent() const + { + return message == NS_COMPOSITION_CHANGE; + } + + bool CausesDOMCompositionEndEvent() const + { + return message == NS_COMPOSITION_END; + } }; /******************************************************************************