# HG changeset patch # User Masayuki Nakano # Date 1518610878 -32400 # Node ID cb4185c40f3d2445850029e4785d324783375497 # Parent 887fd2123fac624e7e0a565528fcd5cc49065503 Bug 1438133 - Ctrl + Enter should cause keypress event even though the key combination doesn't input any character r=smaug Currently, we dispatch keypress event when Enter is pressed without modifiers or only with Shift key. However, the other browsers dispatch keypress event for Ctrl + Enter in any platforms even if it doesn't cause any text input. So, we should fire keypress event for Ctrl + Enter even in strict keypress dispatching mode. Note that with other modifiers, it depends on browser and/or platform. So, anyway, web developers shouldn't use keypress event to catch Alt + Enter, Meta + Enter and two or more modifiers + Enter. MozReview-Commit-ID: 3uUMkhL5VfJ diff --git a/dom/events/test/test_dom_keyboard_event.html b/dom/events/test/test_dom_keyboard_event.html --- a/dom/events/test/test_dom_keyboard_event.html +++ b/dom/events/test/test_dom_keyboard_event.html @@ -3,16 +3,19 @@ Test for DOM KeyboardEvent

+

+

+

 
 
diff --git a/widget/TextEventDispatcher.cpp b/widget/TextEventDispatcher.cpp --- a/widget/TextEventDispatcher.cpp +++ b/widget/TextEventDispatcher.cpp @@ -686,17 +686,17 @@ TextEventDispatcher::DispatchKeyboardEve static_cast(original).mKeyValue); MOZ_ASSERT(keyEvent.mCodeValue == static_cast(original).mCodeValue); } } if (sDispatchKeyPressEventsOnlySystemGroupInContent && keyEvent.mMessage == eKeyPress && - !keyEvent.IsInputtingText() && !keyEvent.IsInputtingLineBreak()) { + !keyEvent.ShouldKeyPressEventBeFiredOnContent()) { keyEvent.mFlags.mOnlySystemGroupDispatchInContent = true; } DispatchInputEvent(mWidget, keyEvent, aStatus); return true; } bool diff --git a/widget/TextEvents.h b/widget/TextEvents.h --- a/widget/TextEvents.h +++ b/widget/TextEvents.h @@ -206,16 +206,39 @@ public: return mMessage == eKeyPress && mKeyNameIndex == KEY_NAME_INDEX_Enter && !(mModifiers & (MODIFIER_ALT | MODIFIER_CONTROL | MODIFIER_META | MODIFIER_OS)); } + /** + * ShouldKeyPressEventBeFiredOnContent() should be called only when the + * instance is eKeyPress event. This returns true when the eKeyPress + * event should be fired even on content in the default event group. + */ + bool ShouldKeyPressEventBeFiredOnContent() const + { + MOZ_DIAGNOSTIC_ASSERT(mMessage == eKeyPress); + if (IsInputtingText() || IsInputtingLineBreak()) { + return true; + } + // Ctrl + Enter won't cause actual input in our editor. + // However, the other browsers fire keypress event in any platforms. + // So, for compatibility with them, we should fire keypress event for + // Ctrl + Enter too. + return mMessage == eKeyPress && + mKeyNameIndex == KEY_NAME_INDEX_Enter && + !(mModifiers & (MODIFIER_ALT | + MODIFIER_META | + MODIFIER_OS | + MODIFIER_SHIFT)); + } + virtual WidgetEvent* Duplicate() const override { MOZ_ASSERT(mClass == eKeyboardEventClass, "Duplicate() must be overridden by sub class"); // Not copying widget, it is a weak reference. WidgetKeyboardEvent* result = new WidgetKeyboardEvent(false, mMessage, nullptr); result->AssignKeyEventData(*this, true);