From 083b9cd7fcd00b6394c090956923f0678687332a Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Fri, 22 Apr 2016 17:50:11 +1200 Subject: [PATCH] Bug 1265256 - Use the canvas positioning area when computing the background-attachment:fixed rect for canvas frames. r=mstange --- layout/base/nsDisplayList.cpp | 24 --------------------- layout/base/nsDisplayList.h | 3 --- layout/generic/nsCanvasFrame.cpp | 36 ++++++++++++++++++++++++++++++++ layout/generic/nsCanvasFrame.h | 4 ++++ 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index c297cded396c..1683c44e033c 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -2586,30 +2586,6 @@ nsDisplayBackgroundImage::ComputeShouldTreatAsFixed(bool isTransformedFixed) con return !isTransformedFixed; } -bool -nsDisplayBackgroundImage::IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder, - const nsRect& aClipRect, - gfxRect* aDestRect) -{ - if (!mBackgroundStyle) - return false; - - if (mBackgroundStyle->mImage.mLayers.Length() != 1) - return false; - - if (!ShouldTreatAsFixed()) - return false; - - // We only care about images here, not gradients. - if (!mIsRasterImage) - return false; - - int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel(); - *aDestRect = nsLayoutUtils::RectToGfxRect(mFillRect, appUnitsPerDevPixel); - - return true; -} - bool nsDisplayBackgroundImage::IsNonEmptyFixedImage() const { diff --git a/layout/base/nsDisplayList.h b/layout/base/nsDisplayList.h index 7d1f10ebf3f7..2c7cc2336b51 100644 --- a/layout/base/nsDisplayList.h +++ b/layout/base/nsDisplayList.h @@ -2736,9 +2736,6 @@ protected: typedef class mozilla::layers::ImageLayer ImageLayer; bool TryOptimizeToImageLayer(LayerManager* aManager, nsDisplayListBuilder* aBuilder); - bool IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder, - const nsRect& aClipRect, - gfxRect* aDestRect); bool IsNonEmptyFixedImage() const; nsRect GetBoundsInternal(nsDisplayListBuilder* aBuilder); bool ShouldTreatAsFixed() const; diff --git a/layout/generic/nsCanvasFrame.cpp b/layout/generic/nsCanvasFrame.cpp index 1b279364dc92..301033efd90b 100644 --- a/layout/generic/nsCanvasFrame.cpp +++ b/layout/generic/nsCanvasFrame.cpp @@ -326,6 +326,42 @@ nsDisplayCanvasBackgroundImage::Paint(nsDisplayListBuilder* aBuilder, PaintInternal(aBuilder, aCtx, mVisibleRect, &bgClipRect); } +bool +nsDisplayCanvasBackgroundImage::IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder, + const nsRect& aClipRect, + gfxRect* aDestRect) +{ + if (!mBackgroundStyle) + return false; + + if (mBackgroundStyle->mImage.mLayers.Length() != 1) + return false; + + + nsPresContext* presContext = mFrame->PresContext(); + uint32_t flags = aBuilder->GetBackgroundPaintFlags(); + nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize()); + const nsStyleImageLayers::Layer &layer = mBackgroundStyle->mImage.mLayers[mLayer]; + + if (layer.mAttachment != NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED) + return false; + + nsBackgroundLayerState state = + nsCSSRendering::PrepareImageLayer(presContext, mFrame, flags, + borderArea, aClipRect, layer); + + + // We only care about images here, not gradients. + if (!mIsRasterImage) + return false; + + int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel(); + *aDestRect = nsLayoutUtils::RectToGfxRect(state.mFillArea, appUnitsPerDevPixel); + + return true; +} + + void nsDisplayCanvasThemedBackground::Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) diff --git a/layout/generic/nsCanvasFrame.h b/layout/generic/nsCanvasFrame.h index 5b628be78f37..d22389737cde 100644 --- a/layout/generic/nsCanvasFrame.h +++ b/layout/generic/nsCanvasFrame.h @@ -227,6 +227,10 @@ public: // We still need to paint a background color as well as an image for this item, // so we can't support this yet. virtual bool SupportsOptimizingToImage() override { return false; } + + bool IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder, + const nsRect& aClipRect, + gfxRect* aDestRect); NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)