fix logic
[personal-kdelibs.git] / khtml / html / htmlparser.h
blobf4a21dc4fbf6df21c3d0460603286e7210aaa7d1
1 /*
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 (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., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA.
25 //----------------------------------------------------------------------------
27 // KDE HTML Widget -- HTML Parser
29 #ifndef HTMLPARSER_H
30 #define HTMLPARSER_H
32 // 0 all
33 // 1 domtree + rendertree + styleForElement, no layouting
34 // 2 domtree only
35 #define SPEED_DEBUG 0
37 #ifdef SPEED_DEBUG
38 #include <QDateTime>
39 #endif
42 #include "dom/dom_string.h"
43 #include "xml/dom_nodeimpl.h"
44 #include "html/html_documentimpl.h"
46 class KHTMLView;
47 class HTMLStackElem;
49 namespace DOM {
50 class HTMLDocumentImpl;
51 class DocumentImpl;
52 class NodeImpl;
53 class HTMLFormElementImpl;
54 class HTMLMapElementImpl;
55 class HTMLHeadElementImpl;
56 class DocumentFragmentImpl;
59 namespace khtml {
61 class Token;
62 class DoctypeToken;
64 /**
65 * The parser for html. It receives a stream of tokens from the HTMLTokenizer, and
66 * builds up the Document structure form it.
68 class KHTMLParser
70 public:
71 KHTMLParser( KHTMLView *w, DOM::DocumentImpl *i );
72 KHTMLParser( DOM::DocumentFragmentImpl *frag, DOM::DocumentImpl *doc );
73 virtual ~KHTMLParser();
75 /**
76 * parses one token delivered by the tokenizer
78 void parseToken(Token *_t);
80 /**
81 * parses a doctype token delivered by the tokenizer
83 void parseDoctypeToken(DoctypeToken *_t);
85 /**
86 * resets the parser
88 void reset();
90 bool skipMode() const { return (discard_until != 0); }
91 bool noSpaces() const { return (inSelect || !m_inline || !inBody); }
92 bool selectMode() const { return inSelect; }
94 DOM::HTMLDocumentImpl *doc() const { return static_cast<DOM::HTMLDocumentImpl *>(document); }
95 DOM::DocumentImpl *docPtr() const { return document; }
97 protected:
99 KHTMLView *HTMLWidget;
100 DOM::DocumentImpl *document;
103 * generate an element from the token
105 DOM::NodeImpl *getElement(Token *);
107 void processCloseTag(Token *);
109 bool insertNode(DOM::NodeImpl *n, bool flat = false);
112 * The currently active element (the one new elements will be added to)
114 void setCurrent( DOM::NodeImpl* newNode )
116 if ( newNode ) newNode->ref();
117 if ( current ) current->deref();
118 current = newNode;
121 private:
122 DOM::NodeImpl *current;
124 HTMLStackElem *blockStack;
126 void pushBlock( int _id, int _level);
128 void generateImpliedEndTags( int _id );
129 void popOptionalBlock( int _id );
130 void popBlock( int _id );
131 void popOneBlock(bool delBlock = true);
132 void popInlineBlocks();
134 void freeBlock( void);
136 void createHead();
138 bool isResidualStyleTag(int _id);
139 bool isAffectedByResidualStyle(int _id);
140 void handleResidualStyleCloseTagAcrossBlocks(HTMLStackElem* elem);
141 void reopenResidualStyleTags(HTMLStackElem* elem, DOM::NodeImpl* malformedTableParent);
143 ushort *forbiddenTag;
146 * currently active form
148 DOM::HTMLFormElementImpl *form;
151 * current map
153 DOM::HTMLMapElementImpl *map;
156 * the head element. Needed for crappy html which defines <base> after </head>
158 DOM::HTMLHeadElementImpl *head;
161 * a possible <isindex> element in the head. Compatibility hack for
162 * html from the stone age
164 DOM::NodeImpl *isindex;
165 DOM::NodeImpl *handleIsindex( Token *t );
168 * inserts the stupid isIndex element.
170 void startBody();
172 bool inBody;
173 bool haveContent;
174 bool haveBody;
175 bool haveFrameSet;
176 bool haveTitle;
177 bool m_inline;
178 bool end;
179 bool inSelect;
183 * tells the parser to discard all tags, until it reaches the one specified
185 int discard_until;
187 bool headLoaded;
188 int inStrayTableContent;
190 #if SPEED_DEBUG > 0
191 QTime qt;
192 #endif
195 } // namespace khtml
197 #endif // HTMLPARSER_H