Bug 1659124 - Avoid passing non-CSS points to IsZero as it may return false when it should return true. r=botond

IsZero() is changed to take a CSSPoint parameter instead of any
point type, to avoid accidentally re-introducing the issue.

Differential Revision: https://phabricator.services.mozilla.com/D145173
This commit is contained in:
Razvan Cojocaru 2022-05-04 21:51:57 +00:00
Родитель 24901643cf
Коммит d0d119f806
7 изменённых файлов: 26 добавлений и 9 удалений

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

@ -2718,7 +2718,8 @@ ParentLayerPoint APZCTreeManager::DispatchFling(
residualVelocity += current->AttemptFling(transformedHandoffState);
// If there's no residual velocity, there's nothing more to hand off.
if (IsZero(residualVelocity)) {
if (current->Metrics().GetZoom() == CSSToParentLayerScale(0) ||
IsZero(residualVelocity / current->Metrics().GetZoom())) {
return ParentLayerPoint();
}

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

@ -76,8 +76,7 @@ inline bool ScrollSourceAllowsOverscroll(ScrollSource aSource) {
// isn't too large.
const float COORDINATE_EPSILON = 0.02f;
template <typename Units>
static bool IsZero(const gfx::PointTyped<Units>& aPoint) {
inline bool IsZero(const CSSPoint& aPoint) {
return FuzzyEqualsAdditive(aPoint.x, 0.0f, COORDINATE_EPSILON) &&
FuzzyEqualsAdditive(aPoint.y, 0.0f, COORDINATE_EPSILON);
}

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

@ -2265,6 +2265,16 @@ bool AsyncPanZoomController::IsContentOfHonouredTargetRightToLeft(
return Metrics().IsHorizontalContentRightToLeft();
}
bool AsyncPanZoomController::IsZero(const ParentLayerPoint& aPoint) const {
const auto zoom = Metrics().GetZoom();
if (zoom == CSSToParentLayerScale(0)) {
return true;
}
return layers::IsZero(aPoint / zoom);
}
bool AsyncPanZoomController::AllowScrollHandoffInCurrentBlock() const {
bool result = mInputQueue->AllowScrollHandoff();
if (!StaticPrefs::apz_allow_immediate_handoff()) {

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

@ -580,6 +580,8 @@ class AsyncPanZoomController {
// @see mozilla::WheelDeltaAdjustmentStrategy
bool IsContentOfHonouredTargetRightToLeft(bool aHonoursRoot) const;
bool IsZero(const ParentLayerPoint& aPoint) const;
protected:
// Protected destructor, to discourage deletion outside of Release():
virtual ~AsyncPanZoomController();

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

@ -100,6 +100,11 @@ class GenericFlingAnimation : public AsyncPanZoomAnimation,
*/
virtual bool DoSample(FrameMetrics& aFrameMetrics,
const TimeDuration& aDelta) override {
CSSToParentLayerScale zoom(aFrameMetrics.GetZoom());
if (zoom == CSSToParentLayerScale(0)) {
return false;
}
ParentLayerPoint velocity;
ParentLayerPoint offset;
FlingPhysics::Sample(aDelta, &velocity, &offset);
@ -107,7 +112,7 @@ class GenericFlingAnimation : public AsyncPanZoomAnimation,
mApzc.SetVelocityVector(velocity);
// If we shouldn't continue the fling, let's just stop and repaint.
if (IsZero(velocity)) {
if (IsZero(velocity / zoom)) {
FLING_LOG("%p ending fling animation. overscrolled=%d\n", &mApzc,
mApzc.IsOverscrolled());
// This APZC or an APZC further down the handoff chain may be be
@ -137,7 +142,7 @@ class GenericFlingAnimation : public AsyncPanZoomAnimation,
}
// The fling may have caused us to reach the end of our scroll range.
if (!IsZero(overscroll)) {
if (!IsZero(overscroll / zoom)) {
// Hand off the fling to the next APZC in the overscroll handoff chain.
// We may have reached the end of the scroll range along one axis but
@ -176,7 +181,7 @@ class GenericFlingAnimation : public AsyncPanZoomAnimation,
// as well. (This fling and the handed-off fling will run concurrently.)
// Note that AdjustDisplacement() will have zeroed out the velocity
// along the axes where we're overscrolled.
return !IsZero(mApzc.GetVelocityVector());
return !IsZero(mApzc.GetVelocityVector() / zoom);
}
return true;

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

@ -79,7 +79,7 @@ bool GenericScrollAnimation::DoSample(FrameMetrics& aFrameMetrics,
if (finished) {
mApzc.mX.SetVelocity(0);
mApzc.mY.SetVelocity(0);
} else if (!IsZero(displacement)) {
} else if (!IsZero(displacement / zoom)) {
// Convert velocity from AppUnits/Seconds to ParentLayerCoords/Milliseconds
nsSize velocity = mAnimationPhysics->VelocityAt(now);
ParentLayerPoint velocityPL =
@ -99,7 +99,7 @@ bool GenericScrollAnimation::DoSample(FrameMetrics& aFrameMetrics,
// then end the animation early. Note that the initial displacement could be 0
// if the compositor ran very quickly (<1ms) after the animation was created.
// When that happens we want to make sure the animation continues.
if (!IsZero(displacement) && IsZero(adjustedOffset)) {
if (!IsZero(displacement / zoom) && IsZero(adjustedOffset / zoom)) {
// Nothing more to do - end the animation.
return false;
}

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

@ -79,7 +79,7 @@ bool SmoothMsdScrollAnimation::DoSample(FrameMetrics& aFrameMetrics,
// layout.css.scroll-behavior.damping-ratio preference is set to less than 1
// (underdamped) or if a smooth scroll inherits velocity from a fling
// gesture.
if (!IsZero(overscroll)) {
if (!IsZero(overscroll / zoom)) {
// Hand off a fling with the remaining momentum to the next APZC in the
// overscroll handoff chain.