| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. |
| 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
| 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
| 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. | 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. |
| 9 * Copyright (C) 2012 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
| 10 * | 10 * |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * Boston, MA 02110-1301, USA. | 24 * Boston, MA 02110-1301, USA. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/css/parser/CSSPropertyParser.h" | 28 #include "core/css/parser/CSSPropertyParser.h" |
| 29 | 29 |
| 30 #include "core/StylePropertyShorthand.h" | 30 #include "core/StylePropertyShorthand.h" |
| 31 #include "core/css/CSSBasicShapeValues.h" | 31 #include "core/css/CSSBasicShapeValues.h" |
| 32 #include "core/css/CSSBorderImage.h" | 32 #include "core/css/CSSBorderImage.h" |
| 33 #include "core/css/CSSContentDistributionValue.h" | 33 #include "core/css/CSSContentDistributionValue.h" |
| 34 #include "core/css/CSSCounterValue.h" | |
| 35 #include "core/css/CSSCrossfadeValue.h" | 34 #include "core/css/CSSCrossfadeValue.h" |
| 36 #include "core/css/CSSCustomIdentValue.h" | 35 #include "core/css/CSSCustomIdentValue.h" |
| 37 #include "core/css/CSSFunctionValue.h" | 36 #include "core/css/CSSFunctionValue.h" |
| 38 #include "core/css/CSSGridLineNamesValue.h" | 37 #include "core/css/CSSGridLineNamesValue.h" |
| 39 #include "core/css/CSSImageSetValue.h" | 38 #include "core/css/CSSImageSetValue.h" |
| 40 #include "core/css/CSSPrimitiveValueMappings.h" | 39 #include "core/css/CSSPrimitiveValueMappings.h" |
| 41 #include "core/css/CSSProperty.h" | 40 #include "core/css/CSSProperty.h" |
| 42 #include "core/css/CSSPropertyMetadata.h" | 41 #include "core/css/CSSPropertyMetadata.h" |
| 43 #include "core/css/CSSQuadValue.h" | 42 #include "core/css/CSSQuadValue.h" |
| 44 #include "core/css/CSSReflectValue.h" | 43 #include "core/css/CSSReflectValue.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return CSSPrimitiveValue::create(m_parsedCalculation.release()); | 232 return CSSPrimitiveValue::create(m_parsedCalculation.release()); |
| 234 } | 233 } |
| 235 | 234 |
| 236 ASSERT((value->unit() >= CSSPrimitiveValue::UnitType::Number && value->unit(
) <= CSSPrimitiveValue::UnitType::Kilohertz) | 235 ASSERT((value->unit() >= CSSPrimitiveValue::UnitType::Number && value->unit(
) <= CSSPrimitiveValue::UnitType::Kilohertz) |
| 237 || (value->unit() >= CSSPrimitiveValue::UnitType::Turns && value->unit()
<= CSSPrimitiveValue::UnitType::Chs) | 236 || (value->unit() >= CSSPrimitiveValue::UnitType::Turns && value->unit()
<= CSSPrimitiveValue::UnitType::Chs) |
| 238 || (value->unit() >= CSSPrimitiveValue::UnitType::ViewportWidth && value
->unit() <= CSSPrimitiveValue::UnitType::ViewportMax) | 237 || (value->unit() >= CSSPrimitiveValue::UnitType::ViewportWidth && value
->unit() <= CSSPrimitiveValue::UnitType::ViewportMax) |
| 239 || (value->unit() >= CSSPrimitiveValue::UnitType::DotsPerPixel && value-
>unit() <= CSSPrimitiveValue::UnitType::DotsPerCentimeter)); | 238 || (value->unit() >= CSSPrimitiveValue::UnitType::DotsPerPixel && value-
>unit() <= CSSPrimitiveValue::UnitType::DotsPerCentimeter)); |
| 240 return cssValuePool().createValue(value->fValue, value->unit()); | 239 return cssValuePool().createValue(value->fValue, value->unit()); |
| 241 } | 240 } |
| 242 | 241 |
| 243 inline PassRefPtrWillBeRawPtr<CSSStringValue> CSSPropertyParser::createPrimitive
StringValue(CSSParserValue* value) | |
| 244 { | |
| 245 ASSERT(value->m_unit == CSSParserValue::String || value->m_unit == CSSParser
Value::Identifier); | |
| 246 return CSSStringValue::create(value->string); | |
| 247 } | |
| 248 | |
| 249 inline PassRefPtrWillBeRawPtr<CSSCustomIdentValue> CSSPropertyParser::createPrim
itiveCustomIdentValue(CSSParserValue* value) | 242 inline PassRefPtrWillBeRawPtr<CSSCustomIdentValue> CSSPropertyParser::createPrim
itiveCustomIdentValue(CSSParserValue* value) |
| 250 { | 243 { |
| 251 ASSERT(value->m_unit == CSSParserValue::String || value->m_unit == CSSParser
Value::Identifier); | 244 ASSERT(value->m_unit == CSSParserValue::String || value->m_unit == CSSParser
Value::Identifier); |
| 252 return CSSCustomIdentValue::create(value->string); | 245 return CSSCustomIdentValue::create(value->string); |
| 253 } | 246 } |
| 254 | 247 |
| 255 static inline bool isComma(CSSParserValue* value) | 248 static inline bool isComma(CSSParserValue* value) |
| 256 { | 249 { |
| 257 ASSERT(value); | 250 ASSERT(value); |
| 258 return value->m_unit == CSSParserValue::Operator && value->iValue == ','; | 251 return value->m_unit == CSSParserValue::Operator && value->iValue == ','; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 return false; | 322 return false; |
| 330 addProperty(propId, cssValuePool().createIdentifierValue(id), important)
; | 323 addProperty(propId, cssValuePool().createIdentifierValue(id), important)
; |
| 331 return true; | 324 return true; |
| 332 } | 325 } |
| 333 | 326 |
| 334 bool validPrimitive = false; | 327 bool validPrimitive = false; |
| 335 Units unitless = FUnknown; | 328 Units unitless = FUnknown; |
| 336 RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; | 329 RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; |
| 337 | 330 |
| 338 switch (propId) { | 331 switch (propId) { |
| 339 case CSSPropertyContent: // [ <string> | <uri> | <counter> | at
tr(X) | open-quote | | |
| 340 // close-quote | no-open-quote | no-close-quote ]+ | inherit | |
| 341 parsedValue = parseContent(); | |
| 342 break; | |
| 343 | |
| 344 /* Start of supported CSS properties with validation. This is needed for par
seShorthand to work | |
| 345 * correctly and allows optimization in blink::applyRule(..) | |
| 346 */ | |
| 347 | |
| 348 case CSSPropertyBackgroundColor: // <color> | inherit | 332 case CSSPropertyBackgroundColor: // <color> | inherit |
| 349 case CSSPropertyBorderTopColor: // <color> | inherit | 333 case CSSPropertyBorderTopColor: // <color> | inherit |
| 350 case CSSPropertyBorderRightColor: | 334 case CSSPropertyBorderRightColor: |
| 351 case CSSPropertyBorderBottomColor: | 335 case CSSPropertyBorderBottomColor: |
| 352 case CSSPropertyBorderLeftColor: | 336 case CSSPropertyBorderLeftColor: |
| 353 parsedValue = parseColor(m_valueList->current(), inQuirksMode() && (!inS
horthand() || m_currentShorthand == CSSPropertyBorderColor)); | 337 parsedValue = parseColor(m_valueList->current(), inQuirksMode() && (!inS
horthand() || m_currentShorthand == CSSPropertyBorderColor)); |
| 354 if (parsedValue) | 338 if (parsedValue) |
| 355 m_valueList->next(); | 339 m_valueList->next(); |
| 356 break; | 340 break; |
| 357 | 341 |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 case CSSPropertyCy: | 878 case CSSPropertyCy: |
| 895 case CSSPropertyX: | 879 case CSSPropertyX: |
| 896 case CSSPropertyY: | 880 case CSSPropertyY: |
| 897 case CSSPropertyR: | 881 case CSSPropertyR: |
| 898 case CSSPropertyRx: | 882 case CSSPropertyRx: |
| 899 case CSSPropertyRy: | 883 case CSSPropertyRy: |
| 900 case CSSPropertyScale: | 884 case CSSPropertyScale: |
| 901 case CSSPropertyTranslate: | 885 case CSSPropertyTranslate: |
| 902 case CSSPropertyCursor: | 886 case CSSPropertyCursor: |
| 903 case CSSPropertyTransformOrigin: | 887 case CSSPropertyTransformOrigin: |
| 888 case CSSPropertyContent: |
| 904 validPrimitive = false; | 889 validPrimitive = false; |
| 905 break; | 890 break; |
| 906 | 891 |
| 907 case CSSPropertyScrollSnapPointsX: | 892 case CSSPropertyScrollSnapPointsX: |
| 908 case CSSPropertyScrollSnapPointsY: | 893 case CSSPropertyScrollSnapPointsY: |
| 909 parsedValue = parseScrollSnapPoints(); | 894 parsedValue = parseScrollSnapPoints(); |
| 910 break; | 895 break; |
| 911 case CSSPropertyScrollSnapCoordinate: | 896 case CSSPropertyScrollSnapCoordinate: |
| 912 parsedValue = parseScrollSnapCoordinate(); | 897 parsedValue = parseScrollSnapCoordinate(); |
| 913 break; | 898 break; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseScrollSnapCoordinate() | 1235 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseScrollSnapCoordinate() |
| 1251 { | 1236 { |
| 1252 if (m_valueList->current()->id == CSSValueNone) { | 1237 if (m_valueList->current()->id == CSSValueNone) { |
| 1253 m_valueList->next(); | 1238 m_valueList->next(); |
| 1254 return cssValuePool().createIdentifierValue(CSSValueNone); | 1239 return cssValuePool().createIdentifierValue(CSSValueNone); |
| 1255 } | 1240 } |
| 1256 | 1241 |
| 1257 return parsePositionList(m_valueList); | 1242 return parsePositionList(m_valueList); |
| 1258 } | 1243 } |
| 1259 | 1244 |
| 1260 // [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open
-quote | no-close-quote ]+ | inherit | |
| 1261 // in CSS 2.1 this got somewhat reduced: | |
| 1262 // [ <string> | attr(X) | open-quote | close-quote | no-open-quote | no-close-qu
ote ]+ | inherit | |
| 1263 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseContent() | |
| 1264 { | |
| 1265 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated
(); | |
| 1266 | |
| 1267 while (CSSParserValue* val = m_valueList->current()) { | |
| 1268 RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; | |
| 1269 if (val->m_unit == CSSParserValue::URI) { | |
| 1270 // url | |
| 1271 parsedValue = createCSSImageValueWithReferrer(val->string, m_context
); | |
| 1272 } else if (val->m_unit == CSSParserValue::Function) { | |
| 1273 // attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradie
nt(...) | |
| 1274 CSSParserValueList* args = val->function->args.get(); | |
| 1275 if (!args) | |
| 1276 return nullptr; | |
| 1277 if (val->function->id == CSSValueAttr) { | |
| 1278 parsedValue = parseAttr(args); | |
| 1279 } else if (val->function->id == CSSValueCounter) { | |
| 1280 parsedValue = parseCounterContent(args, false); | |
| 1281 } else if (val->function->id == CSSValueCounters) { | |
| 1282 parsedValue = parseCounterContent(args, true); | |
| 1283 } else if (val->function->id == CSSValueWebkitImageSet) { | |
| 1284 parsedValue = parseImageSet(m_valueList); | |
| 1285 } else if (CSSPropertyParser::isGeneratedImage(val->function->id)) { | |
| 1286 if (!parseGeneratedImage(m_valueList, parsedValue)) | |
| 1287 return nullptr; | |
| 1288 } | |
| 1289 } else if (val->m_unit == CSSParserValue::Identifier) { | |
| 1290 switch (val->id) { | |
| 1291 case CSSValueOpenQuote: | |
| 1292 case CSSValueCloseQuote: | |
| 1293 case CSSValueNoOpenQuote: | |
| 1294 case CSSValueNoCloseQuote: | |
| 1295 case CSSValueNone: | |
| 1296 case CSSValueNormal: | |
| 1297 parsedValue = cssValuePool().createIdentifierValue(val->id); | |
| 1298 default: | |
| 1299 break; | |
| 1300 } | |
| 1301 } else if (val->m_unit == CSSParserValue::String) { | |
| 1302 parsedValue = createPrimitiveStringValue(val); | |
| 1303 } | |
| 1304 if (!parsedValue) | |
| 1305 return nullptr; | |
| 1306 values->append(parsedValue.release()); | |
| 1307 m_valueList->next(); | |
| 1308 } | |
| 1309 | |
| 1310 return values.release(); | |
| 1311 } | |
| 1312 | |
| 1313 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAttr(CSSParserValueList
* args) | |
| 1314 { | |
| 1315 if (args->size() != 1) | |
| 1316 return nullptr; | |
| 1317 | |
| 1318 CSSParserValue* a = args->current(); | |
| 1319 | |
| 1320 if (a->m_unit != CSSParserValue::Identifier) | |
| 1321 return nullptr; | |
| 1322 | |
| 1323 String attrName = a->string; | |
| 1324 // CSS allows identifiers with "-" at the start, like "-webkit-mask-image". | |
| 1325 // But HTML attribute names can't have those characters, and we should not | |
| 1326 // even parse them inside attr(). | |
| 1327 if (attrName[0] == '-') | |
| 1328 return nullptr; | |
| 1329 | |
| 1330 if (m_context.isHTMLDocument()) | |
| 1331 attrName = attrName.lower(); | |
| 1332 | |
| 1333 RefPtrWillBeRawPtr<CSSFunctionValue> attrValue = CSSFunctionValue::create(CS
SValueAttr); | |
| 1334 attrValue->append(CSSCustomIdentValue::create(attrName)); | |
| 1335 return attrValue.release(); | |
| 1336 } | |
| 1337 | |
| 1338 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseColor(const CSSParserVa
lue* value, bool acceptQuirkyColors) | 1245 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseColor(const CSSParserVa
lue* value, bool acceptQuirkyColors) |
| 1339 { | 1246 { |
| 1340 CSSValueID id = value->id; | 1247 CSSValueID id = value->id; |
| 1341 if (isColorKeyword(id)) { | 1248 if (isColorKeyword(id)) { |
| 1342 if (!isValueAllowedInMode(id, m_context.mode())) | 1249 if (!isValueAllowedInMode(id, m_context.mode())) |
| 1343 return nullptr; | 1250 return nullptr; |
| 1344 if (id == CSSValueWebkitText && m_context.useCounter()) | 1251 if (id == CSSValueWebkitText && m_context.useCounter()) |
| 1345 m_context.useCounter()->count(UseCounter::WebkitTextInColorProperty)
; | 1252 m_context.useCounter()->count(UseCounter::WebkitTextInColorProperty)
; |
| 1346 return cssValuePool().createIdentifierValue(id); | 1253 return cssValuePool().createIdentifierValue(id); |
| 1347 } | 1254 } |
| (...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2730 default: | 2637 default: |
| 2731 return parsedValues; | 2638 return parsedValues; |
| 2732 } | 2639 } |
| 2733 parsedValues->append(cssValuePool().createIdentifierValue(value->id)); | 2640 parsedValues->append(cssValuePool().createIdentifierValue(value->id)); |
| 2734 list.next(); | 2641 list.next(); |
| 2735 } | 2642 } |
| 2736 | 2643 |
| 2737 return parsedValues; | 2644 return parsedValues; |
| 2738 } | 2645 } |
| 2739 | 2646 |
| 2740 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseCounterContent(CSSParse
rValueList* args, bool counters) | |
| 2741 { | |
| 2742 unsigned numArgs = args->size(); | |
| 2743 if (counters && numArgs != 3 && numArgs != 5) | |
| 2744 return nullptr; | |
| 2745 if (!counters && numArgs != 1 && numArgs != 3) | |
| 2746 return nullptr; | |
| 2747 | |
| 2748 CSSParserValue* i = args->current(); | |
| 2749 if (i->m_unit != CSSParserValue::Identifier) | |
| 2750 return nullptr; | |
| 2751 RefPtrWillBeRawPtr<CSSCustomIdentValue> identifier = createPrimitiveCustomId
entValue(i); | |
| 2752 | |
| 2753 RefPtrWillBeRawPtr<CSSCustomIdentValue> separator = nullptr; | |
| 2754 if (!counters) | |
| 2755 separator = CSSCustomIdentValue::create(String()); | |
| 2756 else { | |
| 2757 args->next(); | |
| 2758 if (!consumeComma(args)) | |
| 2759 return nullptr; | |
| 2760 | |
| 2761 i = args->current(); | |
| 2762 if (i->m_unit != CSSParserValue::String) | |
| 2763 return nullptr; | |
| 2764 | |
| 2765 separator = createPrimitiveCustomIdentValue(i); | |
| 2766 } | |
| 2767 | |
| 2768 RefPtrWillBeRawPtr<CSSPrimitiveValue> listStyle = nullptr; | |
| 2769 i = args->next(); | |
| 2770 if (!i) // Make the list style default decimal | |
| 2771 listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal); | |
| 2772 else { | |
| 2773 if (!consumeComma(args)) | |
| 2774 return nullptr; | |
| 2775 | |
| 2776 i = args->current(); | |
| 2777 if (i->m_unit != CSSParserValue::Identifier) | |
| 2778 return nullptr; | |
| 2779 | |
| 2780 CSSValueID listStyleID = CSSValueInvalid; | |
| 2781 if (i->id == CSSValueNone || (i->id >= CSSValueDisc && i->id <= CSSValue
KatakanaIroha)) | |
| 2782 listStyleID = i->id; | |
| 2783 else | |
| 2784 return nullptr; | |
| 2785 | |
| 2786 listStyle = cssValuePool().createIdentifierValue(listStyleID); | |
| 2787 } | |
| 2788 | |
| 2789 return CSSCounterValue::create(identifier.release(), listStyle.release(), se
parator.release()); | |
| 2790 } | |
| 2791 | |
| 2792 static void completeBorderRadii(RefPtrWillBeRawPtr<CSSPrimitiveValue> radii[4]) | 2647 static void completeBorderRadii(RefPtrWillBeRawPtr<CSSPrimitiveValue> radii[4]) |
| 2793 { | 2648 { |
| 2794 if (radii[3]) | 2649 if (radii[3]) |
| 2795 return; | 2650 return; |
| 2796 if (!radii[2]) { | 2651 if (!radii[2]) { |
| 2797 if (!radii[1]) | 2652 if (!radii[1]) |
| 2798 radii[1] = radii[0]; | 2653 radii[1] = radii[0]; |
| 2799 radii[2] = radii[0]; | 2654 radii[2] = radii[0]; |
| 2800 } | 2655 } |
| 2801 radii[3] = radii[1]; | 2656 radii[3] = radii[1]; |
| (...skipping 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4926 ASSERT(!m_parsedCalculation); | 4781 ASSERT(!m_parsedCalculation); |
| 4927 m_parsedCalculation = CSSCalcValue::create(args, range); | 4782 m_parsedCalculation = CSSCalcValue::create(args, range); |
| 4928 | 4783 |
| 4929 if (!m_parsedCalculation) | 4784 if (!m_parsedCalculation) |
| 4930 return false; | 4785 return false; |
| 4931 | 4786 |
| 4932 return true; | 4787 return true; |
| 4933 } | 4788 } |
| 4934 | 4789 |
| 4935 } // namespace blink | 4790 } // namespace blink |
| OLD | NEW |