Bug 1223946 - Part 1: Clean up and support needed for converting WidgetWheelEvent to ScrollWheelInput. r=kats
authorRandall Barker <rbarker@mozilla.com>
Wed, 18 Nov 2015 19:32:37 -0500
changeset 307349 ffa10317f183b83b1c2936297a139e86e25ce39e
parent 307348 4bef6154547c446f8202c44fd6b80bf4ac9e52b2
child 307350 ca5fae7924d23616afaf3d625b5d10d5a79e6bfa
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1223946
milestone45.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 1223946 - Part 1: Clean up and support needed for converting WidgetWheelEvent to ScrollWheelInput. r=kats
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/util/APZThreadUtils.cpp
gfx/layers/apz/util/APZThreadUtils.h
layout/base/UnitTransforms.h
widget/InputData.cpp
widget/InputData.h
widget/cocoa/SwipeTracker.mm
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -998,17 +998,17 @@ APZCTreeManager::UpdateWheelTransaction(
    case eMouseMove:
    case eDragOver: {
      WidgetMouseEvent* mouseEvent = aEvent.AsMouseEvent();
      if (!mouseEvent->IsReal()) {
        return;
      }
 
      ScreenIntPoint point =
-       ViewAs<ScreenPixel>(aEvent.refPoint, PixelCastJustification::LayoutDeviceToScreenForUntransformedEvent);
+       ViewAs<ScreenPixel>(aEvent.refPoint, PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);
      txn->OnMouseMove(point);
      return;
    }
    case eKeyPress:
    case eKeyUp:
    case eKeyDown:
    case eMouseUp:
    case eMouseDown:
--- a/gfx/layers/apz/util/APZThreadUtils.cpp
+++ b/gfx/layers/apz/util/APZThreadUtils.cpp
@@ -93,12 +93,22 @@ APZThreadUtils::RunDelayedTaskOnCurrentT
     AndroidBridge::Bridge()->PostTaskToUiThread(aTask, aDelay.ToMilliseconds());
 #else
     // Other platforms should.
     MOZ_RELEASE_ASSERT(false, "This non-Fennec platform should have a MessageLoop::current()");
 #endif
   }
 }
 
+/*static*/ bool
+APZThreadUtils::IsControllerThread()
+{
+#ifdef MOZ_ANDROID_APZ
+  return AndroidBridge::IsJavaUiThread();
+#else
+  return sControllerThread == MessageLoop::current();
+#endif
+}
+
 NS_IMPL_ISUPPORTS(GenericTimerCallbackBase, nsITimerCallback)
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/apz/util/APZThreadUtils.h
+++ b/gfx/layers/apz/util/APZThreadUtils.h
@@ -52,16 +52,21 @@ public:
    */
   static void RunOnControllerThread(Task* aTask);
 
   /**
    * Runs the given task on the current thread after a delay of |aDelay|.
    */
   static void RunDelayedTaskOnCurrentThread(Task* aTask,
                                             const TimeDuration& aDelay);
+
+  /**
+   * Returns true if currently on APZ "controller thread".
+   */
+  static bool IsControllerThread();
 };
 
 // A base class for GenericTimerCallback<Function>.
 // This is necessary because NS_IMPL_ISUPPORTS doesn't work for a class
 // template.
 class GenericTimerCallbackBase : public nsITimerCallback
 {
 public:
--- a/layout/base/UnitTransforms.h
+++ b/layout/base/UnitTransforms.h
@@ -33,19 +33,20 @@ enum class PixelCastJustification : uint
   MovingDownToChildren,
   // The transform that is usually used to convert between two coordinate
   // systems is not available (for example, because the object that stores it
   // is being destroyed), so fall back to the identity.
   TransformNotAvailable,
   // When an OS event is initially constructed, its reference point is
   // technically in screen pixels, as it has not yet accounted for any
   // asynchronous transforms. This justification is for viewing the initial
-  // reference point as a screen point.
-  LayoutDeviceToScreenForUntransformedEvent,
-  // Similar to LayoutDeviceToScreenForUntransformedEvent, PBrowser handles
+  // reference point as a screen point. The reverse is useful when synthetically
+  // created WidgetEvents need to be converted back to InputData.
+  LayoutDeviceIsScreenForUntransformedEvent,
+  // Similar to LayoutDeviceIsScreenForUntransformedEvent, PBrowser handles
   // some widget/tab dimension information as the OS does -- in screen units.
   LayoutDeviceIsScreenForTabDims
 };
 
 template <class TargetUnits, class SourceUnits>
 gfx::SizeTyped<TargetUnits> ViewAs(const gfx::SizeTyped<SourceUnits>& aSize, PixelCastJustification) {
   return gfx::SizeTyped<TargetUnits>(aSize.width, aSize.height);
 }
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -115,19 +115,18 @@ MultiTouchInput::MultiTouchInput(const W
     // Extract data from weird interfaces.
     int32_t identifier = domTouch->Identifier();
     int32_t radiusX = domTouch->RadiusX();
     int32_t radiusY = domTouch->RadiusY();
     float rotationAngle = domTouch->RotationAngle();
     float force = domTouch->Force();
 
     SingleTouchData data(identifier,
-                         ScreenIntPoint::FromUnknownPoint(
-                           gfx::IntPoint(domTouch->mRefPoint.x,
-                                         domTouch->mRefPoint.y)),
+                         ViewAs<ScreenPixel>(domTouch->mRefPoint,
+                                             PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
                          ScreenSize(radiusX, radiusY),
                          rotationAngle,
                          force);
 
     mTouches.AppendElement(data);
   }
 }
 
