1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QTEXTHTMLPARSER_P_H
|
---|
43 | #define QTEXTHTMLPARSER_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "QtCore/qvector.h"
|
---|
57 | #include "QtGui/qbrush.h"
|
---|
58 | #include "QtGui/qcolor.h"
|
---|
59 | #include "QtGui/qfont.h"
|
---|
60 | #include "QtGui/qtextdocument.h"
|
---|
61 | #include "QtGui/qtextcursor.h"
|
---|
62 | #include "private/qtextformat_p.h"
|
---|
63 | #include "private/qtextdocument_p.h"
|
---|
64 | #include "private/qcssparser_p.h"
|
---|
65 |
|
---|
66 | #ifndef QT_NO_TEXTHTMLPARSER
|
---|
67 |
|
---|
68 | QT_BEGIN_NAMESPACE
|
---|
69 |
|
---|
70 | enum QTextHTMLElements {
|
---|
71 | Html_unknown = -1,
|
---|
72 | Html_qt = 0,
|
---|
73 | Html_body,
|
---|
74 |
|
---|
75 | Html_a,
|
---|
76 | Html_em,
|
---|
77 | Html_i,
|
---|
78 | Html_big,
|
---|
79 | Html_small,
|
---|
80 | Html_strong,
|
---|
81 | Html_b,
|
---|
82 | Html_cite,
|
---|
83 | Html_address,
|
---|
84 | Html_var,
|
---|
85 | Html_dfn,
|
---|
86 |
|
---|
87 | Html_h1,
|
---|
88 | Html_h2,
|
---|
89 | Html_h3,
|
---|
90 | Html_h4,
|
---|
91 | Html_h5,
|
---|
92 | Html_h6,
|
---|
93 | Html_p,
|
---|
94 | Html_center,
|
---|
95 |
|
---|
96 | Html_font,
|
---|
97 |
|
---|
98 | Html_ul,
|
---|
99 | Html_ol,
|
---|
100 | Html_li,
|
---|
101 |
|
---|
102 | Html_code,
|
---|
103 | Html_tt,
|
---|
104 | Html_kbd,
|
---|
105 | Html_samp,
|
---|
106 |
|
---|
107 | Html_img,
|
---|
108 | Html_br,
|
---|
109 | Html_hr,
|
---|
110 |
|
---|
111 | Html_sub,
|
---|
112 | Html_sup,
|
---|
113 |
|
---|
114 | Html_pre,
|
---|
115 | Html_blockquote,
|
---|
116 | Html_head,
|
---|
117 | Html_div,
|
---|
118 | Html_span,
|
---|
119 | Html_dl,
|
---|
120 | Html_dt,
|
---|
121 | Html_dd,
|
---|
122 | Html_u,
|
---|
123 | Html_s,
|
---|
124 | Html_nobr,
|
---|
125 |
|
---|
126 | // tables
|
---|
127 | Html_table,
|
---|
128 | Html_tr,
|
---|
129 | Html_td,
|
---|
130 | Html_th,
|
---|
131 | Html_thead,
|
---|
132 | Html_tbody,
|
---|
133 | Html_tfoot,
|
---|
134 | Html_caption,
|
---|
135 |
|
---|
136 | // misc...
|
---|
137 | Html_html,
|
---|
138 | Html_style,
|
---|
139 | Html_title,
|
---|
140 | Html_meta,
|
---|
141 | Html_link,
|
---|
142 | Html_script,
|
---|
143 |
|
---|
144 | Html_NumElements
|
---|
145 | };
|
---|
146 |
|
---|
147 | struct QTextHtmlElement
|
---|
148 | {
|
---|
149 | const char *name;
|
---|
150 | QTextHTMLElements id;
|
---|
151 | enum DisplayMode { DisplayBlock, DisplayInline, DisplayTable, DisplayNone } displayMode;
|
---|
152 | };
|
---|
153 |
|
---|
154 | class QTextHtmlParser;
|
---|
155 |
|
---|
156 | struct QTextHtmlParserNode {
|
---|
157 | enum WhiteSpaceMode {
|
---|
158 | WhiteSpaceNormal,
|
---|
159 | WhiteSpacePre,
|
---|
160 | WhiteSpaceNoWrap,
|
---|
161 | WhiteSpacePreWrap,
|
---|
162 | WhiteSpaceModeUndefined = -1
|
---|
163 | };
|
---|
164 |
|
---|
165 | QTextHtmlParserNode();
|
---|
166 | QString tag;
|
---|
167 | QString text;
|
---|
168 | QStringList attributes;
|
---|
169 | int parent;
|
---|
170 | QVector<int> children;
|
---|
171 | QTextHTMLElements id;
|
---|
172 | QTextCharFormat charFormat;
|
---|
173 | QTextBlockFormat blockFormat;
|
---|
174 | uint cssFloat : 2;
|
---|
175 | uint hasOwnListStyle : 1;
|
---|
176 | uint hasCssListIndent : 1;
|
---|
177 | uint isEmptyParagraph : 1;
|
---|
178 | uint isTextFrame : 1;
|
---|
179 | uint isRootFrame : 1;
|
---|
180 | uint displayMode : 3; // QTextHtmlElement::DisplayMode
|
---|
181 | uint hasHref : 1;
|
---|
182 | QTextListFormat::Style listStyle;
|
---|
183 | QString imageName;
|
---|
184 | qreal imageWidth;
|
---|
185 | qreal imageHeight;
|
---|
186 | QTextLength width;
|
---|
187 | QTextLength height;
|
---|
188 | qreal tableBorder;
|
---|
189 | int tableCellRowSpan;
|
---|
190 | int tableCellColSpan;
|
---|
191 | qreal tableCellSpacing;
|
---|
192 | qreal tableCellPadding;
|
---|
193 | QBrush borderBrush;
|
---|
194 | QTextFrameFormat::BorderStyle borderStyle;
|
---|
195 | int userState;
|
---|
196 |
|
---|
197 | int cssListIndent;
|
---|
198 |
|
---|
199 | WhiteSpaceMode wsm;
|
---|
200 |
|
---|
201 | inline bool isListStart() const
|
---|
202 | { return id == Html_ol || id == Html_ul; }
|
---|
203 | inline bool isTableCell() const
|
---|
204 | { return id == Html_td || id == Html_th; }
|
---|
205 | inline bool isBlock() const
|
---|
206 | { return displayMode == QTextHtmlElement::DisplayBlock; }
|
---|
207 |
|
---|
208 | inline bool isNotSelfNesting() const
|
---|
209 | { return id == Html_p || id == Html_li; }
|
---|
210 |
|
---|
211 | inline bool allowedInContext(int parentId) const
|
---|
212 | {
|
---|
213 | switch (id) {
|
---|
214 | case Html_dd:
|
---|
215 | case Html_dt: return (parentId == Html_dl);
|
---|
216 | case Html_tr: return (parentId == Html_table
|
---|
217 | || parentId == Html_thead
|
---|
218 | || parentId == Html_tbody
|
---|
219 | || parentId == Html_tfoot
|
---|
220 | );
|
---|
221 | case Html_th:
|
---|
222 | case Html_td: return (parentId == Html_tr);
|
---|
223 | case Html_thead:
|
---|
224 | case Html_tbody:
|
---|
225 | case Html_tfoot: return (parentId == Html_table);
|
---|
226 | case Html_caption: return (parentId == Html_table);
|
---|
227 | case Html_body: return parentId != Html_head;
|
---|
228 | default: break;
|
---|
229 | }
|
---|
230 | return true;
|
---|
231 | }
|
---|
232 |
|
---|
233 | inline bool mayNotHaveChildren() const
|
---|
234 | { return id == Html_img || id == Html_hr || id == Html_br || id == Html_meta; }
|
---|
235 |
|
---|
236 | void initializeProperties(const QTextHtmlParserNode *parent, const QTextHtmlParser *parser);
|
---|
237 |
|
---|
238 | inline int uncollapsedMargin(int mar) const { return margin[mar]; }
|
---|
239 |
|
---|
240 | bool isNestedList(const QTextHtmlParser *parser) const;
|
---|
241 |
|
---|
242 | void parseStyleAttribute(const QString &value, const QTextDocument *resourceProvider);
|
---|
243 |
|
---|
244 | #ifndef QT_NO_CSSPARSER
|
---|
245 | void applyCssDeclarations(const QVector<QCss::Declaration> &declarations, const QTextDocument *resourceProvider);
|
---|
246 |
|
---|
247 | void setListStyle(const QVector<QCss::Value> &cssValues);
|
---|
248 | #endif
|
---|
249 |
|
---|
250 | void applyBackgroundImage(const QString &url, const QTextDocument *resourceProvider);
|
---|
251 |
|
---|
|
---|