From 78c4bdc4bd57414ee0cc16e41d05f1160928efbf Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Fri, 2 Apr 2010 18:58:26 -0700 Subject: [PATCH] Use the appropriate color based on visitedness for the 'background-color' property. (Bug 147777) r=zweinberg --- layout/base/nsCSSRendering.cpp | 23 ++++++++++++++++------- layout/generic/nsObjectFrame.cpp | 7 ++++--- layout/generic/nsTextFrameThebes.cpp | 10 +++++----- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 972b0c34317..02cfa2592f0 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -575,7 +575,8 @@ nsCSSRendering::PaintBorder(nsPresContext* aPresContext, // for determining the background color nsStyleContext* bgContext = nsCSSRendering::FindNonTransparentBackground (aStyleContext, compatMode == eCompatibility_NavQuirks ? PR_TRUE : PR_FALSE); - const nsStyleBackground* bgColor = bgContext->GetStyleBackground(); + nscolor bgColor = + bgContext->GetVisitedDependentColor(eCSSProperty_background_color); border = aStyleBorder.GetComputedBorder(); if ((0 == border.left) && (0 == border.right) && @@ -659,7 +660,7 @@ nsCSSRendering::PaintBorder(nsPresContext* aPresContext, borderColors, compositeColors, aSkipSides, - bgColor->mBackgroundColor); + bgColor); br.DrawBorders(); ctx->Restore(); @@ -702,7 +703,8 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext, nsStyleContext* bgContext = nsCSSRendering::FindNonTransparentBackground (aStyleContext, PR_FALSE); - const nsStyleBackground* bgColor = bgContext->GetStyleBackground(); + nscolor bgColor = + bgContext->GetVisitedDependentColor(eCSSProperty_background_color); // get the radius for our outline GetBorderRadiusTwips(aOutlineStyle.mOutlineRadius, aBorderArea.width, @@ -800,7 +802,7 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext, outlineRadii, outlineColors, nsnull, 0, - bgColor->mBackgroundColor); + bgColor); br.DrawBorders(); ctx->Restore(); @@ -926,6 +928,8 @@ nsCSSRendering::FindNonTransparentBackground(nsStyleContext* aContext, while (context) { const nsStyleBackground* bg = context->GetStyleBackground(); + // No need to call GetVisitedDependentColor because it always uses + // this alpha component anyway. if (NS_GET_A(bg->mBackgroundColor) > 0) break; @@ -1562,9 +1566,9 @@ DetermineBackgroundColorInternal(nsPresContext* aPresContext, } nscolor bgColor; - const nsStyleBackground *bg = aStyleContext->GetStyleBackground(); if (aDrawBackgroundColor) { - bgColor = bg->mBackgroundColor; + bgColor = + aStyleContext->GetVisitedDependentColor(eCSSProperty_background_color); if (NS_GET_A(bgColor) == 0) aDrawBackgroundColor = PR_FALSE; } else { @@ -1573,7 +1577,8 @@ 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 || !bg->IsTransparent()) + if (aDrawBackgroundImage || + !aStyleContext->GetStyleBackground()->IsTransparent()) aDrawBackgroundColor = PR_TRUE; else bgColor = NS_RGBA(0,0,0,0); @@ -3016,6 +3021,8 @@ nsCSSRendering::DrawTableBorderSegment(nsIRenderingContext& aContext, nscoord endBevel = (aEndBevelOffset > 0) ? RoundFloatToPixel(0.5f * (float)aEndBevelOffset, twipsPerPixel, PR_TRUE) : 0; PRUint8 ridgeGrooveSide = (horizontal) ? NS_SIDE_TOP : NS_SIDE_LEFT; + // FIXME: In theory, this should use the visited-dependent + // background color, but I don't care. aContext.SetColor ( MakeBevelColor(ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor)); nsRect rect(aBorder); @@ -3049,6 +3056,8 @@ nsCSSRendering::DrawTableBorderSegment(nsIRenderingContext& aContext, rect = aBorder; ridgeGrooveSide = (NS_SIDE_TOP == ridgeGrooveSide) ? NS_SIDE_BOTTOM : NS_SIDE_RIGHT; + // FIXME: In theory, this should use the visited-dependent + // background color, but I don't care. aContext.SetColor ( MakeBevelColor(ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor)); if (horizontal) { diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index 50b14021897..34a318374d7 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -753,9 +753,10 @@ nsObjectFrame::CreateWidget(nscoord aWidth, // Sometimes, a frame doesn't have a background color or is transparent. In this // case, walk up the frame tree until we do find a frame with a background color for (nsIFrame* frame = this; frame; frame = frame->GetParent()) { - const nsStyleBackground* background = frame->GetStyleBackground(); - if (!background->IsTransparent()) { // make sure we got an actual color - mWidget->SetBackgroundColor(background->mBackgroundColor); + nscolor bgcolor = + frame->GetVisitedDependentColor(eCSSProperty_background_color); + if (NS_GET_A(bgcolor) > 0) { // make sure we got an actual color + mWidget->SetBackgroundColor(bgcolor); break; } } diff --git a/layout/generic/nsTextFrameThebes.cpp b/layout/generic/nsTextFrameThebes.cpp index 6280b7d6cee..a6d2746dc1c 100644 --- a/layout/generic/nsTextFrameThebes.cpp +++ b/layout/generic/nsTextFrameThebes.cpp @@ -3092,11 +3092,11 @@ nsTextPaintStyle::InitCommonColors() nsStyleContext* bgContext = nsCSSRendering::FindNonTransparentBackground(sc); NS_ASSERTION(bgContext, "Cannot find NonTransparentBackground."); - const nsStyleBackground* bg = bgContext->GetStyleBackground(); + nscolor bgColor = + bgContext->GetVisitedDependentColor(eCSSProperty_background_color); nscolor defaultBgColor = mPresContext->DefaultBackgroundColor(); - mFrameBackgroundColor = NS_ComposeColors(defaultBgColor, - bg->mBackgroundColor); + mFrameBackgroundColor = NS_ComposeColors(defaultBgColor, bgColor); if (bgContext->GetStyleDisplay()->mAppearance) { // Assume a native widget has sufficient contrast always @@ -3166,8 +3166,8 @@ nsTextPaintStyle::InitSelectionColors() mFrame->GetStyleContext()); // Use -moz-selection pseudo class. if (sc) { - const nsStyleBackground* bg = sc->GetStyleBackground(); - mSelectionBGColor = bg->mBackgroundColor; + mSelectionBGColor = + sc->GetVisitedDependentColor(eCSSProperty_background_color); mSelectionTextColor = sc->GetVisitedDependentColor(eCSSProperty_color); return PR_TRUE; }