Make PaintBackgroundWithSC and related methods operate on nsStyleContext* rather than const nsStyleBackground*. (Bug 147777) r=zweinberg

This commit is contained in:
L. David Baron 2010-04-02 18:58:26 -07:00
parent b5cbbc06ce
commit 68d7839f41
14 changed files with 77 additions and 69 deletions

View File

@ -7233,8 +7233,8 @@ ApplyRenderingChangeToTree(nsPresContext* aPresContext,
// If the frame's background is propagated to an ancestor, walk up to
// that ancestor.
const nsStyleBackground *bg;
while (!nsCSSRendering::FindBackground(aPresContext, aFrame, &bg)) {
nsStyleContext *bgSC;
while (!nsCSSRendering::FindBackground(aPresContext, aFrame, &bgSC)) {
aFrame = aFrame->GetParent();
NS_ASSERTION(aFrame, "root frame must paint");
}

View File

@ -1022,22 +1022,22 @@ nsCSSRendering::FindBackgroundStyleFrame(nsIFrame* aForFrame)
* the resulting style context to use for the background information
* will be filled in to |aBackground|.
*/
const nsStyleBackground*
nsStyleContext*
nsCSSRendering::FindRootFrameBackground(nsIFrame* aForFrame)
{
return FindBackgroundStyleFrame(aForFrame)->GetStyleBackground();
return FindBackgroundStyleFrame(aForFrame)->GetStyleContext();
}
inline PRBool
FindElementBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame,
const nsStyleBackground** aBackground)
nsStyleContext** aBackgroundSC)
{
if (aForFrame == aRootElementFrame) {
// We must have propagated our background to the viewport or canvas. Abort.
return PR_FALSE;
}
*aBackground = aForFrame->GetStyleBackground();
*aBackgroundSC = aForFrame->GetStyleContext();
// Return true unless the frame is for a BODY element whose background
// was propagated to the viewport.
@ -1074,15 +1074,15 @@ FindElementBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame,
PRBool
nsCSSRendering::FindBackground(nsPresContext* aPresContext,
nsIFrame* aForFrame,
const nsStyleBackground** aBackground)
nsStyleContext** aBackgroundSC)
{
nsIFrame* rootElementFrame =
aPresContext->PresShell()->FrameConstructor()->GetRootElementStyleFrame();
if (IsCanvasFrame(aForFrame)) {
*aBackground = FindCanvasBackground(aForFrame, rootElementFrame);
*aBackgroundSC = FindCanvasBackground(aForFrame, rootElementFrame);
return PR_TRUE;
} else {
return FindElementBackground(aForFrame, rootElementFrame, aBackground);
return FindElementBackground(aForFrame, rootElementFrame, aBackgroundSC);
}
}
@ -1387,8 +1387,8 @@ nsCSSRendering::PaintBackground(nsPresContext* aPresContext,
NS_PRECONDITION(aForFrame,
"Frame is expected to be provided to PaintBackground");
const nsStyleBackground *background;
if (!FindBackground(aPresContext, aForFrame, &background)) {
nsStyleContext *sc;
if (!FindBackground(aPresContext, aForFrame, &sc)) {
// We don't want to bail out if moz-appearance is set on a root
// node. If it has a parent content node, bail because it's not
// a root, other wise keep going in order to let the theme stuff
@ -1403,11 +1403,11 @@ nsCSSRendering::PaintBackground(nsPresContext* aPresContext,
return;
}
background = aForFrame->GetStyleBackground();
sc = aForFrame->GetStyleContext();
}
PaintBackgroundWithSC(aPresContext, aRenderingContext, aForFrame,
aDirtyRect, aBorderArea, *background,
aDirtyRect, aBorderArea, sc,
*aForFrame->GetStyleBorder(), aFlags,
aBGClipRect);
}
@ -1548,7 +1548,7 @@ SetupBackgroundClip(gfxContext *aCtx, PRUint8 aBackgroundClip,
static nscolor
DetermineBackgroundColorInternal(nsPresContext* aPresContext,
const nsStyleBackground& aBackground,
nsStyleContext* aStyleContext,
nsIFrame* aFrame,
PRBool& aDrawBackgroundImage,
PRBool& aDrawBackgroundColor)
@ -1562,8 +1562,9 @@ DetermineBackgroundColorInternal(nsPresContext* aPresContext,
}
nscolor bgColor;
const nsStyleBackground *bg = aStyleContext->GetStyleBackground();
if (aDrawBackgroundColor) {
bgColor = aBackground.mBackgroundColor;
bgColor = bg->mBackgroundColor;
if (NS_GET_A(bgColor) == 0)
aDrawBackgroundColor = PR_FALSE;
} else {
@ -1572,7 +1573,7 @@ DetermineBackgroundColorInternal(nsPresContext* aPresContext,
// transparent, but we are expected to use white instead of whatever
// color was specified.
bgColor = NS_RGB(255, 255, 255);
if (aDrawBackgroundImage || !aBackground.IsTransparent())
if (aDrawBackgroundImage || !bg->IsTransparent())
aDrawBackgroundColor = PR_TRUE;
else
bgColor = NS_RGBA(0,0,0,0);
@ -1583,13 +1584,13 @@ DetermineBackgroundColorInternal(nsPresContext* aPresContext,
nscolor
nsCSSRendering::DetermineBackgroundColor(nsPresContext* aPresContext,
const nsStyleBackground& aBackground,
nsStyleContext* aStyleContext,
nsIFrame* aFrame)
{
PRBool drawBackgroundImage;
PRBool drawBackgroundColor;
return DetermineBackgroundColorInternal(aPresContext,
aBackground,
aStyleContext,
aFrame,
drawBackgroundImage,
drawBackgroundColor);
@ -2062,7 +2063,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
nsIFrame* aForFrame,
const nsRect& aDirtyRect,
const nsRect& aBorderArea,
const nsStyleBackground& aBackground,
nsStyleContext* aBackgroundSC,
const nsStyleBorder& aBorder,
PRUint32 aFlags,
nsRect* aBGClipRect)
@ -2098,7 +2099,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
PRBool drawBackgroundColor;
nscolor bgColor = DetermineBackgroundColorInternal(aPresContext,
aBackground,
aBackgroundSC,
aForFrame,
drawBackgroundImage,
drawBackgroundColor);
@ -2132,6 +2133,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
// SetupCurrentBackgroundClip. (Arguably it should be the
// intersection, but that breaks the table painter -- in particular,
// taking the intersection breaks reftests/bugs/403249-1[ab].)
const nsStyleBackground *bg = aBackgroundSC->GetStyleBackground();
nsRect bgClipArea, dirtyRect;
gfxRect dirtyRectGfx;
PRUint8 currentBackgroundClip;
@ -2150,7 +2152,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
// radii as the border code will.
// The background-color is drawn based on the bottom
// background-clip.
currentBackgroundClip = aBackground.BottomLayer().mClip;
currentBackgroundClip = bg->BottomLayer().mClip;
isSolidBorder =
(aFlags & PAINTBG_WILL_PAINT_BORDER) && IsOpaqueBorder(aBorder);
if (isSolidBorder)
@ -2180,12 +2182,12 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
// Ensure we get invalidated for loads of the image. We need to do
// this here because this might be the only code that knows about the
// association of the style data with the frame.
aPresContext->SetupBackgroundImageLoaders(aForFrame, &aBackground);
aPresContext->SetupBackgroundImageLoaders(aForFrame, bg);
// We can skip painting the background color if a background image is opaque.
if (drawBackgroundColor &&
aBackground.BottomLayer().mRepeat == NS_STYLE_BG_REPEAT_XY &&
aBackground.BottomLayer().mImage.IsOpaque())
bg->BottomLayer().mRepeat == NS_STYLE_BG_REPEAT_XY &&
bg->BottomLayer().mImage.IsOpaque())
drawBackgroundColor = PR_FALSE;
// The background color is rendered over the entire dirty area,
@ -2199,8 +2201,8 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
}
if (drawBackgroundImage) {
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, &aBackground) {
const nsStyleBackground::Layer &layer = aBackground.mLayers[i];
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
const nsStyleBackground::Layer &layer = bg->mLayers[i];
if (!aBGClipRect) {
PRUint8 newBackgroundClip =
isSolidBorder ? NS_STYLE_BG_CLIP_PADDING : layer.mClip;
@ -2214,7 +2216,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
}
if (!dirtyRectGfx.IsEmpty()) {
PaintBackgroundLayer(aPresContext, aRenderingContext, aForFrame, aFlags,
dirtyRect, aBorderArea, bgClipArea, aBackground,
dirtyRect, aBorderArea, bgClipArea, *bg,
layer);
}
}

View File

@ -152,21 +152,21 @@ struct nsCSSRendering {
static PRBool IsCanvasFrame(nsIFrame* aFrame);
/**
* Fill in an nsStyleBackground to be used to paint the background
* Fill in an aBackgroundSC to be used to paint the background
* for an element. This applies the rules for propagating
* backgrounds between BODY, the root element, and the canvas.
* @return PR_TRUE if there is some meaningful background.
*/
static PRBool FindBackground(nsPresContext* aPresContext,
nsIFrame* aForFrame,
const nsStyleBackground** aBackground);
nsStyleContext** aBackgroundSC);
/**
* As FindBackground, but the passed-in frame is known to be a root frame
* (returned from nsCSSFrameConstructor::GetRootElementStyleFrame())
* and there is always some meaningful background returned.
*/
static const nsStyleBackground* FindRootFrameBackground(nsIFrame* aForFrame);
static nsStyleContext* FindRootFrameBackground(nsIFrame* aForFrame);
/**
* Returns background style information for the canvas.
@ -179,7 +179,7 @@ struct nsCSSRendering {
* @param aBackground
* contains background style information for the canvas on return
*/
static const nsStyleBackground*
static nsStyleContext*
FindCanvasBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame)
{
NS_ABORT_IF_FALSE(IsCanvasFrame(aForFrame), "not a canvas frame");
@ -189,7 +189,7 @@ struct nsCSSRendering {
// This should always give transparent, so we'll fill it in with the
// default color if needed. This seems to happen a bit while a page is
// being loaded.
return aForFrame->GetStyleBackground();
return aForFrame->GetStyleContext();
}
/**
@ -210,7 +210,7 @@ struct nsCSSRendering {
*/
static nscolor
DetermineBackgroundColor(nsPresContext* aPresContext,
const nsStyleBackground& aBackground,
nsStyleContext* aStyleContext,
nsIFrame* aFrame);
/**
@ -248,7 +248,7 @@ struct nsCSSRendering {
nsIFrame* aForFrame,
const nsRect& aDirtyRect,
const nsRect& aBorderArea,
const nsStyleBackground& aBackground,
nsStyleContext *aStyleContext,
const nsStyleBorder& aBorder,
PRUint32 aFlags,
nsRect* aBGClipRect = nsnull);

View File

@ -1072,10 +1072,10 @@ nsDisplayBackground::IsOpaque(nsDisplayListBuilder* aBuilder) {
if (mIsThemed)
return PR_FALSE;
const nsStyleBackground* bg;
if (!nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bg))
nsStyleContext *bgSC;
if (!nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bgSC))
return PR_FALSE;
const nsStyleBackground* bg = bgSC->GetStyleBackground();
const nsStyleBackground::Layer& bottomLayer = bg->BottomLayer();
@ -1098,11 +1098,12 @@ nsDisplayBackground::IsUniform(nsDisplayListBuilder* aBuilder) {
if (mIsThemed)
return PR_FALSE;
const nsStyleBackground* bg;
nsStyleContext *bgSC;
PRBool hasBG =
nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bg);
nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bgSC);
if (!hasBG)
return PR_TRUE;
const nsStyleBackground* bg = bgSC->GetStyleBackground();
if (bg->BottomLayer().mImage.IsEmpty() &&
bg->mImageCount == 1 &&
!nsLayoutUtils::HasNonZeroCorner(mFrame->GetStyleBorder()->mBorderRadius) &&
@ -1118,11 +1119,12 @@ nsDisplayBackground::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuild
"IsVaryingRelativeToMovingFrame called on non-moving frame!");
nsPresContext* presContext = mFrame->PresContext();
const nsStyleBackground* bg;
nsStyleContext *bgSC;
PRBool hasBG =
nsCSSRendering::FindBackground(presContext, mFrame, &bg);
nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bgSC);
if (!hasBG)
return PR_FALSE;
const nsStyleBackground* bg = bgSC->GetStyleBackground();
if (!bg->HasFixedBackground())
return PR_FALSE;

View File

@ -3259,11 +3259,12 @@ nsLayoutUtils::GetFrameTransparency(nsIFrame* aBackgroundFrame,
return eTransparencyOpaque;
}
const nsStyleBackground* bg;
nsStyleContext* bgSC;
if (!nsCSSRendering::FindBackground(aBackgroundFrame->PresContext(),
aBackgroundFrame, &bg)) {
aBackgroundFrame, &bgSC)) {
return eTransparencyTransparent;
}
const nsStyleBackground* bg = bgSC->GetStyleBackground();
if (NS_GET_A(bg->mBackgroundColor) < 255 ||
// bottom layer's clip is used for the color
bg->BottomLayer().mClip != NS_STYLE_BG_CLIP_BORDER)

View File

@ -5584,14 +5584,14 @@ void PresShell::UpdateCanvasBackground()
// cache of that color.
nsIFrame* rootFrame = FrameConstructor()->GetRootElementStyleFrame();
if (rootFrame) {
const nsStyleBackground* bgStyle =
nsStyleContext* bgStyle =
nsCSSRendering::FindRootFrameBackground(rootFrame);
// XXX We should really be passing the canvasframe, not the root element
// style frame but we don't have access to the canvasframe here. It isn't
// a problem because only a few frames can return something other than true
// and none of them would be a canvas frame or root element style frame.
mCanvasBackgroundColor =
nsCSSRendering::DetermineBackgroundColor(GetPresContext(), *bgStyle,
nsCSSRendering::DetermineBackgroundColor(GetPresContext(), bgStyle,
rootFrame);
}

View File

@ -586,8 +586,9 @@ nsCanvasFrame::Reflow(nsPresContext* aPresContext,
if (nsSize(aDesiredSize.width, aDesiredSize.height) != GetSize()) {
nsIFrame* rootElementFrame =
aPresContext->PresShell()->FrameConstructor()->GetRootElementStyleFrame();
const nsStyleBackground* bg =
nsStyleContext* bgSC =
nsCSSRendering::FindCanvasBackground(this, rootElementFrame);
const nsStyleBackground* bg = bgSC->GetStyleBackground();
if (!bg->IsTransparent()) {
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
const nsStyleBackground::Layer& layer = bg->mLayers[i];

View File

@ -3992,8 +3992,8 @@ nsFrame::CheckInvalidateSizeChange(nsHTMLReflowMetrics& aNewDesiredSize)
static void
InvalidateRectForFrameSizeChange(nsIFrame* aFrame, const nsRect& aRect)
{
const nsStyleBackground* bg;
if (!nsCSSRendering::FindBackground(aFrame->PresContext(), aFrame, &bg)) {
nsStyleContext *bgSC;
if (!nsCSSRendering::FindBackground(aFrame->PresContext(), aFrame, &bgSC)) {
nsIFrame* rootFrame =
aFrame->PresContext()->PresShell()->FrameManager()->GetRootFrame();
rootFrame->Invalidate(nsRect(nsPoint(0, 0), rootFrame->GetSize()));

View File

@ -1933,10 +1933,10 @@ void nsDisplayMathMLCharBackground::Paint(nsDisplayListBuilder* aBuilder,
nsIRenderingContext* aCtx)
{
const nsStyleBorder* border = mStyleContext->GetStyleBorder();
const nsStyleBackground* backg = mStyleContext->GetStyleBackground();
nsRect rect(mRect + aBuilder->ToReferenceFrame(mFrame));
nsCSSRendering::PaintBackgroundWithSC(mFrame->PresContext(), *aCtx, mFrame,
mVisibleRect, rect, *backg, *border,
mVisibleRect, rect,
mStyleContext, *border,
aBuilder->GetBackgroundPaintFlags());
}

View File

@ -1181,6 +1181,6 @@ nsBCTableCellFrame::PaintBackground(nsIRenderingContext& aRenderingContext,
// of frame cannot be used for the root element
nsCSSRendering::PaintBackgroundWithSC(PresContext(), aRenderingContext, this,
aDirtyRect, rect,
*GetStyleBackground(), myBorder,
GetStyleContext(), myBorder,
aFlags, nsnull);
}

View File

@ -1119,10 +1119,10 @@ nsDisplayTableItem::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilde
/* static */ void
nsDisplayTableItem::UpdateForFrameBackground(nsIFrame* aFrame)
{
const nsStyleBackground* bg;
if (!nsCSSRendering::FindBackground(aFrame->PresContext(), aFrame, &bg))
nsStyleContext *bgSC;
if (!nsCSSRendering::FindBackground(aFrame->PresContext(), aFrame, &bgSC))
return;
if (!bg->HasFixedBackground())
if (!bgSC->GetStyleBackground()->HasFixedBackground())
return;
mPartHasFixedBackground = PR_TRUE;

View File

@ -135,7 +135,7 @@
TableBackgroundPainter::TableBackgroundData::TableBackgroundData()
: mFrame(nsnull),
mBackground(nsnull),
mVisible(PR_FALSE),
mBorder(nsnull),
mSynthBorder(nsnull)
{
@ -164,7 +164,7 @@ TableBackgroundPainter::TableBackgroundData::Clear()
mRect.Empty();
mFrame = nsnull;
mBorder = nsnull;
mBackground = nsnull;
mVisible = PR_FALSE;
}
void
@ -180,7 +180,7 @@ TableBackgroundPainter::TableBackgroundData::SetData()
{
NS_PRECONDITION(mFrame, "null frame");
if (mFrame->IsVisibleForPainting()) {
mBackground = mFrame->GetStyleBackground();
mVisible = PR_TRUE;
mBorder = mFrame->GetStyleBorder();
}
}
@ -197,12 +197,13 @@ inline PRBool
TableBackgroundPainter::TableBackgroundData::ShouldSetBCBorder()
{
/* we only need accurate border data when positioning background images*/
if (!mBackground) {
if (!mVisible) {
return PR_FALSE;
}
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, mBackground) {
if (!mBackground->mLayers[i].mImage.IsEmpty())
const nsStyleBackground *bg = mFrame->GetStyleBackground();
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
if (!bg->mLayers[i].mImage.IsEmpty())
return PR_TRUE;
}
return PR_FALSE;
@ -324,7 +325,7 @@ TableBackgroundPainter::PaintTableFrame(nsTableFrame* aTableFrame,
nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
tableData.mFrame, mDirtyRect,
tableData.mRect + mRenderPt,
*tableData.mBackground,
tableData.mFrame->GetStyleContext(),
*tableData.mBorder,
mBGPaintFlags);
}
@ -633,7 +634,7 @@ TableBackgroundPainter::PaintCell(nsTableCellFrame* aCell,
nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
mCols[colIndex].mColGroup->mFrame, mDirtyRect,
mCols[colIndex].mColGroup->mRect + mRenderPt,
*mCols[colIndex].mColGroup->mBackground,
mCols[colIndex].mColGroup->mFrame->GetStyleContext(),
*mCols[colIndex].mColGroup->mBorder,
mBGPaintFlags, &mCellRect);
}
@ -643,7 +644,7 @@ TableBackgroundPainter::PaintCell(nsTableCellFrame* aCell,
nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
mCols[colIndex].mCol.mFrame, mDirtyRect,
mCols[colIndex].mCol.mRect + mRenderPt,
*mCols[colIndex].mCol.mBackground,
mCols[colIndex].mCol.mFrame->GetStyleContext(),
*mCols[colIndex].mCol.mBorder,
mBGPaintFlags, &mCellRect);
}
@ -653,7 +654,8 @@ TableBackgroundPainter::PaintCell(nsTableCellFrame* aCell,
nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
mRowGroup.mFrame, mDirtyRect,
mRowGroup.mRect + mRenderPt,
*mRowGroup.mBackground, *mRowGroup.mBorder,
mRowGroup.mFrame->GetStyleContext(),
*mRowGroup.mBorder,
mBGPaintFlags, &mCellRect);
}
@ -662,7 +664,8 @@ TableBackgroundPainter::PaintCell(nsTableCellFrame* aCell,
nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
mRow.mFrame, mDirtyRect,
mRow.mRect + mRenderPt,
*mRow.mBackground, *mRow.mBorder,
mRow.mFrame->GetStyleContext(),
*mRow.mBorder,
mBGPaintFlags, &mCellRect);
}

View File

@ -183,11 +183,11 @@ class TableBackgroundPainter
nsIFrame* mFrame;
/** mRect is the rect of mFrame in the current coordinate system */
nsRect mRect;
const nsStyleBackground* mBackground;
PRBool mVisible;
const nsStyleBorder* mBorder;
/** Data is valid & frame is visible */
PRBool IsVisible() const { return mBackground != nsnull; }
PRBool IsVisible() const { return mVisible; }
/** Constructor */
TableBackgroundData();

View File

@ -3900,13 +3900,12 @@ nsTreeBodyFrame::PaintBackgroundLayer(nsStyleContext* aStyleContext,
const nsRect& aRect,
const nsRect& aDirtyRect)
{
const nsStyleBackground* myColor = aStyleContext->GetStyleBackground();
const nsStyleBorder* myBorder = aStyleContext->GetStyleBorder();
const nsStyleOutline* myOutline = aStyleContext->GetStyleOutline();
nsCSSRendering::PaintBackgroundWithSC(aPresContext, aRenderingContext,
this, aDirtyRect, aRect,
*myColor, *myBorder,
aStyleContext, *myBorder,
nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES);
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,