1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/*
Copyright (C) 2008 Eric Seidel <eric@webkit.org>
Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
2004, 2005, 2007, 2010 Rob Buis <buis@kde.org>
Copyright (C) 2005, 2006 Apple Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "CSSInheritedValue.h"
#include "CSSInitialValue.h"
#include "CSSParser.h"
#include "CSSPropertyNames.h"
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
#include "RenderTheme.h"
#include "SVGPaint.h"
namespace WebCore {
static bool isValidSystemControlColorValue(CSSValueID id)
{
return id >= CSSValueActiveborder && CSSParser::isValidSystemColorValue(id);
}
bool CSSParser::parseSVGValue(CSSPropertyID propId, bool important)
{
if (!m_valueList->current())
return false;
ValueWithCalculation valueWithCalculation(*m_valueList->current());
CSSValueID id = valueWithCalculation.value().id;
bool valid_primitive = false;
RefPtr<CSSValue> parsedValue;
switch (propId) {
/* The comment to the right defines all valid value of these
* properties as defined in SVG 1.1, Appendix N. Property index */
case CSSPropertyAlignmentBaseline:
// auto | baseline | before-edge | text-before-edge | middle |
// central | after-edge | text-after-edge | ideographic | alphabetic |
// hanging | mathematical | inherit
if (id == CSSValueAuto || id == CSSValueBaseline || id == CSSValueMiddle ||
(id >= CSSValueBeforeEdge && id <= CSSValueMathematical))
valid_primitive = true;
break;
case CSSPropertyBaselineShift:
// baseline | super | sub | <percentage> | <length> | inherit
if (id == CSSValueBaseline || id == CSSValueSub ||
id >= CSSValueSuper)
valid_primitive = true;
else
valid_primitive = validateUnit(valueWithCalculation, FLength | FPercent, SVGAttributeMode);
break;
case CSSPropertyDominantBaseline:
// auto | use-script | no-change | reset-size | ideographic |
// alphabetic | hanging | mathematical | central | middle |
// text-after-edge | text-before-edge | inherit
if (id == CSSValueAuto || id == CSSValueMiddle ||
(id >= CSSValueUseScript && id <= CSSValueResetSize) ||
(id >= CSSValueCentral && id <= CSSValueMathematical))
valid_primitive = true;
break;
case CSSPropertyEnableBackground:
// accumulate | new [x] [y] [width] [height] | inherit
if (id == CSSValueAccumulate) // TODO : new
valid_primitive = true;
break;
case CSSPropertyMarkerStart:
case CSSPropertyMarkerMid:
case CSSPropertyMarkerEnd:
case CSSPropertyMask:
if (id == CSSValueNone)
valid_primitive = true;
else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = CSSPrimitiveValue::create(valueWithCalculation.value().string, CSSPrimitiveValue::CSS_URI);
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyClipRule: // nonzero | evenodd | inherit
case CSSPropertyFillRule:
if (id == CSSValueNonzero || id == CSSValueEvenodd)
valid_primitive = true;
break;
case CSSPropertyStrokeMiterlimit: // <miterlimit> | inherit
valid_primitive = validateUnit(valueWithCalculation, FNumber | FNonNeg, SVGAttributeMode);
break;
case CSSPropertyStrokeLinejoin: // miter | round | bevel | inherit
if (id == CSSValueMiter || id == CSSValueRound || id == CSSValueBevel)
valid_primitive = true;
break;
case CSSPropertyStrokeLinecap: // butt | round | square | inherit
if (id == CSSValueButt || id == CSSValueRound || id == CSSValueSquare)
valid_primitive = true;
break;
case CSSPropertyStrokeOpacity: // <opacity-value> | inherit
case CSSPropertyFillOpacity:
case CSSPropertyStopOpacity:
case CSSPropertyFloodOpacity:
valid_primitive = (!id && validateUnit(valueWithCalculation, FNumber | FPercent, SVGAttributeMode));
break;
case CSSPropertyShapeRendering:
// auto | optimizeSpeed | crispEdges | geometricPrecision | inherit
if (id == CSSValueAuto || id == CSSValueOptimizespeed ||
id == CSSValueCrispedges || id == CSSValueGeometricprecision)
valid_primitive = true;
break;
case CSSPropertyColorRendering: // auto | optimizeSpeed | optimizeQuality | inherit
if (id == CSSValueAuto || id == CSSValueOptimizespeed ||
id == CSSValueOptimizequality)
valid_primitive = true;
break;
case CSSPropertyBufferedRendering: // auto | dynamic | static
if (id == CSSValueAuto || id == CSSValueDynamic || id == CSSValueStatic)
valid_primitive = true;
break;
case CSSPropertyColorProfile: // auto | sRGB | <name> | <uri> inherit
if (id == CSSValueAuto || id == CSSValueSrgb)
valid_primitive = true;
break;
case CSSPropertyColorInterpolation: // auto | sRGB | linearRGB | inherit
case CSSPropertyColorInterpolationFilters:
if (id == CSSValueAuto || id == CSSValueSrgb || id == CSSValueLinearrgb)
valid_primitive = true;
break;
/* Start of supported CSS properties with validation. This is needed for parseShortHand to work
* correctly and allows optimization in applyRule(..)
*/
case CSSPropertyTextAnchor: // start | middle | end | inherit
if (id == CSSValueStart || id == CSSValueMiddle || id == CSSValueEnd)
valid_primitive = true;
break;
case CSSPropertyGlyphOrientationVertical: // auto | <angle> | inherit
if (id == CSSValueAuto) {
valid_primitive = true;
break;
}
FALLTHROUGH;
case CSSPropertyGlyphOrientationHorizontal: // <angle> (restricted to _deg_ per SVG 1.1 spec) | inherit
if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_DEG || valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_NUMBER) {
parsedValue = CSSPrimitiveValue::create(valueWithCalculation.value().fValue, CSSPrimitiveValue::CSS_DEG);
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyPaintOrder:
if (id == CSSValueNormal)
valid_primitive = true;
else
parsedValue = parsePaintOrder();
break;
case CSSPropertyFill: // <paint> | inherit
case CSSPropertyStroke: // <paint> | inherit
{
if (id == CSSValueNone)
parsedValue = SVGPaint::createNone();
else if (id == CSSValueCurrentcolor)
parsedValue = SVGPaint::createCurrentColor();
else if (isValidSystemControlColorValue(id) || id == CSSValueMenu)
parsedValue = SVGPaint::createColor(RenderTheme::defaultTheme()->systemColor(id));
else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) {
RGBA32 c = Color::transparent;
if (m_valueList->next()) {
if (parseColorFromValue(*m_valueList->current(), c))
parsedValue = SVGPaint::createURIAndColor(valueWithCalculation.value().string, c);
else if (m_valueList->current()->id == CSSValueNone)
parsedValue = SVGPaint::createURIAndNone(valueWithCalculation.value().string);
}
if (!parsedValue)
parsedValue = SVGPaint::createURI(valueWithCalculation.value().string);
} else
parsedValue = parseSVGPaint();
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyStopColor: // TODO : icccolor
case CSSPropertyFloodColor:
case CSSPropertyLightingColor:
if (CSSParser::isValidSystemColorValue(id)
|| (id >= CSSValueAliceblue && id <= CSSValueYellowgreen))
parsedValue = SVGColor::createFromString(valueWithCalculation.value().string);
else if (id == CSSValueCurrentcolor)
parsedValue = SVGColor::createCurrentColor();
else // TODO : svgcolor (iccColor)
parsedValue = parseSVGColor();
if (parsedValue)
m_valueList->next();
break;
case CSSPropertyVectorEffect: // none | non-scaling-stroke | inherit
if (id == CSSValueNone || id == CSSValueNonScalingStroke)
valid_primitive = true;
break;
case CSSPropertyWritingMode:
// lr-tb | rl_tb | tb-rl | lr | rl | tb | inherit
if (id == CSSValueLrTb || id == CSSValueRlTb || id == CSSValueTbRl || id == CSSValueLr || id == CSSValueRl || id == CSSValueTb)
valid_primitive = true;
break;
case CSSPropertyStrokeWidth: // <length> | inherit
case CSSPropertyStrokeDashoffset:
valid_primitive = validateUnit(valueWithCalculation, FLength | FPercent, SVGAttributeMode);
break;
case CSSPropertyStrokeDasharray: // none | <dasharray> | inherit
if (id == CSSValueNone)
valid_primitive = true;
else
parsedValue = parseSVGStrokeDasharray();
break;
case CSSPropertyKerning: // auto | normal | <length> | inherit
if (id == CSSValueAuto || id == CSSValueNormal)
valid_primitive = true;
else
valid_primitive = validateUnit(valueWithCalculation, FLength, SVGAttributeMode);
break;
case CSSPropertyClipPath: // <uri> | none | inherit
case CSSPropertyFilter:
if (id == CSSValueNone)
valid_primitive = true;
else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = CSSPrimitiveValue::create(valueWithCalculation.value().string, (CSSPrimitiveValue::UnitTypes) valueWithCalculation.value().unit);
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyWebkitSvgShadow:
if (id == CSSValueNone)
valid_primitive = true;
else {
RefPtr<CSSValueList> shadowValueList = parseShadow(*m_valueList, propId);
if (shadowValueList) {
addProperty(propId, shadowValueList.release(), important);
m_valueList->next();
return true;
}
return false;
}
break;
case CSSPropertyMaskType: // luminance | alpha | inherit
if (id == CSSValueLuminance || id == CSSValueAlpha)
valid_primitive = true;
break;
/* shorthand properties */
case CSSPropertyMarker:
{
ShorthandScope scope(this, propId);
m_implicitShorthand = true;
if (!parseValue(CSSPropertyMarkerStart, important))
return false;
if (m_valueList->current()) {
rollbackLastProperties(1);
return false;
}
CSSValue* value = m_parsedProperties.last().value();
addProperty(CSSPropertyMarkerMid, value, important);
addProperty(CSSPropertyMarkerEnd, value, important);
m_implicitShorthand = false;
return true;
}
case CSSPropertyCx:
case CSSPropertyCy:
case CSSPropertyR:
case CSSPropertyRx:
case CSSPropertyRy:
case CSSPropertyX:
case CSSPropertyY:
valid_primitive = (!id && validateUnit(valueWithCalculation, FLength | FPercent));
break;
default:
// If you crash here, it's because you added a css property and are not handling it
// in either this switch statement or the one in CSSParser::parseValue
ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propId);
return false;
}
if (valid_primitive) {
if (id != 0)
parsedValue = CSSPrimitiveValue::createIdentifier(id);
else if (valueWithCalculation.value().unit == CSSPrimitiveValue::CSS_STRING)
parsedValue = CSSPrimitiveValue::create(valueWithCalculation.value().string, (CSSPrimitiveValue::UnitTypes) valueWithCalculation.value().unit);
else if (valueWithCalculation.value().unit >= CSSPrimitiveValue::CSS_NUMBER && valueWithCalculation.value().unit <= CSSPrimitiveValue::CSS_KHZ)
parsedValue = CSSPrimitiveValue::create(valueWithCalculation.value().fValue, (CSSPrimitiveValue::UnitTypes) valueWithCalculation.value().unit);
else if (valueWithCalculation.value().unit >= CSSParserValue::Q_EMS)
parsedValue = CSSPrimitiveValue::createAllowingMarginQuirk(valueWithCalculation.value().fValue, CSSPrimitiveValue::CSS_EMS);
if (isCalculation(valueWithCalculation))
parsedValue = CSSPrimitiveValue::create(valueWithCalculation.calculation());
m_valueList->next();
}
if (!parsedValue || (m_valueList->current() && !inShorthand()))
return false;
addProperty(propId, parsedValue.release(), important);
return true;
}
RefPtr<CSSValue> CSSParser::parseSVGStrokeDasharray()
{
RefPtr<CSSValueList> ret = CSSValueList::createCommaSeparated();
CSSParserValue* value = m_valueList->current();
bool valid_primitive = true;
while (value) {
ValueWithCalculation valueWithCalculation(*value);
valid_primitive = validateUnit(valueWithCalculation, FLength | FPercent | FNonNeg, SVGAttributeMode);
if (!valid_primitive)
break;
// FIXME: This code doesn't handle calculated values.
if (value->id != 0)
ret->append(CSSPrimitiveValue::createIdentifier(value->id));
else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
ret->append(CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit));
value = m_valueList->next();
if (value && value->unit == CSSParserValue::Operator && value->iValue == ',')
value = m_valueList->next();
}
if (!valid_primitive)
return nullptr;
return ret;
}
RefPtr<CSSValue> CSSParser::parseSVGPaint()
{
RGBA32 c = Color::transparent;
if (!parseColorFromValue(*m_valueList->current(), c))
return nullptr;
return SVGPaint::createColor(Color(c));
}
RefPtr<CSSValue> CSSParser::parseSVGColor()
{
RGBA32 c = Color::transparent;
if (!parseColorFromValue(*m_valueList->current(), c))
return nullptr;
return SVGColor::createFromColor(Color(c));
}
RefPtr<CSSValue> CSSParser::parsePaintOrder()
{
CSSParserValue* value = m_valueList->current();
Vector<CSSValueID> paintTypeList;
RefPtr<CSSPrimitiveValue> fill;
RefPtr<CSSPrimitiveValue> stroke;
RefPtr<CSSPrimitiveValue> markers;
while (value) {
if (value->id == CSSValueFill && !fill)
fill = CSSPrimitiveValue::createIdentifier(value->id);
else if (value->id == CSSValueStroke && !stroke)
stroke = CSSPrimitiveValue::createIdentifier(value->id);
else if (value->id == CSSValueMarkers && !markers)
markers = CSSPrimitiveValue::createIdentifier(value->id);
else
return nullptr;
paintTypeList.append(value->id);
value = m_valueList->next();
}
// After parsing we serialize the paint-order list. Since it is not possible to
// pop a last list items from CSSValueList without bigger cost, we create the
// list after parsing.
CSSValueID firstPaintOrderType = paintTypeList.at(0);
RefPtr<CSSValueList> paintOrderList = CSSValueList::createSpaceSeparated();
switch (firstPaintOrderType) {
case CSSValueFill:
FALLTHROUGH;
case CSSValueStroke:
paintOrderList->append(firstPaintOrderType == CSSValueFill ? fill.releaseNonNull() : stroke.releaseNonNull());
if (paintTypeList.size() > 1) {
if (paintTypeList.at(1) == CSSValueMarkers)
paintOrderList->append(markers.releaseNonNull());
}
break;
case CSSValueMarkers:
paintOrderList->append(markers.releaseNonNull());
if (paintTypeList.size() > 1) {
if (paintTypeList.at(1) == CSSValueStroke)
paintOrderList->append(stroke.releaseNonNull());
}
break;
default:
ASSERT_NOT_REACHED();
}
return paintOrderList;
}
}
|