1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsDOMCSSDeclaration.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* base class for DOM objects for element.style and cssStyleRule.style */ 1.10 + 1.11 +#ifndef nsDOMCSSDeclaration_h___ 1.12 +#define nsDOMCSSDeclaration_h___ 1.13 + 1.14 +#include "nsICSSDeclaration.h" 1.15 + 1.16 +#include "mozilla/Attributes.h" 1.17 +#include "nsCOMPtr.h" 1.18 + 1.19 +class nsIPrincipal; 1.20 +class nsIDocument; 1.21 +struct JSContext; 1.22 +class JSObject; 1.23 + 1.24 +namespace mozilla { 1.25 +namespace css { 1.26 +class Declaration; 1.27 +class Loader; 1.28 +class Rule; 1.29 +} 1.30 +} 1.31 + 1.32 +class nsDOMCSSDeclaration : public nsICSSDeclaration 1.33 +{ 1.34 +public: 1.35 + // Only implement QueryInterface; subclasses have the responsibility 1.36 + // of implementing AddRef/Release. 1.37 + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE; 1.38 + 1.39 + // Declare addref and release so they can be called on us, but don't 1.40 + // implement them. Our subclasses must handle their own 1.41 + // refcounting. 1.42 + NS_IMETHOD_(MozExternalRefCountType) AddRef() MOZ_OVERRIDE = 0; 1.43 + NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE = 0; 1.44 + 1.45 + NS_DECL_NSICSSDECLARATION 1.46 + using nsICSSDeclaration::GetLength; 1.47 + 1.48 + // Require subclasses to implement |GetParentRule|. 1.49 + //NS_DECL_NSIDOMCSSSTYLEDECLARATION 1.50 + NS_IMETHOD GetCssText(nsAString & aCssText) MOZ_OVERRIDE; 1.51 + NS_IMETHOD SetCssText(const nsAString & aCssText) MOZ_OVERRIDE; 1.52 + NS_IMETHOD GetPropertyValue(const nsAString & propertyName, 1.53 + nsAString & _retval) MOZ_OVERRIDE; 1.54 + virtual already_AddRefed<mozilla::dom::CSSValue> 1.55 + GetPropertyCSSValue(const nsAString & propertyName, 1.56 + mozilla::ErrorResult& aRv) MOZ_OVERRIDE; 1.57 + using nsICSSDeclaration::GetPropertyCSSValue; 1.58 + NS_IMETHOD RemoveProperty(const nsAString & propertyName, 1.59 + nsAString & _retval) MOZ_OVERRIDE; 1.60 + NS_IMETHOD GetPropertyPriority(const nsAString & propertyName, 1.61 + nsAString & _retval) MOZ_OVERRIDE; 1.62 + NS_IMETHOD SetProperty(const nsAString & propertyName, 1.63 + const nsAString & value, const nsAString & priority) MOZ_OVERRIDE; 1.64 + NS_IMETHOD GetLength(uint32_t *aLength) MOZ_OVERRIDE; 1.65 + NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) MOZ_OVERRIDE = 0; 1.66 + 1.67 + // WebIDL interface for CSS2Properties 1.68 +#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_ 1.69 +#define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \ 1.70 + kwtable_, stylestruct_, stylestructoffset_, animtype_) \ 1.71 + void \ 1.72 + Get##method_(nsAString& aValue, mozilla::ErrorResult& rv) \ 1.73 + { \ 1.74 + rv = GetPropertyValue(eCSSProperty_##id_, aValue); \ 1.75 + } \ 1.76 + \ 1.77 + void \ 1.78 + Set##method_(const nsAString& aValue, mozilla::ErrorResult& rv) \ 1.79 + { \ 1.80 + rv = SetPropertyValue(eCSSProperty_##id_, aValue); \ 1.81 + } 1.82 + 1.83 +#define CSS_PROP_LIST_EXCLUDE_INTERNAL 1.84 +#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \ 1.85 + CSS_PROP(name_, id_, method_, flags_, pref_, X, X, X, X, X) 1.86 +#include "nsCSSPropList.h" 1.87 + 1.88 +#define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_, pref_) \ 1.89 + CSS_PROP(X, propid_, aliasmethod_, X, pref_, X, X, X, X, X) 1.90 +#include "nsCSSPropAliasList.h" 1.91 +#undef CSS_PROP_ALIAS 1.92 + 1.93 +#undef CSS_PROP_SHORTHAND 1.94 +#undef CSS_PROP_LIST_EXCLUDE_INTERNAL 1.95 +#undef CSS_PROP 1.96 +#undef CSS_PROP_PUBLIC_OR_PRIVATE 1.97 + 1.98 + virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) MOZ_OVERRIDE; 1.99 + 1.100 + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.101 + 1.102 +protected: 1.103 + // This method can return null regardless of the value of aAllocate; 1.104 + // however, a null return should only be considered a failure 1.105 + // if aAllocate is true. 1.106 + virtual mozilla::css::Declaration* GetCSSDeclaration(bool aAllocate) = 0; 1.107 + virtual nsresult SetCSSDeclaration(mozilla::css::Declaration* aDecl) = 0; 1.108 + // Document that we must call BeginUpdate/EndUpdate on around the 1.109 + // calls to SetCSSDeclaration and the style rule mutation that leads 1.110 + // to it. 1.111 + virtual nsIDocument* DocToUpdate() = 0; 1.112 + 1.113 + // Information neded to parse a declaration. We need the mSheetURI 1.114 + // for error reporting, mBaseURI to resolve relative URIs, 1.115 + // mPrincipal for subresource loads, and mCSSLoader for determining 1.116 + // whether we're in quirks mode. mBaseURI needs to be a strong 1.117 + // pointer because of xml:base possibly creating base URIs on the 1.118 + // fly. This is why we don't use CSSParsingEnvironment as a return 1.119 + // value, to avoid multiple-refcounting of mBaseURI. 1.120 + struct CSSParsingEnvironment { 1.121 + nsIURI* mSheetURI; 1.122 + nsCOMPtr<nsIURI> mBaseURI; 1.123 + nsIPrincipal* mPrincipal; 1.124 + mozilla::css::Loader* mCSSLoader; 1.125 + }; 1.126 + 1.127 + // On failure, mPrincipal should be set to null in aCSSParseEnv. 1.128 + // If mPrincipal is null, the other members may not be set to 1.129 + // anything meaningful. 1.130 + virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) = 0; 1.131 + 1.132 + // An implementation for GetCSSParsingEnvironment for callers wrapping 1.133 + // an css::Rule. 1.134 + static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule, 1.135 + CSSParsingEnvironment& aCSSParseEnv); 1.136 + 1.137 + nsresult ParsePropertyValue(const nsCSSProperty aPropID, 1.138 + const nsAString& aPropValue, 1.139 + bool aIsImportant); 1.140 + 1.141 + // Prop-id based version of RemoveProperty. Note that this does not 1.142 + // return the old value; it just does a straight removal. 1.143 + nsresult RemoveProperty(const nsCSSProperty aPropID); 1.144 + 1.145 + void GetCustomPropertyValue(const nsAString& aPropertyName, nsAString& aValue); 1.146 + nsresult RemoveCustomProperty(const nsAString& aPropertyName); 1.147 + nsresult ParseCustomPropertyValue(const nsAString& aPropertyName, 1.148 + const nsAString& aPropValue, 1.149 + bool aIsImportant); 1.150 + 1.151 +protected: 1.152 + virtual ~nsDOMCSSDeclaration(); 1.153 + nsDOMCSSDeclaration() 1.154 + { 1.155 + SetIsDOMBinding(); 1.156 + } 1.157 +}; 1.158 + 1.159 +bool IsCSSPropertyExposedToJS(nsCSSProperty aProperty, JSContext* cx, JSObject* obj); 1.160 + 1.161 +template <nsCSSProperty Property> 1.162 +MOZ_ALWAYS_INLINE bool IsCSSPropertyExposedToJS(JSContext* cx, JSObject* obj) 1.163 +{ 1.164 + return IsCSSPropertyExposedToJS(Property, cx, obj); 1.165 +} 1.166 + 1.167 +#endif // nsDOMCSSDeclaration_h___