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