Bug 1467873 - Fix FrameMetrics::CalculateCompositedRectInCssPixels(). r=kats

- Fix the implementation to return a numerically correct result
  - Change call sites that should have instead been using
    CalculateCompositedSizeInCssPixels(), to do so
  - Rename and document to emphasize that the returned rect is in the
    CSS pixels of the content surrounding the scroll frame

MozReview-Commit-ID: GCPbA1k88rz

--HG--
extra : rebase_source : f5b937936fb84b3ae414d6cf0250add4078a9d53
This commit is contained in:
Botond Ballo 2018-06-09 16:33:26 -04:00
parent 7151ed16d0
commit 59adc89262
4 changed files with 21 additions and 7 deletions

View File

@ -197,12 +197,25 @@ public:
return mCompositionBounds.Size() / GetZoom();
}
CSSRect CalculateCompositedRectInCssPixels() const
/*
* Calculate the composition bounds of this frame in the CSS pixels of
* the content surrounding the scroll frame. (This can be thought of as
* "parent CSS" pixels).
* Note that it does not make to ask for the composition bounds in the
* CSS pixels of the scrolled content (that is, regular CSS pixels),
* because the origin of the composition bounds is not meaningful in that
* coordinate space. (The size is, use CalculateCompositedSizeInCssPixels()
* for that.)
*/
CSSRect CalculateCompositionBoundsInCssPixelsOfSurroundingContent() const
{
if (GetZoom() == CSSToParentLayerScale2D(0, 0)) {
return CSSRect(); // avoid division by zero
}
return mCompositionBounds / GetZoom();
// The CSS pixels of the scrolled content and the CSS pixels of the
// surrounding content only differ if the scrolled content is rendered
// at a higher resolution, and the difference is the resolution.
return mCompositionBounds / GetZoom() * CSSToCSSScale{mPresShellResolution};
}
CSSSize CalculateBoundedCompositedSizeInCssPixels() const

View File

@ -1056,7 +1056,7 @@ nsEventStatus AsyncPanZoomController::HandleDragEvent(const MouseInput& aEvent,
GetAxisStart(direction, mFrameMetrics.GetScrollableRect().TopLeft());
CSSCoord maxScrollPosition =
GetAxisStart(direction, mFrameMetrics.GetScrollableRect().BottomRight()) -
GetAxisLength(direction, mFrameMetrics.CalculateCompositedRectInCssPixels());
GetAxisLength(direction, mFrameMetrics.CalculateCompositionBoundsInCssPixelsOfSurroundingContent());
CSSCoord scrollPosition = minScrollPosition + (scrollPercent * (maxScrollPosition - minScrollPosition));
scrollPosition = std::max(scrollPosition, minScrollPosition);
@ -1750,7 +1750,7 @@ AsyncPanZoomController::ConvertScrollbarPoint(const ParentLayerPoint& aScrollbar
scrollbarPoint = scrollbarPoint * mFrameMetrics.GetPresShellResolution();
// Now, get it to be relative to the beginning of the scroll track.
CSSRect cssCompositionBound = mFrameMetrics.CalculateCompositedRectInCssPixels();
CSSRect cssCompositionBound = mFrameMetrics.CalculateCompositionBoundsInCssPixelsOfSurroundingContent();
return GetAxisStart(*aThumbData.mDirection, scrollbarPoint)
- GetAxisStart(*aThumbData.mDirection, cssCompositionBound)
- aThumbData.mScrollTrackStart;

View File

@ -210,10 +210,10 @@ SetDisplayPortMargins(nsIPresShell* aPresShell,
aContent->GetPrimaryFrame(), nsLayoutUtils::RepaintMode::Repaint);
}
CSSRect baseCSS = aMetrics.CalculateCompositedRectInCssPixels();
CSSSize baseSize = aMetrics.CalculateCompositedSizeInCssPixels();
nsRect base(0, 0,
baseCSS.Width() * nsPresContext::AppUnitsPerCSSPixel(),
baseCSS.Height() * nsPresContext::AppUnitsPerCSSPixel());
baseSize.width * nsPresContext::AppUnitsPerCSSPixel(),
baseSize.height * nsPresContext::AppUnitsPerCSSPixel());
nsLayoutUtils::SetDisplayPortBaseIfNotSet(aContent, base);
}

View File

@ -139,6 +139,7 @@ typedef gfx::IntSizeTyped<DesktopPixel> DesktopIntSize;
typedef gfx::RectTyped<DesktopPixel> DesktopRect;
typedef gfx::IntRectTyped<DesktopPixel> DesktopIntRect;
typedef gfx::ScaleFactor<CSSPixel, CSSPixel> CSSToCSSScale;
typedef gfx::ScaleFactor<CSSPixel, LayoutDevicePixel> CSSToLayoutDeviceScale;
typedef gfx::ScaleFactor<CSSPixel, LayerPixel> CSSToLayerScale;
typedef gfx::ScaleFactor<CSSPixel, ScreenPixel> CSSToScreenScale;