|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* base class for DOM objects for element.style and cssStyleRule.style */ |
|
7 |
|
8 #ifndef nsDOMCSSDeclaration_h___ |
|
9 #define nsDOMCSSDeclaration_h___ |
|
10 |
|
11 #include "nsICSSDeclaration.h" |
|
12 |
|
13 #include "mozilla/Attributes.h" |
|
14 #include "nsCOMPtr.h" |
|
15 |
|
16 class nsIPrincipal; |
|
17 class nsIDocument; |
|
18 struct JSContext; |
|
19 class JSObject; |
|
20 |
|
21 namespace mozilla { |
|
22 namespace css { |
|
23 class Declaration; |
|
24 class Loader; |
|
25 class Rule; |
|
26 } |
|
27 } |
|
28 |
|
29 class nsDOMCSSDeclaration : public nsICSSDeclaration |
|
30 { |
|
31 public: |
|
32 // Only implement QueryInterface; subclasses have the responsibility |
|
33 // of implementing AddRef/Release. |
|
34 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE; |
|
35 |
|
36 // Declare addref and release so they can be called on us, but don't |
|
37 // implement them. Our subclasses must handle their own |
|
38 // refcounting. |
|
39 NS_IMETHOD_(MozExternalRefCountType) AddRef() MOZ_OVERRIDE = 0; |
|
40 NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE = 0; |
|
41 |
|
42 NS_DECL_NSICSSDECLARATION |
|
43 using nsICSSDeclaration::GetLength; |
|
44 |
|
45 // Require subclasses to implement |GetParentRule|. |
|
46 //NS_DECL_NSIDOMCSSSTYLEDECLARATION |
|
47 NS_IMETHOD GetCssText(nsAString & aCssText) MOZ_OVERRIDE; |
|
48 NS_IMETHOD SetCssText(const nsAString & aCssText) MOZ_OVERRIDE; |
|
49 NS_IMETHOD GetPropertyValue(const nsAString & propertyName, |
|
50 nsAString & _retval) MOZ_OVERRIDE; |
|
51 virtual already_AddRefed<mozilla::dom::CSSValue> |
|
52 GetPropertyCSSValue(const nsAString & propertyName, |
|
53 mozilla::ErrorResult& aRv) MOZ_OVERRIDE; |
|
54 using nsICSSDeclaration::GetPropertyCSSValue; |
|
55 NS_IMETHOD RemoveProperty(const nsAString & propertyName, |
|
56 nsAString & _retval) MOZ_OVERRIDE; |
|
57 NS_IMETHOD GetPropertyPriority(const nsAString & propertyName, |
|
58 nsAString & _retval) MOZ_OVERRIDE; |
|
59 NS_IMETHOD SetProperty(const nsAString & propertyName, |
|
60 const nsAString & value, const nsAString & priority) MOZ_OVERRIDE; |
|
61 NS_IMETHOD GetLength(uint32_t *aLength) MOZ_OVERRIDE; |
|
62 NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) MOZ_OVERRIDE = 0; |
|
63 |
|
64 // WebIDL interface for CSS2Properties |
|
65 #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_ |
|
66 #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \ |
|
67 kwtable_, stylestruct_, stylestructoffset_, animtype_) \ |
|
68 void \ |
|
69 Get##method_(nsAString& aValue, mozilla::ErrorResult& rv) \ |
|
70 { \ |
|
71 rv = GetPropertyValue(eCSSProperty_##id_, aValue); \ |
|
72 } \ |
|
73 \ |
|
74 void \ |
|
75 Set##method_(const nsAString& aValue, mozilla::ErrorResult& rv) \ |
|
76 { \ |
|
77 rv = SetPropertyValue(eCSSProperty_##id_, aValue); \ |
|
78 } |
|
79 |
|
80 #define CSS_PROP_LIST_EXCLUDE_INTERNAL |
|
81 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \ |
|
82 CSS_PROP(name_, id_, method_, flags_, pref_, X, X, X, X, X) |
|
83 #include "nsCSSPropList.h" |
|
84 |
|
85 #define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_, pref_) \ |
|
86 CSS_PROP(X, propid_, aliasmethod_, X, pref_, X, X, X, X, X) |
|
87 #include "nsCSSPropAliasList.h" |
|
88 #undef CSS_PROP_ALIAS |
|
89 |
|
90 #undef CSS_PROP_SHORTHAND |
|
91 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL |
|
92 #undef CSS_PROP |
|
93 #undef CSS_PROP_PUBLIC_OR_PRIVATE |
|
94 |
|
95 virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) MOZ_OVERRIDE; |
|
96 |
|
97 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
98 |
|
99 protected: |
|
100 // This method can return null regardless of the value of aAllocate; |
|
101 // however, a null return should only be considered a failure |
|
102 // if aAllocate is true. |
|
103 virtual mozilla::css::Declaration* GetCSSDeclaration(bool aAllocate) = 0; |
|
104 virtual nsresult SetCSSDeclaration(mozilla::css::Declaration* aDecl) = 0; |
|
105 // Document that we must call BeginUpdate/EndUpdate on around the |
|
106 // calls to SetCSSDeclaration and the style rule mutation that leads |
|
107 // to it. |
|
108 virtual nsIDocument* DocToUpdate() = 0; |
|
109 |
|
110 // Information neded to parse a declaration. We need the mSheetURI |
|
111 // for error reporting, mBaseURI to resolve relative URIs, |
|
112 // mPrincipal for subresource loads, and mCSSLoader for determining |
|
113 // whether we're in quirks mode. mBaseURI needs to be a strong |
|
114 // pointer because of xml:base possibly creating base URIs on the |
|
115 // fly. This is why we don't use CSSParsingEnvironment as a return |
|
116 // value, to avoid multiple-refcounting of mBaseURI. |
|
117 struct CSSParsingEnvironment { |
|
118 nsIURI* mSheetURI; |
|
119 nsCOMPtr<nsIURI> mBaseURI; |
|
120 nsIPrincipal* mPrincipal; |
|
121 mozilla::css::Loader* mCSSLoader; |
|
122 }; |
|
123 |
|
124 // On failure, mPrincipal should be set to null in aCSSParseEnv. |
|
125 // If mPrincipal is null, the other members may not be set to |
|
126 // anything meaningful. |
|
127 virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) = 0; |
|
128 |
|
129 // An implementation for GetCSSParsingEnvironment for callers wrapping |
|
130 // an css::Rule. |
|
131 static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule, |
|
132 CSSParsingEnvironment& aCSSParseEnv); |
|
133 |
|
134 nsresult ParsePropertyValue(const nsCSSProperty aPropID, |
|
135 const nsAString& aPropValue, |
|
136 bool aIsImportant); |
|
137 |
|
138 // Prop-id based version of RemoveProperty. Note that this does not |
|
139 // return the old value; it just does a straight removal. |
|
140 nsresult RemoveProperty(const nsCSSProperty aPropID); |
|
141 |
|
142 void GetCustomPropertyValue(const nsAString& aPropertyName, nsAString& aValue); |
|
143 nsresult RemoveCustomProperty(const nsAString& aPropertyName); |
|
144 nsresult ParseCustomPropertyValue(const nsAString& aPropertyName, |
|
145 const nsAString& aPropValue, |
|
146 bool aIsImportant); |
|
147 |
|
148 protected: |
|
149 virtual ~nsDOMCSSDeclaration(); |
|
150 nsDOMCSSDeclaration() |
|
151 { |
|
152 SetIsDOMBinding(); |
|
153 } |
|
154 }; |
|
155 |
|
156 bool IsCSSPropertyExposedToJS(nsCSSProperty aProperty, JSContext* cx, JSObject* obj); |
|
157 |
|
158 template <nsCSSProperty Property> |
|
159 MOZ_ALWAYS_INLINE bool IsCSSPropertyExposedToJS(JSContext* cx, JSObject* obj) |
|
160 { |
|
161 return IsCSSPropertyExposedToJS(Property, cx, obj); |
|
162 } |
|
163 |
|
164 #endif // nsDOMCSSDeclaration_h___ |