Fix serialization of currentColor for some properties. b=414550 r+sr=bzbarsky a=schrep

git-svn-id: svn://10.0.0.236/trunk@245249 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dbaron%dbaron.org
2008-02-08 19:51:41 +00:00
parent d9f25753a4
commit 53a15aec19
6 changed files with 48 additions and 59 deletions

View File

@@ -344,37 +344,9 @@ nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty,
}
}
else if (eCSSUnit_Integer == unit) {
switch (aProperty) {
case eCSSProperty_color:
case eCSSProperty_background_color:
case eCSSProperty_border_top_color:
case eCSSProperty_border_bottom_color:
case eCSSProperty_border_left_color_value:
case eCSSProperty_border_right_color_value:
case eCSSProperty_border_start_color_value:
case eCSSProperty_border_end_color_value:
case eCSSProperty_outline_color: {
// we can lookup the property in the ColorTable and then
// get a string mapping the name
nsCAutoString str;
if (nsCSSProps::GetColorName(aValue.GetIntValue(), str)){
AppendASCIItoUTF16(str, aResult);
} else {
nsAutoString tmpStr;
tmpStr.AppendInt(aValue.GetIntValue(), 10);
aResult.Append(tmpStr);
}
}
break;
default:
{
nsAutoString tmpStr;
tmpStr.AppendInt(aValue.GetIntValue(), 10);
aResult.Append(tmpStr);
}
break;
}
nsAutoString tmpStr;
tmpStr.AppendInt(aValue.GetIntValue(), 10);
aResult.Append(tmpStr);
}
else if (eCSSUnit_Enumerated == unit) {
if (eCSSProperty_text_decoration == aProperty) {
@@ -422,6 +394,16 @@ nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty,
AppendASCIItoUTF16(name, aResult);
}
}
else if (eCSSUnit_EnumColor == unit) {
// we can lookup the property in the ColorTable and then
// get a string mapping the name
nsCAutoString str;
if (nsCSSProps::GetColorName(aValue.GetIntValue(), str)){
AppendASCIItoUTF16(str, aResult);
} else {
NS_NOTREACHED("bad color value");
}
}
else if (eCSSUnit_Color == unit) {
nscolor color = aValue.GetColorValue();
if (color == NS_RGBA(0, 0, 0, 0)) {
@@ -487,6 +469,7 @@ nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty,
case eCSSUnit_Counters: aResult.Append(PRUnichar(')')); break;
case eCSSUnit_Integer: break;
case eCSSUnit_Enumerated: break;
case eCSSUnit_EnumColor: break;
case eCSSUnit_Color: break;
case eCSSUnit_Percent: aResult.Append(PRUnichar('%')); break;
case eCSSUnit_Number: break;

View File

@@ -1124,7 +1124,7 @@ CSSParserImpl::ParseColorString(const nsSubstring& aBuffer,
} else if (value.GetUnit() == eCSSUnit_Color) {
(*aColor) = value.GetColorValue();
rv = NS_OK;
} else if (value.GetUnit() == eCSSUnit_Integer) {
} else if (value.GetUnit() == eCSSUnit_EnumColor) {
PRInt32 intValue = value.GetIntValue();
if (intValue >= 0) {
nsCOMPtr<nsILookAndFeel> lfSvc = do_GetService("@mozilla.org/widget/lookandfeel;1");
@@ -2941,7 +2941,7 @@ PRBool CSSParserImpl::ParseColor(nsresult& aErrorCode, nsCSSValue& aValue)
return PR_TRUE;
}
if (nsCSSProps::FindKeyword(keyword, nsCSSProps::kColorKTable, value)) {
aValue.SetIntValue(value, eCSSUnit_Integer);
aValue.SetIntValue(value, eCSSUnit_EnumColor);
return PR_TRUE;
}
}
@@ -6374,7 +6374,7 @@ PRBool CSSParserImpl::ParseTextShadow(nsresult& aErrorCode)
} else {
// Must be a color (as string or color value)
NS_ASSERTION(unit == eCSSUnit_String || unit == eCSSUnit_Color ||
unit == eCSSUnit_Integer,
unit == eCSSUnit_EnumColor,
"Must be a color value (named color, numeric color, "
"or system color)");
haveColor = PR_TRUE;

View File

@@ -52,10 +52,10 @@
nsCSSValue::nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit)
: mUnit(aUnit)
{
NS_ASSERTION((eCSSUnit_Integer == aUnit) ||
(eCSSUnit_Enumerated == aUnit), "not an int value");
if ((eCSSUnit_Integer == aUnit) ||
(eCSSUnit_Enumerated == aUnit)) {
NS_ASSERTION(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
aUnit == eCSSUnit_EnumColor, "not an int value");
if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
aUnit == eCSSUnit_EnumColor) {
mValue.mInt = aValue;
}
else {
@@ -131,7 +131,7 @@ nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
mValue.mString = aCopy.mValue.mString;
mValue.mString->AddRef();
}
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) {
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_EnumColor)) {
mValue.mInt = aCopy.mValue.mInt;
}
else if (eCSSUnit_Color == mUnit){
@@ -173,7 +173,7 @@ PRBool nsCSSValue::operator==(const nsCSSValue& aOther) const
return (NS_strcmp(GetBufferValue(mValue.mString),
GetBufferValue(aOther.mValue.mString)) == 0);
}
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) {
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_EnumColor)) {
return mValue.mInt == aOther.mValue.mInt;
}
else if (eCSSUnit_Color == mUnit) {
@@ -255,11 +255,11 @@ void nsCSSValue::DoReset()
void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit)
{
NS_ASSERTION((eCSSUnit_Integer == aUnit) ||
(eCSSUnit_Enumerated == aUnit), "not an int value");
NS_ASSERTION(aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
aUnit == eCSSUnit_EnumColor, "not an int value");
Reset();
if ((eCSSUnit_Integer == aUnit) ||
(eCSSUnit_Enumerated == aUnit)) {
if (aUnit == eCSSUnit_Integer || aUnit == eCSSUnit_Enumerated ||
aUnit == eCSSUnit_EnumColor) {
mUnit = aUnit;
mValue.mInt = aValue;
}

View File

@@ -73,7 +73,8 @@ enum nsCSSUnit {
eCSSUnit_Image = 31, // (nsCSSValue::Image*) value
eCSSUnit_Integer = 50, // (int) simple value
eCSSUnit_Enumerated = 51, // (int) value has enumerated meaning
eCSSUnit_Color = 80, // (color) an RGBA value
eCSSUnit_EnumColor = 80, // (int) enumerated color (kColorKTable)
eCSSUnit_Color = 81, // (nscolor) an RGBA value
eCSSUnit_Percent = 90, // (float) 1.0 == 100%) value is percentage of something
eCSSUnit_Number = 91, // (float) value is numeric (usually multiplier, different behavior that percent)
@@ -174,7 +175,8 @@ public:
PRInt32 GetIntValue() const
{
NS_ASSERTION(mUnit == eCSSUnit_Integer || mUnit == eCSSUnit_Enumerated,
NS_ASSERTION(mUnit == eCSSUnit_Integer || mUnit == eCSSUnit_Enumerated ||
mUnit == eCSSUnit_EnumColor,
"not an int value");
return mValue.mInt;
}

View File

@@ -389,7 +389,7 @@ static PRBool SetColor(const nsCSSValue& aValue, const nscolor aParentColor,
result = PR_TRUE;
}
}
else if (eCSSUnit_Integer == unit) {
else if (eCSSUnit_EnumColor == unit) {
PRInt32 intValue = aValue.GetIntValue();
if (0 <= intValue) {
nsILookAndFeel* look = aPresContext->LookAndFeel();
@@ -725,7 +725,7 @@ CheckColorCallback(const nsRuleDataStruct& aData,
static_cast<const nsRuleDataColor&>(aData);
// currentColor values for color require inheritance
if (colorData.mColor.GetUnit() == eCSSUnit_Integer &&
if (colorData.mColor.GetUnit() == eCSSUnit_EnumColor &&
colorData.mColor.GetIntValue() == NS_COLOR_CURRENTCOLOR) {
NS_ASSERTION(aResult == nsRuleNode::eRuleFullReset,
"we should already be counted as full-reset");
@@ -3381,7 +3381,7 @@ nsRuleNode::ComputeColorData(void* aStartStruct,
// color: color, string, inherit
// Special case for currentColor. According to CSS3, setting color to 'currentColor'
// should behave as if it is inherited
if (colorData.mColor.GetUnit() == eCSSUnit_Integer &&
if (colorData.mColor.GetUnit() == eCSSUnit_EnumColor &&
colorData.mColor.GetIntValue() == NS_COLOR_CURRENTCOLOR) {
color->mColor = parentColor->mColor;
inherited = PR_TRUE;

View File

@@ -108,7 +108,7 @@ var gCSSProperties = {
inherited: false,
type: CSS_TYPE_LONGHAND,
initial_values: [ "none" ],
other_values: [ "red green", "red #fc3", "#ff00cc" ],
other_values: [ "red green", "red #fc3", "#ff00cc", "currentColor", "blue currentColor orange currentColor" ],
invalid_values: [ "red none", "red inherit", "red, green" ]
},
"-moz-border-end": {
@@ -154,7 +154,7 @@ var gCSSProperties = {
inherited: false,
type: CSS_TYPE_LONGHAND,
initial_values: [ "none" ],
other_values: [ "red green", "red #fc3", "#ff00cc" ],
other_values: [ "red green", "red #fc3", "#ff00cc", "currentColor", "blue currentColor orange currentColor" ],
invalid_values: [ "red none", "red inherit", "red, green" ]
},
"-moz-border-radius": {
@@ -203,7 +203,7 @@ var gCSSProperties = {
inherited: false,
type: CSS_TYPE_LONGHAND,
initial_values: [ "none" ],
other_values: [ "red green", "red #fc3", "#ff00cc" ],
other_values: [ "red green", "red #fc3", "#ff00cc", "currentColor", "blue currentColor orange currentColor" ],
invalid_values: [ "red none", "red inherit", "red, green" ]
},
"-moz-border-start": {
@@ -249,7 +249,7 @@ var gCSSProperties = {
inherited: false,
type: CSS_TYPE_LONGHAND,
initial_values: [ "none" ],
other_values: [ "red green", "red #fc3", "#ff00cc" ],
other_values: [ "red green", "red #fc3", "#ff00cc", "currentColor", "blue currentColor orange currentColor" ],
invalid_values: [ "red none", "red inherit", "red, green" ]
},
"-moz-box-align": {
@@ -1495,7 +1495,7 @@ var gCSSProperties = {
backend_only: true,
type: CSS_TYPE_LONGHAND,
initial_values: [ "none" ],
other_values: [ "2px 2px", "2px 2px 1px", "2px 2px green", "2px 2px 1px green", "green 2px 2px", "green 2px 2px 1px", "green 2px 2px, blue 1px 3px 4px" ],
other_values: [ "2px 2px", "2px 2px 1px", "2px 2px green", "2px 2px 1px green", "green 2px 2px", "green 2px 2px 1px", "green 2px 2px, blue 1px 3px 4px", "currentColor 3px 3px", "blue 2px 2px, currentColor 1px 2px" ],
invalid_values: [ "3% 3%", "2px 2px 2px 2px", "2px 2px, none" ]
},
"text-transform": {
@@ -1651,8 +1651,9 @@ var gCSSProperties = {
domProp: null,
inherited: true,
type: CSS_TYPE_LONGHAND,
prerequisites: { "color": "blue" },
initial_values: [ "black", "#000", "#000000", "rgb(0,0,0)", "rgba(0,0,0,1)" ],
other_values: [ "green", "#fc3", "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green', "none" ],
other_values: [ "green", "#fc3", "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green', "none", "currentColor" ],
invalid_values: []
},
"fill-opacity": {
@@ -1683,8 +1684,9 @@ var gCSSProperties = {
domProp: null,
inherited: false,
type: CSS_TYPE_LONGHAND,
prerequisites: { "color": "blue" },
initial_values: [ "black", "#000", "#000000", "rgb(0,0,0)", "rgba(0,0,0,1)" ],
other_values: [ "green", "#fc3" ],
other_values: [ "green", "#fc3", "currentColor" ],
invalid_values: [ "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green' ]
},
"flood-opacity": {
@@ -1699,8 +1701,9 @@ var gCSSProperties = {
domProp: null,
inherited: false,
type: CSS_TYPE_LONGHAND,
prerequisites: { "color": "blue" },
initial_values: [ "white", "#fff", "#ffffff", "rgb(255,255,255)", "rgba(255,255,255,1.0)", "rgba(255,255,255,42.0)" ],
other_values: [ "green", "#fc3" ],
other_values: [ "green", "#fc3", "currentColor" ],
invalid_values: [ "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green' ]
},
"marker": {
@@ -1764,8 +1767,9 @@ var gCSSProperties = {
domProp: null,
inherited: false,
type: CSS_TYPE_LONGHAND,
prerequisites: { "color": "blue" },
initial_values: [ "black", "#000", "#000000", "rgb(0,0,0)", "rgba(0,0,0,1)" ],
other_values: [ "green", "#fc3" ],
other_values: [ "green", "#fc3", "currentColor" ],
invalid_values: [ "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green' ]
},
"stop-opacity": {
@@ -1781,7 +1785,7 @@ var gCSSProperties = {
inherited: true,
type: CSS_TYPE_LONGHAND,
initial_values: [ "none" ],
other_values: [ "black", "#000", "#000000", "rgb(0,0,0)", "rgba(0,0,0,1)", "green", "#fc3", "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green' ],
other_values: [ "black", "#000", "#000000", "rgb(0,0,0)", "rgba(0,0,0,1)", "green", "#fc3", "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green', "currentColor" ],
invalid_values: []
},
"stroke-dasharray": {