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