1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Pierre Phaneuf <pp@ludusdesign.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : /*
41 : * style sheet and style rule processor representing data from presentational
42 : * HTML attributes
43 : */
44 :
45 : #ifndef nsHTMLStyleSheet_h_
46 : #define nsHTMLStyleSheet_h_
47 :
48 : #include "mozilla/Attributes.h"
49 :
50 : #include "nsIStyleSheet.h"
51 : #include "nsIStyleRuleProcessor.h"
52 : #include "nsIStyleRule.h"
53 : #include "pldhash.h"
54 : #include "nsCOMPtr.h"
55 : #include "nsColor.h"
56 : class nsMappedAttributes;
57 :
58 : class nsHTMLStyleSheet : public nsIStyleSheet, public nsIStyleRuleProcessor {
59 : public:
60 : nsHTMLStyleSheet(void);
61 : nsresult Init();
62 :
63 : NS_DECL_ISUPPORTS
64 :
65 : // nsIStyleSheet api
66 : virtual nsIURI* GetSheetURI() const;
67 : virtual nsIURI* GetBaseURI() const;
68 : virtual void GetTitle(nsString& aTitle) const;
69 : virtual void GetType(nsString& aType) const;
70 : virtual bool HasRules() const;
71 : virtual bool IsApplicable() const;
72 : virtual void SetEnabled(bool aEnabled);
73 : virtual bool IsComplete() const;
74 : virtual void SetComplete();
75 : virtual nsIStyleSheet* GetParentSheet() const; // will be null
76 : virtual nsIDocument* GetOwningDocument() const;
77 : virtual void SetOwningDocument(nsIDocument* aDocumemt);
78 : #ifdef DEBUG
79 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
80 : #endif
81 :
82 : // nsIStyleRuleProcessor API
83 : virtual void RulesMatching(ElementRuleProcessorData* aData);
84 : virtual void RulesMatching(PseudoElementRuleProcessorData* aData);
85 : virtual void RulesMatching(AnonBoxRuleProcessorData* aData);
86 : #ifdef MOZ_XUL
87 : virtual void RulesMatching(XULTreeRuleProcessorData* aData);
88 : #endif
89 : virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData);
90 : virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData);
91 : virtual nsRestyleHint
92 : HasAttributeDependentStyle(AttributeRuleProcessorData* aData);
93 : virtual bool MediumFeaturesChanged(nsPresContext* aPresContext);
94 : virtual NS_MUST_OVERRIDE size_t
95 : SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
96 : virtual NS_MUST_OVERRIDE size_t
97 : SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
98 : size_t DOMSizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
99 :
100 : nsresult Init(nsIURI* aURL, nsIDocument* aDocument);
101 : void Reset(nsIURI* aURL);
102 : nsresult SetLinkColor(nscolor aColor);
103 : nsresult SetActiveLinkColor(nscolor aColor);
104 : nsresult SetVisitedLinkColor(nscolor aColor);
105 :
106 : // Mapped Attribute management methods
107 : already_AddRefed<nsMappedAttributes>
108 : UniqueMappedAttributes(nsMappedAttributes* aMapped);
109 : void DropMappedAttributes(nsMappedAttributes* aMapped);
110 :
111 : private:
112 : nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) MOZ_DELETE;
113 : nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) MOZ_DELETE;
114 :
115 : ~nsHTMLStyleSheet();
116 :
117 : class HTMLColorRule;
118 : friend class HTMLColorRule;
119 : class HTMLColorRule : public nsIStyleRule {
120 : public:
121 0 : HTMLColorRule() {}
122 :
123 : NS_DECL_ISUPPORTS
124 :
125 : // nsIStyleRule interface
126 : virtual void MapRuleInfoInto(nsRuleData* aRuleData);
127 : #ifdef DEBUG
128 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
129 : #endif
130 :
131 : nscolor mColor;
132 : };
133 :
134 : // Implementation of SetLink/VisitedLink/ActiveLinkColor
135 : nsresult ImplLinkColorSetter(nsRefPtr<HTMLColorRule>& aRule, nscolor aColor);
136 :
137 : class GenericTableRule;
138 : friend class GenericTableRule;
139 : class GenericTableRule: public nsIStyleRule {
140 : public:
141 938 : GenericTableRule() {}
142 :
143 : NS_DECL_ISUPPORTS
144 :
145 : // nsIStyleRule interface
146 : virtual void MapRuleInfoInto(nsRuleData* aRuleData) = 0;
147 : #ifdef DEBUG
148 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
149 : #endif
150 : };
151 :
152 : // this rule handles <th> inheritance
153 : class TableTHRule;
154 : friend class TableTHRule;
155 : class TableTHRule: public GenericTableRule {
156 : public:
157 469 : TableTHRule() {}
158 :
159 : virtual void MapRuleInfoInto(nsRuleData* aRuleData);
160 : };
161 :
162 : // Rule to handle quirk table colors
163 : class TableQuirkColorRule : public GenericTableRule {
164 : public:
165 469 : TableQuirkColorRule() {}
166 :
167 : virtual void MapRuleInfoInto(nsRuleData* aRuleData);
168 : };
169 :
170 : nsCOMPtr<nsIURI> mURL;
171 : nsIDocument* mDocument;
172 : nsRefPtr<HTMLColorRule> mLinkRule;
173 : nsRefPtr<HTMLColorRule> mVisitedRule;
174 : nsRefPtr<HTMLColorRule> mActiveRule;
175 : nsRefPtr<TableQuirkColorRule> mTableQuirkColorRule;
176 : nsRefPtr<TableTHRule> mTableTHRule;
177 :
178 : PLDHashTable mMappedAttrTable;
179 : };
180 :
181 : // XXX convenience method. Calls Initialize() automatically.
182 : nsresult
183 : NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult, nsIURI* aURL,
184 : nsIDocument* aDocument);
185 :
186 : nsresult
187 : NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult);
188 :
189 : #endif /* !defined(nsHTMLStyleSheet_h_) */
|