Bug 1706865. Factor out a couple of FrameMetrics calculations so they can be used on variables outside the metrics. r=botond

We use this in the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D113071
This commit is contained in:
Timothy Nikkel 2021-04-28 03:08:08 +00:00
parent 9597a30fbb
commit 6ec47c43ec
2 changed files with 35 additions and 11 deletions

View File

@ -123,6 +123,30 @@ void FrameMetrics::KeepLayoutViewportEnclosingVisualViewport(
aLayoutViewport = aLayoutViewport.MoveInsideAndClamp(aScrollableRect);
}
/* static */
CSSRect FrameMetrics::CalculateScrollRange(
const CSSRect& aScrollableRect, const ParentLayerRect& aCompositionBounds,
const CSSToParentLayerScale2D& aZoom) {
CSSSize scrollPortSize =
CalculateCompositedSizeInCssPixels(aCompositionBounds, aZoom);
CSSRect scrollRange = aScrollableRect;
scrollRange.SetWidth(
std::max(scrollRange.Width() - scrollPortSize.width, 0.0f));
scrollRange.SetHeight(
std::max(scrollRange.Height() - scrollPortSize.height, 0.0f));
return scrollRange;
}
/* static */
CSSSize FrameMetrics::CalculateCompositedSizeInCssPixels(
const ParentLayerRect& aCompositionBounds,
const CSSToParentLayerScale2D& aZoom) {
if (aZoom == CSSToParentLayerScale2D(0, 0)) {
return CSSSize(); // avoid division by zero
}
return aCompositionBounds.Size() / aZoom;
}
bool FrameMetrics::ApplyScrollUpdateFrom(const ScrollPositionUpdate& aUpdate) {
// In applying a main-thread scroll update, try to preserve the relative
// offset between the visual and layout viewports.

View File

@ -193,10 +193,7 @@ struct FrameMetrics {
}
CSSSize CalculateCompositedSizeInCssPixels() const {
if (GetZoom() == CSSToParentLayerScale2D(0, 0)) {
return CSSSize(); // avoid division by zero
}
return mCompositionBounds.Size() / GetZoom();
return CalculateCompositedSizeInCssPixels(mCompositionBounds, mZoom);
}
/*
@ -227,13 +224,7 @@ struct FrameMetrics {
}
CSSRect CalculateScrollRange() const {
CSSSize scrollPortSize = CalculateCompositedSizeInCssPixels();
CSSRect scrollRange = mScrollableRect;
scrollRange.SetWidth(
std::max(scrollRange.Width() - scrollPortSize.width, 0.0f));
scrollRange.SetHeight(
std::max(scrollRange.Height() - scrollPortSize.height, 0.0f));
return scrollRange;
return CalculateScrollRange(mScrollableRect, mCompositionBounds, mZoom);
}
void ScrollBy(const CSSPoint& aPoint) {
@ -478,6 +469,15 @@ struct FrameMetrics {
const CSSRect& aVisualViewport, const CSSRect& aScrollableRect,
CSSRect& aLayoutViewport);
// Helper functions exposed so we can perform operations on copies outside of
// frame metrics object.
static CSSRect CalculateScrollRange(const CSSRect& aScrollableRect,
const ParentLayerRect& aCompositionBounds,
const CSSToParentLayerScale2D& aZoom);
static CSSSize CalculateCompositedSizeInCssPixels(
const ParentLayerRect& aCompositionBounds,
const CSSToParentLayerScale2D& aZoom);
private:
// A ID assigned to each scrollable frame, unique within each LayersId..
ViewID mScrollId;