diff --git a/gfx/2d/Point.h b/gfx/2d/Point.h index a50e85da4e7..ed7f6be5963 100644 --- a/gfx/2d/Point.h +++ b/gfx/2d/Point.h @@ -24,6 +24,17 @@ struct IntPointTyped : IntPointTyped() : Super() {} IntPointTyped(int32_t aX, int32_t aY) : Super(aX, aY) {} + + // XXX When all of the code is ported, the following functions to convert to and from + // unknown types should be removed. + + static IntPointTyped FromUnknownPoint(const IntPointTyped& aPoint) { + return IntPointTyped(aPoint.x, aPoint.y); + } + + IntPointTyped ToUnknownPoint() const { + return IntPointTyped(this->x, this->y); + } }; typedef IntPointTyped IntPoint; @@ -40,8 +51,8 @@ struct PointTyped : // XXX When all of the code is ported, the following functions to convert to and from // unknown types should be removed. - static PointTyped FromUnknownPoint(const PointTyped& pt) { - return PointTyped(pt.x, pt.y); + static PointTyped FromUnknownPoint(const PointTyped& aPoint) { + return PointTyped(aPoint.x, aPoint.y); } PointTyped ToUnknownPoint() const { @@ -58,6 +69,17 @@ struct IntSizeTyped : IntSizeTyped() : Super() {} IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {} + + // XXX When all of the code is ported, the following functions to convert to and from + // unknown types should be removed. + + static IntSizeTyped FromUnknownSize(const IntSizeTyped& aSize) { + return IntSizeTyped(aSize.width, aSize.height); + } + + IntSizeTyped ToUnknownSize() const { + return IntSizeTyped(this->width, this->height); + } }; typedef IntSizeTyped IntSize; @@ -71,6 +93,17 @@ struct SizeTyped : SizeTyped(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {} explicit SizeTyped(const IntSizeTyped& size) : Super(float(size.width), float(size.height)) {} + + // XXX When all of the code is ported, the following functions to convert to and from + // unknown types should be removed. + + static SizeTyped FromUnknownSize(const SizeTyped& aSize) { + return SizeTyped(aSize.width, aSize.height); + } + + SizeTyped ToUnknownSize() const { + return SizeTyped(this->width, this->height); + } }; typedef SizeTyped Size; diff --git a/gfx/layers/ipc/AsyncPanZoomController.cpp b/gfx/layers/ipc/AsyncPanZoomController.cpp index 5e35be6d349..1291148c22c 100644 --- a/gfx/layers/ipc/AsyncPanZoomController.cpp +++ b/gfx/layers/ipc/AsyncPanZoomController.cpp @@ -388,8 +388,7 @@ nsEventStatus AsyncPanZoomController::HandleInputEvent(const InputData& aEvent) nsEventStatus AsyncPanZoomController::OnTouchStart(const MultiTouchInput& aEvent) { SingleTouchData& touch = GetFirstSingleTouch(aEvent); - nsIntPoint point = touch.mScreenPoint; - int32_t xPos = point.x, yPos = point.y; + ScreenIntPoint point = touch.mScreenPoint; switch (mState) { case ANIMATING_ZOOM: @@ -407,8 +406,8 @@ nsEventStatus AsyncPanZoomController::OnTouchStart(const MultiTouchInput& aEvent CancelAnimation(); // Fall through. case NOTHING: - mX.StartTouch(xPos); - mY.StartTouch(yPos); + mX.StartTouch(point.x); + mY.StartTouch(point.y); SetState(TOUCHING); break; case TOUCHING: @@ -530,7 +529,7 @@ nsEventStatus AsyncPanZoomController::OnScaleBegin(const PinchGestureInput& aEve } SetState(PINCHING); - mLastZoomFocus = gfx::Point(aEvent.mFocusPoint.x, aEvent.mFocusPoint.y); + mLastZoomFocus = aEvent.mFocusPoint; return nsEventStatus_eConsumeNoDefault; } @@ -553,18 +552,20 @@ nsEventStatus AsyncPanZoomController::OnScale(const PinchGestureInput& aEvent) { gfxFloat resolution = CalculateResolution(mFrameMetrics).width; gfxFloat userZoom = mFrameMetrics.mZoom.width; - gfx::Point focusPoint = gfx::Point(aEvent.mFocusPoint.x, aEvent.mFocusPoint.y); - gfxFloat xFocusChange = (mLastZoomFocus.x - focusPoint.x) / resolution; - gfxFloat yFocusChange = (mLastZoomFocus.y - focusPoint.y) / resolution; + ScreenPoint focusPoint = aEvent.mFocusPoint; + + CSSPoint focusChange = ScreenPoint::ToCSSPoint(mLastZoomFocus - focusPoint, + 1.0 / resolution, + 1.0 / resolution); // If displacing by the change in focus point will take us off page bounds, // then reduce the displacement such that it doesn't. - if (mX.DisplacementWillOverscroll(xFocusChange) != Axis::OVERSCROLL_NONE) { - xFocusChange -= mX.DisplacementWillOverscrollAmount(xFocusChange); + if (mX.DisplacementWillOverscroll(focusChange.x) != Axis::OVERSCROLL_NONE) { + focusChange.x -= mX.DisplacementWillOverscrollAmount(focusChange.x); } - if (mY.DisplacementWillOverscroll(yFocusChange) != Axis::OVERSCROLL_NONE) { - yFocusChange -= mY.DisplacementWillOverscrollAmount(yFocusChange); + if (mY.DisplacementWillOverscroll(focusChange.y) != Axis::OVERSCROLL_NONE) { + focusChange.y -= mY.DisplacementWillOverscrollAmount(focusChange.y); } - ScrollBy(gfx::Point(xFocusChange, yFocusChange)); + ScrollBy(focusChange.ToUnknownPoint()); // When we zoom in with focus, we can zoom too much towards the boundaries // that we actually go over them. These are the needed displacements along @@ -730,8 +731,7 @@ void AsyncPanZoomController::StartPanning(const MultiTouchInput& aEvent) { void AsyncPanZoomController::UpdateWithTouchAtDevicePoint(const MultiTouchInput& aEvent) { SingleTouchData& touch = GetFirstSingleTouch(aEvent); - nsIntPoint point = touch.mScreenPoint; - int32_t xPos = point.x, yPos = point.y; + ScreenIntPoint point = touch.mScreenPoint; TimeDuration timeDelta = TimeDuration().FromMilliseconds(aEvent.mTime - mLastEventTime); // Probably a duplicate event, just throw it away. @@ -739,8 +739,8 @@ void AsyncPanZoomController::UpdateWithTouchAtDevicePoint(const MultiTouchInput& return; } - mX.UpdateWithTouchAtDevicePoint(xPos, timeDelta); - mY.UpdateWithTouchAtDevicePoint(yPos, timeDelta); + mX.UpdateWithTouchAtDevicePoint(point.x, timeDelta); + mY.UpdateWithTouchAtDevicePoint(point.y, timeDelta); } void AsyncPanZoomController::TrackTouch(const MultiTouchInput& aEvent) { @@ -833,7 +833,7 @@ void AsyncPanZoomController::ScrollBy(const gfx::Point& aOffset) { } void AsyncPanZoomController::ScaleWithFocus(float aZoom, - const gfx::Point& aFocus) { + const ScreenPoint& aFocus) { float zoomFactor = aZoom / mFrameMetrics.mZoom.width; gfxFloat resolution = CalculateResolution(mFrameMetrics).width; @@ -843,9 +843,9 @@ void AsyncPanZoomController::ScaleWithFocus(float aZoom, // errors, so don't bother adjusting the scroll offset. if (resolution >= 0.01f) { mFrameMetrics.mScrollOffset.x += - gfxFloat(aFocus.x) * (zoomFactor - 1.0) / resolution; + aFocus.x * (zoomFactor - 1.0) / resolution; mFrameMetrics.mScrollOffset.y += - gfxFloat(aFocus.y) * (zoomFactor - 1.0) / resolution; + aFocus.y * (zoomFactor - 1.0) / resolution; } } diff --git a/gfx/layers/ipc/AsyncPanZoomController.h b/gfx/layers/ipc/AsyncPanZoomController.h index 79b193529d0..d10a0c8d61d 100644 --- a/gfx/layers/ipc/AsyncPanZoomController.h +++ b/gfx/layers/ipc/AsyncPanZoomController.h @@ -342,7 +342,7 @@ protected: * * XXX: Fix focus point calculations. */ - void ScaleWithFocus(float aScale, const gfx::Point& aFocus); + void ScaleWithFocus(float aScale, const ScreenPoint& aFocus); /** * Schedules a composite on the compositor thread. Wrapper for @@ -546,7 +546,7 @@ private: // Stores the previous focus point if there is a pinch gesture happening. Used // to allow panning by moving multiple fingers (thus moving the focus point). - gfx::Point mLastZoomFocus; + ScreenPoint mLastZoomFocus; // Stores the state of panning and zooming this frame. This is protected by // |mMonitor|; that is, it should be held whenever this is updated. diff --git a/gfx/layers/ipc/GestureEventListener.cpp b/gfx/layers/ipc/GestureEventListener.cpp index 98be52274f6..20762ddc5ac 100644 --- a/gfx/layers/ipc/GestureEventListener.cpp +++ b/gfx/layers/ipc/GestureEventListener.cpp @@ -101,9 +101,9 @@ nsEventStatus GestureEventListener::HandleInputEvent(const InputData& aEvent) } case MultiTouchInput::MULTITOUCH_MOVE: { // If we move too much, bail out of the tap. - nsIntPoint touch = (nsIntPoint&)event.mTouches[0].mScreenPoint; + ScreenIntPoint delta = event.mTouches[0].mScreenPoint - mTouchStartPosition; if (mTouches.Length() == 1 && - NS_hypot(mTouchStartPosition.x - touch.x, mTouchStartPosition.y - touch.y) > + NS_hypot(delta.x, delta.y) > mAsyncPanZoomController->GetDPI() * mAsyncPanZoomController->GetTouchStartTolerance()) { HandleTapCancel(event); @@ -200,14 +200,11 @@ nsEventStatus GestureEventListener::HandlePinchGestureEvent(const MultiTouchInpu nsEventStatus rv = nsEventStatus_eIgnore; if (mTouches.Length() > 1 && !aClearTouches) { - const nsIntPoint& firstTouch = mTouches[0].mScreenPoint, - secondTouch = mTouches[mTouches.Length() - 1].mScreenPoint; - nsIntPoint focusPoint = - nsIntPoint((firstTouch.x + secondTouch.x)/2, - (firstTouch.y + secondTouch.y)/2); - float currentSpan = - float(NS_hypot(firstTouch.x - secondTouch.x, - firstTouch.y - secondTouch.y)); + const ScreenIntPoint& firstTouch = mTouches[0].mScreenPoint, + secondTouch = mTouches[mTouches.Length() - 1].mScreenPoint; + ScreenPoint focusPoint = ScreenPoint(firstTouch + secondTouch) / 2; + ScreenIntPoint delta = secondTouch - firstTouch; + float currentSpan = float(NS_hypot(delta.x, delta.y)); switch (mState) { case GESTURE_NONE: diff --git a/gfx/layers/ipc/GestureEventListener.h b/gfx/layers/ipc/GestureEventListener.h index 9fcb5e22552..79b1a83ffd4 100644 --- a/gfx/layers/ipc/GestureEventListener.h +++ b/gfx/layers/ipc/GestureEventListener.h @@ -222,7 +222,7 @@ protected: * to determine if a touch is a tap. This means that it is used in both the * "GESTURE_WAITING_SINGLE_TAP" and "GESTURE_WAITING_DOUBLE_TAP" states. */ - nsIntPoint mTouchStartPosition; + ScreenIntPoint mTouchStartPosition; }; } diff --git a/layout/base/Units.h b/layout/base/Units.h index c504b38a200..516a8eee9fd 100644 --- a/layout/base/Units.h +++ b/layout/base/Units.h @@ -126,9 +126,16 @@ typedef gfx::IntRectTyped LayerIntRect; * generally be represented in ScreenPixel units. */ struct ScreenPixel { + static CSSPoint ToCSSPoint(const gfx::PointTyped& aPoint, float aResolutionX, float aResolutionY) { + return CSSPoint(aPoint.x * aResolutionX, + aPoint.y * aResolutionY); + } }; typedef gfx::PointTyped ScreenPoint; +typedef gfx::IntPointTyped ScreenIntPoint; +typedef gfx::SizeTyped ScreenSize; +typedef gfx::IntSizeTyped ScreenIntSize; }; diff --git a/widget/InputData.h b/widget/InputData.h index d103f2a187e..4d2d05cd808 100644 --- a/widget/InputData.h +++ b/widget/InputData.h @@ -9,6 +9,7 @@ #include "nsDebug.h" #include "nsPoint.h" #include "nsTArray.h" +#include "Units.h" class nsTouchEvent; class nsMouseEvent; @@ -85,8 +86,8 @@ class SingleTouchData { public: SingleTouchData(int32_t aIdentifier, - nsIntPoint aScreenPoint, - nsIntPoint aRadius, + ScreenIntPoint aScreenPoint, + ScreenSize aRadius, float aRotationAngle, float aForce) : mIdentifier(aIdentifier), @@ -109,14 +110,14 @@ public: // Point on the screen that the touch hit, in device pixels. They are // coordinates on the screen. - nsIntPoint mScreenPoint; + ScreenIntPoint mScreenPoint; // Radius that the touch covers, i.e. if you're using your thumb it will // probably be larger than using your pinky, even with the same force. // Radius can be different along x and y. For example, if you press down with // your entire finger vertically, the y radius will be much larger than the x // radius. - nsIntPoint mRadius; + ScreenSize mRadius; float mRotationAngle; @@ -189,7 +190,7 @@ public: PinchGestureInput(PinchGestureType aType, uint32_t aTime, - const nsIntPoint& aFocusPoint, + const ScreenPoint& aFocusPoint, float aCurrentSpan, float aPreviousSpan) : InputData(PINCHGESTURE_INPUT, aTime), @@ -209,7 +210,7 @@ public: // point is implementation-specific, but can for example be the midpoint // between the very first and very last touch. This is in device pixels and // are the coordinates on the screen of this midpoint. - nsIntPoint mFocusPoint; + ScreenPoint mFocusPoint; // The distance in device pixels (though as a float for increased precision // and because it is the distance along both the x and y axis) between the @@ -239,7 +240,7 @@ public: TAPGESTURE_CANCEL }; - TapGestureInput(TapGestureType aType, uint32_t aTime, const nsIntPoint& aPoint) + TapGestureInput(TapGestureType aType, uint32_t aTime, const ScreenIntPoint& aPoint) : InputData(TAPGESTURE_INPUT, aTime), mType(aType), mPoint(aPoint) @@ -249,7 +250,7 @@ public: } TapGestureType mType; - nsIntPoint mPoint; + ScreenIntPoint mPoint; }; } diff --git a/widget/android/AndroidJavaWrappers.cpp b/widget/android/AndroidJavaWrappers.cpp index 47afd85bdf4..f2efadca10b 100644 --- a/widget/android/AndroidJavaWrappers.cpp +++ b/widget/android/AndroidJavaWrappers.cpp @@ -797,9 +797,13 @@ AndroidGeckoEvent::MakeMultiTouchInput(nsIWidget* widget) const nsIntPoint& offset = widget->WidgetToScreenOffset(); event.mTouches.SetCapacity(endIndex - startIndex); for (int i = startIndex; i < endIndex; i++) { + nsIntPoint point = Points()[i] - offset; + nsIntPoint radius = PointRadii()[i]; SingleTouchData data(PointIndicies()[i], - Points()[i] - offset, - PointRadii()[i], + ScreenIntPoint::FromUnknownPoint( + gfx::IntPoint(point.x, point.y)), + ScreenSize::FromUnknownSize( + gfx::Size(radius.x, radius.y)), Orientations()[i], Pressures()[i]); event.mTouches.AppendElement(data); diff --git a/widget/xpwidgets/InputData.cpp b/widget/xpwidgets/InputData.cpp index 445e9648c50..73edfeada44 100644 --- a/widget/xpwidgets/InputData.cpp +++ b/widget/xpwidgets/InputData.cpp @@ -57,8 +57,10 @@ MultiTouchInput::MultiTouchInput(const nsTouchEvent& aTouchEvent) domTouch->GetForce(&force); SingleTouchData data(identifier, - domTouch->mRefPoint, - nsIntPoint(radiusX, radiusY), + ScreenIntPoint::FromUnknownPoint( + gfx::IntPoint(domTouch->mRefPoint.x, + domTouch->mRefPoint.y)), + ScreenSize(radiusX, radiusY), rotationAngle, force); @@ -100,8 +102,10 @@ MultiTouchInput::MultiTouchInput(const nsMouseEvent& aMouseEvent) } mTouches.AppendElement(SingleTouchData(0, - aMouseEvent.refPoint, - nsIntPoint(1, 1), + ScreenIntPoint::FromUnknownPoint( + gfx::IntPoint(aMouseEvent.refPoint.x, + aMouseEvent.refPoint.y)), + ScreenSize(1, 1), 180.0f, 1.0f)); }