Skip to content

Commit

Permalink
Bug 1303241 part 2 - Make GetVisitedDependentColor use style structs …
Browse files Browse the repository at this point in the history
…directly. r=dbaron

I think there are three advantages of this change:
1. removes some dependencies from layout / painting code to pre-computed
   value stuff in the style system;
2. makes it easier to audit usage of specific fields in style structs
   (which is probably a side effect of the first one);
3. potentially improves performance since it doesn't go through the
   unnecessary general logic in ExtractComputedValue.

Also, combined with the part before, we get a unified list for visited-
dependent properties so that we can ensure the assertion here and the
style difference calc code are consistent.

MozReview-Commit-ID: 5B9aN7CfRgI

--HG--
extra : rebase_source : ac80eaea2474b9ec4b47b1cc9a5bdd2e61f6ec4d
  • Loading branch information
upsuper committed Dec 30, 2016
1 parent 801cd27 commit 97d13f4
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 120 deletions.
7 changes: 3 additions & 4 deletions layout/base/nsLayoutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5578,13 +5578,12 @@ ShouldDarkenColors(nsPresContext* aPresContext)
}

nscolor
nsLayoutUtils::GetColor(nsIFrame* aFrame, nsCSSPropertyID aProperty)
nsLayoutUtils::DarkenColorIfNeeded(nsIFrame* aFrame, nscolor aColor)
{
nscolor color = aFrame->GetVisitedDependentColor(aProperty);
if (ShouldDarkenColors(aFrame->PresContext())) {
color = DarkenColor(color);
return DarkenColor(aColor);
}
return color;
return aColor;
}

gfxFloat
Expand Down
14 changes: 12 additions & 2 deletions layout/base/nsLayoutUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,18 @@ class nsLayoutUtils
static nscoord MinISizeFromInline(nsIFrame* aFrame,
nsRenderingContext* aRenderingContext);

// Get a suitable foreground color for painting aProperty for aFrame.
static nscolor GetColor(nsIFrame* aFrame, nsCSSPropertyID aProperty);
// Get a suitable foreground color for painting aColor for aFrame.
static nscolor DarkenColorIfNeeded(nsIFrame* aFrame, nscolor aColor);

// Get a suitable foreground color for painting aField for aFrame.
// Type of aFrame is made a template parameter because nsIFrame is not
// a complete type in the header. Type-safety is not harmed given that
// DarkenColorIfNeeded requires an nsIFrame pointer.
template<typename Frame, typename T, typename S>
static nscolor GetColor(Frame* aFrame, T S::* aField) {
nscolor color = aFrame->GetVisitedDependentColor(aField);
return DarkenColorIfNeeded(aFrame, color);
}

// Get a baseline y position in app units that is snapped to device pixels.
static gfxFloat GetSnappedBaselineY(nsIFrame* aFrame, gfxContext* aContext,
Expand Down
2 changes: 1 addition & 1 deletion layout/generic/TextOverflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ nsDisplayTextOverflowMarker::Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx)
{
nscolor foregroundColor = nsLayoutUtils::
GetColor(mFrame, eCSSProperty__webkit_text_fill_color);
GetColor(mFrame, &nsStyleText::mWebkitTextFillColor);

// Paint the text-shadows for the overflow marker
nsLayoutUtils::PaintTextShadow(mFrame, aCtx, mRect, mVisibleRect,
Expand Down
4 changes: 2 additions & 2 deletions layout/generic/nsBulletFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
}

ColorPattern color(ToDeviceColor(
nsLayoutUtils::GetColor(this, eCSSProperty_color)));
nsLayoutUtils::GetColor(this, &nsStyleColor::mColor)));

DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
Expand Down Expand Up @@ -423,7 +423,7 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
disable(aRenderingContext.GetDrawTarget(), aDisableSubpixelAA);

aRenderingContext.ThebesContext()->SetColor(
Color::FromABGR(nsLayoutUtils::GetColor(this, eCSSProperty_color)));
Color::FromABGR(nsLayoutUtils::GetColor(this, &nsStyleColor::mColor)));

RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForFrame(this, GetFontSizeInflation());
Expand Down
2 changes: 1 addition & 1 deletion layout/generic/nsColumnSetFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ nsColumnSetFrame::PaintColumnRule(nsRenderingContext* aCtx,
return;

nscolor ruleColor =
GetVisitedDependentColor(eCSSProperty_column_rule_color);
GetVisitedDependentColor(&nsStyleColumn::mColumnRuleColor);

// In order to re-use a large amount of code, we treat the column rule as a border.
// We create a new border style object and fill in all the details of the column rule as
Expand Down
5 changes: 3 additions & 2 deletions layout/generic/nsIFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,9 @@ class nsIFrame : public nsQueryFrame
#undef STYLE_STRUCT

/** Also forward GetVisitedDependentColor to the style context */
nscolor GetVisitedDependentColor(nsCSSPropertyID aProperty)
{ return mStyleContext->GetVisitedDependentColor(aProperty); }
template<typename T, typename S>
nscolor GetVisitedDependentColor(T S::* aField)
{ return mStyleContext->GetVisitedDependentColor(aField); }

/**
* These methods are to access any additional style contexts that
Expand Down
4 changes: 2 additions & 2 deletions layout/generic/nsPluginFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ nsPluginFrame::PrepForDrawing(nsIWidget *aWidget)
// 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()) {
nscolor bgcolor =
frame->GetVisitedDependentColor(eCSSProperty_background_color);
nscolor bgcolor = frame->
GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);
if (NS_GET_A(bgcolor) > 0) { // make sure we got an actual color
mWidget->SetBackgroundColor(bgcolor);
break;
Expand Down
35 changes: 17 additions & 18 deletions layout/generic/nsTextFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3752,14 +3752,14 @@ nsTextPaintStyle::GetTextColor()
case eStyleSVGPaintType_None:
return NS_RGBA(0, 0, 0, 0);
case eStyleSVGPaintType_Color:
return nsLayoutUtils::GetColor(mFrame, eCSSProperty_fill);
return nsLayoutUtils::GetColor(mFrame, &nsStyleSVG::mFill);
default:
NS_ERROR("cannot resolve SVG paint to nscolor");
return NS_RGBA(0, 0, 0, 255);
}
}

return nsLayoutUtils::GetColor(mFrame, eCSSProperty__webkit_text_fill_color);
return nsLayoutUtils::GetColor(mFrame, &nsStyleText::mWebkitTextFillColor);
}

bool
Expand Down Expand Up @@ -3853,8 +3853,8 @@ nsTextPaintStyle::InitCommonColors()
nsIFrame* bgFrame =
nsCSSRendering::FindNonTransparentBackgroundFrame(mFrame);
NS_ASSERTION(bgFrame, "Cannot find NonTransparentBackgroundFrame.");
nscolor bgColor =
bgFrame->GetVisitedDependentColor(eCSSProperty_background_color);
nscolor bgColor = bgFrame->
GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);

nscolor defaultBgColor = mPresContext->DefaultBackgroundColor();
mFrameBackgroundColor = NS_ComposeColors(defaultBgColor, bgColor);
Expand Down Expand Up @@ -3951,9 +3951,9 @@ nsTextPaintStyle::InitSelectionColorsAndShadow()
// Use -moz-selection pseudo class.
if (sc) {
mSelectionBGColor =
sc->GetVisitedDependentColor(eCSSProperty_background_color);
sc->GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);
mSelectionTextColor =
sc->GetVisitedDependentColor(eCSSProperty__webkit_text_fill_color);
sc->GetVisitedDependentColor(&nsStyleText::mWebkitTextFillColor);
mHasSelectionShadow =
nsRuleNode::HasAuthorSpecifiedRules(sc,
NS_AUTHOR_SPECIFIED_TEXT_SHADOW,
Expand Down Expand Up @@ -3989,16 +3989,14 @@ nsTextPaintStyle::InitSelectionColorsAndShadow()
if (mResolveColors) {
// On MacOS X, we don't exchange text color and BG color.
if (mSelectionTextColor == NS_DONT_CHANGE_COLOR) {
nsCSSPropertyID property = mFrame->IsSVGText()
? eCSSProperty_fill
: eCSSProperty__webkit_text_fill_color;
nscoord frameColor = mFrame->GetVisitedDependentColor(property);
nscolor frameColor = mFrame->IsSVGText()
? mFrame->GetVisitedDependentColor(&nsStyleSVG::mFill)
: mFrame->GetVisitedDependentColor(&nsStyleText::mWebkitTextFillColor);
mSelectionTextColor = EnsureDifferentColors(frameColor, mSelectionBGColor);
} else if (mSelectionTextColor == NS_CHANGE_COLOR_IF_SAME_AS_BG) {
nsCSSPropertyID property = mFrame->IsSVGText()
? eCSSProperty_fill
: eCSSProperty__webkit_text_fill_color;
nscolor frameColor = mFrame->GetVisitedDependentColor(property);
nscolor frameColor = mFrame->IsSVGText()
? mFrame->GetVisitedDependentColor(&nsStyleSVG::mFill)
: mFrame->GetVisitedDependentColor(&nsStyleText::mWebkitTextFillColor);
if (frameColor == mSelectionBGColor) {
mSelectionTextColor =
LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectForegroundCustom);
Expand Down Expand Up @@ -5313,7 +5311,7 @@ nsTextFrame::GetTextDecorations(
// la la</font></a> case. The link underline should be green.
useOverride = true;
overrideColor =
nsLayoutUtils::GetColor(f, eCSSProperty_text_decoration_color);
nsLayoutUtils::GetColor(f, &nsStyleTextReset::mTextDecorationColor);
}

nsBlockFrame* fBlock = nsLayoutUtils::GetAsBlock(f);
Expand Down Expand Up @@ -5367,10 +5365,11 @@ nsTextFrame::GetTextDecorations(
// for SVG text, and have e.g. text-decoration-color:red to
// override the fill paint of the decoration.
color = aColorResolution == eResolvedColors ?
nsLayoutUtils::GetColor(f, eCSSProperty_fill) :
nsLayoutUtils::GetColor(f, &nsStyleSVG::mFill) :
NS_SAME_AS_FOREGROUND_COLOR;
} else {
color = nsLayoutUtils::GetColor(f, eCSSProperty_text_decoration_color);
color = nsLayoutUtils::
GetColor(f, &nsStyleTextReset::mTextDecorationColor);
}

bool swapUnderlineAndOverline = vertical && IsUnderlineRight(f);
Expand Down Expand Up @@ -6561,7 +6560,7 @@ nsTextFrame::DrawEmphasisMarks(gfxContext* aContext, WritingMode aWM,

bool isTextCombined = StyleContext()->IsTextCombined();
nscolor color = aDecorationOverrideColor ? *aDecorationOverrideColor :
nsLayoutUtils::GetColor(this, eCSSProperty_text_emphasis_color);
nsLayoutUtils::GetColor(this, &nsStyleText::mTextEmphasisColor);
aContext->SetColor(Color::FromABGR(color));
gfxPoint pt;
if (!isTextCombined) {
Expand Down
2 changes: 1 addition & 1 deletion layout/mathml/nsMathMLChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,7 @@ nsMathMLChar::PaintForeground(nsPresContext* aPresContext,

// Set color ...
nscolor fgColor = styleContext->
GetVisitedDependentColor(eCSSProperty__webkit_text_fill_color);
GetVisitedDependentColor(&nsStyleText::mWebkitTextFillColor);
if (aIsSelected) {
// get color to use for selection from the look&feel object
fgColor = LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectForeground,
Expand Down
2 changes: 1 addition & 1 deletion layout/mathml/nsMathMLFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void nsDisplayMathMLBar::Paint(nsDisplayListBuilder* aBuilder,
mFrame->PresContext()->AppUnitsPerDevPixel(),
*drawTarget);
ColorPattern color(ToDeviceColor(
mFrame->GetVisitedDependentColor(eCSSProperty__webkit_text_fill_color)));
mFrame->GetVisitedDependentColor(&nsStyleText::mWebkitTextFillColor)));
drawTarget->FillRect(rect, color);
}

Expand Down
2 changes: 1 addition & 1 deletion layout/mathml/nsMathMLmencloseFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
rect.Deflate(strokeWidth / 2.f);

ColorPattern color(ToDeviceColor(
mFrame->GetVisitedDependentColor(eCSSProperty__webkit_text_fill_color)));
mFrame->GetVisitedDependentColor(&nsStyleText::mWebkitTextFillColor)));

StrokeOptions strokeOptions(strokeWidth);

Expand Down
2 changes: 1 addition & 1 deletion layout/mathml/nsMathMLmfracFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ void nsDisplayMathMLSlash::Paint(nsDisplayListBuilder* aBuilder,
presContext->AppUnitsPerDevPixel());

ColorPattern color(ToDeviceColor(
mFrame->GetVisitedDependentColor(eCSSProperty__webkit_text_fill_color)));
mFrame->GetVisitedDependentColor(&nsStyleText::mWebkitTextFillColor)));

// draw the slash as a parallelogram
Point delta = Point(presContext->AppUnitsToGfxUnits(mThickness), 0);
Expand Down
22 changes: 11 additions & 11 deletions layout/painting/nsCSSRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,8 @@ nsCSSRendering::PaintBorder(nsPresContext* aPresContext,
nsStyleBorder newStyleBorder(*styleBorder);

NS_FOR_CSS_SIDES(side) {
nscolor color = aStyleContext->GetVisitedDependentColor(
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color)[side]);
nscolor color = aStyleContext->
GetVisitedDependentColor(nsStyleBorder::BorderColorFieldFor(side));
newStyleBorder.mBorderColor[side] = StyleComplexColor::FromColor(color);
}
return PaintBorderWithStyleBorder(aPresContext, aRenderingContext, aForFrame,
Expand Down Expand Up @@ -702,8 +702,8 @@ nsCSSRendering::CreateBorderRenderer(nsPresContext* aPresContext,
nsStyleBorder newStyleBorder(*styleBorder);

NS_FOR_CSS_SIDES(side) {
nscolor color = aStyleContext->GetVisitedDependentColor(
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color)[side]);
nscolor color = aStyleContext->
GetVisitedDependentColor(nsStyleBorder::BorderColorFieldFor(side));
newStyleBorder.mBorderColor[side] = StyleComplexColor::FromColor(color);
}
return CreateBorderRendererWithStyleBorder(aPresContext, aDrawTarget,
Expand Down Expand Up @@ -733,8 +733,8 @@ ConstructBorderRenderer(nsPresContext* aPresContext,
bool quirks = aPresContext->CompatibilityMode() == eCompatibility_NavQuirks;
nsIFrame* bgFrame = nsCSSRendering::FindNonTransparentBackgroundFrame(aForFrame, quirks);
nsStyleContext* bgContext = bgFrame->StyleContext();
nscolor bgColor =
bgContext->GetVisitedDependentColor(eCSSProperty_background_color);
nscolor bgColor = bgContext->
GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);

// Compute the outermost boundary of the area that might be painted.
// Same coordinate space as aBorderArea & aBGClipRect.
Expand Down Expand Up @@ -973,8 +973,8 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext,
nsIFrame* bgFrame = nsCSSRendering::FindNonTransparentBackgroundFrame
(aForFrame, false);
nsStyleContext* bgContext = bgFrame->StyleContext();
nscolor bgColor =
bgContext->GetVisitedDependentColor(eCSSProperty_background_color);
nscolor bgColor = bgContext->
GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);

nsRect innerRect;
if (
Expand Down Expand Up @@ -1041,7 +1041,7 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext,
// This handles treating the initial color as 'currentColor'; if we
// ever want 'invert' back we'll need to do a bit of work here too.
nscolor outlineColor =
aStyleContext->GetVisitedDependentColor(eCSSProperty_outline_color);
aStyleContext->GetVisitedDependentColor(&nsStyleOutline::mOutlineColor);
nscolor outlineColors[4] = { outlineColor,
outlineColor,
outlineColor,
Expand Down Expand Up @@ -2240,8 +2240,8 @@ nsCSSRendering::DetermineBackgroundColor(nsPresContext* aPresContext,
const nsStyleBackground *bg = aStyleContext->StyleBackground();
nscolor bgColor;
if (aDrawBackgroundColor) {
bgColor =
aStyleContext->GetVisitedDependentColor(eCSSProperty_background_color);
bgColor = aStyleContext->
GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);
if (NS_GET_A(bgColor) == 0) {
aDrawBackgroundColor = false;
}
Expand Down
Loading

0 comments on commit 97d13f4

Please sign in to comment.