Bug 1456037 - Gesture activate documents on key/mouse down not up. r=masayuki
authorChris Pearce <cpearce@mozilla.com>
Mon, 23 Apr 2018 15:56:29 +1200
changeset 468779 f38381338fee3e23b1393eead1fe42aa06e4d8bf
parent 468778 b89f665eed0f68706b20f0d850a7865cb3c0c808
child 468780 a5fe3122bc5979fb4c0a9ca8b0d6835610342666
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1456037
milestone61.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 1456037 - Gesture activate documents on key/mouse down not up. r=masayuki We should gesture activate documents in key/mouse down instead of up because if a web app wants to play a video inside a key/mouse handler, the document needs to be activated before the handler runs. Also, Chrome activates on key/mouse down, so we may have compat issues if we have different behaviour. MozReview-Commit-ID: JgGaQcNQfzz
dom/events/EventStateManager.cpp
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -638,33 +638,33 @@ EventStateManager::PreHandleEvent(nsPres
       mMClickCount = mouseEvent->mClickCount;
       SetClickCount(mouseEvent, aStatus);
       break;
     case WidgetMouseEvent::eRightButton:
       mRClickCount = mouseEvent->mClickCount;
       SetClickCount(mouseEvent, aStatus);
       break;
     }
+    NotifyTargetUserActivation(aEvent, aTargetContent);
     break;
   }
   case eMouseUp: {
     switch (mouseEvent->button) {
       case WidgetMouseEvent::eLeftButton:
         if (Prefs::ClickHoldContextMenu()) {
           KillClickHoldTimer();
         }
         StopTrackingDragGesture();
         sNormalLMouseEventInProcess = false;
         // then fall through...
         MOZ_FALLTHROUGH;
       case WidgetMouseEvent::eRightButton:
       case WidgetMouseEvent::eMiddleButton:
         RefPtr<EventStateManager> esm = ESMFromContentOrThis(aOverrideClickTarget);
         esm->SetClickCount(mouseEvent, aStatus, aOverrideClickTarget);
-        NotifyTargetUserActivation(aEvent, aTargetContent);
         break;
     }
     break;
   }
   case eMouseEnterIntoWidget:
     // In some cases on e10s eMouseEnterIntoWidget
     // event was sent twice into child process of content.
     // (From specific widget code (sending is not permanent) and
@@ -709,16 +709,23 @@ EventStateManager::PreHandleEvent(nsPres
       aEvent->mMessage = eVoidEvent;
       break;
     }
     MOZ_FALLTHROUGH;
   case eMouseMove:
   case ePointerDown:
     if (aEvent->mMessage == ePointerDown) {
       PointerEventHandler::ImplicitlyCapturePointer(aTargetFrame, aEvent);
+#ifndef MOZ_WIDGET_ANDROID
+      // Pointer events aren't enabled on Android yet, but when they
+      // are enabled, we should not activate on pointerdown, as that
+      // fires for touches that turn into moves on Android, and we don't
+      // want to gesture activate for scroll actions.
+      NotifyTargetUserActivation(aEvent, aTargetContent);
+#endif
     }
     MOZ_FALLTHROUGH;
   case ePointerMove: {
     // on the Mac, GenerateDragGesture() may not return until the drag
     // has completed and so |aTargetFrame| may have been deleted (moving
     // a bookmark, for example).  If this is the case, however, we know
     // that ClearFrameRefs() has been called and it cleared out
     // |mCurrentTarget|. As a result, we should pass |mCurrentTarget|
@@ -789,16 +796,20 @@ EventStateManager::PreHandleEvent(nsPres
             *aStatus = nsEventStatus_eConsumeNoDefault;
           }
         }
       }
     }
     // then fall through...
     MOZ_FALLTHROUGH;
   case eKeyDown:
+    if (aEvent->mMessage == eKeyDown) {
+      NotifyTargetUserActivation(aEvent, aTargetContent);
+    }
+    MOZ_FALLTHROUGH;
   case eKeyUp:
     {
       nsIContent* content = GetFocusedContent();
       if (content)
         mCurrentTargetContent = content;
 
       // NOTE: Don't refer TextComposition::IsComposing() since UI Events
       //       defines that KeyboardEvent.isComposing is true when it's
@@ -818,19 +829,16 @@ EventStateManager::PreHandleEvent(nsPres
       // to reset it if the target (focused content) isn't in a remote process
       // because PresShell needs to check if it's marked as so before
       // dispatching events into the DOM tree.
       if (aEvent->IsWaitingReplyFromRemoteProcess() &&
           !aEvent->PropagationStopped() &&
           !IsRemoteTarget(content)) {
         aEvent->ResetWaitingReplyFromRemoteProcessState();
       }
-      if (aEvent->mMessage == eKeyUp) {
-        NotifyTargetUserActivation(aEvent, aTargetContent);
-      }
     }
     break;
   case eWheel:
   case eWheelOperationStart:
   case eWheelOperationEnd:
     {
       NS_ASSERTION(aEvent->IsTrusted(),
                    "Untrusted wheel event shouldn't be here");
@@ -916,18 +924,19 @@ EventStateManager::NotifyTargetUserActiv
     return;
   }
 
   nsIDocument* doc = node->OwnerDoc();
   if (!doc || doc->HasBeenUserActivated()) {
     return;
   }
 
-  MOZ_ASSERT(aEvent->mMessage == eKeyUp   ||
-             aEvent->mMessage == eMouseUp ||
+  MOZ_ASSERT(aEvent->mMessage == eKeyDown   ||
+             aEvent->mMessage == eMouseDown ||
+             aEvent->mMessage == ePointerDown ||
              aEvent->mMessage == eTouchEnd);
   doc->NotifyUserActivation();
 }
 
 already_AddRefed<EventStateManager>
 EventStateManager::ESMFromContentOrThis(nsIContent* aContent)
 {
   if (aContent) {