Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtexthtmlparser.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qtexthtmlparser_p.h" | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #include <qbytearray.h> | - | ||||||||||||||||||
37 | #include <qtextcodec.h> | - | ||||||||||||||||||
38 | #include <qstack.h> | - | ||||||||||||||||||
39 | #include <qdebug.h> | - | ||||||||||||||||||
40 | #include <qthread.h> | - | ||||||||||||||||||
41 | #include <qguiapplication.h> | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | #include "qtextdocument.h" | - | ||||||||||||||||||
44 | #include "qtextformat_p.h" | - | ||||||||||||||||||
45 | #include "qtextdocument_p.h" | - | ||||||||||||||||||
46 | #include "qtextcursor.h" | - | ||||||||||||||||||
47 | #include "qfont_p.h" | - | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | #include <algorithm> | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | #ifndef QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | // see also tst_qtextdocumentfragment.cpp | - | ||||||||||||||||||
56 | #define MAX_ENTITY 258 | - | ||||||||||||||||||
57 | static const struct QTextHtmlEntity { const char name[9]; quint16 code; } entities[]= { | - | ||||||||||||||||||
58 | { "AElig", 0x00c6 }, | - | ||||||||||||||||||
59 | { "AMP", 38 }, | - | ||||||||||||||||||
60 | { "Aacute", 0x00c1 }, | - | ||||||||||||||||||
61 | { "Acirc", 0x00c2 }, | - | ||||||||||||||||||
62 | { "Agrave", 0x00c0 }, | - | ||||||||||||||||||
63 | { "Alpha", 0x0391 }, | - | ||||||||||||||||||
64 | { "Aring", 0x00c5 }, | - | ||||||||||||||||||
65 | { "Atilde", 0x00c3 }, | - | ||||||||||||||||||
66 | { "Auml", 0x00c4 }, | - | ||||||||||||||||||
67 | { "Beta", 0x0392 }, | - | ||||||||||||||||||
68 | { "Ccedil", 0x00c7 }, | - | ||||||||||||||||||
69 | { "Chi", 0x03a7 }, | - | ||||||||||||||||||
70 | { "Dagger", 0x2021 }, | - | ||||||||||||||||||
71 | { "Delta", 0x0394 }, | - | ||||||||||||||||||
72 | { "ETH", 0x00d0 }, | - | ||||||||||||||||||
73 | { "Eacute", 0x00c9 }, | - | ||||||||||||||||||
74 | { "Ecirc", 0x00ca }, | - | ||||||||||||||||||
75 | { "Egrave", 0x00c8 }, | - | ||||||||||||||||||
76 | { "Epsilon", 0x0395 }, | - | ||||||||||||||||||
77 | { "Eta", 0x0397 }, | - | ||||||||||||||||||
78 | { "Euml", 0x00cb }, | - | ||||||||||||||||||
79 | { "GT", 62 }, | - | ||||||||||||||||||
80 | { "Gamma", 0x0393 }, | - | ||||||||||||||||||
81 | { "Iacute", 0x00cd }, | - | ||||||||||||||||||
82 | { "Icirc", 0x00ce }, | - | ||||||||||||||||||
83 | { "Igrave", 0x00cc }, | - | ||||||||||||||||||
84 | { "Iota", 0x0399 }, | - | ||||||||||||||||||
85 | { "Iuml", 0x00cf }, | - | ||||||||||||||||||
86 | { "Kappa", 0x039a }, | - | ||||||||||||||||||
87 | { "LT", 60 }, | - | ||||||||||||||||||
88 | { "Lambda", 0x039b }, | - | ||||||||||||||||||
89 | { "Mu", 0x039c }, | - | ||||||||||||||||||
90 | { "Ntilde", 0x00d1 }, | - | ||||||||||||||||||
91 | { "Nu", 0x039d }, | - | ||||||||||||||||||
92 | { "OElig", 0x0152 }, | - | ||||||||||||||||||
93 | { "Oacute", 0x00d3 }, | - | ||||||||||||||||||
94 | { "Ocirc", 0x00d4 }, | - | ||||||||||||||||||
95 | { "Ograve", 0x00d2 }, | - | ||||||||||||||||||
96 | { "Omega", 0x03a9 }, | - | ||||||||||||||||||
97 | { "Omicron", 0x039f }, | - | ||||||||||||||||||
98 | { "Oslash", 0x00d8 }, | - | ||||||||||||||||||
99 | { "Otilde", 0x00d5 }, | - | ||||||||||||||||||
100 | { "Ouml", 0x00d6 }, | - | ||||||||||||||||||
101 | { "Phi", 0x03a6 }, | - | ||||||||||||||||||
102 | { "Pi", 0x03a0 }, | - | ||||||||||||||||||
103 | { "Prime", 0x2033 }, | - | ||||||||||||||||||
104 | { "Psi", 0x03a8 }, | - | ||||||||||||||||||
105 | { "QUOT", 34 }, | - | ||||||||||||||||||
106 | { "Rho", 0x03a1 }, | - | ||||||||||||||||||
107 | { "Scaron", 0x0160 }, | - | ||||||||||||||||||
108 | { "Sigma", 0x03a3 }, | - | ||||||||||||||||||
109 | { "THORN", 0x00de }, | - | ||||||||||||||||||
110 | { "Tau", 0x03a4 }, | - | ||||||||||||||||||
111 | { "Theta", 0x0398 }, | - | ||||||||||||||||||
112 | { "Uacute", 0x00da }, | - | ||||||||||||||||||
113 | { "Ucirc", 0x00db }, | - | ||||||||||||||||||
114 | { "Ugrave", 0x00d9 }, | - | ||||||||||||||||||
115 | { "Upsilon", 0x03a5 }, | - | ||||||||||||||||||
116 | { "Uuml", 0x00dc }, | - | ||||||||||||||||||
117 | { "Xi", 0x039e }, | - | ||||||||||||||||||
118 | { "Yacute", 0x00dd }, | - | ||||||||||||||||||
119 | { "Yuml", 0x0178 }, | - | ||||||||||||||||||
120 | { "Zeta", 0x0396 }, | - | ||||||||||||||||||
121 | { "aacute", 0x00e1 }, | - | ||||||||||||||||||
122 | { "acirc", 0x00e2 }, | - | ||||||||||||||||||
123 | { "acute", 0x00b4 }, | - | ||||||||||||||||||
124 | { "aelig", 0x00e6 }, | - | ||||||||||||||||||
125 | { "agrave", 0x00e0 }, | - | ||||||||||||||||||
126 | { "alefsym", 0x2135 }, | - | ||||||||||||||||||
127 | { "alpha", 0x03b1 }, | - | ||||||||||||||||||
128 | { "amp", 38 }, | - | ||||||||||||||||||
129 | { "and", 0x22a5 }, | - | ||||||||||||||||||
130 | { "ang", 0x2220 }, | - | ||||||||||||||||||
131 | { "apos", 0x0027 }, | - | ||||||||||||||||||
132 | { "aring", 0x00e5 }, | - | ||||||||||||||||||
133 | { "asymp", 0x2248 }, | - | ||||||||||||||||||
134 | { "atilde", 0x00e3 }, | - | ||||||||||||||||||
135 | { "auml", 0x00e4 }, | - | ||||||||||||||||||
136 | { "bdquo", 0x201e }, | - | ||||||||||||||||||
137 | { "beta", 0x03b2 }, | - | ||||||||||||||||||
138 | { "brvbar", 0x00a6 }, | - | ||||||||||||||||||
139 | { "bull", 0x2022 }, | - | ||||||||||||||||||
140 | { "cap", 0x2229 }, | - | ||||||||||||||||||
141 | { "ccedil", 0x00e7 }, | - | ||||||||||||||||||
142 | { "cedil", 0x00b8 }, | - | ||||||||||||||||||
143 | { "cent", 0x00a2 }, | - | ||||||||||||||||||
144 | { "chi", 0x03c7 }, | - | ||||||||||||||||||
145 | { "circ", 0x02c6 }, | - | ||||||||||||||||||
146 | { "clubs", 0x2663 }, | - | ||||||||||||||||||
147 | { "cong", 0x2245 }, | - | ||||||||||||||||||
148 | { "copy", 0x00a9 }, | - | ||||||||||||||||||
149 | { "crarr", 0x21b5 }, | - | ||||||||||||||||||
150 | { "cup", 0x222a }, | - | ||||||||||||||||||
151 | { "curren", 0x00a4 }, | - | ||||||||||||||||||
152 | { "dArr", 0x21d3 }, | - | ||||||||||||||||||
153 | { "dagger", 0x2020 }, | - | ||||||||||||||||||
154 | { "darr", 0x2193 }, | - | ||||||||||||||||||
155 | { "deg", 0x00b0 }, | - | ||||||||||||||||||
156 | { "delta", 0x03b4 }, | - | ||||||||||||||||||
157 | { "diams", 0x2666 }, | - | ||||||||||||||||||
158 | { "divide", 0x00f7 }, | - | ||||||||||||||||||
159 | { "eacute", 0x00e9 }, | - | ||||||||||||||||||
160 | { "ecirc", 0x00ea }, | - | ||||||||||||||||||
161 | { "egrave", 0x00e8 }, | - | ||||||||||||||||||
162 | { "empty", 0x2205 }, | - | ||||||||||||||||||
163 | { "emsp", 0x2003 }, | - | ||||||||||||||||||
164 | { "ensp", 0x2002 }, | - | ||||||||||||||||||
165 | { "epsilon", 0x03b5 }, | - | ||||||||||||||||||
166 | { "equiv", 0x2261 }, | - | ||||||||||||||||||
167 | { "eta", 0x03b7 }, | - | ||||||||||||||||||
168 | { "eth", 0x00f0 }, | - | ||||||||||||||||||
169 | { "euml", 0x00eb }, | - | ||||||||||||||||||
170 | { "euro", 0x20ac }, | - | ||||||||||||||||||
171 | { "exist", 0x2203 }, | - | ||||||||||||||||||
172 | { "fnof", 0x0192 }, | - | ||||||||||||||||||
173 | { "forall", 0x2200 }, | - | ||||||||||||||||||
174 | { "frac12", 0x00bd }, | - | ||||||||||||||||||
175 | { "frac14", 0x00bc }, | - | ||||||||||||||||||
176 | { "frac34", 0x00be }, | - | ||||||||||||||||||
177 | { "frasl", 0x2044 }, | - | ||||||||||||||||||
178 | { "gamma", 0x03b3 }, | - | ||||||||||||||||||
179 | { "ge", 0x2265 }, | - | ||||||||||||||||||
180 | { "gt", 62 }, | - | ||||||||||||||||||
181 | { "hArr", 0x21d4 }, | - | ||||||||||||||||||
182 | { "harr", 0x2194 }, | - | ||||||||||||||||||
183 | { "hearts", 0x2665 }, | - | ||||||||||||||||||
184 | { "hellip", 0x2026 }, | - | ||||||||||||||||||
185 | { "iacute", 0x00ed }, | - | ||||||||||||||||||
186 | { "icirc", 0x00ee }, | - | ||||||||||||||||||
187 | { "iexcl", 0x00a1 }, | - | ||||||||||||||||||
188 | { "igrave", 0x00ec }, | - | ||||||||||||||||||
189 | { "image", 0x2111 }, | - | ||||||||||||||||||
190 | { "infin", 0x221e }, | - | ||||||||||||||||||
191 | { "int", 0x222b }, | - | ||||||||||||||||||
192 | { "iota", 0x03b9 }, | - | ||||||||||||||||||
193 | { "iquest", 0x00bf }, | - | ||||||||||||||||||
194 | { "isin", 0x2208 }, | - | ||||||||||||||||||
195 | { "iuml", 0x00ef }, | - | ||||||||||||||||||
196 | { "kappa", 0x03ba }, | - | ||||||||||||||||||
197 | { "lArr", 0x21d0 }, | - | ||||||||||||||||||
198 | { "lambda", 0x03bb }, | - | ||||||||||||||||||
199 | { "lang", 0x2329 }, | - | ||||||||||||||||||
200 | { "laquo", 0x00ab }, | - | ||||||||||||||||||
201 | { "larr", 0x2190 }, | - | ||||||||||||||||||
202 | { "lceil", 0x2308 }, | - | ||||||||||||||||||
203 | { "ldquo", 0x201c }, | - | ||||||||||||||||||
204 | { "le", 0x2264 }, | - | ||||||||||||||||||
205 | { "lfloor", 0x230a }, | - | ||||||||||||||||||
206 | { "lowast", 0x2217 }, | - | ||||||||||||||||||
207 | { "loz", 0x25ca }, | - | ||||||||||||||||||
208 | { "lrm", 0x200e }, | - | ||||||||||||||||||
209 | { "lsaquo", 0x2039 }, | - | ||||||||||||||||||
210 | { "lsquo", 0x2018 }, | - | ||||||||||||||||||
211 | { "lt", 60 }, | - | ||||||||||||||||||
212 | { "macr", 0x00af }, | - | ||||||||||||||||||
213 | { "mdash", 0x2014 }, | - | ||||||||||||||||||
214 | { "micro", 0x00b5 }, | - | ||||||||||||||||||
215 | { "middot", 0x00b7 }, | - | ||||||||||||||||||
216 | { "minus", 0x2212 }, | - | ||||||||||||||||||
217 | { "mu", 0x03bc }, | - | ||||||||||||||||||
218 | { "nabla", 0x2207 }, | - | ||||||||||||||||||
219 | { "nbsp", 0x00a0 }, | - | ||||||||||||||||||
220 | { "ndash", 0x2013 }, | - | ||||||||||||||||||
221 | { "ne", 0x2260 }, | - | ||||||||||||||||||
222 | { "ni", 0x220b }, | - | ||||||||||||||||||
223 | { "not", 0x00ac }, | - | ||||||||||||||||||
224 | { "notin", 0x2209 }, | - | ||||||||||||||||||
225 | { "nsub", 0x2284 }, | - | ||||||||||||||||||
226 | { "ntilde", 0x00f1 }, | - | ||||||||||||||||||
227 | { "nu", 0x03bd }, | - | ||||||||||||||||||
228 | { "oacute", 0x00f3 }, | - | ||||||||||||||||||
229 | { "ocirc", 0x00f4 }, | - | ||||||||||||||||||
230 | { "oelig", 0x0153 }, | - | ||||||||||||||||||
231 | { "ograve", 0x00f2 }, | - | ||||||||||||||||||
232 | { "oline", 0x203e }, | - | ||||||||||||||||||
233 | { "omega", 0x03c9 }, | - | ||||||||||||||||||
234 | { "omicron", 0x03bf }, | - | ||||||||||||||||||
235 | { "oplus", 0x2295 }, | - | ||||||||||||||||||
236 | { "or", 0x22a6 }, | - | ||||||||||||||||||
237 | { "ordf", 0x00aa }, | - | ||||||||||||||||||
238 | { "ordm", 0x00ba }, | - | ||||||||||||||||||
239 | { "oslash", 0x00f8 }, | - | ||||||||||||||||||
240 | { "otilde", 0x00f5 }, | - | ||||||||||||||||||
241 | { "otimes", 0x2297 }, | - | ||||||||||||||||||
242 | { "ouml", 0x00f6 }, | - | ||||||||||||||||||
243 | { "para", 0x00b6 }, | - | ||||||||||||||||||
244 | { "part", 0x2202 }, | - | ||||||||||||||||||
245 | { "percnt", 0x0025 }, | - | ||||||||||||||||||
246 | { "permil", 0x2030 }, | - | ||||||||||||||||||
247 | { "perp", 0x22a5 }, | - | ||||||||||||||||||
248 | { "phi", 0x03c6 }, | - | ||||||||||||||||||
249 | { "pi", 0x03c0 }, | - | ||||||||||||||||||
250 | { "piv", 0x03d6 }, | - | ||||||||||||||||||
251 | { "plusmn", 0x00b1 }, | - | ||||||||||||||||||
252 | { "pound", 0x00a3 }, | - | ||||||||||||||||||
253 | { "prime", 0x2032 }, | - | ||||||||||||||||||
254 | { "prod", 0x220f }, | - | ||||||||||||||||||
255 | { "prop", 0x221d }, | - | ||||||||||||||||||
256 | { "psi", 0x03c8 }, | - | ||||||||||||||||||
257 | { "quot", 34 }, | - | ||||||||||||||||||
258 | { "rArr", 0x21d2 }, | - | ||||||||||||||||||
259 | { "radic", 0x221a }, | - | ||||||||||||||||||
260 | { "rang", 0x232a }, | - | ||||||||||||||||||
261 | { "raquo", 0x00bb }, | - | ||||||||||||||||||
262 | { "rarr", 0x2192 }, | - | ||||||||||||||||||
263 | { "rceil", 0x2309 }, | - | ||||||||||||||||||
264 | { "rdquo", 0x201d }, | - | ||||||||||||||||||
265 | { "real", 0x211c }, | - | ||||||||||||||||||
266 | { "reg", 0x00ae }, | - | ||||||||||||||||||
267 | { "rfloor", 0x230b }, | - | ||||||||||||||||||
268 | { "rho", 0x03c1 }, | - | ||||||||||||||||||
269 | { "rlm", 0x200f }, | - | ||||||||||||||||||
270 | { "rsaquo", 0x203a }, | - | ||||||||||||||||||
271 | { "rsquo", 0x2019 }, | - | ||||||||||||||||||
272 | { "sbquo", 0x201a }, | - | ||||||||||||||||||
273 | { "scaron", 0x0161 }, | - | ||||||||||||||||||
274 | { "sdot", 0x22c5 }, | - | ||||||||||||||||||
275 | { "sect", 0x00a7 }, | - | ||||||||||||||||||
276 | { "shy", 0x00ad }, | - | ||||||||||||||||||
277 | { "sigma", 0x03c3 }, | - | ||||||||||||||||||
278 | { "sigmaf", 0x03c2 }, | - | ||||||||||||||||||
279 | { "sim", 0x223c }, | - | ||||||||||||||||||
280 | { "spades", 0x2660 }, | - | ||||||||||||||||||
281 | { "sub", 0x2282 }, | - | ||||||||||||||||||
282 | { "sube", 0x2286 }, | - | ||||||||||||||||||
283 | { "sum", 0x2211 }, | - | ||||||||||||||||||
284 | { "sup", 0x2283 }, | - | ||||||||||||||||||
285 | { "sup1", 0x00b9 }, | - | ||||||||||||||||||
286 | { "sup2", 0x00b2 }, | - | ||||||||||||||||||
287 | { "sup3", 0x00b3 }, | - | ||||||||||||||||||
288 | { "supe", 0x2287 }, | - | ||||||||||||||||||
289 | { "szlig", 0x00df }, | - | ||||||||||||||||||
290 | { "tau", 0x03c4 }, | - | ||||||||||||||||||
291 | { "there4", 0x2234 }, | - | ||||||||||||||||||
292 | { "theta", 0x03b8 }, | - | ||||||||||||||||||
293 | { "thetasym", 0x03d1 }, | - | ||||||||||||||||||
294 | { "thinsp", 0x2009 }, | - | ||||||||||||||||||
295 | { "thorn", 0x00fe }, | - | ||||||||||||||||||
296 | { "tilde", 0x02dc }, | - | ||||||||||||||||||
297 | { "times", 0x00d7 }, | - | ||||||||||||||||||
298 | { "trade", 0x2122 }, | - | ||||||||||||||||||
299 | { "uArr", 0x21d1 }, | - | ||||||||||||||||||
300 | { "uacute", 0x00fa }, | - | ||||||||||||||||||
301 | { "uarr", 0x2191 }, | - | ||||||||||||||||||
302 | { "ucirc", 0x00fb }, | - | ||||||||||||||||||
303 | { "ugrave", 0x00f9 }, | - | ||||||||||||||||||
304 | { "uml", 0x00a8 }, | - | ||||||||||||||||||
305 | { "upsih", 0x03d2 }, | - | ||||||||||||||||||
306 | { "upsilon", 0x03c5 }, | - | ||||||||||||||||||
307 | { "uuml", 0x00fc }, | - | ||||||||||||||||||
308 | { "weierp", 0x2118 }, | - | ||||||||||||||||||
309 | { "xi", 0x03be }, | - | ||||||||||||||||||
310 | { "yacute", 0x00fd }, | - | ||||||||||||||||||
311 | { "yen", 0x00a5 }, | - | ||||||||||||||||||
312 | { "yuml", 0x00ff }, | - | ||||||||||||||||||
313 | { "zeta", 0x03b6 }, | - | ||||||||||||||||||
314 | { "zwj", 0x200d }, | - | ||||||||||||||||||
315 | { "zwnj", 0x200c } | - | ||||||||||||||||||
316 | }; | - | ||||||||||||||||||
317 | Q_STATIC_ASSERT(MAX_ENTITY == sizeof entities / sizeof *entities); | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | #if defined(Q_CC_MSVC) && _MSC_VER < 1600 | - | ||||||||||||||||||
320 | bool operator<(const QTextHtmlEntity &entity1, const QTextHtmlEntity &entity2) | - | ||||||||||||||||||
321 | { | - | ||||||||||||||||||
322 | return QLatin1String(entity1.name) < QLatin1String(entity2.name); | - | ||||||||||||||||||
323 | } | - | ||||||||||||||||||
324 | #endif | - | ||||||||||||||||||
325 | - | |||||||||||||||||||
326 | static bool operator<(const QString &entityStr, const QTextHtmlEntity &entity) | - | ||||||||||||||||||
327 | { | - | ||||||||||||||||||
328 | return entityStr < QLatin1String(entity.name); never executed: return entityStr < QLatin1String(entity.name); | 0 | ||||||||||||||||||
329 | } | - | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | static bool operator<(const QTextHtmlEntity &entity, const QString &entityStr) | - | ||||||||||||||||||
332 | { | - | ||||||||||||||||||
333 | return QLatin1String(entity.name) < entityStr; never executed: return QLatin1String(entity.name) < entityStr; | 0 | ||||||||||||||||||
334 | } | - | ||||||||||||||||||
335 | - | |||||||||||||||||||
336 | static QChar resolveEntity(const QString &entity) | - | ||||||||||||||||||
337 | { | - | ||||||||||||||||||
338 | const QTextHtmlEntity *start = &entities[0]; | - | ||||||||||||||||||
339 | const QTextHtmlEntity *end = &entities[MAX_ENTITY]; | - | ||||||||||||||||||
340 | const QTextHtmlEntity *e = std::lower_bound(start, end, entity); | - | ||||||||||||||||||
341 | if (e == end || (entity < *e))
| 0 | ||||||||||||||||||
342 | return QChar(); never executed: return QChar(); | 0 | ||||||||||||||||||
343 | return e->code; never executed: return e->code; | 0 | ||||||||||||||||||
344 | } | - | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | static const ushort windowsLatin1ExtendedCharacters[0xA0 - 0x80] = { | - | ||||||||||||||||||
347 | 0x20ac, // 0x80 | - | ||||||||||||||||||
348 | 0x0081, // 0x81 direct mapping | - | ||||||||||||||||||
349 | 0x201a, // 0x82 | - | ||||||||||||||||||
350 | 0x0192, // 0x83 | - | ||||||||||||||||||
351 | 0x201e, // 0x84 | - | ||||||||||||||||||
352 | 0x2026, // 0x85 | - | ||||||||||||||||||
353 | 0x2020, // 0x86 | - | ||||||||||||||||||
354 | 0x2021, // 0x87 | - | ||||||||||||||||||
355 | 0x02C6, // 0x88 | - | ||||||||||||||||||
356 | 0x2030, // 0x89 | - | ||||||||||||||||||
357 | 0x0160, // 0x8A | - | ||||||||||||||||||
358 | 0x2039, // 0x8B | - | ||||||||||||||||||
359 | 0x0152, // 0x8C | - | ||||||||||||||||||
360 | 0x008D, // 0x8D direct mapping | - | ||||||||||||||||||
361 | 0x017D, // 0x8E | - | ||||||||||||||||||
362 | 0x008F, // 0x8F directmapping | - | ||||||||||||||||||
363 | 0x0090, // 0x90 directmapping | - | ||||||||||||||||||
364 | 0x2018, // 0x91 | - | ||||||||||||||||||
365 | 0x2019, // 0x92 | - | ||||||||||||||||||
366 | 0x201C, // 0x93 | - | ||||||||||||||||||
367 | 0X201D, // 0x94 | - | ||||||||||||||||||
368 | 0x2022, // 0x95 | - | ||||||||||||||||||
369 | 0x2013, // 0x96 | - | ||||||||||||||||||
370 | 0x2014, // 0x97 | - | ||||||||||||||||||
371 | 0x02DC, // 0x98 | - | ||||||||||||||||||
372 | 0x2122, // 0x99 | - | ||||||||||||||||||
373 | 0x0161, // 0x9A | - | ||||||||||||||||||
374 | 0x203A, // 0x9B | - | ||||||||||||||||||
375 | 0x0153, // 0x9C | - | ||||||||||||||||||
376 | 0x009D, // 0x9D direct mapping | - | ||||||||||||||||||
377 | 0x017E, // 0x9E | - | ||||||||||||||||||
378 | 0x0178 // 0x9F | - | ||||||||||||||||||
379 | }; | - | ||||||||||||||||||
380 | - | |||||||||||||||||||
381 | // the displayMode value is according to the what are blocks in the piecetable, not | - | ||||||||||||||||||
382 | // what the w3c defines. | - | ||||||||||||||||||
383 | static const QTextHtmlElement elements[Html_NumElements]= { | - | ||||||||||||||||||
384 | { "a", Html_a, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
385 | { "address", Html_address, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
386 | { "b", Html_b, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
387 | { "big", Html_big, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
388 | { "blockquote", Html_blockquote, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
389 | { "body", Html_body, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
390 | { "br", Html_br, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
391 | { "caption", Html_caption, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
392 | { "center", Html_center, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
393 | { "cite", Html_cite, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
394 | { "code", Html_code, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
395 | { "dd", Html_dd, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
396 | { "dfn", Html_dfn, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
397 | { "div", Html_div, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
398 | { "dl", Html_dl, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
399 | { "dt", Html_dt, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
400 | { "em", Html_em, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
401 | { "font", Html_font, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
402 | { "h1", Html_h1, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
403 | { "h2", Html_h2, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
404 | { "h3", Html_h3, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
405 | { "h4", Html_h4, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
406 | { "h5", Html_h5, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
407 | { "h6", Html_h6, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
408 | { "head", Html_head, QTextHtmlElement::DisplayNone }, | - | ||||||||||||||||||
409 | { "hr", Html_hr, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
410 | { "html", Html_html, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
411 | { "i", Html_i, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
412 | { "img", Html_img, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
413 | { "kbd", Html_kbd, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
414 | { "li", Html_li, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
415 | { "link", Html_link, QTextHtmlElement::DisplayNone }, | - | ||||||||||||||||||
416 | { "meta", Html_meta, QTextHtmlElement::DisplayNone }, | - | ||||||||||||||||||
417 | { "nobr", Html_nobr, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
418 | { "ol", Html_ol, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
419 | { "p", Html_p, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
420 | { "pre", Html_pre, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
421 | { "qt", Html_body /*deliberate mapping*/, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
422 | { "s", Html_s, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
423 | { "samp", Html_samp, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
424 | { "script", Html_script, QTextHtmlElement::DisplayNone }, | - | ||||||||||||||||||
425 | { "small", Html_small, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
426 | { "span", Html_span, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
427 | { "strong", Html_strong, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
428 | { "style", Html_style, QTextHtmlElement::DisplayNone }, | - | ||||||||||||||||||
429 | { "sub", Html_sub, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
430 | { "sup", Html_sup, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
431 | { "table", Html_table, QTextHtmlElement::DisplayTable }, | - | ||||||||||||||||||
432 | { "tbody", Html_tbody, QTextHtmlElement::DisplayTable }, | - | ||||||||||||||||||
433 | { "td", Html_td, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
434 | { "tfoot", Html_tfoot, QTextHtmlElement::DisplayTable }, | - | ||||||||||||||||||
435 | { "th", Html_th, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
436 | { "thead", Html_thead, QTextHtmlElement::DisplayTable }, | - | ||||||||||||||||||
437 | { "title", Html_title, QTextHtmlElement::DisplayNone }, | - | ||||||||||||||||||
438 | { "tr", Html_tr, QTextHtmlElement::DisplayTable }, | - | ||||||||||||||||||
439 | { "tt", Html_tt, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
440 | { "u", Html_u, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
441 | { "ul", Html_ul, QTextHtmlElement::DisplayBlock }, | - | ||||||||||||||||||
442 | { "var", Html_var, QTextHtmlElement::DisplayInline }, | - | ||||||||||||||||||
443 | }; | - | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | #if defined(Q_CC_MSVC) && _MSC_VER < 1600 | - | ||||||||||||||||||
446 | static bool operator<(const QTextHtmlElement &e1, const QTextHtmlElement &e2) | - | ||||||||||||||||||
447 | { | - | ||||||||||||||||||
448 | return QLatin1String(e1.name) < QLatin1String(e2.name); | - | ||||||||||||||||||
449 | } | - | ||||||||||||||||||
450 | #endif | - | ||||||||||||||||||
451 | - | |||||||||||||||||||
452 | static bool operator<(const QString &str, const QTextHtmlElement &e) | - | ||||||||||||||||||
453 | { | - | ||||||||||||||||||
454 | return str < QLatin1String(e.name); never executed: return str < QLatin1String(e.name); | 0 | ||||||||||||||||||
455 | } | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | static bool operator<(const QTextHtmlElement &e, const QString &str) | - | ||||||||||||||||||
458 | { | - | ||||||||||||||||||
459 | return QLatin1String(e.name) < str; never executed: return QLatin1String(e.name) < str; | 0 | ||||||||||||||||||
460 | } | - | ||||||||||||||||||
461 | - | |||||||||||||||||||
462 | static const QTextHtmlElement *lookupElementHelper(const QString &element) | - | ||||||||||||||||||
463 | { | - | ||||||||||||||||||
464 | const QTextHtmlElement *start = &elements[0]; | - | ||||||||||||||||||
465 | const QTextHtmlElement *end = &elements[Html_NumElements]; | - | ||||||||||||||||||
466 | const QTextHtmlElement *e = std::lower_bound(start, end, element); | - | ||||||||||||||||||
467 | if ((e == end) || (element < *e))
| 0 | ||||||||||||||||||
468 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
469 | return e; never executed: return e; | 0 | ||||||||||||||||||
470 | } | - | ||||||||||||||||||
471 | - | |||||||||||||||||||
472 | int QTextHtmlParser::lookupElement(const QString &element) | - | ||||||||||||||||||
473 | { | - | ||||||||||||||||||
474 | const QTextHtmlElement *e = lookupElementHelper(element); | - | ||||||||||||||||||
475 | if (!e)
| 0 | ||||||||||||||||||
476 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
477 | return e->id; never executed: return e->id; | 0 | ||||||||||||||||||
478 | } | - | ||||||||||||||||||
479 | - | |||||||||||||||||||
480 | // quotes newlines as "\\n" | - | ||||||||||||||||||
481 | static QString quoteNewline(const QString &s) | - | ||||||||||||||||||
482 | { | - | ||||||||||||||||||
483 | QString n = s; | - | ||||||||||||||||||
484 | n.replace(QLatin1Char('\n'), QLatin1String("\\n")); | - | ||||||||||||||||||
485 | return n; never executed: return n; | 0 | ||||||||||||||||||
486 | } | - | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | QTextHtmlParserNode::QTextHtmlParserNode() | - | ||||||||||||||||||
489 | : parent(0), id(Html_unknown), | - | ||||||||||||||||||
490 | cssFloat(QTextFrameFormat::InFlow), hasOwnListStyle(false), | - | ||||||||||||||||||
491 | hasCssListIndent(false), isEmptyParagraph(false), isTextFrame(false), isRootFrame(false), | - | ||||||||||||||||||
492 | displayMode(QTextHtmlElement::DisplayInline), hasHref(false), | - | ||||||||||||||||||
493 | listStyle(QTextListFormat::ListStyleUndefined), imageWidth(-1), imageHeight(-1), tableBorder(0), | - | ||||||||||||||||||
494 | tableCellRowSpan(1), tableCellColSpan(1), tableCellSpacing(2), tableCellPadding(0), | - | ||||||||||||||||||
495 | borderBrush(Qt::darkGray), borderStyle(QTextFrameFormat::BorderStyle_Outset), | - | ||||||||||||||||||
496 | userState(-1), cssListIndent(0), wsm(WhiteSpaceModeUndefined) | - | ||||||||||||||||||
497 | { | - | ||||||||||||||||||
498 | margin[QTextHtmlParser::MarginLeft] = 0; | - | ||||||||||||||||||
499 | margin[QTextHtmlParser::MarginRight] = 0; | - | ||||||||||||||||||
500 | margin[QTextHtmlParser::MarginTop] = 0; | - | ||||||||||||||||||
501 | margin[QTextHtmlParser::MarginBottom] = 0; | - | ||||||||||||||||||
502 | } never executed: end of block | 0 | ||||||||||||||||||
503 | - | |||||||||||||||||||
504 | void QTextHtmlParser::dumpHtml() | - | ||||||||||||||||||
505 | { | - | ||||||||||||||||||
506 | for (int i = 0; i < count(); ++i) {
| 0 | ||||||||||||||||||
507 | qDebug().nospace() << qPrintable(QString(depth(i)*4, QLatin1Char(' '))) | - | ||||||||||||||||||
508 | << qPrintable(at(i).tag) << ':' | - | ||||||||||||||||||
509 | << quoteNewline(at(i).text); | - | ||||||||||||||||||
510 | ; | - | ||||||||||||||||||
511 | } never executed: end of block | 0 | ||||||||||||||||||
512 | } never executed: end of block | 0 | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | QTextHtmlParserNode *QTextHtmlParser::newNode(int parent) | - | ||||||||||||||||||
515 | { | - | ||||||||||||||||||
516 | QTextHtmlParserNode *lastNode = &nodes.last(); | - | ||||||||||||||||||
517 | QTextHtmlParserNode *newNode = 0; | - | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | bool reuseLastNode = true; | - | ||||||||||||||||||
520 | - | |||||||||||||||||||
521 | if (nodes.count() == 1) {
| 0 | ||||||||||||||||||
522 | reuseLastNode = false; | - | ||||||||||||||||||
523 | } else if (lastNode->tag.isEmpty()) { never executed: end of block
| 0 | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | if (lastNode->text.isEmpty()) {
| 0 | ||||||||||||||||||
526 | reuseLastNode = true; | - | ||||||||||||||||||
527 | } else { // last node is a text node (empty tag) with some text never executed: end of block | 0 | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | if (lastNode->text.length() == 1 && lastNode->text.at(0).isSpace()) {
| 0 | ||||||||||||||||||
530 | - | |||||||||||||||||||
531 | int lastSibling = count() - 2; | - | ||||||||||||||||||
532 | while (lastSibling
| 0 | ||||||||||||||||||
533 | && at(lastSibling).parent != lastNode->parent
| 0 | ||||||||||||||||||
534 | && at(lastSibling).displayMode == QTextHtmlElement::DisplayInline) {
| 0 | ||||||||||||||||||
535 | lastSibling = at(lastSibling).parent; | - | ||||||||||||||||||
536 | } never executed: end of block | 0 | ||||||||||||||||||
537 | - | |||||||||||||||||||
538 | if (at(lastSibling).displayMode == QTextHtmlElement::DisplayInline) {
| 0 | ||||||||||||||||||
539 | reuseLastNode = false; | - | ||||||||||||||||||
540 | } else { never executed: end of block | 0 | ||||||||||||||||||
541 | reuseLastNode = true; | - | ||||||||||||||||||
542 | } never executed: end of block | 0 | ||||||||||||||||||
543 | } else { | - | ||||||||||||||||||
544 | // text node with real (non-whitespace) text -> nothing to re-use | - | ||||||||||||||||||
545 | reuseLastNode = false; | - | ||||||||||||||||||
546 | } never executed: end of block | 0 | ||||||||||||||||||
547 | - | |||||||||||||||||||
548 | } | - | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | } else { | - | ||||||||||||||||||
551 | // last node had a proper tag -> nothing to re-use | - | ||||||||||||||||||
552 | reuseLastNode = false; | - | ||||||||||||||||||
553 | } never executed: end of block | 0 | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | if (reuseLastNode) {
| 0 | ||||||||||||||||||
556 | newNode = lastNode; | - | ||||||||||||||||||
557 | newNode->tag.clear(); | - | ||||||||||||||||||
558 | newNode->text.clear(); | - | ||||||||||||||||||
559 | newNode->id = Html_unknown; | - | ||||||||||||||||||
560 | } else { never executed: end of block | 0 | ||||||||||||||||||
561 | nodes.resize(nodes.size() + 1); | - | ||||||||||||||||||
562 | newNode = &nodes.last(); | - | ||||||||||||||||||
563 | } never executed: end of block | 0 | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | newNode->parent = parent; | - | ||||||||||||||||||
566 | return newNode; never executed: return newNode; | 0 | ||||||||||||||||||
567 | } | - | ||||||||||||||||||
568 | - | |||||||||||||||||||
569 | void QTextHtmlParser::parse(const QString &text, const QTextDocument *_resourceProvider) | - | ||||||||||||||||||
570 | { | - | ||||||||||||||||||
571 | nodes.clear(); | - | ||||||||||||||||||
572 | nodes.resize(1); | - | ||||||||||||||||||
573 | txt = text; | - | ||||||||||||||||||
574 | pos = 0; | - | ||||||||||||||||||
575 | len = txt.length(); | - | ||||||||||||||||||
576 | textEditMode = false; | - | ||||||||||||||||||
577 | resourceProvider = _resourceProvider; | - | ||||||||||||||||||
578 | parse(); | - | ||||||||||||||||||
579 | //dumpHtml(); | - | ||||||||||||||||||
580 | } never executed: end of block | 0 | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | int QTextHtmlParser::depth(int i) const | - | ||||||||||||||||||
583 | { | - | ||||||||||||||||||
584 | int depth = 0; | - | ||||||||||||||||||
585 | while (i) {
| 0 | ||||||||||||||||||
586 | i = at(i).parent; | - | ||||||||||||||||||
587 | ++depth; | - | ||||||||||||||||||
588 | } never executed: end of block | 0 | ||||||||||||||||||
589 | return depth; never executed: return depth; | 0 | ||||||||||||||||||
590 | } | - | ||||||||||||||||||
591 | - | |||||||||||||||||||
592 | int QTextHtmlParser::margin(int i, int mar) const { | - | ||||||||||||||||||
593 | int m = 0; | - | ||||||||||||||||||
594 | const QTextHtmlParserNode *node; | - | ||||||||||||||||||
595 | if (mar == MarginLeft
| 0 | ||||||||||||||||||
596 | || mar == MarginRight) {
| 0 | ||||||||||||||||||
597 | while (i) {
| 0 | ||||||||||||||||||
598 | node = &at(i); | - | ||||||||||||||||||
599 | if (!node->isBlock() && node->id != Html_table)
| 0 | ||||||||||||||||||
600 | break; never executed: break; | 0 | ||||||||||||||||||
601 | if (node->isTableCell())
| 0 | ||||||||||||||||||
602 | break; never executed: break; | 0 | ||||||||||||||||||
603 | m += node->margin[mar]; | - | ||||||||||||||||||
604 | i = node->parent; | - | ||||||||||||||||||
605 | } never executed: end of block | 0 | ||||||||||||||||||
606 | } never executed: end of block | 0 | ||||||||||||||||||
607 | return m; never executed: return m; | 0 | ||||||||||||||||||
608 | } | - | ||||||||||||||||||
609 | - | |||||||||||||||||||
610 | int QTextHtmlParser::topMargin(int i) const | - | ||||||||||||||||||
611 | { | - | ||||||||||||||||||
612 | if (!i)
| 0 | ||||||||||||||||||
613 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
614 | return at(i).margin[MarginTop]; never executed: return at(i).margin[MarginTop]; | 0 | ||||||||||||||||||
615 | } | - | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | int QTextHtmlParser::bottomMargin(int i) const | - | ||||||||||||||||||
618 | { | - | ||||||||||||||||||
619 | if (!i)
| 0 | ||||||||||||||||||
620 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
621 | return at(i).margin[MarginBottom]; never executed: return at(i).margin[MarginBottom]; | 0 | ||||||||||||||||||
622 | } | - | ||||||||||||||||||
623 | - | |||||||||||||||||||
624 | void QTextHtmlParser::eatSpace() | - | ||||||||||||||||||
625 | { | - | ||||||||||||||||||
626 | while (pos < len && txt.at(pos).isSpace() && txt.at(pos) != QChar::ParagraphSeparator)
| 0 | ||||||||||||||||||
627 | pos++; never executed: pos++; | 0 | ||||||||||||||||||
628 | } never executed: end of block | 0 | ||||||||||||||||||
629 | - | |||||||||||||||||||
630 | void QTextHtmlParser::parse() | - | ||||||||||||||||||
631 | { | - | ||||||||||||||||||
632 | while (pos < len) {
| 0 | ||||||||||||||||||
633 | QChar c = txt.at(pos++); | - | ||||||||||||||||||
634 | if (c == QLatin1Char('<')) {
| 0 | ||||||||||||||||||
635 | parseTag(); | - | ||||||||||||||||||
636 | } else if (c == QLatin1Char('&')) { never executed: end of block
| 0 | ||||||||||||||||||
637 | nodes.last().text += parseEntity(); | - | ||||||||||||||||||
638 | } else { never executed: end of block | 0 | ||||||||||||||||||
639 | nodes.last().text += c; | - | ||||||||||||||||||
640 | } never executed: end of block | 0 | ||||||||||||||||||
641 | } | - | ||||||||||||||||||
642 | } never executed: end of block | 0 | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | // parses a tag after "<" | - | ||||||||||||||||||
645 | void QTextHtmlParser::parseTag() | - | ||||||||||||||||||
646 | { | - | ||||||||||||||||||
647 | eatSpace(); | - | ||||||||||||||||||
648 | - | |||||||||||||||||||
649 | // handle comments and other exclamation mark declarations | - | ||||||||||||||||||
650 | if (hasPrefix(QLatin1Char('!'))) {
| 0 | ||||||||||||||||||
651 | parseExclamationTag(); | - | ||||||||||||||||||
652 | if (nodes.last().wsm != QTextHtmlParserNode::WhiteSpacePre
| 0 | ||||||||||||||||||
653 | && nodes.last().wsm != QTextHtmlParserNode::WhiteSpacePreWrap
| 0 | ||||||||||||||||||
654 | && !textEditMode)
| 0 | ||||||||||||||||||
655 | eatSpace(); never executed: eatSpace(); | 0 | ||||||||||||||||||
656 | return; never executed: return; | 0 | ||||||||||||||||||
657 | } | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | // if close tag just close | - | ||||||||||||||||||
660 | if (hasPrefix(QLatin1Char('/'))) {
| 0 | ||||||||||||||||||
661 | if (nodes.last().id == Html_style) {
| 0 | ||||||||||||||||||
662 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
663 | QCss::Parser parser(nodes.last().text); | - | ||||||||||||||||||
664 | QCss::StyleSheet sheet; | - | ||||||||||||||||||
665 | sheet.origin = QCss::StyleSheetOrigin_Author; | - | ||||||||||||||||||
666 | parser.parse(&sheet, Qt::CaseInsensitive); | - | ||||||||||||||||||
667 | inlineStyleSheets.append(sheet); | - | ||||||||||||||||||
668 | resolveStyleSheetImports(sheet); | - | ||||||||||||||||||
669 | #endif | - | ||||||||||||||||||
670 | } never executed: end of block | 0 | ||||||||||||||||||
671 | parseCloseTag(); | - | ||||||||||||||||||
672 | return; never executed: return; | 0 | ||||||||||||||||||
673 | } | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | int p = last(); | - | ||||||||||||||||||
676 | while (p && at(p).tag.size() == 0)
| 0 | ||||||||||||||||||
677 | p = at(p).parent; never executed: p = at(p).parent; | 0 | ||||||||||||||||||
678 | - | |||||||||||||||||||
679 | QTextHtmlParserNode *node = newNode(p); | - | ||||||||||||||||||
680 | - | |||||||||||||||||||
681 | // parse tag name | - | ||||||||||||||||||
682 | node->tag = parseWord().toLower(); | - | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | const QTextHtmlElement *elem = lookupElementHelper(node->tag); | - | ||||||||||||||||||
685 | if (elem) {
| 0 | ||||||||||||||||||
686 | node->id = elem->id; | - | ||||||||||||||||||
687 | node->displayMode = elem->displayMode; | - | ||||||||||||||||||
688 | } else { never executed: end of block | 0 | ||||||||||||||||||
689 | node->id = Html_unknown; | - | ||||||||||||||||||
690 | } never executed: end of block | 0 | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | node->attributes.clear(); | - | ||||||||||||||||||
693 | // _need_ at least one space after the tag name, otherwise there can't be attributes | - | ||||||||||||||||||
694 | if (pos < len && txt.at(pos).isSpace())
| 0 | ||||||||||||||||||
695 | node->attributes = parseAttributes(); never executed: node->attributes = parseAttributes(); | 0 | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | // resolveParent() may have to change the order in the tree and | - | ||||||||||||||||||
698 | // insert intermediate nodes for buggy HTML, so re-initialize the 'node' | - | ||||||||||||||||||
699 | // pointer through the return value | - | ||||||||||||||||||
700 | node = resolveParent(); | - | ||||||||||||||||||
701 | resolveNode(); | - | ||||||||||||||||||
702 | - | |||||||||||||||||||
703 | const int nodeIndex = nodes.count() - 1; // this new node is always the last | - | ||||||||||||||||||
704 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
705 | node->applyCssDeclarations(declarationsForNode(nodeIndex), resourceProvider); | - | ||||||||||||||||||
706 | #endif | - | ||||||||||||||||||
707 | applyAttributes(node->attributes); | - | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | // finish tag | - | ||||||||||||||||||
710 | bool tagClosed = false; | - | ||||||||||||||||||
711 | while (pos < len && txt.at(pos) != QLatin1Char('>')) {
| 0 | ||||||||||||||||||
712 | if (txt.at(pos) == QLatin1Char('/'))
| 0 | ||||||||||||||||||
713 | tagClosed = true; never executed: tagClosed = true; | 0 | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | pos++; | - | ||||||||||||||||||
716 | } never executed: end of block | 0 | ||||||||||||||||||
717 | pos++; | - | ||||||||||||||||||
718 | - | |||||||||||||||||||
719 | // in a white-space preserving environment strip off a initial newline | - | ||||||||||||||||||
720 | // since the element itself already generates a newline | - | ||||||||||||||||||
721 | if ((node->wsm == QTextHtmlParserNode::WhiteSpacePre
| 0 | ||||||||||||||||||
722 | || node->wsm == QTextHtmlParserNode::WhiteSpacePreWrap)
| 0 | ||||||||||||||||||
723 | && node->isBlock()) {
| 0 | ||||||||||||||||||
724 | if (pos < len - 1 && txt.at(pos) == QLatin1Char('\n'))
| 0 | ||||||||||||||||||
725 | ++pos; never executed: ++pos; | 0 | ||||||||||||||||||
726 | } never executed: end of block | 0 | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | if (node->mayNotHaveChildren() || tagClosed) {
| 0 | ||||||||||||||||||
729 | newNode(node->parent); | - | ||||||||||||||||||
730 | resolveNode(); | - | ||||||||||||||||||
731 | } never executed: end of block | 0 | ||||||||||||||||||
732 | } never executed: end of block | 0 | ||||||||||||||||||
733 | - | |||||||||||||||||||
734 | // parses a tag beginning with "/" | - | ||||||||||||||||||
735 | void QTextHtmlParser::parseCloseTag() | - | ||||||||||||||||||
736 | { | - | ||||||||||||||||||
737 | ++pos; | - | ||||||||||||||||||
738 | QString tag = parseWord().toLower().trimmed(); | - | ||||||||||||||||||
739 | while (pos < len) {
| 0 | ||||||||||||||||||
740 | QChar c = txt.at(pos++); | - | ||||||||||||||||||
741 | if (c == QLatin1Char('>'))
| 0 | ||||||||||||||||||
742 | break; never executed: break; | 0 | ||||||||||||||||||
743 | } never executed: end of block | 0 | ||||||||||||||||||
744 | - | |||||||||||||||||||
745 | // find corresponding open node | - | ||||||||||||||||||
746 | int p = last(); | - | ||||||||||||||||||
747 | if (p > 0
| 0 | ||||||||||||||||||
748 | && at(p - 1).tag == tag
| 0 | ||||||||||||||||||
749 | && at(p - 1).mayNotHaveChildren())
| 0 | ||||||||||||||||||
750 | p--; never executed: p--; | 0 | ||||||||||||||||||
751 | - | |||||||||||||||||||
752 | while (p && at(p).tag != tag)
| 0 | ||||||||||||||||||
753 | p = at(p).parent; never executed: p = at(p).parent; | 0 | ||||||||||||||||||
754 | - | |||||||||||||||||||
755 | // simply ignore the tag if we can't find | - | ||||||||||||||||||
756 | // a corresponding open node, for broken | - | ||||||||||||||||||
757 | // html such as <font>blah</font></font> | - | ||||||||||||||||||
758 | if (!p)
| 0 | ||||||||||||||||||
759 | return; never executed: return; | 0 | ||||||||||||||||||
760 | - | |||||||||||||||||||
761 | // in a white-space preserving environment strip off a trailing newline | - | ||||||||||||||||||
762 | // since the closing of the opening block element will automatically result | - | ||||||||||||||||||
763 | // in a new block for elements following the <pre> | - | ||||||||||||||||||
764 | // ...foo\n</pre><p>blah -> foo</pre><p>blah | - | ||||||||||||||||||
765 | if ((at(p).wsm == QTextHtmlParserNode::WhiteSpacePre
| 0 | ||||||||||||||||||
766 | || at(p).wsm == QTextHtmlParserNode::WhiteSpacePreWrap)
| 0 | ||||||||||||||||||
767 | && at(p).isBlock()) {
| 0 | ||||||||||||||||||
768 | if (at(last()).text.endsWith(QLatin1Char('\n')))
| 0 | ||||||||||||||||||
769 | nodes[last()].text.chop(1); never executed: nodes[last()].text.chop(1); | 0 | ||||||||||||||||||
770 | } never executed: end of block | 0 | ||||||||||||||||||
771 | - | |||||||||||||||||||
772 | newNode(at(p).parent); | - | ||||||||||||||||||
773 | resolveNode(); | - | ||||||||||||||||||
774 | } never executed: end of block | 0 | ||||||||||||||||||
775 | - | |||||||||||||||||||
776 | // parses a tag beginning with "!" | - | ||||||||||||||||||
777 | void QTextHtmlParser::parseExclamationTag() | - | ||||||||||||||||||
778 | { | - | ||||||||||||||||||
779 | ++pos; | - | ||||||||||||||||||
780 | if (hasPrefix(QLatin1Char('-'),1) && hasPrefix(QLatin1Char('-'),2)) {
| 0 | ||||||||||||||||||
781 | pos += 3; | - | ||||||||||||||||||
782 | // eat comments | - | ||||||||||||||||||
783 | int end = txt.indexOf(QLatin1String("-->"), pos); | - | ||||||||||||||||||
784 | pos = (end >= 0 ? end + 3 : len);
| 0 | ||||||||||||||||||
785 | } else { never executed: end of block | 0 | ||||||||||||||||||
786 | // eat internal tags | - | ||||||||||||||||||
787 | while (pos < len) {
| 0 | ||||||||||||||||||
788 | QChar c = txt.at(pos++); | - | ||||||||||||||||||
789 | if (c == QLatin1Char('>'))
| 0 | ||||||||||||||||||
790 | break; never executed: break; | 0 | ||||||||||||||||||
791 | } never executed: end of block | 0 | ||||||||||||||||||
792 | } never executed: end of block | 0 | ||||||||||||||||||
793 | } | - | ||||||||||||||||||
794 | - | |||||||||||||||||||
795 | // parses an entity after "&", and returns it | - | ||||||||||||||||||
796 | QString QTextHtmlParser::parseEntity() | - | ||||||||||||||||||
797 | { | - | ||||||||||||||||||
798 | int recover = pos; | - | ||||||||||||||||||
799 | QString entity; | - | ||||||||||||||||||
800 | while (pos < len) {
| 0 | ||||||||||||||||||
801 | QChar c = txt.at(pos++); | - | ||||||||||||||||||
802 | if (c.isSpace() || pos - recover > 9) {
| 0 | ||||||||||||||||||
803 | goto error; never executed: goto error; | 0 | ||||||||||||||||||
804 | } | - | ||||||||||||||||||
805 | if (c == QLatin1Char(';'))
| 0 | ||||||||||||||||||
806 | break; never executed: break; | 0 | ||||||||||||||||||
807 | entity += c; | - | ||||||||||||||||||
808 | } never executed: end of block | 0 | ||||||||||||||||||
809 | { | - | ||||||||||||||||||
810 | QChar resolved = resolveEntity(entity); | - | ||||||||||||||||||
811 | if (!resolved.isNull())
| 0 | ||||||||||||||||||
812 | return QString(resolved); never executed: return QString(resolved); | 0 | ||||||||||||||||||
813 | } | - | ||||||||||||||||||
814 | if (entity.length() > 1 && entity.at(0) == QLatin1Char('#')) {
| 0 | ||||||||||||||||||
815 | entity.remove(0, 1); // removing leading # | - | ||||||||||||||||||
816 | - | |||||||||||||||||||
817 | int base = 10; | - | ||||||||||||||||||
818 | bool ok = false; | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | if (entity.at(0).toLower() == QLatin1Char('x')) { // hex entity?
| 0 | ||||||||||||||||||
821 | entity.remove(0, 1); | - | ||||||||||||||||||
822 | base = 16; | - | ||||||||||||||||||
823 | } never executed: end of block | 0 | ||||||||||||||||||
824 | - | |||||||||||||||||||
825 | uint uc = entity.toUInt(&ok, base); | - | ||||||||||||||||||
826 | if (ok) {
| 0 | ||||||||||||||||||
827 | if (uc >= 0x80 && uc < 0x80 + (sizeof(windowsLatin1ExtendedCharacters)/sizeof(windowsLatin1ExtendedCharacters[0])))
| 0 | ||||||||||||||||||
828 | uc = windowsLatin1ExtendedCharacters[uc - 0x80]; never executed: uc = windowsLatin1ExtendedCharacters[uc - 0x80]; | 0 | ||||||||||||||||||
829 | QString str; | - | ||||||||||||||||||
830 | if (QChar::requiresSurrogates(uc)) {
| 0 | ||||||||||||||||||
831 | str += QChar(QChar::highSurrogate(uc)); | - | ||||||||||||||||||
832 | str += QChar(QChar::lowSurrogate(uc)); | - | ||||||||||||||||||
833 | } else { never executed: end of block | 0 | ||||||||||||||||||
834 | str = QChar(uc); | - | ||||||||||||||||||
835 | } never executed: end of block | 0 | ||||||||||||||||||
836 | return str; never executed: return str; | 0 | ||||||||||||||||||
837 | } | - | ||||||||||||||||||
838 | } never executed: end of block | 0 | ||||||||||||||||||
839 | error: code before this statement never executed: error: | 0 | ||||||||||||||||||
840 | pos = recover; | - | ||||||||||||||||||
841 | return QLatin1String("&"); never executed: return QLatin1String("&"); | 0 | ||||||||||||||||||
842 | } | - | ||||||||||||||||||
843 | - | |||||||||||||||||||
844 | // parses one word, possibly quoted, and returns it | - | ||||||||||||||||||
845 | QString QTextHtmlParser::parseWord() | - | ||||||||||||||||||
846 | { | - | ||||||||||||||||||
847 | QString word; | - | ||||||||||||||||||
848 | if (hasPrefix(QLatin1Char('\"'))) { // double quotes
| 0 | ||||||||||||||||||
849 | ++pos; | - | ||||||||||||||||||
850 | while (pos < len) {
| 0 | ||||||||||||||||||
851 | QChar c = txt.at(pos++); | - | ||||||||||||||||||
852 | if (c == QLatin1Char('\"'))
| 0 | ||||||||||||||||||
853 | break; never executed: break; | 0 | ||||||||||||||||||
854 | else if (c == QLatin1Char('&'))
| 0 | ||||||||||||||||||
855 | word += parseEntity(); never executed: word += parseEntity(); | 0 | ||||||||||||||||||
856 | else | - | ||||||||||||||||||
857 | word += c; never executed: word += c; | 0 | ||||||||||||||||||
858 | } | - | ||||||||||||||||||
859 | } else if (hasPrefix(QLatin1Char('\''))) { // single quotes never executed: end of block
| 0 | ||||||||||||||||||
860 | ++pos; | - | ||||||||||||||||||
861 | while (pos < len) {
| 0 | ||||||||||||||||||
862 | QChar c = txt.at(pos++); | - | ||||||||||||||||||
863 | if (c == QLatin1Char('\''))
| 0 | ||||||||||||||||||
864 | break; never executed: break; | 0 | ||||||||||||||||||
865 | else | - | ||||||||||||||||||
866 | word += c; never executed: word += c; | 0 | ||||||||||||||||||
867 | } | - | ||||||||||||||||||
868 | } else { // normal text never executed: end of block | 0 | ||||||||||||||||||
869 | while (pos < len) {
| 0 | ||||||||||||||||||
870 | QChar c = txt.at(pos++); | - | ||||||||||||||||||
871 | if (c == QLatin1Char('>')
| 0 | ||||||||||||||||||
872 | || (c == QLatin1Char('/') && hasPrefix(QLatin1Char('>'), 1))
| 0 | ||||||||||||||||||
873 | || c == QLatin1Char('<')
| 0 | ||||||||||||||||||
874 | || c == QLatin1Char('=')
| 0 | ||||||||||||||||||
875 | || c.isSpace()) {
| 0 | ||||||||||||||||||
876 | --pos; | - | ||||||||||||||||||
877 | break; never executed: break; | 0 | ||||||||||||||||||
878 | } | - | ||||||||||||||||||
879 | if (c == QLatin1Char('&'))
| 0 | ||||||||||||||||||
880 | word += parseEntity(); never executed: word += parseEntity(); | 0 | ||||||||||||||||||
881 | else | - | ||||||||||||||||||
882 | word += c; never executed: word += c; | 0 | ||||||||||||||||||
883 | } | - | ||||||||||||||||||
884 | } never executed: end of block | 0 | ||||||||||||||||||
885 | return word; never executed: return word; | 0 | ||||||||||||||||||
886 | } | - | ||||||||||||||||||
887 | - | |||||||||||||||||||
888 | // gives the new node the right parent | - | ||||||||||||||||||
889 | QTextHtmlParserNode *QTextHtmlParser::resolveParent() | - | ||||||||||||||||||
890 | { | - | ||||||||||||||||||
891 | QTextHtmlParserNode *node = &nodes.last(); | - | ||||||||||||||||||
892 | - | |||||||||||||||||||
893 | int p = node->parent; | - | ||||||||||||||||||
894 | - | |||||||||||||||||||
895 | // Excel gives us buggy HTML with just tr without surrounding table tags | - | ||||||||||||||||||
896 | // or with just td tags | - | ||||||||||||||||||
897 | - | |||||||||||||||||||
898 | if (node->id == Html_td) {
| 0 | ||||||||||||||||||
899 | int n = p; | - | ||||||||||||||||||
900 | while (n && at(n).id != Html_tr)
| 0 | ||||||||||||||||||
901 | n = at(n).parent; never executed: n = at(n).parent; | 0 | ||||||||||||||||||
902 | - | |||||||||||||||||||
903 | if (!n) {
| 0 | ||||||||||||||||||
904 | nodes.insert(nodes.count() - 1, QTextHtmlParserNode()); | - | ||||||||||||||||||
905 | nodes.insert(nodes.count() - 1, QTextHtmlParserNode()); | - | ||||||||||||||||||
906 | - | |||||||||||||||||||
907 | QTextHtmlParserNode *table = &nodes[nodes.count() - 3]; | - | ||||||||||||||||||
908 | table->parent = p; | - | ||||||||||||||||||
909 | table->id = Html_table; | - | ||||||||||||||||||
910 | table->tag = QLatin1String("table"); | - | ||||||||||||||||||
911 | table->children.append(nodes.count() - 2); // add row as child | - | ||||||||||||||||||
912 | - | |||||||||||||||||||
913 | QTextHtmlParserNode *row = &nodes[nodes.count() - 2]; | - | ||||||||||||||||||
914 | row->parent = nodes.count() - 3; // table as parent | - | ||||||||||||||||||
915 | row->id = Html_tr; | - | ||||||||||||||||||
916 | row->tag = QLatin1String("tr"); | - | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | p = nodes.count() - 2; | - | ||||||||||||||||||
919 | node = &nodes.last(); // re-initialize pointer | - | ||||||||||||||||||
920 | } never executed: end of block | 0 | ||||||||||||||||||
921 | } never executed: end of block | 0 | ||||||||||||||||||
922 | - | |||||||||||||||||||
923 | if (node->id == Html_tr) {
| 0 | ||||||||||||||||||
924 | int n = p; | - | ||||||||||||||||||
925 | while (n && at(n).id != Html_table)
| 0 | ||||||||||||||||||
926 | n = at(n).parent; never executed: n = at(n).parent; | 0 | ||||||||||||||||||
927 | - | |||||||||||||||||||
928 | if (!n) {
| 0 | ||||||||||||||||||
929 | nodes.insert(nodes.count() - 1, QTextHtmlParserNode()); | - | ||||||||||||||||||
930 | QTextHtmlParserNode *table = &nodes[nodes.count() - 2]; | - | ||||||||||||||||||
931 | table->parent = p; | - | ||||||||||||||||||
932 | table->id = Html_table; | - | ||||||||||||||||||
933 | table->tag = QLatin1String("table"); | - | ||||||||||||||||||
934 | p = nodes.count() - 2; | - | ||||||||||||||||||
935 | node = &nodes.last(); // re-initialize pointer | - | ||||||||||||||||||
936 | } never executed: end of block | 0 | ||||||||||||||||||
937 | } never executed: end of block | 0 | ||||||||||||||||||
938 | - | |||||||||||||||||||
939 | // permit invalid html by letting block elements be children | - | ||||||||||||||||||
940 | // of inline elements with the exception of paragraphs: | - | ||||||||||||||||||
941 | // | - | ||||||||||||||||||
942 | // a new paragraph closes parent inline elements (while loop), | - | ||||||||||||||||||
943 | // unless they themselves are children of a non-paragraph block | - | ||||||||||||||||||
944 | // element (if statement) | - | ||||||||||||||||||
945 | // | - | ||||||||||||||||||
946 | // For example: | - | ||||||||||||||||||
947 | // | - | ||||||||||||||||||
948 | // <body><p><b>Foo<p>Bar <-- second <p> implicitly closes <b> that | - | ||||||||||||||||||
949 | // belongs to the first <p>. The self-nesting | - | ||||||||||||||||||
950 | // check further down prevents the second <p> | - | ||||||||||||||||||
951 | // from nesting into the first one then. | - | ||||||||||||||||||
952 | // so Bar is not bold. | - | ||||||||||||||||||
953 | // | - | ||||||||||||||||||
954 | // <body><b><p>Foo <-- Foo should be bold. | - | ||||||||||||||||||
955 | // | - | ||||||||||||||||||
956 | // <body><b><p>Foo<p>Bar <-- Foo and Bar should be bold. | - | ||||||||||||||||||
957 | // | - | ||||||||||||||||||
958 | if (node->id == Html_p) {
| 0 | ||||||||||||||||||
959 | while (p && !at(p).isBlock())
| 0 | ||||||||||||||||||
960 | p = at(p).parent; never executed: p = at(p).parent; | 0 | ||||||||||||||||||
961 | - | |||||||||||||||||||
962 | if (!p || at(p).id != Html_p)
| 0 | ||||||||||||||||||
963 | p = node->parent; never executed: p = node->parent; | 0 | ||||||||||||||||||
964 | } never executed: end of block | 0 | ||||||||||||||||||
965 | - | |||||||||||||||||||
966 | // some elements are not self nesting | - | ||||||||||||||||||
967 | if (node->id == at(p).id
| 0 | ||||||||||||||||||
968 | && node->isNotSelfNesting())
| 0 | ||||||||||||||||||
969 | p = at(p).parent; never executed: p = at(p).parent; | 0 | ||||||||||||||||||
970 | - | |||||||||||||||||||
971 | // some elements are not allowed in certain contexts | - | ||||||||||||||||||
972 | while ((p && !node->allowedInContext(at(p).id))
| 0 | ||||||||||||||||||
973 | // ### make new styles aware of empty tags | - | ||||||||||||||||||
974 | || at(p).mayNotHaveChildren()
| 0 | ||||||||||||||||||
975 | ) { | - | ||||||||||||||||||
976 | p = at(p).parent; | - | ||||||||||||||||||
977 | } never executed: end of block | 0 | ||||||||||||||||||
978 | - | |||||||||||||||||||
979 | node->parent = p; | - | ||||||||||||||||||
980 | - | |||||||||||||||||||
981 | // makes it easier to traverse the tree, later | - | ||||||||||||||||||
982 | nodes[p].children.append(nodes.count() - 1); | - | ||||||||||||||||||
983 | return node; never executed: return node; | 0 | ||||||||||||||||||
984 | } | - | ||||||||||||||||||
985 | - | |||||||||||||||||||
986 | // sets all properties on the new node | - | ||||||||||||||||||
987 | void QTextHtmlParser::resolveNode() | - | ||||||||||||||||||
988 | { | - | ||||||||||||||||||
989 | QTextHtmlParserNode *node = &nodes.last(); | - | ||||||||||||||||||
990 | const QTextHtmlParserNode *parent = &nodes.at(node->parent); | - | ||||||||||||||||||
991 | node->initializeProperties(parent, this); | - | ||||||||||||||||||
992 | } never executed: end of block | 0 | ||||||||||||||||||
993 | - | |||||||||||||||||||
994 | bool QTextHtmlParserNode::isNestedList(const QTextHtmlParser *parser) const | - | ||||||||||||||||||
995 | { | - | ||||||||||||||||||
996 | if (!isListStart())
| 0 | ||||||||||||||||||
997 | return false; never executed: return false; | 0 | ||||||||||||||||||
998 | - | |||||||||||||||||||
999 | int p = parent; | - | ||||||||||||||||||
1000 | while (p) {
| 0 | ||||||||||||||||||
1001 | if (parser->at(p).isListStart())
| 0 | ||||||||||||||||||
1002 | return true; never executed: return true; | 0 | ||||||||||||||||||
1003 | p = parser->at(p).parent; | - | ||||||||||||||||||
1004 | } never executed: end of block | 0 | ||||||||||||||||||
1005 | return false; never executed: return false; | 0 | ||||||||||||||||||
1006 | } | - | ||||||||||||||||||
1007 | - | |||||||||||||||||||
1008 | void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent, const QTextHtmlParser *parser) | - | ||||||||||||||||||
1009 | { | - | ||||||||||||||||||
1010 | // inherit properties from parent element | - | ||||||||||||||||||
1011 | charFormat = parent->charFormat; | - | ||||||||||||||||||
1012 | - | |||||||||||||||||||
1013 | if (id == Html_html)
| 0 | ||||||||||||||||||
1014 | blockFormat.setLayoutDirection(Qt::LeftToRight); // HTML default never executed: blockFormat.setLayoutDirection(Qt::LeftToRight); | 0 | ||||||||||||||||||
1015 | else if (parent->blockFormat.hasProperty(QTextFormat::LayoutDirection))
| 0 | ||||||||||||||||||
1016 | blockFormat.setLayoutDirection(parent->blockFormat.layoutDirection()); never executed: blockFormat.setLayoutDirection(parent->blockFormat.layoutDirection()); | 0 | ||||||||||||||||||
1017 | - | |||||||||||||||||||
1018 | if (parent->displayMode == QTextHtmlElement::DisplayNone)
| 0 | ||||||||||||||||||
1019 | displayMode = QTextHtmlElement::DisplayNone; never executed: displayMode = QTextHtmlElement::DisplayNone; | 0 | ||||||||||||||||||
1020 | - | |||||||||||||||||||
1021 | if (parent->id != Html_table || id == Html_caption) {
| 0 | ||||||||||||||||||
1022 | if (parent->blockFormat.hasProperty(QTextFormat::BlockAlignment))
| 0 | ||||||||||||||||||
1023 | blockFormat.setAlignment(parent->blockFormat.alignment()); never executed: blockFormat.setAlignment(parent->blockFormat.alignment()); | 0 | ||||||||||||||||||
1024 | else | - | ||||||||||||||||||
1025 | blockFormat.clearProperty(QTextFormat::BlockAlignment); never executed: blockFormat.clearProperty(QTextFormat::BlockAlignment); | 0 | ||||||||||||||||||
1026 | } | - | ||||||||||||||||||
1027 | // we don't paint per-row background colors, yet. so as an | - | ||||||||||||||||||
1028 | // exception inherit the background color here | - | ||||||||||||||||||
1029 | // we also inherit the background between inline elements | - | ||||||||||||||||||
1030 | if ((parent->id != Html_tr || !isTableCell())
| 0 | ||||||||||||||||||
1031 | && (displayMode != QTextHtmlElement::DisplayInline || parent->displayMode != QTextHtmlElement::DisplayInline)) {
| 0 | ||||||||||||||||||
1032 | charFormat.clearProperty(QTextFormat::BackgroundBrush); | - | ||||||||||||||||||
1033 | } never executed: end of block | 0 | ||||||||||||||||||
1034 | - | |||||||||||||||||||
1035 | listStyle = parent->listStyle; | - | ||||||||||||||||||
1036 | // makes no sense to inherit that property, a named anchor is a single point | - | ||||||||||||||||||
1037 | // in the document, which is set by the DocumentFragment | - | ||||||||||||||||||
1038 | charFormat.clearProperty(QTextFormat::AnchorName); | - | ||||||||||||||||||
1039 | wsm = parent->wsm; | - | ||||||||||||||||||
1040 | - | |||||||||||||||||||
1041 | // initialize remaining properties | - | ||||||||||||||||||
1042 | margin[QTextHtmlParser::MarginLeft] = 0; | - | ||||||||||||||||||
1043 | margin[QTextHtmlParser::MarginRight] = 0; | - | ||||||||||||||||||
1044 | margin[QTextHtmlParser::MarginTop] = 0; | - | ||||||||||||||||||
1045 | margin[QTextHtmlParser::MarginBottom] = 0; | - | ||||||||||||||||||
1046 | cssFloat = QTextFrameFormat::InFlow; | - | ||||||||||||||||||
1047 | - | |||||||||||||||||||
1048 | for (int i = 0; i < 4; ++i)
| 0 | ||||||||||||||||||
1049 | padding[i] = -1; never executed: padding[i] = -1; | 0 | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | // set element specific attributes | - | ||||||||||||||||||
1052 | switch (id) { | - | ||||||||||||||||||
1053 | case Html_a: never executed: case Html_a: | 0 | ||||||||||||||||||
1054 | for (int i = 0; i < attributes.count(); i += 2) {
| 0 | ||||||||||||||||||
1055 | const QString key = attributes.at(i); | - | ||||||||||||||||||
1056 | if (key.compare(QLatin1String("href"), Qt::CaseInsensitive) == 0
| 0 | ||||||||||||||||||
1057 | && !attributes.at(i + 1).isEmpty()) {
| 0 | ||||||||||||||||||
1058 | hasHref = true; | - | ||||||||||||||||||
1059 | } never executed: end of block | 0 | ||||||||||||||||||
1060 | } never executed: end of block | 0 | ||||||||||||||||||
1061 | charFormat.setAnchor(true); | - | ||||||||||||||||||
1062 | break; never executed: break; | 0 | ||||||||||||||||||
1063 | case Html_big: never executed: case Html_big: | 0 | ||||||||||||||||||
1064 | charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(1)); | - | ||||||||||||||||||
1065 | break; never executed: break; | 0 | ||||||||||||||||||
1066 | case Html_small: never executed: case Html_small: | 0 | ||||||||||||||||||
1067 | charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(-1)); | - | ||||||||||||||||||
1068 | break; never executed: break; | 0 | ||||||||||||||||||
1069 | case Html_h1: never executed: case Html_h1: | 0 | ||||||||||||||||||
1070 | charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(3)); | - | ||||||||||||||||||
1071 | margin[QTextHtmlParser::MarginTop] = 18; | - | ||||||||||||||||||
1072 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1073 | break; never executed: break; | 0 | ||||||||||||||||||
1074 | case Html_h2: never executed: case Html_h2: | 0 | ||||||||||||||||||
1075 | charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(2)); | - | ||||||||||||||||||
1076 | margin[QTextHtmlParser::MarginTop] = 16; | - | ||||||||||||||||||
1077 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1078 | break; never executed: break; | 0 | ||||||||||||||||||
1079 | case Html_h3: never executed: case Html_h3: | 0 | ||||||||||||||||||
1080 | charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(1)); | - | ||||||||||||||||||
1081 | margin[QTextHtmlParser::MarginTop] = 14; | - | ||||||||||||||||||
1082 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1083 | break; never executed: break; | 0 | ||||||||||||||||||
1084 | case Html_h4: never executed: case Html_h4: | 0 | ||||||||||||||||||
1085 | charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(0)); | - | ||||||||||||||||||
1086 | margin[QTextHtmlParser::MarginTop] = 12; | - | ||||||||||||||||||
1087 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1088 | break; never executed: break; | 0 | ||||||||||||||||||
1089 | case Html_h5: never executed: case Html_h5: | 0 | ||||||||||||||||||
1090 | charFormat.setProperty(QTextFormat::FontSizeAdjustment, int(-1)); | - | ||||||||||||||||||
1091 | margin[QTextHtmlParser::MarginTop] = 12; | - | ||||||||||||||||||
1092 | margin[QTextHtmlParser::MarginBottom] = 4; | - | ||||||||||||||||||
1093 | break; never executed: break; | 0 | ||||||||||||||||||
1094 | case Html_p: never executed: case Html_p: | 0 | ||||||||||||||||||
1095 | margin[QTextHtmlParser::MarginTop] = 12; | - | ||||||||||||||||||
1096 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1097 | break; never executed: break; | 0 | ||||||||||||||||||
1098 | case Html_ul: never executed: case Html_ul: | 0 | ||||||||||||||||||
1099 | // nested lists don't have margins, except for the toplevel one | - | ||||||||||||||||||
1100 | if (!isNestedList(parser)) {
| 0 | ||||||||||||||||||
1101 | margin[QTextHtmlParser::MarginTop] = 12; | - | ||||||||||||||||||
1102 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1103 | } never executed: end of block | 0 | ||||||||||||||||||
1104 | // no left margin as we use indenting instead | - | ||||||||||||||||||
1105 | break; never executed: break; | 0 | ||||||||||||||||||
1106 | case Html_ol: never executed: case Html_ol: | 0 | ||||||||||||||||||
1107 | // nested lists don't have margins, except for the toplevel one | - | ||||||||||||||||||
1108 | if (!isNestedList(parser)) {
| 0 | ||||||||||||||||||
1109 | margin[QTextHtmlParser::MarginTop] = 12; | - | ||||||||||||||||||
1110 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1111 | } never executed: end of block | 0 | ||||||||||||||||||
1112 | // no left margin as we use indenting instead | - | ||||||||||||||||||
1113 | break; never executed: break; | 0 | ||||||||||||||||||
1114 | case Html_br: never executed: case Html_br: | 0 | ||||||||||||||||||
1115 | text = QChar(QChar::LineSeparator); | - | ||||||||||||||||||
1116 | break; never executed: break; | 0 | ||||||||||||||||||
1117 | case Html_pre: never executed: case Html_pre: | 0 | ||||||||||||||||||
1118 | margin[QTextHtmlParser::MarginTop] = 12; | - | ||||||||||||||||||
1119 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1120 | break; never executed: break; | 0 | ||||||||||||||||||
1121 | case Html_blockquote: never executed: case Html_blockquote: | 0 | ||||||||||||||||||
1122 | margin[QTextHtmlParser::MarginTop] = 12; | - | ||||||||||||||||||
1123 | margin[QTextHtmlParser::MarginBottom] = 12; | - | ||||||||||||||||||
1124 | margin[QTextHtmlParser::MarginLeft] = 40; | - | ||||||||||||||||||
1125 | margin[QTextHtmlParser::MarginRight] = 40; | - | ||||||||||||||||||
1126 | break; never executed: break; | 0 | ||||||||||||||||||
1127 | case Html_dl: never executed: case Html_dl: | 0 | ||||||||||||||||||
1128 | margin[QTextHtmlParser::MarginTop] = 8; | - | ||||||||||||||||||
1129 | margin[QTextHtmlParser::MarginBottom] = 8; | - | ||||||||||||||||||
1130 | break; never executed: break; | 0 | ||||||||||||||||||
1131 | case Html_dd: never executed: case Html_dd: | 0 | ||||||||||||||||||
1132 | margin[QTextHtmlParser::MarginLeft] = 30; | - | ||||||||||||||||||
1133 | break; never executed: break; | 0 | ||||||||||||||||||
1134 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1135 | } | - | ||||||||||||||||||
1136 | } | - | ||||||||||||||||||
1137 | - | |||||||||||||||||||
1138 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
1139 | void QTextHtmlParserNode::setListStyle(const QVector<QCss::Value> &cssValues) | - | ||||||||||||||||||
1140 | { | - | ||||||||||||||||||
1141 | for (int i = 0; i < cssValues.count(); ++i) {
| 0 | ||||||||||||||||||
1142 | if (cssValues.at(i).type == QCss::Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
1143 | switch (static_cast<QCss::KnownValue>(cssValues.at(i).variant.toInt())) { | - | ||||||||||||||||||
1144 | case QCss::Value_Disc: hasOwnListStyle = true; listStyle = QTextListFormat::ListDisc; break; never executed: break; never executed: case QCss::Value_Disc: | 0 | ||||||||||||||||||
1145 | case QCss::Value_Square: hasOwnListStyle = true; listStyle = QTextListFormat::ListSquare; break; never executed: break; never executed: case QCss::Value_Square: | 0 | ||||||||||||||||||
1146 | case QCss::Value_Circle: hasOwnListStyle = true; listStyle = QTextListFormat::ListCircle; break; never executed: break; never executed: case QCss::Value_Circle: | 0 | ||||||||||||||||||
1147 | case QCss::Value_Decimal: hasOwnListStyle = true; listStyle = QTextListFormat::ListDecimal; break; never executed: break; never executed: case QCss::Value_Decimal: | 0 | ||||||||||||||||||
1148 | case QCss::Value_LowerAlpha: hasOwnListStyle = true; listStyle = QTextListFormat::ListLowerAlpha; break; never executed: break; never executed: case QCss::Value_LowerAlpha: | 0 | ||||||||||||||||||
1149 | case QCss::Value_UpperAlpha: hasOwnListStyle = true; listStyle = QTextListFormat::ListUpperAlpha; break; never executed: break; never executed: case QCss::Value_UpperAlpha: | 0 | ||||||||||||||||||
1150 | case QCss::Value_LowerRoman: hasOwnListStyle = true; listStyle = QTextListFormat::ListLowerRoman; break; never executed: break; never executed: case QCss::Value_LowerRoman: | 0 | ||||||||||||||||||
1151 | case QCss::Value_UpperRoman: hasOwnListStyle = true; listStyle = QTextListFormat::ListUpperRoman; break; never executed: break; never executed: case QCss::Value_UpperRoman: | 0 | ||||||||||||||||||
1152 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1153 | } | - | ||||||||||||||||||
1154 | } | - | ||||||||||||||||||
1155 | } never executed: end of block | 0 | ||||||||||||||||||
1156 | // allow individual list items to override the style | - | ||||||||||||||||||
1157 | if (id == Html_li && hasOwnListStyle)
| 0 | ||||||||||||||||||
1158 | blockFormat.setProperty(QTextFormat::ListStyle, listStyle); never executed: blockFormat.setProperty(QTextFormat::ListStyle, listStyle); | 0 | ||||||||||||||||||
1159 | } never executed: end of block | 0 | ||||||||||||||||||
1160 | - | |||||||||||||||||||
1161 | void QTextHtmlParserNode::applyCssDeclarations(const QVector<QCss::Declaration> &declarations, const QTextDocument *resourceProvider) | - | ||||||||||||||||||
1162 | { | - | ||||||||||||||||||
1163 | QCss::ValueExtractor extractor(declarations); | - | ||||||||||||||||||
1164 | extractor.extractBox(margin, padding); | - | ||||||||||||||||||
1165 | - | |||||||||||||||||||
1166 | for (int i = 0; i < declarations.count(); ++i) {
| 0 | ||||||||||||||||||
1167 | const QCss::Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
1168 | if (decl.d->values.isEmpty()) continue; never executed: continue;
| 0 | ||||||||||||||||||
1169 | - | |||||||||||||||||||
1170 | QCss::KnownValue identifier = QCss::UnknownValue; | - | ||||||||||||||||||
1171 | if (decl.d->values.first().type == QCss::Value::KnownIdentifier)
| 0 | ||||||||||||||||||
1172 | identifier = static_cast<QCss::KnownValue>(decl.d->values.first().variant.toInt()); never executed: identifier = static_cast<QCss::KnownValue>(decl.d->values.first().variant.toInt()); | 0 | ||||||||||||||||||
1173 | - | |||||||||||||||||||
1174 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
1175 | case QCss::BorderColor: borderBrush = QBrush(decl.colorValue()); break; never executed: break; never executed: case QCss::BorderColor: | 0 | ||||||||||||||||||
1176 | case QCss::BorderStyles: never executed: case QCss::BorderStyles: | 0 | ||||||||||||||||||
1177 | if (decl.styleValue() != QCss::BorderStyle_Unknown && decl.styleValue() != QCss::BorderStyle_Native)
| 0 | ||||||||||||||||||
1178 | borderStyle = static_cast<QTextFrameFormat::BorderStyle>(decl.styleValue() - 1); never executed: borderStyle = static_cast<QTextFrameFormat::BorderStyle>(decl.styleValue() - 1); | 0 | ||||||||||||||||||
1179 | break; never executed: break; | 0 | ||||||||||||||||||
1180 | case QCss::BorderWidth: never executed: case QCss::BorderWidth: | 0 | ||||||||||||||||||
1181 | tableBorder = extractor.lengthValue(decl); | - | ||||||||||||||||||
1182 | break; never executed: break; | 0 | ||||||||||||||||||
1183 | case QCss::Color: charFormat.setForeground(decl.colorValue()); break; never executed: break; never executed: case QCss::Color: | 0 | ||||||||||||||||||
1184 | case QCss::Float: never executed: case QCss::Float: | 0 | ||||||||||||||||||
1185 | cssFloat = QTextFrameFormat::InFlow; | - | ||||||||||||||||||
1186 | switch (identifier) { | - | ||||||||||||||||||
1187 | case QCss::Value_Left: cssFloat = QTextFrameFormat::FloatLeft; break; never executed: break; never executed: case QCss::Value_Left: | 0 | ||||||||||||||||||
1188 | case QCss::Value_Right: cssFloat = QTextFrameFormat::FloatRight; break; never executed: break; never executed: case QCss::Value_Right: | 0 | ||||||||||||||||||
1189 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1190 | } | - | ||||||||||||||||||
1191 | break; never executed: break; | 0 | ||||||||||||||||||
1192 | case QCss::QtBlockIndent: never executed: case QCss::QtBlockIndent: | 0 | ||||||||||||||||||
1193 | blockFormat.setIndent(decl.d->values.first().variant.toInt()); | - | ||||||||||||||||||
1194 | break; never executed: break; | 0 | ||||||||||||||||||
1195 | case QCss::LineHeight: { never executed: case QCss::LineHeight: | 0 | ||||||||||||||||||
1196 | qreal lineHeight; | - | ||||||||||||||||||
1197 | if (decl.realValue(&lineHeight, "px")) {
| 0 | ||||||||||||||||||
1198 | blockFormat.setLineHeight(lineHeight, QTextBlockFormat::FixedHeight); | - | ||||||||||||||||||
1199 | } else { never executed: end of block | 0 | ||||||||||||||||||
1200 | bool ok; | - | ||||||||||||||||||
1201 | QString value = decl.d->values.first().toString(); | - | ||||||||||||||||||
1202 | lineHeight = value.toDouble(&ok); | - | ||||||||||||||||||
1203 | if (ok)
| 0 | ||||||||||||||||||
1204 | blockFormat.setLineHeight(lineHeight, QTextBlockFormat::ProportionalHeight); never executed: blockFormat.setLineHeight(lineHeight, QTextBlockFormat::ProportionalHeight); | 0 | ||||||||||||||||||
1205 | else | - | ||||||||||||||||||
1206 | blockFormat.setLineHeight(0, QTextBlockFormat::SingleHeight); never executed: blockFormat.setLineHeight(0, QTextBlockFormat::SingleHeight); | 0 | ||||||||||||||||||
1207 | } | - | ||||||||||||||||||
1208 | break; } never executed: break; | 0 | ||||||||||||||||||
1209 | case QCss::TextIndent: { never executed: case QCss::TextIndent: | 0 | ||||||||||||||||||
1210 | qreal indent = 0; | - | ||||||||||||||||||
1211 | if (decl.realValue(&indent, "px"))
| 0 | ||||||||||||||||||
1212 | blockFormat.setTextIndent(indent); never executed: blockFormat.setTextIndent(indent); | 0 | ||||||||||||||||||
1213 | break; } never executed: break; | 0 | ||||||||||||||||||
1214 | case QCss::QtListIndent: never executed: case QCss::QtListIndent: | 0 | ||||||||||||||||||
1215 | if (decl.intValue(&cssListIndent))
| 0 | ||||||||||||||||||
1216 | hasCssListIndent = true; never executed: hasCssListIndent = true; | 0 | ||||||||||||||||||
1217 | break; never executed: break; | 0 | ||||||||||||||||||
1218 | case QCss::QtParagraphType: never executed: case QCss::QtParagraphType: | 0 | ||||||||||||||||||
1219 | if (decl.d->values.first().variant.toString().compare(QLatin1String("empty"), Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
1220 | isEmptyParagraph = true; never executed: isEmptyParagraph = true; | 0 | ||||||||||||||||||
1221 | break; never executed: break; | 0 | ||||||||||||||||||
1222 | case QCss::QtTableType: never executed: case QCss::QtTableType: | 0 | ||||||||||||||||||
1223 | if (decl.d->values.first().variant.toString().compare(QLatin1String("frame"), Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
1224 | isTextFrame = true; never executed: isTextFrame = true; | 0 | ||||||||||||||||||
1225 | else if (decl.d->values.first().variant.toString().compare(QLatin1String("root"), Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
1226 | isTextFrame = true; | - | ||||||||||||||||||
1227 | isRootFrame = true; | - | ||||||||||||||||||
1228 | } never executed: end of block | 0 | ||||||||||||||||||
1229 | break; never executed: break; | 0 | ||||||||||||||||||
1230 | case QCss::QtUserState: never executed: case QCss::QtUserState: | 0 | ||||||||||||||||||
1231 | userState = decl.d->values.first().variant.toInt(); | - | ||||||||||||||||||
1232 | break; never executed: break; | 0 | ||||||||||||||||||
1233 | case QCss::Whitespace: never executed: case QCss::Whitespace: | 0 | ||||||||||||||||||
1234 | switch (identifier) { | - | ||||||||||||||||||
1235 | case QCss::Value_Normal: wsm = QTextHtmlParserNode::WhiteSpaceNormal; break; never executed: break; never executed: case QCss::Value_Normal: | 0 | ||||||||||||||||||
1236 | case QCss::Value_Pre: wsm = QTextHtmlParserNode::WhiteSpacePre; break; never executed: break; never executed: case QCss::Value_Pre: | 0 | ||||||||||||||||||
1237 | case QCss::Value_NoWrap: wsm = QTextHtmlParserNode::WhiteSpaceNoWrap; break; never executed: break; never executed: case QCss::Value_NoWrap: | 0 | ||||||||||||||||||
1238 | case QCss::Value_PreWrap: wsm = QTextHtmlParserNode::WhiteSpacePreWrap; break; never executed: break; never executed: case QCss::Value_PreWrap: | 0 | ||||||||||||||||||
1239 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1240 | } | - | ||||||||||||||||||
1241 | break; never executed: break; | 0 | ||||||||||||||||||
1242 | case QCss::VerticalAlignment: never executed: case QCss::VerticalAlignment: | 0 | ||||||||||||||||||
1243 | switch (identifier) { | - | ||||||||||||||||||
1244 | case QCss::Value_Sub: charFormat.setVerticalAlignment(QTextCharFormat::AlignSubScript); break; never executed: break; never executed: case QCss::Value_Sub: | 0 | ||||||||||||||||||
1245 | case QCss::Value_Super: charFormat.setVerticalAlignment(QTextCharFormat::AlignSuperScript); break; never executed: break; never executed: case QCss::Value_Super: | 0 | ||||||||||||||||||
1246 | case QCss::Value_Middle: charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); break; never executed: break; never executed: case QCss::Value_Middle: | 0 | ||||||||||||||||||
1247 | case QCss::Value_Top: charFormat.setVerticalAlignment(QTextCharFormat::AlignTop); break; never executed: break; never executed: case QCss::Value_Top: | 0 | ||||||||||||||||||
1248 | case QCss::Value_Bottom: charFormat.setVerticalAlignment(QTextCharFormat::AlignBottom); break; never executed: break; never executed: case QCss::Value_Bottom: | 0 | ||||||||||||||||||
1249 | default: charFormat.setVerticalAlignment(QTextCharFormat::AlignNormal); break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1250 | } | - | ||||||||||||||||||
1251 | break; never executed: break; | 0 | ||||||||||||||||||
1252 | case QCss::PageBreakBefore: never executed: case QCss::PageBreakBefore: | 0 | ||||||||||||||||||
1253 | switch (identifier) { | - | ||||||||||||||||||
1254 | case QCss::Value_Always: blockFormat.setPageBreakPolicy(blockFormat.pageBreakPolicy() | QTextFormat::PageBreak_AlwaysBefore); break; never executed: break; never executed: case QCss::Value_Always: | 0 | ||||||||||||||||||
1255 | case QCss::Value_Auto: blockFormat.setPageBreakPolicy(blockFormat.pageBreakPolicy() & ~QTextFormat::PageBreak_AlwaysBefore); break; never executed: break; never executed: case QCss::Value_Auto: | 0 | ||||||||||||||||||
1256 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1257 | } | - | ||||||||||||||||||
1258 | break; never executed: break; | 0 | ||||||||||||||||||
1259 | case QCss::PageBreakAfter: never executed: case QCss::PageBreakAfter: | 0 | ||||||||||||||||||
1260 | switch (identifier) { | - | ||||||||||||||||||
1261 | case QCss::Value_Always: blockFormat.setPageBreakPolicy(blockFormat.pageBreakPolicy() | QTextFormat::PageBreak_AlwaysAfter); break; never executed: break; never executed: case QCss::Value_Always: | 0 | ||||||||||||||||||
1262 | case QCss::Value_Auto: blockFormat.setPageBreakPolicy(blockFormat.pageBreakPolicy() & ~QTextFormat::PageBreak_AlwaysAfter); break; never executed: break; never executed: case QCss::Value_Auto: | 0 | ||||||||||||||||||
1263 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1264 | } | - | ||||||||||||||||||
1265 | break; never executed: break; | 0 | ||||||||||||||||||
1266 | case QCss::TextUnderlineStyle: never executed: case QCss::TextUnderlineStyle: | 0 | ||||||||||||||||||
1267 | switch (identifier) { | - | ||||||||||||||||||
1268 | case QCss::Value_None: charFormat.setUnderlineStyle(QTextCharFormat::NoUnderline); break; never executed: break; never executed: case QCss::Value_None: | 0 | ||||||||||||||||||
1269 | case QCss::Value_Solid: charFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); break; never executed: break; never executed: case QCss::Value_Solid: | 0 | ||||||||||||||||||
1270 | case QCss::Value_Dashed: charFormat.setUnderlineStyle(QTextCharFormat::DashUnderline); break; never executed: break; never executed: case QCss::Value_Dashed: | 0 | ||||||||||||||||||
1271 | case QCss::Value_Dotted: charFormat.setUnderlineStyle(QTextCharFormat::DotLine); break; never executed: break; never executed: case QCss::Value_Dotted: | 0 | ||||||||||||||||||
1272 | case QCss::Value_DotDash: charFormat.setUnderlineStyle(QTextCharFormat::DashDotLine); break; never executed: break; never executed: case QCss::Value_DotDash: | 0 | ||||||||||||||||||
1273 | case QCss::Value_DotDotDash: charFormat.setUnderlineStyle(QTextCharFormat::DashDotDotLine); break; never executed: break; never executed: case QCss::Value_DotDotDash: | 0 | ||||||||||||||||||
1274 | case QCss::Value_Wave: charFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline); break; never executed: break; never executed: case QCss::Value_Wave: | 0 | ||||||||||||||||||
1275 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1276 | } | - | ||||||||||||||||||
1277 | break; never executed: break; | 0 | ||||||||||||||||||
1278 | case QCss::ListStyleType: never executed: case QCss::ListStyleType: | 0 | ||||||||||||||||||
1279 | case QCss::ListStyle: never executed: case QCss::ListStyle: | 0 | ||||||||||||||||||
1280 | setListStyle(decl.d->values); | - | ||||||||||||||||||
1281 | break; never executed: break; | 0 | ||||||||||||||||||
1282 | case QCss::QtListNumberPrefix: never executed: case QCss::QtListNumberPrefix: | 0 | ||||||||||||||||||
1283 | textListNumberPrefix = decl.d->values.first().variant.toString(); | - | ||||||||||||||||||
1284 | break; never executed: break; | 0 | ||||||||||||||||||
1285 | case QCss::QtListNumberSuffix: never executed: case QCss::QtListNumberSuffix: | 0 | ||||||||||||||||||
1286 | textListNumberSuffix = decl.d->values.first().variant.toString(); | - | ||||||||||||||||||
1287 | break; never executed: break; | 0 | ||||||||||||||||||
1288 | case QCss::TextAlignment: never executed: case QCss::TextAlignment: | 0 | ||||||||||||||||||
1289 | switch (identifier) { | - | ||||||||||||||||||
1290 | case QCss::Value_Left: blockFormat.setAlignment(Qt::AlignLeft); break; never executed: break; never executed: case QCss::Value_Left: | 0 | ||||||||||||||||||
1291 | case QCss::Value_Center: blockFormat.setAlignment(Qt::AlignCenter); break; never executed: break; never executed: case QCss::Value_Center: | 0 | ||||||||||||||||||
1292 | case QCss::Value_Right: blockFormat.setAlignment(Qt::AlignRight); break; never executed: break; never executed: case QCss::Value_Right: | 0 | ||||||||||||||||||
1293 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1294 | } | - | ||||||||||||||||||
1295 | break; never executed: break; | 0 | ||||||||||||||||||
1296 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1297 | } | - | ||||||||||||||||||
1298 | } | - | ||||||||||||||||||
1299 | - | |||||||||||||||||||
1300 | QFont f; | - | ||||||||||||||||||
1301 | int adjustment = -255; | - | ||||||||||||||||||
1302 | extractor.extractFont(&f, &adjustment); | - | ||||||||||||||||||
1303 | charFormat.setFont(f, QTextCharFormat::FontPropertiesSpecifiedOnly); | - | ||||||||||||||||||
1304 | - | |||||||||||||||||||
1305 | if (adjustment >= -1)
| 0 | ||||||||||||||||||
1306 | charFormat.setProperty(QTextFormat::FontSizeAdjustment, adjustment); never executed: charFormat.setProperty(QTextFormat::FontSizeAdjustment, adjustment); | 0 | ||||||||||||||||||
1307 | - | |||||||||||||||||||
1308 | { | - | ||||||||||||||||||
1309 | Qt::Alignment ignoredAlignment; | - | ||||||||||||||||||
1310 | QCss::Repeat ignoredRepeat; | - | ||||||||||||||||||
1311 | QString bgImage; | - | ||||||||||||||||||
1312 | QBrush bgBrush; | - | ||||||||||||||||||
1313 | QCss::Origin ignoredOrigin, ignoredClip; | - | ||||||||||||||||||
1314 | QCss::Attachment ignoredAttachment; | - | ||||||||||||||||||
1315 | extractor.extractBackground(&bgBrush, &bgImage, &ignoredRepeat, &ignoredAlignment, | - | ||||||||||||||||||
1316 | &ignoredOrigin, &ignoredAttachment, &ignoredClip); | - | ||||||||||||||||||
1317 | - | |||||||||||||||||||
1318 | if (!bgImage.isEmpty() && resourceProvider) {
| 0 | ||||||||||||||||||
1319 | applyBackgroundImage(bgImage, resourceProvider); | - | ||||||||||||||||||
1320 | } else if (bgBrush.style() != Qt::NoBrush) { never executed: end of block
| 0 | ||||||||||||||||||
1321 | charFormat.setBackground(bgBrush); | - | ||||||||||||||||||
1322 | } never executed: end of block | 0 | ||||||||||||||||||
1323 | } | - | ||||||||||||||||||
1324 | } never executed: end of block | 0 | ||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | #endif // QT_NO_CSSPARSER | - | ||||||||||||||||||
1327 | - | |||||||||||||||||||
1328 | void QTextHtmlParserNode::applyBackgroundImage(const QString &url, const QTextDocument *resourceProvider) | - | ||||||||||||||||||
1329 | { | - | ||||||||||||||||||
1330 | if (!url.isEmpty() && resourceProvider) {
| 0 | ||||||||||||||||||
1331 | QVariant val = resourceProvider->resource(QTextDocument::ImageResource, url); | - | ||||||||||||||||||
1332 | - | |||||||||||||||||||
1333 | if (QCoreApplication::instance()->thread() != QThread::currentThread()) {
| 0 | ||||||||||||||||||
1334 | // must use images in non-GUI threads | - | ||||||||||||||||||
1335 | if (val.type() == QVariant::Image) {
| 0 | ||||||||||||||||||
1336 | QImage image = qvariant_cast<QImage>(val); | - | ||||||||||||||||||
1337 | charFormat.setBackground(image); | - | ||||||||||||||||||
1338 | } else if (val.type() == QVariant::ByteArray) { never executed: end of block
| 0 | ||||||||||||||||||
1339 | QImage image; | - | ||||||||||||||||||
1340 | if (image.loadFromData(val.toByteArray())) {
| 0 | ||||||||||||||||||
1341 | charFormat.setBackground(image); | - | ||||||||||||||||||
1342 | } never executed: end of block | 0 | ||||||||||||||||||
1343 | } never executed: end of block | 0 | ||||||||||||||||||
1344 | } else { never executed: end of block | 0 | ||||||||||||||||||
1345 | if (val.type() == QVariant::Image || val.type() == QVariant::Pixmap) {
| 0 | ||||||||||||||||||
1346 | charFormat.setBackground(qvariant_cast<QPixmap>(val)); | - | ||||||||||||||||||
1347 | } else if (val.type() == QVariant::ByteArray) { never executed: end of block
| 0 | ||||||||||||||||||
1348 | QPixmap pm; | - | ||||||||||||||||||
1349 | if (pm.loadFromData(val.toByteArray())) {
| 0 | ||||||||||||||||||
1350 | charFormat.setBackground(pm); | - | ||||||||||||||||||
1351 | } never executed: end of block | 0 | ||||||||||||||||||
1352 | } never executed: end of block | 0 | ||||||||||||||||||
1353 | } never executed: end of block | 0 | ||||||||||||||||||
1354 | } | - | ||||||||||||||||||
1355 | if (!url.isEmpty())
| 0 | ||||||||||||||||||
1356 | charFormat.setProperty(QTextFormat::BackgroundImageUrl, url); never executed: charFormat.setProperty(QTextFormat::BackgroundImageUrl, url); | 0 | ||||||||||||||||||
1357 | } never executed: end of block | 0 | ||||||||||||||||||
1358 | - | |||||||||||||||||||
1359 | bool QTextHtmlParserNode::hasOnlyWhitespace() const | - | ||||||||||||||||||
1360 | { | - | ||||||||||||||||||
1361 | for (int i = 0; i < text.count(); ++i)
| 0 | ||||||||||||||||||
1362 | if (!text.at(i).isSpace() || text.at(i) == QChar::LineSeparator)
| 0 | ||||||||||||||||||
1363 | return false; never executed: return false; | 0 | ||||||||||||||||||
1364 | return true; never executed: return true; | 0 | ||||||||||||||||||
1365 | } | - | ||||||||||||||||||
1366 | - | |||||||||||||||||||
1367 | static bool setIntAttribute(int *destination, const QString &value) | - | ||||||||||||||||||
1368 | { | - | ||||||||||||||||||
1369 | bool ok = false; | - | ||||||||||||||||||
1370 | int val = value.toInt(&ok); | - | ||||||||||||||||||
1371 | if (ok)
| 0 | ||||||||||||||||||
1372 | *destination = val; never executed: *destination = val; | 0 | ||||||||||||||||||
1373 | - | |||||||||||||||||||
1374 | return ok; never executed: return ok; | 0 | ||||||||||||||||||
1375 | } | - | ||||||||||||||||||
1376 | - | |||||||||||||||||||
1377 | static bool setFloatAttribute(qreal *destination, const QString &value) | - | ||||||||||||||||||
1378 | { | - | ||||||||||||||||||
1379 | bool ok = false; | - | ||||||||||||||||||
1380 | qreal val = value.toDouble(&ok); | - | ||||||||||||||||||
1381 | if (ok)
| 0 | ||||||||||||||||||
1382 | *destination = val; never executed: *destination = val; | 0 | ||||||||||||||||||
1383 | - | |||||||||||||||||||
1384 | return ok; never executed: return ok; | 0 | ||||||||||||||||||
1385 | } | - | ||||||||||||||||||
1386 | - | |||||||||||||||||||
1387 | static void setWidthAttribute(QTextLength *width, QString value) | - | ||||||||||||||||||
1388 | { | - | ||||||||||||||||||
1389 | bool ok = false; | - | ||||||||||||||||||
1390 | qreal realVal = value.toDouble(&ok); | - | ||||||||||||||||||
1391 | if (ok) {
| 0 | ||||||||||||||||||
1392 | *width = QTextLength(QTextLength::FixedLength, realVal); | - | ||||||||||||||||||
1393 | } else { never executed: end of block | 0 | ||||||||||||||||||
1394 | value = value.trimmed(); | - | ||||||||||||||||||
1395 | if (!value.isEmpty() && value.endsWith(QLatin1Char('%'))) {
| 0 | ||||||||||||||||||
1396 | value.chop(1); | - | ||||||||||||||||||
1397 | realVal = value.toDouble(&ok); | - | ||||||||||||||||||
1398 | if (ok)
| 0 | ||||||||||||||||||
1399 | *width = QTextLength(QTextLength::PercentageLength, realVal); never executed: *width = QTextLength(QTextLength::PercentageLength, realVal); | 0 | ||||||||||||||||||
1400 | } never executed: end of block | 0 | ||||||||||||||||||
1401 | } never executed: end of block | 0 | ||||||||||||||||||
1402 | } | - | ||||||||||||||||||
1403 | - | |||||||||||||||||||
1404 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
1405 | void QTextHtmlParserNode::parseStyleAttribute(const QString &value, const QTextDocument *resourceProvider) | - | ||||||||||||||||||
1406 | { | - | ||||||||||||||||||
1407 | QString css = value; | - | ||||||||||||||||||
1408 | css.prepend(QLatin1String("* {")); | - | ||||||||||||||||||
1409 | css.append(QLatin1Char('}')); | - | ||||||||||||||||||
1410 | QCss::Parser parser(css); | - | ||||||||||||||||||
1411 | QCss::StyleSheet sheet; | - | ||||||||||||||||||
1412 | parser.parse(&sheet, Qt::CaseInsensitive); | - | ||||||||||||||||||
1413 | if (sheet.styleRules.count() != 1) return; never executed: return;
| 0 | ||||||||||||||||||
1414 | applyCssDeclarations(sheet.styleRules.at(0).declarations, resourceProvider); | - | ||||||||||||||||||
1415 | } never executed: end of block | 0 | ||||||||||||||||||
1416 | #endif | - | ||||||||||||||||||
1417 | - | |||||||||||||||||||
1418 | QStringList QTextHtmlParser::parseAttributes() | - | ||||||||||||||||||
1419 | { | - | ||||||||||||||||||
1420 | QStringList attrs; | - | ||||||||||||||||||
1421 | - | |||||||||||||||||||
1422 | while (pos < len) {
| 0 | ||||||||||||||||||
1423 | eatSpace(); | - | ||||||||||||||||||
1424 | if (hasPrefix(QLatin1Char('>')) || hasPrefix(QLatin1Char('/')))
| 0 | ||||||||||||||||||
1425 | break; never executed: break; | 0 | ||||||||||||||||||
1426 | QString key = parseWord().toLower(); | - | ||||||||||||||||||
1427 | QString value = QLatin1String("1"); | - | ||||||||||||||||||
1428 | if (key.size() == 0)
| 0 | ||||||||||||||||||
1429 | break; never executed: break; | 0 | ||||||||||||||||||
1430 | eatSpace(); | - | ||||||||||||||||||
1431 | if (hasPrefix(QLatin1Char('='))){
| 0 | ||||||||||||||||||
1432 | pos++; | - | ||||||||||||||||||
1433 | eatSpace(); | - | ||||||||||||||||||
1434 | value = parseWord(); | - | ||||||||||||||||||
1435 | } never executed: end of block | 0 | ||||||||||||||||||
1436 | if (value.size() == 0)
| 0 | ||||||||||||||||||
1437 | continue; never executed: continue; | 0 | ||||||||||||||||||
1438 | attrs << key << value; | - | ||||||||||||||||||
1439 | } never executed: end of block | 0 | ||||||||||||||||||
1440 | - | |||||||||||||||||||
1441 | return attrs; never executed: return attrs; | 0 | ||||||||||||||||||
1442 | } | - | ||||||||||||||||||
1443 | - | |||||||||||||||||||
1444 | void QTextHtmlParser::applyAttributes(const QStringList &attributes) | - | ||||||||||||||||||
1445 | { | - | ||||||||||||||||||
1446 | // local state variable for qt3 textedit mode | - | ||||||||||||||||||
1447 | bool seenQt3Richtext = false; | - | ||||||||||||||||||
1448 | QString linkHref; | - | ||||||||||||||||||
1449 | QString linkType; | - | ||||||||||||||||||
1450 | - | |||||||||||||||||||
1451 | if (attributes.count() % 2 == 1)
| 0 | ||||||||||||||||||
1452 | return; never executed: return; | 0 | ||||||||||||||||||
1453 | - | |||||||||||||||||||
1454 | QTextHtmlParserNode *node = &nodes.last(); | - | ||||||||||||||||||
1455 | - | |||||||||||||||||||
1456 | for (int i = 0; i < attributes.count(); i += 2) {
| 0 | ||||||||||||||||||
1457 | QString key = attributes.at(i); | - | ||||||||||||||||||
1458 | QString value = attributes.at(i + 1); | - | ||||||||||||||||||
1459 | - | |||||||||||||||||||
1460 | switch (node->id) { | - | ||||||||||||||||||
1461 | case Html_font: never executed: case Html_font: | 0 | ||||||||||||||||||
1462 | // the infamous font tag | - | ||||||||||||||||||
1463 | if (key == QLatin1String("size") && value.size()) {
| 0 | ||||||||||||||||||
1464 | int n = value.toInt(); | - | ||||||||||||||||||
1465 | if (value.at(0) != QLatin1Char('+') && value.at(0) != QLatin1Char('-'))
| 0 | ||||||||||||||||||
1466 | n -= 3; never executed: n -= 3; | 0 | ||||||||||||||||||
1467 | node->charFormat.setProperty(QTextFormat::FontSizeAdjustment, n); | - | ||||||||||||||||||
1468 | } else if (key == QLatin1String("face")) { never executed: end of block
| 0 | ||||||||||||||||||
1469 | node->charFormat.setFontFamily(value); | - | ||||||||||||||||||
1470 | } else if (key == QLatin1String("color")) { never executed: end of block
| 0 | ||||||||||||||||||
1471 | QColor c; c.setNamedColor(value); | - | ||||||||||||||||||
1472 | if (!c.isValid())
| 0 | ||||||||||||||||||
1473 | qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); never executed: QMessageLogger(__FILE__, 1473, __PRETTY_FUNCTION__).warning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); | 0 | ||||||||||||||||||
1474 | node->charFormat.setForeground(c); | - | ||||||||||||||||||
1475 | } never executed: end of block | 0 | ||||||||||||||||||
1476 | break; never executed: break; | 0 | ||||||||||||||||||
1477 | case Html_ol: never executed: case Html_ol: | 0 | ||||||||||||||||||
1478 | case Html_ul: never executed: case Html_ul: | 0 | ||||||||||||||||||
1479 | if (key == QLatin1String("type")) {
| 0 | ||||||||||||||||||
1480 | node->hasOwnListStyle = true; | - | ||||||||||||||||||
1481 | if (value == QLatin1String("1")) {
| 0 | ||||||||||||||||||
1482 | node->listStyle = QTextListFormat::ListDecimal; | - | ||||||||||||||||||
1483 | } else if (value == QLatin1String("a")) { never executed: end of block
| 0 | ||||||||||||||||||
1484 | node->listStyle = QTextListFormat::ListLowerAlpha; | - | ||||||||||||||||||
1485 | } else if (value == QLatin1String("A")) { never executed: end of block
| 0 | ||||||||||||||||||
1486 | node->listStyle = QTextListFormat::ListUpperAlpha; | - | ||||||||||||||||||
1487 | } else if (value == QLatin1String("i")) { never executed: end of block
| 0 | ||||||||||||||||||
1488 | node->listStyle = QTextListFormat::ListLowerRoman; | - | ||||||||||||||||||
1489 | } else if (value == QLatin1String("I")) { never executed: end of block
| 0 | ||||||||||||||||||
1490 | node->listStyle = QTextListFormat::ListUpperRoman; | - | ||||||||||||||||||
1491 | } else { never executed: end of block | 0 | ||||||||||||||||||
1492 | value = value.toLower(); | - | ||||||||||||||||||
1493 | if (value == QLatin1String("square"))
| 0 | ||||||||||||||||||
1494 | node->listStyle = QTextListFormat::ListSquare; never executed: node->listStyle = QTextListFormat::ListSquare; | 0 | ||||||||||||||||||
1495 | else if (value == QLatin1String("disc"))
| 0 | ||||||||||||||||||
1496 | node->listStyle = QTextListFormat::ListDisc; never executed: node->listStyle = QTextListFormat::ListDisc; | 0 | ||||||||||||||||||
1497 | else if (value == QLatin1String("circle"))
| 0 | ||||||||||||||||||
1498 | node->listStyle = QTextListFormat::ListCircle; never executed: node->listStyle = QTextListFormat::ListCircle; | 0 | ||||||||||||||||||
1499 | } never executed: end of block | 0 | ||||||||||||||||||
1500 | } | - | ||||||||||||||||||
1501 | break; never executed: break; | 0 | ||||||||||||||||||
1502 | case Html_a: never executed: case Html_a: | 0 | ||||||||||||||||||
1503 | if (key == QLatin1String("href"))
| 0 | ||||||||||||||||||
1504 | node->charFormat.setAnchorHref(value); never executed: node->charFormat.setAnchorHref(value); | 0 | ||||||||||||||||||
1505 | else if (key == QLatin1String("name"))
| 0 | ||||||||||||||||||
1506 | node->charFormat.setAnchorName(value); never executed: node->charFormat.setAnchorName(value); | 0 | ||||||||||||||||||
1507 | break; never executed: break; | 0 | ||||||||||||||||||
1508 | case Html_img: never executed: case Html_img: | 0 | ||||||||||||||||||
1509 | if (key == QLatin1String("src") || key == QLatin1String("source")) {
| 0 | ||||||||||||||||||
1510 | node->imageName = value; | - | ||||||||||||||||||
1511 | } else if (key == QLatin1String("width")) { never executed: end of block
| 0 | ||||||||||||||||||
1512 | node->imageWidth = -2; // register that there is a value for it. | - | ||||||||||||||||||
1513 | setFloatAttribute(&node->imageWidth, value); | - | ||||||||||||||||||
1514 | } else if (key == QLatin1String("height")) { never executed: end of block
| 0 | ||||||||||||||||||
1515 | node->imageHeight = -2; // register that there is a value for it. | - | ||||||||||||||||||
1516 | setFloatAttribute(&node->imageHeight, value); | - | ||||||||||||||||||
1517 | } never executed: end of block | 0 | ||||||||||||||||||
1518 | break; never executed: break; | 0 | ||||||||||||||||||
1519 | case Html_tr: never executed: case Html_tr: | 0 | ||||||||||||||||||
1520 | case Html_body: never executed: case Html_body: | 0 | ||||||||||||||||||
1521 | if (key == QLatin1String("bgcolor")) {
| 0 | ||||||||||||||||||
1522 | QColor c; c.setNamedColor(value); | - | ||||||||||||||||||
1523 | if (!c.isValid())
| 0 | ||||||||||||||||||
1524 | qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); never executed: QMessageLogger(__FILE__, 1524, __PRETTY_FUNCTION__).warning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); | 0 | ||||||||||||||||||
1525 | node->charFormat.setBackground(c); | - | ||||||||||||||||||
1526 | } else if (key == QLatin1String("background")) { never executed: end of block
| 0 | ||||||||||||||||||
1527 | node->applyBackgroundImage(value, resourceProvider); | - | ||||||||||||||||||
1528 | } never executed: end of block | 0 | ||||||||||||||||||
1529 | break; never executed: break; | 0 | ||||||||||||||||||
1530 | case Html_th: never executed: case Html_th: | 0 | ||||||||||||||||||
1531 | case Html_td: never executed: case Html_td: | 0 | ||||||||||||||||||
1532 | if (key == QLatin1String("width")) {
| 0 | ||||||||||||||||||
1533 | setWidthAttribute(&node->width, value); | - | ||||||||||||||||||
1534 | } else if (key == QLatin1String("bgcolor")) { never executed: end of block
| 0 | ||||||||||||||||||
1535 | QColor c; c.setNamedColor(value); | - | ||||||||||||||||||
1536 | if (!c.isValid())
| 0 | ||||||||||||||||||
1537 | qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); never executed: QMessageLogger(__FILE__, 1537, __PRETTY_FUNCTION__).warning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); | 0 | ||||||||||||||||||
1538 | node->charFormat.setBackground(c); | - | ||||||||||||||||||
1539 | } else if (key == QLatin1String("background")) { never executed: end of block
| 0 | ||||||||||||||||||
1540 | node->applyBackgroundImage(value, resourceProvider); | - | ||||||||||||||||||
1541 | } else if (key == QLatin1String("rowspan")) { never executed: end of block
| 0 | ||||||||||||||||||
1542 | if (setIntAttribute(&node->tableCellRowSpan, value))
| 0 | ||||||||||||||||||
1543 | node->tableCellRowSpan = qMax(1, node->tableCellRowSpan); never executed: node->tableCellRowSpan = qMax(1, node->tableCellRowSpan); | 0 | ||||||||||||||||||
1544 | } else if (key == QLatin1String("colspan")) { never executed: end of block
| 0 | ||||||||||||||||||
1545 | if (setIntAttribute(&node->tableCellColSpan, value))
| 0 | ||||||||||||||||||
1546 | node->tableCellColSpan = qMax(1, node->tableCellColSpan); never executed: node->tableCellColSpan = qMax(1, node->tableCellColSpan); | 0 | ||||||||||||||||||
1547 | } never executed: end of block | 0 | ||||||||||||||||||
1548 | break; never executed: break; | 0 | ||||||||||||||||||
1549 | case Html_table: never executed: case Html_table: | 0 | ||||||||||||||||||
1550 | if (key == QLatin1String("border")) {
| 0 | ||||||||||||||||||
1551 | setFloatAttribute(&node->tableBorder, value); | - | ||||||||||||||||||
1552 | } else if (key == QLatin1String("bgcolor")) { never executed: end of block
| 0 | ||||||||||||||||||
1553 | QColor c; c.setNamedColor(value); | - | ||||||||||||||||||
1554 | if (!c.isValid())
| 0 | ||||||||||||||||||
1555 | qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); never executed: QMessageLogger(__FILE__, 1555, __PRETTY_FUNCTION__).warning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); | 0 | ||||||||||||||||||
1556 | node->charFormat.setBackground(c); | - | ||||||||||||||||||
1557 | } else if (key == QLatin1String("background")) { never executed: end of block
| 0 | ||||||||||||||||||
1558 | node->applyBackgroundImage(value, resourceProvider); | - | ||||||||||||||||||
1559 | } else if (key == QLatin1String("cellspacing")) { never executed: end of block
| 0 | ||||||||||||||||||
1560 | setFloatAttribute(&node->tableCellSpacing, value); | - | ||||||||||||||||||
1561 | } else if (key == QLatin1String("cellpadding")) { never executed: end of block
| 0 | ||||||||||||||||||
1562 | setFloatAttribute(&node->tableCellPadding, value); | - | ||||||||||||||||||
1563 | } else if (key == QLatin1String("width")) { never executed: end of block
| 0 | ||||||||||||||||||
1564 | setWidthAttribute(&node->width, value); | - | ||||||||||||||||||
1565 | } else if (key == QLatin1String("height")) { never executed: end of block
| 0 | ||||||||||||||||||
1566 | setWidthAttribute(&node->height, value); | - | ||||||||||||||||||
1567 | } never executed: end of block | 0 | ||||||||||||||||||
1568 | break; never executed: break; | 0 | ||||||||||||||||||
1569 | case Html_meta: never executed: case Html_meta: | 0 | ||||||||||||||||||
1570 | if (key == QLatin1String("name")
| 0 | ||||||||||||||||||
1571 | && value == QLatin1String("qrichtext")) {
| 0 | ||||||||||||||||||
1572 | seenQt3Richtext = true; | - | ||||||||||||||||||
1573 | } never executed: end of block | 0 | ||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | if (key == QLatin1String("content")
| 0 | ||||||||||||||||||
1576 | && value == QLatin1String("1")
| 0 | ||||||||||||||||||
1577 | && seenQt3Richtext) {
| 0 | ||||||||||||||||||
1578 | - | |||||||||||||||||||
1579 | textEditMode = true; | - | ||||||||||||||||||
1580 | } never executed: end of block | 0 | ||||||||||||||||||
1581 | break; never executed: break; | 0 | ||||||||||||||||||
1582 | case Html_hr: never executed: case Html_hr: | 0 | ||||||||||||||||||
1583 | if (key == QLatin1String("width"))
| 0 | ||||||||||||||||||
1584 | setWidthAttribute(&node->width, value); never executed: setWidthAttribute(&node->width, value); | 0 | ||||||||||||||||||
1585 | break; never executed: break; | 0 | ||||||||||||||||||
1586 | case Html_link: never executed: case Html_link: | 0 | ||||||||||||||||||
1587 | if (key == QLatin1String("href"))
| 0 | ||||||||||||||||||
1588 | linkHref = value; never executed: linkHref = value; | 0 | ||||||||||||||||||
1589 | else if (key == QLatin1String("type"))
| 0 | ||||||||||||||||||
1590 | linkType = value; never executed: linkType = value; | 0 | ||||||||||||||||||
1591 | break; never executed: break; | 0 | ||||||||||||||||||
1592 | default: never executed: default: | 0 | ||||||||||||||||||
1593 | break; never executed: break; | 0 | ||||||||||||||||||
1594 | } | - | ||||||||||||||||||
1595 | - | |||||||||||||||||||
1596 | if (key == QLatin1String("style")) {
| 0 | ||||||||||||||||||
1597 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
1598 | node->parseStyleAttribute(value, resourceProvider); | - | ||||||||||||||||||
1599 | #endif | - | ||||||||||||||||||
1600 | } else if (key == QLatin1String("align")) { never executed: end of block
| 0 | ||||||||||||||||||
1601 | value = value.toLower(); | - | ||||||||||||||||||
1602 | bool alignmentSet = true; | - | ||||||||||||||||||
1603 | - | |||||||||||||||||||
1604 | if (value == QLatin1String("left"))
| 0 | ||||||||||||||||||
1605 | node->blockFormat.setAlignment(Qt::AlignLeft|Qt::AlignAbsolute); never executed: node->blockFormat.setAlignment(Qt::AlignLeft|Qt::AlignAbsolute); | 0 | ||||||||||||||||||
1606 | else if (value == QLatin1String("right"))
| 0 | ||||||||||||||||||
1607 | node->blockFormat.setAlignment(Qt::AlignRight|Qt::AlignAbsolute); never executed: node->blockFormat.setAlignment(Qt::AlignRight|Qt::AlignAbsolute); | 0 | ||||||||||||||||||
1608 | else if (value == QLatin1String("center"))
| 0 | ||||||||||||||||||
1609 | node->blockFormat.setAlignment(Qt::AlignHCenter); never executed: node->blockFormat.setAlignment(Qt::AlignHCenter); | 0 | ||||||||||||||||||
1610 | else if (value == QLatin1String("justify"))
| 0 | ||||||||||||||||||
1611 | node->blockFormat.setAlignment(Qt::AlignJustify); never executed: node->blockFormat.setAlignment(Qt::AlignJustify); | 0 | ||||||||||||||||||
1612 | else | - | ||||||||||||||||||
1613 | alignmentSet = false; never executed: alignmentSet = false; | 0 | ||||||||||||||||||
1614 | - | |||||||||||||||||||
1615 | if (node->id == Html_img) {
| 0 | ||||||||||||||||||
1616 | // HTML4 compat | - | ||||||||||||||||||
1617 | if (alignmentSet) {
| 0 | ||||||||||||||||||
1618 | if (node->blockFormat.alignment() & Qt::AlignLeft)
| 0 | ||||||||||||||||||
1619 | node->cssFloat = QTextFrameFormat::FloatLeft; never executed: node->cssFloat = QTextFrameFormat::FloatLeft; | 0 | ||||||||||||||||||
1620 | else if (node->blockFormat.alignment() & Qt::AlignRight)
| 0 | ||||||||||||||||||
1621 | node->cssFloat = QTextFrameFormat::FloatRight; never executed: node->cssFloat = QTextFrameFormat::FloatRight; | 0 | ||||||||||||||||||
1622 | } else if (value == QLatin1String("middle")) { never executed: end of block
| 0 | ||||||||||||||||||
1623 | node->charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); | - | ||||||||||||||||||
1624 | } else if (value == QLatin1String("top")) { never executed: end of block
| 0 | ||||||||||||||||||
1625 | node->charFormat.setVerticalAlignment(QTextCharFormat::AlignTop); | - | ||||||||||||||||||
1626 | } never executed: end of block | 0 | ||||||||||||||||||
1627 | } never executed: end of block | 0 | ||||||||||||||||||
1628 | } else if (key == QLatin1String("valign")) { never executed: end of block
| 0 | ||||||||||||||||||
1629 | value = value.toLower(); | - | ||||||||||||||||||
1630 | if (value == QLatin1String("top"))
| 0 | ||||||||||||||||||
1631 | node->charFormat.setVerticalAlignment(QTextCharFormat::AlignTop); never executed: node->charFormat.setVerticalAlignment(QTextCharFormat::AlignTop); | 0 | ||||||||||||||||||
1632 | else if (value == QLatin1String("middle"))
| 0 | ||||||||||||||||||
1633 | node->charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); never executed: node->charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); | 0 | ||||||||||||||||||
1634 | else if (value == QLatin1String("bottom"))
| 0 | ||||||||||||||||||
1635 | node->charFormat.setVerticalAlignment(QTextCharFormat::AlignBottom); never executed: node->charFormat.setVerticalAlignment(QTextCharFormat::AlignBottom); | 0 | ||||||||||||||||||
1636 | } else if (key == QLatin1String("dir")) { never executed: end of block
| 0 | ||||||||||||||||||
1637 | value = value.toLower(); | - | ||||||||||||||||||
1638 | if (value == QLatin1String("ltr"))
| 0 | ||||||||||||||||||
1639 | node->blockFormat.setLayoutDirection(Qt::LeftToRight); never executed: node->blockFormat.setLayoutDirection(Qt::LeftToRight); | 0 | ||||||||||||||||||
1640 | else if (value == QLatin1String("rtl"))
| 0 | ||||||||||||||||||
1641 | node->blockFormat.setLayoutDirection(Qt::RightToLeft); never executed: node->blockFormat.setLayoutDirection(Qt::RightToLeft); | 0 | ||||||||||||||||||
1642 | } else if (key == QLatin1String("title")) { never executed: end of block
| 0 | ||||||||||||||||||
1643 | node->charFormat.setToolTip(value); | - | ||||||||||||||||||
1644 | } else if (key == QLatin1String("id")) { never executed: end of block
| 0 | ||||||||||||||||||
1645 | node->charFormat.setAnchor(true); | - | ||||||||||||||||||
1646 | node->charFormat.setAnchorName(value); | - | ||||||||||||||||||
1647 | } never executed: end of block | 0 | ||||||||||||||||||
1648 | } never executed: end of block | 0 | ||||||||||||||||||
1649 | - | |||||||||||||||||||
1650 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
1651 | if (resourceProvider && !linkHref.isEmpty() && linkType == QLatin1String("text/css"))
| 0 | ||||||||||||||||||
1652 | importStyleSheet(linkHref); never executed: importStyleSheet(linkHref); | 0 | ||||||||||||||||||
1653 | #endif | - | ||||||||||||||||||
1654 | } never executed: end of block | 0 | ||||||||||||||||||
1655 | - | |||||||||||||||||||
1656 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
1657 | class QTextHtmlStyleSelector : public QCss::StyleSelector | - | ||||||||||||||||||
1658 | { | - | ||||||||||||||||||
1659 | public: | - | ||||||||||||||||||
1660 | inline QTextHtmlStyleSelector(const QTextHtmlParser *parser) | - | ||||||||||||||||||
1661 | : parser(parser) { nameCaseSensitivity = Qt::CaseInsensitive; } never executed: end of block | 0 | ||||||||||||||||||
1662 | - | |||||||||||||||||||
1663 | virtual QStringList nodeNames(NodePtr node) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||
1664 | virtual QString attribute(NodePtr node, const QString &name) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||
1665 | virtual bool hasAttributes(NodePtr node) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||
1666 | virtual bool isNullNode(NodePtr node) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||
1667 | virtual NodePtr parentNode(NodePtr node) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||
1668 | virtual NodePtr previousSiblingNode(NodePtr node) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||
1669 | virtual NodePtr duplicateNode(NodePtr node) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||
1670 | virtual void freeNode(NodePtr node) const Q_DECL_OVERRIDE; | - | ||||||||||||||||||
1671 | - | |||||||||||||||||||
1672 | private: | - | ||||||||||||||||||
1673 | const QTextHtmlParser *parser; | - | ||||||||||||||||||
1674 | }; | - | ||||||||||||||||||
1675 | - | |||||||||||||||||||
1676 | QStringList QTextHtmlStyleSelector::nodeNames(NodePtr node) const | - | ||||||||||||||||||
1677 | { | - | ||||||||||||||||||
1678 | return QStringList(parser->at(node.id).tag.toLower()); never executed: return QStringList(parser->at(node.id).tag.toLower()); | 0 | ||||||||||||||||||
1679 | } | - | ||||||||||||||||||
1680 | - | |||||||||||||||||||
1681 | #endif // QT_NO_CSSPARSER | - | ||||||||||||||||||
1682 | - | |||||||||||||||||||
1683 | static inline int findAttribute(const QStringList &attributes, const QString &name) | - | ||||||||||||||||||
1684 | { | - | ||||||||||||||||||
1685 | int idx = -1; | - | ||||||||||||||||||
1686 | do { | - | ||||||||||||||||||
1687 | idx = attributes.indexOf(name, idx + 1); | - | ||||||||||||||||||
1688 | } while (idx != -1 && (idx % 2 == 1)); never executed: end of block
| 0 | ||||||||||||||||||
1689 | return idx; never executed: return idx; | 0 | ||||||||||||||||||
1690 | } | - | ||||||||||||||||||
1691 | - | |||||||||||||||||||
1692 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
1693 | - | |||||||||||||||||||
1694 | QString QTextHtmlStyleSelector::attribute(NodePtr node, const QString &name) const | - | ||||||||||||||||||
1695 | { | - | ||||||||||||||||||
1696 | const QStringList &attributes = parser->at(node.id).attributes; | - | ||||||||||||||||||
1697 | const int idx = findAttribute(attributes, name); | - | ||||||||||||||||||
1698 | if (idx == -1)
| 0 | ||||||||||||||||||
1699 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
1700 | return attributes.at(idx + 1); never executed: return attributes.at(idx + 1); | 0 | ||||||||||||||||||
1701 | } | - | ||||||||||||||||||
1702 | - | |||||||||||||||||||
1703 | bool QTextHtmlStyleSelector::hasAttributes(NodePtr node) const | - | ||||||||||||||||||
1704 | { | - | ||||||||||||||||||
1705 | const QStringList &attributes = parser->at(node.id).attributes; | - | ||||||||||||||||||
1706 | return !attributes.isEmpty(); never executed: return !attributes.isEmpty(); | 0 | ||||||||||||||||||
1707 | } | - | ||||||||||||||||||
1708 | - | |||||||||||||||||||
1709 | bool QTextHtmlStyleSelector::isNullNode(NodePtr node) const | - | ||||||||||||||||||
1710 | { | - | ||||||||||||||||||
1711 | return node.id == 0; never executed: return node.id == 0; | 0 | ||||||||||||||||||
1712 | } | - | ||||||||||||||||||
1713 | - | |||||||||||||||||||
1714 | QCss::StyleSelector::NodePtr QTextHtmlStyleSelector::parentNode(NodePtr node) const | - | ||||||||||||||||||
1715 | { | - | ||||||||||||||||||
1716 | NodePtr parent; | - | ||||||||||||||||||
1717 | parent.id = 0; | - | ||||||||||||||||||
1718 | if (node.id) {
| 0 | ||||||||||||||||||
1719 | parent.id = parser->at(node.id).parent; | - | ||||||||||||||||||
1720 | } never executed: end of block | 0 | ||||||||||||||||||
1721 | return parent; never executed: return parent; | 0 | ||||||||||||||||||
1722 | } | - | ||||||||||||||||||
1723 | - | |||||||||||||||||||
1724 | QCss::StyleSelector::NodePtr QTextHtmlStyleSelector::duplicateNode(NodePtr node) const | - | ||||||||||||||||||
1725 | { | - | ||||||||||||||||||
1726 | return node; never executed: return node; | 0 | ||||||||||||||||||
1727 | } | - | ||||||||||||||||||
1728 | - | |||||||||||||||||||
1729 | QCss::StyleSelector::NodePtr QTextHtmlStyleSelector::previousSiblingNode(NodePtr node) const | - | ||||||||||||||||||
1730 | { | - | ||||||||||||||||||
1731 | NodePtr sibling; | - | ||||||||||||||||||
1732 | sibling.id = 0; | - | ||||||||||||||||||
1733 | if (!node.id)
| 0 | ||||||||||||||||||
1734 | return sibling; never executed: return sibling; | 0 | ||||||||||||||||||
1735 | int parent = parser->at(node.id).parent; | - | ||||||||||||||||||
1736 | if (!parent)
| 0 | ||||||||||||||||||
1737 | return sibling; never executed: return sibling; | 0 | ||||||||||||||||||
1738 | const int childIdx = parser->at(parent).children.indexOf(node.id); | - | ||||||||||||||||||
1739 | if (childIdx <= 0)
| 0 | ||||||||||||||||||
1740 | return sibling; never executed: return sibling; | 0 | ||||||||||||||||||
1741 | sibling.id = parser->at(parent).children.at(childIdx - 1); | - | ||||||||||||||||||
1742 | return sibling; never executed: return sibling; | 0 | ||||||||||||||||||
1743 | } | - | ||||||||||||||||||
1744 | - | |||||||||||||||||||
1745 | void QTextHtmlStyleSelector::freeNode(NodePtr) const | - | ||||||||||||||||||
1746 | { | - | ||||||||||||||||||
1747 | } | - | ||||||||||||||||||
1748 | - | |||||||||||||||||||
1749 | void QTextHtmlParser::resolveStyleSheetImports(const QCss::StyleSheet &sheet) | - | ||||||||||||||||||
1750 | { | - | ||||||||||||||||||
1751 | for (int i = 0; i < sheet.importRules.count(); ++i) {
| 0 | ||||||||||||||||||
1752 | const QCss::ImportRule &rule = sheet.importRules.at(i); | - | ||||||||||||||||||
1753 | if (rule.media.isEmpty()
| 0 | ||||||||||||||||||
1754 | || rule.media.contains(QLatin1String("screen"), Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
1755 | importStyleSheet(rule.href); never executed: importStyleSheet(rule.href); | 0 | ||||||||||||||||||
1756 | } never executed: end of block | 0 | ||||||||||||||||||
1757 | } never executed: end of block | 0 | ||||||||||||||||||
1758 | - | |||||||||||||||||||
1759 | void QTextHtmlParser::importStyleSheet(const QString &href) | - | ||||||||||||||||||
1760 | { | - | ||||||||||||||||||
1761 | if (!resourceProvider)
| 0 | ||||||||||||||||||
1762 | return; never executed: return; | 0 | ||||||||||||||||||
1763 | for (int i = 0; i < externalStyleSheets.count(); ++i)
| 0 | ||||||||||||||||||
1764 | if (externalStyleSheets.at(i).url == href)
| 0 | ||||||||||||||||||
1765 | return; never executed: return; | 0 | ||||||||||||||||||
1766 | - | |||||||||||||||||||
1767 | QVariant res = resourceProvider->resource(QTextDocument::StyleSheetResource, href); | - | ||||||||||||||||||
1768 | QString css; | - | ||||||||||||||||||
1769 | if (res.type() == QVariant::String) {
| 0 | ||||||||||||||||||
1770 | css = res.toString(); | - | ||||||||||||||||||
1771 | } else if (res.type() == QVariant::ByteArray) { never executed: end of block
| 0 | ||||||||||||||||||
1772 | // #### detect @charset | - | ||||||||||||||||||
1773 | css = QString::fromUtf8(res.toByteArray()); | - | ||||||||||||||||||
1774 | } never executed: end of block | 0 | ||||||||||||||||||
1775 | if (!css.isEmpty()) {
| 0 | ||||||||||||||||||
1776 | QCss::Parser parser(css); | - | ||||||||||||||||||
1777 | QCss::StyleSheet sheet; | - | ||||||||||||||||||
1778 | parser.parse(&sheet, Qt::CaseInsensitive); | - | ||||||||||||||||||
1779 | externalStyleSheets.append(ExternalStyleSheet(href, sheet)); | - | ||||||||||||||||||
1780 | resolveStyleSheetImports(sheet); | - | ||||||||||||||||||
1781 | } never executed: end of block | 0 | ||||||||||||||||||
1782 | } never executed: end of block | 0 | ||||||||||||||||||
1783 | - | |||||||||||||||||||
1784 | QVector<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &node) | - | ||||||||||||||||||
1785 | { | - | ||||||||||||||||||
1786 | QVector<QCss::Declaration> decls; | - | ||||||||||||||||||
1787 | QCss::Declaration decl; | - | ||||||||||||||||||
1788 | QCss::Value val; | - | ||||||||||||||||||
1789 | switch (node.id) { | - | ||||||||||||||||||
1790 | case Html_a: never executed: case Html_a: | 0 | ||||||||||||||||||
1791 | case Html_u: { never executed: case Html_u: | 0 | ||||||||||||||||||
1792 | bool needsUnderline = (node.id == Html_u) ? true : false;
| 0 | ||||||||||||||||||
1793 | if (node.id == Html_a) {
| 0 | ||||||||||||||||||
1794 | for (int i = 0; i < node.attributes.count(); i += 2) {
| 0 | ||||||||||||||||||
1795 | const QString key = node.attributes.at(i); | - | ||||||||||||||||||
1796 | if (key.compare(QLatin1String("href"), Qt::CaseInsensitive) == 0
| 0 | ||||||||||||||||||
1797 | && !node.attributes.at(i + 1).isEmpty()) {
| 0 | ||||||||||||||||||
1798 | needsUnderline = true; | - | ||||||||||||||||||
1799 | decl.d->property = QLatin1String("color"); | - | ||||||||||||||||||
1800 | decl.d->propertyId = QCss::Color; | - | ||||||||||||||||||
1801 | val.type = QCss::Value::Color; | - | ||||||||||||||||||
1802 | val.variant = QVariant(QGuiApplication::palette().link()); | - | ||||||||||||||||||
1803 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1804 | decl.d->inheritable = true; | - | ||||||||||||||||||
1805 | decls << decl; | - | ||||||||||||||||||
1806 | break; never executed: break; | 0 | ||||||||||||||||||
1807 | } | - | ||||||||||||||||||
1808 | } never executed: end of block | 0 | ||||||||||||||||||
1809 | } never executed: end of block | 0 | ||||||||||||||||||
1810 | if (needsUnderline) {
| 0 | ||||||||||||||||||
1811 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1812 | decl.d->property = QLatin1String("text-decoration"); | - | ||||||||||||||||||
1813 | decl.d->propertyId = QCss::TextDecoration; | - | ||||||||||||||||||
1814 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1815 | val.variant = QVariant(QCss::Value_Underline); | - | ||||||||||||||||||
1816 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1817 | decl.d->inheritable = true; | - | ||||||||||||||||||
1818 | decls << decl; | - | ||||||||||||||||||
1819 | } never executed: end of block | 0 | ||||||||||||||||||
1820 | break; never executed: break; | 0 | ||||||||||||||||||
1821 | } | - | ||||||||||||||||||
1822 | case Html_b: never executed: case Html_b: | 0 | ||||||||||||||||||
1823 | case Html_strong: never executed: case Html_strong: | 0 | ||||||||||||||||||
1824 | case Html_h1: never executed: case Html_h1: | 0 | ||||||||||||||||||
1825 | case Html_h2: never executed: case Html_h2: | 0 | ||||||||||||||||||
1826 | case Html_h3: never executed: case Html_h3: | 0 | ||||||||||||||||||
1827 | case Html_h4: never executed: case Html_h4: | 0 | ||||||||||||||||||
1828 | case Html_h5: never executed: case Html_h5: | 0 | ||||||||||||||||||
1829 | case Html_th: never executed: case Html_th: | 0 | ||||||||||||||||||
1830 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1831 | decl.d->property = QLatin1String("font-weight"); | - | ||||||||||||||||||
1832 | decl.d->propertyId = QCss::FontWeight; | - | ||||||||||||||||||
1833 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1834 | val.variant = QVariant(QCss::Value_Bold); | - | ||||||||||||||||||
1835 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1836 | decl.d->inheritable = true; | - | ||||||||||||||||||
1837 | decls << decl; | - | ||||||||||||||||||
1838 | if (node.id == Html_b || node.id == Html_strong)
| 0 | ||||||||||||||||||
1839 | break; never executed: break; | 0 | ||||||||||||||||||
1840 | // Delibrate fall through | - | ||||||||||||||||||
1841 | case Html_big: code before this statement never executed: case Html_big: never executed: case Html_big: | 0 | ||||||||||||||||||
1842 | case Html_small: never executed: case Html_small: | 0 | ||||||||||||||||||
1843 | if (node.id != Html_th) {
| 0 | ||||||||||||||||||
1844 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1845 | decl.d->property = QLatin1String("font-size"); | - | ||||||||||||||||||
1846 | decl.d->propertyId = QCss::FontSize; | - | ||||||||||||||||||
1847 | decl.d->inheritable = false; | - | ||||||||||||||||||
1848 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1849 | switch (node.id) { | - | ||||||||||||||||||
1850 | case Html_h1: val.variant = QVariant(QCss::Value_XXLarge); break; never executed: break; never executed: case Html_h1: | 0 | ||||||||||||||||||
1851 | case Html_h2: val.variant = QVariant(QCss::Value_XLarge); break; never executed: break; never executed: case Html_h2: | 0 | ||||||||||||||||||
1852 | case Html_h3: case Html_big: val.variant = QVariant(QCss::Value_Large); break; never executed: break; never executed: case Html_h3: never executed: case Html_big: | 0 | ||||||||||||||||||
1853 | case Html_h4: val.variant = QVariant(QCss::Value_Medium); break; never executed: break; never executed: case Html_h4: | 0 | ||||||||||||||||||
1854 | case Html_h5: case Html_small: val.variant = QVariant(QCss::Value_Small); break; never executed: break; never executed: case Html_h5: never executed: case Html_small: | 0 | ||||||||||||||||||
1855 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1856 | } | - | ||||||||||||||||||
1857 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1858 | decls << decl; | - | ||||||||||||||||||
1859 | break; never executed: break; | 0 | ||||||||||||||||||
1860 | } | - | ||||||||||||||||||
1861 | // Delibrate fall through | - | ||||||||||||||||||
1862 | case Html_center: code before this statement never executed: case Html_center: never executed: case Html_center: | 0 | ||||||||||||||||||
1863 | case Html_td: never executed: case Html_td: | 0 | ||||||||||||||||||
1864 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1865 | decl.d->property = QLatin1String("text-align"); | - | ||||||||||||||||||
1866 | decl.d->propertyId = QCss::TextAlignment; | - | ||||||||||||||||||
1867 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1868 | val.variant = (node.id == Html_td) ? QVariant(QCss::Value_Left) : QVariant(QCss::Value_Center);
| 0 | ||||||||||||||||||
1869 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1870 | decl.d->inheritable = true; | - | ||||||||||||||||||
1871 | decls << decl; | - | ||||||||||||||||||
1872 | break; never executed: break; | 0 | ||||||||||||||||||
1873 | case Html_s: never executed: case Html_s: | 0 | ||||||||||||||||||
1874 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1875 | decl.d->property = QLatin1String("text-decoration"); | - | ||||||||||||||||||
1876 | decl.d->propertyId = QCss::TextDecoration; | - | ||||||||||||||||||
1877 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1878 | val.variant = QVariant(QCss::Value_LineThrough); | - | ||||||||||||||||||
1879 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1880 | decl.d->inheritable = true; | - | ||||||||||||||||||
1881 | decls << decl; | - | ||||||||||||||||||
1882 | break; never executed: break; | 0 | ||||||||||||||||||
1883 | case Html_em: never executed: case Html_em: | 0 | ||||||||||||||||||
1884 | case Html_i: never executed: case Html_i: | 0 | ||||||||||||||||||
1885 | case Html_cite: never executed: case Html_cite: | 0 | ||||||||||||||||||
1886 | case Html_address: never executed: case Html_address: | 0 | ||||||||||||||||||
1887 | case Html_var: never executed: case Html_var: | 0 | ||||||||||||||||||
1888 | case Html_dfn: never executed: case Html_dfn: | 0 | ||||||||||||||||||
1889 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1890 | decl.d->property = QLatin1String("font-style"); | - | ||||||||||||||||||
1891 | decl.d->propertyId = QCss::FontStyle; | - | ||||||||||||||||||
1892 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1893 | val.variant = QVariant(QCss::Value_Italic); | - | ||||||||||||||||||
1894 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1895 | decl.d->inheritable = true; | - | ||||||||||||||||||
1896 | decls << decl; | - | ||||||||||||||||||
1897 | break; never executed: break; | 0 | ||||||||||||||||||
1898 | case Html_sub: never executed: case Html_sub: | 0 | ||||||||||||||||||
1899 | case Html_sup: never executed: case Html_sup: | 0 | ||||||||||||||||||
1900 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1901 | decl.d->property = QLatin1String("vertical-align"); | - | ||||||||||||||||||
1902 | decl.d->propertyId = QCss::VerticalAlignment; | - | ||||||||||||||||||
1903 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1904 | val.variant = (node.id == Html_sub) ? QVariant(QCss::Value_Sub) : QVariant(QCss::Value_Super);
| 0 | ||||||||||||||||||
1905 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1906 | decl.d->inheritable = true; | - | ||||||||||||||||||
1907 | decls << decl; | - | ||||||||||||||||||
1908 | break; never executed: break; | 0 | ||||||||||||||||||
1909 | case Html_ul: never executed: case Html_ul: | 0 | ||||||||||||||||||
1910 | case Html_ol: never executed: case Html_ol: | 0 | ||||||||||||||||||
1911 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1912 | decl.d->property = QLatin1String("list-style"); | - | ||||||||||||||||||
1913 | decl.d->propertyId = QCss::ListStyle; | - | ||||||||||||||||||
1914 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1915 | val.variant = (node.id == Html_ul) ? QVariant(QCss::Value_Disc) : QVariant(QCss::Value_Decimal);
| 0 | ||||||||||||||||||
1916 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1917 | decl.d->inheritable = true; | - | ||||||||||||||||||
1918 | decls << decl; | - | ||||||||||||||||||
1919 | break; never executed: break; | 0 | ||||||||||||||||||
1920 | case Html_code: never executed: case Html_code: | 0 | ||||||||||||||||||
1921 | case Html_tt: never executed: case Html_tt: | 0 | ||||||||||||||||||
1922 | case Html_kbd: never executed: case Html_kbd: | 0 | ||||||||||||||||||
1923 | case Html_samp: never executed: case Html_samp: | 0 | ||||||||||||||||||
1924 | case Html_pre: { never executed: case Html_pre: | 0 | ||||||||||||||||||
1925 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1926 | decl.d->property = QLatin1String("font-family"); | - | ||||||||||||||||||
1927 | decl.d->propertyId = QCss::FontFamily; | - | ||||||||||||||||||
1928 | QVector<QCss::Value> values; | - | ||||||||||||||||||
1929 | val.type = QCss::Value::String; | - | ||||||||||||||||||
1930 | val.variant = QFontDatabase::systemFont(QFontDatabase::FixedFont).family(); | - | ||||||||||||||||||
1931 | values << val; | - | ||||||||||||||||||
1932 | decl.d->values = values; | - | ||||||||||||||||||
1933 | decl.d->inheritable = true; | - | ||||||||||||||||||
1934 | decls << decl; | - | ||||||||||||||||||
1935 | } | - | ||||||||||||||||||
1936 | if (node.id != Html_pre)
| 0 | ||||||||||||||||||
1937 | break; never executed: break; | 0 | ||||||||||||||||||
1938 | // Delibrate fall through | - | ||||||||||||||||||
1939 | case Html_br: code before this statement never executed: case Html_br: never executed: case Html_br: | 0 | ||||||||||||||||||
1940 | case Html_nobr: never executed: case Html_nobr: | 0 | ||||||||||||||||||
1941 | decl = QCss::Declaration(); | - | ||||||||||||||||||
1942 | decl.d->property = QLatin1String("whitespace"); | - | ||||||||||||||||||
1943 | decl.d->propertyId = QCss::Whitespace; | - | ||||||||||||||||||
1944 | val.type = QCss::Value::KnownIdentifier; | - | ||||||||||||||||||
1945 | switch (node.id) { | - | ||||||||||||||||||
1946 | case Html_br: val.variant = QVariant(QCss::Value_PreWrap); break; never executed: break; never executed: case Html_br: | 0 | ||||||||||||||||||
1947 | case Html_nobr: val.variant = QVariant(QCss::Value_NoWrap); break; never executed: break; never executed: case Html_nobr: | 0 | ||||||||||||||||||
1948 | case Html_pre: val.variant = QVariant(QCss::Value_Pre); break; never executed: break; never executed: case Html_pre: | 0 | ||||||||||||||||||
1949 | default: break; never executed: break; never executed: default: | 0 | ||||||||||||||||||
1950 | } | - | ||||||||||||||||||
1951 | decl.d->values = QVector<QCss::Value>() << val; | - | ||||||||||||||||||
1952 | decl.d->inheritable = true; | - | ||||||||||||||||||
1953 | decls << decl; | - | ||||||||||||||||||
1954 | break; never executed: break; | 0 | ||||||||||||||||||
1955 | default: never executed: default: | 0 | ||||||||||||||||||
1956 | break; never executed: break; | 0 | ||||||||||||||||||
1957 | } | - | ||||||||||||||||||
1958 | return decls; never executed: return decls; | 0 | ||||||||||||||||||
1959 | } | - | ||||||||||||||||||
1960 | - | |||||||||||||||||||
1961 | QVector<QCss::Declaration> QTextHtmlParser::declarationsForNode(int node) const | - | ||||||||||||||||||
1962 | { | - | ||||||||||||||||||
1963 | QVector<QCss::Declaration> decls; | - | ||||||||||||||||||
1964 | - | |||||||||||||||||||
1965 | QTextHtmlStyleSelector selector(this); | - | ||||||||||||||||||
1966 | - | |||||||||||||||||||
1967 | int idx = 0; | - | ||||||||||||||||||
1968 | selector.styleSheets.resize((resourceProvider ? 1 : 0) | - | ||||||||||||||||||
1969 | + externalStyleSheets.count() | - | ||||||||||||||||||
1970 | + inlineStyleSheets.count()); | - | ||||||||||||||||||
1971 | if (resourceProvider)
| 0 | ||||||||||||||||||
1972 | selector.styleSheets[idx++] = resourceProvider->docHandle()->parsedDefaultStyleSheet; never executed: selector.styleSheets[idx++] = resourceProvider->docHandle()->parsedDefaultStyleSheet; | 0 | ||||||||||||||||||
1973 | - | |||||||||||||||||||
1974 | for (int i = 0; i < externalStyleSheets.count(); ++i, ++idx)
| 0 | ||||||||||||||||||
1975 | selector.styleSheets[idx] = externalStyleSheets.at(i).sheet; never executed: selector.styleSheets[idx] = externalStyleSheets.at(i).sheet; | 0 | ||||||||||||||||||
1976 | - | |||||||||||||||||||
1977 | for (int i = 0; i < inlineStyleSheets.count(); ++i, ++idx)
| 0 | ||||||||||||||||||
1978 | selector.styleSheets[idx] = inlineStyleSheets.at(i); never executed: selector.styleSheets[idx] = inlineStyleSheets.at(i); | 0 | ||||||||||||||||||
1979 | - | |||||||||||||||||||
1980 | selector.medium = QLatin1String("screen"); | - | ||||||||||||||||||
1981 | - | |||||||||||||||||||
1982 | QCss::StyleSelector::NodePtr n; | - | ||||||||||||||||||
1983 | n.id = node; | - | ||||||||||||||||||
1984 | - | |||||||||||||||||||
1985 | const char *extraPseudo = 0; | - | ||||||||||||||||||
1986 | if (nodes.at(node).id == Html_a && nodes.at(node).hasHref)
| 0 | ||||||||||||||||||
1987 | extraPseudo = "link"; never executed: extraPseudo = "link"; | 0 | ||||||||||||||||||
1988 | // Ensure that our own style is taken into consideration | - | ||||||||||||||||||
1989 | decls = standardDeclarationForNode(nodes.at(node)); | - | ||||||||||||||||||
1990 | decls += selector.declarationsForNode(n, extraPseudo); | - | ||||||||||||||||||
1991 | n = selector.parentNode(n); | - | ||||||||||||||||||
1992 | while (!selector.isNullNode(n)) {
| 0 | ||||||||||||||||||
1993 | QVector<QCss::Declaration> inheritedDecls; | - | ||||||||||||||||||
1994 | inheritedDecls = selector.declarationsForNode(n, extraPseudo); | - | ||||||||||||||||||
1995 | for (int i = 0; i < inheritedDecls.size(); ++i) {
| 0 | ||||||||||||||||||
1996 | const QCss::Declaration &decl = inheritedDecls.at(i); | - | ||||||||||||||||||
1997 | if (decl.d->inheritable)
| 0 | ||||||||||||||||||
1998 | decls.prepend(decl); never executed: decls.prepend(decl); | 0 | ||||||||||||||||||
1999 | } never executed: end of block | 0 | ||||||||||||||||||
2000 | n = selector.parentNode(n); | - | ||||||||||||||||||
2001 | } never executed: end of block | 0 | ||||||||||||||||||
2002 | return decls; never executed: return decls; | 0 | ||||||||||||||||||
2003 | } | - | ||||||||||||||||||
2004 | - | |||||||||||||||||||
2005 | bool QTextHtmlParser::nodeIsChildOf(int i, QTextHTMLElements id) const | - | ||||||||||||||||||
2006 | { | - | ||||||||||||||||||
2007 | while (i) {
| 0 | ||||||||||||||||||
2008 | if (at(i).id == id)
| 0 | ||||||||||||||||||
2009 | return true; never executed: return true; | 0 | ||||||||||||||||||
2010 | i = at(i).parent; | - | ||||||||||||||||||
2011 | } never executed: end of block | 0 | ||||||||||||||||||
2012 | return false; never executed: return false; | 0 | ||||||||||||||||||
2013 | } | - | ||||||||||||||||||
2014 | - | |||||||||||||||||||
2015 | QT_END_NAMESPACE | - | ||||||||||||||||||
2016 | #endif // QT_NO_CSSPARSER | - | ||||||||||||||||||
2017 | - | |||||||||||||||||||
2018 | #endif // QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |