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