1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
8 * style sheet and style rule processor representing data from presentational
12 #ifndef nsHTMLStyleSheet_h_
13 #define nsHTMLStyleSheet_h_
15 #include "nsAutoPtr.h"
18 #include "nsIStyleRule.h"
19 #include "nsIStyleRuleProcessor.h"
21 #include "mozilla/Attributes.h"
22 #include "mozilla/MemoryReporting.h"
26 class nsMappedAttributes
;
28 class nsHTMLStyleSheet MOZ_FINAL
: public nsIStyleRuleProcessor
31 explicit nsHTMLStyleSheet(nsIDocument
* aDocument
);
33 void SetOwningDocument(nsIDocument
* aDocument
);
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
;
42 virtual void RulesMatching(XULTreeRuleProcessorData
* aData
) MOZ_OVERRIDE
;
44 virtual nsRestyleHint
HasStateDependentStyle(StateRuleProcessorData
* aData
) MOZ_OVERRIDE
;
45 virtual nsRestyleHint
HasStateDependentStyle(PseudoElementStateRuleProcessorData
* aData
) MOZ_OVERRIDE
;
46 virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData
* aData
) MOZ_OVERRIDE
;
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;
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
);
69 nsHTMLStyleSheet(const nsHTMLStyleSheet
& aCopy
) = delete;
70 nsHTMLStyleSheet
& operator=(const nsHTMLStyleSheet
& aCopy
) = delete;
75 friend class HTMLColorRule
;
76 class HTMLColorRule MOZ_FINAL
: public nsIStyleRule
{
84 // nsIStyleRule interface
85 virtual void MapRuleInfoInto(nsRuleData
* aRuleData
) MOZ_OVERRIDE
;
87 virtual void List(FILE* out
= stdout
, int32_t aIndent
= 0) const MOZ_OVERRIDE
;
93 // Implementation of SetLink/VisitedLink/ActiveLinkColor
94 nsresult
ImplLinkColorSetter(nsRefPtr
<HTMLColorRule
>& aRule
, nscolor aColor
);
96 class GenericTableRule
;
97 friend class GenericTableRule
;
98 class GenericTableRule
: public nsIStyleRule
{
100 virtual ~GenericTableRule() {}
102 GenericTableRule() {}
106 // nsIStyleRule interface
107 virtual void MapRuleInfoInto(nsRuleData
* aRuleData
) MOZ_OVERRIDE
= 0;
109 virtual void List(FILE* out
= stdout
, int32_t aIndent
= 0) const MOZ_OVERRIDE
;
113 // this rule handles <th> inheritance
115 friend class TableTHRule
;
116 class TableTHRule MOZ_FINAL
: public GenericTableRule
{
120 virtual void MapRuleInfoInto(nsRuleData
* aRuleData
) MOZ_OVERRIDE
;
123 // Rule to handle quirk table colors
124 class TableQuirkColorRule MOZ_FINAL
: public GenericTableRule
{
126 TableQuirkColorRule() {}
128 virtual void MapRuleInfoInto(nsRuleData
* aRuleData
) MOZ_OVERRIDE
;
131 public: // for mLangRuleTable structures only
133 // Rule to handle xml:lang attributes, of which we have exactly one
134 // per language string, maintained in mLangRuleTable.
135 class LangRule MOZ_FINAL
: public nsIStyleRule
{
139 explicit LangRule(const nsSubstring
& aLang
) : mLang(aLang
) {}
143 // nsIStyleRule interface
144 virtual void MapRuleInfoInto(nsRuleData
* aRuleData
) MOZ_OVERRIDE
;
146 virtual void List(FILE* out
= stdout
, int32_t aIndent
= 0) const MOZ_OVERRIDE
;
153 nsIDocument
* mDocument
;
154 nsRefPtr
<HTMLColorRule
> mLinkRule
;
155 nsRefPtr
<HTMLColorRule
> mVisitedRule
;
156 nsRefPtr
<HTMLColorRule
> mActiveRule
;
157 nsRefPtr
<TableQuirkColorRule
> mTableQuirkColorRule
;
158 nsRefPtr
<TableTHRule
> mTableTHRule
;
160 PLDHashTable mMappedAttrTable
;
161 PLDHashTable mLangRuleTable
;
164 #endif /* !defined(nsHTMLStyleSheet_h_) */