Bug 1403034: Convert NS_STYLE_COLOR.. and NS_COLOR_* macros to enum class.
MozReview-Commit-ID: L6qaBG7oP3q
--- a/layout/style/Declaration.cpp
+++ b/layout/style/Declaration.cpp
@@ -762,17 +762,17 @@ Declaration::GetPropertyValueInternal(
bool ok = AppendValueToString(subprops[0], aValue);
if (ok) {
aValue.Append(u' ');
ok = AppendValueToString(subprops[1], aValue);
if (ok) {
const nsCSSValue *colorValue = data->ValueFor(subprops[2]);
bool isCurrentColor =
colorValue->GetUnit() == eCSSUnit_EnumColor &&
- colorValue->GetIntValue() == NS_COLOR_CURRENTCOLOR;
+ colorValue->GetIntValue() == static_cast<int32_t>(StyleColor::CurrentColor);
// Don't output a third value when it's currentcolor.
if (!isCurrentColor) {
aValue.Append(u' ');
ok = AppendValueToString(subprops[2], aValue);
}
}
}
@@ -998,17 +998,17 @@ Declaration::GetPropertyValueInternal(
AppendValueToString(eCSSProperty_text_decoration_line, aValue);
if (decorationStyle->GetIntValue() !=
NS_STYLE_TEXT_DECORATION_STYLE_SOLID) {
aValue.Append(char16_t(' '));
AppendValueToString(eCSSProperty_text_decoration_style, aValue);
}
if (decorationColor->GetUnit() != eCSSUnit_EnumColor ||
- decorationColor->GetIntValue() != NS_COLOR_CURRENTCOLOR) {
+ decorationColor->GetIntValue() != static_cast<int32_t>(StyleColor::CurrentColor)) {
aValue.Append(char16_t(' '));
AppendValueToString(eCSSProperty_text_decoration_color, aValue);
}
break;
}
case eCSSProperty_transition: {
const nsCSSValue *transProp =
data->ValueFor(eCSSProperty_transition_property);
@@ -1436,17 +1436,17 @@ Declaration::GetPropertyValueInternal(
break;
}
case eCSSProperty_text_emphasis: {
const nsCSSValue* emphasisStyle =
data->ValueFor(eCSSProperty_text_emphasis_style);
const nsCSSValue* emphasisColor =
data->ValueFor(eCSSProperty_text_emphasis_color);
bool isDefaultColor = emphasisColor->GetUnit() == eCSSUnit_EnumColor &&
- emphasisColor->GetIntValue() == NS_COLOR_CURRENTCOLOR;
+ emphasisColor->GetIntValue() == static_cast<int32_t>(StyleColor::CurrentColor);
if (emphasisStyle->GetUnit() != eCSSUnit_None || isDefaultColor) {
AppendValueToString(eCSSProperty_text_emphasis_style, aValue);
if (!isDefaultColor) {
aValue.Append(char16_t(' '));
}
}
if (!isDefaultColor) {
@@ -1476,17 +1476,17 @@ Declaration::GetPropertyValueInternal(
break;
}
case eCSSProperty__webkit_text_stroke: {
const nsCSSValue* strokeWidth =
data->ValueFor(eCSSProperty__webkit_text_stroke_width);
const nsCSSValue* strokeColor =
data->ValueFor(eCSSProperty__webkit_text_stroke_color);
bool isDefaultColor = strokeColor->GetUnit() == eCSSUnit_EnumColor &&
- strokeColor->GetIntValue() == NS_COLOR_CURRENTCOLOR;
+ strokeColor->GetIntValue() == static_cast<int32_t>(StyleColor::CurrentColor);
if (strokeWidth->GetUnit() != eCSSUnit_Integer ||
strokeWidth->GetIntValue() != 0 || isDefaultColor) {
AppendValueToString(eCSSProperty__webkit_text_stroke_width, aValue);
if (!isDefaultColor) {
aValue.Append(char16_t(' '));
}
}
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -3729,17 +3729,17 @@ StyleAnimationValue::UncomputeValue(nsCS
case eUnit_Percent:
aSpecifiedValue.SetPercentValue(aComputedValue.GetPercentValue());
break;
case eUnit_Float:
aSpecifiedValue.
SetFloatValue(aComputedValue.GetFloatValue(), eCSSUnit_Number);
break;
case eUnit_CurrentColor:
- aSpecifiedValue.SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
+ aSpecifiedValue.SetIntValue(static_cast<int32_t>(StyleColor::CurrentColor), eCSSUnit_EnumColor);
break;
case eUnit_Calc:
case eUnit_Color:
case eUnit_ObjectPosition:
case eUnit_URL:
case eUnit_DiscreteCSSValue: {
nsCSSValue* val = aComputedValue.GetCSSValueValue();
// Sanity-check that the underlying unit in the nsCSSValue is what we
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -6550,17 +6550,17 @@ GetEnumColorValue(nsCSSKeyword aKeyword,
{
int32_t value;
if (!nsCSSProps::FindKeyword(aKeyword, nsCSSProps::kColorKTable, value)) {
// Unknown color keyword.
return Nothing();
}
if (value < 0) {
// Known special color keyword handled by style system,
- // e.g. NS_COLOR_CURRENTCOLOR. See nsStyleConsts.h.
+ // e.g. StyleColor::CurrentColor. See nsStyleConsts.h.
return Some(value);
}
nscolor color;
auto colorID = static_cast<LookAndFeel::ColorID>(value);
if (NS_FAILED(LookAndFeel::GetColor(colorID, !aIsChrome, &color))) {
// Known LookAndFeel::ColorID, but this platform's LookAndFeel impl
// doesn't map it to a color. (This might be a platform-specific
// ColorID, which only makes sense on another platform.)
@@ -10691,17 +10691,17 @@ CSSParserImpl::ParseWebkitGradientColorS
// Unrecognized function name (invalid for a -webkit-gradient color stop).
UngetToken();
return false;
}
CSSParseResult result = ParseVariant(stop->mColor, VARIANT_COLOR, nullptr);
if (result != CSSParseResult::Ok ||
(stop->mColor.GetUnit() == eCSSUnit_EnumColor &&
- stop->mColor.GetIntValue() == NS_COLOR_CURRENTCOLOR)) {
+ stop->mColor.GetIntValue() == static_cast<int32_t>(StyleColor::CurrentColor))) {
// Parse failure, or parsed "currentColor" which is forbidden in
// -webkit-gradient for some reason.
SkipUntil(')');
return false;
}
// Parse color-stop function close-paren
if (!ExpectSymbol(')', true)) {
@@ -11013,17 +11013,17 @@ CSSParserImpl::ParseWebkitTextStroke()
return false;
}
if (!(found & 1)) { // Provide default -webkit-text-stroke-width
values[0].SetFloatValue(0, eCSSUnit_Pixel);
}
if (!(found & 2)) { // Provide default -webkit-text-stroke-color
- values[1].SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
+ values[1].SetIntValue(static_cast<int32_t>(StyleColor::CurrentColor), eCSSUnit_EnumColor);
}
for (size_t index = 0; index < numProps; ++index) {
AppendValue(kWebkitTextStrokeIDs[index], values[index]);
}
return true;
}
@@ -13422,17 +13422,17 @@ CSSParserImpl::ParseBorderSide(const nsC
if ((found & 1) == 0) { // Provide default border-width
values[0].SetIntValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
}
if ((found & 2) == 0) { // Provide default border-style
values[1].SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
}
if ((found & 4) == 0) { // text color will be used
- values[2].SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
+ values[2].SetIntValue(static_cast<int32_t>(StyleColor::CurrentColor), eCSSUnit_EnumColor);
}
if (aSetAllSides) {
// Parsing "border" shorthand; set all four sides to the same thing
for (int32_t index = 0; index < 4; index++) {
NS_ASSERTION(numProps == 3, "This code needs updating");
AppendValue(kBorderWidthIDs[index], values[0]);
AppendValue(kBorderStyleIDs[index], values[1]);
@@ -15295,17 +15295,17 @@ CSSParserImpl::ParseOutline()
nsCSSValue values[numProps];
int32_t found = ParseChoice(values, kOutlineIDs, numProps);
if (found < 1) {
return false;
}
// Provide default values
if ((found & 1) == 0) { // Provide default outline-color
- values[0].SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
+ values[0].SetIntValue(static_cast<int32_t>(StyleColor::CurrentColor), eCSSUnit_EnumColor);
}
if ((found & 2) == 0) { // Provide default outline-style
values[1].SetIntValue(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
}
if ((found & 4) == 0) { // Provide default outline-width
values[2].SetIntValue(NS_STYLE_BORDER_WIDTH_MEDIUM, eCSSUnit_Enumerated);
}
@@ -15405,17 +15405,17 @@ CSSParserImpl::ParseTextDecoration()
values[0].SetIntValue(NS_STYLE_TEXT_DECORATION_LINE_NONE,
eCSSUnit_Enumerated);
}
if ((found & 2) == 0) { // Provide default text-decoration-style
values[1].SetIntValue(NS_STYLE_TEXT_DECORATION_STYLE_SOLID,
eCSSUnit_Enumerated);
}
if ((found & 4) == 0) { // Provide default text-decoration-color
- values[2].SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
+ values[2].SetIntValue(static_cast<int32_t>(StyleColor::CurrentColor), eCSSUnit_EnumColor);
}
for (int32_t index = 0; index < numProps; index++) {
AppendValue(kTextDecorationIDs[index], values[index]);
}
return true;
}
@@ -15433,17 +15433,17 @@ CSSParserImpl::ParseTextEmphasis()
if (found < 1) {
return false;
}
if (!(found & 1)) { // Provide default text-emphasis-style
values[0].SetNoneValue();
}
if (!(found & 2)) { // Provide default text-emphasis-color
- values[1].SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
+ values[1].SetIntValue(static_cast<int32_t>(StyleColor::CurrentColor), eCSSUnit_EnumColor);
}
for (int32_t index = 0; index < numProps; index++) {
AppendValue(kTextEmphasisIDs[index], values[index]);
}
return true;
}
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -1139,17 +1139,17 @@ const KTableEntry nsCSSProps::kColorKTab
{ eCSSKeyword__moz_mac_active_source_list_selection, LookAndFeel::eColorID__moz_mac_active_source_list_selection },
{ eCSSKeyword__moz_mac_tooltip, LookAndFeel::eColorID__moz_mac_tooltip },
{ eCSSKeyword__moz_menuhover, LookAndFeel::eColorID__moz_menuhover },
{ eCSSKeyword__moz_menuhovertext, LookAndFeel::eColorID__moz_menuhovertext },
{ eCSSKeyword__moz_menubartext, LookAndFeel::eColorID__moz_menubartext },
{ eCSSKeyword__moz_menubarhovertext, LookAndFeel::eColorID__moz_menubarhovertext },
{ eCSSKeyword__moz_oddtreerow, LookAndFeel::eColorID__moz_oddtreerow },
{ eCSSKeyword__moz_visitedhyperlinktext, NS_COLOR_MOZ_VISITEDHYPERLINKTEXT },
- { eCSSKeyword_currentcolor, NS_COLOR_CURRENTCOLOR },
+ { eCSSKeyword_currentcolor, StyleColor::CurrentColor },
{ eCSSKeyword__moz_win_accentcolor, LookAndFeel::eColorID__moz_win_accentcolor },
{ eCSSKeyword__moz_win_accentcolortext, LookAndFeel::eColorID__moz_win_accentcolortext },
{ eCSSKeyword__moz_win_mediatext, LookAndFeel::eColorID__moz_win_mediatext },
{ eCSSKeyword__moz_win_communicationstext, LookAndFeel::eColorID__moz_win_communicationstext },
{ eCSSKeyword__moz_nativehyperlinktext, LookAndFeel::eColorID__moz_nativehyperlinktext },
{ eCSSKeyword__moz_comboboxtext, LookAndFeel::eColorID__moz_comboboxtext },
{ eCSSKeyword__moz_combobox, LookAndFeel::eColorID__moz_combobox },
{ eCSSKeyword_UNKNOWN, -1 }
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -1726,17 +1726,17 @@ nsCSSValue::AppendToString(nsCSSProperty
aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
}
aResult.Append(char16_t(')'));
}
else if (eCSSUnit_ComplexColor == unit) {
StyleComplexColor color = GetStyleComplexColorValue();
nsCSSValue serializable;
if (color.IsCurrentColor()) {
- serializable.SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
+ serializable.SetIntValue(static_cast<int32_t>(StyleColor::CurrentColor), eCSSUnit_EnumColor);
} else if (color.IsNumericColor()) {
serializable.SetColorValue(color.mColor);
} else {
MOZ_ASSERT_UNREACHABLE("Cannot serialize a complex color");
}
serializable.AppendToString(aProperty, aResult);
}
else if (eCSSUnit_URL == unit || eCSSUnit_Image == unit) {
--- a/layout/style/nsHTMLStyleSheet.cpp
+++ b/layout/style/nsHTMLStyleSheet.cpp
@@ -116,17 +116,17 @@ GetDiscretelyAnimatedCSSValue(nsCSSPrope
/* virtual */ void
nsHTMLStyleSheet::TableQuirkColorRule::MapRuleInfoInto(nsRuleData* aRuleData)
{
if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
nsCSSValue* color = aRuleData->ValueForColor();
// We do not check UseDocumentColors() here, because we want to
// use the body color no matter what.
if (color->GetUnit() == eCSSUnit_Null)
- color->SetIntValue(NS_STYLE_COLOR_INHERIT_FROM_BODY,
+ color->SetIntValue(static_cast<int32_t>(StyleColor::InheritFromBody),
eCSSUnit_Enumerated);
}
}
/* virtual */ bool
nsHTMLStyleSheet::TableQuirkColorRule::MightMapInheritedStyleData()
{
return true;
--- a/layout/style/nsRuleData.h
+++ b/layout/style/nsRuleData.h
@@ -173,17 +173,17 @@ struct nsRuleData final : mozilla::Gener
}
void SetAutoValue(nsCSSPropertyID aId) {
ValueFor(aId)->SetAutoValue();
}
void SetCurrentColor(nsCSSPropertyID aId)
{
- ValueFor(aId)->SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
+ ValueFor(aId)->SetIntValue(static_cast<int32_t>(mozilla::StyleColor::CurrentColor), eCSSUnit_EnumColor);
}
void SetColorValue(nsCSSPropertyID aId, nscolor aValue)
{
ValueFor(aId)->SetColorValue(aValue);
}
void SetFontFamily(const nsString& aValue);
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -1159,17 +1159,17 @@ static bool SetColor(const nsCSSValue& a
}
break;
case NS_COLOR_MOZ_ACTIVEHYPERLINKTEXT:
if (aPresContext) {
aResult = aPresContext->DefaultActiveLinkColor();
result = true;
}
break;
- case NS_COLOR_CURRENTCOLOR:
+ case static_cast<int32_t>(StyleColor::CurrentColor):
// The data computed from this can't be shared in the rule tree
// because they could be used on a node with a different color
aConditions.SetUncacheable();
if (aContext) {
aResult = aContext->StyleColor()->mColor;
result = true;
}
break;
@@ -1192,17 +1192,17 @@ static bool SetColor(const nsCSSValue& a
}
}
else if (eCSSUnit_Inherit == unit) {
aResult = aParentColor;
result = true;
aConditions.SetUncacheable();
}
else if (eCSSUnit_Enumerated == unit &&
- aValue.GetIntValue() == NS_STYLE_COLOR_INHERIT_FROM_BODY) {
+ aValue.GetIntValue() == static_cast<int32_t>(StyleColor::InheritFromBody)) {
NS_ASSERTION(aPresContext->CompatibilityMode() == eCompatibility_NavQuirks,
"Should only get this value in quirks mode");
// We just grab the color from the prescontext, and rely on the fact that
// if the body color ever changes all its descendants will get new style
// contexts (but NOT necessarily new rulenodes).
aResult = aPresContext->BodyTextColor();
result = true;
aConditions.SetUncacheable();
@@ -1226,17 +1226,17 @@ SetComplexColor(const nsCSSValue& aValue
if (unit == eCSSUnit_Initial ||
(UnsetTo == eUnsetInitial && unit == eCSSUnit_Unset)) {
aResult = aInitialColor;
} else if (unit == eCSSUnit_Inherit ||
(UnsetTo == eUnsetInherit && unit == eCSSUnit_Unset)) {
aConditions.SetUncacheable();
aResult = aParentColor;
} else if (unit == eCSSUnit_EnumColor &&
- aValue.GetIntValue() == NS_COLOR_CURRENTCOLOR) {
+ aValue.GetIntValue() == static_cast<int32_t>(StyleColor::CurrentColor)) {
aResult = StyleComplexColor::CurrentColor();
} else if (unit == eCSSUnit_ComplexColor) {
aResult = aValue.GetStyleComplexColorValue();
} else if (unit == eCSSUnit_Auto) {
aResult = StyleComplexColor::Auto();
} else {
nscolor resultColor;
if (!SetColor(aValue, aParentColor.mColor, aPresContext,
@@ -2142,17 +2142,17 @@ CheckFontCallback(const nsRuleData* aRul
static nsRuleNode::RuleDetail
CheckColorCallback(const nsRuleData* aRuleData,
nsRuleNode::RuleDetail aResult)
{
// currentColor values for color require inheritance
const nsCSSValue* colorValue = aRuleData->ValueForColor();
if (colorValue->GetUnit() == eCSSUnit_EnumColor &&
- colorValue->GetIntValue() == NS_COLOR_CURRENTCOLOR) {
+ colorValue->GetIntValue() == static_cast<int32_t>(StyleColor::CurrentColor)) {
NS_ASSERTION(aResult == nsRuleNode::eRuleFullReset,
"we should already be counted as full-reset");
aResult = nsRuleNode::eRuleFullInherited;
}
return aResult;
}
@@ -6797,17 +6797,17 @@ nsRuleNode::ComputeColorData(void* aStar
{
COMPUTE_START_INHERITED(Color, color, parentColor)
// color: color, string, inherit
// Special case for currentColor. According to CSS3, setting color to 'currentColor'
// should behave as if it is inherited
const nsCSSValue* colorValue = aRuleData->ValueForColor();
if ((colorValue->GetUnit() == eCSSUnit_EnumColor &&
- colorValue->GetIntValue() == NS_COLOR_CURRENTCOLOR) ||
+ colorValue->GetIntValue() == static_cast<int32_t>(StyleColor::CurrentColor)) ||
colorValue->GetUnit() == eCSSUnit_Unset) {
color->mColor = parentColor->mColor;
conditions.SetUncacheable();
}
else if (colorValue->GetUnit() == eCSSUnit_Initial) {
color->mColor = mPresContext->DefaultColor();
}
else {
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -225,19 +225,29 @@ enum class StyleWindowDragging : uint8_t
// orient
enum class StyleOrient : uint8_t {
Inline,
Block,
Horizontal,
Vertical,
};
-
-// See nsStyleColor
-#define NS_STYLE_COLOR_INHERIT_FROM_BODY 2 /* Can't come from CSS directly */
+// color
+enum class StyleColor : int8_t {
+ InheritFromBody = 2, /* Can't come from CSS directly */
+ CurrentColor = -1,
+ MozDefaultColor = -2,
+ MozDefaultBackgroundColor = -3,
+ MozHyperlinkText = -4,
+ MozVisitedHyperlinkText = -5,
+ MozActiveHyperlinkText = -6,
+// Only valid as paints in SVG glyphs
+ ContextFill = -7,
+ ContextStroke = -8,
+};
// See nsStyleColor
#define NS_COLOR_CURRENTCOLOR -1
#define NS_COLOR_MOZ_DEFAULT_COLOR -2
#define NS_COLOR_MOZ_DEFAULT_BACKGROUND_COLOR -3
#define NS_COLOR_MOZ_HYPERLINKTEXT -4
#define NS_COLOR_MOZ_VISITEDHYPERLINKTEXT -5
#define NS_COLOR_MOZ_ACTIVEHYPERLINKTEXT -6