OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 2 Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
3 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> | 3 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
4 2004, 2005, 2007, 2010 Rob Buis <buis@kde.org> | 4 2004, 2005, 2007, 2010 Rob Buis <buis@kde.org> |
5 Copyright (C) 2005, 2006 Apple Computer, Inc. | 5 Copyright (C) 2005, 2006 Apple Computer, Inc. |
6 | 6 |
7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
11 | 11 |
12 This library is distributed in the hope that it will be useful, | 12 This library is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 Library General Public License for more details. | 15 Library General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU Library General Public License | 17 You should have received a copy of the GNU Library General Public License |
18 along with this library; see the file COPYING.LIB. If not, write to | 18 along with this library; see the file COPYING.LIB. If not, write to |
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 Boston, MA 02110-1301, USA. | 20 Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 | 24 |
25 #include "CSSPropertyNames.h" | 25 #include "CSSPropertyNames.h" |
26 #include "CSSValueKeywords.h" | 26 #include "CSSValueKeywords.h" |
27 #include "RuntimeEnabledFeatures.h" | 27 #include "RuntimeEnabledFeatures.h" |
28 #include "core/css/CSSParser.h" | 28 #include "core/css/parser/BisonCSSParser.h" |
29 #include "core/css/CSSValueList.h" | 29 #include "core/css/CSSValueList.h" |
30 #include "core/rendering/RenderTheme.h" | 30 #include "core/rendering/RenderTheme.h" |
31 #include "core/svg/SVGPaint.h" | 31 #include "core/svg/SVGPaint.h" |
32 | 32 |
33 using namespace std; | 33 using namespace std; |
34 | 34 |
35 namespace WebCore { | 35 namespace WebCore { |
36 | 36 |
37 static bool isSystemColor(int id) | 37 static bool isSystemColor(int id) |
38 { | 38 { |
39 return (id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSS
ValueMenu; | 39 return (id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSS
ValueMenu; |
40 } | 40 } |
41 | 41 |
42 bool CSSParser::parseSVGValue(CSSPropertyID propId, bool important) | 42 bool BisonCSSParser::parseSVGValue(CSSPropertyID propId, bool important) |
43 { | 43 { |
44 CSSParserValue* value = m_valueList->current(); | 44 CSSParserValue* value = m_valueList->current(); |
45 if (!value) | 45 if (!value) |
46 return false; | 46 return false; |
47 | 47 |
48 CSSValueID id = value->id; | 48 CSSValueID id = value->id; |
49 | 49 |
50 bool valid_primitive = false; | 50 bool valid_primitive = false; |
51 RefPtr<CSSValue> parsedValue; | 51 RefPtr<CSSValue> parsedValue; |
52 | 52 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 break; | 280 break; |
281 case CSSPropertyMaskType: // luminance | alpha | inherit | 281 case CSSPropertyMaskType: // luminance | alpha | inherit |
282 if (id == CSSValueLuminance || id == CSSValueAlpha) | 282 if (id == CSSValueLuminance || id == CSSValueAlpha) |
283 valid_primitive = true; | 283 valid_primitive = true; |
284 break; | 284 break; |
285 | 285 |
286 /* shorthand properties */ | 286 /* shorthand properties */ |
287 case CSSPropertyMarker: | 287 case CSSPropertyMarker: |
288 { | 288 { |
289 ShorthandScope scope(this, propId); | 289 ShorthandScope scope(this, propId); |
290 CSSParser::ImplicitScope implicitScope(this, PropertyImplicit); | 290 BisonCSSParser::ImplicitScope implicitScope(this, PropertyImplicit); |
291 if (!parseValue(CSSPropertyMarkerStart, important)) | 291 if (!parseValue(CSSPropertyMarkerStart, important)) |
292 return false; | 292 return false; |
293 if (m_valueList->current()) { | 293 if (m_valueList->current()) { |
294 rollbackLastProperties(1); | 294 rollbackLastProperties(1); |
295 return false; | 295 return false; |
296 } | 296 } |
297 CSSValue* value = m_parsedProperties.last().value(); | 297 CSSValue* value = m_parsedProperties.last().value(); |
298 addProperty(CSSPropertyMarkerMid, value, important); | 298 addProperty(CSSPropertyMarkerMid, value, important); |
299 addProperty(CSSPropertyMarkerEnd, value, important); | 299 addProperty(CSSPropertyMarkerEnd, value, important); |
300 return true; | 300 return true; |
301 } | 301 } |
302 default: | 302 default: |
303 // If you crash here, it's because you added a css property and are not
handling it | 303 // If you crash here, it's because you added a css property and are not
handling it |
304 // in either this switch statement or the one in CSSParser::parseValue | 304 // in either this switch statement or the one in BisonCSSParser::parseVa
lue |
305 ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propId); | 305 ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propId); |
306 return false; | 306 return false; |
307 } | 307 } |
308 | 308 |
309 if (valid_primitive) { | 309 if (valid_primitive) { |
310 if (id != 0) | 310 if (id != 0) |
311 parsedValue = CSSPrimitiveValue::createIdentifier(id); | 311 parsedValue = CSSPrimitiveValue::createIdentifier(id); |
312 else if (value->unit == CSSPrimitiveValue::CSS_STRING) | 312 else if (value->unit == CSSPrimitiveValue::CSS_STRING) |
313 parsedValue = CSSPrimitiveValue::create(value->string, (CSSPrimitive
Value::UnitTypes) value->unit); | 313 parsedValue = CSSPrimitiveValue::create(value->string, (CSSPrimitive
Value::UnitTypes) value->unit); |
314 else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <=
CSSPrimitiveValue::CSS_KHZ) | 314 else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <=
CSSPrimitiveValue::CSS_KHZ) |
315 parsedValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitive
Value::UnitTypes) value->unit); | 315 parsedValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitive
Value::UnitTypes) value->unit); |
316 else if (value->unit >= CSSParserValue::Q_EMS) | 316 else if (value->unit >= CSSParserValue::Q_EMS) |
317 parsedValue = CSSPrimitiveValue::createAllowingMarginQuirk(value->fV
alue, CSSPrimitiveValue::CSS_EMS); | 317 parsedValue = CSSPrimitiveValue::createAllowingMarginQuirk(value->fV
alue, CSSPrimitiveValue::CSS_EMS); |
318 if (isCalculation(value)) { | 318 if (isCalculation(value)) { |
319 // FIXME calc() http://webkit.org/b/16662 : actually create a CSSPri
mitiveValue here, ie | 319 // FIXME calc() http://webkit.org/b/16662 : actually create a CSSPri
mitiveValue here, ie |
320 // parsedValue = CSSPrimitiveValue::create(m_parsedCalculation.relea
se()); | 320 // parsedValue = CSSPrimitiveValue::create(m_parsedCalculation.relea
se()); |
321 m_parsedCalculation.release(); | 321 m_parsedCalculation.release(); |
322 parsedValue = 0; | 322 parsedValue = 0; |
323 } | 323 } |
324 m_valueList->next(); | 324 m_valueList->next(); |
325 } | 325 } |
326 if (!parsedValue || (m_valueList->current() && !inShorthand())) | 326 if (!parsedValue || (m_valueList->current() && !inShorthand())) |
327 return false; | 327 return false; |
328 | 328 |
329 addProperty(propId, parsedValue.release(), important); | 329 addProperty(propId, parsedValue.release(), important); |
330 return true; | 330 return true; |
331 } | 331 } |
332 | 332 |
333 PassRefPtr<CSSValue> CSSParser::parseSVGStrokeDasharray() | 333 PassRefPtr<CSSValue> BisonCSSParser::parseSVGStrokeDasharray() |
334 { | 334 { |
335 RefPtr<CSSValueList> ret = CSSValueList::createCommaSeparated(); | 335 RefPtr<CSSValueList> ret = CSSValueList::createCommaSeparated(); |
336 CSSParserValue* value = m_valueList->current(); | 336 CSSParserValue* value = m_valueList->current(); |
337 bool valid_primitive = true; | 337 bool valid_primitive = true; |
338 while (value) { | 338 while (value) { |
339 valid_primitive = validUnit(value, FLength | FPercent | FNonNeg, SVGAttr
ibuteMode); | 339 valid_primitive = validUnit(value, FLength | FPercent | FNonNeg, SVGAttr
ibuteMode); |
340 if (!valid_primitive) | 340 if (!valid_primitive) |
341 break; | 341 break; |
342 if (value->id != 0) | 342 if (value->id != 0) |
343 ret->append(CSSPrimitiveValue::createIdentifier(value->id)); | 343 ret->append(CSSPrimitiveValue::createIdentifier(value->id)); |
344 else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <=
CSSPrimitiveValue::CSS_KHZ) | 344 else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <=
CSSPrimitiveValue::CSS_KHZ) |
345 ret->append(CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveVa
lue::UnitTypes) value->unit)); | 345 ret->append(CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveVa
lue::UnitTypes) value->unit)); |
346 value = m_valueList->next(); | 346 value = m_valueList->next(); |
347 if (value && value->unit == CSSParserValue::Operator && value->iValue ==
',') | 347 if (value && value->unit == CSSParserValue::Operator && value->iValue ==
',') |
348 value = m_valueList->next(); | 348 value = m_valueList->next(); |
349 } | 349 } |
350 if (!valid_primitive) | 350 if (!valid_primitive) |
351 return 0; | 351 return 0; |
352 return ret.release(); | 352 return ret.release(); |
353 } | 353 } |
354 | 354 |
355 PassRefPtr<CSSValue> CSSParser::parseSVGPaint() | 355 PassRefPtr<CSSValue> BisonCSSParser::parseSVGPaint() |
356 { | 356 { |
357 RGBA32 c = Color::transparent; | 357 RGBA32 c = Color::transparent; |
358 if (!parseColorFromValue(m_valueList->current(), c)) | 358 if (!parseColorFromValue(m_valueList->current(), c)) |
359 return SVGPaint::createUnknown(); | 359 return SVGPaint::createUnknown(); |
360 return SVGPaint::createColor(Color(c)); | 360 return SVGPaint::createColor(Color(c)); |
361 } | 361 } |
362 | 362 |
363 PassRefPtr<CSSValue> CSSParser::parseSVGColor() | 363 PassRefPtr<CSSValue> BisonCSSParser::parseSVGColor() |
364 { | 364 { |
365 RGBA32 c = Color::transparent; | 365 RGBA32 c = Color::transparent; |
366 if (!parseColorFromValue(m_valueList->current(), c)) | 366 if (!parseColorFromValue(m_valueList->current(), c)) |
367 return 0; | 367 return 0; |
368 return SVGColor::createFromColor(Color(c)); | 368 return SVGColor::createFromColor(Color(c)); |
369 } | 369 } |
370 | 370 |
371 // normal | [ fill || stroke || markers ] | 371 // normal | [ fill || stroke || markers ] |
372 PassRefPtr<CSSValue> CSSParser::parsePaintOrder() const | 372 PassRefPtr<CSSValue> BisonCSSParser::parsePaintOrder() const |
373 { | 373 { |
374 if (m_valueList->size() > 3) | 374 if (m_valueList->size() > 3) |
375 return 0; | 375 return 0; |
376 | 376 |
377 CSSParserValue* value = m_valueList->current(); | 377 CSSParserValue* value = m_valueList->current(); |
378 if (!value) | 378 if (!value) |
379 return 0; | 379 return 0; |
380 | 380 |
381 RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated(); | 381 RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated(); |
382 | 382 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueFill)); | 420 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueFill)); |
421 if (!seenStroke) | 421 if (!seenStroke) |
422 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueStroke)
); | 422 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueStroke)
); |
423 if (!seenMarkers) | 423 if (!seenMarkers) |
424 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueMarkers
)); | 424 parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueMarkers
)); |
425 | 425 |
426 return parsedValues.release(); | 426 return parsedValues.release(); |
427 } | 427 } |
428 | 428 |
429 } | 429 } |
OLD | NEW |