1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsICSSDeclaration.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,174 @@ 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 +/* 1.10 + * faster version of nsIDOMCSSStyleDeclaration using enums instead of 1.11 + * strings, for internal use 1.12 + */ 1.13 + 1.14 +#ifndef nsICSSDeclaration_h__ 1.15 +#define nsICSSDeclaration_h__ 1.16 + 1.17 +/** 1.18 + * This interface provides access to methods analogous to those of 1.19 + * nsIDOMCSSStyleDeclaration; the difference is that these use 1.20 + * nsCSSProperty enums for the prop names instead of using strings. 1.21 + * This is meant for use in performance-sensitive code only! Most 1.22 + * consumers should continue to use nsIDOMCSSStyleDeclaration. 1.23 + */ 1.24 + 1.25 +#include "mozilla/Attributes.h" 1.26 +#include "nsIDOMCSSStyleDeclaration.h" 1.27 +#include "nsCSSProperty.h" 1.28 +#include "CSSValue.h" 1.29 +#include "nsWrapperCache.h" 1.30 +#include "nsString.h" 1.31 +#include "nsIDOMCSSRule.h" 1.32 +#include "nsIDOMCSSValue.h" 1.33 +#include "mozilla/ErrorResult.h" 1.34 +#include "nsAutoPtr.h" 1.35 +#include "nsCOMPtr.h" 1.36 +#include "nsINode.h" 1.37 + 1.38 +// dbeabbfa-6cb3-4f5c-aec2-dd558d9d681f 1.39 +#define NS_ICSSDECLARATION_IID \ 1.40 +{ 0xdbeabbfa, 0x6cb3, 0x4f5c, \ 1.41 + { 0xae, 0xc2, 0xdd, 0x55, 0x8d, 0x9d, 0x68, 0x1f } } 1.42 + 1.43 +class nsICSSDeclaration : public nsIDOMCSSStyleDeclaration, 1.44 + public nsWrapperCache 1.45 +{ 1.46 +public: 1.47 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSSDECLARATION_IID) 1.48 + 1.49 + /** 1.50 + * Method analogous to nsIDOMCSSStyleDeclaration::GetPropertyValue, 1.51 + * which obeys all the same restrictions. 1.52 + */ 1.53 + NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID, 1.54 + nsAString& aValue) = 0; 1.55 + 1.56 + NS_IMETHOD GetAuthoredPropertyValue(const nsAString& aPropName, 1.57 + nsAString& aValue) = 0; 1.58 + 1.59 + /** 1.60 + * Method analogous to nsIDOMCSSStyleDeclaration::SetProperty. This 1.61 + * method does NOT allow setting a priority (the priority will 1.62 + * always be set to default priority). 1.63 + */ 1.64 + NS_IMETHOD SetPropertyValue(const nsCSSProperty aPropID, 1.65 + const nsAString& aValue) = 0; 1.66 + 1.67 + virtual nsINode *GetParentObject() = 0; 1.68 + 1.69 + // Also have to declare all the nsIDOMCSSStyleDeclaration methods, 1.70 + // since we want to be able to call them from the WebIDL versions. 1.71 + NS_IMETHOD GetCssText(nsAString& aCssText) MOZ_OVERRIDE = 0; 1.72 + NS_IMETHOD SetCssText(const nsAString& aCssText) MOZ_OVERRIDE = 0; 1.73 + NS_IMETHOD GetPropertyValue(const nsAString& aPropName, 1.74 + nsAString& aValue) MOZ_OVERRIDE = 0; 1.75 + virtual already_AddRefed<mozilla::dom::CSSValue> 1.76 + GetPropertyCSSValue(const nsAString& aPropertyName, 1.77 + mozilla::ErrorResult& aRv) = 0; 1.78 + NS_IMETHOD GetPropertyCSSValue(const nsAString& aProp, nsIDOMCSSValue** aVal) MOZ_OVERRIDE 1.79 + { 1.80 + mozilla::ErrorResult error; 1.81 + nsRefPtr<mozilla::dom::CSSValue> val = GetPropertyCSSValue(aProp, error); 1.82 + if (error.Failed()) { 1.83 + return error.ErrorCode(); 1.84 + } 1.85 + 1.86 + nsCOMPtr<nsIDOMCSSValue> xpVal = do_QueryInterface(val); 1.87 + xpVal.forget(aVal); 1.88 + return NS_OK; 1.89 + } 1.90 + NS_IMETHOD RemoveProperty(const nsAString& aPropertyName, 1.91 + nsAString& aReturn) MOZ_OVERRIDE = 0; 1.92 + NS_IMETHOD GetPropertyPriority(const nsAString& aPropertyName, 1.93 + nsAString& aReturn) MOZ_OVERRIDE = 0; 1.94 + NS_IMETHOD SetProperty(const nsAString& aPropertyName, 1.95 + const nsAString& aValue, 1.96 + const nsAString& aPriority) MOZ_OVERRIDE = 0; 1.97 + NS_IMETHOD GetLength(uint32_t* aLength) MOZ_OVERRIDE = 0; 1.98 + NS_IMETHOD Item(uint32_t aIndex, nsAString& aReturn) MOZ_OVERRIDE 1.99 + { 1.100 + bool found; 1.101 + IndexedGetter(aIndex, found, aReturn); 1.102 + if (!found) { 1.103 + aReturn.Truncate(); 1.104 + } 1.105 + return NS_OK; 1.106 + } 1.107 + NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) MOZ_OVERRIDE = 0; 1.108 + 1.109 + // WebIDL interface for CSSStyleDeclaration 1.110 + void SetCssText(const nsAString& aString, mozilla::ErrorResult& rv) { 1.111 + rv = SetCssText(aString); 1.112 + } 1.113 + void GetCssText(nsString& aString) { 1.114 + // Cast to nsAString& so we end up calling our virtual 1.115 + // |GetCssText(nsAString& aCssText)| overload, which does the real work. 1.116 + GetCssText(static_cast<nsAString&>(aString)); 1.117 + } 1.118 + uint32_t Length() { 1.119 + uint32_t length; 1.120 + GetLength(&length); 1.121 + return length; 1.122 + } 1.123 + void Item(uint32_t aIndex, nsString& aPropName) { 1.124 + Item(aIndex, static_cast<nsAString&>(aPropName)); 1.125 + } 1.126 + 1.127 + // The actual implementation of the Item method and the WebIDL indexed getter 1.128 + virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) = 0; 1.129 + 1.130 + void GetPropertyValue(const nsAString& aPropName, nsString& aValue, 1.131 + mozilla::ErrorResult& rv) { 1.132 + rv = GetPropertyValue(aPropName, aValue); 1.133 + } 1.134 + void GetAuthoredPropertyValue(const nsAString& aPropName, nsString& aValue, 1.135 + mozilla::ErrorResult& rv) { 1.136 + rv = GetAuthoredPropertyValue(aPropName, aValue); 1.137 + } 1.138 + void GetPropertyPriority(const nsAString& aPropName, nsString& aPriority) { 1.139 + GetPropertyPriority(aPropName, static_cast<nsAString&>(aPriority)); 1.140 + } 1.141 + void SetProperty(const nsAString& aPropName, const nsAString& aValue, 1.142 + const nsAString& aPriority, mozilla::ErrorResult& rv) { 1.143 + rv = SetProperty(aPropName, aValue, aPriority); 1.144 + } 1.145 + void RemoveProperty(const nsAString& aPropName, nsString& aRetval, 1.146 + mozilla::ErrorResult& rv) { 1.147 + rv = RemoveProperty(aPropName, aRetval); 1.148 + } 1.149 + already_AddRefed<nsIDOMCSSRule> GetParentRule() { 1.150 + nsCOMPtr<nsIDOMCSSRule> rule; 1.151 + GetParentRule(getter_AddRefs(rule)); 1.152 + return rule.forget(); 1.153 + } 1.154 +}; 1.155 + 1.156 +NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSDeclaration, NS_ICSSDECLARATION_IID) 1.157 + 1.158 +#define NS_DECL_NSICSSDECLARATION \ 1.159 + NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID, \ 1.160 + nsAString& aValue); \ 1.161 + NS_IMETHOD GetAuthoredPropertyValue(const nsAString& aPropName, \ 1.162 + nsAString& aValue); \ 1.163 + NS_IMETHOD SetPropertyValue(const nsCSSProperty aPropID, \ 1.164 + const nsAString& aValue); 1.165 + 1.166 +#define NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER \ 1.167 + NS_IMETHOD GetCssText(nsAString & aCssText); \ 1.168 + NS_IMETHOD SetCssText(const nsAString & aCssText); \ 1.169 + NS_IMETHOD GetPropertyValue(const nsAString & propertyName, nsAString & _retval); \ 1.170 + NS_IMETHOD RemoveProperty(const nsAString & propertyName, nsAString & _retval); \ 1.171 + NS_IMETHOD GetPropertyPriority(const nsAString & propertyName, nsAString & _retval); \ 1.172 + NS_IMETHOD SetProperty(const nsAString & propertyName, const nsAString & value, const nsAString & priority); \ 1.173 + NS_IMETHOD GetLength(uint32_t *aLength); \ 1.174 + NS_IMETHOD Item(uint32_t index, nsAString & _retval); \ 1.175 + NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule); 1.176 + 1.177 +#endif // nsICSSDeclaration_h__