Bug 1121313 - Part 2. Don't generate composition event on child process if parent process doesn't send composition event by NotifyIME. r=masayuki

This commit is contained in:
Makoto Kato
2015-02-17 11:30:55 +09:00
parent 2076396c7e
commit 83584c1268
5 changed files with 21 additions and 17 deletions

View File

@@ -267,15 +267,18 @@ parent:
/** /**
* Instructs chrome to end any pending composition * Instructs chrome to end any pending composition
* *
* cancel PR_TRUE if composition should be cancelled * cancel true if composition should be cancelled
* noCompositionEvent true if no composition event is fired by commit or
* cancel
* composition Text to commit before ending the composition * composition Text to commit before ending the composition
* *
* if cancel is PR_TRUE, * if cancel is true,
* widget should return empty string for composition * widget should return empty string for composition
* if cancel is PR_FALSE, * if cancel is false,
* widget should return the current composition text * widget should return the current composition text
*/ */
prio(urgent) sync EndIMEComposition(bool cancel) returns (nsString composition); prio(urgent) sync EndIMEComposition(bool cancel)
returns (bool noCompositionEvent, nsString composition);
/** /**
* Request that the parent process move focus to the browser's frame. If * Request that the parent process move focus to the browser's frame. If

View File

@@ -259,6 +259,7 @@ TabParent::TabParent(nsIContentParent* aManager,
, mWritingMode() , mWritingMode()
, mIMEComposing(false) , mIMEComposing(false)
, mIMECompositionEnding(false) , mIMECompositionEnding(false)
, mIMEEventCountAfterEnding(0)
, mIMECompositionStart(0) , mIMECompositionStart(0)
, mIMESeqno(0) , mIMESeqno(0)
, mIMECompositionRectOffset(0) , mIMECompositionRectOffset(0)
@@ -1990,8 +1991,10 @@ TabParent::SendCompositionEvent(WidgetCompositionEvent& event)
mIMEComposing = !event.CausesDOMCompositionEndEvent(); mIMEComposing = !event.CausesDOMCompositionEndEvent();
mIMECompositionStart = std::min(mIMESelectionAnchor, mIMESelectionFocus); mIMECompositionStart = std::min(mIMESelectionAnchor, mIMESelectionFocus);
if (mIMECompositionEnding) if (mIMECompositionEnding) {
mIMEEventCountAfterEnding++;
return true; return true;
}
event.mSeqno = ++mIMESeqno; event.mSeqno = ++mIMESeqno;
return PBrowserParent::SendCompositionEvent(event); return PBrowserParent::SendCompositionEvent(event);
} }
@@ -2009,6 +2012,7 @@ TabParent::SendCompositionChangeEvent(WidgetCompositionEvent& event)
{ {
if (mIMECompositionEnding) { if (mIMECompositionEnding) {
mIMECompositionText = event.mData; mIMECompositionText = event.mData;
mIMEEventCountAfterEnding++;
return true; return true;
} }
@@ -2099,6 +2103,7 @@ TabParent::GetRenderFrame()
bool bool
TabParent::RecvEndIMEComposition(const bool& aCancel, TabParent::RecvEndIMEComposition(const bool& aCancel,
bool* aNoCompositionEvent,
nsString* aComposition) nsString* aComposition)
{ {
nsCOMPtr<nsIWidget> widget = GetWidget(); nsCOMPtr<nsIWidget> widget = GetWidget();
@@ -2106,11 +2111,13 @@ TabParent::RecvEndIMEComposition(const bool& aCancel,
return true; return true;
mIMECompositionEnding = true; mIMECompositionEnding = true;
mIMEEventCountAfterEnding = 0;
widget->NotifyIME(IMENotification(aCancel ? REQUEST_TO_CANCEL_COMPOSITION : widget->NotifyIME(IMENotification(aCancel ? REQUEST_TO_CANCEL_COMPOSITION :
REQUEST_TO_COMMIT_COMPOSITION)); REQUEST_TO_COMMIT_COMPOSITION));
mIMECompositionEnding = false; mIMECompositionEnding = false;
*aNoCompositionEvent = !mIMEEventCountAfterEnding;
*aComposition = mIMECompositionText; *aComposition = mIMECompositionText;
mIMECompositionText.Truncate(0); mIMECompositionText.Truncate(0);
return true; return true;

View File

@@ -195,6 +195,7 @@ public:
InfallibleTArray<LayoutDeviceIntRect>&& aCompositionRects, InfallibleTArray<LayoutDeviceIntRect>&& aCompositionRects,
const LayoutDeviceIntRect& aCaretRect) MOZ_OVERRIDE; const LayoutDeviceIntRect& aCaretRect) MOZ_OVERRIDE;
virtual bool RecvEndIMEComposition(const bool& aCancel, virtual bool RecvEndIMEComposition(const bool& aCancel,
bool* aNoCompositionEvent,
nsString* aComposition) MOZ_OVERRIDE; nsString* aComposition) MOZ_OVERRIDE;
virtual bool RecvGetInputContext(int32_t* aIMEEnabled, virtual bool RecvGetInputContext(int32_t* aIMEEnabled,
int32_t* aIMEOpen, int32_t* aIMEOpen,
@@ -418,6 +419,7 @@ protected:
mozilla::WritingMode mWritingMode; mozilla::WritingMode mWritingMode;
bool mIMEComposing; bool mIMEComposing;
bool mIMECompositionEnding; bool mIMECompositionEnding;
uint32_t mIMEEventCountAfterEnding;
// Buffer to store composition text during ResetInputState // Buffer to store composition text during ResetInputState
// Compositions in almost all cases are small enough for nsAutoString // Compositions in almost all cases are small enough for nsAutoString
nsAutoString mIMECompositionText; nsAutoString mIMECompositionText;

View File

@@ -109,7 +109,6 @@ PuppetWidget::Create(nsIWidget *aParent,
mDrawTarget = gfxPlatform::GetPlatform()-> mDrawTarget = gfxPlatform::GetPlatform()->
CreateOffscreenContentDrawTarget(IntSize(1, 1), SurfaceFormat::B8G8R8A8); CreateOffscreenContentDrawTarget(IntSize(1, 1), SurfaceFormat::B8G8R8A8);
mIMEComposing = false;
mNeedIMEStateInit = MightNeedIMEFocus(aInitData); mNeedIMEStateInit = MightNeedIMEFocus(aInitData);
PuppetWidget* parent = static_cast<PuppetWidget*>(aParent); PuppetWidget* parent = static_cast<PuppetWidget*>(aParent);
@@ -305,9 +304,6 @@ PuppetWidget::DispatchEvent(WidgetGUIEvent* event, nsEventStatus& aStatus)
aStatus = nsEventStatus_eIgnore; aStatus = nsEventStatus_eIgnore;
if (event->message == NS_COMPOSITION_START) {
mIMEComposing = true;
}
uint32_t seqno = kLatestSeqno; uint32_t seqno = kLatestSeqno;
switch (event->mClass) { switch (event->mClass) {
case eCompositionEventClass: case eCompositionEventClass:
@@ -330,11 +326,6 @@ PuppetWidget::DispatchEvent(WidgetGUIEvent* event, nsEventStatus& aStatus)
aStatus = mAttachedWidgetListener->HandleEvent(event, mUseAttachedEvents); aStatus = mAttachedWidgetListener->HandleEvent(event, mUseAttachedEvents);
} }
if (event->mClass == eCompositionEventClass &&
event->AsCompositionEvent()->CausesDOMCompositionEndEvent()) {
mIMEComposing = false;
}
return NS_OK; return NS_OK;
} }
@@ -402,19 +393,21 @@ PuppetWidget::IMEEndComposition(bool aCancel)
#endif #endif
nsEventStatus status; nsEventStatus status;
bool noCompositionEvent = true;
WidgetCompositionEvent compositionCommitEvent(true, NS_COMPOSITION_COMMIT, WidgetCompositionEvent compositionCommitEvent(true, NS_COMPOSITION_COMMIT,
this); this);
InitEvent(compositionCommitEvent, nullptr); InitEvent(compositionCommitEvent, nullptr);
// SendEndIMEComposition is always called since ResetInputState // SendEndIMEComposition is always called since ResetInputState
// should always be called even if we aren't composing something. // should always be called even if we aren't composing something.
if (!mTabChild || if (!mTabChild ||
!mTabChild->SendEndIMEComposition(aCancel, !mTabChild->SendEndIMEComposition(aCancel, &noCompositionEvent,
&compositionCommitEvent.mData)) { &compositionCommitEvent.mData)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
if (!mIMEComposing) if (noCompositionEvent) {
return NS_OK; return NS_OK;
}
compositionCommitEvent.mSeqno = mIMELastReceivedSeqno; compositionCommitEvent.mSeqno = mIMELastReceivedSeqno;
DispatchEvent(&compositionCommitEvent, status); DispatchEvent(&compositionCommitEvent, status);

View File

@@ -259,7 +259,6 @@ private:
mozilla::RefPtr<DrawTarget> mDrawTarget; mozilla::RefPtr<DrawTarget> mDrawTarget;
// IME // IME
nsIMEUpdatePreference mIMEPreferenceOfParent; nsIMEUpdatePreference mIMEPreferenceOfParent;
bool mIMEComposing;
// Latest seqno received through events // Latest seqno received through events
uint32_t mIMELastReceivedSeqno; uint32_t mIMELastReceivedSeqno;
// Chrome's seqno value when last blur occurred // Chrome's seqno value when last blur occurred