/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 | | QtPlaceHolderText, |
169 | | QtAccent, |
170 | | QtStrokeWidth, |
171 | | QtStrokeColor, |
172 | | QtStrokeLineCap, |
173 | | QtStrokeLineJoin, |
174 | | QtStrokeMiterLimit, |
175 | | QtStrokeDashArray, |
176 | | QtStrokeDashOffset, |
177 | | QtForeground, |
178 | | }; |
179 | | |
180 | | enum KnownValue { |
181 | | UnknownValue, |
182 | | Value_Normal, |
183 | | Value_Pre, |
184 | | Value_NoWrap, |
185 | | Value_PreLine, |
186 | | Value_PreWrap, |
187 | | Value_Small, |
188 | | Value_Medium, |
189 | | Value_Large, |
190 | | Value_XLarge, |
191 | | Value_XXLarge, |
192 | | Value_Italic, |
193 | | Value_Oblique, |
194 | | Value_Bold, |
195 | | Value_Underline, |
196 | | Value_Overline, |
197 | | Value_LineThrough, |
198 | | Value_Sub, |
199 | | Value_Super, |
200 | | Value_Left, |
201 | | Value_Right, |
202 | | Value_Top, |
203 | | Value_Bottom, |
204 | | Value_Center, |
205 | | Value_Native, |
206 | | Value_Solid, |
207 | | Value_Dotted, |
208 | | Value_Dashed, |
209 | | Value_DotDash, |
210 | | Value_DotDotDash, |
211 | | Value_Double, |
212 | | Value_Groove, |
213 | | Value_Ridge, |
214 | | Value_Inset, |
215 | | Value_Outset, |
216 | | Value_Wave, |
217 | | Value_Middle, |
218 | | Value_Auto, |
219 | | Value_Always, |
220 | | Value_None, |
221 | | Value_Transparent, |
222 | | Value_Disc, |
223 | | Value_Circle, |
224 | | Value_Square, |
225 | | Value_Decimal, |
226 | | Value_LowerAlpha, |
227 | | Value_UpperAlpha, |
228 | | Value_LowerRoman, |
229 | | Value_UpperRoman, |
230 | | Value_SmallCaps, |
231 | | Value_Uppercase, |
232 | | Value_Lowercase, |
233 | | Value_SquareCap, |
234 | | Value_FlatCap, |
235 | | Value_RoundCap, |
236 | | Value_MiterJoin, |
237 | | Value_BevelJoin, |
238 | | Value_RoundJoin, |
239 | | Value_SvgMiterJoin, |
240 | | |
241 | | /* keep these in same order as QPalette::ColorRole */ |
242 | | Value_FirstColorRole, |
243 | | Value_WindowText = Value_FirstColorRole, |
244 | | Value_Button, |
245 | | Value_Light, |
246 | | Value_Midlight, |
247 | | Value_Dark, |
248 | | Value_Mid, |
249 | | Value_Text, |
250 | | Value_BrightText, |
251 | | Value_ButtonText, |
252 | | Value_Base, |
253 | | Value_Window, |
254 | | Value_Shadow, |
255 | | Value_Highlight, |
256 | | Value_HighlightedText, |
257 | | Value_Link, |
258 | | Value_LinkVisited, |
259 | | Value_AlternateBase, |
260 | | Value_NoRole, |
261 | | Value_ToolTipBase, |
262 | | Value_ToolTipText, |
263 | | Value_PlaceholderText, |
264 | | Value_Accent, |
265 | | Value_LastColorRole = Value_Accent, |
266 | | |
267 | | Value_Disabled, |
268 | | Value_Active, |
269 | | Value_Selected, |
270 | | Value_On, |
271 | | Value_Off, |
272 | | }; |
273 | | |
274 | | enum BorderStyle { |
275 | | BorderStyle_Unknown, |
276 | | BorderStyle_None, |
277 | | BorderStyle_Dotted, |
278 | | BorderStyle_Dashed, |
279 | | BorderStyle_Solid, |
280 | | BorderStyle_Double, |
281 | | BorderStyle_DotDash, |
282 | | BorderStyle_DotDotDash, |
283 | | BorderStyle_Groove, |
284 | | BorderStyle_Ridge, |
285 | | BorderStyle_Inset, |
286 | | BorderStyle_Outset, |
287 | | BorderStyle_Native, |
288 | | }; |
289 | | |
290 | | enum Edge { |
291 | | TopEdge, |
292 | | RightEdge, |
293 | | BottomEdge, |
294 | | LeftEdge, |
295 | | NumEdges |
296 | | }; |
297 | | |
298 | | enum TileMode { |
299 | | TileMode_Unknown, |
300 | | TileMode_Round, |
301 | | TileMode_Stretch, |
302 | | TileMode_Repeat, |
303 | | }; |
304 | | |
305 | | enum Repeat { |
306 | | Repeat_Unknown, |
307 | | Repeat_None, |
308 | | Repeat_X, |
309 | | Repeat_Y, |
310 | | Repeat_XY, |
311 | | }; |
312 | | |
313 | | enum Origin { |
314 | | Origin_Unknown, |
315 | | Origin_Padding, |
316 | | Origin_Border, |
317 | | Origin_Content, |
318 | | Origin_Margin, |
319 | | }; |
320 | | |
321 | | enum PositionMode { |
322 | | PositionMode_Unknown, |
323 | | PositionMode_Static, |
324 | | PositionMode_Relative, |
325 | | PositionMode_Absolute, |
326 | | PositionMode_Fixed, |
327 | | }; |
328 | | |
329 | | enum Attachment { |
330 | | Attachment_Unknown, |
331 | | Attachment_Fixed, |
332 | | Attachment_Scroll, |
333 | | }; |
334 | | |
335 | | enum StyleFeature { |
336 | | StyleFeature_None = 0, |
337 | | StyleFeature_BackgroundColor = 1, |
338 | | StyleFeature_BackgroundGradient = 2, |
339 | | }; |
340 | | |
341 | | struct Value |
342 | | { |
343 | | enum Type { |
344 | | Unknown, |
345 | | Number, |
346 | | Percentage, |
347 | | Length, |
348 | | String, |
349 | | Identifier, |
350 | | KnownIdentifier, |
351 | | Uri, |
352 | | Color, |
353 | | Function, |
354 | | TermOperatorSlash, |
355 | | TermOperatorComma |
356 | | }; |
357 | 0 | inline Value() : type(Unknown) { } |
358 | | Type type; |
359 | | QVariant variant; |
360 | | |
361 | | Q_GUI_EXPORT QString toString() const; |
362 | | }; |
363 | | QT_CSS_DECLARE_TYPEINFO(Value, Q_RELOCATABLE_TYPE) |
364 | | |
365 | | struct ColorData { |
366 | 0 | ColorData() : role(QPalette::NoRole), type(Invalid) {} |
367 | 0 | ColorData(const QColor &col) : color(col), role(QPalette::NoRole), type(Color) {} |
368 | 0 | ColorData(QPalette::ColorRole r) : role(r), type(Role) {} |
369 | | QColor color; |
370 | | QPalette::ColorRole role; |
371 | | enum { Invalid, Color, Role} type; |
372 | | }; |
373 | | QT_CSS_DECLARE_TYPEINFO(ColorData, Q_RELOCATABLE_TYPE) |
374 | | |
375 | | struct BrushData { |
376 | 0 | BrushData() : role(QPalette::NoRole), type(Invalid) {} |
377 | 0 | BrushData(const QBrush &br) : brush(br), role(QPalette::NoRole), type(Brush) {} |
378 | 0 | BrushData(QPalette::ColorRole r) : role(r), type(Role) {} |
379 | | QBrush brush; |
380 | | QPalette::ColorRole role; |
381 | | enum { Invalid, Brush, Role, DependsOnThePalette } type; |
382 | | }; |
383 | | QT_CSS_DECLARE_TYPEINFO(BrushData, Q_RELOCATABLE_TYPE) |
384 | | |
385 | | struct BackgroundData { |
386 | | BrushData brush; |
387 | | QString image; |
388 | | Repeat repeat; |
389 | | Qt::Alignment alignment; |
390 | | }; |
391 | | QT_CSS_DECLARE_TYPEINFO(BackgroundData, Q_RELOCATABLE_TYPE) |
392 | | |
393 | | struct LengthData { |
394 | | qreal number; |
395 | | enum { None, Px, Ex, Em, Percent } unit; |
396 | | }; |
397 | | QT_CSS_DECLARE_TYPEINFO(LengthData, Q_PRIMITIVE_TYPE) |
398 | | |
399 | | struct BorderData { |
400 | | LengthData width; |
401 | | BorderStyle style; |
402 | | BrushData color; |
403 | | }; |
404 | | QT_CSS_DECLARE_TYPEINFO(BorderData, Q_RELOCATABLE_TYPE) |
405 | | |
406 | | // 1. StyleRule - x:hover, y:clicked > z:checked { prop1: value1; prop2: value2; } |
407 | | // 2. QList<Selector> - x:hover, y:clicked z:checked |
408 | | // 3. QList<BasicSelector> - y:clicked z:checked |
409 | | // 4. QList<Declaration> - { prop1: value1; prop2: value2; } |
410 | | // 5. Declaration - prop1: value1; |
411 | | |
412 | | struct Q_GUI_EXPORT Declaration |
413 | | { |
414 | | struct DeclarationData : public QSharedData |
415 | | { |
416 | 0 | inline DeclarationData() : propertyId(UnknownProperty), important(false), inheritable(false) {} |
417 | | QString property; |
418 | | Property propertyId; |
419 | | QList<Value> values; |
420 | | QVariant parsed; |
421 | | bool important:1; |
422 | | bool inheritable:1; |
423 | | }; |
424 | | QExplicitlySharedDataPointer<DeclarationData> d; |
425 | 0 | inline Declaration() : d(new DeclarationData()) {} |
426 | 0 | inline bool isEmpty() const { return d->property.isEmpty() && d->propertyId == UnknownProperty; } |
427 | | |
428 | | // helper functions |
429 | | QColor colorValue(const QPalette & = QPalette()) const; |
430 | | void colorValues(QColor *c, const QPalette & = QPalette()) const; |
431 | | QBrush brushValue(const QPalette & = QPalette()) const; |
432 | | void brushValues(QBrush *c, const QPalette & = QPalette()) const; |
433 | | |
434 | | BorderStyle styleValue() const; |
435 | | void styleValues(BorderStyle *s) const; |
436 | | |
437 | | Origin originValue() const; |
438 | | Repeat repeatValue() const; |
439 | | Qt::Alignment alignmentValue() const; |
440 | | PositionMode positionValue() const; |
441 | | Attachment attachmentValue() const; |
442 | | int styleFeaturesValue() const; |
443 | | |
444 | | bool intValue(int *i, const char *unit = nullptr) const; |
445 | | bool realValue(qreal *r, const char *unit = nullptr) const; |
446 | | |
447 | | QSize sizeValue() const; |
448 | | QRect rectValue() const; |
449 | | QString uriValue() const; |
450 | | QIcon iconValue() const; |
451 | | |
452 | | void borderImageValue(QString *image, int *cuts, TileMode *h, TileMode *v) const; |
453 | | bool borderCollapseValue() const; |
454 | | |
455 | | QList<qreal> dashArray() const; |
456 | | }; |
457 | | QT_CSS_DECLARE_TYPEINFO(Declaration, Q_RELOCATABLE_TYPE) |
458 | | |
459 | | const quint64 PseudoClass_Unknown = Q_UINT64_C(0x0000000000000000); |
460 | | const quint64 PseudoClass_Enabled = Q_UINT64_C(0x0000000000000001); |
461 | | const quint64 PseudoClass_Disabled = Q_UINT64_C(0x0000000000000002); |
462 | | const quint64 PseudoClass_Pressed = Q_UINT64_C(0x0000000000000004); |
463 | | const quint64 PseudoClass_Focus = Q_UINT64_C(0x0000000000000008); |
464 | | const quint64 PseudoClass_Hover = Q_UINT64_C(0x0000000000000010); |
465 | | const quint64 PseudoClass_Checked = Q_UINT64_C(0x0000000000000020); |
466 | | const quint64 PseudoClass_Unchecked = Q_UINT64_C(0x0000000000000040); |
467 | | const quint64 PseudoClass_Indeterminate = Q_UINT64_C(0x0000000000000080); |
468 | | const quint64 PseudoClass_Unspecified = Q_UINT64_C(0x0000000000000100); |
469 | | const quint64 PseudoClass_Selected = Q_UINT64_C(0x0000000000000200); |
470 | | const quint64 PseudoClass_Horizontal = Q_UINT64_C(0x0000000000000400); |
471 | | const quint64 PseudoClass_Vertical = Q_UINT64_C(0x0000000000000800); |
472 | | const quint64 PseudoClass_Window = Q_UINT64_C(0x0000000000001000); |
473 | | const quint64 PseudoClass_Children = Q_UINT64_C(0x0000000000002000); |
474 | | const quint64 PseudoClass_Sibling = Q_UINT64_C(0x0000000000004000); |
475 | | const quint64 PseudoClass_Default = Q_UINT64_C(0x0000000000008000); |
476 | | const quint64 PseudoClass_First = Q_UINT64_C(0x0000000000010000); |
477 | | const quint64 PseudoClass_Last = Q_UINT64_C(0x0000000000020000); |
478 | | const quint64 PseudoClass_Middle = Q_UINT64_C(0x0000000000040000); |
479 | | const quint64 PseudoClass_OnlyOne = Q_UINT64_C(0x0000000000080000); |
480 | | const quint64 PseudoClass_PreviousSelected = Q_UINT64_C(0x0000000000100000); |
481 | | const quint64 PseudoClass_NextSelected = Q_UINT64_C(0x0000000000200000); |
482 | | const quint64 PseudoClass_Flat = Q_UINT64_C(0x0000000000400000); |
483 | | const quint64 PseudoClass_Left = Q_UINT64_C(0x0000000000800000); |
484 | | const quint64 PseudoClass_Right = Q_UINT64_C(0x0000000001000000); |
485 | | const quint64 PseudoClass_Top = Q_UINT64_C(0x0000000002000000); |
486 | | const quint64 PseudoClass_Bottom = Q_UINT64_C(0x0000000004000000); |
487 | | const quint64 PseudoClass_Exclusive = Q_UINT64_C(0x0000000008000000); |
488 | | const quint64 PseudoClass_NonExclusive = Q_UINT64_C(0x0000000010000000); |
489 | | const quint64 PseudoClass_Frameless = Q_UINT64_C(0x0000000020000000); |
490 | | const quint64 PseudoClass_ReadOnly = Q_UINT64_C(0x0000000040000000); |
491 | | const quint64 PseudoClass_Active = Q_UINT64_C(0x0000000080000000); |
492 | | const quint64 PseudoClass_Closable = Q_UINT64_C(0x0000000100000000); |
493 | | const quint64 PseudoClass_Movable = Q_UINT64_C(0x0000000200000000); |
494 | | const quint64 PseudoClass_Floatable = Q_UINT64_C(0x0000000400000000); |
495 | | const quint64 PseudoClass_Minimized = Q_UINT64_C(0x0000000800000000); |
496 | | const quint64 PseudoClass_Maximized = Q_UINT64_C(0x0000001000000000); |
497 | | const quint64 PseudoClass_On = Q_UINT64_C(0x0000002000000000); |
498 | | const quint64 PseudoClass_Off = Q_UINT64_C(0x0000004000000000); |
499 | | const quint64 PseudoClass_Editable = Q_UINT64_C(0x0000008000000000); |
500 | | const quint64 PseudoClass_Item = Q_UINT64_C(0x0000010000000000); |
501 | | const quint64 PseudoClass_Closed = Q_UINT64_C(0x0000020000000000); |
502 | | const quint64 PseudoClass_Open = Q_UINT64_C(0x0000040000000000); |
503 | | const quint64 PseudoClass_EditFocus = Q_UINT64_C(0x0000080000000000); |
504 | | const quint64 PseudoClass_Alternate = Q_UINT64_C(0x0000100000000000); |
505 | | // The Any specifier is never generated, but can be used as a wildcard in searches. |
506 | | const quint64 PseudoClass_Any = Q_UINT64_C(0x0000ffffffffffff); |
507 | | const int NumPseudos = 45; |
508 | | |
509 | | struct Pseudo |
510 | | { |
511 | 0 | Pseudo() : type(0), negated(false) { } |
512 | | quint64 type; |
513 | | QString name; |
514 | | QString function; |
515 | | bool negated; |
516 | | }; |
517 | | QT_CSS_DECLARE_TYPEINFO(Pseudo, Q_RELOCATABLE_TYPE) |
518 | | |
519 | | struct AttributeSelector |
520 | | { |
521 | | enum ValueMatchType { |
522 | | NoMatch, |
523 | | MatchEqual, |
524 | | MatchIncludes, |
525 | | MatchDashMatch, |
526 | | MatchBeginsWith, |
527 | | MatchEndsWith, |
528 | | MatchContains |
529 | | }; |
530 | | |
531 | | QString name; |
532 | | QString value; |
533 | | ValueMatchType valueMatchCriterium = NoMatch; |
534 | | }; |
535 | | QT_CSS_DECLARE_TYPEINFO(AttributeSelector, Q_RELOCATABLE_TYPE) |
536 | | |
537 | | struct BasicSelector |
538 | | { |
539 | 0 | inline BasicSelector() : relationToNext(NoRelation) {} |
540 | | |
541 | | enum Relation { |
542 | | NoRelation, |
543 | | MatchNextSelectorIfAncestor, |
544 | | MatchNextSelectorIfParent, |
545 | | MatchNextSelectorIfDirectAdjecent, |
546 | | MatchNextSelectorIfIndirectAdjecent, |
547 | | }; |
548 | | |
549 | | QString elementName; |
550 | | |
551 | | QStringList ids; |
552 | | QList<Pseudo> pseudos; |
553 | | QList<AttributeSelector> attributeSelectors; |
554 | | |
555 | | Relation relationToNext; |
556 | | }; |
557 | | QT_CSS_DECLARE_TYPEINFO(BasicSelector, Q_RELOCATABLE_TYPE) |
558 | | |
559 | | struct Q_GUI_EXPORT Selector |
560 | | { |
561 | | QList<BasicSelector> basicSelectors; |
562 | | int specificity() const; |
563 | | quint64 pseudoClass(quint64 *negated = nullptr) const; |
564 | | QString pseudoElement() const; |
565 | | }; |
566 | | QT_CSS_DECLARE_TYPEINFO(Selector, Q_RELOCATABLE_TYPE) |
567 | | |
568 | | struct StyleRule |
569 | | { |
570 | 0 | StyleRule() : order(0) { } |
571 | | QList<Selector> selectors; |
572 | | QList<Declaration> declarations; |
573 | | int order; |
574 | | }; |
575 | | QT_CSS_DECLARE_TYPEINFO(StyleRule, Q_RELOCATABLE_TYPE) |
576 | | |
577 | | struct MediaRule |
578 | | { |
579 | | QStringList media; |
580 | | QList<StyleRule> styleRules; |
581 | | }; |
582 | | QT_CSS_DECLARE_TYPEINFO(MediaRule, Q_RELOCATABLE_TYPE) |
583 | | |
584 | | struct PageRule |
585 | | { |
586 | | QString selector; |
587 | | QList<Declaration> declarations; |
588 | | }; |
589 | | QT_CSS_DECLARE_TYPEINFO(PageRule, Q_RELOCATABLE_TYPE) |
590 | | |
591 | | struct AnimationRule |
592 | | { |
593 | | struct AnimationRuleSet |
594 | | { |
595 | | float keyFrame; |
596 | | QList<Declaration> declarations; |
597 | | Declaration timingFunction; |
598 | | }; |
599 | | |
600 | | QString animName; |
601 | | QList<AnimationRuleSet> ruleSets; |
602 | | }; |
603 | | QT_CSS_DECLARE_TYPEINFO(AnimationRule, Q_RELOCATABLE_TYPE) |
604 | | |
605 | | struct ImportRule |
606 | | { |
607 | | QString href; |
608 | | QStringList media; |
609 | | }; |
610 | | QT_CSS_DECLARE_TYPEINFO(ImportRule, Q_RELOCATABLE_TYPE) |
611 | | |
612 | | enum StyleSheetOrigin { |
613 | | StyleSheetOrigin_Unspecified, |
614 | | StyleSheetOrigin_UserAgent, |
615 | | StyleSheetOrigin_User, |
616 | | StyleSheetOrigin_Author, |
617 | | StyleSheetOrigin_Inline |
618 | | }; |
619 | | |
620 | | struct StyleSheet |
621 | | { |
622 | 0 | StyleSheet() : origin(StyleSheetOrigin_Unspecified), depth(0) { } |
623 | | QList<StyleRule> styleRules; // only contains rules that are not indexed |
624 | | QList<MediaRule> mediaRules; |
625 | | QList<PageRule> pageRules; |
626 | | QList<AnimationRule> animationRules; |
627 | | QList<ImportRule> importRules; |
628 | | StyleSheetOrigin origin; |
629 | | int depth; // applicable only for inline style sheets |
630 | | QMultiHash<QString, StyleRule> nameIndex; |
631 | | QMultiHash<QString, StyleRule> idIndex; |
632 | | |
633 | | Q_GUI_EXPORT void buildIndexes(Qt::CaseSensitivity nameCaseSensitivity = Qt::CaseSensitive); |
634 | | }; |
635 | | QT_CSS_DECLARE_TYPEINFO(StyleSheet, Q_RELOCATABLE_TYPE) |
636 | | |
637 | | |
638 | | class Q_GUI_EXPORT StyleSelector |
639 | | { |
640 | | public: |
641 | 0 | StyleSelector() : nameCaseSensitivity(Qt::CaseSensitive) {} |
642 | | virtual ~StyleSelector(); |
643 | | |
644 | | union NodePtr { |
645 | | void *ptr; |
646 | | int id; |
647 | | }; |
648 | | |
649 | | QList<StyleRule> styleRulesForNode(NodePtr node); |
650 | | QList<Declaration> declarationsForNode(NodePtr node, const char *extraPseudo = nullptr); |
651 | | |
652 | | virtual bool nodeNameEquals(NodePtr node, const QString& nodeName) const; |
653 | | virtual QString attributeValue(NodePtr node, const QCss::AttributeSelector &aSelector) const = 0; |
654 | | virtual bool hasAttributes(NodePtr node) const = 0; |
655 | | virtual QStringList nodeIds(NodePtr node) const; |
656 | | virtual QStringList nodeNames(NodePtr node) const = 0; |
657 | | virtual bool isNullNode(NodePtr node) const = 0; |
658 | | virtual NodePtr parentNode(NodePtr node) const = 0; |
659 | | virtual NodePtr previousSiblingNode(NodePtr node) const = 0; |
660 | | virtual NodePtr duplicateNode(NodePtr node) const = 0; |
661 | | virtual void freeNode(NodePtr node) const = 0; |
662 | | |
663 | | QList<StyleSheet> styleSheets; |
664 | | QString medium; |
665 | | Qt::CaseSensitivity nameCaseSensitivity; |
666 | | private: |
667 | | void matchRule(NodePtr node, const StyleRule &rules, StyleSheetOrigin origin, |
668 | | int depth, std::multimap<uint64_t, StyleRule> *weightedRules) const; |
669 | | bool selectorMatches(const Selector &rule, NodePtr node) const; |
670 | | bool basicSelectorMatches(const BasicSelector &rule, NodePtr node) const; |
671 | | }; |
672 | | |
673 | | enum TokenType { |
674 | | NONE, |
675 | | |
676 | | S, |
677 | | |
678 | | CDO, |
679 | | CDC, |
680 | | INCLUDES, |
681 | | DASHMATCH, |
682 | | BEGINSWITH, |
683 | | ENDSWITH, |
684 | | CONTAINS, |
685 | | |
686 | | LBRACE, |
687 | | PLUS, |
688 | | GREATER, |
689 | | COMMA, |
690 | | TILDE, |
691 | | |
692 | | STRING, |
693 | | INVALID, |
694 | | |
695 | | IDENT, |
696 | | |
697 | | HASH, |
698 | | |
699 | | ATKEYWORD_SYM, |
700 | | |
701 | | EXCLAMATION_SYM, |
702 | | |
703 | | LENGTH, |
704 | | |
705 | | PERCENTAGE, |
706 | | NUMBER, |
707 | | |
708 | | FUNCTION, |
709 | | |
710 | | COLON, |
711 | | SEMICOLON, |
712 | | RBRACE, |
713 | | SLASH, |
714 | | MINUS, |
715 | | DOT, |
716 | | STAR, |
717 | | LBRACKET, |
718 | | RBRACKET, |
719 | | EQUAL, |
720 | | LPAREN, |
721 | | RPAREN, |
722 | | OR |
723 | | }; |
724 | | |
725 | | struct Symbol |
726 | | { |
727 | 0 | inline Symbol() : token(NONE), start(0), len(-1) {} |
728 | | TokenType token; |
729 | | QString text; |
730 | | int start, len; |
731 | | Q_GUI_EXPORT QString lexem() const; |
732 | | }; |
733 | | QT_CSS_DECLARE_TYPEINFO(Symbol, Q_RELOCATABLE_TYPE) |
734 | | |
735 | | class Q_GUI_EXPORT Scanner |
736 | | { |
737 | | public: |
738 | | static QString preprocess(const QString &input, bool *hasEscapeSequences = nullptr); |
739 | | static void scan(const QString &preprocessedInput, QList<Symbol> *symbols); |
740 | | }; |
741 | | |
742 | | class Q_GUI_EXPORT Parser |
743 | | { |
744 | | public: |
745 | | Parser(); |
746 | | explicit Parser(const QString &css, bool file = false); |
747 | | |
748 | | void init(const QString &css, bool file = false); |
749 | | bool parse(StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity = Qt::CaseSensitive); |
750 | | Symbol errorSymbol(); |
751 | | |
752 | | bool parseImport(ImportRule *importRule); |
753 | | bool parseMedia(MediaRule *mediaRule); |
754 | | bool parseMedium(QStringList *media); |
755 | | bool parsePage(PageRule *pageRule); |
756 | | bool parsePseudoPage(QString *selector); |
757 | | bool parseNextOperator(Value *value); |
758 | | bool parseAnimation(AnimationRule *animationRule); |
759 | | bool parseCombinator(BasicSelector::Relation *relation); |
760 | | bool parseProperty(Declaration *decl); |
761 | | bool parseRuleset(StyleRule *styleRule); |
762 | | bool parseSelector(Selector *sel); |
763 | | bool parseSimpleSelector(BasicSelector *basicSel); |
764 | | bool parseClass(QString *name); |
765 | | bool parseElementName(QString *name); |
766 | | bool parseAttrib(AttributeSelector *attr); |
767 | | bool parsePseudo(Pseudo *pseudo); |
768 | | bool parseNextDeclaration(Declaration *declaration); |
769 | | bool parsePrio(Declaration *declaration); |
770 | | bool parseExpr(QList<Value> *values); |
771 | | bool parseTerm(Value *value); |
772 | | bool parseFunction(QString *name, QString *args); |
773 | | bool parseHexColor(QColor *col); |
774 | | bool testAndParseUri(QString *uri); |
775 | | |
776 | 0 | inline bool testRuleset() { return testSelector(); } |
777 | 0 | inline bool testSelector() { return testSimpleSelector(); } |
778 | 0 | inline bool parseNextSelector(Selector *sel) { if (!testSelector()) return recordError(); return parseSelector(sel); } |
779 | | bool testSimpleSelector(); |
780 | 0 | inline bool parseNextSimpleSelector(BasicSelector *basicSel) { if (!testSimpleSelector()) return recordError(); return parseSimpleSelector(basicSel); } |
781 | 0 | inline bool testElementName() { return test(IDENT) || test(STAR); } |
782 | 0 | inline bool testClass() { return test(DOT); } |
783 | 0 | inline bool testAttrib() { return test(LBRACKET); } |
784 | 0 | inline bool testPseudo() { return test(COLON); } |
785 | 0 | inline bool testMedium() { return test(IDENT); } |
786 | 0 | inline bool parseNextMedium(QStringList *media) { if (!testMedium()) return recordError(); return parseMedium(media); } |
787 | 0 | inline bool testPseudoPage() { return test(COLON); } |
788 | 0 | inline bool testImport() { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1StringView("import")); } |
789 | 0 | inline bool testMedia() { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1StringView("media")); } |
790 | 0 | inline bool testPage() { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1StringView("page")); } |
791 | 0 | inline bool testAnimation() { return testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1StringView("keyframes")); } |
792 | 0 | inline bool testCombinator() { return test(PLUS) || test(GREATER) || test(TILDE) || test(S); } |
793 | 0 | inline bool testProperty() { return test(IDENT); } |
794 | | bool testTerm(); |
795 | 0 | inline bool testExpr() { return testTerm(); } |
796 | | inline bool parseNextExpr(QList<Value> *values) |
797 | 0 | { |
798 | 0 | if (!testExpr()) |
799 | 0 | return recordError(); |
800 | 0 | return parseExpr(values); |
801 | 0 | } |
802 | | bool testPrio(); |
803 | 0 | inline bool testHexColor() { return test(HASH); } |
804 | 0 | inline bool testFunction() { return test(FUNCTION); } |
805 | 0 | inline bool parseNextFunction(QString *name, QString *args) { if (!testFunction()) return recordError(); return parseFunction(name, args); } |
806 | | |
807 | 0 | inline bool lookupElementName() const { return lookup() == IDENT || lookup() == STAR; } |
808 | | |
809 | 0 | inline void skipSpace() { while (test(S)) {}; } |
810 | | |
811 | 0 | inline bool hasNext() const { return index < symbols.size(); } |
812 | 0 | inline TokenType next() { return symbols.at(index++).token; } |
813 | | bool next(TokenType t); |
814 | | bool test(TokenType t); |
815 | 0 | inline void prev() { index--; } |
816 | 0 | inline const Symbol &symbol() const { return symbols.at(index - 1); } |
817 | 0 | inline QString lexem() const { return symbol().lexem(); } |
818 | | QString unquotedLexem() const; |
819 | | QString lexemUntil(TokenType t); |
820 | | bool until(TokenType target, TokenType target2 = NONE); |
821 | 0 | inline TokenType lookup() const { |
822 | 0 | return (index - 1) < symbols.size() ? symbols.at(index - 1).token : NONE; |
823 | 0 | } |
824 | | |
825 | | bool testTokenAndEndsWith(TokenType t, QLatin1StringView str); |
826 | | |
827 | 0 | inline bool recordError() { errorIndex = index; return false; } |
828 | | |
829 | | QList<Symbol> symbols; |
830 | | int index; |
831 | | int errorIndex; |
832 | | bool hasEscapeSequences; |
833 | | QString sourcePath; |
834 | | }; |
835 | | |
836 | | struct Q_GUI_EXPORT ValueExtractor |
837 | | { |
838 | | ValueExtractor(const QList<Declaration> &declarations, const QPalette & = QPalette()); |
839 | | |
840 | | bool extractFont(QFont *font, int *fontSizeAdjustment); |
841 | | bool extractBackground(QBrush *, QString *, Repeat *, Qt::Alignment *, QCss::Origin *, QCss::Attachment *, |
842 | | QCss::Origin *) const; |
843 | | bool extractGeometry(int *w, int *h, int *minw, int *minh, int *maxw, int *maxh); |
844 | | bool extractPosition(int *l, int *t, int *r, int *b, QCss::Origin *, Qt::Alignment *, |
845 | | QCss::PositionMode *, Qt::Alignment *); |
846 | | bool extractBox(int *margins, int *paddings, int *spacing = nullptr); |
847 | | bool extractBorder(int *borders, QBrush *colors, BorderStyle *Styles, QSize *radii); |
848 | | bool extractOutline(int *borders, QBrush *colors, BorderStyle *Styles, QSize *radii, int *offsets); |
849 | | bool extractPalette(QBrush *foreground, QBrush *selectedForeground, QBrush *selectedBackground, |
850 | | QBrush *alternateBackground, QBrush *placeHolderTextForeground, |
851 | | QBrush *accent) const; |
852 | | int extractStyleFeatures() const; |
853 | | bool extractImage(QIcon *icon, Qt::Alignment *a, QSize *size) const; |
854 | | bool extractIcon(QIcon *icon, QSize *size) const; |
855 | | |
856 | | void lengthValues(const Declaration &decl, int *m); |
857 | | QTextLength textLength(const Declaration &decl); |
858 | | |
859 | | private: |
860 | | void extractFont(); |
861 | | void borderValue(const Declaration &decl, int *width, QCss::BorderStyle *style, QBrush *color); |
862 | | LengthData lengthValue(const Value& v); |
863 | | int lengthValue(const Declaration &decl); |
864 | | QSize sizeValue(const Declaration &decl); |
865 | | void sizeValues(const Declaration &decl, QSize *radii); |
866 | | |
867 | | QList<Declaration> declarations; |
868 | | QFont f; |
869 | | int adjustment; |
870 | | int fontExtracted; |
871 | | QPalette pal; |
872 | | }; |
873 | | |
874 | | } // namespace QCss |
875 | | |
876 | | QT_END_NAMESPACE |
877 | | |
878 | 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() |
879 | 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() |
880 | | 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() |
881 | | |
882 | | #undef QT_CSS_DECLARE_TYPEINFO |
883 | | |
884 | | #endif // QT_NO_CSSPARSER |
885 | | |
886 | | #endif |