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