Bug 1446724 - Lets plugins still receive original delta values instead of horizontalized values if the default action for wheel scrolling is to horizontalize vertical wheel scrolling. ?masayuki draft
authorZhang Junzhi <zjz@zjz.name>
Sun, 18 Mar 2018 17:10:32 +0800
changeset 769079 22250abba75239b92e5b0b9fce00254fac481963
parent 769029 efce78e62b6dac195e7cb4898684da54155d1661
push id103032
push userbmo:zjz@zjz.name
push dateSun, 18 Mar 2018 09:11:06 +0000
bugs1446724
milestone61.0a1
Bug 1446724 - Lets plugins still receive original delta values instead of horizontalized values if the default action for wheel scrolling is to horizontalize vertical wheel scrolling. ?masayuki Unlike a DOM wheel event listeners which receive original delta values, plugins receive horizontalized ones. However, the result for the plugin isn't quite reasonable. Plugin developers can do any delta adjustment if they want, because they are capable of DIRECTLY getting what IO the user is manipulating; conversely, they aren't capable of getting what delta adjustment their upstream has already encapsulated for them. So we need to restore adjusted delta values to the original for plugins. MozReview-Commit-ID: 8YQq1bTaRFx
dom/events/EventStateManager.cpp
dom/events/WheelHandlingHelper.cpp
dom/events/WheelHandlingHelper.h
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -3374,16 +3374,18 @@ EventStateManager::PostHandleEvent(nsPre
       // because if the scroll target is a plugin, the default action should be
       // chosen by the plugin rather than by our prefs.
       nsIFrame* frameToScroll =
         ComputeScrollTarget(mCurrentTarget, wheelEvent,
                             COMPUTE_DEFAULT_ACTION_TARGET);
       nsPluginFrame* pluginFrame = do_QueryFrame(frameToScroll);
       if (pluginFrame) {
         MOZ_ASSERT(pluginFrame->WantsToHandleWheelEventAsDefaultAction());
+        // Plugins should receive original values instead of adjusted values.
+        adjuster.CancelAdjustment();
         action = WheelPrefs::ACTION_SEND_TO_PLUGIN;
       }
 
       switch (action) {
         case WheelPrefs::ACTION_SCROLL:
         case WheelPrefs::ACTION_HORIZONTAL_SCROLL: {
           // For scrolling of default action, we should honor the mouse wheel
           // transaction.
--- a/dom/events/WheelHandlingHelper.cpp
+++ b/dom/events/WheelHandlingHelper.cpp
@@ -605,24 +605,30 @@ AutoWheelDeltaAdjuster::AutoWheelDeltaAd
     mWheelEvent.mOverflowDeltaY = 0.0;
     mWheelEvent.mLineOrPageDeltaX = mWheelEvent.mLineOrPageDeltaY;
     mWheelEvent.mLineOrPageDeltaY = 0;
     mWheelEvent.mDeltaValuesAdjustedForDefaultHandler = true;
     mTreatedVerticalWheelAsHorizontalScroll = true;
   }
 }
 
-AutoWheelDeltaAdjuster::~AutoWheelDeltaAdjuster()
+void AutoWheelDeltaAdjuster::CancelAdjustment()
 {
   if (mTreatedVerticalWheelAsHorizontalScroll &&
       mWheelEvent.mDeltaValuesAdjustedForDefaultHandler) {
     mWheelEvent.mDeltaY = mWheelEvent.mDeltaX;
     mWheelEvent.mDeltaX = mOldDeltaX;
     mWheelEvent.mDeltaZ = mOldDeltaZ;
     mWheelEvent.mOverflowDeltaY = mWheelEvent.mOverflowDeltaX;
     mWheelEvent.mOverflowDeltaX = mOldOverflowDeltaX;
     mWheelEvent.mLineOrPageDeltaY = mWheelEvent.mLineOrPageDeltaX;
     mWheelEvent.mLineOrPageDeltaX = mOldLineOrPageDeltaX;
     mWheelEvent.mDeltaValuesAdjustedForDefaultHandler = false;
+    mTreatedVerticalWheelAsHorizontalScroll = false;
   }
 }
 
+AutoWheelDeltaAdjuster::~AutoWheelDeltaAdjuster()
+{
+  CancelAdjustment();
+}
+
 } // namespace mozilla
--- a/dom/events/WheelHandlingHelper.h
+++ b/dom/events/WheelHandlingHelper.h
@@ -224,16 +224,17 @@ public:
    *                           modified for default handler.
    *                           Its mDeltaValuesAdjustedForDefaultHandler
    *                           must not be true because if it's true,
    *                           the event has already been adjusted the
    *                           delta values for default handler.
    */
   explicit AutoWheelDeltaAdjuster(WidgetWheelEvent& aWheelEvent);
   ~AutoWheelDeltaAdjuster();
+  void CancelAdjustment();
 
 private:
   WidgetWheelEvent& mWheelEvent;
   double mOldDeltaX;
   double mOldDeltaZ;
   double mOldOverflowDeltaX;
   int32_t mOldLineOrPageDeltaX;
   bool mTreatedVerticalWheelAsHorizontalScroll;