michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* base class for DOM objects for element.style and cssStyleRule.style */ michael@0: michael@0: #ifndef nsDOMCSSDeclaration_h___ michael@0: #define nsDOMCSSDeclaration_h___ michael@0: michael@0: #include "nsICSSDeclaration.h" michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: class nsIPrincipal; michael@0: class nsIDocument; michael@0: struct JSContext; michael@0: class JSObject; michael@0: michael@0: namespace mozilla { michael@0: namespace css { michael@0: class Declaration; michael@0: class Loader; michael@0: class Rule; michael@0: } michael@0: } michael@0: michael@0: class nsDOMCSSDeclaration : public nsICSSDeclaration michael@0: { michael@0: public: michael@0: // Only implement QueryInterface; subclasses have the responsibility michael@0: // of implementing AddRef/Release. michael@0: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE; michael@0: michael@0: // Declare addref and release so they can be called on us, but don't michael@0: // implement them. Our subclasses must handle their own michael@0: // refcounting. michael@0: NS_IMETHOD_(MozExternalRefCountType) AddRef() MOZ_OVERRIDE = 0; michael@0: NS_IMETHOD_(MozExternalRefCountType) Release() MOZ_OVERRIDE = 0; michael@0: michael@0: NS_DECL_NSICSSDECLARATION michael@0: using nsICSSDeclaration::GetLength; michael@0: michael@0: // Require subclasses to implement |GetParentRule|. michael@0: //NS_DECL_NSIDOMCSSSTYLEDECLARATION michael@0: NS_IMETHOD GetCssText(nsAString & aCssText) MOZ_OVERRIDE; michael@0: NS_IMETHOD SetCssText(const nsAString & aCssText) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetPropertyValue(const nsAString & propertyName, michael@0: nsAString & _retval) MOZ_OVERRIDE; michael@0: virtual already_AddRefed michael@0: GetPropertyCSSValue(const nsAString & propertyName, michael@0: mozilla::ErrorResult& aRv) MOZ_OVERRIDE; michael@0: using nsICSSDeclaration::GetPropertyCSSValue; michael@0: NS_IMETHOD RemoveProperty(const nsAString & propertyName, michael@0: nsAString & _retval) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetPropertyPriority(const nsAString & propertyName, michael@0: nsAString & _retval) MOZ_OVERRIDE; michael@0: NS_IMETHOD SetProperty(const nsAString & propertyName, michael@0: const nsAString & value, const nsAString & priority) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetLength(uint32_t *aLength) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) MOZ_OVERRIDE = 0; michael@0: michael@0: // WebIDL interface for CSS2Properties michael@0: #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_ michael@0: #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \ michael@0: kwtable_, stylestruct_, stylestructoffset_, animtype_) \ michael@0: void \ michael@0: Get##method_(nsAString& aValue, mozilla::ErrorResult& rv) \ michael@0: { \ michael@0: rv = GetPropertyValue(eCSSProperty_##id_, aValue); \ michael@0: } \ michael@0: \ michael@0: void \ michael@0: Set##method_(const nsAString& aValue, mozilla::ErrorResult& rv) \ michael@0: { \ michael@0: rv = SetPropertyValue(eCSSProperty_##id_, aValue); \ michael@0: } michael@0: michael@0: #define CSS_PROP_LIST_EXCLUDE_INTERNAL michael@0: #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \ michael@0: CSS_PROP(name_, id_, method_, flags_, pref_, X, X, X, X, X) michael@0: #include "nsCSSPropList.h" michael@0: michael@0: #define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_, pref_) \ michael@0: CSS_PROP(X, propid_, aliasmethod_, X, pref_, X, X, X, X, X) michael@0: #include "nsCSSPropAliasList.h" michael@0: #undef CSS_PROP_ALIAS michael@0: michael@0: #undef CSS_PROP_SHORTHAND michael@0: #undef CSS_PROP_LIST_EXCLUDE_INTERNAL michael@0: #undef CSS_PROP michael@0: #undef CSS_PROP_PUBLIC_OR_PRIVATE michael@0: michael@0: virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) MOZ_OVERRIDE; michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: // This method can return null regardless of the value of aAllocate; michael@0: // however, a null return should only be considered a failure michael@0: // if aAllocate is true. michael@0: virtual mozilla::css::Declaration* GetCSSDeclaration(bool aAllocate) = 0; michael@0: virtual nsresult SetCSSDeclaration(mozilla::css::Declaration* aDecl) = 0; michael@0: // Document that we must call BeginUpdate/EndUpdate on around the michael@0: // calls to SetCSSDeclaration and the style rule mutation that leads michael@0: // to it. michael@0: virtual nsIDocument* DocToUpdate() = 0; michael@0: michael@0: // Information neded to parse a declaration. We need the mSheetURI michael@0: // for error reporting, mBaseURI to resolve relative URIs, michael@0: // mPrincipal for subresource loads, and mCSSLoader for determining michael@0: // whether we're in quirks mode. mBaseURI needs to be a strong michael@0: // pointer because of xml:base possibly creating base URIs on the michael@0: // fly. This is why we don't use CSSParsingEnvironment as a return michael@0: // value, to avoid multiple-refcounting of mBaseURI. michael@0: struct CSSParsingEnvironment { michael@0: nsIURI* mSheetURI; michael@0: nsCOMPtr mBaseURI; michael@0: nsIPrincipal* mPrincipal; michael@0: mozilla::css::Loader* mCSSLoader; michael@0: }; michael@0: michael@0: // On failure, mPrincipal should be set to null in aCSSParseEnv. michael@0: // If mPrincipal is null, the other members may not be set to michael@0: // anything meaningful. michael@0: virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) = 0; michael@0: michael@0: // An implementation for GetCSSParsingEnvironment for callers wrapping michael@0: // an css::Rule. michael@0: static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule, michael@0: CSSParsingEnvironment& aCSSParseEnv); michael@0: michael@0: nsresult ParsePropertyValue(const nsCSSProperty aPropID, michael@0: const nsAString& aPropValue, michael@0: bool aIsImportant); michael@0: michael@0: // Prop-id based version of RemoveProperty. Note that this does not michael@0: // return the old value; it just does a straight removal. michael@0: nsresult RemoveProperty(const nsCSSProperty aPropID); michael@0: michael@0: void GetCustomPropertyValue(const nsAString& aPropertyName, nsAString& aValue); michael@0: nsresult RemoveCustomProperty(const nsAString& aPropertyName); michael@0: nsresult ParseCustomPropertyValue(const nsAString& aPropertyName, michael@0: const nsAString& aPropValue, michael@0: bool aIsImportant); michael@0: michael@0: protected: michael@0: virtual ~nsDOMCSSDeclaration(); michael@0: nsDOMCSSDeclaration() michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: }; michael@0: michael@0: bool IsCSSPropertyExposedToJS(nsCSSProperty aProperty, JSContext* cx, JSObject* obj); michael@0: michael@0: template michael@0: MOZ_ALWAYS_INLINE bool IsCSSPropertyExposedToJS(JSContext* cx, JSObject* obj) michael@0: { michael@0: return IsCSSPropertyExposedToJS(Property, cx, obj); michael@0: } michael@0: michael@0: #endif // nsDOMCSSDeclaration_h___