Bug 1530220 - part1 : allow some non-printalble keys as supported user gesture inputs to activate document. r=masayuki,cpearce a=lizzard
authorAlastor Wu <alwu@mozilla.com>
Tue, 05 Mar 2019 02:06:22 +0000
changeset 516285 dc39216dfad3
parent 516284 494caa8f588d
child 516286 4b05bf628c61
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki, cpearce, lizzard
bugs1530220
milestone66.0
Bug 1530220 - part1 : allow some non-printalble keys as supported user gesture inputs to activate document. r=masayuki,cpearce a=lizzard `carriage return` and `space` are common keys which user might use to start media, so we should take account them as supported user gesture inputs. As their pseudo char code are zero, we have to check their key code in order to distinguish them from other controls keys such as shift, alt... Differential Revision: https://phabricator.services.mozilla.com/D21253
dom/events/EventStateManager.cpp
widget/TextEvents.h
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -823,22 +823,19 @@ void EventStateManager::NotifyTargetUser
   // Don't activate if the target content of the event is contentEditable or
   // is inside an editable document, or is a text input control. Activating
   // due to typing/clicking on a text input would be surprising user experience.
   if (aTargetContent->IsEditable() || IsTextInput(aTargetContent)) {
     return;
   }
 
   // Don't gesture activate for key events for keys which are likely
-  // to be interaction with the browser, OS, or likely to be scrolling.
+  // to be interaction with the browser, OS.
   WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
-  if (keyEvent && (!keyEvent->PseudoCharCode() ||
-                   (keyEvent->IsControl() && !keyEvent->IsAltGraph()) ||
-                   (keyEvent->IsAlt() && !keyEvent->IsAltGraph()) ||
-                   keyEvent->IsMeta() || keyEvent->IsOS())) {
+  if (keyEvent && !keyEvent->CanUserGestureActivateTarget()) {
     return;
   }
 
   // Touch gestures that end outside the drag target were touches that turned
   // into scroll/pan/swipe actions. We don't want to gesture activate on such
   // actions, we want to only gesture activate on touches that are taps.
   // That is, touches that end in roughly the same place that they started.
   if (aEvent->mMessage == eTouchEnd && aEvent->AsTouchEvent() &&
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -294,16 +294,32 @@ class WidgetKeyboardEvent : public Widge
     result->AssignKeyEventData(*this, true);
     result->mEditCommandsForSingleLineEditor = mEditCommandsForSingleLineEditor;
     result->mEditCommandsForMultiLineEditor = mEditCommandsForMultiLineEditor;
     result->mEditCommandsForRichTextEditor = mEditCommandsForRichTextEditor;
     result->mFlags = mFlags;
     return result;
   }
 
+  bool CanUserGestureActivateTarget() const {
+    // Printable keys, 'carriage return' and 'space' are supported user gestures
+    // for activating the document. However, if supported key is being pressed
+    // combining with other operation keys, such like alt, control ..etc., we
+    // won't activate the target for them because at that time user might
+    // interact with browser or window manager which doesn't necessarily
+    // demonstrate user's intent to play media.
+    const bool isCombiningWithOperationKeys = (IsControl() && !IsAltGraph()) ||
+                                              (IsAlt() && !IsAltGraph()) ||
+                                              IsMeta() || IsOS();
+    const bool isEnterOrSpaceKey =
+        mKeyNameIndex == KEY_NAME_INDEX_Enter || mKeyCode == NS_VK_SPACE;
+    return (PseudoCharCode() || isEnterOrSpaceKey) &&
+           !isCombiningWithOperationKeys;
+  }
+
   // OS translated Unicode chars which are used for accesskey and accelkey
   // handling. The handlers will try from first character to last character.
   nsTArray<AlternativeCharCode> mAlternativeCharCodes;
   // DOM KeyboardEvent.key only when mKeyNameIndex is KEY_NAME_INDEX_USE_STRING.
   nsString mKeyValue;
   // DOM KeyboardEvent.code only when mCodeNameIndex is
   // CODE_NAME_INDEX_USE_STRING.
   nsString mCodeValue;