|
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/. */ |
|
5 |
|
6 #ifndef nsXMLContentSink_h__ |
|
7 #define nsXMLContentSink_h__ |
|
8 |
|
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" |
|
20 |
|
21 class nsIDocument; |
|
22 class nsIURI; |
|
23 class nsIContent; |
|
24 class nsINodeInfo; |
|
25 class nsIParser; |
|
26 class nsViewManager; |
|
27 |
|
28 typedef enum { |
|
29 eXMLContentSinkState_InProlog, |
|
30 eXMLContentSinkState_InDocumentElement, |
|
31 eXMLContentSinkState_InEpilog |
|
32 } XMLContentSinkState; |
|
33 |
|
34 struct StackNode { |
|
35 nsCOMPtr<nsIContent> mContent; |
|
36 uint32_t mNumFlushed; |
|
37 }; |
|
38 |
|
39 class nsXMLContentSink : public nsContentSink, |
|
40 public nsIXMLContentSink, |
|
41 public nsITransformObserver, |
|
42 public nsIExpatSink |
|
43 { |
|
44 public: |
|
45 nsXMLContentSink(); |
|
46 virtual ~nsXMLContentSink(); |
|
47 |
|
48 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW |
|
49 |
|
50 nsresult Init(nsIDocument* aDoc, |
|
51 nsIURI* aURL, |
|
52 nsISupports* aContainer, |
|
53 nsIChannel* aChannel); |
|
54 |
|
55 // nsISupports |
|
56 NS_DECL_ISUPPORTS_INHERITED |
|
57 |
|
58 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink, |
|
59 nsContentSink) |
|
60 |
|
61 NS_DECL_NSIEXPATSINK |
|
62 |
|
63 // nsIContentSink |
|
64 NS_IMETHOD WillParse(void) MOZ_OVERRIDE; |
|
65 NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE; |
|
66 NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE; |
|
67 NS_IMETHOD WillInterrupt(void) MOZ_OVERRIDE; |
|
68 NS_IMETHOD WillResume(void) MOZ_OVERRIDE; |
|
69 NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE; |
|
70 virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE; |
|
71 NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE; |
|
72 virtual nsISupports *GetTarget() MOZ_OVERRIDE; |
|
73 virtual bool IsScriptExecuting() MOZ_OVERRIDE; |
|
74 virtual void ContinueInterruptedParsingAsync() MOZ_OVERRIDE; |
|
75 |
|
76 // nsITransformObserver |
|
77 NS_IMETHOD OnDocumentCreated(nsIDocument *aResultDocument) MOZ_OVERRIDE; |
|
78 NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument) MOZ_OVERRIDE; |
|
79 |
|
80 // nsICSSLoaderObserver |
|
81 NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet, bool aWasAlternate, |
|
82 nsresult aStatus) MOZ_OVERRIDE; |
|
83 static bool ParsePIData(const nsString &aData, nsString &aHref, |
|
84 nsString &aTitle, nsString &aMedia, |
|
85 bool &aIsAlternate); |
|
86 |
|
87 protected: |
|
88 |
|
89 nsIParser* GetParser(); |
|
90 |
|
91 void ContinueInterruptedParsingIfEnabled(); |
|
92 |
|
93 // Start layout. If aIgnorePendingSheets is true, this will happen even if |
|
94 // we still have stylesheet loads pending. Otherwise, we'll wait until the |
|
95 // stylesheets are all done loading. |
|
96 virtual void MaybeStartLayout(bool aIgnorePendingSheets); |
|
97 |
|
98 virtual nsresult AddAttributes(const char16_t** aNode, nsIContent* aContent); |
|
99 nsresult AddText(const char16_t* aString, int32_t aLength); |
|
100 |
|
101 virtual bool OnOpenContainer(const char16_t **aAtts, |
|
102 uint32_t aAttsCount, |
|
103 int32_t aNameSpaceID, |
|
104 nsIAtom* aTagName, |
|
105 uint32_t aLineNumber) { return true; } |
|
106 // Set the given content as the root element for the created document |
|
107 // don't set if root element was already set. |
|
108 // return TRUE if this call set the root element |
|
109 virtual bool SetDocElement(int32_t aNameSpaceID, |
|
110 nsIAtom *aTagName, |
|
111 nsIContent *aContent); |
|
112 virtual bool NotifyForDocElement() { return true; } |
|
113 virtual nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount, |
|
114 nsINodeInfo* aNodeInfo, uint32_t aLineNumber, |
|
115 nsIContent** aResult, bool* aAppendContent, |
|
116 mozilla::dom::FromParser aFromParser); |
|
117 |
|
118 // aParent is allowed to be null here if this is the root content |
|
119 // being closed |
|
120 virtual nsresult CloseElement(nsIContent* aContent); |
|
121 |
|
122 virtual nsresult FlushText(bool aReleaseTextNode = true); |
|
123 |
|
124 nsresult AddContentAsLeaf(nsIContent *aContent); |
|
125 |
|
126 nsIContent* GetCurrentContent(); |
|
127 StackNode* GetCurrentStackNode(); |
|
128 nsresult PushContent(nsIContent *aContent); |
|
129 void PopContent(); |
|
130 bool HaveNotifiedForCurrentContent() const; |
|
131 |
|
132 nsresult FlushTags() MOZ_OVERRIDE; |
|
133 |
|
134 void UpdateChildCounts() MOZ_OVERRIDE; |
|
135 |
|
136 void DidAddContent() |
|
137 { |
|
138 if (IsTimeToNotify()) { |
|
139 FlushTags(); |
|
140 } |
|
141 } |
|
142 |
|
143 // nsContentSink override |
|
144 virtual nsresult ProcessStyleLink(nsIContent* aElement, |
|
145 const nsSubstring& aHref, |
|
146 bool aAlternate, |
|
147 const nsSubstring& aTitle, |
|
148 const nsSubstring& aType, |
|
149 const nsSubstring& aMedia) MOZ_OVERRIDE; |
|
150 |
|
151 nsresult LoadXSLStyleSheet(nsIURI* aUrl); |
|
152 |
|
153 bool CanStillPrettyPrint(); |
|
154 |
|
155 nsresult MaybePrettyPrint(); |
|
156 |
|
157 bool IsMonolithicContainer(nsINodeInfo* aNodeInfo); |
|
158 |
|
159 nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts, |
|
160 uint32_t aAttsCount, int32_t aIndex, |
|
161 uint32_t aLineNumber, |
|
162 bool aInterruptable); |
|
163 nsresult HandleEndElement(const char16_t *aName, bool aInterruptable); |
|
164 nsresult HandleCharacterData(const char16_t *aData, uint32_t aLength, |
|
165 bool aInterruptable); |
|
166 |
|
167 nsCOMPtr<nsIContent> mDocElement; |
|
168 nsCOMPtr<nsIContent> mCurrentHead; // When set, we're in an XHTML <haed> |
|
169 char16_t* mText; |
|
170 |
|
171 XMLContentSinkState mState; |
|
172 |
|
173 int32_t mTextLength; |
|
174 int32_t mTextSize; |
|
175 |
|
176 int32_t mNotifyLevel; |
|
177 nsCOMPtr<nsIContent> mLastTextNode; |
|
178 int32_t mLastTextNodeSize; |
|
179 |
|
180 uint8_t mConstrainSize : 1; |
|
181 uint8_t mPrettyPrintXML : 1; |
|
182 uint8_t mPrettyPrintHasSpecialRoot : 1; |
|
183 uint8_t mPrettyPrintHasFactoredElements : 1; |
|
184 uint8_t mPrettyPrinting : 1; // True if we called PrettyPrint() and it |
|
185 // decided we should in fact prettyprint. |
|
186 // True to call prevent script execution in the fragment mode. |
|
187 uint8_t mPreventScriptExecution : 1; |
|
188 |
|
189 nsTArray<StackNode> mContentStack; |
|
190 |
|
191 nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor; |
|
192 }; |
|
193 |
|
194 #endif // nsXMLContentSink_h__ |