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: /* michael@0: * faster version of nsIDOMCSSStyleDeclaration using enums instead of michael@0: * strings, for internal use michael@0: */ michael@0: michael@0: #ifndef nsICSSDeclaration_h__ michael@0: #define nsICSSDeclaration_h__ michael@0: michael@0: /** michael@0: * This interface provides access to methods analogous to those of michael@0: * nsIDOMCSSStyleDeclaration; the difference is that these use michael@0: * nsCSSProperty enums for the prop names instead of using strings. michael@0: * This is meant for use in performance-sensitive code only! Most michael@0: * consumers should continue to use nsIDOMCSSStyleDeclaration. michael@0: */ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIDOMCSSStyleDeclaration.h" michael@0: #include "nsCSSProperty.h" michael@0: #include "CSSValue.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsString.h" michael@0: #include "nsIDOMCSSRule.h" michael@0: #include "nsIDOMCSSValue.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsINode.h" michael@0: michael@0: // dbeabbfa-6cb3-4f5c-aec2-dd558d9d681f michael@0: #define NS_ICSSDECLARATION_IID \ michael@0: { 0xdbeabbfa, 0x6cb3, 0x4f5c, \ michael@0: { 0xae, 0xc2, 0xdd, 0x55, 0x8d, 0x9d, 0x68, 0x1f } } michael@0: michael@0: class nsICSSDeclaration : public nsIDOMCSSStyleDeclaration, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSSDECLARATION_IID) michael@0: michael@0: /** michael@0: * Method analogous to nsIDOMCSSStyleDeclaration::GetPropertyValue, michael@0: * which obeys all the same restrictions. michael@0: */ michael@0: NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID, michael@0: nsAString& aValue) = 0; michael@0: michael@0: NS_IMETHOD GetAuthoredPropertyValue(const nsAString& aPropName, michael@0: nsAString& aValue) = 0; michael@0: michael@0: /** michael@0: * Method analogous to nsIDOMCSSStyleDeclaration::SetProperty. This michael@0: * method does NOT allow setting a priority (the priority will michael@0: * always be set to default priority). michael@0: */ michael@0: NS_IMETHOD SetPropertyValue(const nsCSSProperty aPropID, michael@0: const nsAString& aValue) = 0; michael@0: michael@0: virtual nsINode *GetParentObject() = 0; michael@0: michael@0: // Also have to declare all the nsIDOMCSSStyleDeclaration methods, michael@0: // since we want to be able to call them from the WebIDL versions. michael@0: NS_IMETHOD GetCssText(nsAString& aCssText) MOZ_OVERRIDE = 0; michael@0: NS_IMETHOD SetCssText(const nsAString& aCssText) MOZ_OVERRIDE = 0; michael@0: NS_IMETHOD GetPropertyValue(const nsAString& aPropName, michael@0: nsAString& aValue) MOZ_OVERRIDE = 0; michael@0: virtual already_AddRefed michael@0: GetPropertyCSSValue(const nsAString& aPropertyName, michael@0: mozilla::ErrorResult& aRv) = 0; michael@0: NS_IMETHOD GetPropertyCSSValue(const nsAString& aProp, nsIDOMCSSValue** aVal) MOZ_OVERRIDE michael@0: { michael@0: mozilla::ErrorResult error; michael@0: nsRefPtr val = GetPropertyCSSValue(aProp, error); michael@0: if (error.Failed()) { michael@0: return error.ErrorCode(); michael@0: } michael@0: michael@0: nsCOMPtr xpVal = do_QueryInterface(val); michael@0: xpVal.forget(aVal); michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHOD RemoveProperty(const nsAString& aPropertyName, michael@0: nsAString& aReturn) MOZ_OVERRIDE = 0; michael@0: NS_IMETHOD GetPropertyPriority(const nsAString& aPropertyName, michael@0: nsAString& aReturn) MOZ_OVERRIDE = 0; michael@0: NS_IMETHOD SetProperty(const nsAString& aPropertyName, michael@0: const nsAString& aValue, michael@0: const nsAString& aPriority) MOZ_OVERRIDE = 0; michael@0: NS_IMETHOD GetLength(uint32_t* aLength) MOZ_OVERRIDE = 0; michael@0: NS_IMETHOD Item(uint32_t aIndex, nsAString& aReturn) MOZ_OVERRIDE michael@0: { michael@0: bool found; michael@0: IndexedGetter(aIndex, found, aReturn); michael@0: if (!found) { michael@0: aReturn.Truncate(); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) MOZ_OVERRIDE = 0; michael@0: michael@0: // WebIDL interface for CSSStyleDeclaration michael@0: void SetCssText(const nsAString& aString, mozilla::ErrorResult& rv) { michael@0: rv = SetCssText(aString); michael@0: } michael@0: void GetCssText(nsString& aString) { michael@0: // Cast to nsAString& so we end up calling our virtual michael@0: // |GetCssText(nsAString& aCssText)| overload, which does the real work. michael@0: GetCssText(static_cast(aString)); michael@0: } michael@0: uint32_t Length() { michael@0: uint32_t length; michael@0: GetLength(&length); michael@0: return length; michael@0: } michael@0: void Item(uint32_t aIndex, nsString& aPropName) { michael@0: Item(aIndex, static_cast(aPropName)); michael@0: } michael@0: michael@0: // The actual implementation of the Item method and the WebIDL indexed getter michael@0: virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) = 0; michael@0: michael@0: void GetPropertyValue(const nsAString& aPropName, nsString& aValue, michael@0: mozilla::ErrorResult& rv) { michael@0: rv = GetPropertyValue(aPropName, aValue); michael@0: } michael@0: void GetAuthoredPropertyValue(const nsAString& aPropName, nsString& aValue, michael@0: mozilla::ErrorResult& rv) { michael@0: rv = GetAuthoredPropertyValue(aPropName, aValue); michael@0: } michael@0: void GetPropertyPriority(const nsAString& aPropName, nsString& aPriority) { michael@0: GetPropertyPriority(aPropName, static_cast(aPriority)); michael@0: } michael@0: void SetProperty(const nsAString& aPropName, const nsAString& aValue, michael@0: const nsAString& aPriority, mozilla::ErrorResult& rv) { michael@0: rv = SetProperty(aPropName, aValue, aPriority); michael@0: } michael@0: void RemoveProperty(const nsAString& aPropName, nsString& aRetval, michael@0: mozilla::ErrorResult& rv) { michael@0: rv = RemoveProperty(aPropName, aRetval); michael@0: } michael@0: already_AddRefed GetParentRule() { michael@0: nsCOMPtr rule; michael@0: GetParentRule(getter_AddRefs(rule)); michael@0: return rule.forget(); michael@0: } michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSDeclaration, NS_ICSSDECLARATION_IID) michael@0: michael@0: #define NS_DECL_NSICSSDECLARATION \ michael@0: NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID, \ michael@0: nsAString& aValue); \ michael@0: NS_IMETHOD GetAuthoredPropertyValue(const nsAString& aPropName, \ michael@0: nsAString& aValue); \ michael@0: NS_IMETHOD SetPropertyValue(const nsCSSProperty aPropID, \ michael@0: const nsAString& aValue); michael@0: michael@0: #define NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER \ michael@0: NS_IMETHOD GetCssText(nsAString & aCssText); \ michael@0: NS_IMETHOD SetCssText(const nsAString & aCssText); \ michael@0: NS_IMETHOD GetPropertyValue(const nsAString & propertyName, nsAString & _retval); \ michael@0: NS_IMETHOD RemoveProperty(const nsAString & propertyName, nsAString & _retval); \ michael@0: NS_IMETHOD GetPropertyPriority(const nsAString & propertyName, nsAString & _retval); \ michael@0: NS_IMETHOD SetProperty(const nsAString & propertyName, const nsAString & value, const nsAString & priority); \ michael@0: NS_IMETHOD GetLength(uint32_t *aLength); \ michael@0: NS_IMETHOD Item(uint32_t index, nsAString & _retval); \ michael@0: NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule); michael@0: michael@0: #endif // nsICSSDeclaration_h__