Bug 657865 High resolution scrolling should be able to be disabled by pref r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 19 May 2011 08:12:16 +0900
changeset 69681 6424f0d08d6ed7f24aa93320f6778645c5794d69
parent 69680 659100d227581e967519f57b9a52014a167d2288
child 69682 b8a035ebdf0f6c6eb6a5c203cf0ec4346cc5c140
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs657865
milestone6.0a1
Bug 657865 High resolution scrolling should be able to be disabled by pref r=smaug
modules/libpref/src/init/all.js
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindow.h
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -1106,19 +1106,16 @@ pref("middlemouse.scrollbarPosition", fa
 // Clipboard behavior
 pref("clipboard.autocopy", false);
 
 // mouse wheel scroll transaction period of time (in milliseconds)
 pref("mousewheel.transaction.timeout", 1500);
 // mouse wheel scroll transaction is held even if the mouse cursor is moved.
 pref("mousewheel.transaction.ignoremovedelay", 100);
 
-// Macbook touchpad two finger pixel scrolling
-pref("mousewheel.enable_pixel_scrolling", true);
-
 // prefs for app level mouse wheel scrolling acceleration.
 // number of mousewheel clicks when acceleration starts
 // acceleration can be turned off if pref is set to -1
 pref("mousewheel.acceleration.start", -1);
 // factor to be multiplied for constant acceleration
 pref("mousewheel.acceleration.factor", 10);
 
 // Prefs for override the system mouse wheel scrolling speed on the root
@@ -1847,16 +1844,19 @@ pref("intl.tsf.on_layout_change_interval
 pref("ui.panel.default_level_parent", true);
 #else
 // See bug 448927, on topmost panel, some IMEs are not usable on Windows.
 pref("ui.panel.default_level_parent", false);
 #endif
 
 pref("mousewheel.system_scroll_override_on_root_content.enabled", true);
 
+// High resolution scrolling with supported mouse drivers on Vista or later.
+pref("mousewheel.enable_pixel_scrolling", false);
+
 // If your mouse drive sends WM_*SCROLL messages when you turn your mouse wheel,
 // set this to true.  Then, gecko processes them as mouse wheel messages.
 pref("mousewheel.emulate_at_wm_scroll", false);
 
 // Enables or disabled the TrackPoint hack, -1 is autodetect, 0 is off,
 // and 1 is on.  Set this to 1 if TrackPoint scrolling is not working.
 pref("ui.trackpoint_hack.enabled", -1);
 
@@ -2295,16 +2295,19 @@ pref("print.print_extra_margin", 90); //
 
 // See bug 404131, topmost <panel> element wins to Dashboard on MacOSX.
 pref("ui.panel.default_level_parent", false);
 
 pref("ui.plugin.cancel_composition_at_input_source_changed", false);
 
 pref("mousewheel.system_scroll_override_on_root_content.enabled", false);
 
+// Macbook touchpad two finger pixel scrolling
+pref("mousewheel.enable_pixel_scrolling", true);
+
 # XP_MACOSX
 #endif
 
 #ifdef XP_OS2
 
 pref("ui.key.menuAccessKeyFocuses", true);
 
 pref("font.alias-list", "sans,sans-serif,serif,monospace,Tms Rmn,Helv,Courier,Times New Roman");
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -293,16 +293,17 @@ LPFNLRESULTFROMOBJECT
 
 // Used in OOPP plugin focus processing.
 const PRUnichar* kOOPPPluginFocusEventId   = L"OOPP Plugin Focus Widget Event";
 PRUint32        nsWindow::sOOPPPluginFocusEvent   =
                   RegisterWindowMessageW(kOOPPPluginFocusEventId);
 
 MSG             nsWindow::sRedirectedKeyDown;
 
+PRBool          nsWindow::sEnablePixelScrolling = PR_TRUE;
 PRBool          nsWindow::sNeedsToInitMouseWheelSettings = PR_TRUE;
 ULONG           nsWindow::sMouseWheelScrollLines  = 0;
 ULONG           nsWindow::sMouseWheelScrollChars  = 0;
 
 HWND            nsWindow::sLastMouseWheelWnd = NULL;
 PRInt32         nsWindow::sRemainingDeltaForScroll = 0;
 PRInt32         nsWindow::sRemainingDeltaForPixel = 0;
 PRBool          nsWindow::sLastMouseWheelDeltaIsPositive = PR_FALSE;
@@ -662,16 +663,21 @@ nsWindow::Create(nsIWidget *aParent,
 
         if (NS_SUCCEEDED(prefBranch->GetBoolPref("intl.keyboard.per_window_layout",
                                                  &temp)))
           sSwitchKeyboardLayout = temp;
 
         if (NS_SUCCEEDED(prefBranch->GetBoolPref("mozilla.widget.disable-native-theme",
                                                  &temp)))
           gDisableNativeTheme = temp;
+
+        if (NS_SUCCEEDED(prefBranch->GetBoolPref("mousewheel.enable_pixel_scrolling",
+                                                 &temp))) {
+          sEnablePixelScrolling = temp;
+        }
       }
     }
   }
 
   return NS_OK;
 }
 
 // Close this nsWindow
