Bug 1265715 - Part 3. Use nsLayoutUtils::PaintFrame in ClipBackgroundByText; r=jfkthame

MozReview-Commit-ID: LRh54GNT0qW

--HG--
extra : rebase_source : ad03f0a22b6eb285f6abb622396caf1da48021b7
This commit is contained in:
CJKu 2016-04-26 00:26:51 +08:00
parent f75bface0f
commit f934d566c4
2 changed files with 26 additions and 33 deletions

View File

@ -493,48 +493,28 @@ AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty,
static void
ClipBackgroundByText(nsIFrame* aFrame, nsRenderingContext* aContext,
const gfxRect& aFillRect)
const nsRect& aFillRect)
{
// The main function of enabling background-clip:text property value.
// When a nsDisplayBackgroundImage detects "text" bg-clip style, it will call
// this function to
// 1. Ask every text frame objects in aFrame puts glyph paths into aContext.
// 2. Then, clip aContext.
// 2. Clip aContext.
//
// Then, nsDisplayBackgroundImage paints bg-images into this clipped region,
// so we get images embedded in text shape!
nsDisplayListBuilder builder(aFrame, nsDisplayListBuilderMode::GENERATE_GLYPH, false);
builder.EnterPresShell(aFrame);
nsDisplayList list;
aFrame->BuildDisplayListForStackingContext(&builder,
nsRect(nsPoint(0, 0), aFrame->GetSize()),
&list);
builder.LeavePresShell(aFrame);
#ifdef DEBUG
// ClipBackgroundByText is called by nsDisplayBackgroundImage::Paint or
// nsDisplayBackgroundColor::Paint.
// Assert that we do not generate and put nsDisplayBackgroundImage or
// nsDisplayBackgroundColor into the list again, which would lead to
// infinite recursion.
for (nsDisplayItem* i = list.GetBottom(); i; i = i->GetAbove()) {
MOZ_ASSERT(nsDisplayItem::TYPE_BACKGROUND != i->GetType() &&
nsDisplayItem::TYPE_BACKGROUND_COLOR != i->GetType());
}
#endif
gfxContext* ctx = aContext->ThebesContext();
gfxContextMatrixAutoSaveRestore save(ctx);
ctx->SetMatrix(ctx->CurrentMatrix().Translate(aFillRect.TopLeft()));
gfxRect bounds = nsLayoutUtils::RectToGfxRect(aFillRect, aFrame->PresContext()->AppUnitsPerDevPixel());
ctx->SetMatrix(ctx->CurrentMatrix().Translate(bounds.TopLeft()));
ctx->NewPath();
RefPtr<LayerManager> layerManager =
list.PaintRoot(&builder, aContext, nsDisplayList::PAINT_DEFAULT);
nsLayoutUtils::PaintFrame(aContext, aFrame, aFrame->GetRect(),
NS_RGB(255, 255, 255),
nsDisplayListBuilderMode::GENERATE_GLYPH, 0);
ctx->Clip();
list.DeleteAll();
}
/* static */ void
@ -2955,9 +2935,8 @@ nsDisplayBackgroundImage::PaintInternal(nsDisplayListBuilder* aBuilder,
uint8_t clip = mBackgroundStyle->mImage.mLayers[mLayer].mClip;
if (clip == NS_STYLE_IMAGELAYER_CLIP_TEXT) {
gfxRect bounds = nsLayoutUtils::RectToGfxRect(borderBox, mFrame->PresContext()->AppUnitsPerDevPixel());
ctx->Save();
ClipBackgroundByText(mFrame, aCtx, bounds);
ClipBackgroundByText(mFrame, aCtx, borderBox);
}
image::DrawResult result =
@ -3386,20 +3365,20 @@ nsDisplayBackgroundColor::Paint(nsDisplayListBuilder* aBuilder,
#else
gfxContext* ctx = aCtx->ThebesContext();
gfxRect bounds =
nsLayoutUtils::RectToGfxRect(borderBox, mFrame->PresContext()->AppUnitsPerDevPixel());
uint8_t clip = mBackgroundStyle->mImage.mLayers[0].mClip;
if (clip == NS_STYLE_IMAGELAYER_CLIP_TEXT) {
gfxContextAutoSaveRestore save(ctx);
ClipBackgroundByText(mFrame, aCtx, bounds);
ClipBackgroundByText(mFrame, aCtx, borderBox);
ctx->SetColor(mColor);
ctx->Fill();
return;
}
gfxRect bounds =
nsLayoutUtils::RectToGfxRect(borderBox, mFrame->PresContext()->AppUnitsPerDevPixel());
ctx->SetColor(mColor);
ctx->NewPath();
ctx->Rectangle(bounds, true);

View File

@ -3442,6 +3442,20 @@ nsLayoutUtils::PaintFrame(nsRenderingContext* aRenderingContext, nsIFrame* aFram
js::ProfileEntry::Category::GRAPHICS);
aFrame->BuildDisplayListForStackingContext(&builder, dirtyRect, &list);
#ifdef DEBUG
if (builder.IsForGenerateGlyphPath()) {
// PaintFrame is called to generate text glyph by
// nsDisplayBackgroundImage::Paint or nsDisplayBackgroundColor::Paint.
//
// Assert that we do not generate and put nsDisplayBackgroundImage or
// nsDisplayBackgroundColor into the list again, which would lead to
// infinite recursion.
for (nsDisplayItem* i = list.GetBottom(); i; i = i->GetAbove()) {
MOZ_ASSERT(nsDisplayItem::TYPE_BACKGROUND != i->GetType() &&
nsDisplayItem::TYPE_BACKGROUND_COLOR != i->GetType());
}
}
#endif
}
nsIAtom* frameType = aFrame->GetType();