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