Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / xml / nsXMLContentSink.h
blob35a5664eb070f02fcab6abbf0fbb8dd55cb25696
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"
14 #include "nsTArray.h"
15 #include "nsCOMPtr.h"
16 #include "nsCRT.h"
17 #include "nsCycleCollectionParticipant.h"
18 #include "nsIDTD.h"
19 #include "mozilla/dom/FromParser.h"
21 class nsIDocument;
22 class nsIURI;
23 class nsIContent;
24 class nsIParser;
25 class nsViewManager;
27 namespace mozilla {
28 namespace dom {
29 class NodeInfo;
33 typedef enum {
34 eXMLContentSinkState_InProlog,
35 eXMLContentSinkState_InDocumentElement,
36 eXMLContentSinkState_InEpilog
37 } XMLContentSinkState;
39 struct StackNode {
40 nsCOMPtr<nsIContent> mContent;
41 uint32_t mNumFlushed;
44 class nsXMLContentSink : public nsContentSink,
45 public nsIXMLContentSink,
46 public nsITransformObserver,
47 public nsIExpatSink
49 public:
50 nsXMLContentSink();
52 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
54 nsresult Init(nsIDocument* aDoc,
55 nsIURI* aURL,
56 nsISupports* aContainer,
57 nsIChannel* aChannel);
59 // nsISupports
60 NS_DECL_ISUPPORTS_INHERITED
62 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink,
63 nsContentSink)
65 NS_DECL_NSIEXPATSINK
67 // nsIContentSink
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,
86 bool aWasAlternate,
87 nsresult aStatus) MOZ_OVERRIDE;
88 static bool ParsePIData(const nsString &aData, nsString &aHref,
89 nsString &aTitle, nsString &aMedia,
90 bool &aIsAlternate);
92 protected:
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,
108 uint32_t aAttsCount,
109 int32_t aNameSpaceID,
110 nsIAtom* aTagName,
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,
116 nsIAtom *aTagName,
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
125 // being closed
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);
135 void PopContent();
136 bool HaveNotifiedForCurrentContent() const;
138 nsresult FlushTags() MOZ_OVERRIDE;
140 void UpdateChildCounts() MOZ_OVERRIDE;
142 void DidAddContent()
144 if (IsTimeToNotify()) {
145 FlushTags();
149 // nsContentSink override
150 virtual nsresult ProcessStyleLink(nsIContent* aElement,
151 const nsSubstring& aHref,
152 bool aAlternate,
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>
174 char16_t* mText;
176 XMLContentSinkState mState;
178 int32_t mTextLength;
179 int32_t mTextSize;
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__