diff --git a/gfx/layers/FrameMetrics.h b/gfx/layers/FrameMetrics.h index e86bf5f1e803..853226e72295 100644 --- a/gfx/layers/FrameMetrics.h +++ b/gfx/layers/FrameMetrics.h @@ -179,11 +179,17 @@ public: CSSSize CalculateCompositedSizeInCssPixels() const { + if (GetZoom() == CSSToParentLayerScale2D(0, 0)) { + return CSSSize(); // avoid division by zero + } return mCompositionBounds.Size() / GetZoom(); } CSSRect CalculateCompositedRectInCssPixels() const { + if (GetZoom() == CSSToParentLayerScale2D(0, 0)) { + return CSSRect(); // avoid division by zero + } return mCompositionBounds / GetZoom(); } diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 148810dcf0e8..7282c6781bff 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -2697,7 +2697,10 @@ const ScreenMargin AsyncPanZoomController::CalculatePendingDisplayPort( } CSSSize compositionSize = aFrameMetrics.CalculateBoundedCompositedSizeInCssPixels(); - CSSPoint velocity = aVelocity / aFrameMetrics.GetZoom(); + CSSPoint velocity; + if (aFrameMetrics.GetZoom() != CSSToParentLayerScale2D(0, 0)) { + velocity = aVelocity / aFrameMetrics.GetZoom(); // avoid division by zero + } CSSRect scrollableRect = aFrameMetrics.GetExpandedScrollableRect(); // Calculate the displayport size based on how fast we're moving along each axis. diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 3cc277fd55ff..816dfcd134ca 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -1000,6 +1000,19 @@ GetDisplayPortFromMarginsData(nsIContent* aContent, LayoutDeviceToScreenScale2D res(presContext->PresShell()->GetCumulativeResolution() * nsLayoutUtils::GetTransformToAncestorScale(frame)); + // Calculate the expanded scrollable rect, which we'll be clamping the + // displayport to. + nsRect expandedScrollableRect = + nsLayoutUtils::CalculateExpandedScrollableRect(frame); + + // GetTransformToAncestorScale() can return 0. In this case, just return the + // base rect (clamped to the expanded scrollable rect), as other calculations + // would run into divisions by zero. + if (res == LayoutDeviceToScreenScale2D(0, 0)) { + // Make sure the displayport remains within the scrollable rect. + return base.MoveInsideAndClamp(expandedScrollableRect - scrollPos); + } + // First convert the base rect to screen pixels LayoutDeviceToScreenScale2D parentRes = res; if (isRoot) { @@ -1113,8 +1126,6 @@ GetDisplayPortFromMarginsData(nsIContent* aContent, result = ApplyRectMultiplier(result, aMultiplier); // Make sure the displayport remains within the scrollable rect. - nsRect expandedScrollableRect = - nsLayoutUtils::CalculateExpandedScrollableRect(frame); result = result.MoveInsideAndClamp(expandedScrollableRect - scrollPos); return result;