1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsXMLContentSink_h__
7 #define nsXMLContentSink_h__
9 #include "mozilla/Attributes.h"
10 #include "nsContentSink.h"
11 #include "nsIXMLContentSink.h"
12 #include "nsIExpatSink.h"
13 #include "nsIDocumentTransformer.h"
17 #include "nsCycleCollectionParticipant.h"
19 #include "mozilla/dom/FromParser.h"
34 eXMLContentSinkState_InProlog
,
35 eXMLContentSinkState_InDocumentElement
,
36 eXMLContentSinkState_InEpilog
37 } XMLContentSinkState
;
40 nsCOMPtr
<nsIContent
> mContent
;
44 class nsXMLContentSink
: public nsContentSink
,
45 public nsIXMLContentSink
,
46 public nsITransformObserver
,
52 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
54 nsresult
Init(nsIDocument
* aDoc
,
56 nsISupports
* aContainer
,
57 nsIChannel
* aChannel
);
60 NS_DECL_ISUPPORTS_INHERITED
62 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink
,
68 NS_IMETHOD
WillParse(void) MOZ_OVERRIDE
;
69 NS_IMETHOD
WillBuildModel(nsDTDMode aDTDMode
) MOZ_OVERRIDE
;
70 NS_IMETHOD
DidBuildModel(bool aTerminated
) MOZ_OVERRIDE
;
71 NS_IMETHOD
WillInterrupt(void) MOZ_OVERRIDE
;
72 NS_IMETHOD
WillResume(void) MOZ_OVERRIDE
;
73 NS_IMETHOD
SetParser(nsParserBase
* aParser
) MOZ_OVERRIDE
;
74 virtual void FlushPendingNotifications(mozFlushType aType
) MOZ_OVERRIDE
;
75 NS_IMETHOD
SetDocumentCharset(nsACString
& aCharset
) MOZ_OVERRIDE
;
76 virtual nsISupports
*GetTarget() MOZ_OVERRIDE
;
77 virtual bool IsScriptExecuting() MOZ_OVERRIDE
;
78 virtual void ContinueInterruptedParsingAsync() MOZ_OVERRIDE
;
80 // nsITransformObserver
81 NS_IMETHOD
OnDocumentCreated(nsIDocument
*aResultDocument
) MOZ_OVERRIDE
;
82 NS_IMETHOD
OnTransformDone(nsresult aResult
, nsIDocument
*aResultDocument
) MOZ_OVERRIDE
;
84 // nsICSSLoaderObserver
85 NS_IMETHOD
StyleSheetLoaded(mozilla::CSSStyleSheet
* aSheet
,
87 nsresult aStatus
) MOZ_OVERRIDE
;
88 static bool ParsePIData(const nsString
&aData
, nsString
&aHref
,
89 nsString
&aTitle
, nsString
&aMedia
,
93 virtual ~nsXMLContentSink();
95 nsIParser
* GetParser();
97 void ContinueInterruptedParsingIfEnabled();
99 // Start layout. If aIgnorePendingSheets is true, this will happen even if
100 // we still have stylesheet loads pending. Otherwise, we'll wait until the
101 // stylesheets are all done loading.
102 virtual void MaybeStartLayout(bool aIgnorePendingSheets
);
104 virtual nsresult
AddAttributes(const char16_t
** aNode
, nsIContent
* aContent
);
105 nsresult
AddText(const char16_t
* aString
, int32_t aLength
);
107 virtual bool OnOpenContainer(const char16_t
**aAtts
,
109 int32_t aNameSpaceID
,
111 uint32_t aLineNumber
) { return true; }
112 // Set the given content as the root element for the created document
113 // don't set if root element was already set.
114 // return TRUE if this call set the root element
115 virtual bool SetDocElement(int32_t aNameSpaceID
,
117 nsIContent
*aContent
);
118 virtual bool NotifyForDocElement() { return true; }
119 virtual nsresult
CreateElement(const char16_t
** aAtts
, uint32_t aAttsCount
,
120 mozilla::dom::NodeInfo
* aNodeInfo
, uint32_t aLineNumber
,
121 nsIContent
** aResult
, bool* aAppendContent
,
122 mozilla::dom::FromParser aFromParser
);
124 // aParent is allowed to be null here if this is the root content
126 virtual nsresult
CloseElement(nsIContent
* aContent
);
128 virtual nsresult
FlushText(bool aReleaseTextNode
= true);
130 nsresult
AddContentAsLeaf(nsIContent
*aContent
);
132 nsIContent
* GetCurrentContent();
133 StackNode
* GetCurrentStackNode();
134 nsresult
PushContent(nsIContent
*aContent
);
136 bool HaveNotifiedForCurrentContent() const;
138 nsresult
FlushTags() MOZ_OVERRIDE
;
140 void UpdateChildCounts() MOZ_OVERRIDE
;
144 if (IsTimeToNotify()) {
149 // nsContentSink override
150 virtual nsresult
ProcessStyleLink(nsIContent
* aElement
,
151 const nsSubstring
& aHref
,
153 const nsSubstring
& aTitle
,
154 const nsSubstring
& aType
,
155 const nsSubstring
& aMedia
) MOZ_OVERRIDE
;
157 nsresult
LoadXSLStyleSheet(nsIURI
* aUrl
);
159 bool CanStillPrettyPrint();
161 nsresult
MaybePrettyPrint();
163 bool IsMonolithicContainer(mozilla::dom::NodeInfo
* aNodeInfo
);
165 nsresult
HandleStartElement(const char16_t
*aName
, const char16_t
**aAtts
,
166 uint32_t aAttsCount
, uint32_t aLineNumber
,
167 bool aInterruptable
);
168 nsresult
HandleEndElement(const char16_t
*aName
, bool aInterruptable
);
169 nsresult
HandleCharacterData(const char16_t
*aData
, uint32_t aLength
,
170 bool aInterruptable
);
172 nsCOMPtr
<nsIContent
> mDocElement
;
173 nsCOMPtr
<nsIContent
> mCurrentHead
; // When set, we're in an XHTML <haed>
176 XMLContentSinkState mState
;
181 int32_t mNotifyLevel
;
182 nsCOMPtr
<nsIContent
> mLastTextNode
;
183 int32_t mLastTextNodeSize
;
185 uint8_t mConstrainSize
: 1;
186 uint8_t mPrettyPrintXML
: 1;
187 uint8_t mPrettyPrintHasSpecialRoot
: 1;
188 uint8_t mPrettyPrintHasFactoredElements
: 1;
189 uint8_t mPrettyPrinting
: 1; // True if we called PrettyPrint() and it
190 // decided we should in fact prettyprint.
191 // True to call prevent script execution in the fragment mode.
192 uint8_t mPreventScriptExecution
: 1;
194 nsTArray
<StackNode
> mContentStack
;
196 nsCOMPtr
<nsIDocumentTransformer
> mXSLTProcessor
;
199 #endif // nsXMLContentSink_h__