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

source code of qtbase/src/gui/text/qcssparser_p.h