diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp
index 94824e71bad6..0a3e2d6ff328 100644
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -1396,7 +1396,11 @@ nsGenericHTMLElement::ParseColor(const nsString& aString,
}
}
-#if XXX_no_nav_compat
+// XXX Nav doesn't map illegal values to zero, at least not for color names.
+// Changing it so we ignore the illegal values rather than whack the color to
+// black, which in the case of a background color makes the document unreadable
+//#if XXX_no_nav_compat
+#if 1
// Illegal values are mapped to empty
aResult.SetEmptyValue();
return PR_FALSE;
@@ -1911,10 +1915,13 @@ nsGenericHTMLElement::MapBackgroundAttributesInto(nsIHTMLAttributes* aAttributes
char cbuf[40];
buffer.ToCString(cbuf, sizeof(cbuf));
- nsStyleColor* color = (nsStyleColor*)
- aContext->GetMutableStyleData(eStyleStruct_Color);
- NS_ColorNameToRGB(cbuf, &(color->mBackgroundColor));
- color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
+ nscolor backgroundColor;
+ if (NS_ColorNameToRGB(cbuf, &backgroundColor)) {
+ nsStyleColor* color = (nsStyleColor*)
+ aContext->GetMutableStyleData(eStyleStruct_Color);
+ color->mBackgroundColor = backgroundColor;
+ color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
+ }
}
}
}
diff --git a/content/html/content/src/nsHTMLBodyElement.cpp b/content/html/content/src/nsHTMLBodyElement.cpp
index 101fc5da3b22..27464a93faf5 100644
--- a/content/html/content/src/nsHTMLBodyElement.cpp
+++ b/content/html/content/src/nsHTMLBodyElement.cpp
@@ -618,16 +618,14 @@ nsHTMLBodyElement::AttributeToString(nsIAtom* aAttribute,
return mInner.AttributeToString(aAttribute, aValue, aResult);
}
-static nscolor ColorNameToRGB(const nsHTMLValue& aValue)
+static PRBool ColorNameToRGB(const nsHTMLValue& aValue, nscolor* aColor)
{
nsAutoString buffer;
aValue.GetStringValue(buffer);
char cbuf[40];
buffer.ToCString(cbuf, sizeof(cbuf));
- nscolor color;
- NS_ColorNameToRGB(cbuf, &color);
- return color;
+ return NS_ColorNameToRGB(cbuf, aColor);
}
static void
@@ -646,9 +644,12 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
color->mColor = value.GetColorValue();
}
else if (eHTMLUnit_String == value.GetUnit()) {
- nsStyleColor* color = (nsStyleColor*)
- aContext->GetMutableStyleData(eStyleStruct_Color);
- color->mColor = ColorNameToRGB(value);
+ nscolor backgroundColor;
+ if (ColorNameToRGB(value, &backgroundColor)) {
+ nsStyleColor* color = (nsStyleColor*)
+ aContext->GetMutableStyleData(eStyleStruct_Color);
+ color->mColor = backgroundColor;
+ }
}
nsCOMPtr presShell;
@@ -667,7 +668,10 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
styleSheet->SetLinkColor(value.GetColorValue());
}
else if (eHTMLUnit_String == value.GetUnit()) {
- styleSheet->SetLinkColor(ColorNameToRGB(value));
+ nscolor linkColor;
+ if (ColorNameToRGB(value, &linkColor)) {
+ styleSheet->SetLinkColor(linkColor);
+ }
}
aAttributes->GetAttribute(nsHTMLAtoms::alink, value);
@@ -675,7 +679,10 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
styleSheet->SetActiveLinkColor(value.GetColorValue());
}
else if (eHTMLUnit_String == value.GetUnit()) {
- styleSheet->SetActiveLinkColor(ColorNameToRGB(value));
+ nscolor linkColor;
+ if (ColorNameToRGB(value, &linkColor)) {
+ styleSheet->SetActiveLinkColor(linkColor);
+ }
}
aAttributes->GetAttribute(nsHTMLAtoms::vlink, value);
@@ -683,7 +690,10 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
styleSheet->SetVisitedLinkColor(value.GetColorValue());
}
else if (eHTMLUnit_String == value.GetUnit()) {
- styleSheet->SetVisitedLinkColor(ColorNameToRGB(value));
+ nscolor linkColor;
+ if (ColorNameToRGB(value, &linkColor)) {
+ styleSheet->SetVisitedLinkColor(linkColor);
+ }
}
NS_RELEASE(styleSheet);
}
diff --git a/layout/html/content/src/nsGenericHTMLElement.cpp b/layout/html/content/src/nsGenericHTMLElement.cpp
index 94824e71bad6..0a3e2d6ff328 100644
--- a/layout/html/content/src/nsGenericHTMLElement.cpp
+++ b/layout/html/content/src/nsGenericHTMLElement.cpp
@@ -1396,7 +1396,11 @@ nsGenericHTMLElement::ParseColor(const nsString& aString,
}
}
-#if XXX_no_nav_compat
+// XXX Nav doesn't map illegal values to zero, at least not for color names.
+// Changing it so we ignore the illegal values rather than whack the color to
+// black, which in the case of a background color makes the document unreadable
+//#if XXX_no_nav_compat
+#if 1
// Illegal values are mapped to empty
aResult.SetEmptyValue();
return PR_FALSE;
@@ -1911,10 +1915,13 @@ nsGenericHTMLElement::MapBackgroundAttributesInto(nsIHTMLAttributes* aAttributes
char cbuf[40];
buffer.ToCString(cbuf, sizeof(cbuf));
- nsStyleColor* color = (nsStyleColor*)
- aContext->GetMutableStyleData(eStyleStruct_Color);
- NS_ColorNameToRGB(cbuf, &(color->mBackgroundColor));
- color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
+ nscolor backgroundColor;
+ if (NS_ColorNameToRGB(cbuf, &backgroundColor)) {
+ nsStyleColor* color = (nsStyleColor*)
+ aContext->GetMutableStyleData(eStyleStruct_Color);
+ color->mBackgroundColor = backgroundColor;
+ color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
+ }
}
}
}
diff --git a/layout/html/content/src/nsHTMLBodyElement.cpp b/layout/html/content/src/nsHTMLBodyElement.cpp
index 101fc5da3b22..27464a93faf5 100644
--- a/layout/html/content/src/nsHTMLBodyElement.cpp
+++ b/layout/html/content/src/nsHTMLBodyElement.cpp
@@ -618,16 +618,14 @@ nsHTMLBodyElement::AttributeToString(nsIAtom* aAttribute,
return mInner.AttributeToString(aAttribute, aValue, aResult);
}
-static nscolor ColorNameToRGB(const nsHTMLValue& aValue)
+static PRBool ColorNameToRGB(const nsHTMLValue& aValue, nscolor* aColor)
{
nsAutoString buffer;
aValue.GetStringValue(buffer);
char cbuf[40];
buffer.ToCString(cbuf, sizeof(cbuf));
- nscolor color;
- NS_ColorNameToRGB(cbuf, &color);
- return color;
+ return NS_ColorNameToRGB(cbuf, aColor);
}
static void
@@ -646,9 +644,12 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
color->mColor = value.GetColorValue();
}
else if (eHTMLUnit_String == value.GetUnit()) {
- nsStyleColor* color = (nsStyleColor*)
- aContext->GetMutableStyleData(eStyleStruct_Color);
- color->mColor = ColorNameToRGB(value);
+ nscolor backgroundColor;
+ if (ColorNameToRGB(value, &backgroundColor)) {
+ nsStyleColor* color = (nsStyleColor*)
+ aContext->GetMutableStyleData(eStyleStruct_Color);
+ color->mColor = backgroundColor;
+ }
}
nsCOMPtr presShell;
@@ -667,7 +668,10 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
styleSheet->SetLinkColor(value.GetColorValue());
}
else if (eHTMLUnit_String == value.GetUnit()) {
- styleSheet->SetLinkColor(ColorNameToRGB(value));
+ nscolor linkColor;
+ if (ColorNameToRGB(value, &linkColor)) {
+ styleSheet->SetLinkColor(linkColor);
+ }
}
aAttributes->GetAttribute(nsHTMLAtoms::alink, value);
@@ -675,7 +679,10 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
styleSheet->SetActiveLinkColor(value.GetColorValue());
}
else if (eHTMLUnit_String == value.GetUnit()) {
- styleSheet->SetActiveLinkColor(ColorNameToRGB(value));
+ nscolor linkColor;
+ if (ColorNameToRGB(value, &linkColor)) {
+ styleSheet->SetActiveLinkColor(linkColor);
+ }
}
aAttributes->GetAttribute(nsHTMLAtoms::vlink, value);
@@ -683,7 +690,10 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
styleSheet->SetVisitedLinkColor(value.GetColorValue());
}
else if (eHTMLUnit_String == value.GetUnit()) {
- styleSheet->SetVisitedLinkColor(ColorNameToRGB(value));
+ nscolor linkColor;
+ if (ColorNameToRGB(value, &linkColor)) {
+ styleSheet->SetVisitedLinkColor(linkColor);
+ }
}
NS_RELEASE(styleSheet);
}