From a79188fbc7faf8fa1982d3e93987871538f0fd5a Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 5 Oct 2011 11:19:24 +0900 Subject: [PATCH] Bug 685073 part.2 Consume key event which causes nested key event r=smichaud --- widget/src/cocoa/TextInputHandler.h | 13 ++++++++++++- widget/src/cocoa/TextInputHandler.mm | 13 +++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/widget/src/cocoa/TextInputHandler.h b/widget/src/cocoa/TextInputHandler.h index c2377b9aef63..ce661d6e8f4d 100644 --- a/widget/src/cocoa/TextInputHandler.h +++ b/widget/src/cocoa/TextInputHandler.h @@ -481,6 +481,8 @@ protected: bool mKeyPressDispatched; // Whether keypress event was consumed by web contents or chrome contents. bool mKeyPressHandled; + // Whether the key event causes other key events via IME or something. + bool mCausedOtherKeyEvents; KeyEventState() : mKeyEvent(nsnull) { @@ -502,6 +504,7 @@ protected: mKeyDownHandled = aOther.mKeyDownHandled; mKeyPressDispatched = aOther.mKeyPressDispatched; mKeyPressHandled = aOther.mKeyPressHandled; + mCausedOtherKeyEvents = aOther.mCausedOtherKeyEvents; } ~KeyEventState() @@ -525,6 +528,7 @@ protected: mKeyDownHandled = false; mKeyPressDispatched = false; mKeyPressHandled = false; + mCausedOtherKeyEvents = false; } bool KeyDownOrPressHandled() @@ -570,8 +574,15 @@ protected: */ KeyEventState* PushKeyEvent(NSEvent* aNativeKeyEvent) { + PRUint32 nestCount = mCurrentKeyEvents.Length(); + for (PRUint32 i = 0; i < nestCount; i++) { + // When the key event is caused by another key event, all key events + // which are being handled should be marked as "consumed". + mCurrentKeyEvents[i]->mCausedOtherKeyEvents = true; + } + KeyEventState* keyEvent = nsnull; - if (mCurrentKeyEvents.Length() == 0) { + if (nestCount == 0) { mFirstKeyEvent.Set(aNativeKeyEvent); keyEvent = &mFirstKeyEvent; } else { diff --git a/widget/src/cocoa/TextInputHandler.mm b/widget/src/cocoa/TextInputHandler.mm index 46710dd862fb..830335549795 100644 --- a/widget/src/cocoa/TextInputHandler.mm +++ b/widget/src/cocoa/TextInputHandler.mm @@ -1124,7 +1124,8 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent) // our default action for this key. if (!(interpretKeyEventsCalled && IsNormalCharInputtingEvent(keypressEvent))) { - if (currentKeyEvent->mKeyDownHandled) { + if (currentKeyEvent->mKeyDownHandled || + currentKeyEvent->mCausedOtherKeyEvents) { keypressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT; } currentKeyEvent->mKeyPressHandled = DispatchEvent(keypressEvent); @@ -1419,12 +1420,16 @@ TextInputHandler::DoCommandBySelector(const char* aSelector) PR_LOG(gLog, PR_LOG_ALWAYS, ("%p TextInputHandler::DoCommandBySelector, aSelector=\"%s\", " - "Destroyed()=%s, keypressHandled=%s", + "Destroyed()=%s, keypressHandled=%s, causedOtherKeyEvents=%s", this, aSelector ? aSelector : "", TrueOrFalse(Destroyed()), currentKeyEvent ? - TrueOrFalse(currentKeyEvent->mKeyPressHandled) : "N/A")); + TrueOrFalse(currentKeyEvent->mKeyPressHandled) : "N/A", + currentKeyEvent ? + TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A")); - return !Destroyed() && currentKeyEvent && currentKeyEvent->mKeyPressHandled; + return !Destroyed() && currentKeyEvent && + (currentKeyEvent->mKeyPressHandled || + currentKeyEvent->mCausedOtherKeyEvents); }