2 This file is part of the KDE libraries
4 Copyright (C) 1997 Martin Jones (mjones@kde.org)
5 (C) 1997 Torben Weis (weis@kde.org)
6 (C) 1998 Waldo Bastian (bastian@kde.org)
7 (C) 1999 Lars Knoll (knoll@kde.org)
8 Copyright (C) 2003 Apple Computer, Inc.
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
20 You should have received a copy of the GNU Library General Public License
21 along with this library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.
25 //----------------------------------------------------------------------------
27 // KDE HTML Widget -- HTML Parser
33 // 1 domtree + rendertree + styleForElement, no layouting
38 #include <qdatetime.h>
42 #include "dom/dom_string.h"
43 #include "xml/dom_nodeimpl.h"
44 #include "html/html_documentimpl.h"
50 class HTMLDocumentImpl;
52 class HTMLElementImpl;
54 class HTMLFormElementImpl;
55 class HTMLMapElementImpl;
56 class HTMLHeadElementImpl;
57 class DocumentFragmentImpl;
67 * The parser for html. It receives a stream of tokens from the HTMLTokenizer, and
68 * builds up the Document structure form it.
73 KHTMLParser(KHTMLView *w, DOM::DocumentPtr *i, bool includesComments=false);
74 KHTMLParser(DOM::DocumentFragmentImpl *frag, DOM::DocumentPtr *doc, bool includesComments=false);
75 virtual ~KHTMLParser();
78 * parses one token delivered by the tokenizer
80 void parseToken(khtml::Token *_t);
83 * tokenizer says it's not going to be sending us any more tokens
92 bool skipMode() const { return (discard_until != 0); }
93 bool noSpaces() const { return !inBody; }
94 bool selectMode() const { return inSelect; }
96 DOM::HTMLDocumentImpl *doc() const { return static_cast<DOM::HTMLDocumentImpl *>(document->document()); }
97 DOM::DocumentPtr *docPtr() const { return document; }
100 void setCurrent(DOM::NodeImpl *newCurrent);
102 KHTMLView *HTMLWidget;
103 DOM::DocumentPtr *document;
106 * generate an element from the token
108 DOM::NodeImpl *getElement(khtml::Token *);
110 void processCloseTag(khtml::Token *);
112 bool insertNode(DOM::NodeImpl *n, bool flat = false);
115 * The currently active element (the one new elements will be added to)
117 DOM::NodeImpl *current;
118 bool currentIsReferenced;
120 HTMLStackElem *blockStack;
122 void pushBlock( int _id, int _level);
124 void popBlock( int _id );
125 void popOneBlock(bool delBlock = true);
126 void popInlineBlocks();
128 void freeBlock( void);
132 bool isResidualStyleTag(int _id);
133 bool isAffectedByResidualStyle(int _id);
134 void handleResidualStyleCloseTagAcrossBlocks(HTMLStackElem* elem);
135 void reopenResidualStyleTags(HTMLStackElem* elem, DOM::NodeImpl* malformedTableParent);
137 bool allowNestedRedundantTag(int _id);
139 static bool isHeaderTag(int _id);
140 void popNestedHeaderTag();
142 ushort *forbiddenTag;
145 * currently active form
147 DOM::HTMLFormElementImpl *form;
152 DOM::HTMLMapElementImpl *map;
155 * the head element. Needed for crappy html which defines <base> after </head>
157 DOM::HTMLHeadElementImpl *head;
160 * a possible <isindex> element in the head. Compatibility hack for
161 * html from the stone age
163 DOM::NodeImpl *isindex;
164 DOM::NodeImpl *handleIsindex( khtml::Token *t );
167 * inserts the stupid isIndex element.
178 * tells the parser to discard all tags, until it reaches the one specified
183 int inStrayTableContent;
185 bool includesCommentsInDOM;
192 #endif // HTMLPARSER_H