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
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.
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"
48 #include "nsCycleCollectionParticipant.h"
58 eXMLContentSinkState_InProlog
,
59 eXMLContentSinkState_InDocumentElement
,
60 eXMLContentSinkState_InEpilog
61 } XMLContentSinkState
;
64 nsCOMPtr
<nsIContent
> mContent
;
68 class nsXMLContentSink
: public nsContentSink
,
69 public nsIXMLContentSink
,
70 public nsITransformObserver
,
75 virtual ~nsXMLContentSink();
77 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
79 nsresult
Init(nsIDocument
* aDoc
,
81 nsISupports
* aContainer
,
82 nsIChannel
* aChannel
);
85 NS_DECL_ISUPPORTS_INHERITED
87 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink
,
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
,
110 static PRBool
ParsePIData(const nsString
&aData
, nsString
&aHref
,
111 nsString
&aTitle
, nsString
&aMedia
,
112 PRBool
&aIsAlternate
);
114 virtual nsresult
ProcessMETATag(nsIContent
* aContent
);
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
,
127 PRInt32 aNameSpaceID
,
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
,
135 nsIContent
*aContent
);
136 virtual nsresult
CreateElement(const PRUnichar
** aAtts
, PRUint32 aAttsCount
,
137 nsINodeInfo
* aNodeInfo
, PRUint32 aLineNumber
,
138 nsIContent
** aResult
, PRBool
* aAppendContent
,
141 // aParent is allowed to be null here if this is the root content
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
);
153 PRBool
HaveNotifiedForCurrentContent() const;
155 void ProcessBASETag(nsIContent
* aContent
);
157 nsresult
FlushTags();
159 void UpdateChildCounts();
163 if (IsTimeToNotify()) {
168 // nsContentSink override
169 virtual nsresult
ProcessStyleLink(nsIContent
* aElement
,
170 const nsSubstring
& aHref
,
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>
196 XMLContentSinkState mState
;
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__