| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/properties/CSSPropertyOffsetPathUtils.h" | 5 #include "core/css/properties/CSSPropertyOffsetPathUtils.h" |
| 6 | 6 |
| 7 #include "core/css/CSSIdentifierValue.h" |
| 7 #include "core/css/CSSPathValue.h" | 8 #include "core/css/CSSPathValue.h" |
| 9 #include "core/css/CSSPrimitiveValue.h" |
| 10 #include "core/css/CSSRayValue.h" |
| 8 #include "core/css/parser/CSSParserContext.h" | 11 #include "core/css/parser/CSSParserContext.h" |
| 9 #include "core/css/parser/CSSPropertyParserHelpers.h" | 12 #include "core/css/parser/CSSPropertyParserHelpers.h" |
| 10 #include "core/svg/SVGPathByteStream.h" | 13 #include "core/svg/SVGPathByteStream.h" |
| 11 #include "core/svg/SVGPathUtilities.h" | 14 #include "core/svg/SVGPathUtilities.h" |
| 12 | 15 |
| 13 namespace blink { | 16 namespace blink { |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 CSSValue* ConsumePath(CSSParserTokenRange& range) { | 20 CSSValue* ConsumePath(CSSParserTokenRange& range) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 34 !function_args.AtEnd()) { | 37 !function_args.AtEnd()) { |
| 35 return nullptr; | 38 return nullptr; |
| 36 } | 39 } |
| 37 | 40 |
| 38 range = function_range; | 41 range = function_range; |
| 39 if (byte_stream->IsEmpty()) | 42 if (byte_stream->IsEmpty()) |
| 40 return CSSIdentifierValue::Create(CSSValueNone); | 43 return CSSIdentifierValue::Create(CSSValueNone); |
| 41 return CSSPathValue::Create(std::move(byte_stream)); | 44 return CSSPathValue::Create(std::move(byte_stream)); |
| 42 } | 45 } |
| 43 | 46 |
| 47 CSSValue* ConsumeRay(CSSParserTokenRange& range) { |
| 48 DCHECK_EQ(range.Peek().FunctionId(), CSSValueRay); |
| 49 CSSParserTokenRange function_range = range; |
| 50 CSSParserTokenRange function_args = |
| 51 CSSPropertyParserHelpers::ConsumeFunction(function_range); |
| 52 |
| 53 CSSPrimitiveValue* angle = nullptr; |
| 54 CSSIdentifierValue* size = nullptr; |
| 55 CSSIdentifierValue* contain = nullptr; |
| 56 while (!function_args.AtEnd()) { |
| 57 if (!angle) { |
| 58 angle = CSSPropertyParserHelpers::ConsumeAngle(function_args); |
| 59 if (angle) |
| 60 continue; |
| 61 } |
| 62 if (!size) { |
| 63 size = CSSPropertyParserHelpers::ConsumeIdent< |
| 64 CSSValueClosestSide, CSSValueClosestCorner, CSSValueFarthestSide, |
| 65 CSSValueFarthestCorner, CSSValueSides>(function_args); |
| 66 if (size) |
| 67 continue; |
| 68 } |
| 69 if (RuntimeEnabledFeatures::cssOffsetPathRayContainEnabled() && !contain) { |
| 70 contain = CSSPropertyParserHelpers::ConsumeIdent<CSSValueContain>( |
| 71 function_args); |
| 72 if (contain) |
| 73 continue; |
| 74 } |
| 75 return nullptr; |
| 76 } |
| 77 if (!angle || !size) |
| 78 return nullptr; |
| 79 range = function_range; |
| 80 return CSSRayValue::Create(*angle, *size, contain); |
| 81 } |
| 82 |
| 44 } // namespace | 83 } // namespace |
| 45 | 84 |
| 46 CSSValue* CSSPropertyOffsetPathUtils::ConsumeOffsetPath( | 85 CSSValue* CSSPropertyOffsetPathUtils::ConsumeOffsetPath( |
| 47 CSSParserTokenRange& range, | 86 CSSParserTokenRange& range, |
| 48 const CSSParserContext* context) { | 87 const CSSParserContext* context) { |
| 49 CSSValue* value = ConsumePathOrNone(range); | 88 CSSValue* value = nullptr; |
| 89 if (RuntimeEnabledFeatures::cssOffsetPathRayEnabled() && |
| 90 range.Peek().FunctionId() == CSSValueRay) |
| 91 value = ConsumeRay(range); |
| 92 else |
| 93 value = ConsumePathOrNone(range); |
| 50 | 94 |
| 51 // Count when we receive a valid path other than 'none'. | 95 // Count when we receive a valid path other than 'none'. |
| 52 if (value && !value->IsIdentifierValue()) | 96 if (value && !value->IsIdentifierValue()) |
| 53 context->Count(UseCounter::kCSSOffsetInEffect); | 97 context->Count(UseCounter::kCSSOffsetInEffect); |
| 54 return value; | 98 return value; |
| 55 } | 99 } |
| 56 | 100 |
| 57 CSSValue* CSSPropertyOffsetPathUtils::ConsumePathOrNone( | 101 CSSValue* CSSPropertyOffsetPathUtils::ConsumePathOrNone( |
| 58 CSSParserTokenRange& range) { | 102 CSSParserTokenRange& range) { |
| 59 CSSValueID id = range.Peek().Id(); | 103 CSSValueID id = range.Peek().Id(); |
| 60 if (id == CSSValueNone) | 104 if (id == CSSValueNone) |
| 61 return CSSPropertyParserHelpers::ConsumeIdent(range); | 105 return CSSPropertyParserHelpers::ConsumeIdent(range); |
| 62 | 106 |
| 63 return ConsumePath(range); | 107 return ConsumePath(range); |
| 64 } | 108 } |
| 65 | 109 |
| 66 } // namespace blink | 110 } // namespace blink |
| OLD | NEW |