/src/qtbase/src/gui/text/qcssparser_p.h
Line | Count | Source |
1 | | // Copyright (C) 2016 The Qt Company Ltd. |
2 | | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | | |
4 | | #ifndef QCSSPARSER_P_H |
5 | | #define QCSSPARSER_P_H |
6 | | |
7 | | // |
8 | | // W A R N I N G |
9 | | // ------------- |
10 | | // |
11 | | // This file is not part of the Qt API. It exists purely as an |
12 | | // implementation detail. This header file may change from version to |
13 | | // version without notice, or even be removed. |
14 | | // |
15 | | // We mean it. |
16 | | // |
17 | | |
18 | | #include <QtGui/private/qtguiglobal_p.h> |
19 | | #include <QtCore/QStringList> |
20 | | #include <QtCore/QList> |
21 | | #include <QtCore/QVariant> |
22 | | #include <QtCore/QSize> |
23 | | #include <QtCore/QMultiHash> |
24 | | #include <QtGui/QFont> |
25 | | #include <QtGui/QPalette> |
26 | | #include <QtCore/QSharedData> |
27 | | |
28 | | QT_BEGIN_NAMESPACE |
29 | | class QIcon; |
30 | | QT_END_NAMESPACE |
31 | | |
32 | | #ifndef QT_NO_CSSPARSER |
33 | | |
34 | | // VxWorks defines NONE as (-1) "for times when NULL won't do" |
35 | | #if defined(Q_OS_VXWORKS) && defined(NONE) |
36 | | # undef NONE |
37 | | #endif |
38 | | #if defined(Q_OS_INTEGRITY) |
39 | | # undef Value |
40 | | #endif |
41 | | // Hurd has #define TILDE 0x00080000 from <sys/ioctl.h> |
42 | | #if defined(TILDE) |
43 | | # undef TILDE |
44 | | #endif |
45 | | |
46 | | #define QT_CSS_DECLARE_TYPEINFO(Class, Type) \ |
47 | | } /* namespace QCss */ \ |
48 | | Q_DECLARE_TYPEINFO(QCss:: Class, Type); \ |
49 | | namespace QCss { |
50 | | |
51 | | QT_BEGIN_NAMESPACE |
52 | | |
53 | | namespace QCss |
54 | | { |
55 | | |
56 | | enum Property { |
57 | | UnknownProperty, |
58 | | BackgroundColor, |
59 | | Color, |
60 | | Float, |
61 | | Font, |
62 | | FontFamily, |
63 | | FontSize, |
64 | | FontStyle, |
65 | | FontWeight, |
66 | | Margin, |
67 | | MarginBottom, |
68 | | MarginLeft, |
69 | | MarginRight, |
70 | | MarginTop, |
71 | | QtBlockIndent, |
72 | | QtListIndent, |
73 | | QtParagraphType, |
74 | | QtTableType, |
75 | | QtUserState, |
76 | | TextDecoration, |
77 | | TextIndent, |
78 | | TextUnderlineStyle, |
79 | | VerticalAlignment, |
80 | | Whitespace, |
81 | | QtSelectionForeground, |
82 | | QtSelectionBackground, |
83 | | Border, |
84 | | BorderLeft, |
85 | | BorderRight, |
86 | | BorderTop, |
87 | | BorderBottom, |
88 | | BorderCollapse, |
89 | | Padding, |
90 | | PaddingLeft, |
91 | | PaddingRight, |
92 | | PaddingTop, |
93 | | PaddingBottom, |
94 | | PageBreakBefore, |
95 | | PageBreakAfter, |
96 | | QtAlternateBackground, |
97 | | BorderLeftStyle, |
98 | | BorderRightStyle, |
99 | | BorderTopStyle, |
100 | | BorderBottomStyle, |
101 | | BorderStyles, |
102 | | BorderLeftColor, |
103 | | BorderRightColor, |
104 | | BorderTopColor, |
105 | | BorderBottomColor, |
106 | | BorderColor, |
107 | | BorderLeftWidth, |
108 | | BorderRightWidth, |
109 | | BorderTopWidth, |
110 | | BorderBottomWidth, |
111 | | BorderWidth, |
112 | | BorderTopLeftRadius, |
113 | | BorderTopRightRadius, |
114 | | BorderBottomLeftRadius, |
115 | | BorderBottomRightRadius, |
116 | | BorderRadius, |
117 | | Background, |
118 | | BackgroundOrigin, |
119 | | BackgroundClip, |
120 | | BackgroundRepeat, |
121 | | BackgroundPosition, |
122 | | BackgroundAttachment, |
123 | | BackgroundImage, |
124 | | BorderImage, |
125 | | QtSpacing, |
126 | | Width, |
127 | | Height, |
128 | | MinimumWidth, |
129 | | MinimumHeight, |
130 | | MaximumWidth, |
131 | | MaximumHeight, |
132 | | QtImage, |
133 | | Left, |
134 | | Right, |
135 | | Top, |
136 | | Bottom, |
137 | | QtOrigin, |
138 | | QtPosition, |
139 | | Position, |
140 | | QtStyleFeatures, |
141 | | QtBackgroundRole, |
142 | | ListStyleType, |
143 | | ListStyle, |
144 | | QtImageAlignment, |
145 | | TextAlignment, |
146 | | Outline, |
147 | | OutlineOffset, |
148 | | OutlineWidth, |
149 | | OutlineColor, |
150 | | OutlineStyle, |
151 | | OutlineRadius, |
152 | | OutlineTopLeftRadius, |
153 | | OutlineTopRightRadius, |
154 | | OutlineBottomLeftRadius, |
155 | | OutlineBottomRightRadius, |
156 | | FontVariant, |
157 | | TextTransform, |
158 | | QtListNumberPrefix, |
159 | | QtListNumberSuffix, |
160 | | LineHeight, |
161 | | QtLineHeightType, |
162 | | FontKerning, |
163 | | QtForegroundTextureCacheKey, |
164 | | QtIcon, |
165 | | LetterSpacing, |
166 | | WordSpacing, |
167 | | TextDecorationColor, |
168 | | QtPlaceHolderTextColor, |
169 | | QtAccent, |
170 | | QtStrokeWidth, |
171 | | QtStrokeColor, |
172 | | QtStrokeLineCap, |
173 | | QtStrokeLineJoin, |
174 | | QtStrokeMiterLimit, |
175 | | QtStrokeDashArray, |
176 | | QtStrokeDashOffset, |
177 | | QtForeground, |
178 | | NumProperties |
179 | | }; |
180 | | |
181 | | enum KnownValue { |
182 | | UnknownValue, |
183 | | Value_Normal, |
184 | | Value_Pre, |
185 | | Value_NoWrap, |
186 | | Value_PreLine, |
187 | | Value_PreWrap, |
188 | | Value_Small, |
189 | | Value_Medium, |
190 | | Value_Large, |
191 | | Value_XLarge, |
192 | | Value_XXLarge, |
193 | | Value_Italic, |
194 | | Value_Oblique, |
195 | | Value_Bold, |
196 | | Value_Underline, |
197 | | Value_Overline, |
198 | | Value_LineThrough, |
199 | | Value_Sub, |
200 | | Value_Super, |
201 | | Value_Left, |
202 | | Value_Right, |
203 | | Value_Top, |
204 | | Value_Bottom, |
205 | | Value_Center, |
206 | | Value_Native, |
207 | | Value_Solid, |
208 | | Value_Dotted, |
209 | | Value_Dashed, |
210 | | Value_DotDash, |
211 | | Value_DotDotDash, |
212 | | Value_Double, |
213 | | Value_Groove, |
214 | | Value_Ridge, |
215 | | Value_Inset, |
216 | | Value_Outset, |
217 | | Value_Wave, |
218 | | Value_Middle, |
219 | | Value_Auto, |
220 | | Value_Always, |
221 | | Value_None, |
222 | | Value_Transparent, |
223 | | Value_Disc, |
224 | | Value_Circle, |
225 | | Value_Square, |
226 | | Value_Decimal, |
227 | | Value_LowerAlpha, |
228 | | Value_UpperAlpha, |
229 | | Value_LowerRoman, |
230 | | Value_UpperRoman, |
231 | | Value_SmallCaps, |
232 | | Value_Uppercase, |
233 | | Value_Lowercase, |
234 | | Value_SquareCap, |
235 | | Value_FlatCap, |
236 | | Value_RoundCap, |
237 | | Value_MiterJoin, |
238 | | Value_BevelJoin, |
239 | | Value_RoundJoin, |
240 | | Value_SvgMiterJoin, |
241 | | |
242 | | /* keep these in same order as QPalette::ColorRole */ |
243 | | Value_FirstColorRole, |
244 | | Value_WindowText = Value_FirstColorRole, |
245 | | Value_Button, |
246 | | Value_Light, |
247 | | Value_Midlight, |
248 | | Value_Dark, |
249 | | Value_Mid, |
250 | | Value_Text, |
251 | | Value_BrightText, |
252 | | Value_ButtonText, |
253 | | Value_Base, |
254 | | Value_Window, |
255 | | Value_Shadow, |
256 | | Value_Highlight, |
257 | | Value_HighlightedText, |
258 | | Value_Link, |
259 | | Value_LinkVisited, |
260 | | Value_AlternateBase, |
261 | | Value_NoRole, |
262 | | Value_ToolTipBase, |
263 | | Value_ToolTipText, |
264 | | Value_PlaceholderText, |
265 | | Value_Accent, |
266 | | Value_LastColorRole = Value_Accent, |
267 | | |
268 | | Value_Disabled, |
269 | | Value_Active, |
270 | | Value_Selected, |
271 | | Value_On, |
272 | | Value_Off, |
273 | | |
274 | | NumKnownValues |
275 | | }; |
276 | | |
277 | | enum BorderStyle { |
278 | | BorderStyle_Unknown, |
279 | | BorderStyle_None, |
280 | | BorderStyle_Dotted, |
281 | | BorderStyle_Dashed, |
282 | | BorderStyle_Solid, |
283 | | BorderStyle_Double, |
284 | | BorderStyle_DotDash, |
285 | | BorderStyle_DotDotDash, |
286 | | BorderStyle_Groove, |
287 | | BorderStyle_Ridge, |
288 | | BorderStyle_Inset, |
289 | | BorderStyle_Outset, |
290 | | BorderStyle_Native, |
291 | | NumKnownBorderStyles |
292 | | }; |
293 | | |
294 | | enum Edge { |
295 | | TopEdge, |
296 | | RightEdge, |
297 | | BottomEdge, |
298 | | LeftEdge, |
299 | | NumEdges |
300 | | }; |
301 | | |
302 | | enum Corner { |
303 | | TopLeftCorner, |
304 | | TopRightCorner, |
305 | | BottomLeftCorner, |
306 | | BottomRightCorner |
307 | | }; |
308 | | |
309 | | enum TileMode { |
310 | | TileMode_Unknown, |
311 | | TileMode_Round, |
312 | | TileMode_Stretch, |
313 | | TileMode_Repeat, |
314 | | NumKnownTileModes |
315 | | }; |
316 | | |
317 | | enum Repeat { |
318 | | Repeat_Unknown, |
319 | | Repeat_None, |
320 | | Repeat_X, |
321 | | Repeat_Y, |
322 | | Repeat_XY, |
323 | | NumKnownRepeats |
324 | | }; |
325 | | |
326 | | enum Origin { |
327 | | Origin_Unknown, |
328 | | Origin_Padding, |
329 | | Origin_Border, |
330 | | Origin_Content, |
331 | | Origin_Margin, |
332 | | NumKnownOrigins |
333 | | }; |
334 | | |
335 | | enum PositionMode { |
336 | | PositionMode_Unknown, |
337 | | PositionMode_Static, |
338 | | PositionMode_Relative, |
339 | | PositionMode_Absolute, |
340 | | PositionMode_Fixed, |
341 | | NumKnownPositionModes |
342 | | }; |
343 | | |
344 | | enum Attachment { |
345 | | Attachment_Unknown, |
346 | | Attachment_Fixed, |
347 | | Attachment_Scroll, |
348 | | NumKnownAttachments |
349 | | }; |
350 | | |
351 | | enum StyleFeature { |
352 | | StyleFeature_None = 0, |
353 | | StyleFeature_BackgroundColor = 1, |
354 | | StyleFeature_BackgroundGradient = 2, |
355 | | NumKnownStyleFeatures = 4 |
356 | | }; |
357 | | |
358 | | struct Value |
359 | | { |
360 | | enum Type { |
361 | | Unknown, |
362 | | Number, |
363 | | Percentage, |
364 | | Length, |
365 | | String, |
366 | | Identifier, |
367 | | KnownIdentifier, |
368 | | Uri, |
369 | | Color, |
370 | | Function, |
371 | | TermOperatorSlash, |
372 | | TermOperatorComma |
373 | | }; |
374 | 1.17M | inline Value() : type(Unknown) { } |
375 | | Type type; |
376 | | QVariant variant; |
377 | | |
378 | | Q_GUI_EXPORT QString toString() const; |
379 | | }; |
380 | | QT_CSS_DECLARE_TYPEINFO(Value, Q_RELOCATABLE_TYPE) |
381 | | |
382 | | struct ColorData { |
383 | 0 | ColorData() : role(QPalette::NoRole), type(Invalid) {} |
384 | 0 | ColorData(const QColor &col) : color(col), role(QPalette::NoRole), type(Color) {} |
385 | 0 | ColorData(QPalette::ColorRole r) : role(r), type(Role) {} |
386 | | QColor color; |
387 | | QPalette::ColorRole role; |
388 | | enum { Invalid, Color, Role} type; |
389 | | }; |
390 | | QT_CSS_DECLARE_TYPEINFO(ColorData, Q_RELOCATABLE_TYPE) |
391 | | |
392 | | struct BrushData { |
393 | 0 | BrushData() : role(QPalette::NoRole), type(Invalid) {} |
394 | 0 | BrushData(const QBrush &br) : brush(br), role(QPalette::NoRole), type(Brush) {} |
395 | 0 | BrushData(QPalette::ColorRole r) : role(r), type(Role) {} |
396 | | QBrush brush; |
397 | | QPalette::ColorRole role; |
398 | | enum { Invalid, Brush, Role, DependsOnThePalette } type; |
399 | | }; |
400 | | QT_CSS_DECLARE_TYPEINFO(BrushData, Q_RELOCATABLE_TYPE) |
401 | | |
402 | | struct BackgroundData { |
403 | | BrushData brush; |
404 | | QString image; |
405 | | Repeat repeat; |
406 | | Qt::Alignment alignment; |
407 | | }; |
408 | | QT_CSS_DECLARE_TYPEINFO(BackgroundData, Q_RELOCATABLE_TYPE) |
409 | | |
410 | | struct LengthData { |
411 | | qreal number; |
412 | | enum { None, Px, Ex, Em, Percent } unit; |
413 | | }; |
414 | | QT_CSS_DECLARE_TYPEINFO(LengthData, Q_PRIMITIVE_TYPE) |
415 | | |
416 | | struct BorderData { |
417 | | LengthData width; |
418 | | BorderStyle style; |
419 | | BrushData color; |
420 | | }; |
421 | | QT_CSS_DECLARE_TYPEINFO(BorderData, Q_RELOCATABLE_TYPE) |
422 | | |
423 | | // 1. StyleRule - x:hover, y:clicked > z:checked { prop1: value1; prop2: value2; } |
424 | | // 2. QList<Selector> - x:hover, y:clicked z:checked |
425 | | // 3. QList<BasicSelector> - y:clicked z:checked |
426 | | // 4. QList<Declaration> - { prop1: value1; prop2: value2; } |
427 | | // 5. Declaration - prop1: value1; |
428 | | |
429 | | struct Q_GUI_EXPORT Declaration |
430 | | { |
431 | | struct DeclarationData : public QSharedData |
432 | | { |
433 | 461k | inline DeclarationData() : propertyId(UnknownProperty), important(false), inheritable(false) {} |
434 | | QString property; |
435 | | Property propertyId; |
436 | | QList<Value> values; |
437 | | QVariant parsed; |
438 | | bool important:1; |
439 | | bool inheritable:1; |
440 | | }; |
441 | | QExplicitlySharedDataPointer<DeclarationData> d; |
442 | 461k | inline Declaration() : d(new DeclarationData()) {} |
443 | 356k | inline bool isEmpty() const { return d->property.isEmpty() && d->propertyId == UnknownProperty; } |
444 | | |
445 | | // helper functions |
446 | | QColor colorValue(const QPalette & = QPalette()) const; |
447 | | void colorValues(QColor *c, const QPalette & = QPalette()) const; |
448 | | QBrush brushValue(const QPalette & = QPalette()) const; |
449 | | void brushValues(QBrush *c, const QPalette & = QPalette()) const; |
450 | | |
451 | | BorderStyle styleValue() const; |
452 | | void styleValues(BorderStyle *s) const; |
453 | | |
454 | | Origin originValue() const; |
455 | | Repeat repeatValue() const; |
456 | | Qt::Alignment alignmentValue() const; |
457 | | PositionMode positionValue() const; |
458 | | Attachment attachmentValue() const; |
459 | | int styleFeaturesValue() const; |
460 | | |
461 | | bool intValue(int *i, const char *unit = nullptr) const; |
462 | | bool realValue(qreal *r, const char *unit = nullptr) const; |
463 | | |
464 | | QSize sizeValue() const; |
465 | | QRect rectValue() const; |
466 | | QString uriValue() const; |
467 | | QIcon iconValue() const; |
468 | | |
469 | | void borderImageValue(QString *image, int *cuts, TileMode *h, TileMode *v) const; |
470 | | bool borderCollapseValue() const; |
471 | | |
472 | | QList<qreal> dashArray() const; |
473 | | }; |
474 | | QT_CSS_DECLARE_TYPEINFO(Declaration, Q_RELOCATABLE_TYPE) |
475 | | |
476 | | const quint64 PseudoClass_Unknown = Q_UINT64_C(0x0000000000000000); |
477 | | const quint64 PseudoClass_Enabled = Q_UINT64_C(0x0000000000000001); |
478 | | const quint64 PseudoClass_Disabled = Q_UINT64_C(0x0000000000000002); |
479 | | const quint64 PseudoClass_Pressed = Q_UINT64_C(0x0000000000000004); |
480 | | const quint64 PseudoClass_Focus = Q_UINT64_C(0x0000000000000008); |
481 | | const quint64 PseudoClass_Hover = Q_UINT64_C(0x0000000000000010); |
482 | | const quint64 PseudoClass_Checked = Q_UINT64_C(0x0000000000000020); |
483 | | const quint64 PseudoClass_Unchecked = Q_UINT64_C(0x0000000000000040); |
484 | | const quint64 PseudoClass_Indeterminate = Q_UINT64_C(0x0000000000000080); |
485 | | const quint64 PseudoClass_Unspecified = Q_UINT64_C(0x0000000000000100); |
486 | | const quint64 PseudoClass_Selected = Q_UINT64_C(0x0000000000000200); |
487 | | const quint64 PseudoClass_Horizontal = Q_UINT64_C(0x0000000000000400); |
488 | | const quint64 PseudoClass_Vertical = Q_UINT64_C(0x0000000000000800); |
489 | | const quint64 PseudoClass_Window = Q_UINT64_C(0x0000000000001000); |
490 | | const quint64 PseudoClass_Children = Q_UINT64_C(0x0000000000002000); |
491 | | const quint64 PseudoClass_Sibling = Q_UINT64_C(0x0000000000004000); |
492 | | const quint64 PseudoClass_Default = Q_UINT64_C(0x0000000000008000); |
493 | | const quint64 PseudoClass_First = Q_UINT64_C(0x0000000000010000); |
494 | | const quint64 PseudoClass_Last = Q_UINT64_C(0x0000000000020000); |
495 | | const quint64 PseudoClass_Middle = Q_UINT64_C(0x0000000000040000); |
496 | | const quint64 PseudoClass_OnlyOne = Q_UINT64_C(0x0000000000080000); |
497 | | const quint64 PseudoClass_PreviousSelected = Q_UINT64_C(0x0000000000100000); |
498 | | const quint64 PseudoClass_NextSelected = Q_UINT64_C(0x0000000000200000); |
499 | | const quint64 PseudoClass_Flat = Q_UINT64_C(0x0000000000400000); |
500 | | const quint64 PseudoClass_Left = Q_UINT64_C(0x0000000000800000); |
501 | | const quint64 PseudoClass_Right = Q_UINT64_C(0x0000000001000000); |
502 | | const quint64 PseudoClass_Top = Q_UINT64_C(0x0000000002000000); |
503 | | const quint64 PseudoClass_Bottom = Q_UINT64_C(0x0000000004000000); |
504 | | const quint64 PseudoClass_Exclusive = Q_UINT64_C(0x0000000008000000); |
505 | | const quint64 PseudoClass_NonExclusive = Q_UINT64_C(0x0000000010000000); |
506 | | const quint64 PseudoClass_Frameless = Q_UINT64_C(0x0000000020000000); |
507 | | const quint64 PseudoClass_ReadOnly = Q_UINT64_C(0x0000000040000000); |
508 | | const quint64 PseudoClass_Active = Q_UINT64_C(0x0000000080000000); |
509 | | const quint64 PseudoClass_Closable = Q_UINT64_C(0x0000000100000000); |
510 | | const quint64 PseudoClass_Movable = Q_UINT64_C(0x0000000200000000); |
511 | | const quint64 PseudoClass_Floatable = Q_UINT64_C(0x0000000400000000); |
512 | | const quint64 PseudoClass_Minimized = Q_UINT64_C(0x0000000800000000); |
513 | | const quint64 PseudoClass_Maximized = Q_UINT64_C(0x0000001000000000); |
514 | | const quint64 PseudoClass_On = Q_UINT64_C(0x0000002000000000); |
515 | | const quint64 PseudoClass_Off = Q_UINT64_C(0x0000004000000000); |
516 | | const quint64 PseudoClass_Editable = Q_UINT64_C(0x0000008000000000); |
517 | | const quint64 PseudoClass_Item = Q_UINT64_C(0x0000010000000000); |
518 | | const quint64 PseudoClass_Closed = Q_UINT64_C(0x0000020000000000); |
519 | | const quint64 PseudoClass_Open = Q_UINT64_C(0x0000040000000000); |
520 | | const quint64 PseudoClass_EditFocus = Q_UINT64_C(0x0000080000000000); |
521 | | const quint64 PseudoClass_Alternate = Q_UINT64_C(0x0000100000000000); |
522 | | // The Any specifier is never generated, but can be used as a wildcard in searches. |
523 | | const quint64 PseudoClass_Any = Q_UINT64_C(0x0000ffffffffffff); |
524 | | const int NumPseudos = 45; |
525 | | |
526 | | struct Pseudo |
527 | | { |
528 | 84.7k | Pseudo() : type(0), negated(false) { } |
529 | | quint64 type; |
530 | | QString name; |
531 | | QString function; |
532 | | bool negated; |
533 | | }; |
534 | | QT_CSS_DECLARE_TYPEINFO(Pseudo, Q_RELOCATABLE_TYPE) |
535 | | |
536 | | struct AttributeSelector |
537 | | { |
538 | | enum ValueMatchType { |
539 | | NoMatch, |
540 | | MatchEqual, |
541 | | MatchIncludes, |
542 | | MatchDashMatch, |
543 | | MatchBeginsWith, |
544 | | MatchEndsWith, |
545 | | MatchContains |
546 | | }; |
547 | | |
548 | | QString name; |
549 | | QString value; |
550 | | ValueMatchType valueMatchCriterium = NoMatch; |
551 | | }; |
552 | | QT_CSS_DECLARE_TYPEINFO(AttributeSelector, Q_RELOCATABLE_TYPE) |
553 | | |
554 | | struct BasicSelector |
555 | | { |
556 | 1.05M | inline BasicSelector() : relationToNext(NoRelation) {} |
557 | | |
558 | | enum Relation { |
559 | | NoRelation, |
560 | | MatchNextSelectorIfAncestor, |
561 | | MatchNextSelectorIfParent, |
562 | | MatchNextSelectorIfDirectAdjecent, |
563 | | MatchNextSelectorIfIndirectAdjecent, |
564 | | }; |
565 | | |
566 | | QString elementName; |
567 | | |
568 | | QStringList ids; |
569 | | QList<Pseudo> pseudos; |
570 | | QList<AttributeSelector> attributeSelectors; |
571 | | |
572 | | Relation relationToNext; |
573 | | }; |
574 | | QT_CSS_DECLARE_TYPEINFO(BasicSelector, Q_RELOCATABLE_TYPE) |
575 | | |
576 | | struct Q_GUI_EXPORT Selector |
577 | | { |
578 | | QList<BasicSelector> basicSelectors; |
579 | | int specificity() const; |
580 | | quint64 pseudoClass(quint64 *negated = nullptr) const; |
581 | | QString pseudoElement() const; |
582 | | }; |
583 | | QT_CSS_DECLARE_TYPEINFO(Selector, Q_RELOCATABLE_TYPE) |
584 | | |
585 | | struct StyleRule |
586 | | { |
587 | 901k | StyleRule() : order(0) { } |
588 | | QList<Selector> selectors; |
589 | | QList<Declaration> declarations; |
590 | | int order; |
591 | | }; |
592 | | QT_CSS_DECLARE_TYPEINFO(StyleRule, Q_RELOCATABLE_TYPE) |
593 | | |
594 | | struct MediaRule |
595 | | { |
596 | | QStringList media; |
597 | | QList<StyleRule> styleRules; |
598 | | }; |
599 | | QT_CSS_DECLARE_TYPEINFO(MediaRule, Q_RELOCATABLE_TYPE) |
600 | | |
601 | | struct PageRule |
602 | | { |
603 | | QString selector; |
604 | | QList<Declaration> declarations; |
605 | | }; |
606 | | QT_CSS_DECLARE_TYPEINFO(PageRule, Q_RELOCATABLE_TYPE) |
607 | | |
608 | | struct AnimationRule |
609 | | { |
610 | | struct AnimationRuleSet |
611 | | { |
612 | | float keyFrame; |
613 | | QList<Declaration> declarations; |
614 | | Declaration timingFunction; |
615 | | }; |
616 | | |
617 | | QString animName; |
618 | | QList<AnimationRuleSet> ruleSets; |
619 | | }; |
620 | | QT_CSS_DECLARE_TYPEINFO(AnimationRule, Q_RELOCATABLE_TYPE) |
621 | | |
622 | | struct ImportRule |
623 | | { |
624 | | QString href; |
625 | | QStringList media; |
626 | | }; |
627 | | QT_CSS_DECLARE_TYPEINFO(ImportRule, Q_RELOCATABLE_TYPE) |
628 | | |
629 | | enum StyleSheetOrigin { |
630 | | StyleSheetOrigin_Unspecified, |
631 | | StyleSheetOrigin_UserAgent, |
632 | | StyleSheetOrigin_User, |
633 | | StyleSheetOrigin_Author, |
634 | | StyleSheetOrigin_Inline |
635 | | }; |
636 | | |
637 | | struct StyleSheet |
638 | | { |
639 | 17.9k | StyleSheet() : origin(StyleSheetOrigin_Unspecified), depth(0) { } |
640 | | QList<StyleRule> styleRules; // only contains rules that are not indexed |
641 | | QList<MediaRule> mediaRules; |
642 | | QList<PageRule> pageRules; |
643 | | QList<AnimationRule> animationRules; |
644 | | QList<ImportRule> importRules; |
645 | | StyleSheetOrigin origin; |
646 | | int depth; // applicable only for inline style sheets |
647 | | QMultiHash<QString, StyleRule> nameIndex; |
648 | | QMultiHash<QString, StyleRule> idIndex; |
649 | | |
650 | | Q_GUI_EXPORT void buildIndexes(Qt::CaseSensitivity nameCaseSensitivity = Qt::CaseSensitive); |
651 | | }; |
652 | | QT_CSS_DECLARE_TYPEINFO(StyleSheet, Q_RELOCATABLE_TYPE) |
653 | | |
654 | | |
655 | | class Q_GUI_EXPORT StyleSelector |
656 | | { |
657 | | public: |
658 | 0 | StyleSelector() : nameCaseSensitivity(Qt::CaseSensitive) {} |
659 | | virtual ~StyleSelector(); |
660 | | |
661 | | union NodePtr { |
662 | | void *ptr; |
663 | | int id; |
664 | | }; |
665 | | |
666 | | QList<StyleRule> styleRulesForNode(NodePtr node); |
667 | | QList<Declaration> declarationsForNode(NodePtr node, const char *extraPseudo = nullptr); |
668 | | |
669 | | virtual bool nodeNameEquals(NodePtr node, const QString& nodeName) const; |
670 | | virtual QString attributeValue(NodePtr node, const QCss::AttributeSelector &aSelector) const = 0; |
671 | | virtual bool hasAttributes(NodePtr node) const = 0; |
672 | | virtual QStringList nodeIds(NodePtr node) const; |
673 | | virtual QStringList nodeNames(NodePtr node) const = 0; |
674 | | virtual bool isNullNode(NodePtr node) const = 0; |
675 | | virtual NodePtr parentNode(NodePtr node) const = 0; |
676 | | virtual NodePtr previousSiblingNode(NodePtr node) const = 0; |
677 | | virtual NodePtr duplicateNode(NodePtr node) const = 0; |
678 | | virtual void freeNode(NodePtr node) const = 0; |
679 | | |
680 | | QList<StyleSheet> styleSheets; |
681 | | QString medium; |
682 | | Qt::CaseSensitivity nameCaseSensitivity; |
683 | | private: |
684 | | void matchRule(NodePtr node, const StyleRule &rules, StyleSheetOrigin origin, |
685 | | int depth, std::multimap<uint64_t, StyleRule> *weightedRules) const; |
686 | | bool selectorMatches(const Selector &rule, NodePtr node) const; |
687 | | bool basicSelectorMatches(const BasicSelector &rule, NodePtr node) const; |
688 | | }; |
689 | | |
690 | | enum TokenType { |
691 | | NONE, |
692 | | |
693 | | S, |
694 | | |
695 | | CDO, |
696 | | CDC, |
697 | | INCLUDES, |
698 | | DASHMATCH, |
699 | | BEGINSWITH, |
700 | | ENDSWITH, |
701 | | CONTAINS, |
702 | | |
703 | | LBRACE, |
704 | | PLUS, |
705 | | GREATER, |
706 | | COMMA, |
707 | | TILDE, |
708 | | |
709 | | STRING, |
710 | | INVALID, |
711 | | |
712 | | IDENT, |
713 | | |
714 | | HASH, |
715 | | |
716 | | ATKEYWORD_SYM, |
717 | | |
718 | | EXCLAMATION_SYM, |
719 | | |
720 | | LENGTH, |
721 | | |
722 | | PERCENTAGE, |
723 | | NUMBER, |
724 | | |
725 | | FUNCTION, |
726 | | |
727 | | COLON, |
728 | | SEMICOLON, |
729 | | RBRACE, |
730 | | SLASH, |
731 | | MINUS, |
732 | | DOT, |
733 | | STAR, |
734 | | LBRACKET, |
735 | | RBRACKET, |
736 | | EQUAL, |
737 | | LPAREN, |
738 | | RPAREN, |
739 | | OR |
740 | | }; |
741 | | |
742 | | struct Symbol |
743 | | { |
744 | 988k | inline Symbol() : token(NONE), start(0), len(-1) {} |
745 | | TokenType token; |
746 | | QString text; |
747 | | int start, len; |
748 | | Q_GUI_EXPORT QString lexem() const; |
749 | | }; |
750 | | QT_CSS_DECLARE_TYPEINFO(Symbol, Q_RELOCATABLE_TYPE) |
751 | | |
752 | | class Q_GUI_EXPORT Scanner |
753 | | { |
754 | | public: |
755 | | static QString preprocess(const QString &input, bool *hasEscapeSequences = nullptr); |
756 | | static void scan(const QString &preprocessedInput, QList<Symbol> *symbols); |
757 | | }; |
758 | | |
759 | | class Q_GUI_EXPORT Parser |
760 | | { |
761 | | public: |
762 | | Parser(); |
763 | | explicit Parser(const QString &css, bool file = false); |
764 | | |
765 | | void init(const QString &css, bool file = false); |
766 | | bool parse(StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity = Qt::CaseSensitive); |
767 | | Symbol errorSymbol(); |
768 | | |
769 | | bool parseImport(ImportRule *importRule); |
770 | | bool parseMedia(MediaRule *mediaRule); |
771 | | bool parseMedium(QStringList *media); |
772 | | bool parsePage(PageRule *pageRule); |
773 | | bool parsePseudoPage(QString *selector); |
774 | | bool parseNextOperator(Value *value); |
775 | | bool parseAnimation(AnimationRule *animationRule); |
776 | | bool parseCombinator(BasicSelector::Relation *relation); |
777 | | bool parseProperty(Declaration *decl); |
778 | | bool parseRuleset(StyleRule *styleRule); |
779 | | bool parseSelector(Selector *sel); |
780 | | bool parseSimpleSelector(BasicSelector *basicSel); |
781 | | bool parseClass(QString *name); |
782 | | bool parseElementName(QString *name); |
783 | | bool parseAttrib(AttributeSelector *attr); |
784 | | bool parsePseudo(Pseudo *pseudo); |
785 | | bool parseNextDeclaration(Declaration *declaration); |
786 | | bool parsePrio(Declaration *declaration); |
787 | | bool parseExpr(QList<Value> *values); |
788 | | bool parseTerm(Value *value); |
789 | | bool parseFunction(QString *name, QString *args); |
790 | | bool parseHexColor(QColor *col); |
791 | | bool testAndParseUri(QString *uri); |
792 | | |
793 | 1.06M | inline bool testRuleset() { return testSelector(); } |
794 | 1.09M | inline bool testSelector() { return testSimpleSelector(); } |
795 | 25.3k | inline bool parseNextSelector(Selector *sel) { if (!testSelector()) return recordError(); return parseSelector(sel); } |
796 | | bool testSimpleSelector(); |
797 | 0 | inline bool parseNextSimpleSelector(BasicSelector *basicSel) { if (!testSimpleSelector()) return recordError(); return parseSimpleSelector(basicSel); } |
798 | 1.40M | inline bool testElementName() { return test(IDENT) || test(STAR); } |
799 | 1.91M | inline bool testClass() { return test(DOT); } |
800 | 1.49M | inline bool testAttrib() { return test(LBRACKET); } |
801 | 1.45M | inline bool testPseudo() { return test(COLON); } |
802 | 0 | inline bool testMedium() { return test(IDENT); } |
803 | 0 | inline bool parseNextMedium(QStringList *media) { if (!testMedium()) return recordError(); return parseMedium(media); } |
804 | 11 | inline bool testPseudoPage() { return test(COLON); } |
805 | 887k | inline bool testImport() { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1StringView("import")); } |
806 | 1.06M | inline bool testMedia() { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1StringView("media")); } |
807 | 1.06M | inline bool testPage() { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1StringView("page")); } |
808 | 1.06M | inline bool testAnimation() { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1StringView("keyframes")); } |
809 | 999k | inline bool testCombinator() { return test(PLUS) || test(GREATER) || test(TILDE) || test(S); } |
810 | 441k | inline bool testProperty() { return test(IDENT); } |
811 | | bool testTerm(); |
812 | 285k | inline bool testExpr() { return testTerm(); } |
813 | | inline bool parseNextExpr(QList<Value> *values) |
814 | 285k | { |
815 | 285k | if (!testExpr()) |
816 | 3.83k | return recordError(); |
817 | 281k | return parseExpr(values); |
818 | 285k | } |
819 | | bool testPrio(); |
820 | 487k | inline bool testHexColor() { return test(HASH); } |
821 | 252k | inline bool testFunction() { return test(FUNCTION); } |
822 | 0 | inline bool parseNextFunction(QString *name, QString *args) { if (!testFunction()) return recordError(); return parseFunction(name, args); } |
823 | | |
824 | 1.05M | inline bool lookupElementName() const { return lookup() == IDENT || lookup() == STAR; } |
825 | | |
826 | 4.33M | inline void skipSpace() { while (test(S)) {}; } |
827 | | |
828 | 2.82M | inline bool hasNext() const { return index < symbols.size(); } |
829 | 1.95M | inline TokenType next() { return symbols.at(index++).token; } |
830 | | bool next(TokenType t); |
831 | | bool test(TokenType t); |
832 | 1.11M | inline void prev() { index--; } |
833 | 2.26M | inline const Symbol &symbol() const { return symbols.at(index - 1); } |
834 | 2.26M | inline QString lexem() const { return symbol().lexem(); } |
835 | | QString unquotedLexem() const; |
836 | | QString lexemUntil(TokenType t); |
837 | | bool until(TokenType target, TokenType target2 = NONE); |
838 | 4.29M | inline TokenType lookup() const { |
839 | 4.29M | return (index - 1) < symbols.size() ? symbols.at(index - 1).token : NONE; |
840 | 4.29M | } |
841 | | |
842 | | bool testTokenAndEndsWith(TokenType t, QLatin1StringView str); |
843 | | |
844 | 619k | inline bool recordError() { errorIndex = index; return false; } |
845 | | |
846 | | QList<Symbol> symbols; |
847 | | int index; |
848 | | int errorIndex; |
849 | | bool hasEscapeSequences; |
850 | | QString sourcePath; |
851 | | }; |
852 | | |
853 | | struct Q_GUI_EXPORT ValueExtractor |
854 | | { |
855 | | ValueExtractor(const QList<Declaration> &declarations, const QPalette & = QPalette()); |
856 | | |
857 | | bool extractFont(QFont *font, int *fontSizeAdjustment); |
858 | | bool extractBackground(QBrush *, QString *, Repeat *, Qt::Alignment *, QCss::Origin *, QCss::Attachment *, |
859 | | QCss::Origin *) const; |
860 | | bool extractGeometry(int *w, int *h, int *minw, int *minh, int *maxw, int *maxh); |
861 | | bool extractPosition(int *l, int *t, int *r, int *b, QCss::Origin *, Qt::Alignment *, |
862 | | QCss::PositionMode *, Qt::Alignment *); |
863 | | bool extractBox(int *margins, int *paddings, int *spacing = nullptr); |
864 | | bool extractBorder(int *borders, QBrush *colors, BorderStyle *Styles, QSize *radii); |
865 | | bool extractOutline(int *borders, QBrush *colors, BorderStyle *Styles, QSize *radii, int *offsets); |
866 | | bool extractPalette(QBrush *foreground, QBrush *selectedForeground, QBrush *selectedBackground, |
867 | | QBrush *alternateBackground, QBrush *placeHolderTextForeground, |
868 | | QBrush *accent) const; |
869 | | int extractStyleFeatures() const; |
870 | | bool extractImage(QIcon *icon, Qt::Alignment *a, QSize *size) const; |
871 | | bool extractIcon(QIcon *icon, QSize *size) const; |
872 | | |
873 | | void lengthValues(const Declaration &decl, int *m); |
874 | | QTextLength textLength(const Declaration &decl); |
875 | | |
876 | | private: |
877 | | void extractFont(); |
878 | | void borderValue(const Declaration &decl, int *width, QCss::BorderStyle *style, QBrush *color); |
879 | | LengthData lengthValue(const Value& v); |
880 | | int lengthValue(const Declaration &decl); |
881 | | QSize sizeValue(const Declaration &decl); |
882 | | void sizeValues(const Declaration &decl, QSize *radii); |
883 | | |
884 | | QList<Declaration> declarations; |
885 | | QFont f; |
886 | | int adjustment; |
887 | | int fontExtracted; |
888 | | QPalette pal; |
889 | | }; |
890 | | |
891 | | } // namespace QCss |
892 | | |
893 | | QT_END_NAMESPACE |
894 | | |
895 | 0 | QT_DECL_METATYPE_EXTERN_TAGGED(QCss::BackgroundData, QCss__BackgroundData, Q_GUI_EXPORT) Unexecuted instantiation: int qRegisterNormalizedMetaType<QCss::BackgroundData>(QByteArray const&) Unexecuted instantiation: QMetaTypeId<QCss::BackgroundData>::qt_metatype_id() |
896 | 0 | QT_DECL_METATYPE_EXTERN_TAGGED(QCss::LengthData, QCss__LengthData, Q_GUI_EXPORT) Unexecuted instantiation: int qRegisterNormalizedMetaType<QCss::LengthData>(QByteArray const&) Unexecuted instantiation: QMetaTypeId<QCss::LengthData>::qt_metatype_id() |
897 | | QT_DECL_METATYPE_EXTERN_TAGGED(QCss::BorderData, QCss__BorderData, Q_GUI_EXPORT) Unexecuted instantiation: int qRegisterNormalizedMetaType<QCss::BorderData>(QByteArray const&) Unexecuted instantiation: QMetaTypeId<QCss::BorderData>::qt_metatype_id() |
898 | | |
899 | | #undef QT_CSS_DECLARE_TYPEINFO |
900 | | |
901 | | #endif // QT_NO_CSSPARSER |
902 | | |
903 | | #endif |