Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / xml / document / src / nsXMLContentSink.h
blobe12d478c3e5a4fc54fccc235a5d18f22d38503f8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsXMLContentSink_h__
39 #define nsXMLContentSink_h__
41 #include "nsContentSink.h"
42 #include "nsIXMLContentSink.h"
43 #include "nsIExpatSink.h"
44 #include "nsIDocumentTransformer.h"
45 #include "nsTArray.h"
46 #include "nsCOMPtr.h"
47 #include "nsCRT.h"
48 #include "nsCycleCollectionParticipant.h"
50 class nsIDocument;
51 class nsIURI;
52 class nsIContent;
53 class nsINodeInfo;
54 class nsIParser;
55 class nsIViewManager;
57 typedef enum {
58 eXMLContentSinkState_InProlog,
59 eXMLContentSinkState_InDocumentElement,
60 eXMLContentSinkState_InEpilog
61 } XMLContentSinkState;
63 struct StackNode {
64 nsCOMPtr<nsIContent> mContent;
65 PRUint32 mNumFlushed;
68 class nsXMLContentSink : public nsContentSink,
69 public nsIXMLContentSink,
70 public nsITransformObserver,
71 public nsIExpatSink
73 public:
74 nsXMLContentSink();
75 virtual ~nsXMLContentSink();
77 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
79 nsresult Init(nsIDocument* aDoc,
80 nsIURI* aURL,
81 nsISupports* aContainer,
82 nsIChannel* aChannel);
84 // nsISupports
85 NS_DECL_ISUPPORTS_INHERITED
87 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink,
88 nsContentSink)
90 NS_DECL_NSIEXPATSINK
92 // nsIContentSink
93 NS_IMETHOD WillParse(void);
94 NS_IMETHOD WillBuildModel(void);
95 NS_IMETHOD DidBuildModel(void);
96 NS_IMETHOD WillInterrupt(void);
97 NS_IMETHOD WillResume(void);
98 NS_IMETHOD SetParser(nsIParser* aParser);
99 virtual void FlushPendingNotifications(mozFlushType aType);
100 NS_IMETHOD SetDocumentCharset(nsACString& aCharset);
101 virtual nsISupports *GetTarget();
103 // nsITransformObserver
104 NS_IMETHOD OnDocumentCreated(nsIDocument *aResultDocument);
105 NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument);
107 // nsICSSLoaderObserver
108 NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate,
109 nsresult aStatus);
110 static PRBool ParsePIData(const nsString &aData, nsString &aHref,
111 nsString &aTitle, nsString &aMedia,
112 PRBool &aIsAlternate);
114 virtual nsresult ProcessMETATag(nsIContent* aContent);
116 protected:
117 // Start layout. If aIgnorePendingSheets is true, this will happen even if
118 // we still have stylesheet loads pending. Otherwise, we'll wait until the
119 // stylesheets are all done loading.
120 virtual void MaybeStartLayout(PRBool aIgnorePendingSheets);
122 virtual nsresult AddAttributes(const PRUnichar** aNode, nsIContent* aContent);
123 nsresult AddText(const PRUnichar* aString, PRInt32 aLength);
125 virtual PRBool OnOpenContainer(const PRUnichar **aAtts,
126 PRUint32 aAttsCount,
127 PRInt32 aNameSpaceID,
128 nsIAtom* aTagName,
129 PRUint32 aLineNumber) { return PR_TRUE; }
130 // Set the given content as the root element for the created document
131 // don't set if root element was already set.
132 // return TRUE if this call set the root element
133 virtual PRBool SetDocElement(PRInt32 aNameSpaceID,
134 nsIAtom *aTagName,
135 nsIContent *aContent);
136 virtual nsresult CreateElement(const PRUnichar** aAtts, PRUint32 aAttsCount,
137 nsINodeInfo* aNodeInfo, PRUint32 aLineNumber,
138 nsIContent** aResult, PRBool* aAppendContent,
139 PRBool aFromParser);
141 // aParent is allowed to be null here if this is the root content
142 // being closed
143 virtual nsresult CloseElement(nsIContent* aContent);
145 virtual nsresult FlushText(PRBool aReleaseTextNode = PR_TRUE);
147 nsresult AddContentAsLeaf(nsIContent *aContent);
149 nsIContent* GetCurrentContent();
150 StackNode & GetCurrentStackNode();
151 nsresult PushContent(nsIContent *aContent);
152 void PopContent();
153 PRBool HaveNotifiedForCurrentContent() const;
155 void ProcessBASETag(nsIContent* aContent);
157 nsresult FlushTags();
159 void UpdateChildCounts();
161 void DidAddContent()
163 if (IsTimeToNotify()) {
164 FlushTags();
168 // nsContentSink override
169 virtual nsresult ProcessStyleLink(nsIContent* aElement,
170 const nsSubstring& aHref,
171 PRBool aAlternate,
172 const nsSubstring& aTitle,
173 const nsSubstring& aType,
174 const nsSubstring& aMedia);
176 nsresult LoadXSLStyleSheet(nsIURI* aUrl);
178 PRBool CanStillPrettyPrint();
180 nsresult MaybePrettyPrint();
182 PRBool IsMonolithicContainer(nsINodeInfo* aNodeInfo);
184 nsresult HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts,
185 PRUint32 aAttsCount, PRInt32 aIndex,
186 PRUint32 aLineNumber,
187 PRBool aInterruptable);
188 nsresult HandleEndElement(const PRUnichar *aName, PRBool aInterruptable);
189 nsresult HandleCharacterData(const PRUnichar *aData, PRUint32 aLength,
190 PRBool aInterruptable);
192 nsIContent* mDocElement;
193 nsCOMPtr<nsIContent> mCurrentHead; // When set, we're in an XHTML <haed>
194 PRUnichar* mText;
196 XMLContentSinkState mState;
198 PRInt32 mTextLength;
199 PRInt32 mTextSize;
201 PRInt32 mNotifyLevel;
202 nsCOMPtr<nsIContent> mLastTextNode;
203 PRInt32 mLastTextNodeSize;
205 PRUint8 mConstrainSize : 1;
206 PRUint8 mPrettyPrintXML : 1;
207 PRUint8 mPrettyPrintHasSpecialRoot : 1;
208 PRUint8 mPrettyPrintHasFactoredElements : 1;
209 PRUint8 mHasProcessedBase : 1;
210 PRUint8 mAllowAutoXLinks : 1;
211 PRUint8 mPrettyPrinting : 1; // True if we called PrettyPrint() and it
212 // decided we should in fact prettyprint.
213 PRUint8 unused : 1; // bits available if someone needs one
215 nsTArray<StackNode> mContentStack;
217 nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor;
220 #endif // nsXMLContentSink_h__