Bug 1273250 - Factor out a helper function to calculate the viewport rect. r=mstange
MozReview-Commit-ID: ACJayEWplCY
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -2347,16 +2347,30 @@ RegisterThemeGeometry(nsDisplayListBuild
nsRect borderBox(aFrame->GetOffsetTo(displayRoot), aFrame->GetSize());
aBuilder->RegisterThemeGeometry(aType,
LayoutDeviceIntRect::FromUnknownRect(
borderBox.ToNearestPixels(
aFrame->PresContext()->AppUnitsPerDevPixel())));
}
}
+// Return the bounds of the viewport relative to |aFrame|'s reference frame.
+// Returns Nothing() if transforming into |aFrame|'s coordinate space fails.
+static Maybe<nsRect>
+GetViewportRectRelativeToReferenceFrame(nsDisplayListBuilder* aBuilder,
+ nsIFrame* aFrame)
+{
+ nsIFrame* rootFrame = aFrame->PresContext()->PresShell()->GetRootFrame();
+ nsRect rootRect = rootFrame->GetRectRelativeToSelf();
+ if (nsLayoutUtils::TransformRect(rootFrame, aFrame, rootRect) == nsLayoutUtils::TRANSFORM_SUCCEEDED) {
+ return Some(rootRect + aBuilder->ToReferenceFrame(aFrame));
+ }
+ return Nothing();
+}
+
nsDisplayBackgroundImage::nsDisplayBackgroundImage(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame,
uint32_t aLayer,
const nsRect& aBackgroundRect,
const nsStyleBackground* aBackgroundStyle)
: nsDisplayImageContainer(aBuilder, aFrame)
, mBackgroundStyle(aBackgroundStyle)
, mBackgroundRect(aBackgroundRect)
@@ -3042,20 +3056,18 @@ nsDisplayBackgroundImage::GetBoundsInter
nsRect clipRect = mBackgroundRect;
if (mFrame->GetType() == nsGkAtoms::canvasFrame) {
nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
clipRect = frame->CanvasArea() + ToReferenceFrame();
} else if (nsLayoutUtils::UsesAsyncScrolling(mFrame) && IsNonEmptyFixedImage()) {
// If this is a background-attachment:fixed image, and APZ is enabled,
// async scrolling could reveal additional areas of the image, so don't
// clip it beyond clipping to the document's viewport.
- nsIFrame* rootFrame = presContext->PresShell()->GetRootFrame();
- nsRect rootRect = rootFrame->GetRectRelativeToSelf();
- if (nsLayoutUtils::TransformRect(rootFrame, mFrame, rootRect) == nsLayoutUtils::TRANSFORM_SUCCEEDED) {
- clipRect = clipRect.Union(rootRect + aBuilder->ToReferenceFrame(mFrame));
+ if (Maybe<nsRect> viewportRect = GetViewportRectRelativeToReferenceFrame(aBuilder, mFrame)) {
+ clipRect = clipRect.Union(*viewportRect);
}
}
const nsStyleImageLayers::Layer& layer = mBackgroundStyle->mImage.mLayers[mLayer];
return nsCSSRendering::GetBackgroundLayerRect(presContext, mFrame,
mBackgroundRect, clipRect, layer,
aBuilder->GetBackgroundPaintFlags());
}