Bug 879011 - Convert nsIntPoint instances in InputData.h to types with units. r=kentuckyfriedtakahe

This commit is contained in:
Kartikaya Gupta 2013-06-11 18:13:11 -04:00
parent 6e07b601b1
commit dbc0077c31
9 changed files with 95 additions and 49 deletions

View File

@ -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<units> FromUnknownPoint(const IntPointTyped<UnknownUnits>& aPoint) {
return IntPointTyped<units>(aPoint.x, aPoint.y);
}
IntPointTyped<UnknownUnits> ToUnknownPoint() const {
return IntPointTyped<UnknownUnits>(this->x, this->y);
}
};
typedef IntPointTyped<UnknownUnits> 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<units> FromUnknownPoint(const PointTyped<UnknownUnits>& pt) {
return PointTyped<units>(pt.x, pt.y);
static PointTyped<units> FromUnknownPoint(const PointTyped<UnknownUnits>& aPoint) {
return PointTyped<units>(aPoint.x, aPoint.y);
}
PointTyped<UnknownUnits> 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<units> FromUnknownSize(const IntSizeTyped<UnknownUnits>& aSize) {
return IntSizeTyped<units>(aSize.width, aSize.height);
}
IntSizeTyped<UnknownUnits> ToUnknownSize() const {
return IntSizeTyped<UnknownUnits>(this->width, this->height);
}
};
typedef IntSizeTyped<UnknownUnits> IntSize;
@ -71,6 +93,17 @@ struct SizeTyped :
SizeTyped(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {}
explicit SizeTyped(const IntSizeTyped<units>& 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<units> FromUnknownSize(const SizeTyped<UnknownUnits>& aSize) {
return SizeTyped<units>(aSize.width, aSize.height);
}
SizeTyped<UnknownUnits> ToUnknownSize() const {
return SizeTyped<UnknownUnits>(this->width, this->height);
}
};
typedef SizeTyped<UnknownUnits> Size;

View File

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

View File

@ -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.

View File

@ -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:

View File

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

View File

@ -126,9 +126,16 @@ typedef gfx::IntRectTyped<LayerPixel> LayerIntRect;
* generally be represented in ScreenPixel units.
*/
struct ScreenPixel {
static CSSPoint ToCSSPoint(const gfx::PointTyped<ScreenPixel>& aPoint, float aResolutionX, float aResolutionY) {
return CSSPoint(aPoint.x * aResolutionX,
aPoint.y * aResolutionY);
}
};
typedef gfx::PointTyped<ScreenPixel> ScreenPoint;
typedef gfx::IntPointTyped<ScreenPixel> ScreenIntPoint;
typedef gfx::SizeTyped<ScreenPixel> ScreenSize;
typedef gfx::IntSizeTyped<ScreenPixel> ScreenIntSize;
};

View File

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

View File

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

View File

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