Bug 1365761 - Do not dispatch mouse-move events targeted as a slider frame to web content. r=smaug draft
authorBotond Ballo <botond@mozilla.com>
Mon, 05 Jun 2017 15:05:47 -0400
changeset 590322 30bd643922409f47eb2318938a07e7543337d625
parent 590321 fedaf1464966691c117ee76c5a2d1c4a60742c41
child 632189 64c835823f021c100e49e32168a822e4601b3d3a
push id62701
push userbballo@mozilla.com
push dateWed, 07 Jun 2017 16:30:43 +0000
reviewerssmaug
bugs1365761
milestone55.0a1
Bug 1365761 - Do not dispatch mouse-move events targeted as a slider frame to web content. r=smaug MozReview-Commit-ID: Cpi7orSO7dS
layout/base/PresShell.cpp
layout/generic/nsIFrame.h
layout/xul/nsSliderFrame.cpp
layout/xul/nsSliderFrame.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -8118,16 +8118,21 @@ PresShell::HandleEventInternal(WidgetEve
         nsContentUtils::IsHandlingKeyBoardEvent();
       if (aEvent->mClass == eKeyboardEventClass) {
         nsContentUtils::SetIsHandlingKeyBoardEvent(true);
       }
       if (aEvent->IsAllowedToDispatchDOMEvent()) {
         MOZ_ASSERT(nsContentUtils::IsSafeToRunScript(),
           "Somebody changed aEvent to cause a DOM event!");
         nsPresShellEventCB eventCB(this);
+        if (nsIFrame* target = GetCurrentEventFrame()) {
+          if (target->OnlySystemGroupDispatch(aEvent->mMessage)) {
+              aEvent->StopPropagation();
+          }
+        }
         if (aEvent->mClass == eTouchEventClass) {
           DispatchTouchEventToDOM(aEvent, aStatus, &eventCB, touchIsNew);
         } else {
           DispatchEventToDOM(aEvent, aStatus, &eventCB);
         }
       }
 
       nsContentUtils::SetIsHandlingKeyBoardEvent(wasHandlingKeyBoardEvent);
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -2583,16 +2583,23 @@ public:
   /**
    * Returns true if the frame contains any non-collapsed characters.
    * This method is only available for text frames, and it will return false
    * for all other frame types.
    */
   virtual bool HasAnyNoncollapsedCharacters()
   { return false; }
 
+  /**
+   * Returns true if events of the given type targeted at this frame
+   * should only be dispatched to the system group.
+   */
+  virtual bool OnlySystemGroupDispatch(mozilla::EventMessage aMessage) const
+  { return false; }
+
   //
   // Accessor functions to an associated view object:
   //
   bool HasView() const { return !!(mState & NS_FRAME_HAS_VIEW); }
 protected:
   virtual nsView* GetViewInternal() const
   {
     MOZ_ASSERT_UNREACHABLE("method should have been overridden by subclass");
--- a/layout/xul/nsSliderFrame.cpp
+++ b/layout/xul/nsSliderFrame.cpp
@@ -1633,10 +1633,19 @@ nsSliderFrame::UnsuppressDisplayport()
 {
   if (mSuppressionActive) {
     MOZ_ASSERT(PresContext()->PresShell());
     APZCCallbackHelper::SuppressDisplayport(false, PresContext()->PresShell());
     mSuppressionActive = false;
   }
 }
 
+bool
+nsSliderFrame::OnlySystemGroupDispatch(EventMessage aMessage) const
+{
+  // If we are in a native anonymous subtree, do not dispatch mouse-move events
+  // targeted at this slider frame to web content. This matches the behaviour
+  // of other browsers.
+  return aMessage == eMouseMove && GetContent()->IsInNativeAnonymousSubtree();
+}
+
 NS_IMPL_ISUPPORTS(nsSliderMediator,
                   nsIDOMEventListener)
--- a/layout/xul/nsSliderFrame.h
+++ b/layout/xul/nsSliderFrame.h
@@ -134,16 +134,18 @@ public:
   // scrolled frame.
   float GetThumbRatio() const;
 
   // Notify the slider frame than an async scrollbar drag requested in
   // StartAPZDrag() was rejected by APZ, and the slider frame should
   // fall back to main-thread dragging.
   void AsyncScrollbarDragRejected();
 
+  bool OnlySystemGroupDispatch(mozilla::EventMessage aMessage) const override;
+
 private:
 
   bool GetScrollToClick();
   nsIFrame* GetScrollbar();
   bool ShouldScrollForEvent(mozilla::WidgetGUIEvent* aEvent);
   bool ShouldScrollToClickForEvent(mozilla::WidgetGUIEvent* aEvent);
   bool IsEventOverThumb(mozilla::WidgetGUIEvent* aEvent);