| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "core/css/CSSPropertyMetadata.h" | 42 #include "core/css/CSSPropertyMetadata.h" |
| 43 #include "core/css/CSSQuadValue.h" | 43 #include "core/css/CSSQuadValue.h" |
| 44 #include "core/css/CSSReflectValue.h" | 44 #include "core/css/CSSReflectValue.h" |
| 45 #include "core/css/CSSShadowValue.h" | 45 #include "core/css/CSSShadowValue.h" |
| 46 #include "core/css/CSSStringValue.h" | 46 #include "core/css/CSSStringValue.h" |
| 47 #include "core/css/CSSTimingFunctionValue.h" | 47 #include "core/css/CSSTimingFunctionValue.h" |
| 48 #include "core/css/CSSURIValue.h" | 48 #include "core/css/CSSURIValue.h" |
| 49 #include "core/css/CSSValuePair.h" | 49 #include "core/css/CSSValuePair.h" |
| 50 #include "core/css/CSSValuePool.h" | 50 #include "core/css/CSSValuePool.h" |
| 51 #include "core/css/CSSVariableReferenceValue.h" | 51 #include "core/css/CSSVariableReferenceValue.h" |
| 52 #include "core/css/HashTools.h" | |
| 53 #include "core/css/parser/CSSParserFastPaths.h" | 52 #include "core/css/parser/CSSParserFastPaths.h" |
| 54 #include "core/css/parser/CSSParserValues.h" | 53 #include "core/css/parser/CSSParserValues.h" |
| 55 #include "core/frame/UseCounter.h" | 54 #include "core/frame/UseCounter.h" |
| 56 #include "core/style/GridCoordinate.h" | 55 #include "core/style/GridCoordinate.h" |
| 57 #include "platform/RuntimeEnabledFeatures.h" | 56 #include "platform/RuntimeEnabledFeatures.h" |
| 58 | 57 |
| 59 namespace blink { | 58 namespace blink { |
| 60 | 59 |
| 61 template <unsigned N> | 60 template <unsigned N> |
| 62 static bool equalIgnoringCase(const CSSParserString& a, const char (&b)[N]) | 61 static bool equalIgnoringCase(const CSSParserString& a, const char (&b)[N]) |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 valueList->next(); | 266 valueList->next(); |
| 268 return true; | 267 return true; |
| 269 } | 268 } |
| 270 | 269 |
| 271 static inline bool isForwardSlashOperator(CSSParserValue* value) | 270 static inline bool isForwardSlashOperator(CSSParserValue* value) |
| 272 { | 271 { |
| 273 ASSERT(value); | 272 ASSERT(value); |
| 274 return value->m_unit == CSSParserValue::Operator && value->iValue == '/'; | 273 return value->m_unit == CSSParserValue::Operator && value->iValue == '/'; |
| 275 } | 274 } |
| 276 | 275 |
| 277 static bool isGeneratedImageValue(CSSValueID id) | |
| 278 { | |
| 279 return id == CSSValueLinearGradient || id == CSSValueRadialGradient | |
| 280 || id == CSSValueRepeatingLinearGradient || id == CSSValueRepeatingRadia
lGradient | |
| 281 || id == CSSValueWebkitLinearGradient || id == CSSValueWebkitRadialGradi
ent | |
| 282 || id == CSSValueWebkitRepeatingLinearGradient || id == CSSValueWebkitRe
peatingRadialGradient | |
| 283 || id == CSSValueWebkitGradient || id == CSSValueWebkitCrossFade; | |
| 284 } | |
| 285 | |
| 286 inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseValidPr
imitive(CSSValueID identifier, CSSParserValue* value) | 276 inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseValidPr
imitive(CSSValueID identifier, CSSParserValue* value) |
| 287 { | 277 { |
| 288 if (identifier) | 278 if (identifier) |
| 289 return cssValuePool().createIdentifierValue(identifier); | 279 return cssValuePool().createIdentifierValue(identifier); |
| 290 if (value->unit() >= CSSPrimitiveValue::UnitType::Number && value->unit() <=
CSSPrimitiveValue::UnitType::Kilohertz) | 280 if (value->unit() >= CSSPrimitiveValue::UnitType::Number && value->unit() <=
CSSPrimitiveValue::UnitType::Kilohertz) |
| 291 return createPrimitiveNumericValue(value); | 281 return createPrimitiveNumericValue(value); |
| 292 if (value->unit() >= CSSPrimitiveValue::UnitType::Turns && value->unit() <=
CSSPrimitiveValue::UnitType::Chs) | 282 if (value->unit() >= CSSPrimitiveValue::UnitType::Turns && value->unit() <=
CSSPrimitiveValue::UnitType::Chs) |
| 293 return createPrimitiveNumericValue(value); | 283 return createPrimitiveNumericValue(value); |
| 294 if (value->unit() >= CSSPrimitiveValue::UnitType::ViewportWidth && value->un
it() <= CSSPrimitiveValue::UnitType::ViewportMax) | 284 if (value->unit() >= CSSPrimitiveValue::UnitType::ViewportWidth && value->un
it() <= CSSPrimitiveValue::UnitType::ViewportMax) |
| 295 return createPrimitiveNumericValue(value); | 285 return createPrimitiveNumericValue(value); |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 if (!args) | 1287 if (!args) |
| 1298 return nullptr; | 1288 return nullptr; |
| 1299 if (val->function->id == CSSValueAttr) { | 1289 if (val->function->id == CSSValueAttr) { |
| 1300 parsedValue = parseAttr(args); | 1290 parsedValue = parseAttr(args); |
| 1301 } else if (val->function->id == CSSValueCounter) { | 1291 } else if (val->function->id == CSSValueCounter) { |
| 1302 parsedValue = parseCounterContent(args, false); | 1292 parsedValue = parseCounterContent(args, false); |
| 1303 } else if (val->function->id == CSSValueCounters) { | 1293 } else if (val->function->id == CSSValueCounters) { |
| 1304 parsedValue = parseCounterContent(args, true); | 1294 parsedValue = parseCounterContent(args, true); |
| 1305 } else if (val->function->id == CSSValueWebkitImageSet) { | 1295 } else if (val->function->id == CSSValueWebkitImageSet) { |
| 1306 parsedValue = parseImageSet(m_valueList); | 1296 parsedValue = parseImageSet(m_valueList); |
| 1307 } else if (isGeneratedImageValue(val->function->id)) { | 1297 } else if (CSSPropertyParser::isGeneratedImage(val->function->id)) { |
| 1308 if (!parseGeneratedImage(m_valueList, parsedValue)) | 1298 if (!parseGeneratedImage(m_valueList, parsedValue)) |
| 1309 return nullptr; | 1299 return nullptr; |
| 1310 } | 1300 } |
| 1311 } else if (val->m_unit == CSSParserValue::Identifier) { | 1301 } else if (val->m_unit == CSSParserValue::Identifier) { |
| 1312 switch (val->id) { | 1302 switch (val->id) { |
| 1313 case CSSValueOpenQuote: | 1303 case CSSValueOpenQuote: |
| 1314 case CSSValueCloseQuote: | 1304 case CSSValueCloseQuote: |
| 1315 case CSSValueNoOpenQuote: | 1305 case CSSValueNoOpenQuote: |
| 1316 case CSSValueNoCloseQuote: | 1306 case CSSValueNoCloseQuote: |
| 1317 case CSSValueNone: | 1307 case CSSValueNone: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 return nullptr; | 1340 return nullptr; |
| 1351 | 1341 |
| 1352 if (m_context.isHTMLDocument()) | 1342 if (m_context.isHTMLDocument()) |
| 1353 attrName = attrName.lower(); | 1343 attrName = attrName.lower(); |
| 1354 | 1344 |
| 1355 RefPtrWillBeRawPtr<CSSFunctionValue> attrValue = CSSFunctionValue::create(CS
SValueAttr); | 1345 RefPtrWillBeRawPtr<CSSFunctionValue> attrValue = CSSFunctionValue::create(CS
SValueAttr); |
| 1356 attrValue->append(CSSCustomIdentValue::create(attrName)); | 1346 attrValue->append(CSSCustomIdentValue::create(attrName)); |
| 1357 return attrValue.release(); | 1347 return attrValue.release(); |
| 1358 } | 1348 } |
| 1359 | 1349 |
| 1360 bool CSSPropertyParser::isColorKeyword(CSSValueID id) | |
| 1361 { | |
| 1362 // Named colors and color keywords: | |
| 1363 // | |
| 1364 // <named-color> | |
| 1365 // 'aqua', 'black', 'blue', ..., 'yellow' (CSS3: "basic color keywords") | |
| 1366 // 'aliceblue', ..., 'yellowgreen' (CSS3: "extended color keywords"
) | |
| 1367 // 'transparent' | |
| 1368 // | |
| 1369 // 'currentcolor' | |
| 1370 // | |
| 1371 // <deprecated-system-color> | |
| 1372 // 'ActiveBorder', ..., 'WindowText' | |
| 1373 // | |
| 1374 // WebKit proprietary/internal: | |
| 1375 // '-webkit-link' | |
| 1376 // '-webkit-activelink' | |
| 1377 // '-internal-active-list-box-selection' | |
| 1378 // '-internal-active-list-box-selection-text' | |
| 1379 // '-internal-inactive-list-box-selection' | |
| 1380 // '-internal-inactive-list-box-selection-text' | |
| 1381 // '-webkit-focus-ring-color' | |
| 1382 // '-webkit-text' | |
| 1383 // | |
| 1384 return (id >= CSSValueAqua && id <= CSSValueWebkitText) | |
| 1385 || (id >= CSSValueAliceblue && id <= CSSValueYellowgreen) | |
| 1386 || id == CSSValueMenu; | |
| 1387 } | |
| 1388 | |
| 1389 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseColor(const CSSParserVa
lue* value, bool acceptQuirkyColors) | 1350 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseColor(const CSSParserVa
lue* value, bool acceptQuirkyColors) |
| 1390 { | 1351 { |
| 1391 CSSValueID id = value->id; | 1352 CSSValueID id = value->id; |
| 1392 if (isColorKeyword(id)) { | 1353 if (isColorKeyword(id)) { |
| 1393 if (!isValueAllowedInMode(id, m_context.mode())) | 1354 if (!isValueAllowedInMode(id, m_context.mode())) |
| 1394 return nullptr; | 1355 return nullptr; |
| 1395 if (id == CSSValueWebkitText && m_context.useCounter()) | 1356 if (id == CSSValueWebkitText && m_context.useCounter()) |
| 1396 m_context.useCounter()->count(UseCounter::WebkitTextInColorProperty)
; | 1357 m_context.useCounter()->count(UseCounter::WebkitTextInColorProperty)
; |
| 1397 return cssValuePool().createIdentifierValue(id); | 1358 return cssValuePool().createIdentifierValue(id); |
| 1398 } | 1359 } |
| 1399 RGBA32 c = Color::transparent; | 1360 RGBA32 c = Color::transparent; |
| 1400 if (!parseColorFromValue(value, c, acceptQuirkyColors)) | 1361 if (!parseColorFromValue(value, c, acceptQuirkyColors)) |
| 1401 return nullptr; | 1362 return nullptr; |
| 1402 return cssValuePool().createColorValue(c); | 1363 return cssValuePool().createColorValue(c); |
| 1403 } | 1364 } |
| 1404 | 1365 |
| 1405 bool CSSPropertyParser::parseFillImage(CSSParserValueList* valueList, RefPtrWill
BeRawPtr<CSSValue>& value) | 1366 bool CSSPropertyParser::parseFillImage(CSSParserValueList* valueList, RefPtrWill
BeRawPtr<CSSValue>& value) |
| 1406 { | 1367 { |
| 1407 if (valueList->current()->id == CSSValueNone) { | 1368 if (valueList->current()->id == CSSValueNone) { |
| 1408 value = cssValuePool().createIdentifierValue(CSSValueNone); | 1369 value = cssValuePool().createIdentifierValue(CSSValueNone); |
| 1409 return true; | 1370 return true; |
| 1410 } | 1371 } |
| 1411 if (valueList->current()->m_unit == CSSParserValue::URI) { | 1372 if (valueList->current()->m_unit == CSSParserValue::URI) { |
| 1412 value = createCSSImageValueWithReferrer(valueList->current()->string, m_
context); | 1373 value = createCSSImageValueWithReferrer(valueList->current()->string, m_
context); |
| 1413 return true; | 1374 return true; |
| 1414 } | 1375 } |
| 1415 | 1376 |
| 1416 if (valueList->current()->m_unit == CSSParserValue::Function) { | 1377 if (valueList->current()->m_unit == CSSParserValue::Function) { |
| 1417 if (isGeneratedImageValue(valueList->current()->function->id)) | 1378 if (CSSPropertyParser::isGeneratedImage(valueList->current()->function->
id)) |
| 1418 return parseGeneratedImage(valueList, value); | 1379 return parseGeneratedImage(valueList, value); |
| 1419 | 1380 |
| 1420 if (valueList->current()->function->id == CSSValueWebkitImageSet) { | 1381 if (valueList->current()->function->id == CSSValueWebkitImageSet) { |
| 1421 value = parseImageSet(m_valueList); | 1382 value = parseImageSet(m_valueList); |
| 1422 if (value) | 1383 if (value) |
| 1423 return true; | 1384 return true; |
| 1424 } | 1385 } |
| 1425 } | 1386 } |
| 1426 | 1387 |
| 1427 return false; | 1388 return false; |
| (...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3747 while (CSSParserValue* val = m_valueList->current()) { | 3708 while (CSSParserValue* val = m_valueList->current()) { |
| 3748 context.setCanAdvance(false); | 3709 context.setCanAdvance(false); |
| 3749 | 3710 |
| 3750 if (!context.canAdvance() && context.allowForwardSlashOperator() && isFo
rwardSlashOperator(val)) | 3711 if (!context.canAdvance() && context.allowForwardSlashOperator() && isFo
rwardSlashOperator(val)) |
| 3751 context.commitForwardSlashOperator(); | 3712 context.commitForwardSlashOperator(); |
| 3752 | 3713 |
| 3753 if (!context.canAdvance() && context.allowImage()) { | 3714 if (!context.canAdvance() && context.allowImage()) { |
| 3754 if (val->m_unit == CSSParserValue::URI) { | 3715 if (val->m_unit == CSSParserValue::URI) { |
| 3755 context.commitImage(createCSSImageValueWithReferrer(val->string,
m_context)); | 3716 context.commitImage(createCSSImageValueWithReferrer(val->string,
m_context)); |
| 3756 } else if (val->m_unit == CSSParserValue::Function) { | 3717 } else if (val->m_unit == CSSParserValue::Function) { |
| 3757 if (isGeneratedImageValue(val->function->id)) { | 3718 if (CSSPropertyParser::isGeneratedImage(val->function->id)) { |
| 3758 RefPtrWillBeRawPtr<CSSValue> value = nullptr; | 3719 RefPtrWillBeRawPtr<CSSValue> value = nullptr; |
| 3759 if (parseGeneratedImage(m_valueList, value)) | 3720 if (parseGeneratedImage(m_valueList, value)) |
| 3760 context.commitImage(value.release()); | 3721 context.commitImage(value.release()); |
| 3761 else | 3722 else |
| 3762 return false; | 3723 return false; |
| 3763 } else if (val->function->id == CSSValueWebkitImageSet) { | 3724 } else if (val->function->id == CSSValueWebkitImageSet) { |
| 3764 RefPtrWillBeRawPtr<CSSValue> value = parseImageSet(m_valueLi
st); | 3725 RefPtrWillBeRawPtr<CSSValue> value = parseImageSet(m_valueLi
st); |
| 3765 if (value) | 3726 if (value) |
| 3766 context.commitImage(value.release()); | 3727 context.commitImage(value.release()); |
| 3767 else | 3728 else |
| (...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4976 | 4937 |
| 4977 ASSERT(!m_parsedCalculation); | 4938 ASSERT(!m_parsedCalculation); |
| 4978 m_parsedCalculation = CSSCalcValue::create(args, range); | 4939 m_parsedCalculation = CSSCalcValue::create(args, range); |
| 4979 | 4940 |
| 4980 if (!m_parsedCalculation) | 4941 if (!m_parsedCalculation) |
| 4981 return false; | 4942 return false; |
| 4982 | 4943 |
| 4983 return true; | 4944 return true; |
| 4984 } | 4945 } |
| 4985 | 4946 |
| 4986 template <typename CharacterType> | |
| 4987 static CSSPropertyID unresolvedCSSPropertyID(const CharacterType* propertyName,
unsigned length) | |
| 4988 { | |
| 4989 char buffer[maxCSSPropertyNameLength + 1]; // 1 for null character | |
| 4990 | |
| 4991 for (unsigned i = 0; i != length; ++i) { | |
| 4992 CharacterType c = propertyName[i]; | |
| 4993 if (c == 0 || c >= 0x7F) | |
| 4994 return CSSPropertyInvalid; // illegal character | |
| 4995 buffer[i] = toASCIILower(c); | |
| 4996 } | |
| 4997 buffer[length] = '\0'; | |
| 4998 | |
| 4999 const char* name = buffer; | |
| 5000 const Property* hashTableEntry = findProperty(name, length); | |
| 5001 if (!hashTableEntry) | |
| 5002 return CSSPropertyInvalid; | |
| 5003 CSSPropertyID property = static_cast<CSSPropertyID>(hashTableEntry->id); | |
| 5004 if (!CSSPropertyMetadata::isEnabledProperty(property)) | |
| 5005 return CSSPropertyInvalid; | |
| 5006 return property; | |
| 5007 } | |
| 5008 | |
| 5009 CSSPropertyID unresolvedCSSPropertyID(const String& string) | |
| 5010 { | |
| 5011 unsigned length = string.length(); | |
| 5012 | |
| 5013 if (!length) | |
| 5014 return CSSPropertyInvalid; | |
| 5015 if (length > maxCSSPropertyNameLength) | |
| 5016 return CSSPropertyInvalid; | |
| 5017 | |
| 5018 return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), lengt
h) : unresolvedCSSPropertyID(string.characters16(), length); | |
| 5019 } | |
| 5020 | |
| 5021 CSSPropertyID unresolvedCSSPropertyID(const CSSParserString& string) | |
| 5022 { | |
| 5023 unsigned length = string.length(); | |
| 5024 | |
| 5025 if (!length) | |
| 5026 return CSSPropertyInvalid; | |
| 5027 if (length > maxCSSPropertyNameLength) | |
| 5028 return CSSPropertyInvalid; | |
| 5029 | |
| 5030 return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), lengt
h) : unresolvedCSSPropertyID(string.characters16(), length); | |
| 5031 } | |
| 5032 | |
| 5033 template <typename CharacterType> | |
| 5034 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned
length) | |
| 5035 { | |
| 5036 char buffer[maxCSSValueKeywordLength + 1]; // 1 for null character | |
| 5037 | |
| 5038 for (unsigned i = 0; i != length; ++i) { | |
| 5039 CharacterType c = valueKeyword[i]; | |
| 5040 if (c == 0 || c >= 0x7F) | |
| 5041 return CSSValueInvalid; // illegal character | |
| 5042 buffer[i] = WTF::toASCIILower(c); | |
| 5043 } | |
| 5044 buffer[length] = '\0'; | |
| 5045 | |
| 5046 const Value* hashTableEntry = findValue(buffer, length); | |
| 5047 return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSVal
ueInvalid; | |
| 5048 } | |
| 5049 | |
| 5050 CSSValueID cssValueKeywordID(const CSSParserString& string) | |
| 5051 { | |
| 5052 unsigned length = string.length(); | |
| 5053 if (!length) | |
| 5054 return CSSValueInvalid; | |
| 5055 if (length > maxCSSValueKeywordLength) | |
| 5056 return CSSValueInvalid; | |
| 5057 | |
| 5058 return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : c
ssValueKeywordID(string.characters16(), length); | |
| 5059 } | |
| 5060 | |
| 5061 bool CSSPropertyParser::isSystemColor(CSSValueID id) | |
| 5062 { | |
| 5063 return (id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSS
ValueMenu; | |
| 5064 } | |
| 5065 | |
| 5066 } // namespace blink | 4947 } // namespace blink |
| OLD | NEW |