layout/style/nsICSSDeclaration.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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 /*
michael@0 7 * faster version of nsIDOMCSSStyleDeclaration using enums instead of
michael@0 8 * strings, for internal use
michael@0 9 */
michael@0 10
michael@0 11 #ifndef nsICSSDeclaration_h__
michael@0 12 #define nsICSSDeclaration_h__
michael@0 13
michael@0 14 /**
michael@0 15 * This interface provides access to methods analogous to those of
michael@0 16 * nsIDOMCSSStyleDeclaration; the difference is that these use
michael@0 17 * nsCSSProperty enums for the prop names instead of using strings.
michael@0 18 * This is meant for use in performance-sensitive code only! Most
michael@0 19 * consumers should continue to use nsIDOMCSSStyleDeclaration.
michael@0 20 */
michael@0 21
michael@0 22 #include "mozilla/Attributes.h"
michael@0 23 #include "nsIDOMCSSStyleDeclaration.h"
michael@0 24 #include "nsCSSProperty.h"
michael@0 25 #include "CSSValue.h"
michael@0 26 #include "nsWrapperCache.h"
michael@0 27 #include "nsString.h"
michael@0 28 #include "nsIDOMCSSRule.h"
michael@0 29 #include "nsIDOMCSSValue.h"
michael@0 30 #include "mozilla/ErrorResult.h"
michael@0 31 #include "nsAutoPtr.h"
michael@0 32 #include "nsCOMPtr.h"
michael@0 33 #include "nsINode.h"
michael@0 34
michael@0 35 // dbeabbfa-6cb3-4f5c-aec2-dd558d9d681f
michael@0 36 #define NS_ICSSDECLARATION_IID \
michael@0 37 { 0xdbeabbfa, 0x6cb3, 0x4f5c, \
michael@0 38 { 0xae, 0xc2, 0xdd, 0x55, 0x8d, 0x9d, 0x68, 0x1f } }
michael@0 39
michael@0 40 class nsICSSDeclaration : public nsIDOMCSSStyleDeclaration,
michael@0 41 public nsWrapperCache
michael@0 42 {
michael@0 43 public:
michael@0 44 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSSDECLARATION_IID)
michael@0 45
michael@0 46 /**
michael@0 47 * Method analogous to nsIDOMCSSStyleDeclaration::GetPropertyValue,
michael@0 48 * which obeys all the same restrictions.
michael@0 49 */
michael@0 50 NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID,
michael@0 51 nsAString& aValue) = 0;
michael@0 52
michael@0 53 NS_IMETHOD GetAuthoredPropertyValue(const nsAString& aPropName,
michael@0 54 nsAString& aValue) = 0;
michael@0 55
michael@0 56 /**
michael@0 57 * Method analogous to nsIDOMCSSStyleDeclaration::SetProperty. This
michael@0 58 * method does NOT allow setting a priority (the priority will
michael@0 59 * always be set to default priority).
michael@0 60 */
michael@0 61 NS_IMETHOD SetPropertyValue(const nsCSSProperty aPropID,
michael@0 62 const nsAString& aValue) = 0;
michael@0 63
michael@0 64 virtual nsINode *GetParentObject() = 0;
michael@0 65
michael@0 66 // Also have to declare all the nsIDOMCSSStyleDeclaration methods,
michael@0 67 // since we want to be able to call them from the WebIDL versions.
michael@0 68 NS_IMETHOD GetCssText(nsAString& aCssText) MOZ_OVERRIDE = 0;
michael@0 69 NS_IMETHOD SetCssText(const nsAString& aCssText) MOZ_OVERRIDE = 0;
michael@0 70 NS_IMETHOD GetPropertyValue(const nsAString& aPropName,
michael@0 71 nsAString& aValue) MOZ_OVERRIDE = 0;
michael@0 72 virtual already_AddRefed<mozilla::dom::CSSValue>
michael@0 73 GetPropertyCSSValue(const nsAString& aPropertyName,
michael@0 74 mozilla::ErrorResult& aRv) = 0;
michael@0 75 NS_IMETHOD GetPropertyCSSValue(const nsAString& aProp, nsIDOMCSSValue** aVal) MOZ_OVERRIDE
michael@0 76 {
michael@0 77 mozilla::ErrorResult error;
michael@0 78 nsRefPtr<mozilla::dom::CSSValue> val = GetPropertyCSSValue(aProp, error);
michael@0 79 if (error.Failed()) {
michael@0 80 return error.ErrorCode();
michael@0 81 }
michael@0 82
michael@0 83 nsCOMPtr<nsIDOMCSSValue> xpVal = do_QueryInterface(val);
michael@0 84 xpVal.forget(aVal);
michael@0 85 return NS_OK;
michael@0 86 }
michael@0 87 NS_IMETHOD RemoveProperty(const nsAString& aPropertyName,
michael@0 88 nsAString& aReturn) MOZ_OVERRIDE = 0;
michael@0 89 NS_IMETHOD GetPropertyPriority(const nsAString& aPropertyName,
michael@0 90 nsAString& aReturn) MOZ_OVERRIDE = 0;
michael@0 91 NS_IMETHOD SetProperty(const nsAString& aPropertyName,
michael@0 92 const nsAString& aValue,
michael@0 93 const nsAString& aPriority) MOZ_OVERRIDE = 0;
michael@0 94 NS_IMETHOD GetLength(uint32_t* aLength) MOZ_OVERRIDE = 0;
michael@0 95 NS_IMETHOD Item(uint32_t aIndex, nsAString& aReturn) MOZ_OVERRIDE
michael@0 96 {
michael@0 97 bool found;
michael@0 98 IndexedGetter(aIndex, found, aReturn);
michael@0 99 if (!found) {
michael@0 100 aReturn.Truncate();
michael@0 101 }
michael@0 102 return NS_OK;
michael@0 103 }
michael@0 104 NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) MOZ_OVERRIDE = 0;
michael@0 105
michael@0 106 // WebIDL interface for CSSStyleDeclaration
michael@0 107 void SetCssText(const nsAString& aString, mozilla::ErrorResult& rv) {
michael@0 108 rv = SetCssText(aString);
michael@0 109 }
michael@0 110 void GetCssText(nsString& aString) {
michael@0 111 // Cast to nsAString& so we end up calling our virtual
michael@0 112 // |GetCssText(nsAString& aCssText)| overload, which does the real work.
michael@0 113 GetCssText(static_cast<nsAString&>(aString));
michael@0 114 }
michael@0 115 uint32_t Length() {
michael@0 116 uint32_t length;
michael@0 117 GetLength(&length);
michael@0 118 return length;
michael@0 119 }
michael@0 120 void Item(uint32_t aIndex, nsString& aPropName) {
michael@0 121 Item(aIndex, static_cast<nsAString&>(aPropName));
michael@0 122 }
michael@0 123
michael@0 124 // The actual implementation of the Item method and the WebIDL indexed getter
michael@0 125 virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) = 0;
michael@0 126
michael@0 127 void GetPropertyValue(const nsAString& aPropName, nsString& aValue,
michael@0 128 mozilla::ErrorResult& rv) {
michael@0 129 rv = GetPropertyValue(aPropName, aValue);
michael@0 130 }
michael@0 131 void GetAuthoredPropertyValue(const nsAString& aPropName, nsString& aValue,
michael@0 132 mozilla::ErrorResult& rv) {
michael@0 133 rv = GetAuthoredPropertyValue(aPropName, aValue);
michael@0 134 }
michael@0 135 void GetPropertyPriority(const nsAString& aPropName, nsString& aPriority) {
michael@0 136 GetPropertyPriority(aPropName, static_cast<nsAString&>(aPriority));
michael@0 137 }
michael@0 138 void SetProperty(const nsAString& aPropName, const nsAString& aValue,
michael@0 139 const nsAString& aPriority, mozilla::ErrorResult& rv) {
michael@0 140 rv = SetProperty(aPropName, aValue, aPriority);
michael@0 141 }
michael@0 142 void RemoveProperty(const nsAString& aPropName, nsString& aRetval,
michael@0 143 mozilla::ErrorResult& rv) {
michael@0 144 rv = RemoveProperty(aPropName, aRetval);
michael@0 145 }
michael@0 146 already_AddRefed<nsIDOMCSSRule> GetParentRule() {
michael@0 147 nsCOMPtr<nsIDOMCSSRule> rule;
michael@0 148 GetParentRule(getter_AddRefs(rule));
michael@0 149 return rule.forget();
michael@0 150 }
michael@0 151 };
michael@0 152
michael@0 153 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSDeclaration, NS_ICSSDECLARATION_IID)
michael@0 154
michael@0 155 #define NS_DECL_NSICSSDECLARATION \
michael@0 156 NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID, \
michael@0 157 nsAString& aValue); \
michael@0 158 NS_IMETHOD GetAuthoredPropertyValue(const nsAString& aPropName, \
michael@0 159 nsAString& aValue); \
michael@0 160 NS_IMETHOD SetPropertyValue(const nsCSSProperty aPropID, \
michael@0 161 const nsAString& aValue);
michael@0 162
michael@0 163 #define NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER \
michael@0 164 NS_IMETHOD GetCssText(nsAString & aCssText); \
michael@0 165 NS_IMETHOD SetCssText(const nsAString & aCssText); \
michael@0 166 NS_IMETHOD GetPropertyValue(const nsAString & propertyName, nsAString & _retval); \
michael@0 167 NS_IMETHOD RemoveProperty(const nsAString & propertyName, nsAString & _retval); \
michael@0 168 NS_IMETHOD GetPropertyPriority(const nsAString & propertyName, nsAString & _retval); \
michael@0 169 NS_IMETHOD SetProperty(const nsAString & propertyName, const nsAString & value, const nsAString & priority); \
michael@0 170 NS_IMETHOD GetLength(uint32_t *aLength); \
michael@0 171 NS_IMETHOD Item(uint32_t index, nsAString & _retval); \
michael@0 172 NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule);
michael@0 173
michael@0 174 #endif // nsICSSDeclaration_h__

mercurial