From dafe525b26bb875ac17ba6d28046cb110184fabd Mon Sep 17 00:00:00 2001 From: "dbaron%dbaron.org" Date: Tue, 24 Feb 2004 06:48:25 +0000 Subject: [PATCH] Change -moz-opacity to opacity. Create a mechanism for creating a second name for a CSS property and continue to support -moz-opacity. b=93156 r=bzbarsky sr=roc git-svn-id: svn://10.0.0.236/trunk@153148 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/style/src/nsDOMCSSDeclaration.cpp | 4 ++ mozilla/content/shared/public/nsCSSPropList.h | 2 +- mozilla/content/shared/src/nsCSSProps.cpp | 42 +++++++++++++++---- .../public/idl/css/nsIDOMCSS2Properties.idl | 7 ++++ mozilla/layout/style/nsCSSPropList.h | 2 +- mozilla/layout/style/nsCSSProps.cpp | 42 +++++++++++++++---- mozilla/layout/style/nsDOMCSSDeclaration.cpp | 4 ++ 7 files changed, 85 insertions(+), 18 deletions(-) diff --git a/mozilla/content/html/style/src/nsDOMCSSDeclaration.cpp b/mozilla/content/html/style/src/nsDOMCSSDeclaration.cpp index 5ca6c025efb..5d27032a88d 100644 --- a/mozilla/content/html/style/src/nsDOMCSSDeclaration.cpp +++ b/mozilla/content/html/style/src/nsDOMCSSDeclaration.cpp @@ -345,6 +345,10 @@ CSS2PropertiesTearoff::QueryInterface(REFNSIID aIID, void** aInstancePtr) #define CSS_PROP_SHORTHAND(name_, id_, method_) \ CSS_PROP(name_, id_, method_, , , , ,) #include "nsCSSPropList.h" + +// Aliases +CSS_PROP(opacity, X, MozOpacity, X, X, X, X, X) + #undef CSS_PROP_SHORTHAND #undef CSS_PROP_NOTIMPLEMENTED #undef CSS_PROP_LIST_EXCLUDE_INTERNAL diff --git a/mozilla/content/shared/public/nsCSSPropList.h b/mozilla/content/shared/public/nsCSSPropList.h index 2e14234a135..f0e71881c65 100644 --- a/mozilla/content/shared/public/nsCSSPropList.h +++ b/mozilla/content/shared/public/nsCSSPropList.h @@ -389,7 +389,7 @@ CSS_PROP_POSITION(max-height, max_height, MaxHeight, Position, mMaxHeight, eCSST CSS_PROP_POSITION(max-width, max_width, MaxWidth, Position, mMaxWidth, eCSSType_Value, PR_TRUE, nsnull) CSS_PROP_POSITION(min-height, min_height, MinHeight, Position, mMinHeight, eCSSType_Value, PR_TRUE, nsnull) CSS_PROP_POSITION(min-width, min_width, MinWidth, Position, mMinWidth, eCSSType_Value, PR_TRUE, nsnull) -CSS_PROP_DISPLAY(-moz-opacity, opacity, MozOpacity, Display, mOpacity, eCSSType_Value, PR_FALSE, nsnull) // XXX bug 3935 +CSS_PROP_DISPLAY(opacity, opacity, Opacity, Display, mOpacity, eCSSType_Value, PR_FALSE, nsnull) // XXX bug 3935 CSS_PROP_BACKENDONLY(orphans, orphans, Orphans, Breaks, mOrphans, eCSSType_Value, PR_FALSE, nsnull) CSS_PROP_NOTIMPLEMENTED(outline, outline, Outline) CSS_PROP_NOTIMPLEMENTED(outline-color, outline_color, OutlineColor) diff --git a/mozilla/content/shared/src/nsCSSProps.cpp b/mozilla/content/shared/src/nsCSSProps.cpp index c95706f2b09..735ce6749c7 100644 --- a/mozilla/content/shared/src/nsCSSProps.cpp +++ b/mozilla/content/shared/src/nsCSSProps.cpp @@ -99,14 +99,32 @@ nsCSSProps::ReleaseTable(void) } } +struct CSSPropertyAlias { + const char name[13]; + nsCSSProperty id; +}; + +static const CSSPropertyAlias gAliases[] = { + { "-moz-opacity", eCSSProperty_opacity } +}; + nsCSSProperty nsCSSProps::LookupProperty(const nsACString& aProperty) { NS_ASSERTION(gPropertyTable, "no lookup table, needs addref"); - if (gPropertyTable) { - return nsCSSProperty(gPropertyTable->Lookup(aProperty)); - } - return eCSSProperty_UNKNOWN; + + nsCSSProperty res = nsCSSProperty(gPropertyTable->Lookup(aProperty)); + if (res == eCSSProperty_UNKNOWN) { + const nsCString& prop = PromiseFlatCString(aProperty); + for (const CSSPropertyAlias *alias = gAliases, + *alias_end = gAliases + NS_ARRAY_LENGTH(gAliases); + alias < alias_end; ++alias) + if (nsCRT::strcasecmp(prop.get(), alias->name) == 0) { + res = alias->id; + break; + } + } + return res; } nsCSSProperty @@ -115,10 +133,18 @@ nsCSSProps::LookupProperty(const nsAString& aProperty) { // LookupProperty(nsACString&). The table will do its own // converting and avoid a PromiseFlatCString() call. NS_ASSERTION(gPropertyTable, "no lookup table, needs addref"); - if (gPropertyTable) { - return nsCSSProperty(gPropertyTable->Lookup(aProperty)); - } - return eCSSProperty_UNKNOWN; + nsCSSProperty res = nsCSSProperty(gPropertyTable->Lookup(aProperty)); + if (res == eCSSProperty_UNKNOWN) { + NS_ConvertUTF16toUTF8 prop(aProperty); + for (const CSSPropertyAlias *alias = gAliases, + *alias_end = gAliases + NS_ARRAY_LENGTH(gAliases); + alias < alias_end; ++alias) + if (nsCRT::strcasecmp(prop.get(), alias->name) == 0) { + res = alias->id; + break; + } + } + return res; } const nsAFlatCString& diff --git a/mozilla/dom/public/idl/css/nsIDOMCSS2Properties.idl b/mozilla/dom/public/idl/css/nsIDOMCSS2Properties.idl index 590971738aa..261fdd4b49e 100644 --- a/mozilla/dom/public/idl/css/nsIDOMCSS2Properties.idl +++ b/mozilla/dom/public/idl/css/nsIDOMCSS2Properties.idl @@ -414,6 +414,8 @@ interface nsIDOMCSS2Properties : nsISupports interface nsIDOMNSCSS2Properties : nsIDOMCSS2Properties { /* Non-DOM 2 extensions */ + + /* Mozilla extension CSS properties */ attribute DOMString MozAppearance; // raises(DOMException) on setting @@ -551,4 +553,9 @@ interface nsIDOMNSCSS2Properties : nsIDOMCSS2Properties attribute DOMString MozUserSelect; // raises(DOMException) on setting + + /* CSS3 properties */ + attribute DOMString Opacity; + // raises(DOMException) on setting + }; diff --git a/mozilla/layout/style/nsCSSPropList.h b/mozilla/layout/style/nsCSSPropList.h index 2e14234a135..f0e71881c65 100644 --- a/mozilla/layout/style/nsCSSPropList.h +++ b/mozilla/layout/style/nsCSSPropList.h @@ -389,7 +389,7 @@ CSS_PROP_POSITION(max-height, max_height, MaxHeight, Position, mMaxHeight, eCSST CSS_PROP_POSITION(max-width, max_width, MaxWidth, Position, mMaxWidth, eCSSType_Value, PR_TRUE, nsnull) CSS_PROP_POSITION(min-height, min_height, MinHeight, Position, mMinHeight, eCSSType_Value, PR_TRUE, nsnull) CSS_PROP_POSITION(min-width, min_width, MinWidth, Position, mMinWidth, eCSSType_Value, PR_TRUE, nsnull) -CSS_PROP_DISPLAY(-moz-opacity, opacity, MozOpacity, Display, mOpacity, eCSSType_Value, PR_FALSE, nsnull) // XXX bug 3935 +CSS_PROP_DISPLAY(opacity, opacity, Opacity, Display, mOpacity, eCSSType_Value, PR_FALSE, nsnull) // XXX bug 3935 CSS_PROP_BACKENDONLY(orphans, orphans, Orphans, Breaks, mOrphans, eCSSType_Value, PR_FALSE, nsnull) CSS_PROP_NOTIMPLEMENTED(outline, outline, Outline) CSS_PROP_NOTIMPLEMENTED(outline-color, outline_color, OutlineColor) diff --git a/mozilla/layout/style/nsCSSProps.cpp b/mozilla/layout/style/nsCSSProps.cpp index c95706f2b09..735ce6749c7 100644 --- a/mozilla/layout/style/nsCSSProps.cpp +++ b/mozilla/layout/style/nsCSSProps.cpp @@ -99,14 +99,32 @@ nsCSSProps::ReleaseTable(void) } } +struct CSSPropertyAlias { + const char name[13]; + nsCSSProperty id; +}; + +static const CSSPropertyAlias gAliases[] = { + { "-moz-opacity", eCSSProperty_opacity } +}; + nsCSSProperty nsCSSProps::LookupProperty(const nsACString& aProperty) { NS_ASSERTION(gPropertyTable, "no lookup table, needs addref"); - if (gPropertyTable) { - return nsCSSProperty(gPropertyTable->Lookup(aProperty)); - } - return eCSSProperty_UNKNOWN; + + nsCSSProperty res = nsCSSProperty(gPropertyTable->Lookup(aProperty)); + if (res == eCSSProperty_UNKNOWN) { + const nsCString& prop = PromiseFlatCString(aProperty); + for (const CSSPropertyAlias *alias = gAliases, + *alias_end = gAliases + NS_ARRAY_LENGTH(gAliases); + alias < alias_end; ++alias) + if (nsCRT::strcasecmp(prop.get(), alias->name) == 0) { + res = alias->id; + break; + } + } + return res; } nsCSSProperty @@ -115,10 +133,18 @@ nsCSSProps::LookupProperty(const nsAString& aProperty) { // LookupProperty(nsACString&). The table will do its own // converting and avoid a PromiseFlatCString() call. NS_ASSERTION(gPropertyTable, "no lookup table, needs addref"); - if (gPropertyTable) { - return nsCSSProperty(gPropertyTable->Lookup(aProperty)); - } - return eCSSProperty_UNKNOWN; + nsCSSProperty res = nsCSSProperty(gPropertyTable->Lookup(aProperty)); + if (res == eCSSProperty_UNKNOWN) { + NS_ConvertUTF16toUTF8 prop(aProperty); + for (const CSSPropertyAlias *alias = gAliases, + *alias_end = gAliases + NS_ARRAY_LENGTH(gAliases); + alias < alias_end; ++alias) + if (nsCRT::strcasecmp(prop.get(), alias->name) == 0) { + res = alias->id; + break; + } + } + return res; } const nsAFlatCString& diff --git a/mozilla/layout/style/nsDOMCSSDeclaration.cpp b/mozilla/layout/style/nsDOMCSSDeclaration.cpp index 5ca6c025efb..5d27032a88d 100644 --- a/mozilla/layout/style/nsDOMCSSDeclaration.cpp +++ b/mozilla/layout/style/nsDOMCSSDeclaration.cpp @@ -345,6 +345,10 @@ CSS2PropertiesTearoff::QueryInterface(REFNSIID aIID, void** aInstancePtr) #define CSS_PROP_SHORTHAND(name_, id_, method_) \ CSS_PROP(name_, id_, method_, , , , ,) #include "nsCSSPropList.h" + +// Aliases +CSS_PROP(opacity, X, MozOpacity, X, X, X, X, X) + #undef CSS_PROP_SHORTHAND #undef CSS_PROP_NOTIMPLEMENTED #undef CSS_PROP_LIST_EXCLUDE_INTERNAL