| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qcssparser.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qcssparser_p.h" | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #include <qdebug.h> | - | ||||||||||||||||||
| 37 | #include <qicon.h> | - | ||||||||||||||||||
| 38 | #include <qcolor.h> | - | ||||||||||||||||||
| 39 | #include <qfont.h> | - | ||||||||||||||||||
| 40 | #include <qfileinfo.h> | - | ||||||||||||||||||
| 41 | #include <qfontmetrics.h> | - | ||||||||||||||||||
| 42 | #include <qbrush.h> | - | ||||||||||||||||||
| 43 | #include <qimagereader.h> | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | #include <algorithm> | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | #include "qcssscanner.cpp" | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | using namespace QCss; | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | struct QCssKnownValue | - | ||||||||||||||||||
| 56 | { | - | ||||||||||||||||||
| 57 | const char name[28]; | - | ||||||||||||||||||
| 58 | quint64 id; | - | ||||||||||||||||||
| 59 | }; | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | static const QCssKnownValue properties[NumProperties - 1] = { | - | ||||||||||||||||||
| 62 | { "-qt-background-role", QtBackgroundRole }, | - | ||||||||||||||||||
| 63 | { "-qt-block-indent", QtBlockIndent }, | - | ||||||||||||||||||
| 64 | { "-qt-list-indent", QtListIndent }, | - | ||||||||||||||||||
| 65 | { "-qt-list-number-prefix", QtListNumberPrefix }, | - | ||||||||||||||||||
| 66 | { "-qt-list-number-suffix", QtListNumberSuffix }, | - | ||||||||||||||||||
| 67 | { "-qt-paragraph-type", QtParagraphType }, | - | ||||||||||||||||||
| 68 | { "-qt-style-features", QtStyleFeatures }, | - | ||||||||||||||||||
| 69 | { "-qt-table-type", QtTableType }, | - | ||||||||||||||||||
| 70 | { "-qt-user-state", QtUserState }, | - | ||||||||||||||||||
| 71 | { "alternate-background-color", QtAlternateBackground }, | - | ||||||||||||||||||
| 72 | { "background", Background }, | - | ||||||||||||||||||
| 73 | { "background-attachment", BackgroundAttachment }, | - | ||||||||||||||||||
| 74 | { "background-clip", BackgroundClip }, | - | ||||||||||||||||||
| 75 | { "background-color", BackgroundColor }, | - | ||||||||||||||||||
| 76 | { "background-image", BackgroundImage }, | - | ||||||||||||||||||
| 77 | { "background-origin", BackgroundOrigin }, | - | ||||||||||||||||||
| 78 | { "background-position", BackgroundPosition }, | - | ||||||||||||||||||
| 79 | { "background-repeat", BackgroundRepeat }, | - | ||||||||||||||||||
| 80 | { "border", Border }, | - | ||||||||||||||||||
| 81 | { "border-bottom", BorderBottom }, | - | ||||||||||||||||||
| 82 | { "border-bottom-color", BorderBottomColor }, | - | ||||||||||||||||||
| 83 | { "border-bottom-left-radius", BorderBottomLeftRadius }, | - | ||||||||||||||||||
| 84 | { "border-bottom-right-radius", BorderBottomRightRadius }, | - | ||||||||||||||||||
| 85 | { "border-bottom-style", BorderBottomStyle }, | - | ||||||||||||||||||
| 86 | { "border-bottom-width", BorderBottomWidth }, | - | ||||||||||||||||||
| 87 | { "border-color", BorderColor }, | - | ||||||||||||||||||
| 88 | { "border-image", BorderImage }, | - | ||||||||||||||||||
| 89 | { "border-left", BorderLeft }, | - | ||||||||||||||||||
| 90 | { "border-left-color", BorderLeftColor }, | - | ||||||||||||||||||
| 91 | { "border-left-style", BorderLeftStyle }, | - | ||||||||||||||||||
| 92 | { "border-left-width", BorderLeftWidth }, | - | ||||||||||||||||||
| 93 | { "border-radius", BorderRadius }, | - | ||||||||||||||||||
| 94 | { "border-right", BorderRight }, | - | ||||||||||||||||||
| 95 | { "border-right-color", BorderRightColor }, | - | ||||||||||||||||||
| 96 | { "border-right-style", BorderRightStyle }, | - | ||||||||||||||||||
| 97 | { "border-right-width", BorderRightWidth }, | - | ||||||||||||||||||
| 98 | { "border-style", BorderStyles }, | - | ||||||||||||||||||
| 99 | { "border-top", BorderTop }, | - | ||||||||||||||||||
| 100 | { "border-top-color", BorderTopColor }, | - | ||||||||||||||||||
| 101 | { "border-top-left-radius", BorderTopLeftRadius }, | - | ||||||||||||||||||
| 102 | { "border-top-right-radius", BorderTopRightRadius }, | - | ||||||||||||||||||
| 103 | { "border-top-style", BorderTopStyle }, | - | ||||||||||||||||||
| 104 | { "border-top-width", BorderTopWidth }, | - | ||||||||||||||||||
| 105 | { "border-width", BorderWidth }, | - | ||||||||||||||||||
| 106 | { "bottom", Bottom }, | - | ||||||||||||||||||
| 107 | { "color", Color }, | - | ||||||||||||||||||
| 108 | { "float", Float }, | - | ||||||||||||||||||
| 109 | { "font", Font }, | - | ||||||||||||||||||
| 110 | { "font-family", FontFamily }, | - | ||||||||||||||||||
| 111 | { "font-size", FontSize }, | - | ||||||||||||||||||
| 112 | { "font-style", FontStyle }, | - | ||||||||||||||||||
| 113 | { "font-variant", FontVariant }, | - | ||||||||||||||||||
| 114 | { "font-weight", FontWeight }, | - | ||||||||||||||||||
| 115 | { "height", Height }, | - | ||||||||||||||||||
| 116 | { "image", QtImage }, | - | ||||||||||||||||||
| 117 | { "image-position", QtImageAlignment }, | - | ||||||||||||||||||
| 118 | { "left", Left }, | - | ||||||||||||||||||
| 119 | { "line-height", LineHeight }, | - | ||||||||||||||||||
| 120 | { "list-style", ListStyle }, | - | ||||||||||||||||||
| 121 | { "list-style-type", ListStyleType }, | - | ||||||||||||||||||
| 122 | { "margin" , Margin }, | - | ||||||||||||||||||
| 123 | { "margin-bottom", MarginBottom }, | - | ||||||||||||||||||
| 124 | { "margin-left", MarginLeft }, | - | ||||||||||||||||||
| 125 | { "margin-right", MarginRight }, | - | ||||||||||||||||||
| 126 | { "margin-top", MarginTop }, | - | ||||||||||||||||||
| 127 | { "max-height", MaximumHeight }, | - | ||||||||||||||||||
| 128 | { "max-width", MaximumWidth }, | - | ||||||||||||||||||
| 129 | { "min-height", MinimumHeight }, | - | ||||||||||||||||||
| 130 | { "min-width", MinimumWidth }, | - | ||||||||||||||||||
| 131 | { "outline", Outline }, | - | ||||||||||||||||||
| 132 | { "outline-bottom-left-radius", OutlineBottomLeftRadius }, | - | ||||||||||||||||||
| 133 | { "outline-bottom-right-radius", OutlineBottomRightRadius }, | - | ||||||||||||||||||
| 134 | { "outline-color", OutlineColor }, | - | ||||||||||||||||||
| 135 | { "outline-offset", OutlineOffset }, | - | ||||||||||||||||||
| 136 | { "outline-radius", OutlineRadius }, | - | ||||||||||||||||||
| 137 | { "outline-style", OutlineStyle }, | - | ||||||||||||||||||
| 138 | { "outline-top-left-radius", OutlineTopLeftRadius }, | - | ||||||||||||||||||
| 139 | { "outline-top-right-radius", OutlineTopRightRadius }, | - | ||||||||||||||||||
| 140 | { "outline-width", OutlineWidth }, | - | ||||||||||||||||||
| 141 | { "padding", Padding }, | - | ||||||||||||||||||
| 142 | { "padding-bottom", PaddingBottom }, | - | ||||||||||||||||||
| 143 | { "padding-left", PaddingLeft }, | - | ||||||||||||||||||
| 144 | { "padding-right", PaddingRight }, | - | ||||||||||||||||||
| 145 | { "padding-top", PaddingTop }, | - | ||||||||||||||||||
| 146 | { "page-break-after", PageBreakAfter }, | - | ||||||||||||||||||
| 147 | { "page-break-before", PageBreakBefore }, | - | ||||||||||||||||||
| 148 | { "position", Position }, | - | ||||||||||||||||||
| 149 | { "right", Right }, | - | ||||||||||||||||||
| 150 | { "selection-background-color", QtSelectionBackground }, | - | ||||||||||||||||||
| 151 | { "selection-color", QtSelectionForeground }, | - | ||||||||||||||||||
| 152 | { "spacing", QtSpacing }, | - | ||||||||||||||||||
| 153 | { "subcontrol-origin", QtOrigin }, | - | ||||||||||||||||||
| 154 | { "subcontrol-position", QtPosition }, | - | ||||||||||||||||||
| 155 | { "text-align", TextAlignment }, | - | ||||||||||||||||||
| 156 | { "text-decoration", TextDecoration }, | - | ||||||||||||||||||
| 157 | { "text-indent", TextIndent }, | - | ||||||||||||||||||
| 158 | { "text-transform", TextTransform }, | - | ||||||||||||||||||
| 159 | { "text-underline-style", TextUnderlineStyle }, | - | ||||||||||||||||||
| 160 | { "top", Top }, | - | ||||||||||||||||||
| 161 | { "vertical-align", VerticalAlignment }, | - | ||||||||||||||||||
| 162 | { "white-space", Whitespace }, | - | ||||||||||||||||||
| 163 | { "width", Width } | - | ||||||||||||||||||
| 164 | }; | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | static const QCssKnownValue values[NumKnownValues - 1] = { | - | ||||||||||||||||||
| 167 | { "active", Value_Active }, | - | ||||||||||||||||||
| 168 | { "alternate-base", Value_AlternateBase }, | - | ||||||||||||||||||
| 169 | { "always", Value_Always }, | - | ||||||||||||||||||
| 170 | { "auto", Value_Auto }, | - | ||||||||||||||||||
| 171 | { "base", Value_Base }, | - | ||||||||||||||||||
| 172 | { "bold", Value_Bold }, | - | ||||||||||||||||||
| 173 | { "bottom", Value_Bottom }, | - | ||||||||||||||||||
| 174 | { "bright-text", Value_BrightText }, | - | ||||||||||||||||||
| 175 | { "button", Value_Button }, | - | ||||||||||||||||||
| 176 | { "button-text", Value_ButtonText }, | - | ||||||||||||||||||
| 177 | { "center", Value_Center }, | - | ||||||||||||||||||
| 178 | { "circle", Value_Circle }, | - | ||||||||||||||||||
| 179 | { "dark", Value_Dark }, | - | ||||||||||||||||||
| 180 | { "dashed", Value_Dashed }, | - | ||||||||||||||||||
| 181 | { "decimal", Value_Decimal }, | - | ||||||||||||||||||
| 182 | { "disabled", Value_Disabled }, | - | ||||||||||||||||||
| 183 | { "disc", Value_Disc }, | - | ||||||||||||||||||
| 184 | { "dot-dash", Value_DotDash }, | - | ||||||||||||||||||
| 185 | { "dot-dot-dash", Value_DotDotDash }, | - | ||||||||||||||||||
| 186 | { "dotted", Value_Dotted }, | - | ||||||||||||||||||
| 187 | { "double", Value_Double }, | - | ||||||||||||||||||
| 188 | { "groove", Value_Groove }, | - | ||||||||||||||||||
| 189 | { "highlight", Value_Highlight }, | - | ||||||||||||||||||
| 190 | { "highlighted-text", Value_HighlightedText }, | - | ||||||||||||||||||
| 191 | { "inset", Value_Inset }, | - | ||||||||||||||||||
| 192 | { "italic", Value_Italic }, | - | ||||||||||||||||||
| 193 | { "large", Value_Large }, | - | ||||||||||||||||||
| 194 | { "left", Value_Left }, | - | ||||||||||||||||||
| 195 | { "light", Value_Light }, | - | ||||||||||||||||||
| 196 | { "line-through", Value_LineThrough }, | - | ||||||||||||||||||
| 197 | { "link", Value_Link }, | - | ||||||||||||||||||
| 198 | { "link-visited", Value_LinkVisited }, | - | ||||||||||||||||||
| 199 | { "lower-alpha", Value_LowerAlpha }, | - | ||||||||||||||||||
| 200 | { "lower-roman", Value_LowerRoman }, | - | ||||||||||||||||||
| 201 | { "lowercase", Value_Lowercase }, | - | ||||||||||||||||||
| 202 | { "medium", Value_Medium }, | - | ||||||||||||||||||
| 203 | { "mid", Value_Mid }, | - | ||||||||||||||||||
| 204 | { "middle", Value_Middle }, | - | ||||||||||||||||||
| 205 | { "midlight", Value_Midlight }, | - | ||||||||||||||||||
| 206 | { "native", Value_Native }, | - | ||||||||||||||||||
| 207 | { "none", Value_None }, | - | ||||||||||||||||||
| 208 | { "normal", Value_Normal }, | - | ||||||||||||||||||
| 209 | { "nowrap", Value_NoWrap }, | - | ||||||||||||||||||
| 210 | { "oblique", Value_Oblique }, | - | ||||||||||||||||||
| 211 | { "off", Value_Off }, | - | ||||||||||||||||||
| 212 | { "on", Value_On }, | - | ||||||||||||||||||
| 213 | { "outset", Value_Outset }, | - | ||||||||||||||||||
| 214 | { "overline", Value_Overline }, | - | ||||||||||||||||||
| 215 | { "pre", Value_Pre }, | - | ||||||||||||||||||
| 216 | { "pre-wrap", Value_PreWrap }, | - | ||||||||||||||||||
| 217 | { "ridge", Value_Ridge }, | - | ||||||||||||||||||
| 218 | { "right", Value_Right }, | - | ||||||||||||||||||
| 219 | { "selected", Value_Selected }, | - | ||||||||||||||||||
| 220 | { "shadow", Value_Shadow }, | - | ||||||||||||||||||
| 221 | { "small" , Value_Small }, | - | ||||||||||||||||||
| 222 | { "small-caps", Value_SmallCaps }, | - | ||||||||||||||||||
| 223 | { "solid", Value_Solid }, | - | ||||||||||||||||||
| 224 | { "square", Value_Square }, | - | ||||||||||||||||||
| 225 | { "sub", Value_Sub }, | - | ||||||||||||||||||
| 226 | { "super", Value_Super }, | - | ||||||||||||||||||
| 227 | { "text", Value_Text }, | - | ||||||||||||||||||
| 228 | { "top", Value_Top }, | - | ||||||||||||||||||
| 229 | { "transparent", Value_Transparent }, | - | ||||||||||||||||||
| 230 | { "underline", Value_Underline }, | - | ||||||||||||||||||
| 231 | { "upper-alpha", Value_UpperAlpha }, | - | ||||||||||||||||||
| 232 | { "upper-roman", Value_UpperRoman }, | - | ||||||||||||||||||
| 233 | { "uppercase", Value_Uppercase }, | - | ||||||||||||||||||
| 234 | { "wave", Value_Wave }, | - | ||||||||||||||||||
| 235 | { "window", Value_Window }, | - | ||||||||||||||||||
| 236 | { "window-text", Value_WindowText }, | - | ||||||||||||||||||
| 237 | { "x-large", Value_XLarge }, | - | ||||||||||||||||||
| 238 | { "xx-large", Value_XXLarge } | - | ||||||||||||||||||
| 239 | }; | - | ||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | //Map id to strings as they appears in the 'values' array above | - | ||||||||||||||||||
| 242 | static const short indexOfId[NumKnownValues] = { 0, 41, 48, 42, 49, 54, 35, 26, 70, 71, 25, 43, 5, 63, 47, | - | ||||||||||||||||||
| 243 | 29, 58, 59, 27, 51, 61, 6, 10, 39, 56, 19, 13, 17, 18, 20, 21, 50, 24, 46, 67, 37, 3, 2, 40, 62, 16, | - | ||||||||||||||||||
| 244 | 11, 57, 14, 32, 64, 33, 65, 55, 66, 34, 69, 8, 28, 38, 12, 36, 60, 7, 9, 4, 68, 53, 22, 23, 30, 31, | - | ||||||||||||||||||
| 245 | 1, 15, 0, 52, 45, 44 }; | - | ||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | QString Value::toString() const | - | ||||||||||||||||||
| 248 | { | - | ||||||||||||||||||
| 249 | if (type == KnownIdentifier) {
| 0 | ||||||||||||||||||
| 250 | return QLatin1String(values[indexOfId[variant.toInt()]].name); never executed: return QLatin1String(values[indexOfId[variant.toInt()]].name); | 0 | ||||||||||||||||||
| 251 | } else { | - | ||||||||||||||||||
| 252 | return variant.toString(); never executed: return variant.toString(); | 0 | ||||||||||||||||||
| 253 | } | - | ||||||||||||||||||
| 254 | } | - | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | static const QCssKnownValue pseudos[NumPseudos - 1] = { | - | ||||||||||||||||||
| 257 | { "active", PseudoClass_Active }, | - | ||||||||||||||||||
| 258 | { "adjoins-item", PseudoClass_Item }, | - | ||||||||||||||||||
| 259 | { "alternate", PseudoClass_Alternate }, | - | ||||||||||||||||||
| 260 | { "bottom", PseudoClass_Bottom }, | - | ||||||||||||||||||
| 261 | { "checked", PseudoClass_Checked }, | - | ||||||||||||||||||
| 262 | { "closable", PseudoClass_Closable }, | - | ||||||||||||||||||
| 263 | { "closed", PseudoClass_Closed }, | - | ||||||||||||||||||
| 264 | { "default", PseudoClass_Default }, | - | ||||||||||||||||||
| 265 | { "disabled", PseudoClass_Disabled }, | - | ||||||||||||||||||
| 266 | { "edit-focus", PseudoClass_EditFocus }, | - | ||||||||||||||||||
| 267 | { "editable", PseudoClass_Editable }, | - | ||||||||||||||||||
| 268 | { "enabled", PseudoClass_Enabled }, | - | ||||||||||||||||||
| 269 | { "exclusive", PseudoClass_Exclusive }, | - | ||||||||||||||||||
| 270 | { "first", PseudoClass_First }, | - | ||||||||||||||||||
| 271 | { "flat", PseudoClass_Flat }, | - | ||||||||||||||||||
| 272 | { "floatable", PseudoClass_Floatable }, | - | ||||||||||||||||||
| 273 | { "focus", PseudoClass_Focus }, | - | ||||||||||||||||||
| 274 | { "has-children", PseudoClass_Children }, | - | ||||||||||||||||||
| 275 | { "has-siblings", PseudoClass_Sibling }, | - | ||||||||||||||||||
| 276 | { "horizontal", PseudoClass_Horizontal }, | - | ||||||||||||||||||
| 277 | { "hover", PseudoClass_Hover }, | - | ||||||||||||||||||
| 278 | { "indeterminate" , PseudoClass_Indeterminate }, | - | ||||||||||||||||||
| 279 | { "last", PseudoClass_Last }, | - | ||||||||||||||||||
| 280 | { "left", PseudoClass_Left }, | - | ||||||||||||||||||
| 281 | { "maximized", PseudoClass_Maximized }, | - | ||||||||||||||||||
| 282 | { "middle", PseudoClass_Middle }, | - | ||||||||||||||||||
| 283 | { "minimized", PseudoClass_Minimized }, | - | ||||||||||||||||||
| 284 | { "movable", PseudoClass_Movable }, | - | ||||||||||||||||||
| 285 | { "next-selected", PseudoClass_NextSelected }, | - | ||||||||||||||||||
| 286 | { "no-frame", PseudoClass_Frameless }, | - | ||||||||||||||||||
| 287 | { "non-exclusive", PseudoClass_NonExclusive }, | - | ||||||||||||||||||
| 288 | { "off", PseudoClass_Unchecked }, | - | ||||||||||||||||||
| 289 | { "on", PseudoClass_Checked }, | - | ||||||||||||||||||
| 290 | { "only-one", PseudoClass_OnlyOne }, | - | ||||||||||||||||||
| 291 | { "open", PseudoClass_Open }, | - | ||||||||||||||||||
| 292 | { "pressed", PseudoClass_Pressed }, | - | ||||||||||||||||||
| 293 | { "previous-selected", PseudoClass_PreviousSelected }, | - | ||||||||||||||||||
| 294 | { "read-only", PseudoClass_ReadOnly }, | - | ||||||||||||||||||
| 295 | { "right", PseudoClass_Right }, | - | ||||||||||||||||||
| 296 | { "selected", PseudoClass_Selected }, | - | ||||||||||||||||||
| 297 | { "top", PseudoClass_Top }, | - | ||||||||||||||||||
| 298 | { "unchecked" , PseudoClass_Unchecked }, | - | ||||||||||||||||||
| 299 | { "vertical", PseudoClass_Vertical }, | - | ||||||||||||||||||
| 300 | { "window", PseudoClass_Window } | - | ||||||||||||||||||
| 301 | }; | - | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | static const QCssKnownValue origins[NumKnownOrigins - 1] = { | - | ||||||||||||||||||
| 304 | { "border", Origin_Border }, | - | ||||||||||||||||||
| 305 | { "content", Origin_Content }, | - | ||||||||||||||||||
| 306 | { "margin", Origin_Margin }, // not in css | - | ||||||||||||||||||
| 307 | { "padding", Origin_Padding } | - | ||||||||||||||||||
| 308 | }; | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | static const QCssKnownValue repeats[NumKnownRepeats - 1] = { | - | ||||||||||||||||||
| 311 | { "no-repeat", Repeat_None }, | - | ||||||||||||||||||
| 312 | { "repeat-x", Repeat_X }, | - | ||||||||||||||||||
| 313 | { "repeat-xy", Repeat_XY }, | - | ||||||||||||||||||
| 314 | { "repeat-y", Repeat_Y } | - | ||||||||||||||||||
| 315 | }; | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | static const QCssKnownValue tileModes[NumKnownTileModes - 1] = { | - | ||||||||||||||||||
| 318 | { "repeat", TileMode_Repeat }, | - | ||||||||||||||||||
| 319 | { "round", TileMode_Round }, | - | ||||||||||||||||||
| 320 | { "stretch", TileMode_Stretch }, | - | ||||||||||||||||||
| 321 | }; | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | static const QCssKnownValue positions[NumKnownPositionModes - 1] = { | - | ||||||||||||||||||
| 324 | { "absolute", PositionMode_Absolute }, | - | ||||||||||||||||||
| 325 | { "fixed", PositionMode_Fixed }, | - | ||||||||||||||||||
| 326 | { "relative", PositionMode_Relative }, | - | ||||||||||||||||||
| 327 | { "static", PositionMode_Static } | - | ||||||||||||||||||
| 328 | }; | - | ||||||||||||||||||
| 329 | - | |||||||||||||||||||
| 330 | static const QCssKnownValue attachments[NumKnownAttachments - 1] = { | - | ||||||||||||||||||
| 331 | { "fixed", Attachment_Fixed }, | - | ||||||||||||||||||
| 332 | { "scroll", Attachment_Scroll } | - | ||||||||||||||||||
| 333 | }; | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | static const QCssKnownValue styleFeatures[NumKnownStyleFeatures - 1] = { | - | ||||||||||||||||||
| 336 | { "background-color", StyleFeature_BackgroundColor }, | - | ||||||||||||||||||
| 337 | { "background-gradient", StyleFeature_BackgroundGradient }, | - | ||||||||||||||||||
| 338 | { "none", StyleFeature_None } | - | ||||||||||||||||||
| 339 | }; | - | ||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | #if defined(Q_CC_MSVC) && _MSC_VER < 1600 | - | ||||||||||||||||||
| 342 | static bool operator<(const QCssKnownValue &prop1, const QCssKnownValue &prop2) | - | ||||||||||||||||||
| 343 | { | - | ||||||||||||||||||
| 344 | return QString::compare(QString::fromLatin1(prop1.name), QLatin1String(prop2.name), Qt::CaseInsensitive) < 0; | - | ||||||||||||||||||
| 345 | } | - | ||||||||||||||||||
| 346 | #endif | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | static bool operator<(const QString &name, const QCssKnownValue &prop) | - | ||||||||||||||||||
| 349 | { | - | ||||||||||||||||||
| 350 | return QString::compare(name, QLatin1String(prop.name), Qt::CaseInsensitive) < 0; never executed: return QString::compare(name, QLatin1String(prop.name), Qt::CaseInsensitive) < 0; | 0 | ||||||||||||||||||
| 351 | } | - | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | static bool operator<(const QCssKnownValue &prop, const QString &name) | - | ||||||||||||||||||
| 354 | { | - | ||||||||||||||||||
| 355 | return QString::compare(QLatin1String(prop.name), name, Qt::CaseInsensitive) < 0; never executed: return QString::compare(QLatin1String(prop.name), name, Qt::CaseInsensitive) < 0; | 0 | ||||||||||||||||||
| 356 | } | - | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | static quint64 findKnownValue(const QString &name, const QCssKnownValue *start, int numValues) | - | ||||||||||||||||||
| 359 | { | - | ||||||||||||||||||
| 360 | const QCssKnownValue *end = &start[numValues - 1]; | - | ||||||||||||||||||
| 361 | const QCssKnownValue *prop = std::lower_bound(start, end, name); | - | ||||||||||||||||||
| 362 | if ((prop == end) || (name < *prop))
| 0 | ||||||||||||||||||
| 363 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 364 | return prop->id; never executed: return prop->id; | 0 | ||||||||||||||||||
| 365 | } | - | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | static inline bool isInheritable(Property propertyId) | - | ||||||||||||||||||
| 368 | { | - | ||||||||||||||||||
| 369 | switch (propertyId) { | - | ||||||||||||||||||
| 370 | case Font: never executed: case Font: | 0 | ||||||||||||||||||
| 371 | case FontFamily: never executed: case FontFamily: | 0 | ||||||||||||||||||
| 372 | case FontSize: never executed: case FontSize: | 0 | ||||||||||||||||||
| 373 | case FontStyle: never executed: case FontStyle: | 0 | ||||||||||||||||||
| 374 | case FontWeight: never executed: case FontWeight: | 0 | ||||||||||||||||||
| 375 | case TextIndent: never executed: case TextIndent: | 0 | ||||||||||||||||||
| 376 | case Whitespace: never executed: case Whitespace: | 0 | ||||||||||||||||||
| 377 | case ListStyleType: never executed: case ListStyleType: | 0 | ||||||||||||||||||
| 378 | case ListStyle: never executed: case ListStyle: | 0 | ||||||||||||||||||
| 379 | case TextAlignment: never executed: case TextAlignment: | 0 | ||||||||||||||||||
| 380 | case FontVariant: never executed: case FontVariant: | 0 | ||||||||||||||||||
| 381 | case TextTransform: never executed: case TextTransform: | 0 | ||||||||||||||||||
| 382 | case LineHeight: never executed: case LineHeight: | 0 | ||||||||||||||||||
| 383 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 384 | default: never executed: default: | 0 | ||||||||||||||||||
| 385 | break; never executed: break; | 0 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 388 | } | - | ||||||||||||||||||
| 389 | - | |||||||||||||||||||
| 390 | /////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||
| 391 | // Value Extractor | - | ||||||||||||||||||
| 392 | ValueExtractor::ValueExtractor(const QVector<Declaration> &decls, const QPalette &pal) | - | ||||||||||||||||||
| 393 | : declarations(decls), adjustment(0), fontExtracted(false), pal(pal) | - | ||||||||||||||||||
| 394 | { | - | ||||||||||||||||||
| 395 | } never executed: end of block | 0 | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | LengthData ValueExtractor::lengthValue(const Value& v) | - | ||||||||||||||||||
| 398 | { | - | ||||||||||||||||||
| 399 | QString s = v.variant.toString(); | - | ||||||||||||||||||
| 400 | s.reserve(s.length()); | - | ||||||||||||||||||
| 401 | LengthData data; | - | ||||||||||||||||||
| 402 | data.unit = LengthData::None; | - | ||||||||||||||||||
| 403 | if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
| 404 | data.unit = LengthData::Px; never executed: data.unit = LengthData::Px; | 0 | ||||||||||||||||||
| 405 | else if (s.endsWith(QLatin1String("ex"), Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
| 406 | data.unit = LengthData::Ex; never executed: data.unit = LengthData::Ex; | 0 | ||||||||||||||||||
| 407 | else if (s.endsWith(QLatin1String("em"), Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
| 408 | data.unit = LengthData::Em; never executed: data.unit = LengthData::Em; | 0 | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | if (data.unit != LengthData::None)
| 0 | ||||||||||||||||||
| 411 | s.chop(2); never executed: s.chop(2); | 0 | ||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | data.number = s.toDouble(); | - | ||||||||||||||||||
| 414 | return data; never executed: return data; | 0 | ||||||||||||||||||
| 415 | } | - | ||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | static int lengthValueFromData(const LengthData& data, const QFont& f) | - | ||||||||||||||||||
| 418 | { | - | ||||||||||||||||||
| 419 | if (data.unit == LengthData::Ex)
| 0 | ||||||||||||||||||
| 420 | return qRound(QFontMetrics(f).xHeight() * data.number); never executed: return qRound(QFontMetrics(f).xHeight() * data.number); | 0 | ||||||||||||||||||
| 421 | else if (data.unit == LengthData::Em)
| 0 | ||||||||||||||||||
| 422 | return qRound(QFontMetrics(f).height() * data.number); never executed: return qRound(QFontMetrics(f).height() * data.number); | 0 | ||||||||||||||||||
| 423 | return qRound(data.number); never executed: return qRound(data.number); | 0 | ||||||||||||||||||
| 424 | } | - | ||||||||||||||||||
| 425 | - | |||||||||||||||||||
| 426 | int ValueExtractor::lengthValue(const Declaration &decl) | - | ||||||||||||||||||
| 427 | { | - | ||||||||||||||||||
| 428 | if (decl.d->parsed.isValid())
| 0 | ||||||||||||||||||
| 429 | return lengthValueFromData(qvariant_cast<LengthData>(decl.d->parsed), f); never executed: return lengthValueFromData(qvariant_cast<LengthData>(decl.d->parsed), f); | 0 | ||||||||||||||||||
| 430 | if (decl.d->values.count() < 1)
| 0 | ||||||||||||||||||
| 431 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 432 | LengthData data = lengthValue(decl.d->values.at(0)); | - | ||||||||||||||||||
| 433 | decl.d->parsed = QVariant::fromValue<LengthData>(data); | - | ||||||||||||||||||
| 434 | return lengthValueFromData(data,f); never executed: return lengthValueFromData(data,f); | 0 | ||||||||||||||||||
| 435 | } | - | ||||||||||||||||||
| 436 | - | |||||||||||||||||||
| 437 | void ValueExtractor::lengthValues(const Declaration &decl, int *m) | - | ||||||||||||||||||
| 438 | { | - | ||||||||||||||||||
| 439 | if (decl.d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 440 | QList<QVariant> v = decl.d->parsed.toList(); | - | ||||||||||||||||||
| 441 | for (int i = 0; i < 4; i++)
| 0 | ||||||||||||||||||
| 442 | m[i] = lengthValueFromData(qvariant_cast<LengthData>(v.at(i)), f); never executed: m[i] = lengthValueFromData(qvariant_cast<LengthData>(v.at(i)), f); | 0 | ||||||||||||||||||
| 443 | return; never executed: return; | 0 | ||||||||||||||||||
| 444 | } | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | LengthData datas[4]; | - | ||||||||||||||||||
| 447 | int i; | - | ||||||||||||||||||
| 448 | for (i = 0; i < qMin(decl.d->values.count(), 4); i++)
| 0 | ||||||||||||||||||
| 449 | datas[i] = lengthValue(decl.d->values[i]); never executed: datas[i] = lengthValue(decl.d->values[i]); | 0 | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | if (i == 0) {
| 0 | ||||||||||||||||||
| 452 | LengthData zero = {0.0, LengthData::None}; | - | ||||||||||||||||||
| 453 | datas[0] = datas[1] = datas[2] = datas[3] = zero; | - | ||||||||||||||||||
| 454 | } else if (i == 1) { never executed: end of block
| 0 | ||||||||||||||||||
| 455 | datas[3] = datas[2] = datas[1] = datas[0]; | - | ||||||||||||||||||
| 456 | } else if (i == 2) { never executed: end of block
| 0 | ||||||||||||||||||
| 457 | datas[2] = datas[0]; | - | ||||||||||||||||||
| 458 | datas[3] = datas[1]; | - | ||||||||||||||||||
| 459 | } else if (i == 3) { never executed: end of block
| 0 | ||||||||||||||||||
| 460 | datas[3] = datas[1]; | - | ||||||||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||||||||
| 462 | - | |||||||||||||||||||
| 463 | QList<QVariant> v; | - | ||||||||||||||||||
| 464 | v.reserve(4); | - | ||||||||||||||||||
| 465 | for (i = 0; i < 4; i++) {
| 0 | ||||||||||||||||||
| 466 | v += QVariant::fromValue<LengthData>(datas[i]); | - | ||||||||||||||||||
| 467 | m[i] = lengthValueFromData(datas[i], f); | - | ||||||||||||||||||
| 468 | } never executed: end of block | 0 | ||||||||||||||||||
| 469 | decl.d->parsed = v; | - | ||||||||||||||||||
| 470 | } never executed: end of block | 0 | ||||||||||||||||||
| 471 | - | |||||||||||||||||||
| 472 | bool ValueExtractor::extractGeometry(int *w, int *h, int *minw, int *minh, int *maxw, int *maxh) | - | ||||||||||||||||||
| 473 | { | - | ||||||||||||||||||
| 474 | extractFont(); | - | ||||||||||||||||||
| 475 | bool hit = false; | - | ||||||||||||||||||
| 476 | for (int i = 0; i < declarations.count(); i++) {
| 0 | ||||||||||||||||||
| 477 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 478 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 479 | case Width: *w = lengthValue(decl); break; never executed: break;never executed: case Width: | 0 | ||||||||||||||||||
| 480 | case Height: *h = lengthValue(decl); break; never executed: break;never executed: case Height: | 0 | ||||||||||||||||||
| 481 | case MinimumWidth: *minw = lengthValue(decl); break; never executed: break;never executed: case MinimumWidth: | 0 | ||||||||||||||||||
| 482 | case MinimumHeight: *minh = lengthValue(decl); break; never executed: break;never executed: case MinimumHeight: | 0 | ||||||||||||||||||
| 483 | case MaximumWidth: *maxw = lengthValue(decl); break; never executed: break;never executed: case MaximumWidth: | 0 | ||||||||||||||||||
| 484 | case MaximumHeight: *maxh = lengthValue(decl); break; never executed: break;never executed: case MaximumHeight: | 0 | ||||||||||||||||||
| 485 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 486 | } | - | ||||||||||||||||||
| 487 | hit = true; | - | ||||||||||||||||||
| 488 | } never executed: end of block | 0 | ||||||||||||||||||
| 489 | - | |||||||||||||||||||
| 490 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 491 | } | - | ||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | bool ValueExtractor::extractPosition(int *left, int *top, int *right, int *bottom, QCss::Origin *origin, | - | ||||||||||||||||||
| 494 | Qt::Alignment *position, QCss::PositionMode *mode, Qt::Alignment *textAlignment) | - | ||||||||||||||||||
| 495 | { | - | ||||||||||||||||||
| 496 | extractFont(); | - | ||||||||||||||||||
| 497 | bool hit = false; | - | ||||||||||||||||||
| 498 | for (int i = 0; i < declarations.count(); i++) {
| 0 | ||||||||||||||||||
| 499 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 500 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 501 | case Left: *left = lengthValue(decl); break; never executed: break;never executed: case Left: | 0 | ||||||||||||||||||
| 502 | case Top: *top = lengthValue(decl); break; never executed: break;never executed: case Top: | 0 | ||||||||||||||||||
| 503 | case Right: *right = lengthValue(decl); break; never executed: break;never executed: case Right: | 0 | ||||||||||||||||||
| 504 | case Bottom: *bottom = lengthValue(decl); break; never executed: break;never executed: case Bottom: | 0 | ||||||||||||||||||
| 505 | case QtOrigin: *origin = decl.originValue(); break; never executed: break;never executed: case QtOrigin: | 0 | ||||||||||||||||||
| 506 | case QtPosition: *position = decl.alignmentValue(); break; never executed: break;never executed: case QtPosition: | 0 | ||||||||||||||||||
| 507 | case TextAlignment: *textAlignment = decl.alignmentValue(); break; never executed: break;never executed: case TextAlignment: | 0 | ||||||||||||||||||
| 508 | case Position: *mode = decl.positionValue(); break; never executed: break;never executed: case Position: | 0 | ||||||||||||||||||
| 509 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 510 | } | - | ||||||||||||||||||
| 511 | hit = true; | - | ||||||||||||||||||
| 512 | } never executed: end of block | 0 | ||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 515 | } | - | ||||||||||||||||||
| 516 | - | |||||||||||||||||||
| 517 | bool ValueExtractor::extractBox(int *margins, int *paddings, int *spacing) | - | ||||||||||||||||||
| 518 | { | - | ||||||||||||||||||
| 519 | extractFont(); | - | ||||||||||||||||||
| 520 | bool hit = false; | - | ||||||||||||||||||
| 521 | for (int i = 0; i < declarations.count(); i++) {
| 0 | ||||||||||||||||||
| 522 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 523 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 524 | case PaddingLeft: paddings[LeftEdge] = lengthValue(decl); break; never executed: break;never executed: case PaddingLeft: | 0 | ||||||||||||||||||
| 525 | case PaddingRight: paddings[RightEdge] = lengthValue(decl); break; never executed: break;never executed: case PaddingRight: | 0 | ||||||||||||||||||
| 526 | case PaddingTop: paddings[TopEdge] = lengthValue(decl); break; never executed: break;never executed: case PaddingTop: | 0 | ||||||||||||||||||
| 527 | case PaddingBottom: paddings[BottomEdge] = lengthValue(decl); break; never executed: break;never executed: case PaddingBottom: | 0 | ||||||||||||||||||
| 528 | case Padding: lengthValues(decl, paddings); break; never executed: break;never executed: case Padding: | 0 | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | case MarginLeft: margins[LeftEdge] = lengthValue(decl); break; never executed: break;never executed: case MarginLeft: | 0 | ||||||||||||||||||
| 531 | case MarginRight: margins[RightEdge] = lengthValue(decl); break; never executed: break;never executed: case MarginRight: | 0 | ||||||||||||||||||
| 532 | case MarginTop: margins[TopEdge] = lengthValue(decl); break; never executed: break;never executed: case MarginTop: | 0 | ||||||||||||||||||
| 533 | case MarginBottom: margins[BottomEdge] = lengthValue(decl); break; never executed: break;never executed: case MarginBottom: | 0 | ||||||||||||||||||
| 534 | case Margin: lengthValues(decl, margins); break; never executed: break;never executed: case Margin: | 0 | ||||||||||||||||||
| 535 | case QtSpacing: if (spacing) *spacing = lengthValue(decl); break; never executed: *spacing = lengthValue(decl);never executed: break;
never executed: case QtSpacing: | 0 | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 538 | } | - | ||||||||||||||||||
| 539 | hit = true; | - | ||||||||||||||||||
| 540 | } never executed: end of block | 0 | ||||||||||||||||||
| 541 | - | |||||||||||||||||||
| 542 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 543 | } | - | ||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | int ValueExtractor::extractStyleFeatures() | - | ||||||||||||||||||
| 546 | { | - | ||||||||||||||||||
| 547 | int features = StyleFeature_None; | - | ||||||||||||||||||
| 548 | for (int i = 0; i < declarations.count(); i++) {
| 0 | ||||||||||||||||||
| 549 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 550 | if (decl.d->propertyId == QtStyleFeatures)
| 0 | ||||||||||||||||||
| 551 | features = decl.styleFeaturesValue(); never executed: features = decl.styleFeaturesValue(); | 0 | ||||||||||||||||||
| 552 | } never executed: end of block | 0 | ||||||||||||||||||
| 553 | return features; never executed: return features; | 0 | ||||||||||||||||||
| 554 | } | - | ||||||||||||||||||
| 555 | - | |||||||||||||||||||
| 556 | QSize ValueExtractor::sizeValue(const Declaration &decl) | - | ||||||||||||||||||
| 557 | { | - | ||||||||||||||||||
| 558 | if (decl.d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 559 | QList<QVariant> v = decl.d->parsed.toList(); | - | ||||||||||||||||||
| 560 | return QSize(lengthValueFromData(qvariant_cast<LengthData>(v.at(0)), f), never executed: return QSize(lengthValueFromData(qvariant_cast<LengthData>(v.at(0)), f), lengthValueFromData(qvariant_cast<LengthData>(v.at(1)), f)); | 0 | ||||||||||||||||||
| 561 | lengthValueFromData(qvariant_cast<LengthData>(v.at(1)), f)); never executed: return QSize(lengthValueFromData(qvariant_cast<LengthData>(v.at(0)), f), lengthValueFromData(qvariant_cast<LengthData>(v.at(1)), f)); | 0 | ||||||||||||||||||
| 562 | } | - | ||||||||||||||||||
| 563 | - | |||||||||||||||||||
| 564 | LengthData x[2] = { {0, LengthData::None }, {0, LengthData::None} }; | - | ||||||||||||||||||
| 565 | if (decl.d->values.count() > 0)
| 0 | ||||||||||||||||||
| 566 | x[0] = lengthValue(decl.d->values.at(0)); never executed: x[0] = lengthValue(decl.d->values.at(0)); | 0 | ||||||||||||||||||
| 567 | if (decl.d->values.count() > 1)
| 0 | ||||||||||||||||||
| 568 | x[1] = lengthValue(decl.d->values.at(1)); never executed: x[1] = lengthValue(decl.d->values.at(1)); | 0 | ||||||||||||||||||
| 569 | else | - | ||||||||||||||||||
| 570 | x[1] = x[0]; never executed: x[1] = x[0]; | 0 | ||||||||||||||||||
| 571 | QList<QVariant> v; | - | ||||||||||||||||||
| 572 | v << QVariant::fromValue<LengthData>(x[0]) << QVariant::fromValue<LengthData>(x[1]); | - | ||||||||||||||||||
| 573 | decl.d->parsed = v; | - | ||||||||||||||||||
| 574 | return QSize(lengthValueFromData(x[0], f), lengthValueFromData(x[1], f)); never executed: return QSize(lengthValueFromData(x[0], f), lengthValueFromData(x[1], f)); | 0 | ||||||||||||||||||
| 575 | } | - | ||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | void ValueExtractor::sizeValues(const Declaration &decl, QSize *radii) | - | ||||||||||||||||||
| 578 | { | - | ||||||||||||||||||
| 579 | radii[0] = sizeValue(decl); | - | ||||||||||||||||||
| 580 | for (int i = 1; i < 4; i++)
| 0 | ||||||||||||||||||
| 581 | radii[i] = radii[0]; never executed: radii[i] = radii[0]; | 0 | ||||||||||||||||||
| 582 | } never executed: end of block | 0 | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | bool ValueExtractor::extractBorder(int *borders, QBrush *colors, BorderStyle *styles, | - | ||||||||||||||||||
| 585 | QSize *radii) | - | ||||||||||||||||||
| 586 | { | - | ||||||||||||||||||
| 587 | extractFont(); | - | ||||||||||||||||||
| 588 | bool hit = false; | - | ||||||||||||||||||
| 589 | for (int i = 0; i < declarations.count(); i++) {
| 0 | ||||||||||||||||||
| 590 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 591 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 592 | case BorderLeftWidth: borders[LeftEdge] = lengthValue(decl); break; never executed: break;never executed: case BorderLeftWidth: | 0 | ||||||||||||||||||
| 593 | case BorderRightWidth: borders[RightEdge] = lengthValue(decl); break; never executed: break;never executed: case BorderRightWidth: | 0 | ||||||||||||||||||
| 594 | case BorderTopWidth: borders[TopEdge] = lengthValue(decl); break; never executed: break;never executed: case BorderTopWidth: | 0 | ||||||||||||||||||
| 595 | case BorderBottomWidth: borders[BottomEdge] = lengthValue(decl); break; never executed: break;never executed: case BorderBottomWidth: | 0 | ||||||||||||||||||
| 596 | case BorderWidth: lengthValues(decl, borders); break; never executed: break;never executed: case BorderWidth: | 0 | ||||||||||||||||||
| 597 | - | |||||||||||||||||||
| 598 | case BorderLeftColor: colors[LeftEdge] = decl.brushValue(pal); break; never executed: break;never executed: case BorderLeftColor: | 0 | ||||||||||||||||||
| 599 | case BorderRightColor: colors[RightEdge] = decl.brushValue(pal); break; never executed: break;never executed: case BorderRightColor: | 0 | ||||||||||||||||||
| 600 | case BorderTopColor: colors[TopEdge] = decl.brushValue(pal); break; never executed: break;never executed: case BorderTopColor: | 0 | ||||||||||||||||||
| 601 | case BorderBottomColor: colors[BottomEdge] = decl.brushValue(pal); break; never executed: break;never executed: case BorderBottomColor: | 0 | ||||||||||||||||||
| 602 | case BorderColor: decl.brushValues(colors, pal); break; never executed: break;never executed: case BorderColor: | 0 | ||||||||||||||||||
| 603 | - | |||||||||||||||||||
| 604 | case BorderTopStyle: styles[TopEdge] = decl.styleValue(); break; never executed: break;never executed: case BorderTopStyle: | 0 | ||||||||||||||||||
| 605 | case BorderBottomStyle: styles[BottomEdge] = decl.styleValue(); break; never executed: break;never executed: case BorderBottomStyle: | 0 | ||||||||||||||||||
| 606 | case BorderLeftStyle: styles[LeftEdge] = decl.styleValue(); break; never executed: break;never executed: case BorderLeftStyle: | 0 | ||||||||||||||||||
| 607 | case BorderRightStyle: styles[RightEdge] = decl.styleValue(); break; never executed: break;never executed: case BorderRightStyle: | 0 | ||||||||||||||||||
| 608 | case BorderStyles: decl.styleValues(styles); break; never executed: break;never executed: case BorderStyles: | 0 | ||||||||||||||||||
| 609 | - | |||||||||||||||||||
| 610 | #ifndef QT_OS_ANDROID_GCC_48_WORKAROUND | - | ||||||||||||||||||
| 611 | case BorderTopLeftRadius: radii[0] = sizeValue(decl); break; never executed: break;never executed: case BorderTopLeftRadius: | 0 | ||||||||||||||||||
| 612 | #else | - | ||||||||||||||||||
| 613 | case BorderTopLeftRadius: new(radii)QSize(sizeValue(decl)); break; | - | ||||||||||||||||||
| 614 | #endif | - | ||||||||||||||||||
| 615 | case BorderTopRightRadius: radii[1] = sizeValue(decl); break; never executed: break;never executed: case BorderTopRightRadius: | 0 | ||||||||||||||||||
| 616 | case BorderBottomLeftRadius: radii[2] = sizeValue(decl); break; never executed: break;never executed: case BorderBottomLeftRadius: | 0 | ||||||||||||||||||
| 617 | case BorderBottomRightRadius: radii[3] = sizeValue(decl); break; never executed: break;never executed: case BorderBottomRightRadius: | 0 | ||||||||||||||||||
| 618 | case BorderRadius: sizeValues(decl, radii); break; never executed: break;never executed: case BorderRadius: | 0 | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | case BorderLeft: never executed: case BorderLeft: | 0 | ||||||||||||||||||
| 621 | borderValue(decl, &borders[LeftEdge], &styles[LeftEdge], &colors[LeftEdge]); | - | ||||||||||||||||||
| 622 | break; never executed: break; | 0 | ||||||||||||||||||
| 623 | case BorderTop: never executed: case BorderTop: | 0 | ||||||||||||||||||
| 624 | borderValue(decl, &borders[TopEdge], &styles[TopEdge], &colors[TopEdge]); | - | ||||||||||||||||||
| 625 | break; never executed: break; | 0 | ||||||||||||||||||
| 626 | case BorderRight: never executed: case BorderRight: | 0 | ||||||||||||||||||
| 627 | borderValue(decl, &borders[RightEdge], &styles[RightEdge], &colors[RightEdge]); | - | ||||||||||||||||||
| 628 | break; never executed: break; | 0 | ||||||||||||||||||
| 629 | case BorderBottom: never executed: case BorderBottom: | 0 | ||||||||||||||||||
| 630 | borderValue(decl, &borders[BottomEdge], &styles[BottomEdge], &colors[BottomEdge]); | - | ||||||||||||||||||
| 631 | break; never executed: break; | 0 | ||||||||||||||||||
| 632 | case Border: never executed: case Border: | 0 | ||||||||||||||||||
| 633 | borderValue(decl, &borders[LeftEdge], &styles[LeftEdge], &colors[LeftEdge]); | - | ||||||||||||||||||
| 634 | borders[TopEdge] = borders[RightEdge] = borders[BottomEdge] = borders[LeftEdge]; | - | ||||||||||||||||||
| 635 | styles[TopEdge] = styles[RightEdge] = styles[BottomEdge] = styles[LeftEdge]; | - | ||||||||||||||||||
| 636 | colors[TopEdge] = colors[RightEdge] = colors[BottomEdge] = colors[LeftEdge]; | - | ||||||||||||||||||
| 637 | break; never executed: break; | 0 | ||||||||||||||||||
| 638 | - | |||||||||||||||||||
| 639 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 640 | } | - | ||||||||||||||||||
| 641 | hit = true; | - | ||||||||||||||||||
| 642 | } never executed: end of block | 0 | ||||||||||||||||||
| 643 | - | |||||||||||||||||||
| 644 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 645 | } | - | ||||||||||||||||||
| 646 | - | |||||||||||||||||||
| 647 | bool ValueExtractor::extractOutline(int *borders, QBrush *colors, BorderStyle *styles, | - | ||||||||||||||||||
| 648 | QSize *radii, int *offsets) | - | ||||||||||||||||||
| 649 | { | - | ||||||||||||||||||
| 650 | extractFont(); | - | ||||||||||||||||||
| 651 | bool hit = false; | - | ||||||||||||||||||
| 652 | for (int i = 0; i < declarations.count(); i++) {
| 0 | ||||||||||||||||||
| 653 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 654 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 655 | case OutlineWidth: lengthValues(decl, borders); break; never executed: break;never executed: case OutlineWidth: | 0 | ||||||||||||||||||
| 656 | case OutlineColor: decl.brushValues(colors, pal); break; never executed: break;never executed: case OutlineColor: | 0 | ||||||||||||||||||
| 657 | case OutlineStyle: decl.styleValues(styles); break; never executed: break;never executed: case OutlineStyle: | 0 | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | case OutlineTopLeftRadius: radii[0] = sizeValue(decl); break; never executed: break;never executed: case OutlineTopLeftRadius: | 0 | ||||||||||||||||||
| 660 | case OutlineTopRightRadius: radii[1] = sizeValue(decl); break; never executed: break;never executed: case OutlineTopRightRadius: | 0 | ||||||||||||||||||
| 661 | case OutlineBottomLeftRadius: radii[2] = sizeValue(decl); break; never executed: break;never executed: case OutlineBottomLeftRadius: | 0 | ||||||||||||||||||
| 662 | case OutlineBottomRightRadius: radii[3] = sizeValue(decl); break; never executed: break;never executed: case OutlineBottomRightRadius: | 0 | ||||||||||||||||||
| 663 | case OutlineRadius: sizeValues(decl, radii); break; never executed: break;never executed: case OutlineRadius: | 0 | ||||||||||||||||||
| 664 | case OutlineOffset: lengthValues(decl, offsets); break; never executed: break;never executed: case OutlineOffset: | 0 | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | case Outline: never executed: case Outline: | 0 | ||||||||||||||||||
| 667 | borderValue(decl, &borders[LeftEdge], &styles[LeftEdge], &colors[LeftEdge]); | - | ||||||||||||||||||
| 668 | borders[TopEdge] = borders[RightEdge] = borders[BottomEdge] = borders[LeftEdge]; | - | ||||||||||||||||||
| 669 | styles[TopEdge] = styles[RightEdge] = styles[BottomEdge] = styles[LeftEdge]; | - | ||||||||||||||||||
| 670 | colors[TopEdge] = colors[RightEdge] = colors[BottomEdge] = colors[LeftEdge]; | - | ||||||||||||||||||
| 671 | break; never executed: break; | 0 | ||||||||||||||||||
| 672 | - | |||||||||||||||||||
| 673 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 674 | } | - | ||||||||||||||||||
| 675 | hit = true; | - | ||||||||||||||||||
| 676 | } never executed: end of block | 0 | ||||||||||||||||||
| 677 | - | |||||||||||||||||||
| 678 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 679 | } | - | ||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | static Qt::Alignment parseAlignment(const QCss::Value *values, int count) | - | ||||||||||||||||||
| 682 | { | - | ||||||||||||||||||
| 683 | Qt::Alignment a[2] = { 0, 0 }; | - | ||||||||||||||||||
| 684 | for (int i = 0; i < qMin(2, count); i++) {
| 0 | ||||||||||||||||||
| 685 | if (values[i].type != Value::KnownIdentifier)
| 0 | ||||||||||||||||||
| 686 | break; never executed: break; | 0 | ||||||||||||||||||
| 687 | switch (values[i].variant.toInt()) { | - | ||||||||||||||||||
| 688 | case Value_Left: a[i] = Qt::AlignLeft; break; never executed: break;never executed: case Value_Left: | 0 | ||||||||||||||||||
| 689 | case Value_Right: a[i] = Qt::AlignRight; break; never executed: break;never executed: case Value_Right: | 0 | ||||||||||||||||||
| 690 | case Value_Top: a[i] = Qt::AlignTop; break; never executed: break;never executed: case Value_Top: | 0 | ||||||||||||||||||
| 691 | case Value_Bottom: a[i] = Qt::AlignBottom; break; never executed: break;never executed: case Value_Bottom: | 0 | ||||||||||||||||||
| 692 | case Value_Center: a[i] = Qt::AlignCenter; break; never executed: break;never executed: case Value_Center: | 0 | ||||||||||||||||||
| 693 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 694 | } | - | ||||||||||||||||||
| 695 | } | - | ||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | if (a[0] == Qt::AlignCenter && a[1] != 0 && a[1] != Qt::AlignCenter)
| 0 | ||||||||||||||||||
| 698 | a[0] = (a[1] == Qt::AlignLeft || a[1] == Qt::AlignRight) ? Qt::AlignVCenter : Qt::AlignHCenter; never executed: a[0] = (a[1] == Qt::AlignLeft || a[1] == Qt::AlignRight) ? Qt::AlignVCenter : Qt::AlignHCenter;
| 0 | ||||||||||||||||||
| 699 | if ((a[1] == 0 || a[1] == Qt::AlignCenter) && a[0] != Qt::AlignCenter)
| 0 | ||||||||||||||||||
| 700 | a[1] = (a[0] == Qt::AlignLeft || a[0] == Qt::AlignRight) ? Qt::AlignVCenter : Qt::AlignHCenter; never executed: a[1] = (a[0] == Qt::AlignLeft || a[0] == Qt::AlignRight) ? Qt::AlignVCenter : Qt::AlignHCenter;
| 0 | ||||||||||||||||||
| 701 | return a[0] | a[1]; never executed: return a[0] | a[1]; | 0 | ||||||||||||||||||
| 702 | } | - | ||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | static ColorData parseColorValue(QCss::Value v) | - | ||||||||||||||||||
| 705 | { | - | ||||||||||||||||||
| 706 | if (v.type == Value::Identifier || v.type == Value::String) {
| 0 | ||||||||||||||||||
| 707 | v.variant.convert(QVariant::Color); | - | ||||||||||||||||||
| 708 | v.type = Value::Color; | - | ||||||||||||||||||
| 709 | } never executed: end of block | 0 | ||||||||||||||||||
| 710 | - | |||||||||||||||||||
| 711 | if (v.type == Value::Color)
| 0 | ||||||||||||||||||
| 712 | return qvariant_cast<QColor>(v.variant); never executed: return qvariant_cast<QColor>(v.variant); | 0 | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | if (v.type == Value::KnownIdentifier && v.variant.toInt() == Value_Transparent)
| 0 | ||||||||||||||||||
| 715 | return QColor(Qt::transparent); never executed: return QColor(Qt::transparent); | 0 | ||||||||||||||||||
| 716 | - | |||||||||||||||||||
| 717 | if (v.type != Value::Function)
| 0 | ||||||||||||||||||
| 718 | return ColorData(); never executed: return ColorData(); | 0 | ||||||||||||||||||
| 719 | - | |||||||||||||||||||
| 720 | QStringList lst = v.variant.toStringList(); | - | ||||||||||||||||||
| 721 | if (lst.count() != 2)
| 0 | ||||||||||||||||||
| 722 | return ColorData(); never executed: return ColorData(); | 0 | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | if ((lst.at(0).compare(QLatin1String("palette"), Qt::CaseInsensitive)) == 0) {
| 0 | ||||||||||||||||||
| 725 | int role = findKnownValue(lst.at(1).trimmed(), values, NumKnownValues); | - | ||||||||||||||||||
| 726 | if (role >= Value_FirstColorRole && role <= Value_LastColorRole)
| 0 | ||||||||||||||||||
| 727 | return (QPalette::ColorRole)(role-Value_FirstColorRole); never executed: return (QPalette::ColorRole)(role-Value_FirstColorRole); | 0 | ||||||||||||||||||
| 728 | - | |||||||||||||||||||
| 729 | return ColorData(); never executed: return ColorData(); | 0 | ||||||||||||||||||
| 730 | } | - | ||||||||||||||||||
| 731 | - | |||||||||||||||||||
| 732 | bool rgb = lst.at(0).startsWith(QLatin1String("rgb")); | - | ||||||||||||||||||
| 733 | bool rgba = lst.at(0).startsWith(QLatin1String("rgba")); | - | ||||||||||||||||||
| 734 | - | |||||||||||||||||||
| 735 | Parser p(lst.at(1)); | - | ||||||||||||||||||
| 736 | if (!p.testExpr())
| 0 | ||||||||||||||||||
| 737 | return ColorData(); never executed: return ColorData(); | 0 | ||||||||||||||||||
| 738 | - | |||||||||||||||||||
| 739 | QVector<QCss::Value> colorDigits; | - | ||||||||||||||||||
| 740 | if (!p.parseExpr(&colorDigits))
| 0 | ||||||||||||||||||
| 741 | return ColorData(); never executed: return ColorData(); | 0 | ||||||||||||||||||
| 742 | const int tokenCount = colorDigits.count(); | - | ||||||||||||||||||
| 743 | - | |||||||||||||||||||
| 744 | for (int i = 0; i < qMin(tokenCount, 7); i += 2) {
| 0 | ||||||||||||||||||
| 745 | if (colorDigits.at(i).type == Value::Percentage) {
| 0 | ||||||||||||||||||
| 746 | colorDigits[i].variant = colorDigits.at(i).variant.toReal() * (255. / 100.); | - | ||||||||||||||||||
| 747 | colorDigits[i].type = Value::Number; | - | ||||||||||||||||||
| 748 | } else if (colorDigits.at(i).type != Value::Number) { never executed: end of block
| 0 | ||||||||||||||||||
| 749 | return ColorData(); never executed: return ColorData(); | 0 | ||||||||||||||||||
| 750 | } | - | ||||||||||||||||||
| 751 | } never executed: end of block | 0 | ||||||||||||||||||
| 752 | - | |||||||||||||||||||
| 753 | - | |||||||||||||||||||
| 754 | if (tokenCount < 5)
| 0 | ||||||||||||||||||
| 755 | return ColorData(); never executed: return ColorData(); | 0 | ||||||||||||||||||
| 756 | - | |||||||||||||||||||
| 757 | int v1 = colorDigits.at(0).variant.toInt(); | - | ||||||||||||||||||
| 758 | int v2 = colorDigits.at(2).variant.toInt(); | - | ||||||||||||||||||
| 759 | int v3 = colorDigits.at(4).variant.toInt(); | - | ||||||||||||||||||
| 760 | int alpha = 255; | - | ||||||||||||||||||
| 761 | if (tokenCount >= 7) {
| 0 | ||||||||||||||||||
| 762 | int alphaValue = colorDigits.at(6).variant.toInt(); | - | ||||||||||||||||||
| 763 | if (rgba && alphaValue <= 1)
| 0 | ||||||||||||||||||
| 764 | alpha = colorDigits.at(6).variant.toReal() * 255.; never executed: alpha = colorDigits.at(6).variant.toReal() * 255.; | 0 | ||||||||||||||||||
| 765 | else | - | ||||||||||||||||||
| 766 | alpha = alphaValue; never executed: alpha = alphaValue; | 0 | ||||||||||||||||||
| 767 | } | - | ||||||||||||||||||
| 768 | - | |||||||||||||||||||
| 769 | return rgb ? QColor::fromRgb(v1, v2, v3, alpha) never executed: return rgb ? QColor::fromRgb(v1, v2, v3, alpha) : QColor::fromHsv(v1, v2, v3, alpha);
| 0 | ||||||||||||||||||
| 770 | : QColor::fromHsv(v1, v2, v3, alpha); never executed: return rgb ? QColor::fromRgb(v1, v2, v3, alpha) : QColor::fromHsv(v1, v2, v3, alpha); | 0 | ||||||||||||||||||
| 771 | } | - | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | static QColor colorFromData(const ColorData& c, const QPalette &pal) | - | ||||||||||||||||||
| 774 | { | - | ||||||||||||||||||
| 775 | if (c.type == ColorData::Color) {
| 0 | ||||||||||||||||||
| 776 | return c.color; never executed: return c.color; | 0 | ||||||||||||||||||
| 777 | } else if (c.type == ColorData::Role) {
| 0 | ||||||||||||||||||
| 778 | return pal.color(c.role); never executed: return pal.color(c.role); | 0 | ||||||||||||||||||
| 779 | } | - | ||||||||||||||||||
| 780 | return QColor(); never executed: return QColor(); | 0 | ||||||||||||||||||
| 781 | } | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) | - | ||||||||||||||||||
| 784 | { | - | ||||||||||||||||||
| 785 | ColorData c = parseColorValue(v); | - | ||||||||||||||||||
| 786 | if (c.type == ColorData::Color) {
| 0 | ||||||||||||||||||
| 787 | return QBrush(c.color); never executed: return QBrush(c.color); | 0 | ||||||||||||||||||
| 788 | } else if (c.type == ColorData::Role) {
| 0 | ||||||||||||||||||
| 789 | return c.role; never executed: return c.role; | 0 | ||||||||||||||||||
| 790 | } | - | ||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | if (v.type != Value::Function)
| 0 | ||||||||||||||||||
| 793 | return BrushData(); never executed: return BrushData(); | 0 | ||||||||||||||||||
| 794 | - | |||||||||||||||||||
| 795 | QStringList lst = v.variant.toStringList(); | - | ||||||||||||||||||
| 796 | if (lst.count() != 2)
| 0 | ||||||||||||||||||
| 797 | return BrushData(); never executed: return BrushData(); | 0 | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | QStringList gradFuncs; | - | ||||||||||||||||||
| 800 | gradFuncs << QLatin1String("qlineargradient") << QLatin1String("qradialgradient") << QLatin1String("qconicalgradient") << QLatin1String("qgradient"); | - | ||||||||||||||||||
| 801 | int gradType = -1; | - | ||||||||||||||||||
| 802 | - | |||||||||||||||||||
| 803 | if ((gradType = gradFuncs.indexOf(lst.at(0).toLower())) == -1)
| 0 | ||||||||||||||||||
| 804 | return BrushData(); never executed: return BrushData(); | 0 | ||||||||||||||||||
| 805 | - | |||||||||||||||||||
| 806 | QHash<QString, qreal> vars; | - | ||||||||||||||||||
| 807 | QVector<QGradientStop> stops; | - | ||||||||||||||||||
| 808 | - | |||||||||||||||||||
| 809 | int spread = -1; | - | ||||||||||||||||||
| 810 | QStringList spreads; | - | ||||||||||||||||||
| 811 | spreads << QLatin1String("pad") << QLatin1String("reflect") << QLatin1String("repeat"); | - | ||||||||||||||||||
| 812 | - | |||||||||||||||||||
| 813 | bool dependsOnThePalette = false; | - | ||||||||||||||||||
| 814 | Parser parser(lst.at(1)); | - | ||||||||||||||||||
| 815 | while (parser.hasNext()) {
| 0 | ||||||||||||||||||
| 816 | parser.skipSpace(); | - | ||||||||||||||||||
| 817 | if (!parser.test(IDENT))
| 0 | ||||||||||||||||||
| 818 | return BrushData(); never executed: return BrushData(); | 0 | ||||||||||||||||||
| 819 | QString attr = parser.lexem(); | - | ||||||||||||||||||
| 820 | parser.skipSpace(); | - | ||||||||||||||||||
| 821 | if (!parser.test(COLON))
| 0 | ||||||||||||||||||
| 822 | return BrushData(); never executed: return BrushData(); | 0 | ||||||||||||||||||
| 823 | parser.skipSpace(); | - | ||||||||||||||||||
| 824 | if (attr.compare(QLatin1String("stop"), Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 825 | QCss::Value stop, color; | - | ||||||||||||||||||
| 826 | parser.next(); | - | ||||||||||||||||||
| 827 | if (!parser.parseTerm(&stop)) return BrushData(); never executed: return BrushData();
| 0 | ||||||||||||||||||
| 828 | parser.skipSpace(); | - | ||||||||||||||||||
| 829 | parser.next(); | - | ||||||||||||||||||
| 830 | if (!parser.parseTerm(&color)) return BrushData(); never executed: return BrushData();
| 0 | ||||||||||||||||||
| 831 | ColorData cd = parseColorValue(color); | - | ||||||||||||||||||
| 832 | if(cd.type == ColorData::Role)
| 0 | ||||||||||||||||||
| 833 | dependsOnThePalette = true; never executed: dependsOnThePalette = true; | 0 | ||||||||||||||||||
| 834 | stops.append(QGradientStop(stop.variant.toReal(), colorFromData(cd, pal))); | - | ||||||||||||||||||
| 835 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 836 | parser.next(); | - | ||||||||||||||||||
| 837 | QCss::Value value; | - | ||||||||||||||||||
| 838 | (void)parser.parseTerm(&value); | - | ||||||||||||||||||
| 839 | if (attr.compare(QLatin1String("spread"), Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 840 | spread = spreads.indexOf(value.variant.toString()); | - | ||||||||||||||||||
| 841 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 842 | vars[attr] = value.variant.toReal(); | - | ||||||||||||||||||
| 843 | } never executed: end of block | 0 | ||||||||||||||||||
| 844 | } | - | ||||||||||||||||||
| 845 | parser.skipSpace(); | - | ||||||||||||||||||
| 846 | (void)parser.test(COMMA); | - | ||||||||||||||||||
| 847 | } never executed: end of block | 0 | ||||||||||||||||||
| 848 | - | |||||||||||||||||||
| 849 | if (gradType == 0) {
| 0 | ||||||||||||||||||
| 850 | QLinearGradient lg(vars.value(QLatin1String("x1")), vars.value(QLatin1String("y1")), | - | ||||||||||||||||||
| 851 | vars.value(QLatin1String("x2")), vars.value(QLatin1String("y2"))); | - | ||||||||||||||||||
| 852 | lg.setCoordinateMode(QGradient::ObjectBoundingMode); | - | ||||||||||||||||||
| 853 | lg.setStops(stops); | - | ||||||||||||||||||
| 854 | if (spread != -1)
| 0 | ||||||||||||||||||
| 855 | lg.setSpread(QGradient::Spread(spread)); never executed: lg.setSpread(QGradient::Spread(spread)); | 0 | ||||||||||||||||||
| 856 | BrushData bd = QBrush(lg); | - | ||||||||||||||||||
| 857 | if (dependsOnThePalette)
| 0 | ||||||||||||||||||
| 858 | bd.type = BrushData::DependsOnThePalette; never executed: bd.type = BrushData::DependsOnThePalette; | 0 | ||||||||||||||||||
| 859 | return bd; never executed: return bd; | 0 | ||||||||||||||||||
| 860 | } | - | ||||||||||||||||||
| 861 | - | |||||||||||||||||||
| 862 | if (gradType == 1) {
| 0 | ||||||||||||||||||
| 863 | QRadialGradient rg(vars.value(QLatin1String("cx")), vars.value(QLatin1String("cy")), | - | ||||||||||||||||||
| 864 | vars.value(QLatin1String("radius")), vars.value(QLatin1String("fx")), | - | ||||||||||||||||||
| 865 | vars.value(QLatin1String("fy"))); | - | ||||||||||||||||||
| 866 | rg.setCoordinateMode(QGradient::ObjectBoundingMode); | - | ||||||||||||||||||
| 867 | rg.setStops(stops); | - | ||||||||||||||||||
| 868 | if (spread != -1)
| 0 | ||||||||||||||||||
| 869 | rg.setSpread(QGradient::Spread(spread)); never executed: rg.setSpread(QGradient::Spread(spread)); | 0 | ||||||||||||||||||
| 870 | BrushData bd = QBrush(rg); | - | ||||||||||||||||||
| 871 | if (dependsOnThePalette)
| 0 | ||||||||||||||||||
| 872 | bd.type = BrushData::DependsOnThePalette; never executed: bd.type = BrushData::DependsOnThePalette; | 0 | ||||||||||||||||||
| 873 | return bd; never executed: return bd; | 0 | ||||||||||||||||||
| 874 | } | - | ||||||||||||||||||
| 875 | - | |||||||||||||||||||
| 876 | if (gradType == 2) {
| 0 | ||||||||||||||||||
| 877 | QConicalGradient cg(vars.value(QLatin1String("cx")), vars.value(QLatin1String("cy")), | - | ||||||||||||||||||
| 878 | vars.value(QLatin1String("angle"))); | - | ||||||||||||||||||
| 879 | cg.setCoordinateMode(QGradient::ObjectBoundingMode); | - | ||||||||||||||||||
| 880 | cg.setStops(stops); | - | ||||||||||||||||||
| 881 | if (spread != -1)
| 0 | ||||||||||||||||||
| 882 | cg.setSpread(QGradient::Spread(spread)); never executed: cg.setSpread(QGradient::Spread(spread)); | 0 | ||||||||||||||||||
| 883 | BrushData bd = QBrush(cg); | - | ||||||||||||||||||
| 884 | if (dependsOnThePalette)
| 0 | ||||||||||||||||||
| 885 | bd.type = BrushData::DependsOnThePalette; never executed: bd.type = BrushData::DependsOnThePalette; | 0 | ||||||||||||||||||
| 886 | return bd; never executed: return bd; | 0 | ||||||||||||||||||
| 887 | } | - | ||||||||||||||||||
| 888 | - | |||||||||||||||||||
| 889 | return BrushData(); never executed: return BrushData(); | 0 | ||||||||||||||||||
| 890 | } | - | ||||||||||||||||||
| 891 | - | |||||||||||||||||||
| 892 | static QBrush brushFromData(const BrushData& c, const QPalette &pal) | - | ||||||||||||||||||
| 893 | { | - | ||||||||||||||||||
| 894 | if (c.type == BrushData::Role) {
| 0 | ||||||||||||||||||
| 895 | return pal.color(c.role); never executed: return pal.color(c.role); | 0 | ||||||||||||||||||
| 896 | } else { | - | ||||||||||||||||||
| 897 | return c.brush; never executed: return c.brush; | 0 | ||||||||||||||||||
| 898 | } | - | ||||||||||||||||||
| 899 | } | - | ||||||||||||||||||
| 900 | - | |||||||||||||||||||
| 901 | static BorderStyle parseStyleValue(QCss::Value v) | - | ||||||||||||||||||
| 902 | { | - | ||||||||||||||||||
| 903 | if (v.type == Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
| 904 | switch (v.variant.toInt()) { | - | ||||||||||||||||||
| 905 | case Value_None: never executed: case Value_None: | 0 | ||||||||||||||||||
| 906 | return BorderStyle_None; never executed: return BorderStyle_None; | 0 | ||||||||||||||||||
| 907 | case Value_Dotted: never executed: case Value_Dotted: | 0 | ||||||||||||||||||
| 908 | return BorderStyle_Dotted; never executed: return BorderStyle_Dotted; | 0 | ||||||||||||||||||
| 909 | case Value_Dashed: never executed: case Value_Dashed: | 0 | ||||||||||||||||||
| 910 | return BorderStyle_Dashed; never executed: return BorderStyle_Dashed; | 0 | ||||||||||||||||||
| 911 | case Value_Solid: never executed: case Value_Solid: | 0 | ||||||||||||||||||
| 912 | return BorderStyle_Solid; never executed: return BorderStyle_Solid; | 0 | ||||||||||||||||||
| 913 | case Value_Double: never executed: case Value_Double: | 0 | ||||||||||||||||||
| 914 | return BorderStyle_Double; never executed: return BorderStyle_Double; | 0 | ||||||||||||||||||
| 915 | case Value_DotDash: never executed: case Value_DotDash: | 0 | ||||||||||||||||||
| 916 | return BorderStyle_DotDash; never executed: return BorderStyle_DotDash; | 0 | ||||||||||||||||||
| 917 | case Value_DotDotDash: never executed: case Value_DotDotDash: | 0 | ||||||||||||||||||
| 918 | return BorderStyle_DotDotDash; never executed: return BorderStyle_DotDotDash; | 0 | ||||||||||||||||||
| 919 | case Value_Groove: never executed: case Value_Groove: | 0 | ||||||||||||||||||
| 920 | return BorderStyle_Groove; never executed: return BorderStyle_Groove; | 0 | ||||||||||||||||||
| 921 | case Value_Ridge: never executed: case Value_Ridge: | 0 | ||||||||||||||||||
| 922 | return BorderStyle_Ridge; never executed: return BorderStyle_Ridge; | 0 | ||||||||||||||||||
| 923 | case Value_Inset: never executed: case Value_Inset: | 0 | ||||||||||||||||||
| 924 | return BorderStyle_Inset; never executed: return BorderStyle_Inset; | 0 | ||||||||||||||||||
| 925 | case Value_Outset: never executed: case Value_Outset: | 0 | ||||||||||||||||||
| 926 | return BorderStyle_Outset; never executed: return BorderStyle_Outset; | 0 | ||||||||||||||||||
| 927 | case Value_Native: never executed: case Value_Native: | 0 | ||||||||||||||||||
| 928 | return BorderStyle_Native; never executed: return BorderStyle_Native; | 0 | ||||||||||||||||||
| 929 | default: never executed: default: | 0 | ||||||||||||||||||
| 930 | break; never executed: break; | 0 | ||||||||||||||||||
| 931 | } | - | ||||||||||||||||||
| 932 | } | - | ||||||||||||||||||
| 933 | - | |||||||||||||||||||
| 934 | return BorderStyle_Unknown; never executed: return BorderStyle_Unknown; | 0 | ||||||||||||||||||
| 935 | } | - | ||||||||||||||||||
| 936 | - | |||||||||||||||||||
| 937 | void ValueExtractor::borderValue(const Declaration &decl, int *width, QCss::BorderStyle *style, QBrush *color) | - | ||||||||||||||||||
| 938 | { | - | ||||||||||||||||||
| 939 | if (decl.d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 940 | BorderData data = qvariant_cast<BorderData>(decl.d->parsed); | - | ||||||||||||||||||
| 941 | *width = lengthValueFromData(data.width, f); | - | ||||||||||||||||||
| 942 | *style = data.style; | - | ||||||||||||||||||
| 943 | *color = data.color.type != BrushData::Invalid ? brushFromData(data.color, pal) : QBrush(QColor());
| 0 | ||||||||||||||||||
| 944 | return; never executed: return; | 0 | ||||||||||||||||||
| 945 | } | - | ||||||||||||||||||
| 946 | - | |||||||||||||||||||
| 947 | *width = 0; | - | ||||||||||||||||||
| 948 | *style = BorderStyle_None; | - | ||||||||||||||||||
| 949 | *color = QColor(); | - | ||||||||||||||||||
| 950 | - | |||||||||||||||||||
| 951 | if (decl.d->values.isEmpty())
| 0 | ||||||||||||||||||
| 952 | return; never executed: return; | 0 | ||||||||||||||||||
| 953 | - | |||||||||||||||||||
| 954 | BorderData data; | - | ||||||||||||||||||
| 955 | data.width.number = 0; | - | ||||||||||||||||||
| 956 | data.width.unit = LengthData::None; | - | ||||||||||||||||||
| 957 | data.style = BorderStyle_None; | - | ||||||||||||||||||
| 958 | - | |||||||||||||||||||
| 959 | int i = 0; | - | ||||||||||||||||||
| 960 | if (decl.d->values.at(i).type == Value::Length || decl.d->values.at(i).type == Value::Number) {
| 0 | ||||||||||||||||||
| 961 | data.width = lengthValue(decl.d->values.at(i)); | - | ||||||||||||||||||
| 962 | *width = lengthValueFromData(data.width, f); | - | ||||||||||||||||||
| 963 | if (++i >= decl.d->values.count()) {
| 0 | ||||||||||||||||||
| 964 | decl.d->parsed = QVariant::fromValue<BorderData>(data); | - | ||||||||||||||||||
| 965 | return; never executed: return; | 0 | ||||||||||||||||||
| 966 | } | - | ||||||||||||||||||
| 967 | } never executed: end of block | 0 | ||||||||||||||||||
| 968 | - | |||||||||||||||||||
| 969 | data.style = parseStyleValue(decl.d->values.at(i)); | - | ||||||||||||||||||
| 970 | if (data.style != BorderStyle_Unknown) {
| 0 | ||||||||||||||||||
| 971 | *style = data.style; | - | ||||||||||||||||||
| 972 | if (++i >= decl.d->values.count()) {
| 0 | ||||||||||||||||||
| 973 | decl.d->parsed = QVariant::fromValue<BorderData>(data); | - | ||||||||||||||||||
| 974 | return; never executed: return; | 0 | ||||||||||||||||||
| 975 | } | - | ||||||||||||||||||
| 976 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 977 | data.style = BorderStyle_None; | - | ||||||||||||||||||
| 978 | } never executed: end of block | 0 | ||||||||||||||||||
| 979 | - | |||||||||||||||||||
| 980 | data.color = parseBrushValue(decl.d->values.at(i), pal); | - | ||||||||||||||||||
| 981 | *color = brushFromData(data.color, pal); | - | ||||||||||||||||||
| 982 | if (data.color.type != BrushData::DependsOnThePalette)
| 0 | ||||||||||||||||||
| 983 | decl.d->parsed = QVariant::fromValue<BorderData>(data); never executed: decl.d->parsed = QVariant::fromValue<BorderData>(data); | 0 | ||||||||||||||||||
| 984 | } never executed: end of block | 0 | ||||||||||||||||||
| 985 | - | |||||||||||||||||||
| 986 | static void parseShorthandBackgroundProperty(const QVector<QCss::Value> &values, BrushData *brush, QString *image, Repeat *repeat, Qt::Alignment *alignment, const QPalette &pal) | - | ||||||||||||||||||
| 987 | { | - | ||||||||||||||||||
| 988 | *brush = BrushData(); | - | ||||||||||||||||||
| 989 | *image = QString(); | - | ||||||||||||||||||
| 990 | *repeat = Repeat_XY; | - | ||||||||||||||||||
| 991 | *alignment = Qt::AlignTop | Qt::AlignLeft; | - | ||||||||||||||||||
| 992 | - | |||||||||||||||||||
| 993 | for (int i = 0; i < values.count(); ++i) {
| 0 | ||||||||||||||||||
| 994 | const QCss::Value &v = values.at(i); | - | ||||||||||||||||||
| 995 | if (v.type == Value::Uri) {
| 0 | ||||||||||||||||||
| 996 | *image = v.variant.toString(); | - | ||||||||||||||||||
| 997 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 998 | } else if (v.type == Value::KnownIdentifier && v.variant.toInt() == Value_None) {
| 0 | ||||||||||||||||||
| 999 | *image = QString(); | - | ||||||||||||||||||
| 1000 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1001 | } else if (v.type == Value::KnownIdentifier && v.variant.toInt() == Value_Transparent) {
| 0 | ||||||||||||||||||
| 1002 | *brush = QBrush(Qt::transparent); | - | ||||||||||||||||||
| 1003 | } never executed: end of block | 0 | ||||||||||||||||||
| 1004 | - | |||||||||||||||||||
| 1005 | Repeat repeatAttempt = static_cast<Repeat>(findKnownValue(v.variant.toString(), | - | ||||||||||||||||||
| 1006 | repeats, NumKnownRepeats)); | - | ||||||||||||||||||
| 1007 | if (repeatAttempt != Repeat_Unknown) {
| 0 | ||||||||||||||||||
| 1008 | *repeat = repeatAttempt; | - | ||||||||||||||||||
| 1009 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1010 | } | - | ||||||||||||||||||
| 1011 | - | |||||||||||||||||||
| 1012 | if (v.type == Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
| 1013 | const int start = i; | - | ||||||||||||||||||
| 1014 | int count = 1; | - | ||||||||||||||||||
| 1015 | if (i < values.count() - 1
| 0 | ||||||||||||||||||
| 1016 | && values.at(i + 1).type == Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
| 1017 | ++i; | - | ||||||||||||||||||
| 1018 | ++count; | - | ||||||||||||||||||
| 1019 | } never executed: end of block | 0 | ||||||||||||||||||
| 1020 | Qt::Alignment a = parseAlignment(values.constData() + start, count); | - | ||||||||||||||||||
| 1021 | if (int(a) != 0) {
| 0 | ||||||||||||||||||
| 1022 | *alignment = a; | - | ||||||||||||||||||
| 1023 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1024 | } | - | ||||||||||||||||||
| 1025 | i -= count - 1; | - | ||||||||||||||||||
| 1026 | } never executed: end of block | 0 | ||||||||||||||||||
| 1027 | - | |||||||||||||||||||
| 1028 | *brush = parseBrushValue(v, pal); | - | ||||||||||||||||||
| 1029 | } never executed: end of block | 0 | ||||||||||||||||||
| 1030 | } never executed: end of block | 0 | ||||||||||||||||||
| 1031 | - | |||||||||||||||||||
| 1032 | bool ValueExtractor::extractBackground(QBrush *brush, QString *image, Repeat *repeat, | - | ||||||||||||||||||
| 1033 | Qt::Alignment *alignment, Origin *origin, Attachment *attachment, | - | ||||||||||||||||||
| 1034 | Origin *clip) | - | ||||||||||||||||||
| 1035 | { | - | ||||||||||||||||||
| 1036 | bool hit = false; | - | ||||||||||||||||||
| 1037 | for (int i = 0; i < declarations.count(); ++i) {
| 0 | ||||||||||||||||||
| 1038 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 1039 | if (decl.d->values.isEmpty())
| 0 | ||||||||||||||||||
| 1040 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1041 | const QCss::Value &val = decl.d->values.at(0); | - | ||||||||||||||||||
| 1042 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 1043 | case BackgroundColor: never executed: case BackgroundColor: | 0 | ||||||||||||||||||
| 1044 | *brush = decl.brushValue(); | - | ||||||||||||||||||
| 1045 | break; never executed: break; | 0 | ||||||||||||||||||
| 1046 | case BackgroundImage: never executed: case BackgroundImage: | 0 | ||||||||||||||||||
| 1047 | if (val.type == Value::Uri)
| 0 | ||||||||||||||||||
| 1048 | *image = val.variant.toString(); never executed: *image = val.variant.toString(); | 0 | ||||||||||||||||||
| 1049 | break; never executed: break; | 0 | ||||||||||||||||||
| 1050 | case BackgroundRepeat: never executed: case BackgroundRepeat: | 0 | ||||||||||||||||||
| 1051 | if (decl.d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 1052 | *repeat = static_cast<Repeat>(decl.d->parsed.toInt()); | - | ||||||||||||||||||
| 1053 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1054 | *repeat = static_cast<Repeat>(findKnownValue(val.variant.toString(), | - | ||||||||||||||||||
| 1055 | repeats, NumKnownRepeats)); | - | ||||||||||||||||||
| 1056 | decl.d->parsed = *repeat; | - | ||||||||||||||||||
| 1057 | } never executed: end of block | 0 | ||||||||||||||||||
| 1058 | break; never executed: break; | 0 | ||||||||||||||||||
| 1059 | case BackgroundPosition: never executed: case BackgroundPosition: | 0 | ||||||||||||||||||
| 1060 | *alignment = decl.alignmentValue(); | - | ||||||||||||||||||
| 1061 | break; never executed: break; | 0 | ||||||||||||||||||
| 1062 | case BackgroundOrigin: never executed: case BackgroundOrigin: | 0 | ||||||||||||||||||
| 1063 | *origin = decl.originValue(); | - | ||||||||||||||||||
| 1064 | break; never executed: break; | 0 | ||||||||||||||||||
| 1065 | case BackgroundClip: never executed: case BackgroundClip: | 0 | ||||||||||||||||||
| 1066 | *clip = decl.originValue(); | - | ||||||||||||||||||
| 1067 | break; never executed: break; | 0 | ||||||||||||||||||
| 1068 | case Background: never executed: case Background: | 0 | ||||||||||||||||||
| 1069 | if (decl.d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 1070 | BackgroundData data = qvariant_cast<BackgroundData>(decl.d->parsed); | - | ||||||||||||||||||
| 1071 | *brush = brushFromData(data.brush, pal); | - | ||||||||||||||||||
| 1072 | *image = data.image; | - | ||||||||||||||||||
| 1073 | *repeat = data.repeat; | - | ||||||||||||||||||
| 1074 | *alignment = data.alignment; | - | ||||||||||||||||||
| 1075 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1076 | BrushData brushData; | - | ||||||||||||||||||
| 1077 | parseShorthandBackgroundProperty(decl.d->values, &brushData, image, repeat, alignment, pal); | - | ||||||||||||||||||
| 1078 | *brush = brushFromData(brushData, pal); | - | ||||||||||||||||||
| 1079 | if (brushData.type != BrushData::DependsOnThePalette) {
| 0 | ||||||||||||||||||
| 1080 | BackgroundData data = { brushData, *image, *repeat, *alignment }; | - | ||||||||||||||||||
| 1081 | decl.d->parsed = QVariant::fromValue<BackgroundData>(data); | - | ||||||||||||||||||
| 1082 | } never executed: end of block | 0 | ||||||||||||||||||
| 1083 | } never executed: end of block | 0 | ||||||||||||||||||
| 1084 | break; never executed: break; | 0 | ||||||||||||||||||
| 1085 | case BackgroundAttachment: never executed: case BackgroundAttachment: | 0 | ||||||||||||||||||
| 1086 | *attachment = decl.attachmentValue(); | - | ||||||||||||||||||
| 1087 | break; never executed: break; | 0 | ||||||||||||||||||
| 1088 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 1089 | } | - | ||||||||||||||||||
| 1090 | hit = true; | - | ||||||||||||||||||
| 1091 | } never executed: end of block | 0 | ||||||||||||||||||
| 1092 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 1093 | } | - | ||||||||||||||||||
| 1094 | - | |||||||||||||||||||
| 1095 | static bool setFontSizeFromValue(QCss::Value value, QFont *font, int *fontSizeAdjustment) | - | ||||||||||||||||||
| 1096 | { | - | ||||||||||||||||||
| 1097 | if (value.type == Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
| 1098 | bool valid = true; | - | ||||||||||||||||||
| 1099 | switch (value.variant.toInt()) { | - | ||||||||||||||||||
| 1100 | case Value_Small: *fontSizeAdjustment = -1; break; never executed: break;never executed: case Value_Small: | 0 | ||||||||||||||||||
| 1101 | case Value_Medium: *fontSizeAdjustment = 0; break; never executed: break;never executed: case Value_Medium: | 0 | ||||||||||||||||||
| 1102 | case Value_Large: *fontSizeAdjustment = 1; break; never executed: break;never executed: case Value_Large: | 0 | ||||||||||||||||||
| 1103 | case Value_XLarge: *fontSizeAdjustment = 2; break; never executed: break;never executed: case Value_XLarge: | 0 | ||||||||||||||||||
| 1104 | case Value_XXLarge: *fontSizeAdjustment = 3; break; never executed: break;never executed: case Value_XXLarge: | 0 | ||||||||||||||||||
| 1105 | default: valid = false; break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 1106 | } | - | ||||||||||||||||||
| 1107 | return valid; never executed: return valid; | 0 | ||||||||||||||||||
| 1108 | } | - | ||||||||||||||||||
| 1109 | if (value.type != Value::Length)
| 0 | ||||||||||||||||||
| 1110 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1111 | - | |||||||||||||||||||
| 1112 | bool valid = false; | - | ||||||||||||||||||
| 1113 | QString s = value.variant.toString(); | - | ||||||||||||||||||
| 1114 | if (s.endsWith(QLatin1String("pt"), Qt::CaseInsensitive)) {
| 0 | ||||||||||||||||||
| 1115 | s.chop(2); | - | ||||||||||||||||||
| 1116 | value.variant = s; | - | ||||||||||||||||||
| 1117 | if (value.variant.convert((QVariant::Type)qMetaTypeId<qreal>())) {
| 0 | ||||||||||||||||||
| 1118 | font->setPointSizeF(value.variant.toReal()); | - | ||||||||||||||||||
| 1119 | valid = true; | - | ||||||||||||||||||
| 1120 | } never executed: end of block | 0 | ||||||||||||||||||
| 1121 | } else if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) { never executed: end of block
| 0 | ||||||||||||||||||
| 1122 | s.chop(2); | - | ||||||||||||||||||
| 1123 | value.variant = s; | - | ||||||||||||||||||
| 1124 | if (value.variant.convert(QVariant::Int)) {
| 0 | ||||||||||||||||||
| 1125 | font->setPixelSize(value.variant.toInt()); | - | ||||||||||||||||||
| 1126 | valid = true; | - | ||||||||||||||||||
| 1127 | } never executed: end of block | 0 | ||||||||||||||||||
| 1128 | } never executed: end of block | 0 | ||||||||||||||||||
| 1129 | return valid; never executed: return valid; | 0 | ||||||||||||||||||
| 1130 | } | - | ||||||||||||||||||
| 1131 | - | |||||||||||||||||||
| 1132 | static bool setFontStyleFromValue(const QCss::Value &value, QFont *font) | - | ||||||||||||||||||
| 1133 | { | - | ||||||||||||||||||
| 1134 | if (value.type != Value::KnownIdentifier)
| 0 | ||||||||||||||||||
| 1135 | return false ; never executed: return false ; | 0 | ||||||||||||||||||
| 1136 | switch (value.variant.toInt()) { | - | ||||||||||||||||||
| 1137 | case Value_Normal: font->setStyle(QFont::StyleNormal); return true; never executed: return true;never executed: case Value_Normal: | 0 | ||||||||||||||||||
| 1138 | case Value_Italic: font->setStyle(QFont::StyleItalic); return true; never executed: return true;never executed: case Value_Italic: | 0 | ||||||||||||||||||
| 1139 | case Value_Oblique: font->setStyle(QFont::StyleOblique); return true; never executed: return true;never executed: case Value_Oblique: | 0 | ||||||||||||||||||
| 1140 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 1141 | } | - | ||||||||||||||||||
| 1142 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1143 | } | - | ||||||||||||||||||
| 1144 | - | |||||||||||||||||||
| 1145 | static bool setFontWeightFromValue(const QCss::Value &value, QFont *font) | - | ||||||||||||||||||
| 1146 | { | - | ||||||||||||||||||
| 1147 | if (value.type == Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
| 1148 | switch (value.variant.toInt()) { | - | ||||||||||||||||||
| 1149 | case Value_Normal: font->setWeight(QFont::Normal); return true; never executed: return true;never executed: case Value_Normal: | 0 | ||||||||||||||||||
| 1150 | case Value_Bold: font->setWeight(QFont::Bold); return true; never executed: return true;never executed: case Value_Bold: | 0 | ||||||||||||||||||
| 1151 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 1152 | } | - | ||||||||||||||||||
| 1153 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1154 | } | - | ||||||||||||||||||
| 1155 | if (value.type != Value::Number)
| 0 | ||||||||||||||||||
| 1156 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1157 | font->setWeight(qMin(value.variant.toInt() / 8, 99)); | - | ||||||||||||||||||
| 1158 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 1159 | } | - | ||||||||||||||||||
| 1160 | - | |||||||||||||||||||
| 1161 | /** \internal | - | ||||||||||||||||||
| 1162 | * parse the font family from the values (starting from index \a start) | - | ||||||||||||||||||
| 1163 | * and set it the \a font | - | ||||||||||||||||||
| 1164 | * The function returns \c true if a family was extracted. | - | ||||||||||||||||||
| 1165 | */ | - | ||||||||||||||||||
| 1166 | static bool setFontFamilyFromValues(const QVector<QCss::Value> &values, QFont *font, int start = 0) | - | ||||||||||||||||||
| 1167 | { | - | ||||||||||||||||||
| 1168 | QString family; | - | ||||||||||||||||||
| 1169 | bool shouldAddSpace = false; | - | ||||||||||||||||||
| 1170 | for (int i = start; i < values.count(); ++i) {
| 0 | ||||||||||||||||||
| 1171 | const QCss::Value &v = values.at(i); | - | ||||||||||||||||||
| 1172 | if (v.type == Value::TermOperatorComma) {
| 0 | ||||||||||||||||||
| 1173 | family += QLatin1Char(','); | - | ||||||||||||||||||
| 1174 | shouldAddSpace = false; | - | ||||||||||||||||||
| 1175 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1176 | } | - | ||||||||||||||||||
| 1177 | const QString str = v.variant.toString(); | - | ||||||||||||||||||
| 1178 | if (str.isEmpty())
| 0 | ||||||||||||||||||
| 1179 | break; never executed: break; | 0 | ||||||||||||||||||
| 1180 | if (shouldAddSpace)
| 0 | ||||||||||||||||||
| 1181 | family += QLatin1Char(' '); never executed: family += QLatin1Char(' '); | 0 | ||||||||||||||||||
| 1182 | family += str; | - | ||||||||||||||||||
| 1183 | shouldAddSpace = true; | - | ||||||||||||||||||
| 1184 | } never executed: end of block | 0 | ||||||||||||||||||
| 1185 | if (family.isEmpty())
| 0 | ||||||||||||||||||
| 1186 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1187 | font->setFamily(family); | - | ||||||||||||||||||
| 1188 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 1189 | } | - | ||||||||||||||||||
| 1190 | - | |||||||||||||||||||
| 1191 | static void setTextDecorationFromValues(const QVector<QCss::Value> &values, QFont *font) | - | ||||||||||||||||||
| 1192 | { | - | ||||||||||||||||||
| 1193 | for (int i = 0; i < values.count(); ++i) {
| 0 | ||||||||||||||||||
| 1194 | if (values.at(i).type != Value::KnownIdentifier)
| 0 | ||||||||||||||||||
| 1195 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1196 | switch (values.at(i).variant.toInt()) { | - | ||||||||||||||||||
| 1197 | case Value_Underline: font->setUnderline(true); break; never executed: break;never executed: case Value_Underline: | 0 | ||||||||||||||||||
| 1198 | case Value_Overline: font->setOverline(true); break; never executed: break;never executed: case Value_Overline: | 0 | ||||||||||||||||||
| 1199 | case Value_LineThrough: font->setStrikeOut(true); break; never executed: break;never executed: case Value_LineThrough: | 0 | ||||||||||||||||||
| 1200 | case Value_None: never executed: case Value_None: | 0 | ||||||||||||||||||
| 1201 | font->setUnderline(false); | - | ||||||||||||||||||
| 1202 | font->setOverline(false); | - | ||||||||||||||||||
| 1203 | font->setStrikeOut(false); | - | ||||||||||||||||||
| 1204 | break; never executed: break; | 0 | ||||||||||||||||||
| 1205 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 1206 | } | - | ||||||||||||||||||
| 1207 | } | - | ||||||||||||||||||
| 1208 | } never executed: end of block | 0 | ||||||||||||||||||
| 1209 | - | |||||||||||||||||||
| 1210 | static void parseShorthandFontProperty(const QVector<QCss::Value> &values, QFont *font, int *fontSizeAdjustment) | - | ||||||||||||||||||
| 1211 | { | - | ||||||||||||||||||
| 1212 | font->setStyle(QFont::StyleNormal); | - | ||||||||||||||||||
| 1213 | font->setWeight(QFont::Normal); | - | ||||||||||||||||||
| 1214 | *fontSizeAdjustment = -255; | - | ||||||||||||||||||
| 1215 | - | |||||||||||||||||||
| 1216 | int i = 0; | - | ||||||||||||||||||
| 1217 | while (i < values.count()) {
| 0 | ||||||||||||||||||
| 1218 | if (setFontStyleFromValue(values.at(i), font)
| 0 | ||||||||||||||||||
| 1219 | || setFontWeightFromValue(values.at(i), font))
| 0 | ||||||||||||||||||
| 1220 | ++i; never executed: ++i; | 0 | ||||||||||||||||||
| 1221 | else | - | ||||||||||||||||||
| 1222 | break; never executed: break; | 0 | ||||||||||||||||||
| 1223 | } | - | ||||||||||||||||||
| 1224 | - | |||||||||||||||||||
| 1225 | if (i < values.count()) {
| 0 | ||||||||||||||||||
| 1226 | setFontSizeFromValue(values.at(i), font, fontSizeAdjustment); | - | ||||||||||||||||||
| 1227 | ++i; | - | ||||||||||||||||||
| 1228 | } never executed: end of block | 0 | ||||||||||||||||||
| 1229 | - | |||||||||||||||||||
| 1230 | if (i < values.count()) {
| 0 | ||||||||||||||||||
| 1231 | setFontFamilyFromValues(values, font, i); | - | ||||||||||||||||||
| 1232 | } never executed: end of block | 0 | ||||||||||||||||||
| 1233 | } never executed: end of block | 0 | ||||||||||||||||||
| 1234 | - | |||||||||||||||||||
| 1235 | static void setFontVariantFromValue(const QCss::Value &value, QFont *font) | - | ||||||||||||||||||
| 1236 | { | - | ||||||||||||||||||
| 1237 | if (value.type == Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
| 1238 | switch (value.variant.toInt()) { | - | ||||||||||||||||||
| 1239 | case Value_Normal: font->setCapitalization(QFont::MixedCase); break; never executed: break;never executed: case Value_Normal: | 0 | ||||||||||||||||||
| 1240 | case Value_SmallCaps: font->setCapitalization(QFont::SmallCaps); break; never executed: break;never executed: case Value_SmallCaps: | 0 | ||||||||||||||||||
| 1241 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 1242 | } | - | ||||||||||||||||||
| 1243 | } | - | ||||||||||||||||||
| 1244 | } never executed: end of block | 0 | ||||||||||||||||||
| 1245 | - | |||||||||||||||||||
| 1246 | static void setTextTransformFromValue(const QCss::Value &value, QFont *font) | - | ||||||||||||||||||
| 1247 | { | - | ||||||||||||||||||
| 1248 | if (value.type == Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
| 1249 | switch (value.variant.toInt()) { | - | ||||||||||||||||||
| 1250 | case Value_None: font->setCapitalization(QFont::MixedCase); break; never executed: break;never executed: case Value_None: | 0 | ||||||||||||||||||
| 1251 | case Value_Uppercase: font->setCapitalization(QFont::AllUppercase); break; never executed: break;never executed: case Value_Uppercase: | 0 | ||||||||||||||||||
| 1252 | case Value_Lowercase: font->setCapitalization(QFont::AllLowercase); break; never executed: break;never executed: case Value_Lowercase: | 0 | ||||||||||||||||||
| 1253 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 1254 | } | - | ||||||||||||||||||
| 1255 | } | - | ||||||||||||||||||
| 1256 | } never executed: end of block | 0 | ||||||||||||||||||
| 1257 | - | |||||||||||||||||||
| 1258 | bool ValueExtractor::extractFont(QFont *font, int *fontSizeAdjustment) | - | ||||||||||||||||||
| 1259 | { | - | ||||||||||||||||||
| 1260 | if (fontExtracted) {
| 0 | ||||||||||||||||||
| 1261 | *font = f; | - | ||||||||||||||||||
| 1262 | *fontSizeAdjustment = adjustment; | - | ||||||||||||||||||
| 1263 | return fontExtracted == 1; never executed: return fontExtracted == 1; | 0 | ||||||||||||||||||
| 1264 | } | - | ||||||||||||||||||
| 1265 | - | |||||||||||||||||||
| 1266 | bool hit = false; | - | ||||||||||||||||||
| 1267 | for (int i = 0; i < declarations.count(); ++i) {
| 0 | ||||||||||||||||||
| 1268 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 1269 | if (decl.d->values.isEmpty())
| 0 | ||||||||||||||||||
| 1270 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1271 | const QCss::Value &val = decl.d->values.at(0); | - | ||||||||||||||||||
| 1272 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 1273 | case FontSize: setFontSizeFromValue(val, font, fontSizeAdjustment); break; never executed: break;never executed: case FontSize: | 0 | ||||||||||||||||||
| 1274 | case FontStyle: setFontStyleFromValue(val, font); break; never executed: break;never executed: case FontStyle: | 0 | ||||||||||||||||||
| 1275 | case FontWeight: setFontWeightFromValue(val, font); break; never executed: break;never executed: case FontWeight: | 0 | ||||||||||||||||||
| 1276 | case FontFamily: setFontFamilyFromValues(decl.d->values, font); break; never executed: break;never executed: case FontFamily: | 0 | ||||||||||||||||||
| 1277 | case TextDecoration: setTextDecorationFromValues(decl.d->values, font); break; never executed: break;never executed: case TextDecoration: | 0 | ||||||||||||||||||
| 1278 | case Font: parseShorthandFontProperty(decl.d->values, font, fontSizeAdjustment); break; never executed: break;never executed: case Font: | 0 | ||||||||||||||||||
| 1279 | case FontVariant: setFontVariantFromValue(val, font); break; never executed: break;never executed: case FontVariant: | 0 | ||||||||||||||||||
| 1280 | case TextTransform: setTextTransformFromValue(val, font); break; never executed: break;never executed: case TextTransform: | 0 | ||||||||||||||||||
| 1281 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 1282 | } | - | ||||||||||||||||||
| 1283 | hit = true; | - | ||||||||||||||||||
| 1284 | } never executed: end of block | 0 | ||||||||||||||||||
| 1285 | - | |||||||||||||||||||
| 1286 | f = *font; | - | ||||||||||||||||||
| 1287 | adjustment = *fontSizeAdjustment; | - | ||||||||||||||||||
| 1288 | fontExtracted = hit ? 1 : 2;
| 0 | ||||||||||||||||||
| 1289 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 1290 | } | - | ||||||||||||||||||
| 1291 | - | |||||||||||||||||||
| 1292 | bool ValueExtractor::extractPalette(QBrush *fg, QBrush *sfg, QBrush *sbg, QBrush *abg) | - | ||||||||||||||||||
| 1293 | { | - | ||||||||||||||||||
| 1294 | bool hit = false; | - | ||||||||||||||||||
| 1295 | for (int i = 0; i < declarations.count(); ++i) {
| 0 | ||||||||||||||||||
| 1296 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 1297 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 1298 | case Color: *fg = decl.brushValue(pal); break; never executed: break;never executed: case Color: | 0 | ||||||||||||||||||
| 1299 | case QtSelectionForeground: *sfg = decl.brushValue(pal); break; never executed: break;never executed: case QtSelectionForeground: | 0 | ||||||||||||||||||
| 1300 | case QtSelectionBackground: *sbg = decl.brushValue(pal); break; never executed: break;never executed: case QtSelectionBackground: | 0 | ||||||||||||||||||
| 1301 | case QtAlternateBackground: *abg = decl.brushValue(pal); break; never executed: break;never executed: case QtAlternateBackground: | 0 | ||||||||||||||||||
| 1302 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 1303 | } | - | ||||||||||||||||||
| 1304 | hit = true; | - | ||||||||||||||||||
| 1305 | } never executed: end of block | 0 | ||||||||||||||||||
| 1306 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 1307 | } | - | ||||||||||||||||||
| 1308 | - | |||||||||||||||||||
| 1309 | void ValueExtractor::extractFont() | - | ||||||||||||||||||
| 1310 | { | - | ||||||||||||||||||
| 1311 | if (fontExtracted)
| 0 | ||||||||||||||||||
| 1312 | return; never executed: return; | 0 | ||||||||||||||||||
| 1313 | int dummy = -255; | - | ||||||||||||||||||
| 1314 | extractFont(&f, &dummy); | - | ||||||||||||||||||
| 1315 | } never executed: end of block | 0 | ||||||||||||||||||
| 1316 | - | |||||||||||||||||||
| 1317 | bool ValueExtractor::extractImage(QIcon *icon, Qt::Alignment *a, QSize *size) | - | ||||||||||||||||||
| 1318 | { | - | ||||||||||||||||||
| 1319 | bool hit = false; | - | ||||||||||||||||||
| 1320 | for (int i = 0; i < declarations.count(); ++i) {
| 0 | ||||||||||||||||||
| 1321 | const Declaration &decl = declarations.at(i); | - | ||||||||||||||||||
| 1322 | switch (decl.d->propertyId) { | - | ||||||||||||||||||
| 1323 | case QtImage: never executed: case QtImage: | 0 | ||||||||||||||||||
| 1324 | *icon = decl.iconValue(); | - | ||||||||||||||||||
| 1325 | if (decl.d->values.count() > 0 && decl.d->values.at(0).type == Value::Uri) {
| 0 | ||||||||||||||||||
| 1326 | // try to pull just the size from the image... | - | ||||||||||||||||||
| 1327 | QImageReader imageReader(decl.d->values.at(0).variant.toString()); | - | ||||||||||||||||||
| 1328 | if ((*size = imageReader.size()).isNull()) {
| 0 | ||||||||||||||||||
| 1329 | // but we'll have to load the whole image if the | - | ||||||||||||||||||
| 1330 | // format doesn't support just reading the size | - | ||||||||||||||||||
| 1331 | *size = imageReader.read().size(); | - | ||||||||||||||||||
| 1332 | } never executed: end of block | 0 | ||||||||||||||||||
| 1333 | } never executed: end of block | 0 | ||||||||||||||||||
| 1334 | break; never executed: break; | 0 | ||||||||||||||||||
| 1335 | case QtImageAlignment: *a = decl.alignmentValue(); break; never executed: break;never executed: case QtImageAlignment: | 0 | ||||||||||||||||||
| 1336 | default: continue; never executed: continue;never executed: default: | 0 | ||||||||||||||||||
| 1337 | } | - | ||||||||||||||||||
| 1338 | hit = true; | - | ||||||||||||||||||
| 1339 | } never executed: end of block | 0 | ||||||||||||||||||
| 1340 | return hit; never executed: return hit; | 0 | ||||||||||||||||||
| 1341 | } | - | ||||||||||||||||||
| 1342 | - | |||||||||||||||||||
| 1343 | /////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||
| 1344 | // Declaration | - | ||||||||||||||||||
| 1345 | QColor Declaration::colorValue(const QPalette &pal) const | - | ||||||||||||||||||
| 1346 | { | - | ||||||||||||||||||
| 1347 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1348 | return QColor(); never executed: return QColor(); | 0 | ||||||||||||||||||
| 1349 | - | |||||||||||||||||||
| 1350 | if (d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 1351 | if (d->parsed.type() == QVariant::Color)
| 0 | ||||||||||||||||||
| 1352 | return qvariant_cast<QColor>(d->parsed); never executed: return qvariant_cast<QColor>(d->parsed); | 0 | ||||||||||||||||||
| 1353 | if (d->parsed.type() == QVariant::Int)
| 0 | ||||||||||||||||||
| 1354 | return pal.color((QPalette::ColorRole)(d->parsed.toInt())); never executed: return pal.color((QPalette::ColorRole)(d->parsed.toInt())); | 0 | ||||||||||||||||||
| 1355 | } never executed: end of block | 0 | ||||||||||||||||||
| 1356 | - | |||||||||||||||||||
| 1357 | ColorData color = parseColorValue(d->values.at(0)); | - | ||||||||||||||||||
| 1358 | if(color.type == ColorData::Role) {
| 0 | ||||||||||||||||||
| 1359 | d->parsed = QVariant::fromValue<int>(color.role); | - | ||||||||||||||||||
| 1360 | return pal.color((QPalette::ColorRole)(color.role)); never executed: return pal.color((QPalette::ColorRole)(color.role)); | 0 | ||||||||||||||||||
| 1361 | } else { | - | ||||||||||||||||||
| 1362 | d->parsed = QVariant::fromValue<QColor>(color.color); | - | ||||||||||||||||||
| 1363 | return color.color; never executed: return color.color; | 0 | ||||||||||||||||||
| 1364 | } | - | ||||||||||||||||||
| 1365 | } | - | ||||||||||||||||||
| 1366 | - | |||||||||||||||||||
| 1367 | QBrush Declaration::brushValue(const QPalette &pal) const | - | ||||||||||||||||||
| 1368 | { | - | ||||||||||||||||||
| 1369 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1370 | return QBrush(); never executed: return QBrush(); | 0 | ||||||||||||||||||
| 1371 | - | |||||||||||||||||||
| 1372 | if (d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 1373 | if (d->parsed.type() == QVariant::Brush)
| 0 | ||||||||||||||||||
| 1374 | return qvariant_cast<QBrush>(d->parsed); never executed: return qvariant_cast<QBrush>(d->parsed); | 0 | ||||||||||||||||||
| 1375 | if (d->parsed.type() == QVariant::Int)
| 0 | ||||||||||||||||||
| 1376 | return pal.color((QPalette::ColorRole)(d->parsed.toInt())); never executed: return pal.color((QPalette::ColorRole)(d->parsed.toInt())); | 0 | ||||||||||||||||||
| 1377 | } never executed: end of block | 0 | ||||||||||||||||||
| 1378 | - | |||||||||||||||||||
| 1379 | BrushData data = parseBrushValue(d->values.at(0), pal); | - | ||||||||||||||||||
| 1380 | - | |||||||||||||||||||
| 1381 | if(data.type == BrushData::Role) {
| 0 | ||||||||||||||||||
| 1382 | d->parsed = QVariant::fromValue<int>(data.role); | - | ||||||||||||||||||
| 1383 | return pal.color((QPalette::ColorRole)(data.role)); never executed: return pal.color((QPalette::ColorRole)(data.role)); | 0 | ||||||||||||||||||
| 1384 | } else { | - | ||||||||||||||||||
| 1385 | if (data.type != BrushData::DependsOnThePalette)
| 0 | ||||||||||||||||||
| 1386 | d->parsed = QVariant::fromValue<QBrush>(data.brush); never executed: d->parsed = QVariant::fromValue<QBrush>(data.brush); | 0 | ||||||||||||||||||
| 1387 | return data.brush; never executed: return data.brush; | 0 | ||||||||||||||||||
| 1388 | } | - | ||||||||||||||||||
| 1389 | } | - | ||||||||||||||||||
| 1390 | - | |||||||||||||||||||
| 1391 | void Declaration::brushValues(QBrush *c, const QPalette &pal) const | - | ||||||||||||||||||
| 1392 | { | - | ||||||||||||||||||
| 1393 | int needParse = 0x1f; // bits 0..3 say if we should parse the corresponding value. | - | ||||||||||||||||||
| 1394 | // the bit 4 say we need to update d->parsed | - | ||||||||||||||||||
| 1395 | int i = 0; | - | ||||||||||||||||||
| 1396 | if (d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 1397 | needParse = 0; | - | ||||||||||||||||||
| 1398 | QList<QVariant> v = d->parsed.toList(); | - | ||||||||||||||||||
| 1399 | for (i = 0; i < qMin(v.count(), 4); i++) {
| 0 | ||||||||||||||||||
| 1400 | if (v.at(i).type() == QVariant::Brush) {
| 0 | ||||||||||||||||||
| 1401 | c[i] = qvariant_cast<QBrush>(v.at(i)); | - | ||||||||||||||||||
| 1402 | } else if (v.at(i).type() == QVariant::Int) { never executed: end of block
| 0 | ||||||||||||||||||
| 1403 | c[i] = pal.color((QPalette::ColorRole)(v.at(i).toInt())); | - | ||||||||||||||||||
| 1404 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1405 | needParse |= (1<<i); | - | ||||||||||||||||||
| 1406 | } never executed: end of block | 0 | ||||||||||||||||||
| 1407 | } | - | ||||||||||||||||||
| 1408 | } never executed: end of block | 0 | ||||||||||||||||||
| 1409 | if (needParse != 0) {
| 0 | ||||||||||||||||||
| 1410 | QList<QVariant> v; | - | ||||||||||||||||||
| 1411 | for (i = 0; i < qMin(d->values.count(), 4); i++) {
| 0 | ||||||||||||||||||
| 1412 | if (!(needParse & (1<<i)))
| 0 | ||||||||||||||||||
| 1413 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1414 | BrushData data = parseBrushValue(d->values.at(i), pal); | - | ||||||||||||||||||
| 1415 | if(data.type == BrushData::Role) {
| 0 | ||||||||||||||||||
| 1416 | v += QVariant::fromValue<int>(data.role); | - | ||||||||||||||||||
| 1417 | c[i] = pal.color((QPalette::ColorRole)(data.role)); | - | ||||||||||||||||||
| 1418 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1419 | if (data.type != BrushData::DependsOnThePalette) {
| 0 | ||||||||||||||||||
| 1420 | v += QVariant::fromValue<QBrush>(data.brush); | - | ||||||||||||||||||
| 1421 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1422 | v += QVariant(); | - | ||||||||||||||||||
| 1423 | } never executed: end of block | 0 | ||||||||||||||||||
| 1424 | c[i] = data.brush; | - | ||||||||||||||||||
| 1425 | } never executed: end of block | 0 | ||||||||||||||||||
| 1426 | } | - | ||||||||||||||||||
| 1427 | if (needParse & 0x10)
| 0 | ||||||||||||||||||
| 1428 | d->parsed = v; never executed: d->parsed = v; | 0 | ||||||||||||||||||
| 1429 | } never executed: end of block | 0 | ||||||||||||||||||
| 1430 | if (i == 0) c[0] = c[1] = c[2] = c[3] = QBrush(); never executed: c[0] = c[1] = c[2] = c[3] = QBrush();
| 0 | ||||||||||||||||||
| 1431 | else if (i == 1) c[3] = c[2] = c[1] = c[0]; never executed: c[3] = c[2] = c[1] = c[0];
| 0 | ||||||||||||||||||
| 1432 | else if (i == 2) c[2] = c[0], c[3] = c[1]; never executed: c[2] = c[0], c[3] = c[1];
| 0 | ||||||||||||||||||
| 1433 | else if (i == 3) c[3] = c[1]; never executed: c[3] = c[1];
| 0 | ||||||||||||||||||
| 1434 | } never executed: end of block | 0 | ||||||||||||||||||
| 1435 | - | |||||||||||||||||||
| 1436 | bool Declaration::realValue(qreal *real, const char *unit) const | - | ||||||||||||||||||
| 1437 | { | - | ||||||||||||||||||
| 1438 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1439 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1440 | const Value &v = d->values.at(0); | - | ||||||||||||||||||
| 1441 | if (unit && v.type != Value::Length)
| 0 | ||||||||||||||||||
| 1442 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1443 | QString s = v.variant.toString(); | - | ||||||||||||||||||
| 1444 | if (unit) {
| 0 | ||||||||||||||||||
| 1445 | if (!s.endsWith(QLatin1String(unit), Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
| 1446 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1447 | s.chop(qstrlen(unit)); | - | ||||||||||||||||||
| 1448 | } never executed: end of block | 0 | ||||||||||||||||||
| 1449 | bool ok = false; | - | ||||||||||||||||||
| 1450 | qreal val = s.toDouble(&ok); | - | ||||||||||||||||||
| 1451 | if (ok)
| 0 | ||||||||||||||||||
| 1452 | *real = val; never executed: *real = val; | 0 | ||||||||||||||||||
| 1453 | return ok; never executed: return ok; | 0 | ||||||||||||||||||
| 1454 | } | - | ||||||||||||||||||
| 1455 | - | |||||||||||||||||||
| 1456 | static bool intValueHelper(const QCss::Value &v, int *i, const char *unit) | - | ||||||||||||||||||
| 1457 | { | - | ||||||||||||||||||
| 1458 | if (unit && v.type != Value::Length)
| 0 | ||||||||||||||||||
| 1459 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1460 | QString s = v.variant.toString(); | - | ||||||||||||||||||
| 1461 | if (unit) {
| 0 | ||||||||||||||||||
| 1462 | if (!s.endsWith(QLatin1String(unit), Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
| 1463 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1464 | s.chop(qstrlen(unit)); | - | ||||||||||||||||||
| 1465 | } never executed: end of block | 0 | ||||||||||||||||||
| 1466 | bool ok = false; | - | ||||||||||||||||||
| 1467 | int val = s.toInt(&ok); | - | ||||||||||||||||||
| 1468 | if (ok)
| 0 | ||||||||||||||||||
| 1469 | *i = val; never executed: *i = val; | 0 | ||||||||||||||||||
| 1470 | return ok; never executed: return ok; | 0 | ||||||||||||||||||
| 1471 | } | - | ||||||||||||||||||
| 1472 | - | |||||||||||||||||||
| 1473 | bool Declaration::intValue(int *i, const char *unit) const | - | ||||||||||||||||||
| 1474 | { | - | ||||||||||||||||||
| 1475 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1476 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1477 | return intValueHelper(d->values.at(0), i, unit); never executed: return intValueHelper(d->values.at(0), i, unit); | 0 | ||||||||||||||||||
| 1478 | } | - | ||||||||||||||||||
| 1479 | - | |||||||||||||||||||
| 1480 | QSize Declaration::sizeValue() const | - | ||||||||||||||||||
| 1481 | { | - | ||||||||||||||||||
| 1482 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1483 | return qvariant_cast<QSize>(d->parsed); never executed: return qvariant_cast<QSize>(d->parsed); | 0 | ||||||||||||||||||
| 1484 | - | |||||||||||||||||||
| 1485 | int x[2] = { 0, 0 }; | - | ||||||||||||||||||
| 1486 | if (d->values.count() > 0)
| 0 | ||||||||||||||||||
| 1487 | intValueHelper(d->values.at(0), &x[0], "px"); never executed: intValueHelper(d->values.at(0), &x[0], "px"); | 0 | ||||||||||||||||||
| 1488 | if (d->values.count() > 1)
| 0 | ||||||||||||||||||
| 1489 | intValueHelper(d->values.at(1), &x[1], "px"); never executed: intValueHelper(d->values.at(1), &x[1], "px"); | 0 | ||||||||||||||||||
| 1490 | else | - | ||||||||||||||||||
| 1491 | x[1] = x[0]; never executed: x[1] = x[0]; | 0 | ||||||||||||||||||
| 1492 | QSize size(x[0], x[1]); | - | ||||||||||||||||||
| 1493 | d->parsed = QVariant::fromValue<QSize>(size); | - | ||||||||||||||||||
| 1494 | return size; never executed: return size; | 0 | ||||||||||||||||||
| 1495 | } | - | ||||||||||||||||||
| 1496 | - | |||||||||||||||||||
| 1497 | QRect Declaration::rectValue() const | - | ||||||||||||||||||
| 1498 | { | - | ||||||||||||||||||
| 1499 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1500 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||
| 1501 | - | |||||||||||||||||||
| 1502 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1503 | return qvariant_cast<QRect>(d->parsed); never executed: return qvariant_cast<QRect>(d->parsed); | 0 | ||||||||||||||||||
| 1504 | - | |||||||||||||||||||
| 1505 | const QCss::Value &v = d->values.at(0); | - | ||||||||||||||||||
| 1506 | if (v.type != Value::Function)
| 0 | ||||||||||||||||||
| 1507 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||
| 1508 | QStringList func = v.variant.toStringList(); | - | ||||||||||||||||||
| 1509 | if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0)
| 0 | ||||||||||||||||||
| 1510 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||
| 1511 | QStringList args = func[1].split(QLatin1Char(' '), QString::SkipEmptyParts); | - | ||||||||||||||||||
| 1512 | if (args.count() != 4)
| 0 | ||||||||||||||||||
| 1513 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||
| 1514 | QRect rect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt()); | - | ||||||||||||||||||
| 1515 | d->parsed = QVariant::fromValue<QRect>(rect); | - | ||||||||||||||||||
| 1516 | return rect; never executed: return rect; | 0 | ||||||||||||||||||
| 1517 | } | - | ||||||||||||||||||
| 1518 | - | |||||||||||||||||||
| 1519 | void Declaration::colorValues(QColor *c, const QPalette &pal) const | - | ||||||||||||||||||
| 1520 | { | - | ||||||||||||||||||
| 1521 | int i; | - | ||||||||||||||||||
| 1522 | if (d->parsed.isValid()) {
| 0 | ||||||||||||||||||
| 1523 | QList<QVariant> v = d->parsed.toList(); | - | ||||||||||||||||||
| 1524 | for (i = 0; i < qMin(d->values.count(), 4); i++) {
| 0 | ||||||||||||||||||
| 1525 | if (v.at(i).type() == QVariant::Color) {
| 0 | ||||||||||||||||||
| 1526 | c[i] = qvariant_cast<QColor>(v.at(i)); | - | ||||||||||||||||||
| 1527 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1528 | c[i] = pal.color((QPalette::ColorRole)(v.at(i).toInt())); | - | ||||||||||||||||||
| 1529 | } never executed: end of block | 0 | ||||||||||||||||||
| 1530 | } | - | ||||||||||||||||||
| 1531 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1532 | QList<QVariant> v; | - | ||||||||||||||||||
| 1533 | for (i = 0; i < qMin(d->values.count(), 4); i++) {
| 0 | ||||||||||||||||||
| 1534 | ColorData color = parseColorValue(d->values.at(i)); | - | ||||||||||||||||||
| 1535 | if(color.type == ColorData::Role) {
| 0 | ||||||||||||||||||
| 1536 | v += QVariant::fromValue<int>(color.role); | - | ||||||||||||||||||
| 1537 | c[i] = pal.color((QPalette::ColorRole)(color.role)); | - | ||||||||||||||||||
| 1538 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1539 | v += QVariant::fromValue<QColor>(color.color); | - | ||||||||||||||||||
| 1540 | c[i] = color.color; | - | ||||||||||||||||||
| 1541 | } never executed: end of block | 0 | ||||||||||||||||||
| 1542 | } | - | ||||||||||||||||||
| 1543 | d->parsed = v; | - | ||||||||||||||||||
| 1544 | } never executed: end of block | 0 | ||||||||||||||||||
| 1545 | - | |||||||||||||||||||
| 1546 | if (i == 0) c[0] = c[1] = c[2] = c[3] = QColor(); never executed: c[0] = c[1] = c[2] = c[3] = QColor();
| 0 | ||||||||||||||||||
| 1547 | else if (i == 1) c[3] = c[2] = c[1] = c[0]; never executed: c[3] = c[2] = c[1] = c[0];
| 0 | ||||||||||||||||||
| 1548 | else if (i == 2) c[2] = c[0], c[3] = c[1]; never executed: c[2] = c[0], c[3] = c[1];
| 0 | ||||||||||||||||||
| 1549 | else if (i == 3) c[3] = c[1]; never executed: c[3] = c[1];
| 0 | ||||||||||||||||||
| 1550 | } never executed: end of block | 0 | ||||||||||||||||||
| 1551 | - | |||||||||||||||||||
| 1552 | BorderStyle Declaration::styleValue() const | - | ||||||||||||||||||
| 1553 | { | - | ||||||||||||||||||
| 1554 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1555 | return BorderStyle_None; never executed: return BorderStyle_None; | 0 | ||||||||||||||||||
| 1556 | return parseStyleValue(d->values.at(0)); never executed: return parseStyleValue(d->values.at(0)); | 0 | ||||||||||||||||||
| 1557 | } | - | ||||||||||||||||||
| 1558 | - | |||||||||||||||||||
| 1559 | void Declaration::styleValues(BorderStyle *s) const | - | ||||||||||||||||||
| 1560 | { | - | ||||||||||||||||||
| 1561 | int i; | - | ||||||||||||||||||
| 1562 | for (i = 0; i < qMin(d->values.count(), 4); i++)
| 0 | ||||||||||||||||||
| 1563 | s[i] = parseStyleValue(d->values.at(i)); never executed: s[i] = parseStyleValue(d->values.at(i)); | 0 | ||||||||||||||||||
| 1564 | if (i == 0) s[0] = s[1] = s[2] = s[3] = BorderStyle_None; never executed: s[0] = s[1] = s[2] = s[3] = BorderStyle_None;
| 0 | ||||||||||||||||||
| 1565 | else if (i == 1) s[3] = s[2] = s[1] = s[0]; never executed: s[3] = s[2] = s[1] = s[0];
| 0 | ||||||||||||||||||
| 1566 | else if (i == 2) s[2] = s[0], s[3] = s[1]; never executed: s[2] = s[0], s[3] = s[1];
| 0 | ||||||||||||||||||
| 1567 | else if (i == 3) s[3] = s[1]; never executed: s[3] = s[1];
| 0 | ||||||||||||||||||
| 1568 | } never executed: end of block | 0 | ||||||||||||||||||
| 1569 | - | |||||||||||||||||||
| 1570 | Repeat Declaration::repeatValue() const | - | ||||||||||||||||||
| 1571 | { | - | ||||||||||||||||||
| 1572 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1573 | return static_cast<Repeat>(d->parsed.toInt()); never executed: return static_cast<Repeat>(d->parsed.toInt()); | 0 | ||||||||||||||||||
| 1574 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1575 | return Repeat_Unknown; never executed: return Repeat_Unknown; | 0 | ||||||||||||||||||
| 1576 | int v = findKnownValue(d->values.at(0).variant.toString(), | - | ||||||||||||||||||
| 1577 | repeats, NumKnownRepeats); | - | ||||||||||||||||||
| 1578 | d->parsed = v; | - | ||||||||||||||||||
| 1579 | return static_cast<Repeat>(v); never executed: return static_cast<Repeat>(v); | 0 | ||||||||||||||||||
| 1580 | } | - | ||||||||||||||||||
| 1581 | - | |||||||||||||||||||
| 1582 | Origin Declaration::originValue() const | - | ||||||||||||||||||
| 1583 | { | - | ||||||||||||||||||
| 1584 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1585 | return static_cast<Origin>(d->parsed.toInt()); never executed: return static_cast<Origin>(d->parsed.toInt()); | 0 | ||||||||||||||||||
| 1586 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1587 | return Origin_Unknown; never executed: return Origin_Unknown; | 0 | ||||||||||||||||||
| 1588 | int v = findKnownValue(d->values.at(0).variant.toString(), | - | ||||||||||||||||||
| 1589 | origins, NumKnownOrigins); | - | ||||||||||||||||||
| 1590 | d->parsed = v; | - | ||||||||||||||||||
| 1591 | return static_cast<Origin>(v); never executed: return static_cast<Origin>(v); | 0 | ||||||||||||||||||
| 1592 | } | - | ||||||||||||||||||
| 1593 | - | |||||||||||||||||||
| 1594 | PositionMode Declaration::positionValue() const | - | ||||||||||||||||||
| 1595 | { | - | ||||||||||||||||||
| 1596 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1597 | return static_cast<PositionMode>(d->parsed.toInt()); never executed: return static_cast<PositionMode>(d->parsed.toInt()); | 0 | ||||||||||||||||||
| 1598 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1599 | return PositionMode_Unknown; never executed: return PositionMode_Unknown; | 0 | ||||||||||||||||||
| 1600 | int v = findKnownValue(d->values.at(0).variant.toString(), | - | ||||||||||||||||||
| 1601 | positions, NumKnownPositionModes); | - | ||||||||||||||||||
| 1602 | d->parsed = v; | - | ||||||||||||||||||
| 1603 | return static_cast<PositionMode>(v); never executed: return static_cast<PositionMode>(v); | 0 | ||||||||||||||||||
| 1604 | } | - | ||||||||||||||||||
| 1605 | - | |||||||||||||||||||
| 1606 | Attachment Declaration::attachmentValue() const | - | ||||||||||||||||||
| 1607 | { | - | ||||||||||||||||||
| 1608 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1609 | return static_cast<Attachment>(d->parsed.toInt()); never executed: return static_cast<Attachment>(d->parsed.toInt()); | 0 | ||||||||||||||||||
| 1610 | if (d->values.count() != 1)
| 0 | ||||||||||||||||||
| 1611 | return Attachment_Unknown; never executed: return Attachment_Unknown; | 0 | ||||||||||||||||||
| 1612 | int v = findKnownValue(d->values.at(0).variant.toString(), | - | ||||||||||||||||||
| 1613 | attachments, NumKnownAttachments); | - | ||||||||||||||||||
| 1614 | d->parsed = v; | - | ||||||||||||||||||
| 1615 | return static_cast<Attachment>(v); never executed: return static_cast<Attachment>(v); | 0 | ||||||||||||||||||
| 1616 | } | - | ||||||||||||||||||
| 1617 | - | |||||||||||||||||||
| 1618 | int Declaration::styleFeaturesValue() const | - | ||||||||||||||||||
| 1619 | { | - | ||||||||||||||||||
| 1620 | Q_ASSERT(d->propertyId == QtStyleFeatures); | - | ||||||||||||||||||
| 1621 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1622 | return d->parsed.toInt(); never executed: return d->parsed.toInt(); | 0 | ||||||||||||||||||
| 1623 | int features = StyleFeature_None; | - | ||||||||||||||||||
| 1624 | for (int i = 0; i < d->values.count(); i++) {
| 0 | ||||||||||||||||||
| 1625 | features |= static_cast<int>(findKnownValue(d->values.value(i).variant.toString(), | - | ||||||||||||||||||
| 1626 | styleFeatures, NumKnownStyleFeatures)); | - | ||||||||||||||||||
| 1627 | } never executed: end of block | 0 | ||||||||||||||||||
| 1628 | d->parsed = features; | - | ||||||||||||||||||
| 1629 | return features; never executed: return features; | 0 | ||||||||||||||||||
| 1630 | } | - | ||||||||||||||||||
| 1631 | - | |||||||||||||||||||
| 1632 | QString Declaration::uriValue() const | - | ||||||||||||||||||
| 1633 | { | - | ||||||||||||||||||
| 1634 | if (d->values.isEmpty() || d->values.at(0).type != Value::Uri)
| 0 | ||||||||||||||||||
| 1635 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 1636 | return d->values.at(0).variant.toString(); never executed: return d->values.at(0).variant.toString(); | 0 | ||||||||||||||||||
| 1637 | } | - | ||||||||||||||||||
| 1638 | - | |||||||||||||||||||
| 1639 | Qt::Alignment Declaration::alignmentValue() const | - | ||||||||||||||||||
| 1640 | { | - | ||||||||||||||||||
| 1641 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1642 | return Qt::Alignment(d->parsed.toInt()); never executed: return Qt::Alignment(d->parsed.toInt()); | 0 | ||||||||||||||||||
| 1643 | if (d->values.isEmpty() || d->values.count() > 2)
| 0 | ||||||||||||||||||
| 1644 | return Qt::AlignLeft | Qt::AlignTop; never executed: return Qt::AlignLeft | Qt::AlignTop; | 0 | ||||||||||||||||||
| 1645 | - | |||||||||||||||||||
| 1646 | Qt::Alignment v = parseAlignment(d->values.constData(), d->values.count()); | - | ||||||||||||||||||
| 1647 | d->parsed = int(v); | - | ||||||||||||||||||
| 1648 | return v; never executed: return v; | 0 | ||||||||||||||||||
| 1649 | } | - | ||||||||||||||||||
| 1650 | - | |||||||||||||||||||
| 1651 | void Declaration::borderImageValue(QString *image, int *cuts, | - | ||||||||||||||||||
| 1652 | TileMode *h, TileMode *v) const | - | ||||||||||||||||||
| 1653 | { | - | ||||||||||||||||||
| 1654 | *image = uriValue(); | - | ||||||||||||||||||
| 1655 | for (int i = 0; i < 4; i++)
| 0 | ||||||||||||||||||
| 1656 | cuts[i] = -1; never executed: cuts[i] = -1; | 0 | ||||||||||||||||||
| 1657 | *h = *v = TileMode_Stretch; | - | ||||||||||||||||||
| 1658 | - | |||||||||||||||||||
| 1659 | if (d->values.count() < 2)
| 0 | ||||||||||||||||||
| 1660 | return; never executed: return; | 0 | ||||||||||||||||||
| 1661 | - | |||||||||||||||||||
| 1662 | if (d->values.at(1).type == Value::Number) { // cuts!
| 0 | ||||||||||||||||||
| 1663 | int i; | - | ||||||||||||||||||
| 1664 | for (i = 0; i < qMin(d->values.count()-1, 4); i++) {
| 0 | ||||||||||||||||||
| 1665 | const Value& v = d->values.at(i+1); | - | ||||||||||||||||||
| 1666 | if (v.type != Value::Number)
| 0 | ||||||||||||||||||
| 1667 | break; never executed: break; | 0 | ||||||||||||||||||
| 1668 | cuts[i] = v.variant.toString().toInt(); | - | ||||||||||||||||||
| 1669 | } never executed: end of block | 0 | ||||||||||||||||||
| 1670 | if (i == 0) cuts[0] = cuts[1] = cuts[2] = cuts[3] = 0; never executed: cuts[0] = cuts[1] = cuts[2] = cuts[3] = 0;
| 0 | ||||||||||||||||||
| 1671 | else if (i == 1) cuts[3] = cuts[2] = cuts[1] = cuts[0]; never executed: cuts[3] = cuts[2] = cuts[1] = cuts[0];
| 0 | ||||||||||||||||||
| 1672 | else if (i == 2) cuts[2] = cuts[0], cuts[3] = cuts[1]; never executed: cuts[2] = cuts[0], cuts[3] = cuts[1];
| 0 | ||||||||||||||||||
| 1673 | else if (i == 3) cuts[3] = cuts[1]; never executed: cuts[3] = cuts[1];
| 0 | ||||||||||||||||||
| 1674 | } never executed: end of block | 0 | ||||||||||||||||||
| 1675 | - | |||||||||||||||||||
| 1676 | if (d->values.last().type == Value::Identifier) {
| 0 | ||||||||||||||||||
| 1677 | *v = static_cast<TileMode>(findKnownValue(d->values.last().variant.toString(), | - | ||||||||||||||||||
| 1678 | tileModes, NumKnownTileModes)); | - | ||||||||||||||||||
| 1679 | } never executed: end of block | 0 | ||||||||||||||||||
| 1680 | if (d->values[d->values.count() - 2].type == Value::Identifier) {
| 0 | ||||||||||||||||||
| 1681 | *h = static_cast<TileMode> | - | ||||||||||||||||||
| 1682 | (findKnownValue(d->values[d->values.count()-2].variant.toString(), | - | ||||||||||||||||||
| 1683 | tileModes, NumKnownTileModes)); | - | ||||||||||||||||||
| 1684 | } else never executed: end of block | 0 | ||||||||||||||||||
| 1685 | *h = *v; never executed: *h = *v; | 0 | ||||||||||||||||||
| 1686 | } | - | ||||||||||||||||||
| 1687 | - | |||||||||||||||||||
| 1688 | QIcon Declaration::iconValue() const | - | ||||||||||||||||||
| 1689 | { | - | ||||||||||||||||||
| 1690 | if (d->parsed.isValid())
| 0 | ||||||||||||||||||
| 1691 | return qvariant_cast<QIcon>(d->parsed); never executed: return qvariant_cast<QIcon>(d->parsed); | 0 | ||||||||||||||||||
| 1692 | - | |||||||||||||||||||
| 1693 | QIcon icon; | - | ||||||||||||||||||
| 1694 | for (int i = 0; i < d->values.count();) {
| 0 | ||||||||||||||||||
| 1695 | const Value &value = d->values.at(i++); | - | ||||||||||||||||||
| 1696 | if (value.type != Value::Uri)
| 0 | ||||||||||||||||||
| 1697 | break; never executed: break; | 0 | ||||||||||||||||||
| 1698 | QString uri = value.variant.toString(); | - | ||||||||||||||||||
| 1699 | QIcon::Mode mode = QIcon::Normal; | - | ||||||||||||||||||
| 1700 | QIcon::State state = QIcon::Off; | - | ||||||||||||||||||
| 1701 | for (int j = 0; j < 2; j++) {
| 0 | ||||||||||||||||||
| 1702 | if (i != d->values.count() && d->values.at(i).type == Value::KnownIdentifier) {
| 0 | ||||||||||||||||||
| 1703 | switch (d->values.at(i).variant.toInt()) { | - | ||||||||||||||||||
| 1704 | case Value_Disabled: mode = QIcon::Disabled; break; never executed: break;never executed: case Value_Disabled: | 0 | ||||||||||||||||||
| 1705 | case Value_Active: mode = QIcon::Active; break; never executed: break;never executed: case Value_Active: | 0 | ||||||||||||||||||
| 1706 | case Value_Selected: mode = QIcon::Selected; break; never executed: break;never executed: case Value_Selected: | 0 | ||||||||||||||||||
| 1707 | case Value_Normal: mode = QIcon::Normal; break; never executed: break;never executed: case Value_Normal: | 0 | ||||||||||||||||||
| 1708 | case Value_On: state = QIcon::On; break; never executed: break;never executed: case Value_On: | 0 | ||||||||||||||||||
| 1709 | case Value_Off: state = QIcon::Off; break; never executed: break;never executed: case Value_Off: | 0 | ||||||||||||||||||
| 1710 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 1711 | } | - | ||||||||||||||||||
| 1712 | ++i; | - | ||||||||||||||||||
| 1713 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1714 | break; never executed: break; | 0 | ||||||||||||||||||
| 1715 | } | - | ||||||||||||||||||
| 1716 | } | - | ||||||||||||||||||
| 1717 | - | |||||||||||||||||||
| 1718 | // QIcon is soo broken | - | ||||||||||||||||||
| 1719 | if (icon.isNull())
| 0 | ||||||||||||||||||
| 1720 | icon = QIcon(uri); never executed: icon = QIcon(uri); | 0 | ||||||||||||||||||
| 1721 | else | - | ||||||||||||||||||
| 1722 | icon.addPixmap(uri, mode, state); never executed: icon.addPixmap(uri, mode, state); | 0 | ||||||||||||||||||
| 1723 | - | |||||||||||||||||||
| 1724 | if (i == d->values.count())
| 0 | ||||||||||||||||||
| 1725 | break; never executed: break; | 0 | ||||||||||||||||||
| 1726 | - | |||||||||||||||||||
| 1727 | if (d->values.at(i).type == Value::TermOperatorComma)
| 0 | ||||||||||||||||||
| 1728 | i++; never executed: i++; | 0 | ||||||||||||||||||
| 1729 | } never executed: end of block | 0 | ||||||||||||||||||
| 1730 | - | |||||||||||||||||||
| 1731 | d->parsed = QVariant::fromValue<QIcon>(icon); | - | ||||||||||||||||||
| 1732 | return icon; never executed: return icon; | 0 | ||||||||||||||||||
| 1733 | } | - | ||||||||||||||||||
| 1734 | - | |||||||||||||||||||
| 1735 | /////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||
| 1736 | // Selector | - | ||||||||||||||||||
| 1737 | int Selector::specificity() const | - | ||||||||||||||||||
| 1738 | { | - | ||||||||||||||||||
| 1739 | int val = 0; | - | ||||||||||||||||||
| 1740 | for (int i = 0; i < basicSelectors.count(); ++i) {
| 0 | ||||||||||||||||||
| 1741 | const BasicSelector &sel = basicSelectors.at(i); | - | ||||||||||||||||||
| 1742 | if (!sel.elementName.isEmpty())
| 0 | ||||||||||||||||||
| 1743 | val += 1; never executed: val += 1; | 0 | ||||||||||||||||||
| 1744 | - | |||||||||||||||||||
| 1745 | val += (sel.pseudos.count() + sel.attributeSelectors.count()) * 0x10; | - | ||||||||||||||||||
| 1746 | val += sel.ids.count() * 0x100; | - | ||||||||||||||||||
| 1747 | } never executed: end of block | 0 | ||||||||||||||||||
| 1748 | return val; never executed: return val; | 0 | ||||||||||||||||||
| 1749 | } | - | ||||||||||||||||||
| 1750 | - | |||||||||||||||||||
| 1751 | QString Selector::pseudoElement() const | - | ||||||||||||||||||
| 1752 | { | - | ||||||||||||||||||
| 1753 | const BasicSelector& bs = basicSelectors.last(); | - | ||||||||||||||||||
| 1754 | if (!bs.pseudos.isEmpty() && bs.pseudos.at(0).type == PseudoClass_Unknown)
| 0 | ||||||||||||||||||
| 1755 | return bs.pseudos.at(0).name; never executed: return bs.pseudos.at(0).name; | 0 | ||||||||||||||||||
| 1756 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 1757 | } | - | ||||||||||||||||||
| 1758 | - | |||||||||||||||||||
| 1759 | quint64 Selector::pseudoClass(quint64 *negated) const | - | ||||||||||||||||||
| 1760 | { | - | ||||||||||||||||||
| 1761 | const BasicSelector& bs = basicSelectors.last(); | - | ||||||||||||||||||
| 1762 | if (bs.pseudos.isEmpty())
| 0 | ||||||||||||||||||
| 1763 | return PseudoClass_Unspecified; never executed: return PseudoClass_Unspecified; | 0 | ||||||||||||||||||
| 1764 | quint64 pc = PseudoClass_Unknown; | - | ||||||||||||||||||
| 1765 | for (int i = !pseudoElement().isEmpty(); i < bs.pseudos.count(); i++) {
| 0 | ||||||||||||||||||
| 1766 | const Pseudo &pseudo = bs.pseudos.at(i); | - | ||||||||||||||||||
| 1767 | if (pseudo.type == PseudoClass_Unknown)
| 0 | ||||||||||||||||||
| 1768 | return PseudoClass_Unknown; never executed: return PseudoClass_Unknown; | 0 | ||||||||||||||||||
| 1769 | if (!pseudo.negated)
| 0 | ||||||||||||||||||
| 1770 | pc |= pseudo.type; never executed: pc |= pseudo.type; | 0 | ||||||||||||||||||
| 1771 | else if (negated)
| 0 | ||||||||||||||||||
| 1772 | *negated |= pseudo.type; never executed: *negated |= pseudo.type; | 0 | ||||||||||||||||||
| 1773 | } never executed: end of block | 0 | ||||||||||||||||||
| 1774 | return pc; never executed: return pc; | 0 | ||||||||||||||||||
| 1775 | } | - | ||||||||||||||||||
| 1776 | - | |||||||||||||||||||
| 1777 | /////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||
| 1778 | // StyleSheet | - | ||||||||||||||||||
| 1779 | void StyleSheet::buildIndexes(Qt::CaseSensitivity nameCaseSensitivity) | - | ||||||||||||||||||
| 1780 | { | - | ||||||||||||||||||
| 1781 | QVector<StyleRule> universals; | - | ||||||||||||||||||
| 1782 | for (int i = 0; i < styleRules.count(); ++i) {
| 0 | ||||||||||||||||||
| 1783 | const StyleRule &rule = styleRules.at(i); | - | ||||||||||||||||||
| 1784 | QVector<Selector> universalsSelectors; | - | ||||||||||||||||||
| 1785 | for (int j = 0; j < rule.selectors.count(); ++j) {
| 0 | ||||||||||||||||||
| 1786 | const Selector& selector = rule.selectors.at(j); | - | ||||||||||||||||||
| 1787 | - | |||||||||||||||||||
| 1788 | if (selector.basicSelectors.isEmpty())
| 0 | ||||||||||||||||||
| 1789 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1790 | - | |||||||||||||||||||
| 1791 | if (selector.basicSelectors.at(0).relationToNext == BasicSelector::NoRelation) {
| 0 | ||||||||||||||||||
| 1792 | if (selector.basicSelectors.count() != 1)
| 0 | ||||||||||||||||||
| 1793 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1794 | } else if (selector.basicSelectors.count() <= 1) { never executed: end of block
| 0 | ||||||||||||||||||
| 1795 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1796 | } | - | ||||||||||||||||||
| 1797 | - | |||||||||||||||||||
| 1798 | const BasicSelector &sel = selector.basicSelectors.at(selector.basicSelectors.count() - 1); | - | ||||||||||||||||||
| 1799 | - | |||||||||||||||||||
| 1800 | if (!sel.ids.isEmpty()) {
| 0 | ||||||||||||||||||
| 1801 | StyleRule nr; | - | ||||||||||||||||||
| 1802 | nr.selectors += selector; | - | ||||||||||||||||||
| 1803 | nr.declarations = rule.declarations; | - | ||||||||||||||||||
| 1804 | nr.order = i; | - | ||||||||||||||||||
| 1805 | idIndex.insert(sel.ids.at(0), nr); | - | ||||||||||||||||||
| 1806 | } else if (!sel.elementName.isEmpty()) { never executed: end of block
| 0 | ||||||||||||||||||
| 1807 | StyleRule nr; | - | ||||||||||||||||||
| 1808 | nr.selectors += selector; | - | ||||||||||||||||||
| 1809 | nr.declarations = rule.declarations; | - | ||||||||||||||||||
| 1810 | nr.order = i; | - | ||||||||||||||||||
| 1811 | QString name = sel.elementName; | - | ||||||||||||||||||
| 1812 | if (nameCaseSensitivity == Qt::CaseInsensitive)
| 0 | ||||||||||||||||||
| 1813 | name=name.toLower(); never executed: name=name.toLower(); | 0 | ||||||||||||||||||
| 1814 | nameIndex.insert(name, nr); | - | ||||||||||||||||||
| 1815 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1816 | universalsSelectors += selector; | - | ||||||||||||||||||
| 1817 | } never executed: end of block | 0 | ||||||||||||||||||
| 1818 | } | - | ||||||||||||||||||
| 1819 | if (!universalsSelectors.isEmpty()) {
| 0 | ||||||||||||||||||
| 1820 | StyleRule nr; | - | ||||||||||||||||||
| 1821 | nr.selectors = universalsSelectors; | - | ||||||||||||||||||
| 1822 | nr.declarations = rule.declarations; | - | ||||||||||||||||||
| 1823 | nr.order = i; | - | ||||||||||||||||||
| 1824 | universals << nr; | - | ||||||||||||||||||
| 1825 | } never executed: end of block | 0 | ||||||||||||||||||
| 1826 | } never executed: end of block | 0 | ||||||||||||||||||
| 1827 | styleRules = universals; | - | ||||||||||||||||||
| 1828 | } never executed: end of block | 0 | ||||||||||||||||||
| 1829 | - | |||||||||||||||||||
| 1830 | /////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||
| 1831 | // StyleSelector | - | ||||||||||||||||||
| 1832 | StyleSelector::~StyleSelector() | - | ||||||||||||||||||
| 1833 | { | - | ||||||||||||||||||
| 1834 | } | - | ||||||||||||||||||
| 1835 | - | |||||||||||||||||||
| 1836 | bool StyleSelector::nodeNameEquals(NodePtr node, const QString& nodeName) const | - | ||||||||||||||||||
| 1837 | { | - | ||||||||||||||||||
| 1838 | return nodeNames(node).contains(nodeName, nameCaseSensitivity); never executed: return nodeNames(node).contains(nodeName, nameCaseSensitivity); | 0 | ||||||||||||||||||
| 1839 | } | - | ||||||||||||||||||
| 1840 | - | |||||||||||||||||||
| 1841 | QStringList StyleSelector::nodeIds(NodePtr node) const | - | ||||||||||||||||||
| 1842 | { | - | ||||||||||||||||||
| 1843 | return QStringList(attribute(node, QLatin1String("id"))); never executed: return QStringList(attribute(node, QLatin1String("id"))); | 0 | ||||||||||||||||||
| 1844 | } | - | ||||||||||||||||||
| 1845 | - | |||||||||||||||||||
| 1846 | bool StyleSelector::selectorMatches(const Selector &selector, NodePtr node) | - | ||||||||||||||||||
| 1847 | { | - | ||||||||||||||||||
| 1848 | if (selector.basicSelectors.isEmpty())
| 0 | ||||||||||||||||||
| 1849 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1850 | - | |||||||||||||||||||
| 1851 | if (selector.basicSelectors.at(0).relationToNext == BasicSelector::NoRelation) {
| 0 | ||||||||||||||||||
| 1852 | if (selector.basicSelectors.count() != 1)
| 0 | ||||||||||||||||||
| 1853 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1854 | return basicSelectorMatches(selector.basicSelectors.at(0), node); never executed: return basicSelectorMatches(selector.basicSelectors.at(0), node); | 0 | ||||||||||||||||||
| 1855 | } | - | ||||||||||||||||||
| 1856 | if (selector.basicSelectors.count() <= 1)
| 0 | ||||||||||||||||||
| 1857 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1858 | - | |||||||||||||||||||
| 1859 | int i = selector.basicSelectors.count() - 1; | - | ||||||||||||||||||
| 1860 | node = duplicateNode(node); | - | ||||||||||||||||||
| 1861 | bool match = true; | - | ||||||||||||||||||
| 1862 | - | |||||||||||||||||||
| 1863 | BasicSelector sel = selector.basicSelectors.at(i); | - | ||||||||||||||||||
| 1864 | do { | - | ||||||||||||||||||
| 1865 | match = basicSelectorMatches(sel, node); | - | ||||||||||||||||||
| 1866 | if (!match) {
| 0 | ||||||||||||||||||
| 1867 | if (sel.relationToNext == BasicSelector::MatchNextSelectorIfParent
| 0 | ||||||||||||||||||
| 1868 | || i == selector.basicSelectors.count() - 1) // first element must always match!
| 0 | ||||||||||||||||||
| 1869 | break; never executed: break; | 0 | ||||||||||||||||||
| 1870 | } never executed: end of block | 0 | ||||||||||||||||||
| 1871 | - | |||||||||||||||||||
| 1872 | if (match || sel.relationToNext != BasicSelector::MatchNextSelectorIfAncestor)
| 0 | ||||||||||||||||||
| 1873 | --i; never executed: --i; | 0 | ||||||||||||||||||
| 1874 | - | |||||||||||||||||||
| 1875 | if (i < 0)
| 0 | ||||||||||||||||||
| 1876 | break; never executed: break; | 0 | ||||||||||||||||||
| 1877 | - | |||||||||||||||||||
| 1878 | sel = selector.basicSelectors.at(i); | - | ||||||||||||||||||
| 1879 | if (sel.relationToNext == BasicSelector::MatchNextSelectorIfAncestor
| 0 | ||||||||||||||||||
| 1880 | || sel.relationToNext == BasicSelector::MatchNextSelectorIfParent) {
| 0 | ||||||||||||||||||
| 1881 | - | |||||||||||||||||||
| 1882 | NodePtr nextParent = parentNode(node); | - | ||||||||||||||||||
| 1883 | freeNode(node); | - | ||||||||||||||||||
| 1884 | node = nextParent; | - | ||||||||||||||||||
| 1885 | } else if (sel.relationToNext == BasicSelector::MatchNextSelectorIfPreceeds) { never executed: end of block
| 0 | ||||||||||||||||||
| 1886 | NodePtr previousSibling = previousSiblingNode(node); | - | ||||||||||||||||||
| 1887 | freeNode(node); | - | ||||||||||||||||||
| 1888 | node = previousSibling; | - | ||||||||||||||||||
| 1889 | } never executed: end of block | 0 | ||||||||||||||||||
| 1890 | if (isNullNode(node)) {
| 0 | ||||||||||||||||||
| 1891 | match = false; | - | ||||||||||||||||||
| 1892 | break; never executed: break; | 0 | ||||||||||||||||||
| 1893 | } | - | ||||||||||||||||||
| 1894 | } while (i >= 0 && (match || sel.relationToNext == BasicSelector::MatchNextSelectorIfAncestor)); never executed: end of block
| 0 | ||||||||||||||||||
| 1895 | - | |||||||||||||||||||
| 1896 | freeNode(node); | - | ||||||||||||||||||
| 1897 | - | |||||||||||||||||||
| 1898 | return match; never executed: return match; | 0 | ||||||||||||||||||
| 1899 | } | - | ||||||||||||||||||
| 1900 | - | |||||||||||||||||||
| 1901 | bool StyleSelector::basicSelectorMatches(const BasicSelector &sel, NodePtr node) | - | ||||||||||||||||||
| 1902 | { | - | ||||||||||||||||||
| 1903 | if (!sel.attributeSelectors.isEmpty()) {
| 0 | ||||||||||||||||||
| 1904 | if (!hasAttributes(node))
| 0 | ||||||||||||||||||
| 1905 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1906 | - | |||||||||||||||||||
| 1907 | for (int i = 0; i < sel.attributeSelectors.count(); ++i) {
| 0 | ||||||||||||||||||
| 1908 | const QCss::AttributeSelector &a = sel.attributeSelectors.at(i); | - | ||||||||||||||||||
| 1909 | - | |||||||||||||||||||
| 1910 | const QString attrValue = attribute(node, a.name); | - | ||||||||||||||||||
| 1911 | if (attrValue.isNull())
| 0 | ||||||||||||||||||
| 1912 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1913 | - | |||||||||||||||||||
| 1914 | if (a.valueMatchCriterium == QCss::AttributeSelector::MatchContains) {
| 0 | ||||||||||||||||||
| 1915 | - | |||||||||||||||||||
| 1916 | QStringList lst = attrValue.split(QLatin1Char(' ')); | - | ||||||||||||||||||
| 1917 | if (!lst.contains(a.value))
| 0 | ||||||||||||||||||
| 1918 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1919 | } else if ( never executed: end of block | 0 | ||||||||||||||||||
| 1920 | (a.valueMatchCriterium == QCss::AttributeSelector::MatchEqual
| 0 | ||||||||||||||||||
| 1921 | && attrValue != a.value)
| 0 | ||||||||||||||||||
| 1922 | || | - | ||||||||||||||||||
| 1923 | (a.valueMatchCriterium == QCss::AttributeSelector::MatchBeginsWith
| 0 | ||||||||||||||||||
| 1924 | && !attrValue.startsWith(a.value))
| 0 | ||||||||||||||||||
| 1925 | ) | - | ||||||||||||||||||
| 1926 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1927 | } never executed: end of block | 0 | ||||||||||||||||||
| 1928 | } never executed: end of block | 0 | ||||||||||||||||||
| 1929 | - | |||||||||||||||||||
| 1930 | if (!sel.elementName.isEmpty()
| 0 | ||||||||||||||||||
| 1931 | && !nodeNameEquals(node, sel.elementName))
| 0 | ||||||||||||||||||
| 1932 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1933 | - | |||||||||||||||||||
| 1934 | if (!sel.ids.isEmpty()
| 0 | ||||||||||||||||||
| 1935 | && sel.ids != nodeIds(node))
| 0 | ||||||||||||||||||
| 1936 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1937 | - | |||||||||||||||||||
| 1938 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 1939 | } | - | ||||||||||||||||||
| 1940 | - | |||||||||||||||||||
| 1941 | void StyleSelector::matchRule(NodePtr node, const StyleRule &rule, StyleSheetOrigin origin, | - | ||||||||||||||||||
| 1942 | int depth, QMap<uint, StyleRule> *weightedRules) | - | ||||||||||||||||||
| 1943 | { | - | ||||||||||||||||||
| 1944 | for (int j = 0; j < rule.selectors.count(); ++j) {
| 0 | ||||||||||||||||||
| 1945 | const Selector& selector = rule.selectors.at(j); | - | ||||||||||||||||||
| 1946 | if (selectorMatches(selector, node)) {
| 0 | ||||||||||||||||||
| 1947 | uint weight = rule.order | - | ||||||||||||||||||
| 1948 | + selector.specificity() *0x100 | - | ||||||||||||||||||
| 1949 | + (uint(origin) + depth)*0x100000; | - | ||||||||||||||||||
| 1950 | StyleRule newRule = rule; | - | ||||||||||||||||||
| 1951 | if(rule.selectors.count() > 1) {
| 0 | ||||||||||||||||||
| 1952 | newRule.selectors.resize(1); | - | ||||||||||||||||||
| 1953 | newRule.selectors[0] = selector; | - | ||||||||||||||||||
| 1954 | } never executed: end of block | 0 | ||||||||||||||||||
| 1955 | //We might have rules with the same weight if they came from a rule with several selectors | - | ||||||||||||||||||
| 1956 | weightedRules->insertMulti(weight, newRule); | - | ||||||||||||||||||
| 1957 | } never executed: end of block | 0 | ||||||||||||||||||
| 1958 | } never executed: end of block | 0 | ||||||||||||||||||
| 1959 | } never executed: end of block | 0 | ||||||||||||||||||
| 1960 | - | |||||||||||||||||||
| 1961 | // Returns style rules that are in ascending order of specificity | - | ||||||||||||||||||
| 1962 | // Each of the StyleRule returned will contain exactly one Selector | - | ||||||||||||||||||
| 1963 | QVector<StyleRule> StyleSelector::styleRulesForNode(NodePtr node) | - | ||||||||||||||||||
| 1964 | { | - | ||||||||||||||||||
| 1965 | QVector<StyleRule> rules; | - | ||||||||||||||||||
| 1966 | if (styleSheets.isEmpty())
| 0 | ||||||||||||||||||
| 1967 | return rules; never executed: return rules; | 0 | ||||||||||||||||||
| 1968 | - | |||||||||||||||||||
| 1969 | QMap<uint, StyleRule> weightedRules; // (spec, rule) that will be sorted below | - | ||||||||||||||||||
| 1970 | - | |||||||||||||||||||
| 1971 | //prune using indexed stylesheet | - | ||||||||||||||||||
| 1972 | for (int sheetIdx = 0; sheetIdx < styleSheets.count(); ++sheetIdx) {
| 0 | ||||||||||||||||||
| 1973 | const StyleSheet &styleSheet = styleSheets.at(sheetIdx); | - | ||||||||||||||||||
| 1974 | for (int i = 0; i < styleSheet.styleRules.count(); ++i) {
| 0 | ||||||||||||||||||
| 1975 | matchRule(node, styleSheet.styleRules.at(i), styleSheet.origin, styleSheet.depth, &weightedRules); | - | ||||||||||||||||||
| 1976 | } never executed: end of block | 0 | ||||||||||||||||||
| 1977 | - | |||||||||||||||||||
| 1978 | if (!styleSheet.idIndex.isEmpty()) {
| 0 | ||||||||||||||||||
| 1979 | QStringList ids = nodeIds(node); | - | ||||||||||||||||||
| 1980 | for (int i = 0; i < ids.count(); i++) {
| 0 | ||||||||||||||||||
| 1981 | const QString &key = ids.at(i); | - | ||||||||||||||||||
| 1982 | QMultiHash<QString, StyleRule>::const_iterator it = styleSheet.idIndex.constFind(key); | - | ||||||||||||||||||
| 1983 | while (it != styleSheet.idIndex.constEnd() && it.key() == key) {
| 0 | ||||||||||||||||||
| 1984 | matchRule(node, it.value(), styleSheet.origin, styleSheet.depth, &weightedRules); | - | ||||||||||||||||||
| 1985 | ++it; | - | ||||||||||||||||||
| 1986 | } never executed: end of block | 0 | ||||||||||||||||||
| 1987 | } never executed: end of block | 0 | ||||||||||||||||||
| 1988 | } never executed: end of block | 0 | ||||||||||||||||||
| 1989 | if (!styleSheet.nameIndex.isEmpty()) {
| 0 | ||||||||||||||||||
| 1990 | QStringList names = nodeNames(node); | - | ||||||||||||||||||
| 1991 | for (int i = 0; i < names.count(); i++) {
| 0 | ||||||||||||||||||
| 1992 | QString name = names.at(i); | - | ||||||||||||||||||
| 1993 | if (nameCaseSensitivity == Qt::CaseInsensitive)
| 0 | ||||||||||||||||||
| 1994 | name = name.toLower(); never executed: name = name.toLower(); | 0 | ||||||||||||||||||
| 1995 | QMultiHash<QString, StyleRule>::const_iterator it = styleSheet.nameIndex.constFind(name); | - | ||||||||||||||||||
| 1996 | while (it != styleSheet.nameIndex.constEnd() && it.key() == name) {
| 0 | ||||||||||||||||||
| 1997 | matchRule(node, it.value(), styleSheet.origin, styleSheet.depth, &weightedRules); | - | ||||||||||||||||||
| 1998 | ++it; | - | ||||||||||||||||||
| 1999 | } never executed: end of block | 0 | ||||||||||||||||||
| 2000 | } never executed: end of block | 0 | ||||||||||||||||||
| 2001 | } never executed: end of block | 0 | ||||||||||||||||||
| 2002 | if (!medium.isEmpty()) {
| 0 | ||||||||||||||||||
| 2003 | for (int i = 0; i < styleSheet.mediaRules.count(); ++i) {
| 0 | ||||||||||||||||||
| 2004 | if (styleSheet.mediaRules.at(i).media.contains(medium, Qt::CaseInsensitive)) {
| 0 | ||||||||||||||||||
| 2005 | for (int j = 0; j < styleSheet.mediaRules.at(i).styleRules.count(); ++j) {
| 0 | ||||||||||||||||||
| 2006 | matchRule(node, styleSheet.mediaRules.at(i).styleRules.at(j), styleSheet.origin, | - | ||||||||||||||||||
| 2007 | styleSheet.depth, &weightedRules); | - | ||||||||||||||||||
| 2008 | } never executed: end of block | 0 | ||||||||||||||||||
| 2009 | } never executed: end of block | 0 | ||||||||||||||||||
| 2010 | } never executed: end of block | 0 | ||||||||||||||||||
| 2011 | } never executed: end of block | 0 | ||||||||||||||||||
| 2012 | } never executed: end of block | 0 | ||||||||||||||||||
| 2013 | - | |||||||||||||||||||
| 2014 | rules.reserve(weightedRules.count()); | - | ||||||||||||||||||
| 2015 | QMap<uint, StyleRule>::const_iterator it = weightedRules.constBegin(); | - | ||||||||||||||||||
| 2016 | for ( ; it != weightedRules.constEnd() ; ++it)
| 0 | ||||||||||||||||||
| 2017 | rules += *it; never executed: rules += *it; | 0 | ||||||||||||||||||
| 2018 | - | |||||||||||||||||||
| 2019 | return rules; never executed: return rules; | 0 | ||||||||||||||||||
| 2020 | } | - | ||||||||||||||||||
| 2021 | - | |||||||||||||||||||
| 2022 | // for qtexthtmlparser which requires just the declarations with Enabled state | - | ||||||||||||||||||
| 2023 | // and without pseudo elements | - | ||||||||||||||||||
| 2024 | QVector<Declaration> StyleSelector::declarationsForNode(NodePtr node, const char *extraPseudo) | - | ||||||||||||||||||
| 2025 | { | - | ||||||||||||||||||
| 2026 | QVector<Declaration> decls; | - | ||||||||||||||||||
| 2027 | QVector<StyleRule> rules = styleRulesForNode(node); | - | ||||||||||||||||||
| 2028 | for (int i = 0; i < rules.count(); i++) {
| 0 | ||||||||||||||||||
| 2029 | const Selector& selector = rules.at(i).selectors.at(0); | - | ||||||||||||||||||
| 2030 | const QString pseudoElement = selector.pseudoElement(); | - | ||||||||||||||||||
| 2031 | - | |||||||||||||||||||
| 2032 | if (extraPseudo && pseudoElement == QLatin1String(extraPseudo)) {
| 0 | ||||||||||||||||||
| 2033 | decls += rules.at(i).declarations; | - | ||||||||||||||||||
| 2034 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 2035 | } | - | ||||||||||||||||||
| 2036 | - | |||||||||||||||||||
| 2037 | if (!pseudoElement.isEmpty()) // skip rules with pseudo elements
| 0 | ||||||||||||||||||
| 2038 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 2039 | quint64 pseudoClass = selector.pseudoClass(); | - | ||||||||||||||||||
| 2040 | if (pseudoClass == PseudoClass_Enabled || pseudoClass == PseudoClass_Unspecified)
| 0 | ||||||||||||||||||
| 2041 | decls += rules.at(i).declarations; never executed: decls += rules.at(i).declarations; | 0 | ||||||||||||||||||
| 2042 | } never executed: end of block | 0 | ||||||||||||||||||
| 2043 | return decls; never executed: return decls; | 0 | ||||||||||||||||||
| 2044 | } | - | ||||||||||||||||||
| 2045 | - | |||||||||||||||||||
| 2046 | static inline bool isHexDigit(const char c) | - | ||||||||||||||||||
| 2047 | { | - | ||||||||||||||||||
| 2048 | return (c >= '0' && c <= '9') never executed: return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ;
| 0 | ||||||||||||||||||
| 2049 | || (c >= 'a' && c <= 'f') never executed: return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ;
| 0 | ||||||||||||||||||
| 2050 | || (c >= 'A' && c <= 'F') never executed: return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ;
| 0 | ||||||||||||||||||
| 2051 | ; never executed: return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ; | 0 | ||||||||||||||||||
| 2052 | } | - | ||||||||||||||||||
| 2053 | - | |||||||||||||||||||
| 2054 | QString Scanner::preprocess(const QString &input, bool *hasEscapeSequences) | - | ||||||||||||||||||
| 2055 | { | - | ||||||||||||||||||
| 2056 | QString output = input; | - | ||||||||||||||||||
| 2057 | - | |||||||||||||||||||
| 2058 | if (hasEscapeSequences)
| 0 | ||||||||||||||||||
| 2059 | *hasEscapeSequences = false; never executed: *hasEscapeSequences = false; | 0 | ||||||||||||||||||
| 2060 | - | |||||||||||||||||||
| 2061 | int i = 0; | - | ||||||||||||||||||
| 2062 | while (i < output.size()) {
| 0 | ||||||||||||||||||
| 2063 | if (output.at(i) == QLatin1Char('\\')) {
| 0 | ||||||||||||||||||
| 2064 | - | |||||||||||||||||||
| 2065 | ++i; | - | ||||||||||||||||||
| 2066 | // test for unicode hex escape | - | ||||||||||||||||||
| 2067 | int hexCount = 0; | - | ||||||||||||||||||
| 2068 | const int hexStart = i; | - | ||||||||||||||||||
| 2069 | while (i < output.size()
| 0 | ||||||||||||||||||
| 2070 | && isHexDigit(output.at(i).toLatin1())
| 0 | ||||||||||||||||||
| 2071 | && hexCount < 7) {
| 0 | ||||||||||||||||||
| 2072 | ++hexCount; | - | ||||||||||||||||||
| 2073 | ++i; | - | ||||||||||||||||||
| 2074 | } never executed: end of block | 0 | ||||||||||||||||||
| 2075 | if (hexCount == 0) {
| 0 | ||||||||||||||||||
| 2076 | if (hasEscapeSequences)
| 0 | ||||||||||||||||||
| 2077 | *hasEscapeSequences = true; never executed: *hasEscapeSequences = true; | 0 | ||||||||||||||||||
| 2078 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 2079 | } | - | ||||||||||||||||||
| 2080 | - | |||||||||||||||||||
| 2081 | hexCount = qMin(hexCount, 6); | - | ||||||||||||||||||
| 2082 | bool ok = false; | - | ||||||||||||||||||
| 2083 | ushort code = output.mid(hexStart, hexCount).toUShort(&ok, 16); | - | ||||||||||||||||||
| 2084 | if (ok) {
| 0 | ||||||||||||||||||
| 2085 | output.replace(hexStart - 1, hexCount + 1, QChar(code)); | - | ||||||||||||||||||
| 2086 | i = hexStart; | - | ||||||||||||||||||
| 2087 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2088 | i = hexStart; | - | ||||||||||||||||||
| 2089 | } never executed: end of block | 0 | ||||||||||||||||||
| 2090 | } else { | - | ||||||||||||||||||
| 2091 | ++i; | - | ||||||||||||||||||
| 2092 | } never executed: end of block | 0 | ||||||||||||||||||
| 2093 | } | - | ||||||||||||||||||
| 2094 | return output; never executed: return output; | 0 | ||||||||||||||||||
| 2095 | } | - | ||||||||||||||||||
| 2096 | - | |||||||||||||||||||
| 2097 | int QCssScanner_Generated::handleCommentStart() | - | ||||||||||||||||||
| 2098 | { | - | ||||||||||||||||||
| 2099 | while (pos < input.size() - 1) {
| 0 | ||||||||||||||||||
| 2100 | if (input.at(pos) == QLatin1Char('*')
| 0 | ||||||||||||||||||
| 2101 | && input.at(pos + 1) == QLatin1Char('/')) {
| 0 | ||||||||||||||||||
| 2102 | pos += 2; | - | ||||||||||||||||||
| 2103 | break; never executed: break; | 0 | ||||||||||||||||||
| 2104 | } | - | ||||||||||||||||||
| 2105 | ++pos; | - | ||||||||||||||||||
| 2106 | } never executed: end of block | 0 | ||||||||||||||||||
| 2107 | return S; never executed: return S; | 0 | ||||||||||||||||||
| 2108 | } | - | ||||||||||||||||||
| 2109 | - | |||||||||||||||||||
| 2110 | void Scanner::scan(const QString &preprocessedInput, QVector<Symbol> *symbols) | - | ||||||||||||||||||
| 2111 | { | - | ||||||||||||||||||
| 2112 | QCssScanner_Generated scanner(preprocessedInput); | - | ||||||||||||||||||
| 2113 | Symbol sym; | - | ||||||||||||||||||
| 2114 | int tok = scanner.lex(); | - | ||||||||||||||||||
| 2115 | while (tok != -1) {
| 0 | ||||||||||||||||||
| 2116 | sym.token = static_cast<QCss::TokenType>(tok); | - | ||||||||||||||||||
| 2117 | sym.text = scanner.input; | - | ||||||||||||||||||
| 2118 | sym.start = scanner.lexemStart; | - | ||||||||||||||||||
| 2119 | sym.len = scanner.lexemLength; | - | ||||||||||||||||||
| 2120 | symbols->append(sym); | - | ||||||||||||||||||
| 2121 | tok = scanner.lex(); | - | ||||||||||||||||||
| 2122 | } never executed: end of block | 0 | ||||||||||||||||||
| 2123 | } never executed: end of block | 0 | ||||||||||||||||||
| 2124 | - | |||||||||||||||||||
| 2125 | QString Symbol::lexem() const | - | ||||||||||||||||||
| 2126 | { | - | ||||||||||||||||||
| 2127 | QString result; | - | ||||||||||||||||||
| 2128 | if (len > 0)
| 0 | ||||||||||||||||||
| 2129 | result.reserve(len); never executed: result.reserve(len); | 0 | ||||||||||||||||||
| 2130 | for (int i = 0; i < len; ++i) {
| 0 | ||||||||||||||||||
| 2131 | if (text.at(start + i) == QLatin1Char('\\') && i < len - 1)
| 0 | ||||||||||||||||||
| 2132 | ++i; never executed: ++i; | 0 | ||||||||||||||||||
| 2133 | result += text.at(start + i); | - | ||||||||||||||||||
| 2134 | } never executed: end of block | 0 | ||||||||||||||||||
| 2135 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 2136 | } | - | ||||||||||||||||||
| 2137 | - | |||||||||||||||||||
| 2138 | Parser::Parser(const QString &css, bool isFile) | - | ||||||||||||||||||
| 2139 | { | - | ||||||||||||||||||
| 2140 | init(css, isFile); | - | ||||||||||||||||||
| 2141 | } never executed: end of block | 0 | ||||||||||||||||||
| 2142 | - | |||||||||||||||||||
| 2143 | Parser::Parser() | - | ||||||||||||||||||
| 2144 | { | - | ||||||||||||||||||
| 2145 | index = 0; | - | ||||||||||||||||||
| 2146 | errorIndex = -1; | - | ||||||||||||||||||
| 2147 | hasEscapeSequences = false; | - | ||||||||||||||||||
| 2148 | } never executed: end of block | 0 | ||||||||||||||||||
| 2149 | - | |||||||||||||||||||
| 2150 | void Parser::init(const QString &css, bool isFile) | - | ||||||||||||||||||
| 2151 | { | - | ||||||||||||||||||
| 2152 | QString styleSheet = css; | - | ||||||||||||||||||
| 2153 | if (isFile) {
| 0 | ||||||||||||||||||
| 2154 | QFile file(css); | - | ||||||||||||||||||
| 2155 | if (file.open(QFile::ReadOnly)) {
| 0 | ||||||||||||||||||
| 2156 | sourcePath = QFileInfo(styleSheet).absolutePath() + QLatin1Char('/'); | - | ||||||||||||||||||
| 2157 | QTextStream stream(&file); | - | ||||||||||||||||||
| 2158 | styleSheet = stream.readAll(); | - | ||||||||||||||||||
| 2159 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2160 | qWarning() << "QCss::Parser - Failed to load file " << css; | - | ||||||||||||||||||
| 2161 | styleSheet.clear(); | - | ||||||||||||||||||
| 2162 | } never executed: end of block | 0 | ||||||||||||||||||
| 2163 | } else { | - | ||||||||||||||||||
| 2164 | sourcePath.clear(); | - | ||||||||||||||||||
| 2165 | } never executed: end of block | 0 | ||||||||||||||||||
| 2166 | - | |||||||||||||||||||
| 2167 | hasEscapeSequences = false; | - | ||||||||||||||||||
| 2168 | symbols.resize(0); | - | ||||||||||||||||||
| 2169 | symbols.reserve(8); | - | ||||||||||||||||||
| 2170 | Scanner::scan(Scanner::preprocess(styleSheet, &hasEscapeSequences), &symbols); | - | ||||||||||||||||||
| 2171 | index = 0; | - | ||||||||||||||||||
| 2172 | errorIndex = -1; | - | ||||||||||||||||||
| 2173 | } never executed: end of block | 0 | ||||||||||||||||||
| 2174 | - | |||||||||||||||||||
| 2175 | bool Parser::parse(StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity) | - | ||||||||||||||||||
| 2176 | { | - | ||||||||||||||||||
| 2177 | if (testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1String("charset"))) {
| 0 | ||||||||||||||||||
| 2178 | while (test(S) || test(CDO) || test(CDC)) {} never executed: end of block
| 0 | ||||||||||||||||||
| 2179 | if (!next(STRING)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2180 | if (!next(SEMICOLON)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2181 | } never executed: end of block | 0 | ||||||||||||||||||
| 2182 | - | |||||||||||||||||||
| 2183 | while (test(S) || test(CDO) || test(CDC)) {} never executed: end of block
| 0 | ||||||||||||||||||
| 2184 | - | |||||||||||||||||||
| 2185 | while (testImport()) {
| 0 | ||||||||||||||||||
| 2186 | ImportRule rule; | - | ||||||||||||||||||
| 2187 | if (!parseImport(&rule)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2188 | styleSheet->importRules.append(rule); | - | ||||||||||||||||||
| 2189 | while (test(S) || test(CDO) || test(CDC)) {} never executed: end of block
| 0 | ||||||||||||||||||
| 2190 | } never executed: end of block | 0 | ||||||||||||||||||
| 2191 | - | |||||||||||||||||||
| 2192 | do { | - | ||||||||||||||||||
| 2193 | if (testMedia()) {
| 0 | ||||||||||||||||||
| 2194 | MediaRule rule; | - | ||||||||||||||||||
| 2195 | if (!parseMedia(&rule)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2196 | styleSheet->mediaRules.append(rule); | - | ||||||||||||||||||
| 2197 | } else if (testPage()) { never executed: end of block
| 0 | ||||||||||||||||||
| 2198 | PageRule rule; | - | ||||||||||||||||||
| 2199 | if (!parsePage(&rule)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2200 | styleSheet->pageRules.append(rule); | - | ||||||||||||||||||
| 2201 | } else if (testRuleset()) { never executed: end of block
| 0 | ||||||||||||||||||
| 2202 | StyleRule rule; | - | ||||||||||||||||||
| 2203 | if (!parseRuleset(&rule)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2204 | styleSheet->styleRules.append(rule); | - | ||||||||||||||||||
| 2205 | } else if (test(ATKEYWORD_SYM)) { never executed: end of block
| 0 | ||||||||||||||||||
| 2206 | if (!until(RBRACE)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2207 | } else if (hasNext()) { never executed: end of block
| 0 | ||||||||||||||||||
| 2208 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2209 | } | - | ||||||||||||||||||
| 2210 | while (test(S) || test(CDO) || test(CDC)) {} never executed: end of block
| 0 | ||||||||||||||||||
| 2211 | } while (hasNext()); never executed: end of block
| 0 | ||||||||||||||||||
| 2212 | styleSheet->buildIndexes(nameCaseSensitivity); | - | ||||||||||||||||||
| 2213 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2214 | } | - | ||||||||||||||||||
| 2215 | - | |||||||||||||||||||
| 2216 | Symbol Parser::errorSymbol() | - | ||||||||||||||||||
| 2217 | { | - | ||||||||||||||||||
| 2218 | if (errorIndex == -1) return Symbol(); never executed: return Symbol();
| 0 | ||||||||||||||||||
| 2219 | return symbols.at(errorIndex); never executed: return symbols.at(errorIndex); | 0 | ||||||||||||||||||
| 2220 | } | - | ||||||||||||||||||
| 2221 | - | |||||||||||||||||||
| 2222 | static inline void removeOptionalQuotes(QString *str) | - | ||||||||||||||||||
| 2223 | { | - | ||||||||||||||||||
| 2224 | if (!str->startsWith(QLatin1Char('\''))
| 0 | ||||||||||||||||||
| 2225 | && !str->startsWith(QLatin1Char('\"')))
| 0 | ||||||||||||||||||
| 2226 | return; never executed: return; | 0 | ||||||||||||||||||
| 2227 | str->remove(0, 1); | - | ||||||||||||||||||
| 2228 | str->chop(1); | - | ||||||||||||||||||
| 2229 | } never executed: end of block | 0 | ||||||||||||||||||
| 2230 | - | |||||||||||||||||||
| 2231 | bool Parser::parseImport(ImportRule *importRule) | - | ||||||||||||||||||
| 2232 | { | - | ||||||||||||||||||
| 2233 | skipSpace(); | - | ||||||||||||||||||
| 2234 | - | |||||||||||||||||||
| 2235 | if (test(STRING)) {
| 0 | ||||||||||||||||||
| 2236 | importRule->href = lexem(); | - | ||||||||||||||||||
| 2237 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2238 | if (!testAndParseUri(&importRule->href)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2239 | } never executed: end of block | 0 | ||||||||||||||||||
| 2240 | removeOptionalQuotes(&importRule->href); | - | ||||||||||||||||||
| 2241 | - | |||||||||||||||||||
| 2242 | skipSpace(); | - | ||||||||||||||||||
| 2243 | - | |||||||||||||||||||
| 2244 | if (testMedium()) {
| 0 | ||||||||||||||||||
| 2245 | if (!parseMedium(&importRule->media)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2246 | - | |||||||||||||||||||
| 2247 | while (test(COMMA)) {
| 0 | ||||||||||||||||||
| 2248 | skipSpace(); | - | ||||||||||||||||||
| 2249 | if (!parseNextMedium(&importRule->media)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2250 | } never executed: end of block | 0 | ||||||||||||||||||
| 2251 | } never executed: end of block | 0 | ||||||||||||||||||
| 2252 | - | |||||||||||||||||||
| 2253 | if (!next(SEMICOLON)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2254 | - | |||||||||||||||||||
| 2255 | skipSpace(); | - | ||||||||||||||||||
| 2256 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2257 | } | - | ||||||||||||||||||
| 2258 | - | |||||||||||||||||||
| 2259 | bool Parser::parseMedia(MediaRule *mediaRule) | - | ||||||||||||||||||
| 2260 | { | - | ||||||||||||||||||
| 2261 | do { | - | ||||||||||||||||||
| 2262 | skipSpace(); | - | ||||||||||||||||||
| 2263 | if (!parseNextMedium(&mediaRule->media)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2264 | } while (test(COMMA)); never executed: end of block
| 0 | ||||||||||||||||||
| 2265 | - | |||||||||||||||||||
| 2266 | if (!next(LBRACE)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2267 | skipSpace(); | - | ||||||||||||||||||
| 2268 | - | |||||||||||||||||||
| 2269 | while (testRuleset()) {
| 0 | ||||||||||||||||||
| 2270 | StyleRule rule; | - | ||||||||||||||||||
| 2271 | if (!parseRuleset(&rule)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2272 | mediaRule->styleRules.append(rule); | - | ||||||||||||||||||
| 2273 | } never executed: end of block | 0 | ||||||||||||||||||
| 2274 | - | |||||||||||||||||||
| 2275 | if (!next(RBRACE)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2276 | skipSpace(); | - | ||||||||||||||||||
| 2277 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2278 | } | - | ||||||||||||||||||
| 2279 | - | |||||||||||||||||||
| 2280 | bool Parser::parseMedium(QStringList *media) | - | ||||||||||||||||||
| 2281 | { | - | ||||||||||||||||||
| 2282 | media->append(lexem()); | - | ||||||||||||||||||
| 2283 | skipSpace(); | - | ||||||||||||||||||
| 2284 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2285 | } | - | ||||||||||||||||||
| 2286 | - | |||||||||||||||||||
| 2287 | bool Parser::parsePage(PageRule *pageRule) | - | ||||||||||||||||||
| 2288 | { | - | ||||||||||||||||||
| 2289 | skipSpace(); | - | ||||||||||||||||||
| 2290 | - | |||||||||||||||||||
| 2291 | if (testPseudoPage())
| 0 | ||||||||||||||||||
| 2292 | if (!parsePseudoPage(&pageRule->selector)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2293 | - | |||||||||||||||||||
| 2294 | skipSpace(); | - | ||||||||||||||||||
| 2295 | if (!next(LBRACE)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2296 | - | |||||||||||||||||||
| 2297 | do { | - | ||||||||||||||||||
| 2298 | skipSpace(); | - | ||||||||||||||||||
| 2299 | Declaration decl; | - | ||||||||||||||||||
| 2300 | if (!parseNextDeclaration(&decl)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2301 | if (!decl.isEmpty())
| 0 | ||||||||||||||||||
| 2302 | pageRule->declarations.append(decl); never executed: pageRule->declarations.append(decl); | 0 | ||||||||||||||||||
| 2303 | } while (test(SEMICOLON)); never executed: end of block
| 0 | ||||||||||||||||||
| 2304 | - | |||||||||||||||||||
| 2305 | if (!next(RBRACE)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2306 | skipSpace(); | - | ||||||||||||||||||
| 2307 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2308 | } | - | ||||||||||||||||||
| 2309 | - | |||||||||||||||||||
| 2310 | bool Parser::parsePseudoPage(QString *selector) | - | ||||||||||||||||||
| 2311 | { | - | ||||||||||||||||||
| 2312 | if (!next(IDENT)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2313 | *selector = lexem(); | - | ||||||||||||||||||
| 2314 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2315 | } | - | ||||||||||||||||||
| 2316 | - | |||||||||||||||||||
| 2317 | bool Parser::parseNextOperator(Value *value) | - | ||||||||||||||||||
| 2318 | { | - | ||||||||||||||||||
| 2319 | if (!hasNext()) return true; never executed: return true;
| 0 | ||||||||||||||||||
| 2320 | switch (next()) { | - | ||||||||||||||||||
| 2321 | case SLASH: value->type = Value::TermOperatorSlash; skipSpace(); break; never executed: break;never executed: case SLASH: | 0 | ||||||||||||||||||
| 2322 | case COMMA: value->type = Value::TermOperatorComma; skipSpace(); break; never executed: break;never executed: case COMMA: | 0 | ||||||||||||||||||
| 2323 | default: prev(); break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 2324 | } | - | ||||||||||||||||||
| 2325 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2326 | } | - | ||||||||||||||||||
| 2327 | - | |||||||||||||||||||
| 2328 | bool Parser::parseCombinator(BasicSelector::Relation *relation) | - | ||||||||||||||||||
| 2329 | { | - | ||||||||||||||||||
| 2330 | *relation = BasicSelector::NoRelation; | - | ||||||||||||||||||
| 2331 | if (lookup() == S) {
| 0 | ||||||||||||||||||
| 2332 | *relation = BasicSelector::MatchNextSelectorIfAncestor; | - | ||||||||||||||||||
| 2333 | skipSpace(); | - | ||||||||||||||||||
| 2334 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2335 | prev(); | - | ||||||||||||||||||
| 2336 | } never executed: end of block | 0 | ||||||||||||||||||
| 2337 | if (test(PLUS)) {
| 0 | ||||||||||||||||||
| 2338 | *relation = BasicSelector::MatchNextSelectorIfPreceeds; | - | ||||||||||||||||||
| 2339 | } else if (test(GREATER)) { never executed: end of block
| 0 | ||||||||||||||||||
| 2340 | *relation = BasicSelector::MatchNextSelectorIfParent; | - | ||||||||||||||||||
| 2341 | } never executed: end of block | 0 | ||||||||||||||||||
| 2342 | skipSpace(); | - | ||||||||||||||||||
| 2343 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2344 | } | - | ||||||||||||||||||
| 2345 | - | |||||||||||||||||||
| 2346 | bool Parser::parseProperty(Declaration *decl) | - | ||||||||||||||||||
| 2347 | { | - | ||||||||||||||||||
| 2348 | decl->d->property = lexem(); | - | ||||||||||||||||||
| 2349 | decl->d->propertyId = static_cast<Property>(findKnownValue(decl->d->property, properties, NumProperties)); | - | ||||||||||||||||||
| 2350 | decl->d->inheritable = isInheritable(decl->d->propertyId); | - | ||||||||||||||||||
| 2351 | skipSpace(); | - | ||||||||||||||||||
| 2352 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2353 | } | - | ||||||||||||||||||
| 2354 | - | |||||||||||||||||||
| 2355 | bool Parser::parseRuleset(StyleRule *styleRule) | - | ||||||||||||||||||
| 2356 | { | - | ||||||||||||||||||
| 2357 | Selector sel; | - | ||||||||||||||||||
| 2358 | if (!parseSelector(&sel)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2359 | styleRule->selectors.append(sel); | - | ||||||||||||||||||
| 2360 | - | |||||||||||||||||||
| 2361 | while (test(COMMA)) {
| 0 | ||||||||||||||||||
| 2362 | skipSpace(); | - | ||||||||||||||||||
| 2363 | Selector sel; | - | ||||||||||||||||||
| 2364 | if (!parseNextSelector(&sel)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2365 | styleRule->selectors.append(sel); | - | ||||||||||||||||||
| 2366 | } never executed: end of block | 0 | ||||||||||||||||||
| 2367 | - | |||||||||||||||||||
| 2368 | skipSpace(); | - | ||||||||||||||||||
| 2369 | if (!next(LBRACE)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2370 | const int declarationStart = index; | - | ||||||||||||||||||
| 2371 | - | |||||||||||||||||||
| 2372 | do { | - | ||||||||||||||||||
| 2373 | skipSpace(); | - | ||||||||||||||||||
| 2374 | Declaration decl; | - | ||||||||||||||||||
| 2375 | const int rewind = index; | - | ||||||||||||||||||
| 2376 | if (!parseNextDeclaration(&decl)) {
| 0 | ||||||||||||||||||
| 2377 | index = rewind; | - | ||||||||||||||||||
| 2378 | const bool foundSemicolon = until(SEMICOLON); | - | ||||||||||||||||||
| 2379 | const int semicolonIndex = index; | - | ||||||||||||||||||
| 2380 | - | |||||||||||||||||||
| 2381 | index = declarationStart; | - | ||||||||||||||||||
| 2382 | const bool foundRBrace = until(RBRACE); | - | ||||||||||||||||||
| 2383 | - | |||||||||||||||||||
| 2384 | if (foundSemicolon && semicolonIndex < index) {
| 0 | ||||||||||||||||||
| 2385 | decl = Declaration(); | - | ||||||||||||||||||
| 2386 | index = semicolonIndex - 1; | - | ||||||||||||||||||
| 2387 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2388 | skipSpace(); | - | ||||||||||||||||||
| 2389 | return foundRBrace; never executed: return foundRBrace; | 0 | ||||||||||||||||||
| 2390 | } | - | ||||||||||||||||||
| 2391 | } | - | ||||||||||||||||||
| 2392 | if (!decl.isEmpty())
| 0 | ||||||||||||||||||
| 2393 | styleRule->declarations.append(decl); never executed: styleRule->declarations.append(decl); | 0 | ||||||||||||||||||
| 2394 | } while (test(SEMICOLON)); never executed: end of block
| 0 | ||||||||||||||||||
| 2395 | - | |||||||||||||||||||
| 2396 | if (!next(RBRACE)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2397 | skipSpace(); | - | ||||||||||||||||||
| 2398 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2399 | } | - | ||||||||||||||||||
| 2400 | - | |||||||||||||||||||
| 2401 | bool Parser::parseSelector(Selector *sel) | - | ||||||||||||||||||
| 2402 | { | - | ||||||||||||||||||
| 2403 | BasicSelector basicSel; | - | ||||||||||||||||||
| 2404 | if (!parseSimpleSelector(&basicSel)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2405 | while (testCombinator()) {
| 0 | ||||||||||||||||||
| 2406 | if (!parseCombinator(&basicSel.relationToNext)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2407 | - | |||||||||||||||||||
| 2408 | if (!testSimpleSelector()) break; never executed: break;
| 0 | ||||||||||||||||||
| 2409 | sel->basicSelectors.append(basicSel); | - | ||||||||||||||||||
| 2410 | - | |||||||||||||||||||
| 2411 | basicSel = BasicSelector(); | - | ||||||||||||||||||
| 2412 | if (!parseSimpleSelector(&basicSel)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2413 | } never executed: end of block | 0 | ||||||||||||||||||
| 2414 | sel->basicSelectors.append(basicSel); | - | ||||||||||||||||||
| 2415 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2416 | } | - | ||||||||||||||||||
| 2417 | - | |||||||||||||||||||
| 2418 | bool Parser::parseSimpleSelector(BasicSelector *basicSel) | - | ||||||||||||||||||
| 2419 | { | - | ||||||||||||||||||
| 2420 | int minCount = 0; | - | ||||||||||||||||||
| 2421 | if (lookupElementName()) {
| 0 | ||||||||||||||||||
| 2422 | if (!parseElementName(&basicSel->elementName)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2423 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2424 | prev(); | - | ||||||||||||||||||
| 2425 | minCount = 1; | - | ||||||||||||||||||
| 2426 | } never executed: end of block | 0 | ||||||||||||||||||
| 2427 | bool onceMore; | - | ||||||||||||||||||
| 2428 | int count = 0; | - | ||||||||||||||||||
| 2429 | do { | - | ||||||||||||||||||
| 2430 | onceMore = false; | - | ||||||||||||||||||
| 2431 | if (test(HASH)) {
| 0 | ||||||||||||||||||
| 2432 | QString theid = lexem(); | - | ||||||||||||||||||
| 2433 | // chop off leading # | - | ||||||||||||||||||
| 2434 | theid.remove(0, 1); | - | ||||||||||||||||||
| 2435 | basicSel->ids.append(theid); | - | ||||||||||||||||||
| 2436 | onceMore = true; | - | ||||||||||||||||||
| 2437 | } else if (testClass()) { never executed: end of block
| 0 | ||||||||||||||||||
| 2438 | onceMore = true; | - | ||||||||||||||||||
| 2439 | AttributeSelector a; | - | ||||||||||||||||||
| 2440 | a.name = QLatin1String("class"); | - | ||||||||||||||||||
| 2441 | a.valueMatchCriterium = AttributeSelector::MatchContains; | - | ||||||||||||||||||
| 2442 | if (!parseClass(&a.value)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2443 | basicSel->attributeSelectors.append(a); | - | ||||||||||||||||||
| 2444 | } else if (testAttrib()) { never executed: end of block
| 0 | ||||||||||||||||||
| 2445 | onceMore = true; | - | ||||||||||||||||||
| 2446 | AttributeSelector a; | - | ||||||||||||||||||
| 2447 | if (!parseAttrib(&a)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2448 | basicSel->attributeSelectors.append(a); | - | ||||||||||||||||||
| 2449 | } else if (testPseudo()) { never executed: end of block
| 0 | ||||||||||||||||||
| 2450 | onceMore = true; | - | ||||||||||||||||||
| 2451 | Pseudo ps; | - | ||||||||||||||||||
| 2452 | if (!parsePseudo(&ps)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2453 | basicSel->pseudos.append(ps); | - | ||||||||||||||||||
| 2454 | } never executed: end of block | 0 | ||||||||||||||||||
| 2455 | if (onceMore) ++count; never executed: ++count;
| 0 | ||||||||||||||||||
| 2456 | } while (onceMore); never executed: end of block
| 0 | ||||||||||||||||||
| 2457 | return count >= minCount; never executed: return count >= minCount; | 0 | ||||||||||||||||||
| 2458 | } | - | ||||||||||||||||||
| 2459 | - | |||||||||||||||||||
| 2460 | bool Parser::parseClass(QString *name) | - | ||||||||||||||||||
| 2461 | { | - | ||||||||||||||||||
| 2462 | if (!next(IDENT)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2463 | *name = lexem(); | - | ||||||||||||||||||
| 2464 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2465 | } | - | ||||||||||||||||||
| 2466 | - | |||||||||||||||||||
| 2467 | bool Parser::parseElementName(QString *name) | - | ||||||||||||||||||
| 2468 | { | - | ||||||||||||||||||
| 2469 | switch (lookup()) { | - | ||||||||||||||||||
| 2470 | case STAR: name->clear(); break; never executed: break;never executed: case STAR: | 0 | ||||||||||||||||||
| 2471 | case IDENT: *name = lexem(); break; never executed: break;never executed: case IDENT: | 0 | ||||||||||||||||||
| 2472 | default: return false; never executed: return false;never executed: default: | 0 | ||||||||||||||||||
| 2473 | } | - | ||||||||||||||||||
| 2474 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2475 | } | - | ||||||||||||||||||
| 2476 | - | |||||||||||||||||||
| 2477 | bool Parser::parseAttrib(AttributeSelector *attr) | - | ||||||||||||||||||
| 2478 | { | - | ||||||||||||||||||
| 2479 | skipSpace(); | - | ||||||||||||||||||
| 2480 | if (!next(IDENT)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2481 | attr->name = lexem(); | - | ||||||||||||||||||
| 2482 | skipSpace(); | - | ||||||||||||||||||
| 2483 | - | |||||||||||||||||||
| 2484 | if (test(EQUAL)) {
| 0 | ||||||||||||||||||
| 2485 | attr->valueMatchCriterium = AttributeSelector::MatchEqual; | - | ||||||||||||||||||
| 2486 | } else if (test(INCLUDES)) { never executed: end of block
| 0 | ||||||||||||||||||
| 2487 | attr->valueMatchCriterium = AttributeSelector::MatchContains; | - | ||||||||||||||||||
| 2488 | } else if (test(DASHMATCH)) { never executed: end of block
| 0 | ||||||||||||||||||
| 2489 | attr->valueMatchCriterium = AttributeSelector::MatchBeginsWith; | - | ||||||||||||||||||
| 2490 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2491 | return next(RBRACKET); never executed: return next(RBRACKET); | 0 | ||||||||||||||||||
| 2492 | } | - | ||||||||||||||||||
| 2493 | - | |||||||||||||||||||
| 2494 | skipSpace(); | - | ||||||||||||||||||
| 2495 | - | |||||||||||||||||||
| 2496 | if (!test(IDENT) && !test(STRING)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2497 | attr->value = unquotedLexem(); | - | ||||||||||||||||||
| 2498 | - | |||||||||||||||||||
| 2499 | skipSpace(); | - | ||||||||||||||||||
| 2500 | return next(RBRACKET); never executed: return next(RBRACKET); | 0 | ||||||||||||||||||
| 2501 | } | - | ||||||||||||||||||
| 2502 | - | |||||||||||||||||||
| 2503 | bool Parser::parsePseudo(Pseudo *pseudo) | - | ||||||||||||||||||
| 2504 | { | - | ||||||||||||||||||
| 2505 | (void)test(COLON); | - | ||||||||||||||||||
| 2506 | pseudo->negated = test(EXCLAMATION_SYM); | - | ||||||||||||||||||
| 2507 | if (test(IDENT)) {
| 0 | ||||||||||||||||||
| 2508 | pseudo->name = lexem(); | - | ||||||||||||||||||
| 2509 | pseudo->type = static_cast<quint64>(findKnownValue(pseudo->name, pseudos, NumPseudos)); | - | ||||||||||||||||||
| 2510 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2511 | } | - | ||||||||||||||||||
| 2512 | if (!next(FUNCTION)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2513 | pseudo->function = lexem(); | - | ||||||||||||||||||
| 2514 | // chop off trailing parenthesis | - | ||||||||||||||||||
| 2515 | pseudo->function.chop(1); | - | ||||||||||||||||||
| 2516 | skipSpace(); | - | ||||||||||||||||||
| 2517 | if (!test(IDENT)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2518 | pseudo->name = lexem(); | - | ||||||||||||||||||
| 2519 | skipSpace(); | - | ||||||||||||||||||
| 2520 | return next(RPAREN); never executed: return next(RPAREN); | 0 | ||||||||||||||||||
| 2521 | } | - | ||||||||||||||||||
| 2522 | - | |||||||||||||||||||
| 2523 | bool Parser::parseNextDeclaration(Declaration *decl) | - | ||||||||||||||||||
| 2524 | { | - | ||||||||||||||||||
| 2525 | if (!testProperty())
| 0 | ||||||||||||||||||
| 2526 | return true; // not an error! never executed: return true; | 0 | ||||||||||||||||||
| 2527 | if (!parseProperty(decl)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2528 | if (!next(COLON)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2529 | skipSpace(); | - | ||||||||||||||||||
| 2530 | if (!parseNextExpr(&decl->d->values)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2531 | if (testPrio())
| 0 | ||||||||||||||||||
| 2532 | if (!parsePrio(decl)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2533 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2534 | } | - | ||||||||||||||||||
| 2535 | - | |||||||||||||||||||
| 2536 | bool Parser::testPrio() | - | ||||||||||||||||||
| 2537 | { | - | ||||||||||||||||||
| 2538 | const int rewind = index; | - | ||||||||||||||||||
| 2539 | if (!test(EXCLAMATION_SYM)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2540 | skipSpace(); | - | ||||||||||||||||||
| 2541 | if (!test(IDENT)) {
| 0 | ||||||||||||||||||
| 2542 | index = rewind; | - | ||||||||||||||||||
| 2543 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2544 | } | - | ||||||||||||||||||
| 2545 | if (lexem().compare(QLatin1String("important"), Qt::CaseInsensitive) != 0) {
| 0 | ||||||||||||||||||
| 2546 | index = rewind; | - | ||||||||||||||||||
| 2547 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2548 | } | - | ||||||||||||||||||
| 2549 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2550 | } | - | ||||||||||||||||||
| 2551 | - | |||||||||||||||||||
| 2552 | bool Parser::parsePrio(Declaration *declaration) | - | ||||||||||||||||||
| 2553 | { | - | ||||||||||||||||||
| 2554 | declaration->d->important = true; | - | ||||||||||||||||||
| 2555 | skipSpace(); | - | ||||||||||||||||||
| 2556 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2557 | } | - | ||||||||||||||||||
| 2558 | - | |||||||||||||||||||
| 2559 | bool Parser::parseExpr(QVector<Value> *values) | - | ||||||||||||||||||
| 2560 | { | - | ||||||||||||||||||
| 2561 | Value val; | - | ||||||||||||||||||
| 2562 | if (!parseTerm(&val)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2563 | values->append(val); | - | ||||||||||||||||||
| 2564 | bool onceMore; | - | ||||||||||||||||||
| 2565 | do { | - | ||||||||||||||||||
| 2566 | onceMore = false; | - | ||||||||||||||||||
| 2567 | val = Value(); | - | ||||||||||||||||||
| 2568 | if (!parseNextOperator(&val)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2569 | if (val.type != QCss::Value::Unknown)
| 0 | ||||||||||||||||||
| 2570 | values->append(val); never executed: values->append(val); | 0 | ||||||||||||||||||
| 2571 | if (testTerm()) {
| 0 | ||||||||||||||||||
| 2572 | onceMore = true; | - | ||||||||||||||||||
| 2573 | val = Value(); | - | ||||||||||||||||||
| 2574 | if (!parseTerm(&val)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2575 | values->append(val); | - | ||||||||||||||||||
| 2576 | } never executed: end of block | 0 | ||||||||||||||||||
| 2577 | } while (onceMore); never executed: end of block
| 0 | ||||||||||||||||||
| 2578 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2579 | } | - | ||||||||||||||||||
| 2580 | - | |||||||||||||||||||
| 2581 | bool Parser::testTerm() | - | ||||||||||||||||||
| 2582 | { | - | ||||||||||||||||||
| 2583 | return test(PLUS) || test(MINUS) never executed: return test(PLUS) || test(MINUS) || test(NUMBER) || test(PERCENTAGE) || test(LENGTH) || test(STRING) || test(IDENT) || testHexColor() || testFunction();
| 0 | ||||||||||||||||||
| 2584 | || test(NUMBER) never executed: return test(PLUS) || test(MINUS) || test(NUMBER) || test(PERCENTAGE) || test(LENGTH) || test(STRING) || test(IDENT) || testHexColor() || testFunction();
| 0 | ||||||||||||||||||
| 2585 | || test(PERCENTAGE) never executed: return test(PLUS) || test(MINUS) || test(NUMBER) || test(PERCENTAGE) || test(LENGTH) || test(STRING) || test(IDENT) || testHexColor() || testFunction();
| 0 | ||||||||||||||||||
| 2586 | || test(LENGTH) never executed: return test(PLUS) || test(MINUS) || test(NUMBER) || test(PERCENTAGE) || test(LENGTH) || test(STRING) || test(IDENT) || testHexColor() || testFunction();
| 0 | ||||||||||||||||||
| 2587 | || test(STRING) never executed: return test(PLUS) || test(MINUS) || test(NUMBER) || test(PERCENTAGE) || test(LENGTH) || test(STRING) || test(IDENT) || testHexColor() || testFunction();
| 0 | ||||||||||||||||||
| 2588 | || test(IDENT) never executed: return test(PLUS) || test(MINUS) || test(NUMBER) || test(PERCENTAGE) || test(LENGTH) || test(STRING) || test(IDENT) || testHexColor() || testFunction();
| 0 | ||||||||||||||||||
| 2589 | || testHexColor() never executed: return test(PLUS) || test(MINUS) || test(NUMBER) || test(PERCENTAGE) || test(LENGTH) || test(STRING) || test(IDENT) || testHexColor() || testFunction();
| 0 | ||||||||||||||||||
| 2590 | || testFunction(); never executed: return test(PLUS) || test(MINUS) || test(NUMBER) || test(PERCENTAGE) || test(LENGTH) || test(STRING) || test(IDENT) || testHexColor() || testFunction();
| 0 | ||||||||||||||||||
| 2591 | } | - | ||||||||||||||||||
| 2592 | - | |||||||||||||||||||
| 2593 | bool Parser::parseTerm(Value *value) | - | ||||||||||||||||||
| 2594 | { | - | ||||||||||||||||||
| 2595 | QString str = lexem(); | - | ||||||||||||||||||
| 2596 | bool haveUnary = false; | - | ||||||||||||||||||
| 2597 | if (lookup() == PLUS || lookup() == MINUS) {
| 0 | ||||||||||||||||||
| 2598 | haveUnary = true; | - | ||||||||||||||||||
| 2599 | if (!hasNext()) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2600 | next(); | - | ||||||||||||||||||
| 2601 | str += lexem(); | - | ||||||||||||||||||
| 2602 | } never executed: end of block | 0 | ||||||||||||||||||
| 2603 | - | |||||||||||||||||||
| 2604 | value->variant = str; | - | ||||||||||||||||||
| 2605 | value->type = QCss::Value::String; | - | ||||||||||||||||||
| 2606 | switch (lookup()) { | - | ||||||||||||||||||
| 2607 | case NUMBER: never executed: case NUMBER: | 0 | ||||||||||||||||||
| 2608 | value->type = Value::Number; | - | ||||||||||||||||||
| 2609 | value->variant.convert(QVariant::Double); | - | ||||||||||||||||||
| 2610 | break; never executed: break; | 0 | ||||||||||||||||||
| 2611 | case PERCENTAGE: never executed: case PERCENTAGE: | 0 | ||||||||||||||||||
| 2612 | value->type = Value::Percentage; | - | ||||||||||||||||||
| 2613 | str.chop(1); // strip off % | - | ||||||||||||||||||
| 2614 | value->variant = str; | - | ||||||||||||||||||
| 2615 | break; never executed: break; | 0 | ||||||||||||||||||
| 2616 | case LENGTH: never executed: case LENGTH: | 0 | ||||||||||||||||||
| 2617 | value->type = Value::Length; | - | ||||||||||||||||||
| 2618 | break; never executed: break; | 0 | ||||||||||||||||||
| 2619 | - | |||||||||||||||||||
| 2620 | case STRING: never executed: case STRING: | 0 | ||||||||||||||||||
| 2621 | if (haveUnary) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2622 | value->type = Value::String; | - | ||||||||||||||||||
| 2623 | str.chop(1); | - | ||||||||||||||||||
| 2624 | str.remove(0, 1); | - | ||||||||||||||||||
| 2625 | value->variant = str; | - | ||||||||||||||||||
| 2626 | break; never executed: break; | 0 | ||||||||||||||||||
| 2627 | case IDENT: { never executed: case IDENT: | 0 | ||||||||||||||||||
| 2628 | if (haveUnary) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2629 | value->type = Value::Identifier; | - | ||||||||||||||||||
| 2630 | const int theid = findKnownValue(str, values, NumKnownValues); | - | ||||||||||||||||||
| 2631 | if (theid != 0) {
| 0 | ||||||||||||||||||
| 2632 | value->type = Value::KnownIdentifier; | - | ||||||||||||||||||
| 2633 | value->variant = theid; | - | ||||||||||||||||||
| 2634 | } never executed: end of block | 0 | ||||||||||||||||||
| 2635 | break; never executed: break; | 0 | ||||||||||||||||||
| 2636 | } | - | ||||||||||||||||||
| 2637 | default: { never executed: default: | 0 | ||||||||||||||||||
| 2638 | if (haveUnary) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2639 | prev(); | - | ||||||||||||||||||
| 2640 | if (testHexColor()) {
| 0 | ||||||||||||||||||
| 2641 | QColor col; | - | ||||||||||||||||||
| 2642 | if (!parseHexColor(&col)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2643 | value->type = Value::Color; | - | ||||||||||||||||||
| 2644 | value->variant = col; | - | ||||||||||||||||||
| 2645 | } else if (testFunction()) { never executed: end of block
| 0 | ||||||||||||||||||
| 2646 | QString name, args; | - | ||||||||||||||||||
| 2647 | if (!parseFunction(&name, &args)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2648 | if (name == QLatin1String("url")) {
| 0 | ||||||||||||||||||
| 2649 | value->type = Value::Uri; | - | ||||||||||||||||||
| 2650 | removeOptionalQuotes(&args); | - | ||||||||||||||||||
| 2651 | if (QFileInfo(args).isRelative() && !sourcePath.isEmpty()) {
| 0 | ||||||||||||||||||
| 2652 | args.prepend(sourcePath); | - | ||||||||||||||||||
| 2653 | } never executed: end of block | 0 | ||||||||||||||||||
| 2654 | value->variant = args; | - | ||||||||||||||||||
| 2655 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2656 | value->type = Value::Function; | - | ||||||||||||||||||
| 2657 | value->variant = QStringList() << name << args; | - | ||||||||||||||||||
| 2658 | } never executed: end of block | 0 | ||||||||||||||||||
| 2659 | } else { | - | ||||||||||||||||||
| 2660 | return recordError(); never executed: return recordError(); | 0 | ||||||||||||||||||
| 2661 | } | - | ||||||||||||||||||
| 2662 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2663 | } | - | ||||||||||||||||||
| 2664 | } | - | ||||||||||||||||||
| 2665 | skipSpace(); | - | ||||||||||||||||||
| 2666 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2667 | } | - | ||||||||||||||||||
| 2668 | - | |||||||||||||||||||
| 2669 | bool Parser::parseFunction(QString *name, QString *args) | - | ||||||||||||||||||
| 2670 | { | - | ||||||||||||||||||
| 2671 | *name = lexem(); | - | ||||||||||||||||||
| 2672 | name->chop(1); | - | ||||||||||||||||||
| 2673 | skipSpace(); | - | ||||||||||||||||||
| 2674 | const int start = index; | - | ||||||||||||||||||
| 2675 | if (!until(RPAREN)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2676 | for (int i = start; i < index - 1; ++i)
| 0 | ||||||||||||||||||
| 2677 | args->append(symbols.at(i).lexem()); never executed: args->append(symbols.at(i).lexem()); | 0 | ||||||||||||||||||
| 2678 | /* | - | ||||||||||||||||||
| 2679 | if (!nextExpr(&arguments)) return false; | - | ||||||||||||||||||
| 2680 | if (!next(RPAREN)) return false; | - | ||||||||||||||||||
| 2681 | */ | - | ||||||||||||||||||
| 2682 | skipSpace(); | - | ||||||||||||||||||
| 2683 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2684 | } | - | ||||||||||||||||||
| 2685 | - | |||||||||||||||||||
| 2686 | bool Parser::parseHexColor(QColor *col) | - | ||||||||||||||||||
| 2687 | { | - | ||||||||||||||||||
| 2688 | col->setNamedColor(lexem()); | - | ||||||||||||||||||
| 2689 | if (!col->isValid()) {
| 0 | ||||||||||||||||||
| 2690 | qWarning("QCssParser::parseHexColor: Unknown color name '%s'",lexem().toLatin1().constData()); | - | ||||||||||||||||||
| 2691 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2692 | } | - | ||||||||||||||||||
| 2693 | skipSpace(); | - | ||||||||||||||||||
| 2694 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2695 | } | - | ||||||||||||||||||
| 2696 | - | |||||||||||||||||||
| 2697 | bool Parser::testAndParseUri(QString *uri) | - | ||||||||||||||||||
| 2698 | { | - | ||||||||||||||||||
| 2699 | const int rewind = index; | - | ||||||||||||||||||
| 2700 | if (!testFunction()) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2701 | - | |||||||||||||||||||
| 2702 | QString name, args; | - | ||||||||||||||||||
| 2703 | if (!parseFunction(&name, &args)) {
| 0 | ||||||||||||||||||
| 2704 | index = rewind; | - | ||||||||||||||||||
| 2705 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2706 | } | - | ||||||||||||||||||
| 2707 | if (name.toLower() != QLatin1String("url")) {
| 0 | ||||||||||||||||||
| 2708 | index = rewind; | - | ||||||||||||||||||
| 2709 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2710 | } | - | ||||||||||||||||||
| 2711 | *uri = args; | - | ||||||||||||||||||
| 2712 | removeOptionalQuotes(uri); | - | ||||||||||||||||||
| 2713 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2714 | } | - | ||||||||||||||||||
| 2715 | - | |||||||||||||||||||
| 2716 | bool Parser::testSimpleSelector() | - | ||||||||||||||||||
| 2717 | { | - | ||||||||||||||||||
| 2718 | return testElementName() never executed: return testElementName() || (test(HASH)) || testClass() || testAttrib() || testPseudo();
| 0 | ||||||||||||||||||
| 2719 | || (test(HASH)) never executed: return testElementName() || (test(HASH)) || testClass() || testAttrib() || testPseudo();
| 0 | ||||||||||||||||||
| 2720 | || testClass() never executed: return testElementName() || (test(HASH)) || testClass() || testAttrib() || testPseudo();
| 0 | ||||||||||||||||||
| 2721 | || testAttrib() never executed: return testElementName() || (test(HASH)) || testClass() || testAttrib() || testPseudo();
| 0 | ||||||||||||||||||
| 2722 | || testPseudo(); never executed: return testElementName() || (test(HASH)) || testClass() || testAttrib() || testPseudo();
| 0 | ||||||||||||||||||
| 2723 | } | - | ||||||||||||||||||
| 2724 | - | |||||||||||||||||||
| 2725 | bool Parser::next(QCss::TokenType t) | - | ||||||||||||||||||
| 2726 | { | - | ||||||||||||||||||
| 2727 | if (hasNext() && next() == t)
| 0 | ||||||||||||||||||
| 2728 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2729 | return recordError(); never executed: return recordError(); | 0 | ||||||||||||||||||
| 2730 | } | - | ||||||||||||||||||
| 2731 | - | |||||||||||||||||||
| 2732 | bool Parser::test(QCss::TokenType t) | - | ||||||||||||||||||
| 2733 | { | - | ||||||||||||||||||
| 2734 | if (index >= symbols.count())
| 0 | ||||||||||||||||||
| 2735 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2736 | if (symbols.at(index).token == t) {
| 0 | ||||||||||||||||||
| 2737 | ++index; | - | ||||||||||||||||||
| 2738 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2739 | } | - | ||||||||||||||||||
| 2740 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2741 | } | - | ||||||||||||||||||
| 2742 | - | |||||||||||||||||||
| 2743 | QString Parser::unquotedLexem() const | - | ||||||||||||||||||
| 2744 | { | - | ||||||||||||||||||
| 2745 | QString s = lexem(); | - | ||||||||||||||||||
| 2746 | if (lookup() == STRING) {
| 0 | ||||||||||||||||||
| 2747 | s.chop(1); | - | ||||||||||||||||||
| 2748 | s.remove(0, 1); | - | ||||||||||||||||||
| 2749 | } never executed: end of block | 0 | ||||||||||||||||||
| 2750 | return s; never executed: return s; | 0 | ||||||||||||||||||
| 2751 | } | - | ||||||||||||||||||
| 2752 | - | |||||||||||||||||||
| 2753 | QString Parser::lexemUntil(QCss::TokenType t) | - | ||||||||||||||||||
| 2754 | { | - | ||||||||||||||||||
| 2755 | QString lexem; | - | ||||||||||||||||||
| 2756 | while (hasNext() && next() != t)
| 0 | ||||||||||||||||||
| 2757 | lexem += symbol().lexem(); never executed: lexem += symbol().lexem(); | 0 | ||||||||||||||||||
| 2758 | return lexem; never executed: return lexem; | 0 | ||||||||||||||||||
| 2759 | } | - | ||||||||||||||||||
| 2760 | - | |||||||||||||||||||
| 2761 | bool Parser::until(QCss::TokenType target, QCss::TokenType target2) | - | ||||||||||||||||||
| 2762 | { | - | ||||||||||||||||||
| 2763 | int braceCount = 0; | - | ||||||||||||||||||
| 2764 | int brackCount = 0; | - | ||||||||||||||||||
| 2765 | int parenCount = 0; | - | ||||||||||||||||||
| 2766 | if (index) {
| 0 | ||||||||||||||||||
| 2767 | switch(symbols.at(index-1).token) { | - | ||||||||||||||||||
| 2768 | case LBRACE: ++braceCount; break; never executed: break;never executed: case LBRACE: | 0 | ||||||||||||||||||
| 2769 | case LBRACKET: ++brackCount; break; never executed: break;never executed: case LBRACKET: | 0 | ||||||||||||||||||
| 2770 | case FUNCTION: never executed: case FUNCTION: | 0 | ||||||||||||||||||
| 2771 | case LPAREN: ++parenCount; break; never executed: break;never executed: case LPAREN: | 0 | ||||||||||||||||||
| 2772 | default: ; never executed: default: | 0 | ||||||||||||||||||
| 2773 | } never executed: end of block | 0 | ||||||||||||||||||
| 2774 | } | - | ||||||||||||||||||
| 2775 | while (index < symbols.size()) {
| 0 | ||||||||||||||||||
| 2776 | QCss::TokenType t = symbols.at(index++).token; | - | ||||||||||||||||||
| 2777 | switch (t) { | - | ||||||||||||||||||
| 2778 | case LBRACE: ++braceCount; break; never executed: break;never executed: case LBRACE: | 0 | ||||||||||||||||||
| 2779 | case RBRACE: --braceCount; break; never executed: break;never executed: case RBRACE: | 0 | ||||||||||||||||||
| 2780 | case LBRACKET: ++brackCount; break; never executed: break;never executed: case LBRACKET: | 0 | ||||||||||||||||||
| 2781 | case RBRACKET: --brackCount; break; never executed: break;never executed: case RBRACKET: | 0 | ||||||||||||||||||
| 2782 | case FUNCTION: never executed: case FUNCTION: | 0 | ||||||||||||||||||
| 2783 | case LPAREN: ++parenCount; break; never executed: break;never executed: case LPAREN: | 0 | ||||||||||||||||||
| 2784 | case RPAREN: --parenCount; break; never executed: break;never executed: case RPAREN: | 0 | ||||||||||||||||||
| 2785 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||||||||
| 2786 | } | - | ||||||||||||||||||
| 2787 | if ((t == target || (target2 != NONE && t == target2))
| 0 | ||||||||||||||||||
| 2788 | && braceCount <= 0
| 0 | ||||||||||||||||||
| 2789 | && brackCount <= 0
| 0 | ||||||||||||||||||
| 2790 | && parenCount <= 0)
| 0 | ||||||||||||||||||
| 2791 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2792 | - | |||||||||||||||||||
| 2793 | if (braceCount < 0 || brackCount < 0 || parenCount < 0) {
| 0 | ||||||||||||||||||
| 2794 | --index; | - | ||||||||||||||||||
| 2795 | break; never executed: break; | 0 | ||||||||||||||||||
| 2796 | } | - | ||||||||||||||||||
| 2797 | } never executed: end of block | 0 | ||||||||||||||||||
| 2798 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2799 | } | - | ||||||||||||||||||
| 2800 | - | |||||||||||||||||||
| 2801 | bool Parser::testTokenAndEndsWith(QCss::TokenType t, QLatin1String str) | - | ||||||||||||||||||
| 2802 | { | - | ||||||||||||||||||
| 2803 | if (!test(t)) return false; never executed: return false;
| 0 | ||||||||||||||||||
| 2804 | if (!lexem().endsWith(str, Qt::CaseInsensitive)) {
| 0 | ||||||||||||||||||
| 2805 | prev(); | - | ||||||||||||||||||
| 2806 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2807 | } | - | ||||||||||||||||||
| 2808 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2809 | } | - | ||||||||||||||||||
| 2810 | - | |||||||||||||||||||
| 2811 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 2812 | #endif // QT_NO_CSSPARSER | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |