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