Bug 454376 add -lCrun -lCstd for Solaris OS_LIBS, r=bsmedberg
[wine-gecko.git] / layout / style / nsCSSStyleSheet.h
blob62889147b8940c3917e4ba688913a9d25cde1234
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 virtual ~nsCSSStyleSheetInner();
72 virtual nsCSSStyleSheetInner* CloneFor(nsCSSStyleSheet* aPrimarySheet);
73 virtual void AddSheet(nsICSSStyleSheet* aSheet);
74 virtual void RemoveSheet(nsICSSStyleSheet* aSheet);
76 virtual void RebuildNameSpaces();
78 nsAutoVoidArray mSheets;
79 nsCOMPtr<nsIURI> mSheetURI; // for error reports, etc.
80 nsCOMPtr<nsIURI> mOriginalSheetURI; // for GetHref. Can be null.
81 nsCOMPtr<nsIURI> mBaseURI; // for resolving relative URIs
82 nsCOMPtr<nsIPrincipal> mPrincipal;
83 nsCOMArray<nsICSSRule> mOrderedRules;
84 nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
85 PRBool mComplete;
86 // Linked list of child sheets. This is al fundamentally broken, because
87 // each of the child sheets has a unique parent... We can only hope (and
88 // currently this is the case) that any time page JS can get ts hands on a
89 // child sheet that means we've already ensured unique inners throughout its
90 // parent chain and things are good.
91 nsRefPtr<nsCSSStyleSheet> mFirstChild;
93 #ifdef DEBUG
94 PRBool mPrincipalSet;
95 #endif
99 // -------------------------------
100 // CSS Style Sheet
103 class CSSRuleListImpl;
104 static PRBool CascadeSheetRulesInto(nsICSSStyleSheet* aSheet, void* aData);
105 struct ChildSheetListBuilder;
107 class nsCSSStyleSheet : public nsICSSStyleSheet,
108 public nsIDOMCSSStyleSheet,
109 public nsICSSLoaderObserver
111 public:
112 nsCSSStyleSheet();
114 NS_DECL_ISUPPORTS
116 // nsIStyleSheet interface
117 NS_IMETHOD GetSheetURI(nsIURI** aSheetURI) const;
118 NS_IMETHOD GetBaseURI(nsIURI** aBaseURI) const;
119 NS_IMETHOD GetTitle(nsString& aTitle) const;
120 NS_IMETHOD GetType(nsString& aType) const;
121 NS_IMETHOD_(PRBool) HasRules() const;
122 NS_IMETHOD GetApplicable(PRBool& aApplicable) const;
123 NS_IMETHOD SetEnabled(PRBool aEnabled);
124 NS_IMETHOD GetComplete(PRBool& aComplete) const;
125 NS_IMETHOD SetComplete();
126 NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // may be null
127 NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const; // may be null
128 NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
129 #ifdef DEBUG
130 virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
131 #endif
133 // nsICSSStyleSheet interface
134 NS_IMETHOD ContainsStyleSheet(nsIURI* aURL, PRBool& aContains,
135 nsIStyleSheet** aTheChild=nsnull);
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 protected:
210 nsString mTitle;
211 nsCOMPtr<nsMediaList> mMedia;
212 nsRefPtr<nsCSSStyleSheet> mNext;
213 nsICSSStyleSheet* mParent; // weak ref
214 nsICSSImportRule* mOwnerRule; // weak ref
216 CSSRuleListImpl* mRuleCollection;
217 nsIDocument* mDocument; // weak ref; parents maintain this for their children
218 nsIDOMNode* mOwningNode; // weak ref
219 PRPackedBool mDisabled;
220 PRPackedBool mDirty; // has been modified
222 nsCSSStyleSheetInner* mInner;
224 nsAutoVoidArray* mRuleProcessors;
226 friend class nsMediaList;
227 friend PRBool CascadeSheetRulesInto(nsICSSStyleSheet* aSheet, void* aData);
228 friend nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult);
229 friend struct ChildSheetListBuilder;
232 #endif /* !defined(nsCSSStyleSheet_h_) */