Bug 1515774 - Introduce mScreenOffset for pinch and multitouch events. r=botond

Differential Revision: https://phabricator.services.mozilla.com/D17043

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2019-01-31 16:46:10 +00:00
parent 186e2cc4ca
commit da315919ab
9 changed files with 79 additions and 71 deletions

View File

@ -1900,6 +1900,7 @@ void APZCTreeManager::SynthesizePinchGestureFromMouseWheel(
PinchGestureInput pinchStart{PinchGestureInput::PINCHGESTURE_START, PinchGestureInput pinchStart{PinchGestureInput::PINCHGESTURE_START,
aWheelInput.mTime, aWheelInput.mTime,
aWheelInput.mTimeStamp, aWheelInput.mTimeStamp,
ExternalPoint(0, 0),
focusPoint, focusPoint,
oldSpan, oldSpan,
oldSpan, oldSpan,
@ -1907,6 +1908,7 @@ void APZCTreeManager::SynthesizePinchGestureFromMouseWheel(
PinchGestureInput pinchScale1{PinchGestureInput::PINCHGESTURE_SCALE, PinchGestureInput pinchScale1{PinchGestureInput::PINCHGESTURE_SCALE,
aWheelInput.mTime, aWheelInput.mTime,
aWheelInput.mTimeStamp, aWheelInput.mTimeStamp,
ExternalPoint(0, 0),
focusPoint, focusPoint,
oldSpan, oldSpan,
oldSpan, oldSpan,
@ -1914,6 +1916,7 @@ void APZCTreeManager::SynthesizePinchGestureFromMouseWheel(
PinchGestureInput pinchScale2{PinchGestureInput::PINCHGESTURE_SCALE, PinchGestureInput pinchScale2{PinchGestureInput::PINCHGESTURE_SCALE,
aWheelInput.mTime, aWheelInput.mTime,
aWheelInput.mTimeStamp, aWheelInput.mTimeStamp,
ExternalPoint(0, 0),
focusPoint, focusPoint,
oldSpan, oldSpan,
newSpan, newSpan,
@ -1922,6 +1925,7 @@ void APZCTreeManager::SynthesizePinchGestureFromMouseWheel(
PinchGestureInput::PINCHGESTURE_END, PinchGestureInput::PINCHGESTURE_END,
aWheelInput.mTime, aWheelInput.mTime,
aWheelInput.mTimeStamp, aWheelInput.mTimeStamp,
ExternalPoint(0, 0),
PinchGestureInput::BothFingersLifted<ScreenPixel>(), PinchGestureInput::BothFingersLifted<ScreenPixel>(),
newSpan, newSpan,
newSpan, newSpan,

View File

@ -18,6 +18,29 @@
#include "mozilla/FloatingPoint.h" #include "mozilla/FloatingPoint.h"
namespace mozilla { namespace mozilla {
struct ExternalPixel;
template <>
struct IsPixel<ExternalPixel> : TrueType {};
typedef gfx::CoordTyped<ExternalPixel> ExternalCoord;
typedef gfx::IntCoordTyped<ExternalPixel> ExternalIntCoord;
typedef gfx::PointTyped<ExternalPixel> ExternalPoint;
typedef gfx::IntPointTyped<ExternalPixel> ExternalIntPoint;
typedef gfx::SizeTyped<ExternalPixel> ExternalSize;
typedef gfx::IntSizeTyped<ExternalPixel> ExternalIntSize;
typedef gfx::RectTyped<ExternalPixel> ExternalRect;
typedef gfx::IntRectTyped<ExternalPixel> ExternalIntRect;
typedef gfx::MarginTyped<ExternalPixel> ExternalMargin;
typedef gfx::IntMarginTyped<ExternalPixel> ExternalIntMargin;
typedef gfx::IntRegionTyped<ExternalPixel> ExternalIntRegion;
typedef gfx::Matrix4x4Typed<ExternalPixel, ParentLayerPixel>
ExternalToParentLayerMatrix4x4;
struct ExternalPixel {};
namespace layers { namespace layers {
class AsyncPanZoomController; class AsyncPanZoomController;

View File

@ -311,8 +311,8 @@ nsEventStatus GestureEventListener::HandleInputTouchMove() {
PinchGestureInput pinchEvent( PinchGestureInput pinchEvent(
PinchGestureInput::PINCHGESTURE_START, mLastTouchInput.mTime, PinchGestureInput::PINCHGESTURE_START, mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp, currentFocus, currentSpan, currentSpan, mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
mLastTouchInput.modifiers); currentFocus, currentSpan, currentSpan, mLastTouchInput.modifiers);
rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent); rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
@ -340,8 +340,8 @@ nsEventStatus GestureEventListener::HandleInputTouchMove() {
SetState(GESTURE_PINCH); SetState(GESTURE_PINCH);
PinchGestureInput pinchEvent( PinchGestureInput pinchEvent(
PinchGestureInput::PINCHGESTURE_START, mLastTouchInput.mTime, PinchGestureInput::PINCHGESTURE_START, mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp, currentFocus, currentSpan, currentSpan, mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
mLastTouchInput.modifiers); currentFocus, currentSpan, currentSpan, mLastTouchInput.modifiers);
rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent); rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
} else { } else {
@ -368,8 +368,9 @@ nsEventStatus GestureEventListener::HandleInputTouchMove() {
PinchGestureInput pinchEvent( PinchGestureInput pinchEvent(
PinchGestureInput::PINCHGESTURE_SCALE, mLastTouchInput.mTime, PinchGestureInput::PINCHGESTURE_SCALE, mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp, GetCurrentFocus(mLastTouchInput), mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
currentSpan, mPreviousSpan, mLastTouchInput.modifiers); GetCurrentFocus(mLastTouchInput), currentSpan, mPreviousSpan,
mLastTouchInput.modifiers);
rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent); rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
mPreviousSpan = currentSpan; mPreviousSpan = currentSpan;
@ -390,8 +391,9 @@ nsEventStatus GestureEventListener::HandleInputTouchMove() {
PinchGestureInput pinchEvent( PinchGestureInput pinchEvent(
PinchGestureInput::PINCHGESTURE_SCALE, mLastTouchInput.mTime, PinchGestureInput::PINCHGESTURE_SCALE, mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp, currentFocus, effectiveSpan, mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset,
mPreviousSpan, mLastTouchInput.modifiers); currentFocus, effectiveSpan, mPreviousSpan,
mLastTouchInput.modifiers);
rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent); rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
mPreviousSpan = effectiveSpan; mPreviousSpan = effectiveSpan;
@ -472,10 +474,10 @@ nsEventStatus GestureEventListener::HandleInputTouchEnd() {
// contain meaningful data. // contain meaningful data.
point = mTouches[0].mScreenPoint; point = mTouches[0].mScreenPoint;
} }
PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_END, PinchGestureInput pinchEvent(
mLastTouchInput.mTime, PinchGestureInput::PINCHGESTURE_END, mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp, point, 1.0f, mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, point,
1.0f, mLastTouchInput.modifiers); 1.0f, 1.0f, mLastTouchInput.modifiers);
mAsyncPanZoomController->HandleGestureEvent(pinchEvent); mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
} }
@ -486,10 +488,10 @@ nsEventStatus GestureEventListener::HandleInputTouchEnd() {
case GESTURE_ONE_TOUCH_PINCH: { case GESTURE_ONE_TOUCH_PINCH: {
SetState(GESTURE_NONE); SetState(GESTURE_NONE);
ScreenPoint point = PinchGestureInput::BothFingersLifted<ScreenPixel>(); ScreenPoint point = PinchGestureInput::BothFingersLifted<ScreenPixel>();
PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_END, PinchGestureInput pinchEvent(
mLastTouchInput.mTime, PinchGestureInput::PINCHGESTURE_END, mLastTouchInput.mTime,
mLastTouchInput.mTimeStamp, point, 1.0f, mLastTouchInput.mTimeStamp, mLastTouchInput.mScreenOffset, point,
1.0f, mLastTouchInput.modifiers); 1.0f, 1.0f, mLastTouchInput.modifiers);
mAsyncPanZoomController->HandleGestureEvent(pinchEvent); mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
rv = nsEventStatus_eConsumeNoDefault; rv = nsEventStatus_eConsumeNoDefault;

View File

@ -31,8 +31,9 @@
PinchGestureInput CreatePinchGestureInput( PinchGestureInput CreatePinchGestureInput(
PinchGestureInput::PinchGestureType aType, const ScreenPoint& aFocus, PinchGestureInput::PinchGestureType aType, const ScreenPoint& aFocus,
float aCurrentSpan, float aPreviousSpan) { float aCurrentSpan, float aPreviousSpan) {
PinchGestureInput result(aType, 0, TimeStamp(), aFocus, aCurrentSpan, ParentLayerPoint localFocus(aFocus.x, aFocus.y);
aPreviousSpan, 0); PinchGestureInput result(aType, 0, TimeStamp(), ExternalPoint(0, 0), aFocus,
aCurrentSpan, aPreviousSpan, 0);
return result; return result;
} }

View File

@ -59,6 +59,8 @@ enum class PixelCastJustification : uint8_t {
NoTransformOnLayer, NoTransformOnLayer,
// LayerPixels are ImagePixels // LayerPixels are ImagePixels
LayerIsImage, LayerIsImage,
// External pixels are the same scale as screen pixels
ExternalIsScreen,
}; };
template <class TargetUnits, class SourceUnits> template <class TargetUnits, class SourceUnits>

View File

@ -82,6 +82,7 @@ MultiTouchInput::MultiTouchInput(const MultiTouchInput& aOther)
: InputData(MULTITOUCH_INPUT, aOther.mTime, aOther.mTimeStamp, : InputData(MULTITOUCH_INPUT, aOther.mTime, aOther.mTimeStamp,
aOther.modifiers), aOther.modifiers),
mType(aOther.mType), mType(aOther.mType),
mScreenOffset(aOther.mScreenOffset),
mHandledByAPZ(aOther.mHandledByAPZ) { mHandledByAPZ(aOther.mHandledByAPZ) {
mTouches.AppendElements(aOther.mTouches); mTouches.AppendElements(aOther.mTouches);
} }
@ -111,6 +112,10 @@ MultiTouchInput::MultiTouchInput(const WidgetTouchEvent& aTouchEvent)
break; break;
} }
mScreenOffset = ViewAs<ExternalPixel>(
aTouchEvent.mWidget->WidgetToScreenOffset(),
PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);
for (size_t i = 0; i < aTouchEvent.mTouches.Length(); i++) { for (size_t i = 0; i < aTouchEvent.mTouches.Length(); i++) {
const Touch* domTouch = aTouchEvent.mTouches[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<ScreenPixel>(
aMouseEvent.mRefPoint,
PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
ScreenSize(1, 1), 180.0f, 1.0f));
}
void MultiTouchInput::Translate(const ScreenPoint& aTranslation) { void MultiTouchInput::Translate(const ScreenPoint& aTranslation) {
const int32_t xTranslation = (int32_t)(aTranslation.x + 0.5f); const int32_t xTranslation = (int32_t)(aTranslation.x + 0.5f);
const int32_t yTranslation = (int32_t)(aTranslation.y + 0.5f); const int32_t yTranslation = (int32_t)(aTranslation.y + 0.5f);
@ -546,15 +515,14 @@ ParentLayerPoint PanGestureInput::UserMultipliedLocalPanDisplacement() const {
PinchGestureInput::PinchGestureInput() PinchGestureInput::PinchGestureInput()
: InputData(PINCHGESTURE_INPUT), mType(PINCHGESTURE_START) {} : InputData(PINCHGESTURE_INPUT), mType(PINCHGESTURE_START) {}
PinchGestureInput::PinchGestureInput(PinchGestureType aType, uint32_t aTime, PinchGestureInput::PinchGestureInput(
TimeStamp aTimeStamp, PinchGestureType aType, uint32_t aTime, TimeStamp aTimeStamp,
const ScreenPoint& aFocusPoint, const ExternalPoint& aScreenOffset, const ScreenPoint& aFocusPoint,
ScreenCoord aCurrentSpan, ScreenCoord aCurrentSpan, ScreenCoord aPreviousSpan, Modifiers aModifiers)
ScreenCoord aPreviousSpan,
Modifiers aModifiers)
: InputData(PINCHGESTURE_INPUT, aTime, aTimeStamp, aModifiers), : InputData(PINCHGESTURE_INPUT, aTime, aTimeStamp, aModifiers),
mType(aType), mType(aType),
mFocusPoint(aFocusPoint), mFocusPoint(aFocusPoint),
mScreenOffset(aScreenOffset),
mCurrentSpan(aCurrentSpan), mCurrentSpan(aCurrentSpan),
mPreviousSpan(aPreviousSpan) {} mPreviousSpan(aPreviousSpan) {}

View File

@ -197,13 +197,6 @@ class MultiTouchInput : public InputData {
MultiTouchInput(); MultiTouchInput();
MultiTouchInput(const MultiTouchInput& aOther); MultiTouchInput(const MultiTouchInput& aOther);
explicit MultiTouchInput(const WidgetTouchEvent& aTouchEvent); 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); void Translate(const ScreenPoint& aTranslation);
WidgetTouchEvent ToWidgetTouchEvent(nsIWidget* aWidget) const; WidgetTouchEvent ToWidgetTouchEvent(nsIWidget* aWidget) const;
@ -219,6 +212,9 @@ class MultiTouchInput : public InputData {
// fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
MultiTouchType mType; MultiTouchType mType;
nsTArray<SingleTouchData> mTouches; nsTArray<SingleTouchData> 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; bool mHandledByAPZ;
}; };
@ -415,9 +411,9 @@ class PinchGestureInput : public InputData {
// Construct a pinch gesture from a Screen point. // Construct a pinch gesture from a Screen point.
PinchGestureInput(PinchGestureType aType, uint32_t aTime, PinchGestureInput(PinchGestureType aType, uint32_t aTime,
TimeStamp aTimeStamp, const ScreenPoint& aFocusPoint, TimeStamp aTimeStamp, const ExternalPoint& aScreenOffset,
ScreenCoord aCurrentSpan, ScreenCoord aPreviousSpan, const ScreenPoint& aFocusPoint, ScreenCoord aCurrentSpan,
Modifiers aModifiers); ScreenCoord aPreviousSpan, Modifiers aModifiers);
bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform); bool TransformToLocal(const ScreenToParentLayerMatrix4x4& aTransform);
@ -435,6 +431,10 @@ class PinchGestureInput : public InputData {
// store |BothFingersLifted()|. // store |BothFingersLifted()|.
ScreenPoint mFocusPoint; 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 // |mFocusPoint| transformed to the local coordinates of the APZC targeted
// by the hit. This is set and used by APZ. // by the hit. This is set and used by APZ.
ParentLayerPoint mLocalFocusPoint; ParentLayerPoint mLocalFocusPoint;

View File

@ -3658,6 +3658,9 @@ NSEvent* gLastDragMouseDownEvent = nil;
ScreenPoint position = ScreenPoint position =
ViewAs<ScreenPixel>([self convertWindowCoordinatesRoundDown:locationInWindow], ViewAs<ScreenPixel>([self convertWindowCoordinatesRoundDown:locationInWindow],
PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent); PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);
ExternalPoint screenOffset =
ViewAs<ExternalPixel>(mGeckoChild->WidgetToScreenOffset(),
PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);
PRIntervalTime eventIntervalTime = PR_IntervalNow(); PRIntervalTime eventIntervalTime = PR_IntervalNow();
TimeStamp eventTimeStamp = nsCocoaUtils::GetEventTimeStamp([anEvent timestamp]); TimeStamp eventTimeStamp = nsCocoaUtils::GetEventTimeStamp([anEvent timestamp]);
@ -3686,6 +3689,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
PinchGestureInput event{pinchGestureType, PinchGestureInput event{pinchGestureType,
eventIntervalTime, eventIntervalTime,
eventTimeStamp, eventTimeStamp,
screenOffset,
position, position,
100.0, 100.0,
100.0 * (1.0 - [anEvent magnification]), 100.0 * (1.0 - [anEvent magnification]),

View File

@ -1144,6 +1144,7 @@ struct ParamTraits<mozilla::MultiTouchInput> {
WriteParam(aMsg, aParam.mType); WriteParam(aMsg, aParam.mType);
WriteParam(aMsg, aParam.mTouches); WriteParam(aMsg, aParam.mTouches);
WriteParam(aMsg, aParam.mHandledByAPZ); WriteParam(aMsg, aParam.mHandledByAPZ);
WriteParam(aMsg, aParam.mScreenOffset);
} }
static bool Read(const Message* aMsg, PickleIterator* aIter, static bool Read(const Message* aMsg, PickleIterator* aIter,
@ -1151,7 +1152,8 @@ struct ParamTraits<mozilla::MultiTouchInput> {
return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) && return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) &&
ReadParam(aMsg, aIter, &aResult->mType) && ReadParam(aMsg, aIter, &aResult->mType) &&
ReadParam(aMsg, aIter, &aResult->mTouches) && 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<mozilla::PinchGestureInput> {
static void Write(Message* aMsg, const paramType& aParam) { static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam)); WriteParam(aMsg, static_cast<const mozilla::InputData&>(aParam));
WriteParam(aMsg, aParam.mType); WriteParam(aMsg, aParam.mType);
WriteParam(aMsg, aParam.mScreenOffset);
WriteParam(aMsg, aParam.mFocusPoint); WriteParam(aMsg, aParam.mFocusPoint);
WriteParam(aMsg, aParam.mLocalFocusPoint); WriteParam(aMsg, aParam.mLocalFocusPoint);
WriteParam(aMsg, aParam.mCurrentSpan); WriteParam(aMsg, aParam.mCurrentSpan);
@ -1274,6 +1277,7 @@ struct ParamTraits<mozilla::PinchGestureInput> {
paramType* aResult) { paramType* aResult) {
return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) && return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) &&
ReadParam(aMsg, aIter, &aResult->mType) && ReadParam(aMsg, aIter, &aResult->mType) &&
ReadParam(aMsg, aIter, &aResult->mScreenOffset) &&
ReadParam(aMsg, aIter, &aResult->mFocusPoint) && ReadParam(aMsg, aIter, &aResult->mFocusPoint) &&
ReadParam(aMsg, aIter, &aResult->mLocalFocusPoint) && ReadParam(aMsg, aIter, &aResult->mLocalFocusPoint) &&
ReadParam(aMsg, aIter, &aResult->mCurrentSpan) && ReadParam(aMsg, aIter, &aResult->mCurrentSpan) &&