1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
---|
2 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
3 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
---|
4 | * |
---|
5 | * The contents of this file are subject to the Netscape Public License |
---|
6 | * Version 1.1 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. You may obtain a copy of the License at |
---|
8 | * http://www.mozilla.org/NPL/ |
---|
9 | * |
---|
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. |
---|
14 | * |
---|
15 | * The Original Code is Mozilla Communicator client code. |
---|
16 | * |
---|
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. |
---|
21 | * |
---|
22 | * Contributor(s): |
---|
23 | * |
---|
24 | * |
---|
25 | * Alternatively, the contents of this file may be used under the terms of |
---|
26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
---|
27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
---|
29 | * of those above. If you wish to allow use of your version of this file only |
---|
30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
---|
31 | * use your version of this file under the terms of the NPL, indicate your |
---|
32 | * decision by deleting the provisions above and replace them with the notice |
---|
33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
---|
34 | * the provisions above, a recipient may use your version of this file under |
---|
35 | * the terms of any one of the NPL, the GPL or the LGPL. |
---|
36 | * |
---|
37 | * ***** END LICENSE BLOCK ***** */ |
---|
38 | #ifndef nsIHTMLContentSink_h___ |
---|
39 | #define nsIHTMLContentSink_h___ |
---|
40 | |
---|
41 | /** |
---|
42 | * MODULE NOTES: |
---|
43 | * @update gess 4/1/98 |
---|
44 | * |
---|
45 | * This file declares the concrete HTMLContentSink class. |
---|
46 | * This class is used during the parsing process as the |
---|
47 | * primary interface between the parser and the content |
---|
48 | * model. |
---|
49 | * |
---|
50 | * After the tokenizer completes, the parser iterates over |
---|
51 | * the known token list. As the parser identifies valid |
---|
52 | * elements, it calls the contentsink interface to notify |
---|
53 | * the content model that a new node or child node is being |
---|
54 | * created and added to the content model. |
---|
55 | * |
---|
56 | * The HTMLContentSink interface assumes 4 underlying |
---|
57 | * containers: HTML, HEAD, BODY and FRAMESET. Before |
---|
58 | * accessing any these, the parser will call the appropriate |
---|
59 | * OpennsIHTMLContentSink method: OpenHTML,OpenHead,OpenBody,OpenFrameSet; |
---|
60 | * likewise, the ClosensIHTMLContentSink version will be called when the |
---|
61 | * parser is done with a given section. |
---|
62 | * |
---|
63 | * IMPORTANT: The parser may Open each container more than |
---|
64 | * once! This is due to the irregular nature of HTML files. |
---|
65 | * For example, it is possible to encounter plain text at |
---|
66 | * the start of an HTML document (that preceeds the HTML tag). |
---|
67 | * Such text is treated as if it were part of the body. |
---|
68 | * In such cases, the parser will Open the body, pass the text- |
---|
69 | * node in and then Close the body. The body will likely be |
---|
70 | * re-Opened later when the actual <BODY> tag has been seen. |
---|
71 | * |
---|
72 | * Containers within the body are Opened and Closed |
---|
73 | * using the OpenContainer(...) and CloseContainer(...) calls. |
---|
74 | * It is assumed that the document or contentSink is |
---|
75 | * maintaining its state to manage where new content should |
---|
76 | * be added to the underlying document. |
---|
77 | * |
---|
78 | * NOTE: OpenHTML() and OpenBody() may get called multiple times |
---|
79 | * in the same document. That's fine, and it doesn't mean |
---|
80 | * that we have multiple bodies or HTML's. |
---|
81 | * |
---|
82 | * NOTE: I haven't figured out how sub-documents (non-frames) |
---|
83 | * are going to be handled. Stay tuned. |
---|
84 | */ |
---|
85 | #include "nsIParserNode.h" |
---|
86 | #include "nsIContentSink.h" |
---|
87 | #include "nsHTMLTags.h" |
---|
88 | |
---|
89 | #define NS_IHTML_CONTENT_SINK_IID \ |
---|
90 | { 0x59929de5, 0xe60b, 0x48b1,{0x81, 0x69, 0x48, 0x47, 0xb5, 0xc9, 0x44, 0x29}} |
---|
91 | |
---|
92 | #ifdef XP_MAC |
---|
93 | #define MAX_REFLOW_DEPTH 75 //setting to 75 to prevent layout from crashing on mac. Bug 55095. |
---|
94 | #else |
---|
95 | #define MAX_REFLOW_DEPTH 200 //windows and linux (etc) can do much deeper structures. |
---|
96 | #endif |
---|
97 | |
---|
98 | class nsIHTMLContentSink : public nsIContentSink |
---|
99 | { |
---|
100 | public: |
---|
101 | |
---|
102 | NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTML_CONTENT_SINK_IID) |
---|
103 | |
---|
104 | /** |
---|
105 | * This method gets called by the parser when it encounters |
---|
106 | * a title tag and wants to set the document title in the sink. |
---|
107 | * |
---|
108 | * @update 4/1/98 gess |
---|
109 | * @param nsString reference to new title value |
---|
110 | */ |
---|
111 | NS_IMETHOD SetTitle(const nsString& aValue) = 0; |
---|
112 | |
---|
113 | /** |
---|
114 | * This method is used to open the outer HTML container. |
---|
115 | * |
---|
116 | * @update 4/1/98 gess |
---|
117 | * @param nsIParserNode reference to parser node interface |
---|
118 | */ |
---|
119 | NS_IMETHOD OpenHTML(const nsIParserNode& aNode) = 0; |
---|
120 | |
---|
121 | /** |
---|
122 | * This method is used to close the outer HTML container. |
---|
123 | * |
---|
124 | */ |
---|
125 | NS_IMETHOD CloseHTML() = 0; |
---|
126 | |
---|
127 | /** |
---|
128 | * This method is used to open the only HEAD container. |
---|
129 | * |
---|
130 | * @update 4/1/98 gess |
---|
131 | * @param nsIParserNode reference to parser node interface |
---|
132 | */ |
---|
133 | NS_IMETHOD OpenHead(const nsIParserNode& aNode) = 0; |
---|
134 | |
---|
135 | /** |
---|
136 | * This method is used to close the only HEAD container. |
---|
137 | */ |
---|
138 | NS_IMETHOD CloseHead() = 0; |
---|
139 | |
---|
140 | /** |
---|
141 | * This method is used to open the main BODY container. |
---|
142 | * |
---|
143 | * @update 4/1/98 gess |
---|
144 | * @param nsIParserNode reference to parser node interface |
---|
145 | */ |
---|
146 | NS_IMETHOD OpenBody(const nsIParserNode& aNode) = 0; |
---|
147 | |
---|
148 | /** |
---|
149 | * This method is used to close the main BODY container. |
---|
150 | * |
---|
151 | */ |
---|
152 | NS_IMETHOD CloseBody() = 0; |
---|
153 | |
---|
154 | /** |
---|
155 | * This method is used to open a new FORM container. |
---|
156 | * |
---|
157 | * @update 4/1/98 gess |
---|
158 | * @param nsIParserNode reference to parser node interface |
---|
159 | */ |
---|
160 | NS_IMETHOD OpenForm(const nsIParserNode& aNode) = 0; |
---|
161 | |
---|
162 | /** |
---|
163 | * This method is used to close the outer FORM container. |
---|
164 | * |
---|
165 | */ |
---|
166 | NS_IMETHOD CloseForm() = 0; |
---|
167 | |
---|
168 | /** |
---|
169 | * This method is used to open a new MAP container. |
---|
170 | * |
---|
171 | * @update 4/1/98 gess |
---|
172 | * @param nsIParserNode reference to parser node interface |
---|
173 | */ |
---|
174 | NS_IMETHOD OpenMap(const nsIParserNode& aNode) = 0; |
---|
175 | |
---|
176 | /** |
---|
177 | * This method is used to close the MAP container. |
---|
178 | * |
---|
179 | */ |
---|
180 | NS_IMETHOD CloseMap() = 0; |
---|
181 | |
---|
182 | /** |
---|
183 | * This method is used to open the FRAMESET container. |
---|
184 | * |
---|
185 | * @update 4/1/98 gess |
---|
186 | * @param nsIParserNode reference to parser node interface |
---|
187 | */ |
---|
188 | NS_IMETHOD OpenFrameset(const nsIParserNode& aNode) = 0; |
---|
189 | |
---|
190 | /** |
---|
191 | * This method is used to close the FRAMESET container. |
---|
192 | * |
---|
193 | */ |
---|
194 | NS_IMETHOD CloseFrameset() = 0; |
---|
195 | |
---|
196 | /** |
---|
197 | * This gets called when handling illegal contents, especially |
---|
198 | * in dealing with tables. This method creates a new context. |
---|
199 | * |
---|
200 | * @update 04/04/99 harishd |
---|
201 | * @param aPosition - The position from where the new context begins. |
---|
202 | */ |
---|
203 | NS_IMETHOD BeginContext(PRInt32 aPosition) = 0; |
---|
204 | |
---|
205 | /** |
---|
206 | * This method terminates any new context that got created by |
---|
207 | * BeginContext and switches back to the main context. |
---|
208 | * |
---|
209 | * @update 04/04/99 harishd |
---|
210 | * @param aPosition - Validates the end of a context. |
---|
211 | */ |
---|
212 | NS_IMETHOD EndContext(PRInt32 aPosition) = 0; |
---|
213 | |
---|
214 | /** |
---|
215 | * @update 01/09/2003 harishd |
---|
216 | * @param aTag - Check if this tag is enabled or not. |
---|
217 | */ |
---|
218 | NS_IMETHOD IsEnabled(PRInt32 aTag, PRBool* aReturn) = 0; |
---|
219 | |
---|
220 | /** |
---|
221 | * This method is called when parser is about to begin |
---|
222 | * synchronously processing a chunk of tokens. |
---|
223 | */ |
---|
224 | NS_IMETHOD WillProcessTokens(void) = 0; |
---|
225 | |
---|
226 | /** |
---|
227 | * This method is called when parser has |
---|
228 | * completed processing a chunk of tokens. The processing of the |
---|
229 | * tokens may be interrupted by returning NS_ERROR_HTMLPARSER_INTERRUPTED from |
---|
230 | * DidProcessAToken. |
---|
231 | */ |
---|
232 | NS_IMETHOD DidProcessTokens() = 0; |
---|
233 | |
---|
234 | /** |
---|
235 | * This method is called when parser is about to |
---|
236 | * process a single token |
---|
237 | */ |
---|
238 | NS_IMETHOD WillProcessAToken(void) = 0; |
---|
239 | |
---|
240 | /** |
---|
241 | * This method is called when parser has completed |
---|
242 | * the processing for a single token. |
---|
243 | * @return NS_OK if processing should not be interrupted |
---|
244 | * NS_ERROR_HTMLPARSER_INTERRUPTED if the parsing should be interrupted |
---|
245 | */ |
---|
246 | NS_IMETHOD DidProcessAToken(void) = 0; |
---|
247 | |
---|
248 | /** |
---|
249 | * This method is used to open a generic container in the sink. |
---|
250 | * |
---|
251 | * @update 4/1/98 gess |
---|
252 | * @param nsIParserNode reference to parser node interface |
---|
253 | */ |
---|
254 | NS_IMETHOD OpenContainer(const nsIParserNode& aNode) = 0; |
---|
255 | |
---|
256 | /** |
---|
257 | * This method gets called by the parser when a close |
---|
258 | * container tag has been consumed and needs to be closed. |
---|
259 | * |
---|
260 | * @param aTag - The tag to be closed. |
---|
261 | */ |
---|
262 | NS_IMETHOD CloseContainer(const nsHTMLTag aTag) = 0; |
---|
263 | |
---|
264 | /** |
---|
265 | * This gets called by the parser to contents to |
---|
266 | * the head container |
---|
267 | * |
---|
268 | */ |
---|
269 | NS_IMETHOD AddHeadContent(const nsIParserNode& aNode) = 0; |
---|
270 | |
---|
271 | /** |
---|
272 | * This gets called by the parser when you want to add |
---|
273 | * a leaf node to the current container in the content |
---|
274 | * model. |
---|
275 | * |
---|
276 | * @update 4/1/98 gess |
---|
277 | * @param nsIParserNode reference to parser node interface |
---|
278 | */ |
---|
279 | NS_IMETHOD AddLeaf(const nsIParserNode& aNode) = 0; |
---|
280 | |
---|
281 | /** |
---|
282 | * This gets called by the parser when you want to add |
---|
283 | * a leaf node to the current container in the content |
---|
284 | * model. |
---|
285 | * |
---|
286 | * @update 4/1/98 gess |
---|
287 | * @param nsIParserNode reference to parser node interface |
---|
288 | */ |
---|
289 | NS_IMETHOD AddComment(const nsIParserNode& aNode) = 0; |
---|
290 | |
---|
291 | /** |
---|
292 | * This gets called by the parser when you want to add |
---|
293 | * a leaf node to the current container in the content |
---|
294 | * model. |
---|
295 | * |
---|
296 | * @update 4/1/98 gess |
---|
297 | * @param nsIParserNode reference to parser node interface |
---|
298 | */ |
---|
299 | NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) = 0; |
---|
300 | |
---|
301 | /** |
---|
302 | * This method is called by the parser when it encounters |
---|
303 | * a document type declaration. |
---|
304 | * |
---|
305 | * XXX Should the parser also part the internal subset? |
---|
306 | * |
---|
307 | * @param nsIParserNode reference to parser node interface |
---|
308 | */ |
---|
309 | NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode) = 0; |
---|
310 | |
---|
311 | /** |
---|
312 | * This gets called by the parser to notify observers of |
---|
313 | * the tag |
---|
314 | * |
---|
315 | * @param aErrorResult the error code |
---|
316 | */ |
---|
317 | NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode) = 0; |
---|
318 | |
---|
319 | /** |
---|
320 | * Call this method to determnine if a FORM is on the sink's stack |
---|
321 | * |
---|
322 | * @return PR_TRUE if found else PR_FALSE |
---|
323 | */ |
---|
324 | NS_IMETHOD_(PRBool) IsFormOnStack() = 0; |
---|
325 | |
---|
326 | }; |
---|
327 | |
---|
328 | #endif /* nsIHTMLContentSink_h___ */ |
---|
329 | |
---|