@@ -6406,37 +6412,43 @@ nsWindow::OnMouseWheel(UINT aMessage, WP
     ResetRemainingWheelDelta();
   }
   sLastMouseWheelWnd = mWnd;
   sLastMouseWheelDeltaIsPositive = (nativeDelta > 0);
   sLastMouseWheelOrientationIsVertical = isVertical;
   sLastMouseWheelUnitIsPage = isPageScroll;
   sLastMouseWheelTime = now;
 
-  nsMouseScrollEvent testEvent(PR_TRUE, NS_MOUSE_SCROLL, this);
-  InitEvent(testEvent);
-  testEvent.scrollFlags = isPageScroll ? nsMouseScrollEvent::kIsFullPage : 0;
-  testEvent.scrollFlags |= isVertical ? nsMouseScrollEvent::kIsVertical :
-                                        nsMouseScrollEvent::kIsHorizontal;
-  testEvent.delta = sLastMouseWheelDeltaIsPositive ? -1 : 1;
-  nsQueryContentEvent queryEvent(PR_TRUE, NS_QUERY_SCROLL_TARGET_INFO, this);
-  InitEvent(queryEvent);
-  queryEvent.InitForQueryScrollTargetInfo(&testEvent);
-  DispatchWindowEvent(&queryEvent);
-  // If the necessary interger isn't larger than 0, we should assume that
-  // the event failed for us.
-  if (queryEvent.mSucceeded) {
-    if (isPageScroll) {
-      if (isVertical) {
-        queryEvent.mSucceeded = (queryEvent.mReply.mPageHeight > 0);
+  PRBool dispatchPixelScrollEvent = PR_FALSE;
+  PRInt32 pixelsPerUnit = 0;
+
+  if (sEnablePixelScrolling) {
+    nsMouseScrollEvent testEvent(PR_TRUE, NS_MOUSE_SCROLL, this);
+    InitEvent(testEvent);
+    testEvent.scrollFlags = isPageScroll ? nsMouseScrollEvent::kIsFullPage : 0;
+    testEvent.scrollFlags |= isVertical ? nsMouseScrollEvent::kIsVertical :
+                                          nsMouseScrollEvent::kIsHorizontal;
+    testEvent.delta = sLastMouseWheelDeltaIsPositive ? -1 : 1;
+    nsQueryContentEvent queryEvent(PR_TRUE, NS_QUERY_SCROLL_TARGET_INFO, this);
+    InitEvent(queryEvent);
+    queryEvent.InitForQueryScrollTargetInfo(&testEvent);
+    DispatchWindowEvent(&queryEvent);
+    // If the necessary interger isn't larger than 0, we should assume that
+    // the event failed for us.
+    if (queryEvent.mSucceeded) {
+      if (isPageScroll) {
+        if (isVertical) {
+          pixelsPerUnit = queryEvent.mReply.mPageHeight;
+        } else {
+          pixelsPerUnit = queryEvent.mReply.mPageWidth;
+        }
       } else {
-        queryEvent.mSucceeded = (queryEvent.mReply.mPageWidth > 0);
+        pixelsPerUnit = queryEvent.mReply.mLineHeight;
       }
-    } else {
-      queryEvent.mSucceeded = (queryEvent.mReply.mLineHeight > 0);
+      dispatchPixelScrollEvent = (pixelsPerUnit > 0);
     }
   }
 
   *aRetValue = isVertical ? FALSE : TRUE; // means we process this message
   nsModifierKeyState modKeyState;
 
   // Our positive delta value means to bottom or right.
   // But positive nativeDelta value means to top or right.
@@ -6451,19 +6463,18 @@ nsWindow::OnMouseWheel(UINT aMessage, WP
       static_cast<DWORD>(::GetMessageTime()) < mAssumeWheelIsZoomUntil) {
     isControl = PR_TRUE;
   } else {
     isControl = modKeyState.mIsControlDown;
   }
 
   nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this);
   InitEvent(scrollEvent);
-  // If the query event failed, we cannot send pixel events.
   scrollEvent.scrollFlags =
-    queryEvent.mSucceeded ? nsMouseScrollEvent::kHasPixels : 0;
+    dispatchPixelScrollEvent ? nsMouseScrollEvent::kHasPixels : 0;
   scrollEvent.isShift     = modKeyState.mIsShiftDown;
   scrollEvent.isControl   = isControl;
   scrollEvent.isMeta      = PR_FALSE;
   scrollEvent.isAlt       = modKeyState.mIsAltDown;
 
   PRInt32 nativeDeltaForScroll = nativeDelta + sRemainingDeltaForScroll;
 
   if (isPageScroll) {
@@ -6496,17 +6507,17 @@ nsWindow::OnMouseWheel(UINT aMessage, WP
     aHandled = DispatchWindowEvent(&scrollEvent);
     if (mOnDestroyCalled) {
       ResetRemainingWheelDelta();
       return PR_FALSE;
     }
   }
 
   // If the query event failed, we cannot send pixel events.
-  if (!queryEvent.mSucceeded) {
+  if (!dispatchPixelScrollEvent) {
     sRemainingDeltaForPixel = 0;
     return PR_FALSE;
   }
 
   nsMouseScrollEvent pixelEvent(PR_TRUE, NS_MOUSE_PIXEL_SCROLL, this);
   InitEvent(pixelEvent);
   pixelEvent.scrollFlags = nsMouseScrollEvent::kAllowSmoothScroll |
     (scrollEvent.scrollFlags & ~nsMouseScrollEvent::kHasPixels);
@@ -6514,28 +6525,24 @@ nsWindow::OnMouseWheel(UINT aMessage, WP
   pixelEvent.isControl   = modKeyState.mIsControlDown;
   pixelEvent.isMeta      = PR_FALSE;
   pixelEvent.isAlt       = modKeyState.mIsAltDown;
 
   PRInt32 nativeDeltaForPixel = nativeDelta + sRemainingDeltaForPixel;
 
   double deltaPerPixel;
   if (isPageScroll) {
-    if (isVertical) {
-      deltaPerPixel = (double)WHEEL_DELTA / queryEvent.mReply.mPageHeight;
-    } else {
-      deltaPerPixel = (double)WHEEL_DELTA / queryEvent.mReply.mPageWidth;
-    }
+    deltaPerPixel = (double)WHEEL_DELTA / pixelsPerUnit;
   } else {
     if (isVertical) {
       deltaPerPixel = (double)WHEEL_DELTA / sMouseWheelScrollLines;
     } else {
       deltaPerPixel = (double)WHEEL_DELTA / sMouseWheelScrollChars;
     }
-    deltaPerPixel /= queryEvent.mReply.mLineHeight;
+    deltaPerPixel /= pixelsPerUnit;
   }
   pixelEvent.delta =
     RoundDelta((double)nativeDeltaForPixel * orienter / deltaPerPixel);
   PRInt32 recomputedNativeDelta =
     (PRInt32)(pixelEvent.delta * orienter * deltaPerPixel);
   sRemainingDeltaForPixel = nativeDeltaForPixel - recomputedNativeDelta;
   if (pixelEvent.delta != 0) {
     aHandled = DispatchWindowEvent(&pixelEvent);
--- a/widget/src/windows/nsWindow.h
+++ b/widget/src/windows/nsWindow.h
@@ -611,16 +611,17 @@ protected:
   static HINSTANCE      sAccLib;
   static LPFNLRESULTFROMOBJECT sLresultFromObject;
 #endif // ACCESSIBILITY
 
   // sRedirectedKeyDown is WM_KEYDOWN message or WM_SYSKEYDOWN message which
   // was reirected to SendInput() API by OnKeyDown().
   static MSG            sRedirectedKeyDown;
 
+  static PRBool sEnablePixelScrolling;
   static PRBool sNeedsToInitMouseWheelSettings;
   static ULONG sMouseWheelScrollLines;
   static ULONG sMouseWheelScrollChars;
   static void InitMouseWheelScrollData();
 
   static HWND sLastMouseWheelWnd;
   static PRInt32 sRemainingDeltaForScroll;
   static PRInt32 sRemainingDeltaForPixel;