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