qtexthtmlparser.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9