@@ -258,19 +257,18 @@ MultiTouchInput::MultiTouchInput(const W
     mType = MULTITOUCH_CANCEL;
     break;
   default:
     NS_WARNING("Did not assign a type to a MultiTouchInput");
     break;
   }
 
   mTouches.AppendElement(SingleTouchData(0,
-                                         ScreenIntPoint::FromUnknownPoint(
-                                           gfx::IntPoint(aMouseEvent.refPoint.x,
-                                                         aMouseEvent.refPoint.y)),
+                                         ViewAs<ScreenPixel>(aMouseEvent.refPoint,
+                                                             PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
                                          ScreenSize(1, 1),
                                          180.0f,
                                          1.0f));
 }
 
 bool
 MultiTouchInput::TransformToLocal(const gfx::Matrix4x4& aTransform)
 {
@@ -301,17 +299,17 @@ WidgetWheelEvent
 PanGestureInput::ToWidgetWheelEvent(nsIWidget* aWidget) const
 {
   WidgetWheelEvent wheelEvent(true, eWheel, aWidget);
   wheelEvent.modifiers = this->modifiers;
   wheelEvent.time = mTime;
   wheelEvent.timeStamp = mTimeStamp;
   wheelEvent.refPoint =
     RoundedToInt(ViewAs<LayoutDevicePixel>(mPanStartPoint,
-      PixelCastJustification::LayoutDeviceToScreenForUntransformedEvent));
+      PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
   wheelEvent.buttons = 0;
   wheelEvent.deltaMode = nsIDOMWheelEvent::DOM_DELTA_PIXEL;
   wheelEvent.isMomentum = IsMomentum();
   wheelEvent.lineOrPageDeltaX = mLineOrPageDeltaX;
   wheelEvent.lineOrPageDeltaY = mLineOrPageDeltaY;
   wheelEvent.deltaX = mPanDisplacement.x;
   wheelEvent.deltaY = mPanDisplacement.y;
   wheelEvent.mFlags.mHandledByAPZ = mHandledByAPZ;
@@ -364,26 +362,42 @@ DeltaModeForDeltaType(ScrollWheelInput::
     case ScrollWheelInput::SCROLLDELTA_LINE:
       return nsIDOMWheelEvent::DOM_DELTA_LINE;
     case ScrollWheelInput::SCROLLDELTA_PIXEL:
     default:
       return nsIDOMWheelEvent::DOM_DELTA_PIXEL;
   }
 }
 
+ScrollWheelInput::ScrollWheelInput(const WidgetWheelEvent& aWheelEvent) :
+  InputData(SCROLLWHEEL_INPUT, aWheelEvent.time, aWheelEvent.timeStamp, aWheelEvent.modifiers),
+  mDeltaType(DeltaTypeForDeltaMode(aWheelEvent.deltaMode)),
+  mScrollMode(SCROLLMODE_INSTANT),
+  mHandledByAPZ(aWheelEvent.mFlags.mHandledByAPZ),
+  mDeltaX(aWheelEvent.deltaX),
+  mDeltaY(aWheelEvent.deltaY),
+  mLineOrPageDeltaX(aWheelEvent.lineOrPageDeltaX),
+  mLineOrPageDeltaY(aWheelEvent.lineOrPageDeltaY),
+  mIsMomentum(aWheelEvent.isMomentum)
+{
+  mOrigin =
+    ScreenPoint(ViewAs<ScreenPixel>(aWheelEvent.refPoint,
+      PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
+}
+
 WidgetWheelEvent
 ScrollWheelInput::ToWidgetWheelEvent(nsIWidget* aWidget) const
 {
   WidgetWheelEvent wheelEvent(true, eWheel, aWidget);
   wheelEvent.modifiers = this->modifiers;
   wheelEvent.time = mTime;
   wheelEvent.timeStamp = mTimeStamp;
   wheelEvent.refPoint =
     RoundedToInt(ViewAs<LayoutDevicePixel>(mOrigin,
-      PixelCastJustification::LayoutDeviceToScreenForUntransformedEvent));
+      PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent));
   wheelEvent.buttons = 0;
   wheelEvent.deltaMode = DeltaModeForDeltaType(mDeltaType);
   wheelEvent.isMomentum = mIsMomentum;
   wheelEvent.deltaX = mDeltaX;
   wheelEvent.deltaY = mDeltaY;
   wheelEvent.lineOrPageDeltaX = mLineOrPageDeltaX;
   wheelEvent.lineOrPageDeltaY = mLineOrPageDeltaY;
   wheelEvent.mFlags.mHandledByAPZ = mHandledByAPZ;
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -577,16 +577,18 @@ public:
      mHandledByAPZ(false),
      mDeltaX(aDeltaX),
      mDeltaY(aDeltaY),
      mLineOrPageDeltaX(0),
      mLineOrPageDeltaY(0),
      mIsMomentum(false)
   {}
 
+  explicit ScrollWheelInput(const WidgetWheelEvent& aEvent);
+
   WidgetWheelEvent ToWidgetWheelEvent(nsIWidget* aWidget) const;
   bool TransformToLocal(const gfx::Matrix4x4& aTransform);
 
   ScrollDeltaType mDeltaType;
   ScrollMode mScrollMode;
   ScreenPoint mOrigin;
 
   bool mHandledByAPZ;
--- a/widget/cocoa/SwipeTracker.mm
+++ b/widget/cocoa/SwipeTracker.mm
@@ -36,17 +36,17 @@ GetRefreshDriver(nsIWidget& aWidget)
 SwipeTracker::SwipeTracker(nsChildView& aWidget,
                            const PanGestureInput& aSwipeStartEvent,
                            uint32_t aAllowedDirections,
                            uint32_t aSwipeDirection)
   : mWidget(aWidget)
   , mRefreshDriver(GetRefreshDriver(mWidget))
   , mAxis(0.0, 0.0, 0.0, kSpringForce, 1.0)
   , mEventPosition(RoundedToInt(ViewAs<LayoutDevicePixel>(aSwipeStartEvent.mPanStartPoint,
-                                  PixelCastJustification::LayoutDeviceToScreenForUntransformedEvent)))
+                                  PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent)))
   , mLastEventTimeStamp(aSwipeStartEvent.mTimeStamp)
   , mAllowedDirections(aAllowedDirections)
   , mSwipeDirection(aSwipeDirection)
   , mGestureAmount(0.0)
   , mCurrentVelocity(0.0)
   , mEventsAreControllingSwipe(true)
   , mEventsHaveStartedNewGesture(false)
   , mRegisteredWithRefreshDriver(false)