From f5e05e8e460796f791459fd6f5aab2f5a0482848 Mon Sep 17 00:00:00 2001 From: "caillon%returnzero.com" Date: Mon, 8 Jul 2002 06:22:53 +0000 Subject: [PATCH] Bug 39210 - document.bgcolor reported as 'white' instead of '#ffffff' r=sicking sr=jst --- .../html/content/src/nsHTMLBodyElement.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/content/html/content/src/nsHTMLBodyElement.cpp b/content/html/content/src/nsHTMLBodyElement.cpp index d3a927022beb..24c92304b024 100644 --- a/content/html/content/src/nsHTMLBodyElement.cpp +++ b/content/html/content/src/nsHTMLBodyElement.cpp @@ -559,7 +559,11 @@ nsHTMLBodyElement::SetText(const nsAString& aTextColor) NS_IMETHODIMP nsHTMLBodyElement::GetBgColor(nsAString& aBgColor) { - nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::bgcolor, aBgColor); + aBgColor.Truncate(); + + nsAutoString attr; + nscolor bgcolor; + nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::bgcolor, attr); // If we don't have an attribute, find the actual color used for // (generally from the user agent style sheet) for compatibility @@ -589,11 +593,20 @@ nsHTMLBodyElement::GetBgColor(nsAString& aBgColor) (const nsStyleStruct*&)StyleBackground); NS_ENSURE_SUCCESS(rv, rv); - nsHTMLValue value(StyleBackground->mBackgroundColor); - ColorToString(value, aBgColor); + bgcolor = StyleBackground->mBackgroundColor; + ColorToString(bgcolor, aBgColor); } } } + else if (NS_ColorNameToRGB(attr, &bgcolor)) { + // If we have a color name which we can convert to an nscolor, + // then we should use the hex value instead of the color name. + ColorToString(bgcolor, aBgColor); + } + else { + // Otherwise, just assign whatever the attribute value is. + aBgColor.Assign(attr); + } return NS_OK; }