Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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/. */
7 /*
8 * style sheet and style rule processor representing data from presentational
9 * HTML attributes
10 */
12 #ifndef nsHTMLStyleSheet_h_
13 #define nsHTMLStyleSheet_h_
15 #include "nsAutoPtr.h"
16 #include "nsColor.h"
17 #include "nsCOMPtr.h"
18 #include "nsIStyleRule.h"
19 #include "nsIStyleRuleProcessor.h"
20 #include "pldhash.h"
21 #include "mozilla/Attributes.h"
22 #include "mozilla/MemoryReporting.h"
23 #include "nsString.h"
25 class nsIDocument;
26 class nsMappedAttributes;
28 class nsHTMLStyleSheet MOZ_FINAL : public nsIStyleRuleProcessor
29 {
30 public:
31 nsHTMLStyleSheet(nsIDocument* aDocument);
33 void SetOwningDocument(nsIDocument* aDocument);
35 NS_DECL_ISUPPORTS
37 // nsIStyleRuleProcessor API
38 virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE;
39 virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE;
40 virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE;
41 #ifdef MOZ_XUL
42 virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
43 #endif
44 virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE;
45 virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) MOZ_OVERRIDE;
46 virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE;
47 virtual nsRestyleHint
48 HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE;
49 virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE;
50 virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
51 const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
52 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
53 const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
54 size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
56 void Reset();
57 nsresult SetLinkColor(nscolor aColor);
58 nsresult SetActiveLinkColor(nscolor aColor);
59 nsresult SetVisitedLinkColor(nscolor aColor);
61 // Mapped Attribute management methods
62 already_AddRefed<nsMappedAttributes>
63 UniqueMappedAttributes(nsMappedAttributes* aMapped);
64 void DropMappedAttributes(nsMappedAttributes* aMapped);
66 nsIStyleRule* LangRuleFor(const nsString& aLanguage);
68 private:
69 nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) MOZ_DELETE;
70 nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) MOZ_DELETE;
72 ~nsHTMLStyleSheet();
74 class HTMLColorRule;
75 friend class HTMLColorRule;
76 class HTMLColorRule MOZ_FINAL : public nsIStyleRule {
77 public:
78 HTMLColorRule() {}
80 NS_DECL_ISUPPORTS
82 // nsIStyleRule interface
83 virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
84 #ifdef DEBUG
85 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
86 #endif
88 nscolor mColor;
89 };
91 // Implementation of SetLink/VisitedLink/ActiveLinkColor
92 nsresult ImplLinkColorSetter(nsRefPtr<HTMLColorRule>& aRule, nscolor aColor);
94 class GenericTableRule;
95 friend class GenericTableRule;
96 class GenericTableRule : public nsIStyleRule {
97 public:
98 GenericTableRule() {}
99 virtual ~GenericTableRule() {}
101 NS_DECL_ISUPPORTS
103 // nsIStyleRule interface
104 virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE = 0;
105 #ifdef DEBUG
106 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
107 #endif
108 };
110 // this rule handles <th> inheritance
111 class TableTHRule;
112 friend class TableTHRule;
113 class TableTHRule MOZ_FINAL : public GenericTableRule {
114 public:
115 TableTHRule() {}
117 virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
118 };
120 // Rule to handle quirk table colors
121 class TableQuirkColorRule MOZ_FINAL : public GenericTableRule {
122 public:
123 TableQuirkColorRule() {}
125 virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
126 };
128 public: // for mLangRuleTable structures only
130 // Rule to handle xml:lang attributes, of which we have exactly one
131 // per language string, maintained in mLangRuleTable.
132 class LangRule MOZ_FINAL : public nsIStyleRule {
133 public:
134 LangRule(const nsSubstring& aLang) : mLang(aLang) {}
136 NS_DECL_ISUPPORTS
138 // nsIStyleRule interface
139 virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
140 #ifdef DEBUG
141 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
142 #endif
144 nsString mLang;
145 };
147 private:
148 nsIDocument* mDocument;
149 nsRefPtr<HTMLColorRule> mLinkRule;
150 nsRefPtr<HTMLColorRule> mVisitedRule;
151 nsRefPtr<HTMLColorRule> mActiveRule;
152 nsRefPtr<TableQuirkColorRule> mTableQuirkColorRule;
153 nsRefPtr<TableTHRule> mTableTHRule;
155 PLDHashTable mMappedAttrTable;
156 PLDHashTable mLangRuleTable;
157 };
159 #endif /* !defined(nsHTMLStyleSheet_h_) */