Bug 1261578 - Part 1. Correct text color in selection range;
MozReview-Commit-ID: 9gBWQ00MtNC
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -3603,20 +3603,18 @@ nsTextPaintStyle::GetTextColor()
case eStyleSVGPaintType_Color:
return nsLayoutUtils::GetColor(mFrame, eCSSProperty_fill);
default:
NS_ERROR("cannot resolve SVG paint to nscolor");
return NS_RGBA(0, 0, 0, 255);
}
}
- nsCSSProperty property =
- mFrame->StyleText()->mWebkitTextFillColorForeground
- ? eCSSProperty_color : eCSSProperty__webkit_text_fill_color;
- return nsLayoutUtils::GetColor(mFrame, property);
+ return nsLayoutUtils::GetColor(mFrame,
+ mFrame->StyleContext()->GetTextFillColorProp());
}
bool
nsTextPaintStyle::GetSelectionColors(nscolor* aForeColor,
nscolor* aBackColor)
{
NS_ASSERTION(aForeColor, "aForeColor is null");
NS_ASSERTION(aBackColor, "aBackColor is null");
@@ -3799,17 +3797,17 @@ nsTextPaintStyle::InitSelectionColorsAnd
sc = mPresContext->StyleSet()->
ProbePseudoElementStyle(selectionElement,
CSSPseudoElementType::mozSelection,
mFrame->StyleContext());
// Use -moz-selection pseudo class.
if (sc) {
mSelectionBGColor =
sc->GetVisitedDependentColor(eCSSProperty_background_color);
- mSelectionTextColor = sc->GetVisitedDependentColor(eCSSProperty_color);
+ mSelectionTextColor = sc->GetVisitedDependentColor(sc->GetTextFillColorProp());
mHasSelectionShadow =
nsRuleNode::HasAuthorSpecifiedRules(sc,
NS_AUTHOR_SPECIFIED_TEXT_SHADOW,
true);
if (mHasSelectionShadow) {
mSelectionShadow = sc->StyleText()->mTextShadow;
}
return true;
@@ -3835,23 +3833,25 @@ nsTextPaintStyle::InitSelectionColorsAnd
}
mSelectionTextColor =
LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectForeground);
if (mResolveColors) {
// On MacOS X, we don't exchange text color and BG color.
if (mSelectionTextColor == NS_DONT_CHANGE_COLOR) {
- nsCSSProperty property = mFrame->IsSVGText() ? eCSSProperty_fill :
- eCSSProperty_color;
+ nsCSSProperty property = mFrame->IsSVGText()
+ ? eCSSProperty_fill
+ : mFrame->StyleContext()->GetTextFillColorProp();
nscoord frameColor = mFrame->GetVisitedDependentColor(property);
mSelectionTextColor = EnsureDifferentColors(frameColor, mSelectionBGColor);
} else if (mSelectionTextColor == NS_CHANGE_COLOR_IF_SAME_AS_BG) {
- nsCSSProperty property = mFrame->IsSVGText() ? eCSSProperty_fill :
- eCSSProperty_color;
+ nsCSSProperty property = mFrame->IsSVGText()
+ ? eCSSProperty_fill
+ : mFrame->StyleContext()->GetTextFillColorProp();
nscolor frameColor = mFrame->GetVisitedDependentColor(property);
if (frameColor == mSelectionBGColor) {
mSelectionTextColor =
LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectForegroundCustom);
}
} else {
EnsureSufficientContrast(&mSelectionTextColor, &mSelectionBGColor);
}
--- a/layout/style/nsStyleContext.h
+++ b/layout/style/nsStyleContext.h
@@ -166,25 +166,31 @@ public:
// * !!GetStyleIfVisited() == !!aSourceIfVisited, and, if they're
// non-null, GetStyleIfVisited()->mSource == aSourceIfVisited
// * RelevantLinkVisited() == aRelevantLinkVisited
already_AddRefed<nsStyleContext>
FindChildWithRules(const nsIAtom* aPseudoTag,
mozilla::NonOwningStyleContextSource aSource,
mozilla::NonOwningStyleContextSource aSourceIfVisited,
bool aRelevantLinkVisited);
+ /**
+ * Get the color property that should be used to fill text.
+ */
+ nsCSSProperty GetTextFillColorProp() {
+ return StyleText()->mWebkitTextFillColorForeground
+ ? eCSSProperty_color : eCSSProperty__webkit_text_fill_color;
+ }
/**
* Get the color that should be used to fill text: either
* the current foreground color, or a separately-specified text fill color.
*/
nscolor GetTextFillColor() {
- const nsStyleText* textStyle = StyleText();
- return textStyle->mWebkitTextFillColorForeground
- ? StyleColor()->mColor : textStyle->mWebkitTextFillColor;
+ return (GetTextFillColorProp() == eCSSProperty_color)
+ ? StyleColor()->mColor : StyleText()->mWebkitTextFillColor;
}
// Does this style context or any of its ancestors have text
// decoration lines?
// Differs from nsStyleTextReset::HasTextDecorationLines, which tests
// only the data for a single context.
bool HasTextDecorationLines() const
{ return !!(mBits & NS_STYLE_HAS_TEXT_DECORATION_LINES); }