OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/css/parser/CSSPropertyParser.h" | 6 #include "core/css/parser/CSSPropertyParser.h" |
7 | 7 |
8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
9 #include "core/css/CSSCalculationValue.h" | 9 #include "core/css/CSSCalculationValue.h" |
10 #include "core/css/CSSCustomIdentValue.h" | 10 #include "core/css/CSSCustomIdentValue.h" |
11 #include "core/css/CSSFontFaceSrcValue.h" | 11 #include "core/css/CSSFontFaceSrcValue.h" |
12 #include "core/css/CSSFontFeatureValue.h" | 12 #include "core/css/CSSFontFeatureValue.h" |
13 #include "core/css/CSSPrimitiveValueMappings.h" | 13 #include "core/css/CSSPrimitiveValueMappings.h" |
14 #include "core/css/CSSQuadValue.h" | 14 #include "core/css/CSSQuadValue.h" |
15 #include "core/css/CSSShadowValue.h" | |
15 #include "core/css/CSSStringValue.h" | 16 #include "core/css/CSSStringValue.h" |
16 #include "core/css/CSSTimingFunctionValue.h" | 17 #include "core/css/CSSTimingFunctionValue.h" |
17 #include "core/css/CSSURIValue.h" | 18 #include "core/css/CSSURIValue.h" |
18 #include "core/css/CSSUnicodeRangeValue.h" | 19 #include "core/css/CSSUnicodeRangeValue.h" |
19 #include "core/css/CSSValuePair.h" | 20 #include "core/css/CSSValuePair.h" |
20 #include "core/css/CSSValuePool.h" | 21 #include "core/css/CSSValuePool.h" |
21 #include "core/css/FontFace.h" | 22 #include "core/css/FontFace.h" |
22 #include "core/css/parser/CSSParserFastPaths.h" | 23 #include "core/css/parser/CSSParserFastPaths.h" |
23 #include "core/css/parser/CSSParserValues.h" | 24 #include "core/css/parser/CSSParserValues.h" |
24 #include "core/frame/UseCounter.h" | 25 #include "core/frame/UseCounter.h" |
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1325 } | 1326 } |
1326 | 1327 |
1327 static PassRefPtrWillBeRawPtr<CSSValue> consumeWidowsOrOrphans(CSSParserTokenRan ge& range) | 1328 static PassRefPtrWillBeRawPtr<CSSValue> consumeWidowsOrOrphans(CSSParserTokenRan ge& range) |
1328 { | 1329 { |
1329 // Support for auto is non-standard and for backwards compatibility. | 1330 // Support for auto is non-standard and for backwards compatibility. |
1330 if (range.peek().id() == CSSValueAuto) | 1331 if (range.peek().id() == CSSValueAuto) |
1331 return consumeIdent(range); | 1332 return consumeIdent(range); |
1332 return consumePositiveInteger(range); | 1333 return consumePositiveInteger(range); |
1333 } | 1334 } |
1334 | 1335 |
1336 static PassRefPtrWillBeRawPtr<CSSShadowValue> parseSingleShadow(CSSParserTokenRa nge& range, const CSSParserContext& context, bool allowInset, bool allowSpread) | |
1337 { | |
1338 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nullptr; | |
1339 RefPtrWillBeRawPtr<CSSValue> color = nullptr; | |
1340 WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue>, 4> lengths; | |
Timothy Loh
2015/10/29 02:53:27
Probably nicer to just have four separate variable
rwlbuis
2015/10/29 20:48:14
That actually makes the code much more compact, do
| |
1341 | |
1342 if (range.atEnd()) | |
1343 return nullptr; | |
1344 if (range.peek().id() == CSSValueInset) { | |
1345 if (!allowInset) | |
1346 return nullptr; | |
1347 style = consumeIdent(range); | |
1348 } | |
1349 color = consumeColor(range, context); | |
1350 | |
1351 RefPtrWillBeRawPtr<CSSPrimitiveValue> length = consumeLength(range, context. mode(), ValueRangeAll); | |
1352 if (!length) | |
1353 return nullptr; | |
1354 lengths.append(length.release()); | |
1355 | |
1356 length = consumeLength(range, context.mode(), ValueRangeAll); | |
1357 if (!length) | |
1358 return nullptr; | |
1359 lengths.append(length.release()); | |
1360 | |
1361 length = consumeLength(range, context.mode(), ValueRangeAll); | |
1362 if (length) { | |
1363 // Blur radius must be non-negative. | |
1364 if (length->getDoubleValue() < 0) | |
1365 return nullptr; | |
1366 lengths.append(length.release()); | |
1367 length = consumeLength(range, context.mode(), ValueRangeAll); | |
1368 if (length) { | |
1369 if (!allowSpread) | |
Timothy Loh
2015/10/29 02:53:26
I think it makes more sense to not try and consume
rwlbuis
2015/10/29 20:48:14
Done.
| |
1370 return nullptr; | |
1371 lengths.append(length.release()); | |
1372 } | |
1373 } | |
1374 | |
1375 if (!range.atEnd()) { | |
1376 if (RefPtrWillBeRawPtr<CSSValue> colorValue = consumeColor(range, contex t)) { | |
Timothy Loh
2015/10/29 02:53:27
Can't we write:
if (!color)
color = consumeCol
rwlbuis
2015/10/29 20:48:14
Done.
| |
1377 if (color) | |
1378 return nullptr; | |
1379 color = colorValue; | |
1380 } | |
1381 if (range.peek().id() == CSSValueInset) { | |
1382 if (!allowInset || style) | |
1383 return nullptr; | |
1384 style = consumeIdent(range); | |
1385 } | |
1386 } | |
1387 unsigned lengthsSeen = lengths.size(); | |
1388 return CSSShadowValue::create(lengths.at(0), lengths.at(1), lengthsSeen > 2 ? lengths.at(2) : nullptr, | |
1389 lengthsSeen > 3 ? lengths.at(3) : nullptr, style.release(), color.releas e()); | |
1390 } | |
1391 | |
1392 static PassRefPtrWillBeRawPtr<CSSValue> consumeShadow(CSSParserTokenRange& range , const CSSParserContext& context, bool isBoxShadowProperty) | |
1393 { | |
1394 if (range.peek().id() == CSSValueNone) | |
1395 return consumeIdent(range); | |
1396 | |
1397 RefPtrWillBeRawPtr<CSSValueList> shadowValueList = CSSValueList::createComma Separated(); | |
1398 do { | |
1399 if (RefPtrWillBeRawPtr<CSSShadowValue> shadowValue = parseSingleShadow(r ange, context, isBoxShadowProperty, isBoxShadowProperty)) | |
Timothy Loh
2015/10/29 02:53:26
Doesn't this allow extraneous commas everywhere?
t
rwlbuis
2015/10/29 20:48:14
Ouch! Fixed now.
I noticed box-shadow-interpolatio
| |
1400 shadowValueList->append(shadowValue.release()); | |
1401 } while (consumeCommaIncludingWhitespace(range)); | |
1402 if (shadowValueList->length() == 0) | |
1403 return nullptr; | |
1404 return shadowValueList; | |
1405 } | |
1406 | |
1335 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) | 1407 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) |
1336 { | 1408 { |
1337 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 1409 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
1338 m_range.consumeWhitespace(); | 1410 m_range.consumeWhitespace(); |
1339 switch (property) { | 1411 switch (property) { |
1340 case CSSPropertyWillChange: | 1412 case CSSPropertyWillChange: |
1341 return consumeWillChange(m_range); | 1413 return consumeWillChange(m_range); |
1342 case CSSPropertyPage: | 1414 case CSSPropertyPage: |
1343 return consumePage(m_range); | 1415 return consumePage(m_range); |
1344 case CSSPropertyQuotes: | 1416 case CSSPropertyQuotes: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1427 case CSSPropertyTransitionTimingFunction: | 1499 case CSSPropertyTransitionTimingFunction: |
1428 return consumeAnimationPropertyList(property, m_range, m_context, unreso lvedProperty == CSSPropertyAliasWebkitAnimationName); | 1500 return consumeAnimationPropertyList(property, m_range, m_context, unreso lvedProperty == CSSPropertyAliasWebkitAnimationName); |
1429 case CSSPropertyOrphans: | 1501 case CSSPropertyOrphans: |
1430 case CSSPropertyWidows: | 1502 case CSSPropertyWidows: |
1431 return consumeWidowsOrOrphans(m_range); | 1503 return consumeWidowsOrOrphans(m_range); |
1432 case CSSPropertyWebkitTextFillColor: | 1504 case CSSPropertyWebkitTextFillColor: |
1433 case CSSPropertyWebkitTapHighlightColor: | 1505 case CSSPropertyWebkitTapHighlightColor: |
1434 return consumeColor(m_range, m_context); | 1506 return consumeColor(m_range, m_context); |
1435 case CSSPropertyColor: | 1507 case CSSPropertyColor: |
1436 return consumeColor(m_range, m_context, inQuirksMode()); | 1508 return consumeColor(m_range, m_context, inQuirksMode()); |
1509 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS 3, so treat as CSS3 | |
1510 case CSSPropertyBoxShadow: | |
1511 return consumeShadow(m_range, m_context, property == CSSPropertyBoxShado w); | |
1437 default: | 1512 default: |
1438 return nullptr; | 1513 return nullptr; |
1439 } | 1514 } |
1440 } | 1515 } |
1441 | 1516 |
1442 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 1517 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
1443 { | 1518 { |
1444 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 1519 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
1445 | 1520 |
1446 do { | 1521 do { |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1857 m_currentShorthand = oldShorthand; | 1932 m_currentShorthand = oldShorthand; |
1858 return consumeColumns(important); | 1933 return consumeColumns(important); |
1859 } | 1934 } |
1860 default: | 1935 default: |
1861 m_currentShorthand = oldShorthand; | 1936 m_currentShorthand = oldShorthand; |
1862 return false; | 1937 return false; |
1863 } | 1938 } |
1864 } | 1939 } |
1865 | 1940 |
1866 } // namespace blink | 1941 } // namespace blink |
OLD | NEW |