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 "core/css/parser/CSSPropertyParser.h" | 5 #include "core/css/parser/CSSPropertyParser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
9 #include "core/css/CSSBasicShapeValues.h" | 9 #include "core/css/CSSBasicShapeValues.h" |
10 #include "core/css/CSSContentDistributionValue.h" | 10 #include "core/css/CSSContentDistributionValue.h" |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 context->Count(WebFeature::kUnitlessPerspectiveInPerspectiveProperty); | 800 context->Count(WebFeature::kUnitlessPerspectiveInPerspectiveProperty); |
801 parsed_value = CSSPrimitiveValue::Create( | 801 parsed_value = CSSPrimitiveValue::Create( |
802 perspective, CSSPrimitiveValue::UnitType::kPixels); | 802 perspective, CSSPrimitiveValue::UnitType::kPixels); |
803 } | 803 } |
804 if (parsed_value && | 804 if (parsed_value && |
805 (parsed_value->IsCalculated() || parsed_value->GetDoubleValue() > 0)) | 805 (parsed_value->IsCalculated() || parsed_value->GetDoubleValue() > 0)) |
806 return parsed_value; | 806 return parsed_value; |
807 return nullptr; | 807 return nullptr; |
808 } | 808 } |
809 | 809 |
810 static CSSValue* ConsumeScrollSnapPoints(CSSParserTokenRange& range, | |
811 CSSParserMode css_parser_mode) { | |
812 if (range.Peek().Id() == CSSValueNone) | |
813 return ConsumeIdent(range); | |
814 if (range.Peek().FunctionId() == CSSValueRepeat) { | |
815 CSSParserTokenRange args = ConsumeFunction(range); | |
816 CSSPrimitiveValue* parsed_value = | |
817 ConsumeLengthOrPercent(args, css_parser_mode, kValueRangeNonNegative); | |
818 if (args.AtEnd() && parsed_value && | |
819 (parsed_value->IsCalculated() || parsed_value->GetDoubleValue() > 0)) { | |
820 CSSFunctionValue* result = CSSFunctionValue::Create(CSSValueRepeat); | |
821 result->Append(*parsed_value); | |
822 return result; | |
823 } | |
824 } | |
825 return nullptr; | |
826 } | |
827 | |
828 static CSSValue* ConsumeReflect(CSSParserTokenRange& range, | 810 static CSSValue* ConsumeReflect(CSSParserTokenRange& range, |
829 const CSSParserContext* context) { | 811 const CSSParserContext* context) { |
830 CSSIdentifierValue* direction = | 812 CSSIdentifierValue* direction = |
831 ConsumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>( | 813 ConsumeIdent<CSSValueAbove, CSSValueBelow, CSSValueLeft, CSSValueRight>( |
832 range); | 814 range); |
833 if (!direction) | 815 if (!direction) |
834 return nullptr; | 816 return nullptr; |
835 | 817 |
836 CSSPrimitiveValue* offset = nullptr; | 818 CSSPrimitiveValue* offset = nullptr; |
837 if (range.AtEnd()) { | 819 if (range.AtEnd()) { |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 range_, *context_, UnitlessQuirk::kAllow); | 1509 range_, *context_, UnitlessQuirk::kAllow); |
1528 case CSSPropertyInlineSize: | 1510 case CSSPropertyInlineSize: |
1529 case CSSPropertyBlockSize: | 1511 case CSSPropertyBlockSize: |
1530 case CSSPropertyMinInlineSize: | 1512 case CSSPropertyMinInlineSize: |
1531 case CSSPropertyMinBlockSize: | 1513 case CSSPropertyMinBlockSize: |
1532 case CSSPropertyWebkitMinLogicalWidth: | 1514 case CSSPropertyWebkitMinLogicalWidth: |
1533 case CSSPropertyWebkitMinLogicalHeight: | 1515 case CSSPropertyWebkitMinLogicalHeight: |
1534 case CSSPropertyWebkitLogicalWidth: | 1516 case CSSPropertyWebkitLogicalWidth: |
1535 case CSSPropertyWebkitLogicalHeight: | 1517 case CSSPropertyWebkitLogicalHeight: |
1536 return CSSPropertyLengthUtils::ConsumeWidthOrHeight(range_, *context_); | 1518 return CSSPropertyLengthUtils::ConsumeWidthOrHeight(range_, *context_); |
1537 case CSSPropertyScrollSnapDestination: | |
1538 // TODO(crbug.com/724912): Retire scroll-snap-destination | |
1539 return ConsumePosition(range_, *context_, UnitlessQuirk::kForbid, | |
1540 Optional<WebFeature>()); | |
1541 case CSSPropertyObjectPosition: | 1519 case CSSPropertyObjectPosition: |
1542 return ConsumePosition(range_, *context_, UnitlessQuirk::kForbid, | 1520 return ConsumePosition(range_, *context_, UnitlessQuirk::kForbid, |
1543 WebFeature::kThreeValuedPositionObjectPosition); | 1521 WebFeature::kThreeValuedPositionObjectPosition); |
1544 case CSSPropertyPerspectiveOrigin: | 1522 case CSSPropertyPerspectiveOrigin: |
1545 return ConsumePosition(range_, *context_, UnitlessQuirk::kForbid, | 1523 return ConsumePosition(range_, *context_, UnitlessQuirk::kForbid, |
1546 WebFeature::kThreeValuedPositionPerspectiveOrigin); | 1524 WebFeature::kThreeValuedPositionPerspectiveOrigin); |
1547 case CSSPropertyWebkitHyphenateCharacter: | 1525 case CSSPropertyWebkitHyphenateCharacter: |
1548 case CSSPropertyWebkitLocale: | 1526 case CSSPropertyWebkitLocale: |
1549 return ConsumeLocale(range_); | 1527 return ConsumeLocale(range_); |
1550 case CSSPropertyAnimationDelay: | 1528 case CSSPropertyAnimationDelay: |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 case CSSPropertyCy: | 1625 case CSSPropertyCy: |
1648 case CSSPropertyX: | 1626 case CSSPropertyX: |
1649 case CSSPropertyY: | 1627 case CSSPropertyY: |
1650 case CSSPropertyR: | 1628 case CSSPropertyR: |
1651 return ConsumeLengthOrPercent(range_, kSVGAttributeMode, kValueRangeAll, | 1629 return ConsumeLengthOrPercent(range_, kSVGAttributeMode, kValueRangeAll, |
1652 UnitlessQuirk::kForbid); | 1630 UnitlessQuirk::kForbid); |
1653 case CSSPropertyPerspective: | 1631 case CSSPropertyPerspective: |
1654 return ConsumePerspective( | 1632 return ConsumePerspective( |
1655 range_, context_, | 1633 range_, context_, |
1656 unresolved_property == CSSPropertyAliasWebkitPerspective); | 1634 unresolved_property == CSSPropertyAliasWebkitPerspective); |
1657 case CSSPropertyScrollSnapPointsX: | |
1658 case CSSPropertyScrollSnapPointsY: | |
1659 return ConsumeScrollSnapPoints(range_, context_->Mode()); | |
1660 case CSSPropertyBorderImageRepeat: | 1635 case CSSPropertyBorderImageRepeat: |
1661 case CSSPropertyWebkitMaskBoxImageRepeat: | 1636 case CSSPropertyWebkitMaskBoxImageRepeat: |
1662 return CSSPropertyBorderImageUtils::ConsumeBorderImageRepeat(range_); | 1637 return CSSPropertyBorderImageUtils::ConsumeBorderImageRepeat(range_); |
1663 case CSSPropertyBorderImageSlice: | 1638 case CSSPropertyBorderImageSlice: |
1664 case CSSPropertyWebkitMaskBoxImageSlice: | 1639 case CSSPropertyWebkitMaskBoxImageSlice: |
1665 return CSSPropertyBorderImageUtils::ConsumeBorderImageSlice( | 1640 return CSSPropertyBorderImageUtils::ConsumeBorderImageSlice( |
1666 range_, false /* default_fill */); | 1641 range_, false /* default_fill */); |
1667 case CSSPropertyBorderImageOutset: | 1642 case CSSPropertyBorderImageOutset: |
1668 case CSSPropertyWebkitMaskBoxImageOutset: | 1643 case CSSPropertyWebkitMaskBoxImageOutset: |
1669 return CSSPropertyBorderImageUtils::ConsumeBorderImageOutset(range_); | 1644 return CSSPropertyBorderImageUtils::ConsumeBorderImageOutset(range_); |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2336 | 2311 |
2337 AddExpandedPropertyForValue(CSSPropertyBorderWidth, *width, important); | 2312 AddExpandedPropertyForValue(CSSPropertyBorderWidth, *width, important); |
2338 AddExpandedPropertyForValue(CSSPropertyBorderStyle, *style, important); | 2313 AddExpandedPropertyForValue(CSSPropertyBorderStyle, *style, important); |
2339 AddExpandedPropertyForValue(CSSPropertyBorderColor, *color, important); | 2314 AddExpandedPropertyForValue(CSSPropertyBorderColor, *color, important); |
2340 AddExpandedPropertyForValue(CSSPropertyBorderImage, | 2315 AddExpandedPropertyForValue(CSSPropertyBorderImage, |
2341 *CSSInitialValue::Create(), important); | 2316 *CSSInitialValue::Create(), important); |
2342 | 2317 |
2343 return range_.AtEnd(); | 2318 return range_.AtEnd(); |
2344 } | 2319 } |
2345 | 2320 |
| 2321 bool CSSPropertyParser::Consume2Values(const StylePropertyShorthand& shorthand, |
| 2322 bool important) { |
| 2323 DCHECK_EQ(shorthand.length(), 2u); |
| 2324 const CSSPropertyID* longhands = shorthand.properties(); |
| 2325 const CSSValue* start = ParseSingleValue(longhands[0], shorthand.id()); |
| 2326 if (!start) |
| 2327 return false; |
| 2328 |
| 2329 const CSSValue* end = ParseSingleValue(longhands[1], shorthand.id()); |
| 2330 if (!end) |
| 2331 end = start; |
| 2332 AddParsedProperty(longhands[0], shorthand.id(), *start, important); |
| 2333 AddParsedProperty(longhands[1], shorthand.id(), *end, important); |
| 2334 |
| 2335 return range_.AtEnd(); |
| 2336 } |
| 2337 |
2346 bool CSSPropertyParser::Consume4Values(const StylePropertyShorthand& shorthand, | 2338 bool CSSPropertyParser::Consume4Values(const StylePropertyShorthand& shorthand, |
2347 bool important) { | 2339 bool important) { |
2348 DCHECK_EQ(shorthand.length(), 4u); | 2340 DCHECK_EQ(shorthand.length(), 4u); |
2349 const CSSPropertyID* longhands = shorthand.properties(); | 2341 const CSSPropertyID* longhands = shorthand.properties(); |
2350 const CSSValue* top = ParseSingleValue(longhands[0], shorthand.id()); | 2342 const CSSValue* top = ParseSingleValue(longhands[0], shorthand.id()); |
2351 if (!top) | 2343 if (!top) |
2352 return false; | 2344 return false; |
2353 | 2345 |
2354 const CSSValue* right = ParseSingleValue(longhands[1], shorthand.id()); | 2346 const CSSValue* right = ParseSingleValue(longhands[1], shorthand.id()); |
2355 const CSSValue* bottom = nullptr; | 2347 const CSSValue* bottom = nullptr; |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3279 case CSSPropertyGridTemplate: | 3271 case CSSPropertyGridTemplate: |
3280 return ConsumeGridTemplateShorthand(CSSPropertyGridTemplate, important); | 3272 return ConsumeGridTemplateShorthand(CSSPropertyGridTemplate, important); |
3281 case CSSPropertyGrid: | 3273 case CSSPropertyGrid: |
3282 return ConsumeGridShorthand(important); | 3274 return ConsumeGridShorthand(important); |
3283 case CSSPropertyPlaceContent: | 3275 case CSSPropertyPlaceContent: |
3284 return ConsumePlaceContentShorthand(important); | 3276 return ConsumePlaceContentShorthand(important); |
3285 case CSSPropertyPlaceItems: | 3277 case CSSPropertyPlaceItems: |
3286 return ConsumePlaceItemsShorthand(important); | 3278 return ConsumePlaceItemsShorthand(important); |
3287 case CSSPropertyPlaceSelf: | 3279 case CSSPropertyPlaceSelf: |
3288 return ConsumePlaceSelfShorthand(important); | 3280 return ConsumePlaceSelfShorthand(important); |
| 3281 case CSSPropertyScrollPadding: |
| 3282 return Consume4Values(scrollPaddingShorthand(), important); |
| 3283 case CSSPropertyScrollPaddingBlock: |
| 3284 return Consume2Values(scrollPaddingBlockShorthand(), important); |
| 3285 case CSSPropertyScrollPaddingInline: |
| 3286 return Consume2Values(scrollPaddingInlineShorthand(), important); |
| 3287 case CSSPropertyScrollSnapMargin: |
| 3288 return Consume4Values(scrollSnapMarginShorthand(), important); |
| 3289 case CSSPropertyScrollSnapMarginBlock: |
| 3290 return Consume2Values(scrollSnapMarginBlockShorthand(), important); |
| 3291 case CSSPropertyScrollSnapMarginInline: |
| 3292 return Consume2Values(scrollSnapMarginInlineShorthand(), important); |
3289 default: | 3293 default: |
3290 return false; | 3294 return false; |
3291 } | 3295 } |
3292 } | 3296 } |
3293 | 3297 |
3294 } // namespace blink | 3298 } // namespace blink |
OLD | NEW |