diff --git a/gfx/2d/BaseRect.h b/gfx/2d/BaseRect.h index 459892defeb3..08094a4fbda0 100644 --- a/gfx/2d/BaseRect.h +++ b/gfx/2d/BaseRect.h @@ -441,18 +441,18 @@ struct BaseRect { } /** - * Clamp aRect to this rectangle. This returns aRect after it is forced - * inside the bounds of this rectangle. It will attempt to retain the size - * but will shrink the dimensions that don't fit. + * Clamp this rectangle to be inside aRect. The function returns a copy of + * this rect after it is forced inside the bounds of aRect. It will attempt to + * retain the size but will shrink the dimensions that don't fit. */ - Sub ClampRect(const Sub& aRect) const + Sub ForceInside(const Sub& aRect) const { Sub rect(std::max(aRect.x, x), std::max(aRect.y, y), std::min(aRect.width, width), std::min(aRect.height, height)); - rect.x = std::min(rect.XMost(), XMost()) - rect.width; - rect.y = std::min(rect.YMost(), YMost()) - rect.height; + rect.x = std::min(rect.XMost(), aRect.XMost()) - rect.width; + rect.y = std::min(rect.YMost(), aRect.YMost()) - rect.height; return rect; } diff --git a/gfx/layers/ipc/AsyncPanZoomController.cpp b/gfx/layers/ipc/AsyncPanZoomController.cpp index 789c4518a858..c5935e566026 100644 --- a/gfx/layers/ipc/AsyncPanZoomController.cpp +++ b/gfx/layers/ipc/AsyncPanZoomController.cpp @@ -1257,8 +1257,7 @@ const CSSRect AsyncPanZoomController::CalculatePendingDisplayPort( scrollOffset.y = scrollableRect.y; } - CSSRect shiftedDisplayPort = displayPort + scrollOffset; - return scrollableRect.ClampRect(shiftedDisplayPort) - scrollOffset; + return displayPort.ForceInside(scrollableRect - scrollOffset); } void AsyncPanZoomController::ScheduleComposite() { diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index cdddac27c088..57328ea7177f 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -716,7 +716,7 @@ static void RecordFrameMetrics(nsIFrame* aForFrame, ScreenIntRect screenBounds = ScreenIntRect::FromUnknownRect(mozilla::gfx::IntRect( bounds.x, bounds.y, bounds.width, bounds.height)); AdjustForScrollBars(screenBounds, scrollableFrame); - metrics.mCompositionBounds = screenBounds.ClampRect(metrics.mCompositionBounds); + metrics.mCompositionBounds = metrics.mCompositionBounds.ForceInside(screenBounds); useWidgetBounds = true; } }