nsHTMLStyleSheet.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. /*
  7. * style sheet and style rule processor representing data from presentational
  8. * HTML attributes
  9. */
  10. #ifndef nsHTMLStyleSheet_h_
  11. #define nsHTMLStyleSheet_h_
  12. #include "nsColor.h"
  13. #include "nsCOMPtr.h"
  14. #include "nsIStyleRule.h"
  15. #include "nsIStyleRuleProcessor.h"
  16. #include "PLDHashTable.h"
  17. #include "mozilla/Attributes.h"
  18. #include "mozilla/MemoryReporting.h"
  19. #include "nsString.h"
  20. class nsIDocument;
  21. class nsMappedAttributes;
  22. class nsHTMLStyleSheet final : public nsIStyleRuleProcessor
  23. {
  24. public:
  25. explicit nsHTMLStyleSheet(nsIDocument* aDocument);
  26. void SetOwningDocument(nsIDocument* aDocument);
  27. NS_DECL_ISUPPORTS
  28. // nsIStyleRuleProcessor API
  29. virtual void RulesMatching(ElementRuleProcessorData* aData) override;
  30. virtual void RulesMatching(PseudoElementRuleProcessorData* aData) override;
  31. virtual void RulesMatching(AnonBoxRuleProcessorData* aData) override;
  32. #ifdef MOZ_XUL
  33. virtual void RulesMatching(XULTreeRuleProcessorData* aData) override;
  34. #endif
  35. virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) override;
  36. virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) override;
  37. virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override;
  38. virtual nsRestyleHint
  39. HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
  40. mozilla::RestyleHintData& aRestyleHintDataResult) override;
  41. virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) override;
  42. virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
  43. const MOZ_MUST_OVERRIDE override;
  44. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
  45. const MOZ_MUST_OVERRIDE override;
  46. size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
  47. void Reset();
  48. nsresult SetLinkColor(nscolor aColor);
  49. nsresult SetActiveLinkColor(nscolor aColor);
  50. nsresult SetVisitedLinkColor(nscolor aColor);
  51. // Mapped Attribute management methods
  52. already_AddRefed<nsMappedAttributes>
  53. UniqueMappedAttributes(nsMappedAttributes* aMapped);
  54. void DropMappedAttributes(nsMappedAttributes* aMapped);
  55. nsIStyleRule* LangRuleFor(const nsString& aLanguage);
  56. private:
  57. nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) = delete;
  58. nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) = delete;
  59. ~nsHTMLStyleSheet() {}
  60. class HTMLColorRule;
  61. friend class HTMLColorRule;
  62. class HTMLColorRule final : public nsIStyleRule {
  63. private:
  64. ~HTMLColorRule() {}
  65. public:
  66. HTMLColorRule() {}
  67. NS_DECL_ISUPPORTS
  68. // nsIStyleRule interface
  69. virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
  70. virtual bool MightMapInheritedStyleData() override;
  71. virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
  72. nsCSSValue* aValue) override;
  73. #ifdef DEBUG
  74. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  75. #endif
  76. nscolor mColor;
  77. };
  78. // Implementation of SetLink/VisitedLink/ActiveLinkColor
  79. nsresult ImplLinkColorSetter(RefPtr<HTMLColorRule>& aRule, nscolor aColor);
  80. class GenericTableRule;
  81. friend class GenericTableRule;
  82. class GenericTableRule : public nsIStyleRule {
  83. protected:
  84. virtual ~GenericTableRule() {}
  85. public:
  86. GenericTableRule() {}
  87. NS_DECL_ISUPPORTS
  88. // nsIStyleRule interface
  89. virtual void MapRuleInfoInto(nsRuleData* aRuleData) override = 0;
  90. virtual bool MightMapInheritedStyleData() override = 0;
  91. virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
  92. nsCSSValue* aValue) override = 0;
  93. #ifdef DEBUG
  94. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  95. #endif
  96. };
  97. // this rule handles <th> inheritance
  98. class TableTHRule;
  99. friend class TableTHRule;
  100. class TableTHRule final : public GenericTableRule {
  101. public:
  102. TableTHRule() {}
  103. virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
  104. virtual bool MightMapInheritedStyleData() override;
  105. virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
  106. nsCSSValue* aValue) override;
  107. };
  108. // Rule to handle quirk table colors
  109. class TableQuirkColorRule final : public GenericTableRule {
  110. public:
  111. TableQuirkColorRule() {}
  112. virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
  113. virtual bool MightMapInheritedStyleData() override;
  114. virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
  115. nsCSSValue* aValue) override;
  116. };
  117. public: // for mLangRuleTable structures only
  118. // Rule to handle xml:lang attributes, of which we have exactly one
  119. // per language string, maintained in mLangRuleTable.
  120. // We also create one extra rule for the "x-math" language string, used on
  121. // <math> elements.
  122. class LangRule final : public nsIStyleRule {
  123. private:
  124. ~LangRule() {}
  125. public:
  126. explicit LangRule(const nsSubstring& aLang) : mLang(aLang) {}
  127. NS_DECL_ISUPPORTS
  128. // nsIStyleRule interface
  129. virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
  130. virtual bool MightMapInheritedStyleData() override;
  131. virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
  132. nsCSSValue* aValue) override;
  133. #ifdef DEBUG
  134. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  135. #endif
  136. nsString mLang;
  137. };
  138. private:
  139. nsIDocument* mDocument;
  140. RefPtr<HTMLColorRule> mLinkRule;
  141. RefPtr<HTMLColorRule> mVisitedRule;
  142. RefPtr<HTMLColorRule> mActiveRule;
  143. RefPtr<TableQuirkColorRule> mTableQuirkColorRule;
  144. RefPtr<TableTHRule> mTableTHRule;
  145. PLDHashTable mMappedAttrTable;
  146. PLDHashTable mLangRuleTable;
  147. };
  148. #endif /* !defined(nsHTMLStyleSheet_h_) */