diff --git a/dom/public/idl/css/Makefile.in b/dom/public/idl/css/Makefile.in index 4630ba684be..925b413a752 100644 --- a/dom/public/idl/css/Makefile.in +++ b/dom/public/idl/css/Makefile.in @@ -72,6 +72,7 @@ XPIDLSRCS = \ nsIDOMRGBColor.idl \ nsIDOMRect.idl \ nsIDOMViewCSS.idl \ + nsIDOMNSRGBAColor.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/public/idl/css/nsIDOMNSRGBAColor.idl b/dom/public/idl/css/nsIDOMNSRGBAColor.idl new file mode 100644 index 00000000000..dd26931aceb --- /dev/null +++ b/dom/public/idl/css/nsIDOMNSRGBAColor.idl @@ -0,0 +1,46 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Johnny Stenback (original author) + * L. David Baron (Mozilla Corporation) + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIDOMRGBColor.idl" + +[scriptable, uuid(742dc816-5134-4214-adfa-cad9dd3377cd)] +interface nsIDOMNSRGBAColor : nsIDOMRGBColor +{ + readonly attribute nsIDOMCSSPrimitiveValue alpha; +}; diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 87ddefa5200..4c5ade19c6c 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -178,6 +178,7 @@ #include "nsIDOMCSSRuleList.h" #include "nsIDOMRect.h" #include "nsIDOMRGBColor.h" +#include "nsIDOMNSRGBAColor.h" // XBL related includes. #include "nsIXBLService.h" @@ -2366,6 +2367,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(CSSRGBColor, nsIDOMRGBColor) DOM_CLASSINFO_MAP_ENTRY(nsIDOMRGBColor) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSRGBAColor) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(Range, nsIDOMRange) diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 850fd9a3b6c..2b6a7069359 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -2860,6 +2860,16 @@ PRBool CSSParserImpl::ParseColor(nsresult& aErrorCode, nsCSSValue& aValue) nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(tk->mIdent); if (eCSSKeyword_UNKNOWN < keyword) { // known keyword PRInt32 value; +#ifdef MOZ_CAIRO_GFX + // XXX Once non-cairo is no longer supported, we should remove + // the special parsing of transparent for background-color and + // border-color. (It currently overrides this, since keywords + // are checked earlier in ParseVariant.) +#endif + if (mHandleAlphaColors && keyword == eCSSKeyword_transparent) { + aValue.SetColorValue(NS_RGBA(0, 0, 0, 0)); + return PR_TRUE; + } if (nsCSSProps::FindKeyword(keyword, nsCSSProps::kColorKTable, value)) { aValue.SetIntValue(value, eCSSUnit_Integer); return PR_TRUE; diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 3d2442b8127..38ed9f9cffd 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -464,30 +464,41 @@ nsComputedDOMStyle::GetBottom(nsIDOMCSSValue** aValue) return GetOffsetWidthFor(NS_SIDE_BOTTOM, aValue); } -nsDOMCSSRGBColor* -nsComputedDOMStyle::GetDOMCSSRGBColor(nscolor aColor) +nsresult +nsComputedDOMStyle::SetToRGBAColor(nsROCSSPrimitiveValue* aValue, + nscolor aColor) { + if (NS_GET_A(aColor) == 0) { + aValue->SetIdent(nsGkAtoms::transparent); + return NS_OK; + } + nsROCSSPrimitiveValue *red = GetROCSSPrimitiveValue(); nsROCSSPrimitiveValue *green = GetROCSSPrimitiveValue(); nsROCSSPrimitiveValue *blue = GetROCSSPrimitiveValue(); + nsROCSSPrimitiveValue *alpha = GetROCSSPrimitiveValue(); - if (red && green && blue) { - nsDOMCSSRGBColor *rgbColor = new nsDOMCSSRGBColor(red, green, blue); + if (red && green && blue && alpha) { + nsDOMCSSRGBColor *rgbColor = + new nsDOMCSSRGBColor(red, green, blue, alpha, NS_GET_A(aColor) < 255); if (rgbColor) { red->SetNumber(NS_GET_R(aColor)); green->SetNumber(NS_GET_G(aColor)); blue->SetNumber(NS_GET_B(aColor)); + alpha->SetNumber(float(NS_GET_A(aColor)) / 255.0f); - return rgbColor; + aValue->SetColor(rgbColor); + return NS_OK; } } delete red; delete green; delete blue; + delete alpha; - return nsnull; + return NS_ERROR_OUT_OF_MEMORY; } nsresult @@ -498,15 +509,12 @@ nsComputedDOMStyle::GetColor(nsIDOMCSSValue** aValue) const nsStyleColor* color = GetStyleColor(); - nsDOMCSSRGBColor *rgb = GetDOMCSSRGBColor(color->mColor); - if (!rgb) { + nsresult rv = SetToRGBAColor(val, color->mColor); + if (NS_FAILED(rv)) { delete val; - - return NS_ERROR_OUT_OF_MEMORY; + return rv; } - val->SetColor(rgb); - return CallQueryInterface(val, aValue); } @@ -856,15 +864,11 @@ nsComputedDOMStyle::GetBackgroundColor(nsIDOMCSSValue** aValue) nsCSSProps::kBackgroundColorKTable); val->SetIdent(backgroundColor); } else { - nsDOMCSSRGBColor *rgb = nsnull; - rgb = GetDOMCSSRGBColor(color->mBackgroundColor); - if (!rgb) { + nsresult rv = SetToRGBAColor(val, color->mBackgroundColor); + if (NS_FAILED(rv)) { delete val; - - return NS_ERROR_OUT_OF_MEMORY; + return rv; } - - val->SetColor(rgb); } return CallQueryInterface(val, aValue); @@ -1396,16 +1400,12 @@ nsComputedDOMStyle::GetOutlineColor(nsIDOMCSSValue** aValue) nscolor color; GetStyleOutline()->GetOutlineColor(color); - nsDOMCSSRGBColor *rgb = nsnull; - rgb = GetDOMCSSRGBColor(color); - if (!rgb) { + nsresult rv = SetToRGBAColor(val, color); + if (NS_FAILED(rv)) { delete val; - - return NS_ERROR_OUT_OF_MEMORY; + return rv; } - val->SetColor(rgb); - return CallQueryInterface(val, aValue); } @@ -2925,14 +2925,11 @@ nsComputedDOMStyle::GetBorderColorsFor(PRUint8 aSide, nsIDOMCSSValue** aValue) if (borderColors->mTransparent) { primitive->SetIdent(nsGkAtoms::transparent); } else { - nsDOMCSSRGBColor *rgb = GetDOMCSSRGBColor(borderColors->mColor); - if (rgb) { - primitive->SetColor(rgb); - } else { + nsresult rv = SetToRGBAColor(primitive, borderColors->mColor); + if (NS_FAILED(rv)) { delete valueList; delete primitive; - - return NS_ERROR_OUT_OF_MEMORY; + return rv; } } @@ -3014,15 +3011,13 @@ nsComputedDOMStyle::GetBorderColorFor(PRUint8 aSide, nsIDOMCSSValue** aValue) const nsStyleColor* colorStruct = GetStyleColor(); color = colorStruct->mColor; } + // XXX else? - nsDOMCSSRGBColor *rgb = GetDOMCSSRGBColor(color); - if (!rgb) { + nsresult rv = SetToRGBAColor(val, color); + if (NS_FAILED(rv)) { delete val; - - return NS_ERROR_OUT_OF_MEMORY; + return rv; } - - val->SetColor(rgb); } return CallQueryInterface(val, aValue); diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index 86cd3692bdc..7138bfa9ace 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -272,7 +272,7 @@ private: nsROCSSPrimitiveValue* GetROCSSPrimitiveValue(); nsDOMCSSValueList* GetROCSSValueList(PRBool aCommaDelimited); - nsDOMCSSRGBColor* GetDOMCSSRGBColor(nscolor aColor); + nsresult SetToRGBAColor(nsROCSSPrimitiveValue* aValue, nscolor aColor); struct ComputedStyleMapEntry { diff --git a/layout/style/nsDOMCSSRGBColor.cpp b/layout/style/nsDOMCSSRGBColor.cpp index 3ba6283cd29..322bece4e34 100644 --- a/layout/style/nsDOMCSSRGBColor.cpp +++ b/layout/style/nsDOMCSSRGBColor.cpp @@ -46,8 +46,11 @@ nsDOMCSSRGBColor::nsDOMCSSRGBColor(nsIDOMCSSPrimitiveValue* aRed, nsIDOMCSSPrimitiveValue* aGreen, - nsIDOMCSSPrimitiveValue* aBlue) - : mRed(aRed), mGreen(aGreen), mBlue(aBlue) + nsIDOMCSSPrimitiveValue* aBlue, + nsIDOMCSSPrimitiveValue* aAlpha, + PRBool aHasAlpha) + : mRed(aRed), mGreen(aGreen), mBlue(aBlue), mAlpha(aAlpha) + , mHasAlpha(aHasAlpha) { } @@ -57,6 +60,7 @@ nsDOMCSSRGBColor::~nsDOMCSSRGBColor(void) NS_INTERFACE_MAP_BEGIN(nsDOMCSSRGBColor) NS_INTERFACE_MAP_ENTRY(nsIDOMRGBColor) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSRGBAColor) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSRGBColor) NS_INTERFACE_MAP_END @@ -91,3 +95,12 @@ nsDOMCSSRGBColor::GetBlue(nsIDOMCSSPrimitiveValue** aBlue) NS_ADDREF(*aBlue); return NS_OK; } + +NS_IMETHODIMP +nsDOMCSSRGBColor::GetAlpha(nsIDOMCSSPrimitiveValue** aAlpha) +{ + NS_ENSURE_TRUE(mAlpha, NS_ERROR_NOT_INITIALIZED); + *aAlpha = mAlpha; + NS_ADDREF(*aAlpha); + return NS_OK; +} diff --git a/layout/style/nsDOMCSSRGBColor.h b/layout/style/nsDOMCSSRGBColor.h index cf82c2bcd1e..1139568aa11 100644 --- a/layout/style/nsDOMCSSRGBColor.h +++ b/layout/style/nsDOMCSSRGBColor.h @@ -42,26 +42,33 @@ #define nsDOMCSSRGBColor_h__ #include "nsISupports.h" -#include "nsIDOMRGBColor.h" +#include "nsIDOMNSRGBAColor.h" #include "nsCOMPtr.h" class nsIDOMCSSPrimitiveValue; -class nsDOMCSSRGBColor : public nsIDOMRGBColor { +class nsDOMCSSRGBColor : public nsIDOMNSRGBAColor { public: nsDOMCSSRGBColor(nsIDOMCSSPrimitiveValue* aRed, nsIDOMCSSPrimitiveValue* aGreen, - nsIDOMCSSPrimitiveValue* aBlue); + nsIDOMCSSPrimitiveValue* aBlue, + nsIDOMCSSPrimitiveValue* aAlpha, + PRBool aHasAlpha); virtual ~nsDOMCSSRGBColor(void); NS_DECL_ISUPPORTS NS_DECL_NSIDOMRGBCOLOR + NS_DECL_NSIDOMNSRGBACOLOR + + PRBool HasAlpha() const { return mHasAlpha; } private: nsCOMPtr mRed; nsCOMPtr mGreen; nsCOMPtr mBlue; + nsCOMPtr mAlpha; + PRBool mHasAlpha; }; #endif // nsDOMCSSRGBColor_h__ diff --git a/layout/style/nsROCSSPrimitiveValue.cpp b/layout/style/nsROCSSPrimitiveValue.cpp index 6efb43ed2e4..bb4b7b26662 100644 --- a/layout/style/nsROCSSPrimitiveValue.cpp +++ b/layout/style/nsROCSSPrimitiveValue.cpp @@ -240,7 +240,10 @@ nsROCSSPrimitiveValue::GetCssText(nsAString& aCssText) NS_NAMED_LITERAL_STRING(comma, ", "); nsCOMPtr colorCSSValue; nsAutoString colorValue; - tmpStr.AssignLiteral("rgb("); + if (mValue.mColor->HasAlpha()) + tmpStr.AssignLiteral("rgba("); + else + tmpStr.AssignLiteral("rgb("); // get the red component result = mValue.mColor->GetRed(getter_AddRefs(colorCSSValue)); @@ -267,7 +270,20 @@ nsROCSSPrimitiveValue::GetCssText(nsAString& aCssText) result = colorCSSValue->GetCssText(colorValue); if (NS_FAILED(result)) break; - tmpStr.Append(colorValue + NS_LITERAL_STRING(")")); + tmpStr.Append(colorValue); + + if (mValue.mColor->HasAlpha()) { + // get the alpha component + result = mValue.mColor->GetAlpha(getter_AddRefs(colorCSSValue)); + if (NS_FAILED(result)) + break; + result = colorCSSValue->GetCssText(colorValue); + if (NS_FAILED(result)) + break; + tmpStr.Append(comma + colorValue); + } + + tmpStr.Append(NS_LITERAL_STRING(")")); break; } diff --git a/layout/style/nsROCSSPrimitiveValue.h b/layout/style/nsROCSSPrimitiveValue.h index 15a28b5d617..a3cb355f668 100644 --- a/layout/style/nsROCSSPrimitiveValue.h +++ b/layout/style/nsROCSSPrimitiveValue.h @@ -162,7 +162,7 @@ public: mType = CSS_URI; } - void SetColor(nsIDOMRGBColor* aColor) + void SetColor(nsDOMCSSRGBColor* aColor) { NS_PRECONDITION(aColor, "Null RGBColor being set!"); Reset(); @@ -224,7 +224,7 @@ private: union { nscoord mTwips; float mFloat; - nsIDOMRGBColor* mColor; + nsDOMCSSRGBColor* mColor; nsIDOMRect* mRect; PRUnichar* mString; nsIURI* mURI;