Bug 1433101 - part 2: Treat Enter and Shift+Enter as printable key r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 25 Jan 2018 23:59:20 +0900
changeset 456024 34abf97931631c9d4504f25ac0ce7f0e509aa62f
parent 456023 81157078b090fda2f79d42a1e0e93b1b86449944
child 456025 97ba0ca85c5b9e8f202e2d571951f9bc8fb6e45a
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1433101
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1433101 - part 2: Treat Enter and Shift+Enter as printable key r=smaug Chromium dispatches a keypress event when pressing Enter or Shift+Enter. Actually, when user press them in <pre> element of HTML editor, ツ・n is inserted. It makes sense to treat the key combinations as inputting text. MozReview-Commit-ID: Hvx87MZtZkn
editor/libeditor/HTMLEditor.cpp
editor/libeditor/TextEditor.cpp
widget/TextEventDispatcher.cpp
widget/TextEvents.h
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -661,18 +661,17 @@ HTMLEditor::HandleKeyPressEvent(WidgetKe
       }
       if (aKeyboardEvent->IsShift()) {
         return NS_OK; // don't type text for shift tabs
       }
       aKeyboardEvent->PreventDefault();
       return TypedText(NS_LITERAL_STRING("\t"), eTypedText);
     }
     case NS_VK_RETURN:
-      if (aKeyboardEvent->IsControl() || aKeyboardEvent->IsAlt() ||
-          aKeyboardEvent->IsMeta() || aKeyboardEvent->IsOS()) {
+      if (!aKeyboardEvent->IsInputtingLineBreak()) {
         return NS_OK;
       }
       aKeyboardEvent->PreventDefault(); // consumed
       if (aKeyboardEvent->IsShift()) {
         // only inserts a br node
         return TypedText(EmptyString(), eTypedBR);
       }
       // uses rules to figure out what to insert
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -370,19 +370,17 @@ TextEditor::HandleKeyPressEvent(WidgetKe
         return NS_OK;
       }
 
       // else we insert the tab straight through
       aKeyboardEvent->PreventDefault();
       return TypedText(NS_LITERAL_STRING("\t"), eTypedText);
     }
     case NS_VK_RETURN:
-      if (IsSingleLineEditor() || aKeyboardEvent->IsControl() ||
-          aKeyboardEvent->IsAlt() || aKeyboardEvent->IsMeta() ||
-          aKeyboardEvent->IsOS()) {
+      if (IsSingleLineEditor() || !aKeyboardEvent->IsInputtingLineBreak()) {
         return NS_OK;
       }
       aKeyboardEvent->PreventDefault();
       return TypedText(EmptyString(), eTypedBreak);
   }
 
   if (!aKeyboardEvent->IsInputtingText()) {
     // we don't PreventDefault() here or keybindings like control-x won't work
--- a/widget/TextEventDispatcher.cpp
+++ b/widget/TextEventDispatcher.cpp
@@ -691,17 +691,17 @@ TextEventDispatcher::DispatchKeyboardEve
                    static_cast<WidgetKeyboardEvent&>(original).mKeyValue);
       MOZ_ASSERT(keyEvent.mCodeValue ==
                    static_cast<WidgetKeyboardEvent&>(original).mCodeValue);
     }
   }
 
   if (sDispatchKeyPressEventsOnlySystemGroupInContent &&
       keyEvent.mMessage == eKeyPress &&
-      !keyEvent.IsInputtingText()) {
+      !keyEvent.IsInputtingText() && !keyEvent.IsInputtingLineBreak()) {
     keyEvent.mFlags.mOnlySystemGroupDispatchInContent = true;
   }
 
   DispatchInputEvent(mWidget, keyEvent, aStatus);
   return true;
 }
 
 bool
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -236,16 +236,26 @@ public:
     return mMessage == eKeyPress &&
            mCharCode &&
            !(mModifiers & (MODIFIER_ALT |
                            MODIFIER_CONTROL |
                            MODIFIER_META |
                            MODIFIER_OS));
   }
 
+  bool IsInputtingLineBreak() const
+  {
+    return mMessage == eKeyPress &&
+           mKeyNameIndex == KEY_NAME_INDEX_Enter &&
+           !(mModifiers & (MODIFIER_ALT |
+                           MODIFIER_CONTROL |
+                           MODIFIER_META |
+                           MODIFIER_OS));
+  }
+
   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);