Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 "nsCOMPtr.h"
16 class nsIPrincipal;
17 class nsIDocument;
18 struct JSContext;
19 class JSObject;
21 namespace mozilla {
22 namespace css {
23 class Declaration;
24 class Loader;
25 class Rule;
26 }
27 }
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;
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;
42 NS_DECL_NSICSSDECLARATION
43 using nsICSSDeclaration::GetLength;
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;
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 }
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"
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
90 #undef CSS_PROP_SHORTHAND
91 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
92 #undef CSS_PROP
93 #undef CSS_PROP_PUBLIC_OR_PRIVATE
95 virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) MOZ_OVERRIDE;
97 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
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;
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 };
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;
129 // An implementation for GetCSSParsingEnvironment for callers wrapping
130 // an css::Rule.
131 static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule,
132 CSSParsingEnvironment& aCSSParseEnv);
134 nsresult ParsePropertyValue(const nsCSSProperty aPropID,
135 const nsAString& aPropValue,
136 bool aIsImportant);
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);
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);
148 protected:
149 virtual ~nsDOMCSSDeclaration();
150 nsDOMCSSDeclaration()
151 {
152 SetIsDOMBinding();
153 }
154 };
156 bool IsCSSPropertyExposedToJS(nsCSSProperty aProperty, JSContext* cx, JSObject* obj);
158 template <nsCSSProperty Property>
159 MOZ_ALWAYS_INLINE bool IsCSSPropertyExposedToJS(JSContext* cx, JSObject* obj)
160 {
161 return IsCSSPropertyExposedToJS(Property, cx, obj);
162 }
164 #endif // nsDOMCSSDeclaration_h___