From 4dcd36c48e2ef46e78afb10153bfd00f087c5041 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Tue, 29 Jul 2014 17:24:12 -0400 Subject: [PATCH] Bug 923512 - Introduce strongly-typed coordinate classes (Part2: Changes to rest of codebase, and switching Axis to use the strongly-typed coordinates). r=kats --- content/base/public/Element.h | 4 +- dom/canvas/CanvasRenderingContext2D.cpp | 4 +- dom/canvas/CanvasRenderingContext2D.h | 2 +- dom/events/EventStateManager.cpp | 5 +- gfx/ipc/GfxMessageUtils.h | 32 +++++++++ gfx/layers/apz/src/APZCTreeManager.cpp | 10 +-- gfx/layers/apz/src/AsyncPanZoomController.cpp | 22 +++--- gfx/layers/apz/src/Axis.cpp | 72 +++++++++---------- gfx/layers/apz/src/Axis.h | 62 ++++++++-------- .../composite/ContainerLayerComposite.cpp | 10 ++- gfx/layers/opengl/CompositorOGL.cpp | 7 +- layout/base/Units.h | 9 +++ widget/xpwidgets/nsBaseWidget.cpp | 4 +- 13 files changed, 139 insertions(+), 104 deletions(-) diff --git a/content/base/public/Element.h b/content/base/public/Element.h index 1718232193dc..d962b9452f00 100644 --- a/content/base/public/Element.h +++ b/content/base/public/Element.h @@ -728,7 +728,7 @@ public: int32_t ScrollTop() { nsIScrollableFrame* sf = GetScrollFrame(); - return sf ? sf->GetScrollPositionCSSPixels().y : 0; + return sf ? sf->GetScrollPositionCSSPixels().y.value : 0; } void SetScrollTop(int32_t aScrollTop) { @@ -741,7 +741,7 @@ public: int32_t ScrollLeft() { nsIScrollableFrame* sf = GetScrollFrame(); - return sf ? sf->GetScrollPositionCSSPixels().x : 0; + return sf ? sf->GetScrollPositionCSSPixels().x.value : 0; } void SetScrollLeft(int32_t aScrollLeft) { diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 821ce43d587f..8181a819a10a 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1987,7 +1987,7 @@ CanvasRenderingContext2D::ArcTo(double x1, double y1, double x2, } // Check for colinearity - dir = (p2.x - p1.x) * (p0.y - p1.y) + (p2.y - p1.y) * (p1.x - p0.x); + dir = (p2.x - p1.x).value * (p0.y - p1.y).value + (p2.y - p1.y).value * (p1.x - p0.x).value; if (dir == 0) { LineTo(p1.x, p1.y); return; @@ -4505,7 +4505,7 @@ CanvasPath::ArcTo(double x1, double y1, double x2, double y2, double radius, } // Check for colinearity - dir = (p2.x - p1.x) * (p0.y - p1.y) + (p2.y - p1.y) * (p1.x - p0.x); + dir = (p2.x - p1.x).value * (p0.y - p1.y).value + (p2.y - p1.y).value * (p1.x - p0.x).value; if (dir == 0) { LineTo(p1.x, p1.y); return; diff --git a/dom/canvas/CanvasRenderingContext2D.h b/dom/canvas/CanvasRenderingContext2D.h index 2b0550b5b962..7d99ef421f34 100644 --- a/dom/canvas/CanvasRenderingContext2D.h +++ b/dom/canvas/CanvasRenderingContext2D.h @@ -791,7 +791,7 @@ protected: // The spec says we should not draw shadows if the operator is OVER. // If it's over and the alpha value is zero, nothing needs to be drawn. return NS_GET_A(state.shadowColor) != 0 && - (state.shadowBlur != 0 || state.shadowOffset.x != 0 || state.shadowOffset.y != 0); + (state.shadowBlur != 0.f || state.shadowOffset.x != 0.f || state.shadowOffset.y != 0.f); } mozilla::gfx::CompositionOp UsedOperation() diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 21b156943c4c..caa8af719d46 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -1595,8 +1595,9 @@ EventStateManager::GenerateDragGesture(nsPresContext* aPresContext, // fire drag gesture if mouse has moved enough LayoutDeviceIntPoint pt = aEvent->refPoint + LayoutDeviceIntPoint::FromUntyped(aEvent->widget->WidgetToScreenOffset()); - if (DeprecatedAbs(pt.x - mGestureDownPoint.x) > pixelThresholdX || - DeprecatedAbs(pt.y - mGestureDownPoint.y) > pixelThresholdY) { + LayoutDeviceIntPoint distance = pt - mGestureDownPoint; + if (Abs(distance.x.value) > SafeCast(pixelThresholdX) || + Abs(distance.y.value) > SafeCast(pixelThresholdY)) { if (Prefs::ClickHoldContextMenu()) { // stop the click-hold before we fire off the drag gesture, in case // it takes a long time diff --git a/gfx/ipc/GfxMessageUtils.h b/gfx/ipc/GfxMessageUtils.h index 8a5345d24fb4..64b644c846fa 100644 --- a/gfx/ipc/GfxMessageUtils.h +++ b/gfx/ipc/GfxMessageUtils.h @@ -507,6 +507,38 @@ struct ParamTraits } }; +template +struct ParamTraits< mozilla::gfx::CoordTyped > +{ + typedef mozilla::gfx::CoordTyped paramType; + + static void Write(Message* msg, const paramType& param) + { + WriteParam(msg, param.value); + } + + static bool Read(const Message* msg, void** iter, paramType* result) + { + return (ReadParam(msg, iter, &result->value)); + } +}; + +template +struct ParamTraits< mozilla::gfx::IntCoordTyped > +{ + typedef mozilla::gfx::IntCoordTyped paramType; + + static void Write(Message* msg, const paramType& param) + { + WriteParam(msg, param.value); + } + + static bool Read(const Message* msg, void** iter, paramType* result) + { + return (ReadParam(msg, iter, &result->value)); + } +}; + template struct ParamTraits< mozilla::gfx::ScaleFactor > { diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index ed6e3c2967e9..3439b5d645a8 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -384,16 +384,14 @@ APZCTreeManager::UpdatePanZoomControllerTree(CompositorParent* aCompositor, ApplyTransform(gfx::PointTyped* aPoint, const Matrix4x4& aMatrix) { Point result = aMatrix * aPoint->ToUnknownPoint(); - aPoint->x = result.x; - aPoint->y = result.y; + *aPoint = ViewAs(result); } /*static*/ template void ApplyTransform(gfx::IntPointTyped* aPoint, const Matrix4x4& aMatrix) { Point result = aMatrix * aPoint->ToUnknownPoint(); - aPoint->x = result.x; - aPoint->y = result.y; + *aPoint = TruncatedToInt(ViewAs(result)); } /*static*/ void @@ -651,9 +649,7 @@ APZCTreeManager::TransformCoordinateToGecko(const ScreenIntPoint& aPoint, Matrix4x4 transformToGecko; GetInputTransforms(apzc, transformToApzc, transformToGecko); Matrix4x4 outTransform = transformToApzc * transformToGecko; - aOutTransformedPoint->x = aPoint.x; - aOutTransformedPoint->y = aPoint.y; - ApplyTransform(aOutTransformedPoint, outTransform); + *aOutTransformedPoint = TransformTo(outTransform, aPoint); } } diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 737ff7422ffc..9ced4d14e90d 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -378,8 +378,8 @@ static bool IsCloseToVertical(float aAngle, float aThreshold) template static bool IsZero(const gfx::PointTyped& aPoint) { - return FuzzyEqualsMultiplicative(aPoint.x, 0.0f) - && FuzzyEqualsMultiplicative(aPoint.y, 0.0f); + return FuzzyEqualsMultiplicative(aPoint.x.value, 0.0f) + && FuzzyEqualsMultiplicative(aPoint.y.value, 0.0f); } static inline void LogRendertraceRect(const ScrollableLayerGuid& aGuid, const char* aDesc, const char* aColor, const CSSRect& aRect) @@ -529,9 +529,9 @@ public: // We may have reached the end of the scroll range along one axis but // not the other. In such a case we only want to hand off the relevant // component of the fling. - if (FuzzyEqualsAdditive(overscroll.x, 0.0f, COORDINATE_EPSILON)) { + if (FuzzyEqualsAdditive(overscroll.x.value, 0.0f, COORDINATE_EPSILON)) { velocity.x = 0; - } else if (FuzzyEqualsAdditive(overscroll.y, 0.0f, COORDINATE_EPSILON)) { + } else if (FuzzyEqualsAdditive(overscroll.y.value, 0.0f, COORDINATE_EPSILON)) { velocity.y = 0; } @@ -599,7 +599,7 @@ public: // Sample the zoom at the current time point. The sampled zoom // will affect the final computed resolution. - double sampledPosition = gComputedTimingFunction->GetValue(animPosition); + float sampledPosition = gComputedTimingFunction->GetValue(animPosition); // We scale the scrollOffset linearly with sampledPosition, so the zoom // needs to scale inversely to match. @@ -1357,8 +1357,8 @@ AsyncPanZoomController::ConvertToGecko(const ScreenPoint& aPoint, CSSPoint* aOut nsEventStatus AsyncPanZoomController::OnPanMayBegin(const PanGestureInput& aEvent) { APZC_LOG("%p got a pan-maybegin in state %d\n", this, mState); - mX.StartTouch(aEvent.mPanStartPoint.x, aEvent.mTime); - mY.StartTouch(aEvent.mPanStartPoint.y, aEvent.mTime); + mX.StartTouch(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime); + mY.StartTouch(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime); CancelAnimationForHandoffChain(); return nsEventStatus_eConsumeNoDefault; @@ -1377,8 +1377,8 @@ nsEventStatus AsyncPanZoomController::OnPanCancelled(const PanGestureInput& aEve nsEventStatus AsyncPanZoomController::OnPanBegin(const PanGestureInput& aEvent) { APZC_LOG("%p got a pan-begin in state %d\n", this, mState); - mX.StartTouch(aEvent.mPanStartPoint.x, aEvent.mTime); - mY.StartTouch(aEvent.mPanStartPoint.y, aEvent.mTime); + mX.StartTouch(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime); + mY.StartTouch(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime); if (GetAxisLockMode() == FREE) { SetState(PANNING); @@ -1401,8 +1401,8 @@ nsEventStatus AsyncPanZoomController::OnPan(const PanGestureInput& aEvent, bool // size and position. We need to do so even if this is a momentum pan (i.e. // aFingersOnTouchpad == false); in that case the "with touch" part is not // really appropriate, so we may want to rethink this at some point. - mX.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.x, aEvent.mTime); - mY.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.y, aEvent.mTime); + mX.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime); + mY.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime); HandlePanningUpdate(aEvent.mPanDisplacement.x, aEvent.mPanDisplacement.y); diff --git a/gfx/layers/apz/src/Axis.cpp b/gfx/layers/apz/src/Axis.cpp index 2173df7a6a15..ed1419fe82ff 100644 --- a/gfx/layers/apz/src/Axis.cpp +++ b/gfx/layers/apz/src/Axis.cpp @@ -33,7 +33,7 @@ Axis::Axis(AsyncPanZoomController* aAsyncPanZoomController) { } -void Axis::UpdateWithTouchAtDevicePoint(int32_t aPos, uint32_t aTimestampMs) { +void Axis::UpdateWithTouchAtDevicePoint(ScreenIntCoord aPos, uint32_t aTimestampMs) { // mVelocityQueue is controller-thread only AsyncPanZoomController::AssertOnControllerThread(); @@ -62,16 +62,16 @@ void Axis::UpdateWithTouchAtDevicePoint(int32_t aPos, uint32_t aTimestampMs) { } } -void Axis::StartTouch(int32_t aPos, uint32_t aTimestampMs) { +void Axis::StartTouch(ScreenIntCoord aPos, uint32_t aTimestampMs) { mStartPos = aPos; mPos = aPos; mPosTimeMs = aTimestampMs; mAxisLocked = false; } -bool Axis::AdjustDisplacement(float aDisplacement, - float& aDisplacementOut, - float& aOverscrollAmountOut) +bool Axis::AdjustDisplacement(CSSCoord aDisplacement, + CSSCoord& aDisplacementOut, + CSSCoord& aOverscrollAmountOut) { if (mAxisLocked) { aOverscrollAmountOut = 0; @@ -79,14 +79,14 @@ bool Axis::AdjustDisplacement(float aDisplacement, return false; } - float displacement = aDisplacement; + CSSCoord displacement = aDisplacement; // First consume any overscroll in the opposite direction along this axis. - float consumedOverscroll = 0; + CSSCoord consumedOverscroll = 0; if (mOverscroll > 0 && aDisplacement < 0) { consumedOverscroll = std::min(mOverscroll, -aDisplacement); } else if (mOverscroll < 0 && aDisplacement > 0) { - consumedOverscroll = 0 - std::min(-mOverscroll, aDisplacement); + consumedOverscroll = 0.f - std::min(-mOverscroll, aDisplacement); } mOverscroll -= consumedOverscroll; displacement += consumedOverscroll; @@ -104,7 +104,7 @@ bool Axis::AdjustDisplacement(float aDisplacement, return fabsf(consumedOverscroll) > EPSILON; } -float Axis::ApplyResistance(float aRequestedOverscroll) const { +CSSCoord Axis::ApplyResistance(CSSCoord aRequestedOverscroll) const { // 'resistanceFactor' is a value between 0 and 1, which: // - tends to 1 as the existing overscroll tends to 0 // - tends to 0 as the existing overscroll tends to the composition length @@ -112,23 +112,23 @@ float Axis::ApplyResistance(float aRequestedOverscroll) const { // factor; this should prevent overscrolling by more than the composition // length. float resistanceFactor = 1 - fabsf(mOverscroll) / GetCompositionLength(); - return resistanceFactor < 0 ? 0 : aRequestedOverscroll * resistanceFactor; + return resistanceFactor < 0 ? CSSCoord(0) : aRequestedOverscroll * resistanceFactor; } -void Axis::OverscrollBy(float aOverscroll) { +void Axis::OverscrollBy(CSSCoord aOverscroll) { MOZ_ASSERT(CanScroll()); aOverscroll = ApplyResistance(aOverscroll); if (aOverscroll > 0) { - MOZ_ASSERT(FuzzyEqualsAdditive(GetCompositionEnd(), GetPageEnd(), COORDINATE_EPSILON)); + MOZ_ASSERT(FuzzyEqualsAdditive(GetCompositionEnd().value, GetPageEnd().value, COORDINATE_EPSILON)); MOZ_ASSERT(mOverscroll >= 0); } else if (aOverscroll < 0) { - MOZ_ASSERT(FuzzyEqualsAdditive(GetOrigin(), GetPageStart(), COORDINATE_EPSILON)); + MOZ_ASSERT(FuzzyEqualsAdditive(GetOrigin().value, GetPageStart().value, COORDINATE_EPSILON)); MOZ_ASSERT(mOverscroll <= 0); } mOverscroll += aOverscroll; } -float Axis::GetOverscroll() const { +CSSCoord Axis::GetOverscroll() const { return mOverscroll; } @@ -162,7 +162,7 @@ bool Axis::SampleSnapBack(const TimeDuration& aDelta) { } mOverscroll = std::max(mOverscroll + cssDisplacement, 0.0f); // Overscroll relieved, do not continue animation. - if (mOverscroll == 0) { + if (mOverscroll == 0.f) { mVelocity = 0; return false; } @@ -174,7 +174,7 @@ bool Axis::SampleSnapBack(const TimeDuration& aDelta) { } mOverscroll = std::min(mOverscroll + cssDisplacement, 0.0f); // Overscroll relieved, do not continue animation. - if (mOverscroll == 0) { + if (mOverscroll == 0.f) { mVelocity = 0; return false; } @@ -185,7 +185,7 @@ bool Axis::SampleSnapBack(const TimeDuration& aDelta) { } bool Axis::IsOverscrolled() const { - return mOverscroll != 0; + return mOverscroll != 0.f; } void Axis::ClearOverscroll() { @@ -193,11 +193,11 @@ void Axis::ClearOverscroll() { } float Axis::PanDistance() { - return fabsf(mPos - mStartPos); + return fabsf((mPos - mStartPos).value); } -float Axis::PanDistance(float aPos) { - return fabsf(aPos - mStartPos); +float Axis::PanDistance(ScreenIntCoord aPos) { + return fabsf((aPos - mStartPos).value); } void Axis::EndTouch(uint32_t aTimestampMs) { @@ -252,7 +252,7 @@ bool Axis::FlingApplyFrictionOrCancel(const TimeDuration& aDelta, return true; } -Axis::Overscroll Axis::DisplacementWillOverscroll(float aDisplacement) { +Axis::Overscroll Axis::DisplacementWillOverscroll(CSSCoord aDisplacement) { // If the current pan plus a displacement takes the window to the left of or // above the current page rect. bool minus = GetOrigin() + aDisplacement < GetPageStart(); @@ -271,7 +271,7 @@ Axis::Overscroll Axis::DisplacementWillOverscroll(float aDisplacement) { return OVERSCROLL_NONE; } -float Axis::DisplacementWillOverscrollAmount(float aDisplacement) { +CSSCoord Axis::DisplacementWillOverscrollAmount(CSSCoord aDisplacement) { switch (DisplacementWillOverscroll(aDisplacement)) { case OVERSCROLL_MINUS: return (GetOrigin() + aDisplacement) - GetPageStart(); case OVERSCROLL_PLUS: return (GetCompositionEnd() + aDisplacement) - GetPageEnd(); @@ -281,8 +281,8 @@ float Axis::DisplacementWillOverscrollAmount(float aDisplacement) { } } -float Axis::ScaleWillOverscrollAmount(float aScale, float aFocus) { - float originAfterScale = (GetOrigin() + aFocus) - (aFocus / aScale); +CSSCoord Axis::ScaleWillOverscrollAmount(float aScale, CSSCoord aFocus) { + CSSCoord originAfterScale = (GetOrigin() + aFocus) - (aFocus / aScale); bool both = ScaleWillOverscrollBothSides(aScale); bool minus = GetPageStart() - originAfterScale > COORDINATE_EPSILON; @@ -310,29 +310,29 @@ void Axis::SetVelocity(float aVelocity) { mVelocity = aVelocity; } -float Axis::GetCompositionEnd() const { +CSSCoord Axis::GetCompositionEnd() const { return GetOrigin() + GetCompositionLength(); } -float Axis::GetPageEnd() const { +CSSCoord Axis::GetPageEnd() const { return GetPageStart() + GetPageLength(); } -float Axis::GetOrigin() const { +CSSCoord Axis::GetOrigin() const { CSSPoint origin = GetFrameMetrics().GetScrollOffset(); return GetPointOffset(origin); } -float Axis::GetCompositionLength() const { +CSSCoord Axis::GetCompositionLength() const { return GetRectLength(GetFrameMetrics().CalculateCompositedRectInCssPixels()); } -float Axis::GetPageStart() const { +CSSCoord Axis::GetPageStart() const { CSSRect pageRect = GetFrameMetrics().GetExpandedScrollableRect(); return GetRectOffset(pageRect); } -float Axis::GetPageLength() const { +CSSCoord Axis::GetPageLength() const { CSSRect pageRect = GetFrameMetrics().GetExpandedScrollableRect(); return GetRectLength(pageRect); } @@ -357,17 +357,17 @@ AxisX::AxisX(AsyncPanZoomController* aAsyncPanZoomController) } -float AxisX::GetPointOffset(const CSSPoint& aPoint) const +CSSCoord AxisX::GetPointOffset(const CSSPoint& aPoint) const { return aPoint.x; } -float AxisX::GetRectLength(const CSSRect& aRect) const +CSSCoord AxisX::GetRectLength(const CSSRect& aRect) const { return aRect.width; } -float AxisX::GetRectOffset(const CSSRect& aRect) const +CSSCoord AxisX::GetRectOffset(const CSSRect& aRect) const { return aRect.x; } @@ -378,17 +378,17 @@ AxisY::AxisY(AsyncPanZoomController* aAsyncPanZoomController) } -float AxisY::GetPointOffset(const CSSPoint& aPoint) const +CSSCoord AxisY::GetPointOffset(const CSSPoint& aPoint) const { return aPoint.y; } -float AxisY::GetRectLength(const CSSRect& aRect) const +CSSCoord AxisY::GetRectLength(const CSSRect& aRect) const { return aRect.height; } -float AxisY::GetRectOffset(const CSSRect& aRect) const +CSSCoord AxisY::GetRectOffset(const CSSRect& aRect) const { return aRect.y; } diff --git a/gfx/layers/apz/src/Axis.h b/gfx/layers/apz/src/Axis.h index 759e230c5641..1aa37e0410c9 100644 --- a/gfx/layers/apz/src/Axis.h +++ b/gfx/layers/apz/src/Axis.h @@ -55,13 +55,13 @@ public: * Notify this Axis that a new touch has been received, including a timestamp * for when the touch was received. This triggers a recalculation of velocity. */ - void UpdateWithTouchAtDevicePoint(int32_t aPos, uint32_t aTimestampMs); + void UpdateWithTouchAtDevicePoint(ScreenIntCoord aPos, uint32_t aTimestampMs); /** * Notify this Axis that a touch has begun, i.e. the user has put their finger * on the screen but has not yet tried to pan. */ - void StartTouch(int32_t aPos, uint32_t aTimestampMs); + void StartTouch(ScreenIntCoord aPos, uint32_t aTimestampMs); /** * Notify this Axis that a touch has ended gracefully. This may perform @@ -87,20 +87,20 @@ public: * displacement, and the function returns true iff internal overscroll amounts * were changed. */ - bool AdjustDisplacement(float aDisplacement, - float& aDisplacementOut, - float& aOverscrollAmountOut); + bool AdjustDisplacement(CSSCoord aDisplacement, + CSSCoord& aDisplacementOut, + CSSCoord& aOverscrollAmountOut); /** * Overscrolls this axis by the requested amount in the requested direction. * The axis must be at the end of its scroll range in this direction. */ - void OverscrollBy(float aOverscroll); + void OverscrollBy(CSSCoord aOverscroll); /** * Return the amount of overscroll on this axis, in CSS pixels. */ - float GetOverscroll() const; + CSSCoord GetOverscroll() const; /** * Sample the snap-back animation to relieve overscroll. @@ -129,7 +129,7 @@ public: * Gets the distance between the starting position of the touch supplied in * startTouch() and the supplied position. */ - float PanDistance(float aPos); + float PanDistance(ScreenIntCoord aPos); /** * Applies friction during a fling, or cancels the fling if the velocity is @@ -177,13 +177,13 @@ public: * That is to say, if the given displacement is applied, this will tell you * whether or not it will overscroll, and in what direction. */ - Overscroll DisplacementWillOverscroll(float aDisplacement); + Overscroll DisplacementWillOverscroll(CSSCoord aDisplacement); /** * If a displacement will overscroll the axis, this returns the amount and in * what direction. Similar to GetExcess() but takes a displacement to apply. */ - float DisplacementWillOverscrollAmount(float aDisplacement); + CSSCoord DisplacementWillOverscrollAmount(CSSCoord aDisplacement); /** * If a scale will overscroll the axis, this returns the amount and in what @@ -193,7 +193,7 @@ public: * scroll offset in such a way that it remains in the same place on the page * relative. */ - float ScaleWillOverscrollAmount(float aScale, float aFocus); + CSSCoord ScaleWillOverscrollAmount(float aScale, CSSCoord aFocus); /** * Checks if an axis will overscroll in both directions by computing the @@ -204,23 +204,23 @@ public: */ bool ScaleWillOverscrollBothSides(float aScale); - float GetOrigin() const; - float GetCompositionLength() const; - float GetPageStart() const; - float GetPageLength() const; - float GetCompositionEnd() const; - float GetPageEnd() const; + CSSCoord GetOrigin() const; + CSSCoord GetCompositionLength() const; + CSSCoord GetPageStart() const; + CSSCoord GetPageLength() const; + CSSCoord GetCompositionEnd() const; + CSSCoord GetPageEnd() const; - int32_t GetPos() const { return mPos; } + ScreenIntCoord GetPos() const { return mPos; } - virtual float GetPointOffset(const CSSPoint& aPoint) const = 0; - virtual float GetRectLength(const CSSRect& aRect) const = 0; - virtual float GetRectOffset(const CSSRect& aRect) const = 0; + virtual CSSCoord GetPointOffset(const CSSPoint& aPoint) const = 0; + virtual CSSCoord GetRectLength(const CSSRect& aRect) const = 0; + virtual CSSCoord GetRectOffset(const CSSRect& aRect) const = 0; protected: - int32_t mPos; + ScreenIntCoord mPos; uint32_t mPosTimeMs; - int32_t mStartPos; + ScreenIntCoord mStartPos; float mVelocity; bool mAxisLocked; // Whether movement on this axis is locked. AsyncPanZoomController* mAsyncPanZoomController; @@ -230,7 +230,7 @@ protected: // extreme allowed value in the relevant direction (that is, it must be at // its maximum value if mOverscroll is positive, and at its minimum value // if mOverscroll is negative). - float mOverscroll; + CSSCoord mOverscroll; // A queue of (timestamp, velocity) pairs; these are the historical // velocities at the given timestamps. Timestamps are in milliseconds, // velocities are in screen pixels per ms. This member can only be @@ -241,23 +241,23 @@ protected: // Adjust a requested overscroll amount for resistance, yielding a smaller // actual overscroll amount. - float ApplyResistance(float aOverscroll) const; + CSSCoord ApplyResistance(CSSCoord aOverscroll) const; }; class AxisX : public Axis { public: AxisX(AsyncPanZoomController* mAsyncPanZoomController); - virtual float GetPointOffset(const CSSPoint& aPoint) const; - virtual float GetRectLength(const CSSRect& aRect) const; - virtual float GetRectOffset(const CSSRect& aRect) const; + virtual CSSCoord GetPointOffset(const CSSPoint& aPoint) const; + virtual CSSCoord GetRectLength(const CSSRect& aRect) const; + virtual CSSCoord GetRectOffset(const CSSRect& aRect) const; }; class AxisY : public Axis { public: AxisY(AsyncPanZoomController* mAsyncPanZoomController); - virtual float GetPointOffset(const CSSPoint& aPoint) const; - virtual float GetRectLength(const CSSRect& aRect) const; - virtual float GetRectOffset(const CSSRect& aRect) const; + virtual CSSCoord GetPointOffset(const CSSPoint& aPoint) const; + virtual CSSCoord GetRectLength(const CSSRect& aRect) const; + virtual CSSCoord GetRectOffset(const CSSRect& aRect) const; }; } diff --git a/gfx/layers/composite/ContainerLayerComposite.cpp b/gfx/layers/composite/ContainerLayerComposite.cpp index 555d3907abde..ff32ac91e482 100644 --- a/gfx/layers/composite/ContainerLayerComposite.cpp +++ b/gfx/layers/composite/ContainerLayerComposite.cpp @@ -222,8 +222,8 @@ static void DrawVelGraph(const nsIntRect& aClipRect, for (int32_t i = (int32_t)velocityData->mData.size() - 2; i >= 0; i--) { const gfx::Point& p1 = velocityData->mData[i+1].mPoint; const gfx::Point& p2 = velocityData->mData[i].mPoint; - int vel = sqrt((p1.x - p2.x) * (p1.x - p2.x) + - (p1.y - p2.y) * (p1.y - p2.y)); + int vel = sqrt((p1.x - p2.x).value * (p1.x - p2.x).value + + (p1.y - p2.y).value * (p1.y - p2.y).value); Point next = Point(graphRect.width / circularBufferSize * i, graphRect.height - vel/yScaleFactor); if (first) { @@ -266,11 +266,9 @@ static void PrintUniformityInfo(Layer* aLayer) } FrameMetrics frameMetrics = aLayer->AsContainerLayer()->GetFrameMetrics(); - LayerIntPoint scrollOffset = RoundedToInt(frameMetrics.GetScrollOffsetInLayerPixels()); + const LayerPoint scrollOffset = frameMetrics.GetScrollOffsetInLayerPixels(); const gfx::Point layerTransform = GetScrollData(aLayer); - gfx::Point layerScroll; - layerScroll.x = scrollOffset.x - layerTransform.x; - layerScroll.y = scrollOffset.y - layerTransform.y; + const gfx::Point layerScroll = scrollOffset.ToUnknownPoint() - layerTransform; printf_stderr("UniformityInfo Layer_Move %llu %p %f, %f\n", TimeStamp::Now(), aLayer, layerScroll.x, layerScroll.y); diff --git a/gfx/layers/opengl/CompositorOGL.cpp b/gfx/layers/opengl/CompositorOGL.cpp index aff372271f7d..26d1bd7f75e4 100644 --- a/gfx/layers/opengl/CompositorOGL.cpp +++ b/gfx/layers/opengl/CompositorOGL.cpp @@ -474,8 +474,8 @@ DecomposeIntoNoRepeatRects(const Rect& aRect, // If we are dealing with wrapping br.x and br.y are greater than 1.0 so // wrap them here as well. - br = Point(xwrap ? WrapTexCoord(br.x) : br.x, - ywrap ? WrapTexCoord(br.y) : br.y); + br = Point(xwrap ? WrapTexCoord(br.x) : br.x.value, + ywrap ? WrapTexCoord(br.y) : br.y.value); // If we wrap around along the x axis, we will draw first from // tl.x .. 1.0 and then from 0.0 .. br.x (which we just wrapped above). @@ -759,8 +759,7 @@ CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion, // UI for its dynamic toolbar. IntPoint origin; if (!mTarget) { - origin.x = -mRenderOffset.x; - origin.y = -mRenderOffset.y; + origin = -TruncatedToInt(mRenderOffset.ToUnknownPoint()); } mCurrentRenderTarget = diff --git a/layout/base/Units.h b/layout/base/Units.h index 37f56bffe0dc..144ab55601d5 100644 --- a/layout/base/Units.h +++ b/layout/base/Units.h @@ -7,6 +7,7 @@ #ifndef MOZ_UNITS_H_ #define MOZ_UNITS_H_ +#include "mozilla/gfx/Coord.h" #include "mozilla/gfx/Point.h" #include "mozilla/gfx/Rect.h" #include "mozilla/gfx/ScaleFactor.h" @@ -30,6 +31,8 @@ template<> struct IsPixel : TrueType {}; template<> struct IsPixel : TrueType {}; template<> struct IsPixel : TrueType {}; +typedef gfx::CoordTyped CSSCoord; +typedef gfx::IntCoordTyped CSSIntCoord; typedef gfx::PointTyped CSSPoint; typedef gfx::IntPointTyped CSSIntPoint; typedef gfx::SizeTyped CSSSize; @@ -39,6 +42,8 @@ typedef gfx::IntRectTyped CSSIntRect; typedef gfx::MarginTyped CSSMargin; typedef gfx::IntMarginTyped CSSIntMargin; +typedef gfx::CoordTyped LayoutDeviceCoord; +typedef gfx::IntCoordTyped LayoutDeviceIntCoord; typedef gfx::PointTyped LayoutDevicePoint; typedef gfx::IntPointTyped LayoutDeviceIntPoint; typedef gfx::SizeTyped LayoutDeviceSize; @@ -48,6 +53,8 @@ typedef gfx::IntRectTyped LayoutDeviceIntRect; typedef gfx::MarginTyped LayoutDeviceMargin; typedef gfx::IntMarginTyped LayoutDeviceIntMargin; +typedef gfx::CoordTyped LayerCoord; +typedef gfx::IntCoordTyped LayerIntCoord; typedef gfx::PointTyped LayerPoint; typedef gfx::IntPointTyped LayerIntPoint; typedef gfx::SizeTyped LayerSize; @@ -57,6 +64,8 @@ typedef gfx::IntRectTyped LayerIntRect; typedef gfx::MarginTyped LayerMargin; typedef gfx::IntMarginTyped LayerIntMargin; +typedef gfx::CoordTyped ScreenCoord; +typedef gfx::IntCoordTyped ScreenIntCoord; typedef gfx::PointTyped ScreenPoint; typedef gfx::IntPointTyped ScreenIntPoint; typedef gfx::SizeTyped ScreenSize; diff --git a/widget/xpwidgets/nsBaseWidget.cpp b/widget/xpwidgets/nsBaseWidget.cpp index c06c1967fa06..d8f6bdf544eb 100644 --- a/widget/xpwidgets/nsBaseWidget.cpp +++ b/widget/xpwidgets/nsBaseWidget.cpp @@ -1805,8 +1805,8 @@ nsBaseWidget::debug_DumpEvent(FILE * aFileOut, (void *) aWidget, aWidgetName.get(), aWindowID, - aGuiEvent->refPoint.x, - aGuiEvent->refPoint.y); + aGuiEvent->refPoint.x.value, + aGuiEvent->refPoint.y.value); } ////////////////////////////////////////////////////////////// /* static */ void