nsICSSDeclaration.h 7.0 KB

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