Use stronger typing for GetScrollWheelDelta. (bug 1139220 part 5, r=kats)
authorDavid Anderson <danderson@mozilla.com>
Wed, 01 Apr 2015 23:43:24 -0700
changeset 237523 5c982f0795decc99890aac978217f4216b23745c
parent 237522 e34a66a053da001113b866919fc51b5c7d1345f5
child 237524 890e0a621055c31b1cdfec1015fcfc0865a2b4e0
push id57962
push userdanderson@mozilla.com
push dateFri, 03 Apr 2015 05:40:15 +0000
treeherdermozilla-inbound@5c982f0795de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1139220
milestone40.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
Use stronger typing for GetScrollWheelDelta. (bug 1139220 part 5, r=kats)
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -1411,73 +1411,70 @@ AsyncPanZoomController::ConvertToGecko(c
       ReentrantMonitorAutoEnter lock(mMonitor);
       *aOut = layoutPoint / mFrameMetrics.GetDevPixelsPerCSSPixel();
     }
     return true;
   }
   return false;
 }
 
-void
-AsyncPanZoomController::GetScrollWheelDelta(const ScrollWheelInput& aEvent,
-                                            double& aOutDeltaX,
-                                            double& aOutDeltaY) const
+LayoutDevicePoint
+AsyncPanZoomController::GetScrollWheelDelta(const ScrollWheelInput& aEvent) const
 {
   ReentrantMonitorAutoEnter lock(mMonitor);
 
-  aOutDeltaX = aEvent.mDeltaX;
-  aOutDeltaY = aEvent.mDeltaY;
+  LayoutDevicePoint delta(aEvent.mDeltaX, aEvent.mDeltaY);
   switch (aEvent.mDeltaType) {
     case ScrollWheelInput::SCROLLDELTA_LINE: {
       LayoutDeviceIntSize scrollAmount = mFrameMetrics.GetLineScrollAmount();
-      aOutDeltaX *= scrollAmount.width;
-      aOutDeltaY *= scrollAmount.height;
+      delta.x *= scrollAmount.width;
+      delta.y *= scrollAmount.height;
       break;
     }
     default:
       MOZ_ASSERT_UNREACHABLE("unexpected scroll delta type");
   }
 
   if (gfxPrefs::MouseWheelHasRootScrollDeltaOverride()) {
     // Only apply delta multipliers if we're increasing the delta.
     double hfactor = double(gfxPrefs::MouseWheelRootHScrollDeltaFactor()) / 100;
     double vfactor = double(gfxPrefs::MouseWheelRootVScrollDeltaFactor()) / 100;
     if (vfactor > 1.0) {
-      aOutDeltaX *= hfactor;
+      delta.x *= hfactor;
     }
     if (hfactor > 1.0) {
-      aOutDeltaY *= vfactor;
+      delta.y *= vfactor;
     }
   }
 
   LayoutDeviceIntSize pageScrollSize = mFrameMetrics.GetPageScrollAmount();
-  if (Abs(aOutDeltaX) > pageScrollSize.width) {
-    aOutDeltaX = (aOutDeltaX >= 0)
-                 ? pageScrollSize.width
-                 : -pageScrollSize.width;
+  if (Abs(delta.x) > pageScrollSize.width) {
+    delta.x = (delta.x >= 0)
+              ? pageScrollSize.width
+              : -pageScrollSize.width;
   }
-  if (Abs(aOutDeltaY) > pageScrollSize.height) {
-    aOutDeltaY = (aOutDeltaY >= 0)
-                 ? pageScrollSize.height
-                 : -pageScrollSize.height;
+  if (Abs(delta.y) > pageScrollSize.height) {
+    delta.y = (delta.y >= 0)
+              ? pageScrollSize.height
+              : -pageScrollSize.height;
   }
+
+  return delta;
 }
 
 // Return whether or not the underlying layer can be scrolled on either axis.
 bool
 AsyncPanZoomController::CanScroll(const ScrollWheelInput& aEvent) const
 {
-  double deltaX, deltaY;
-  GetScrollWheelDelta(aEvent, deltaX, deltaY);
-
-  if (!deltaX && !deltaY) {
+  LayoutDevicePoint delta = GetScrollWheelDelta(aEvent);
+  if (!delta.x && !delta.y) {
     return false;
   }
 
-  return CanScroll(deltaX, deltaY);
+  return CanScroll(delta.x, delta.y);
 }
 
 bool
 AsyncPanZoomController::CanScroll(double aDeltaX, double aDeltaY) const
 {
   ReentrantMonitorAutoEnter lock(mMonitor);
   return mX.CanScroll(aDeltaX) || mY.CanScroll(aDeltaY);
 }
@@ -1486,21 +1483,20 @@ bool
 AsyncPanZoomController::AllowScrollHandoffInWheelTransaction() const
 {
   WheelBlockState* block = mInputQueue->CurrentWheelBlock();
   return block->AllowScrollHandoff();
 }
 
 nsEventStatus AsyncPanZoomController::OnScrollWheel(const ScrollWheelInput& aEvent)
 {
-  double deltaX, deltaY;
-  GetScrollWheelDelta(aEvent, deltaX, deltaY);
-
-  if ((deltaX || deltaY) &&
-      !CanScroll(deltaX, deltaY) &&
+  LayoutDevicePoint delta = GetScrollWheelDelta(aEvent);
+
+  if ((delta.x || delta.y) &&
+      !CanScroll(delta.x, delta.y) &&
       mInputQueue->GetCurrentWheelTransaction())
   {
     // We can't scroll this apz anymore, so we simply drop the event.
     if (gfxPrefs::MouseScrollTestingEnabled()) {
       if (nsRefPtr<GeckoContentController> controller = GetGeckoContentController()) {
         controller->NotifyMozMouseScrollEvent(
           mFrameMetrics.GetScrollId(),
           NS_LITERAL_STRING("MozMouseScrollFailed"));
@@ -1516,26 +1512,25 @@ nsEventStatus AsyncPanZoomController::On
                             aEvent.mOrigin, ScreenPoint(0, 0), aEvent.modifiers);
       start.mLocalPanStartPoint = aEvent.mLocalOrigin;
       OnPanBegin(start);
 
       // Pan gestures use natural directions which are inverted from scroll
       // wheel and touchpad scroll gestures, so we invert x/y here. Since the
       // zoom includes any device : css pixel zoom, we convert to CSS pixels
       // before applying the zoom.
-      LayoutDevicePoint devicePixelDelta(-deltaX, -deltaY);
-      ParentLayerPoint delta = (devicePixelDelta / mFrameMetrics.GetDevPixelsPerCSSPixel()) *
+      ParentLayerPoint panDelta = (-delta / mFrameMetrics.GetDevPixelsPerCSSPixel()) *
                                mFrameMetrics.GetZoom();
 
       PanGestureInput move(PanGestureInput::PANGESTURE_PAN, aEvent.mTime, aEvent.mTimeStamp,
                            aEvent.mOrigin,
-                           ToScreenCoordinates(delta, aEvent.mLocalOrigin),
+                           ToScreenCoordinates(panDelta, aEvent.mLocalOrigin),
                            aEvent.modifiers);
       move.mLocalPanStartPoint = aEvent.mLocalOrigin;
-      move.mLocalPanDisplacement = delta;
+      move.mLocalPanDisplacement = panDelta;
       OnPan(move, ScrollSource::Wheel, false);
 
       PanGestureInput end(PanGestureInput::PANGESTURE_END, aEvent.mTime, aEvent.mTimeStamp,
                             aEvent.mOrigin, ScreenPoint(0, 0), aEvent.modifiers);
       end.mLocalPanStartPoint = aEvent.mLocalOrigin;
       OnPanEnd(start);
       break;
     }
@@ -1548,23 +1543,23 @@ nsEventStatus AsyncPanZoomController::On
         nsPoint initialPosition = CSSPoint::ToAppUnits(mFrameMetrics.GetScrollOffset());
         StartAnimation(new WheelScrollAnimation(
           *this,
           initialPosition));
       }
 
       // Cast velocity from ParentLayerPoints/ms to CSSPoints/ms then convert to
       // appunits/second
-      nsPoint delta =
-        CSSPoint::ToAppUnits(LayoutDevicePoint(deltaX, deltaY) / mFrameMetrics.GetDevPixelsPerCSSPixel());
+      nsPoint deltaInAppUnits =
+        CSSPoint::ToAppUnits(delta / mFrameMetrics.GetDevPixelsPerCSSPixel());
       nsPoint velocity =
         CSSPoint::ToAppUnits(CSSPoint(mX.GetVelocity(), mY.GetVelocity())) * 1000.0f;
 
       WheelScrollAnimation* animation = mAnimation->AsWheelScrollAnimation();
-      animation->Update(aEvent.mTimeStamp, delta, nsSize(velocity.x, velocity.y));
+      animation->Update(aEvent.mTimeStamp, deltaInAppUnits, nsSize(velocity.x, velocity.y));
       break;
     }
   }
 
   return nsEventStatus_eConsumeNoDefault;
 }
 
 void
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -429,19 +429,17 @@ protected:
   nsEventStatus OnPanMomentumStart(const PanGestureInput& aEvent);
   nsEventStatus OnPanMomentumEnd(const PanGestureInput& aEvent);
 
   /**
    * Helper methods for handling scroll wheel events.
    */
   nsEventStatus OnScrollWheel(const ScrollWheelInput& aEvent);
 
-  void GetScrollWheelDelta(const ScrollWheelInput& aEvent,
-                           double& aOutDeltaX,
-                           double& aOutDeltaY) const;
+  LayoutDevicePoint GetScrollWheelDelta(const ScrollWheelInput& aEvent) const;
 
   /**
    * Helper methods for long press gestures.
    */
   nsEventStatus OnLongPress(const TapGestureInput& aEvent);
   nsEventStatus OnLongPressUp(const TapGestureInput& aEvent);
 
   /**