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-29 21:11:35 +00:00
Родитель 795da6be8d
Коммит 8ae47905e7
9 изменённых файлов: 79 добавлений и 71 удалений

Просмотреть файл

@ -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<ScreenPixel>(),
newSpan,
newSpan,

Просмотреть файл

@ -18,6 +18,29 @@
#include "mozilla/FloatingPoint.h"
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 {
class AsyncPanZoomController;

Просмотреть файл

@ -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<ScreenPixel>();
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;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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 <class TargetUnits, class SourceUnits>

Просмотреть файл

@ -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<ExternalPixel>(
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<ScreenPixel>(
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) {}

Просмотреть файл

@ -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<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;
};
@ -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;

Просмотреть файл

@ -3658,6 +3658,9 @@ NSEvent* gLastDragMouseDownEvent = nil;
ScreenPoint position =
ViewAs<ScreenPixel>([self convertWindowCoordinatesRoundDown:locationInWindow],
PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);
ExternalPoint screenOffset =
ViewAs<ExternalPixel>(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]),

Просмотреть файл

@ -1144,6 +1144,7 @@ struct ParamTraits<mozilla::MultiTouchInput> {
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<mozilla::MultiTouchInput> {
return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(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<mozilla::PinchGestureInput> {
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, static_cast<const mozilla::InputData&>(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<mozilla::PinchGestureInput> {
paramType* aResult) {
return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(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) &&