Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / style / nsCSSStyleSheet.h
blobaed9c20c135773a34e7881854a9528f269cd1f36
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:tabstop=2:expandtab:shiftwidth=2:
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
16 * The Original Code is mozilla.org code.
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.
23 * Contributor(s):
24 * L. David Baron <dbaron@dbaron.org>
25 * Pierre Phaneuf <pp@ludusdesign.com>
26 * Daniel Glazman <glazman@netscape.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either of the GNU General Public License Version 2 or later (the "GPL"),
30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 /* representation of a CSS style sheet */
44 #ifndef nsCSSStyleSheet_h_
45 #define nsCSSStyleSheet_h_
47 #include "nscore.h"
48 #include "nsCOMPtr.h"
49 #include "nsAutoPtr.h"
50 #include "nsICSSStyleSheet.h"
51 #include "nsIDOMCSSStyleSheet.h"
52 #include "nsICSSLoaderObserver.h"
53 #include "nsVoidArray.h"
54 #include "nsCOMArray.h"
56 class nsIURI;
57 class nsMediaList;
58 class nsMediaQueryResultCacheKey;
59 class nsCSSStyleSheet;
61 // -------------------------------
62 // CSS Style Sheet Inner Data Container
65 class nsCSSStyleSheetInner {
66 public:
67 nsCSSStyleSheetInner(nsICSSStyleSheet* aPrimarySheet);
68 nsCSSStyleSheetInner(nsCSSStyleSheetInner& aCopy,
69 nsCSSStyleSheet* aPrimarySheet);
70 ~nsCSSStyleSheetInner();
72 nsCSSStyleSheetInner* CloneFor(nsCSSStyleSheet* aPrimarySheet);
73 void AddSheet(nsICSSStyleSheet* aSheet);
74 void RemoveSheet(nsICSSStyleSheet* aSheet);
76 void RebuildNameSpaces();
78 // Create a new namespace map
79 nsresult CreateNamespaceMap();
81 nsAutoVoidArray mSheets;
82 nsCOMPtr<nsIURI> mSheetURI; // for error reports, etc.
83 nsCOMPtr<nsIURI> mOriginalSheetURI; // for GetHref. Can be null.
84 nsCOMPtr<nsIURI> mBaseURI; // for resolving relative URIs
85 nsCOMPtr<nsIPrincipal> mPrincipal;
86 nsCOMArray<nsICSSRule> mOrderedRules;
87 nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
88 PRBool mComplete;
89 // Linked list of child sheets. This is al fundamentally broken, because
90 // each of the child sheets has a unique parent... We can only hope (and
91 // currently this is the case) that any time page JS can get ts hands on a
92 // child sheet that means we've already ensured unique inners throughout its
93 // parent chain and things are good.
94 nsRefPtr<nsCSSStyleSheet> mFirstChild;
96 #ifdef DEBUG
97 PRBool mPrincipalSet;
98 #endif
102 // -------------------------------
103 // CSS Style Sheet
106 class CSSRuleListImpl;
107 struct ChildSheetListBuilder;
109 class nsCSSStyleSheet : public nsICSSStyleSheet,
110 public nsIDOMCSSStyleSheet,
111 public nsICSSLoaderObserver
113 public:
114 nsCSSStyleSheet();
116 NS_DECL_ISUPPORTS
118 // nsIStyleSheet interface
119 NS_IMETHOD GetSheetURI(nsIURI** aSheetURI) const;
120 NS_IMETHOD GetBaseURI(nsIURI** aBaseURI) const;
121 NS_IMETHOD GetTitle(nsString& aTitle) const;
122 NS_IMETHOD GetType(nsString& aType) const;
123 NS_IMETHOD_(PRBool) HasRules() const;
124 NS_IMETHOD GetApplicable(PRBool& aApplicable) const;
125 NS_IMETHOD SetEnabled(PRBool aEnabled);
126 NS_IMETHOD GetComplete(PRBool& aComplete) const;
127 NS_IMETHOD SetComplete();
128 NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // may be null
129 NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const; // may be null
130 NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
131 #ifdef DEBUG
132 virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
133 #endif
135 // nsICSSStyleSheet interface
136 NS_IMETHOD AppendStyleSheet(nsICSSStyleSheet* aSheet);
137 NS_IMETHOD InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex);
138 NS_IMETHOD PrependStyleRule(nsICSSRule* aRule);
139 NS_IMETHOD AppendStyleRule(nsICSSRule* aRule);
140 NS_IMETHOD ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew);
141 NS_IMETHOD StyleRuleCount(PRInt32& aCount) const;
142 NS_IMETHOD GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
143 NS_IMETHOD DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex);
144 NS_IMETHOD InsertRuleIntoGroup(const nsAString& aRule, nsICSSGroupRule* aGroup, PRUint32 aIndex, PRUint32* _retval);
145 NS_IMETHOD ReplaceRuleInGroup(nsICSSGroupRule* aGroup, nsICSSRule* aOld, nsICSSRule* aNew);
146 NS_IMETHOD StyleSheetCount(PRInt32& aCount) const;
147 NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const;
148 NS_IMETHOD SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
149 nsIURI* aBaseURI);
150 virtual NS_HIDDEN_(void) SetPrincipal(nsIPrincipal* aPrincipal);
151 virtual NS_HIDDEN_(nsIPrincipal*) Principal() const;
152 NS_IMETHOD SetTitle(const nsAString& aTitle);
153 NS_IMETHOD SetMedia(nsMediaList* aMedia);
154 NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode);
155 NS_IMETHOD SetOwnerRule(nsICSSImportRule* aOwnerRule);
156 NS_IMETHOD GetOwnerRule(nsICSSImportRule** aOwnerRule);
157 virtual NS_HIDDEN_(nsXMLNameSpaceMap*) GetNameSpaceMap() const;
158 NS_IMETHOD Clone(nsICSSStyleSheet* aCloneParent,
159 nsICSSImportRule* aCloneOwnerRule,
160 nsIDocument* aCloneDocument,
161 nsIDOMNode* aCloneOwningNode,
162 nsICSSStyleSheet** aClone) const;
163 NS_IMETHOD IsModified(PRBool* aSheetModified) const;
164 NS_IMETHOD SetModified(PRBool aModified);
165 NS_IMETHOD AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
166 NS_IMETHOD DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
167 NS_IMETHOD InsertRuleInternal(const nsAString& aRule,
168 PRUint32 aIndex, PRUint32* aReturn);
170 // nsICSSLoaderObserver interface
171 NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
172 nsresult aStatus);
174 nsresult EnsureUniqueInner();
176 PRBool UseForPresentation(nsPresContext* aPresContext,
177 nsMediaQueryResultCacheKey& aKey) const;
179 // nsIDOMStyleSheet interface
180 NS_DECL_NSIDOMSTYLESHEET
182 // nsIDOMCSSStyleSheet interface
183 NS_DECL_NSIDOMCSSSTYLESHEET
185 private:
186 nsCSSStyleSheet(const nsCSSStyleSheet& aCopy,
187 nsICSSStyleSheet* aParentToUse,
188 nsICSSImportRule* aOwnerRuleToUse,
189 nsIDocument* aDocumentToUse,
190 nsIDOMNode* aOwningNodeToUse);
192 // These are not supported and are not implemented!
193 nsCSSStyleSheet(const nsCSSStyleSheet& aCopy);
194 nsCSSStyleSheet& operator=(const nsCSSStyleSheet& aCopy);
196 protected:
197 virtual ~nsCSSStyleSheet();
199 void ClearRuleCascades();
201 nsresult WillDirty();
202 void DidDirty();
204 // Return success if the subject principal subsumes the principal of our
205 // inner, error otherwise. This will also succeed if the subject has
206 // UniversalBrowserWrite.
207 nsresult SubjectSubsumesInnerPrincipal() const;
209 // Add the namespace mapping from this @namespace rule to our namespace map
210 nsresult RegisterNamespaceRule(nsICSSRule* aRule);
212 protected:
213 nsString mTitle;
214 nsCOMPtr<nsMediaList> mMedia;
215 nsRefPtr<nsCSSStyleSheet> mNext;
216 nsICSSStyleSheet* mParent; // weak ref
217 nsICSSImportRule* mOwnerRule; // weak ref
219 CSSRuleListImpl* mRuleCollection;
220 nsIDocument* mDocument; // weak ref; parents maintain this for their children
221 nsIDOMNode* mOwningNode; // weak ref
222 PRPackedBool mDisabled;
223 PRPackedBool mDirty; // has been modified
225 nsCSSStyleSheetInner* mInner;
227 nsAutoVoidArray* mRuleProcessors;
229 friend class nsMediaList;
230 friend class nsCSSRuleProcessor;
231 friend nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult);
232 friend struct ChildSheetListBuilder;
235 #endif /* !defined(nsCSSStyleSheet_h_) */