diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index 73c2e94c1b56..669056645bc0 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -1900,6 +1900,7 @@ void APZCTreeManager::SynthesizePinchGestureFromMouseWheel( PinchGestureInput pinchStart{PinchGestureInput::PINCHGESTURE_START, aWheelInput.mTime, aWheelInput.mTimeStamp, + ExternalPoint(0, 0), focusPoint, oldSpan, oldSpan, @@ -1907,6 +1908,7 @@ void APZCTreeManager::SynthesizePinchGestureFromMouseWheel( PinchGestureInput pinchScale1{PinchGestureInput::PINCHGESTURE_SCALE, aWheelInput.mTime, aWheelInput.mTimeStamp, + ExternalPoint(0, 0), focusPoint, oldSpan, oldSpan, @@ -1914,6 +1916,7 @@ void APZCTreeManager::SynthesizePinchGestureFromMouseWheel( PinchGestureInput pinchScale2{PinchGestureInput::PINCHGESTURE_SCALE, aWheelInput.mTime, aWheelInput.mTimeStamp, + ExternalPoint(0, 0), focusPoint, oldSpan, newSpan, @@ -1922,6 +1925,7 @@ void APZCTreeManager::SynthesizePinchGestureFromMouseWheel( PinchGestureInput::PINCHGESTURE_END, aWheelInput.mTime, aWheelInput.mTimeStamp, + ExternalPoint(0, 0), PinchGestureInput::BothFingersLifted(), newSpan, newSpan, diff --git a/gfx/layers/apz/src/APZUtils.h b/gfx/layers/apz/src/APZUtils.h index ce2341341392..7712f3485b06 100644 --- a/gfx/layers/apz/src/APZUtils.h +++ b/gfx/layers/apz/src/APZUtils.h @@ -18,6 +18,29 @@ #include "mozilla/FloatingPoint.h" namespace mozilla { + +struct ExternalPixel; + +template <> +struct IsPixel : TrueType {}; + +typedef gfx::CoordTyped ExternalCoord; +typedef gfx::IntCoordTyped ExternalIntCoord; +typedef gfx::PointTyped ExternalPoint; +typedef gfx::IntPointTyped ExternalIntPoint; +typedef gfx::SizeTyped ExternalSize; +typedef gfx::IntSizeTyped ExternalIntSize; +typedef gfx::RectTyped ExternalRect; +typedef gfx::IntRectTyped ExternalIntRect; +typedef gfx::MarginTyped ExternalMargin; +typedef gfx::IntMarginTyped ExternalIntMargin; +typedef gfx::IntRegionTyped ExternalIntRegion; + +typedef gfx::Matrix4x4Typed + ExternalToParentLayerMatrix4x4; + +struct ExternalPixel {}; + namespace layers { class AsyncPanZoomController; diff --git a/gfx/layers/apz/src/GestureEventListener.cpp b/gfx/layers/apz/src/GestureEventListener.cpp index 63ef130a77c9..fae21aaec052 100644 --- a/gfx/layers/apz/src/GestureEventListener.cpp +++ b/gfx/layers/apz/src/GestureEventListener.cpp @@ -311,8 +311,8 @@ nsEventStatus GestureEventListener::HandleInputTouchMove() { PinchGestureInput pinchEvent( PinchGestureInput::PINCHGESTURE_START, mLastTouchInput.mTime, - mLastTouchInput.mTimeStamp, currentFocus, currentSpan, currentSpan, - mLastTouchInput.modifiers); + mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, + currentFocus, currentSpan, currentSpan, mLastTouchInput.modifiers); rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent); @@ -340,8 +340,8 @@ nsEventStatus GestureEventListener::HandleInputTouchMove() { SetState(GESTURE_PINCH); PinchGestureInput pinchEvent( PinchGestureInput::PINCHGESTURE_START, mLastTouchInput.mTime, - mLastTouchInput.mTimeStamp, currentFocus, currentSpan, currentSpan, - mLastTouchInput.modifiers); + mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, + currentFocus, currentSpan, currentSpan, mLastTouchInput.modifiers); rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent); } else { @@ -368,8 +368,9 @@ nsEventStatus GestureEventListener::HandleInputTouchMove() { PinchGestureInput pinchEvent( PinchGestureInput::PINCHGESTURE_SCALE, mLastTouchInput.mTime, - mLastTouchInput.mTimeStamp, GetCurrentFocus(mLastTouchInput), - currentSpan, mPreviousSpan, mLastTouchInput.modifiers); + mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, + GetCurrentFocus(mLastTouchInput), currentSpan, mPreviousSpan, + mLastTouchInput.modifiers); rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent); mPreviousSpan = currentSpan; @@ -390,8 +391,9 @@ nsEventStatus GestureEventListener::HandleInputTouchMove() { PinchGestureInput pinchEvent( PinchGestureInput::PINCHGESTURE_SCALE, mLastTouchInput.mTime, - mLastTouchInput.mTimeStamp, currentFocus, effectiveSpan, - mPreviousSpan, mLastTouchInput.modifiers); + mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, + currentFocus, effectiveSpan, mPreviousSpan, + mLastTouchInput.modifiers); rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent); mPreviousSpan = effectiveSpan; @@ -472,10 +474,10 @@ nsEventStatus GestureEventListener::HandleInputTouchEnd() { // contain meaningful data. point = mTouches[0].mScreenPoint; } - PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_END, - mLastTouchInput.mTime, - mLastTouchInput.mTimeStamp, point, 1.0f, - 1.0f, mLastTouchInput.modifiers); + PinchGestureInput pinchEvent( + PinchGestureInput::PINCHGESTURE_END, mLastTouchInput.mTime, + mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, point, + 1.0f, 1.0f, mLastTouchInput.modifiers); mAsyncPanZoomController->HandleGestureEvent(pinchEvent); } @@ -486,10 +488,10 @@ nsEventStatus GestureEventListener::HandleInputTouchEnd() { case GESTURE_ONE_TOUCH_PINCH: { SetState(GESTURE_NONE); ScreenPoint point = PinchGestureInput::BothFingersLifted(); - PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_END, - mLastTouchInput.mTime, - mLastTouchInput.mTimeStamp, point, 1.0f, - 1.0f, mLastTouchInput.modifiers); + PinchGestureInput pinchEvent( + PinchGestureInput::PINCHGESTURE_END, mLastTouchInput.mTime, + mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, point, + 1.0f, 1.0f, mLastTouchInput.modifiers); mAsyncPanZoomController->HandleGestureEvent(pinchEvent); rv = nsEventStatus_eConsumeNoDefault; diff --git a/gfx/layers/apz/test/gtest/InputUtils.h b/gfx/layers/apz/test/gtest/InputUtils.h index 8398ea132ede..ca1c147067ce 100644 --- a/gfx/layers/apz/test/gtest/InputUtils.h +++ b/gfx/layers/apz/test/gtest/InputUtils.h @@ -31,8 +31,9 @@ PinchGestureInput CreatePinchGestureInput( PinchGestureInput::PinchGestureType aType, const ScreenPoint& aFocus, float aCurrentSpan, float aPreviousSpan) { - PinchGestureInput result(aType, 0, TimeStamp(), aFocus, aCurrentSpan, - aPreviousSpan, 0); + ParentLayerPoint localFocus(aFocus.x, aFocus.y); + PinchGestureInput result(aType, 0, TimeStamp(), ExternalPoint(0, 0), aFocus, + aCurrentSpan, aPreviousSpan, 0); return result; } diff --git a/layout/base/UnitTransforms.h b/layout/base/UnitTransforms.h index c51bb00ce456..14489f0e3d08 100644 --- a/layout/base/UnitTransforms.h +++ b/layout/base/UnitTransforms.h @@ -59,6 +59,8 @@ enum class PixelCastJustification : uint8_t { NoTransformOnLayer, // LayerPixels are ImagePixels LayerIsImage, + // External pixels are the same scale as screen pixels + ExternalIsScreen, }; template diff --git a/widget/InputData.cpp b/widget/InputData.cpp index 253b18eb3739..4493444a5f33 100644 --- a/widget/InputData.cpp +++ b/widget/InputData.cpp @@ -82,6 +82,7 @@ MultiTouchInput::MultiTouchInput(const MultiTouchInput& aOther) : InputData(MULTITOUCH_INPUT, aOther.mTime, aOther.mTimeStamp, aOther.modifiers), mType(aOther.mType), + mScreenOffset(aOther.mScreenOffset), mHandledByAPZ(aOther.mHandledByAPZ) { mTouches.AppendElements(aOther.mTouches); } @@ -111,6 +112,10 @@ MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent) break; } + mScreenOffset = ViewAs( + aTouchEvent.mWidget->WidgetToScreenOffset(), + PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent); + for (size_t i = 0; i < aTouchEvent.mTouches.Length(); i++) { const Touch* domTouch = aTouchEvent.mTouches[i]; @@ -132,42 +137,6 @@ MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent) } } -MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent) - : InputData(MULTITOUCH_INPUT, aMouseEvent.mTime, aMouseEvent.mTimeStamp, - aMouseEvent.mModifiers), - mHandledByAPZ(aMouseEvent.mFlags.mHandledByAPZ) { - MOZ_ASSERT(NS_IsMainThread(), - "Can only copy from WidgetMouseEvent on main thread"); - switch (aMouseEvent.mMessage) { - case eMouseDown: - mType = MULTITOUCH_START; - break; - case eMouseMove: - mType = MULTITOUCH_MOVE; - break; - case eMouseUp: - mType = MULTITOUCH_END; - break; - // The mouse pointer has been interrupted in an implementation-specific - // manner, such as a synchronous event or action cancelling the touch, or a - // touch point leaving the document window and going into a non-document - // area capable of handling user interactions. - case eMouseExitFromWidget: - mType = MULTITOUCH_CANCEL; - break; - default: - NS_WARNING("Did not assign a type to a MultiTouchInput"); - break; - } - - mTouches.AppendElement(SingleTouchData( - 0, - ViewAs( - aMouseEvent.mRefPoint, - PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent), - ScreenSize(1, 1), 180.0f, 1.0f)); -} - void MultiTouchInput::Translate(const ScreenPoint& aTranslation) { const int32_t xTranslation = (int32_t)(aTranslation.x + 0.5f); const int32_t yTranslation = (int32_t)(aTranslation.y + 0.5f); @@ -546,15 +515,14 @@ ParentLayerPoint PanGestureInput::UserMultipliedLocalPanDisplacement() const { PinchGestureInput::PinchGestureInput() : InputData(PINCHGESTURE_INPUT), mType(PINCHGESTURE_START) {} -PinchGestureInput::PinchGestureInput(PinchGestureType aType, uint32_t aTime, - TimeStamp aTimeStamp, - const ScreenPoint& aFocusPoint, - ScreenCoord aCurrentSpan, - ScreenCoord aPreviousSpan, - Modifiers aModifiers) +PinchGestureInput::PinchGestureInput( + PinchGestureType aType, uint32_t aTime, TimeStamp aTimeStamp, + const ExternalPoint& aScreenOffset, const ScreenPoint& aFocusPoint, + ScreenCoord aCurrentSpan, ScreenCoord aPreviousSpan, Modifiers aModifiers) : InputData(PINCHGESTURE_INPUT, aTime, aTimeStamp, aModifiers), mType(aType), mFocusPoint(aFocusPoint), + mScreenOffset(aScreenOffset), mCurrentSpan(aCurrentSpan), mPreviousSpan(aPreviousSpan) {} diff --git a/widget/InputData.h b/widget/InputData.h index 95c0cce36683..c292aec18e6a 100644 --- a/widget/InputData.h +++ b/widget/InputData.h @@ -197,13 +197,6 @@ class MultiTouchInput : public InputData { MultiTouchInput(); MultiTouchInput(const MultiTouchInput& aOther); explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent); - // This conversion from WidgetMouseEvent to MultiTouchInput is needed because - // on the B2G emulator we can only receive mouse events, but we need to be - // able to pan correctly. To do this, we convert the events into a format that - // the panning code can handle. This code is very limited and only supports - // SingleTouchData. It also sends garbage for the identifier, radius, force - // and rotation angle. - explicit MultiTouchInput(const WidgetMouseEvent& aMouseEvent); void Translate(const ScreenPoint& aTranslation); WidgetTouchEvent ToWidgetTouchEvent(nsIWidget* aWidget) const; @@ -219,6 +212,9 @@ class MultiTouchInput : public InputData { // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h MultiTouchType mType; nsTArray mTouches; + // The screen offset of the root widget. This can be changing along with + // the touch interaction, so we sstore it in the event. + ExternalPoint mScreenOffset; bool mHandledByAPZ; }; @@ -415,9 +411,9 @@ class PinchGestureInput : public InputData { // Construct a pinch gesture from a Screen point. PinchGestureInput(PinchGestureType aType, uint32_t aTime, - TimeStamp aTimeStamp, const ScreenPoint& aFocusPoint, - ScreenCoord aCurrentSpan, ScreenCoord aPreviousSpan, - Modifiers aModifiers); + TimeStamp aTimeStamp, const ExternalPoint& aScreenOffset, + const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan, + ScreenCoord aPreviousSpan, Modifiers aModifiers); bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform); @@ -435,6 +431,10 @@ class PinchGestureInput : public InputData { // store |BothFingersLifted()|. ScreenPoint mFocusPoint; + // The screen offset of the root widget. This can be changing along with + // the touch interaction, so we sstore it in the event. + ExternalPoint mScreenOffset; + // |mFocusPoint| transformed to the local coordinates of the APZC targeted // by the hit. This is set and used by APZ. ParentLayerPoint mLocalFocusPoint; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 4fb893576b30..a5134d857024 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -3658,6 +3658,9 @@ NSEvent* gLastDragMouseDownEvent = nil; ScreenPoint position = ViewAs([self convertWindowCoordinatesRoundDown:locationInWindow], PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent); + ExternalPoint screenOffset = + ViewAs(mGeckoChild->WidgetToScreenOffset(), + PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent); PRIntervalTime eventIntervalTime = PR_IntervalNow(); TimeStamp eventTimeStamp = nsCocoaUtils::GetEventTimeStamp([anEvent timestamp]); @@ -3686,6 +3689,7 @@ NSEvent* gLastDragMouseDownEvent = nil; PinchGestureInput event{pinchGestureType, eventIntervalTime, eventTimeStamp, + screenOffset, position, 100.0, 100.0 * (1.0 - [anEvent magnification]), diff --git a/widget/nsGUIEventIPC.h b/widget/nsGUIEventIPC.h index 0ba04051443d..c2c214356e1b 100644 --- a/widget/nsGUIEventIPC.h +++ b/widget/nsGUIEventIPC.h @@ -1144,6 +1144,7 @@ struct ParamTraits { WriteParam(aMsg, aParam.mType); WriteParam(aMsg, aParam.mTouches); WriteParam(aMsg, aParam.mHandledByAPZ); + WriteParam(aMsg, aParam.mScreenOffset); } static bool Read(const Message* aMsg, PickleIterator* aIter, @@ -1151,7 +1152,8 @@ struct ParamTraits { return ReadParam(aMsg, aIter, static_cast(aResult)) && ReadParam(aMsg, aIter, &aResult->mType) && ReadParam(aMsg, aIter, &aResult->mTouches) && - ReadParam(aMsg, aIter, &aResult->mHandledByAPZ); + ReadParam(aMsg, aIter, &aResult->mHandledByAPZ) && + ReadParam(aMsg, aIter, &aResult->mScreenOffset); } }; @@ -1264,6 +1266,7 @@ struct ParamTraits { static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, static_cast(aParam)); WriteParam(aMsg, aParam.mType); + WriteParam(aMsg, aParam.mScreenOffset); WriteParam(aMsg, aParam.mFocusPoint); WriteParam(aMsg, aParam.mLocalFocusPoint); WriteParam(aMsg, aParam.mCurrentSpan); @@ -1274,6 +1277,7 @@ struct ParamTraits { paramType* aResult) { return ReadParam(aMsg, aIter, static_cast(aResult)) && ReadParam(aMsg, aIter, &aResult->mType) && + ReadParam(aMsg, aIter, &aResult->mScreenOffset) && ReadParam(aMsg, aIter, &aResult->mFocusPoint) && ReadParam(aMsg, aIter, &aResult->mLocalFocusPoint) && ReadParam(aMsg, aIter, &aResult->mCurrentSpan) &&