Chromium Code Reviews| 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" | |
| 11 #include "core/css/CSSValueList.h" | |
| 8 #include "core/css/parser/CSSParserContext.h" | 12 #include "core/css/parser/CSSParserContext.h" |
| 9 #include "core/css/parser/CSSPropertyParserHelpers.h" | 13 #include "core/css/parser/CSSPropertyParserHelpers.h" |
| 10 #include "core/svg/SVGPathByteStream.h" | 14 #include "core/svg/SVGPathByteStream.h" |
| 11 #include "core/svg/SVGPathUtilities.h" | 15 #include "core/svg/SVGPathUtilities.h" |
| 12 | 16 |
| 13 namespace blink { | 17 namespace blink { |
| 14 | 18 |
| 15 namespace { | 19 namespace { |
| 16 | 20 |
| 17 CSSValue* ConsumePath(CSSParserTokenRange& range) { | 21 CSSValue* ConsumePath(CSSParserTokenRange& range) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 34 !function_args.AtEnd()) { | 38 !function_args.AtEnd()) { |
| 35 return nullptr; | 39 return nullptr; |
| 36 } | 40 } |
| 37 | 41 |
| 38 range = function_range; | 42 range = function_range; |
| 39 if (byte_stream->IsEmpty()) | 43 if (byte_stream->IsEmpty()) |
| 40 return CSSIdentifierValue::Create(CSSValueNone); | 44 return CSSIdentifierValue::Create(CSSValueNone); |
| 41 return CSSPathValue::Create(std::move(byte_stream)); | 45 return CSSPathValue::Create(std::move(byte_stream)); |
| 42 } | 46 } |
| 43 | 47 |
| 48 CSSValue* ConsumeRay(CSSParserTokenRange& range) { | |
| 49 DCHECK(range.Peek().FunctionId() == CSSValueRay); | |
| 50 CSSParserTokenRange function_range = range; | |
| 51 CSSParserTokenRange function_args = | |
| 52 CSSPropertyParserHelpers::ConsumeFunction(function_range); | |
| 53 CSSValueList* arguments = CSSValueList::CreateSpaceSeparated(); | |
|
fs
2017/05/15 09:18:14
Rather than constructing a temporary list, could t
Eric Willigers
2017/05/15 10:52:23
Done.
| |
| 54 | |
| 55 CSSPrimitiveValue* angle = nullptr; | |
| 56 CSSIdentifierValue* size = nullptr; | |
| 57 CSSIdentifierValue* contain = nullptr; | |
| 58 while (!function_args.AtEnd()) { | |
| 59 if (!angle && | |
| 60 (angle = CSSPropertyParserHelpers::ConsumeAngle(function_args))) | |
| 61 arguments->Append(*angle); | |
| 62 else if (!size && (size = CSSPropertyParserHelpers::ConsumeIdent< | |
| 63 CSSValueClosestSide, CSSValueClosestCorner, | |
| 64 CSSValueFarthestSide, CSSValueFarthestCorner, | |
| 65 CSSValueSides, CSSValueCover>(function_args))) | |
|
fs
2017/05/15 09:18:14
I didn't see 'cover' in <size>? C'n'P?
Eric Willigers
2017/05/15 10:52:23
Oops. Fixed.
| |
| 66 arguments->Append(*size); | |
| 67 else if (RuntimeEnabledFeatures::cssOffsetPathRayContainEnabled() && | |
| 68 !contain && | |
| 69 (contain = CSSPropertyParserHelpers::ConsumeIdent<CSSValueContain>( | |
| 70 function_args))) | |
| 71 arguments->Append(*contain); | |
| 72 else | |
| 73 return nullptr; | |
| 74 } | |
| 75 if (!angle || !size) | |
| 76 return nullptr; | |
| 77 DCHECK_LE(arguments->length(), 3U); | |
| 78 range = function_range; | |
| 79 return CSSRayValue::Create(arguments); | |
| 80 } | |
| 81 | |
| 44 } // namespace | 82 } // namespace |
| 45 | 83 |
| 46 CSSValue* CSSPropertyOffsetPathUtils::ConsumeOffsetPath( | 84 CSSValue* CSSPropertyOffsetPathUtils::ConsumeOffsetPath( |
| 47 CSSParserTokenRange& range, | 85 CSSParserTokenRange& range, |
| 48 const CSSParserContext* context) { | 86 const CSSParserContext* context) { |
| 49 CSSValue* value = ConsumePathOrNone(range); | 87 CSSValue* value = nullptr; |
| 88 if (RuntimeEnabledFeatures::cssOffsetPathRayEnabled() && | |
| 89 range.Peek().FunctionId() == CSSValueRay) | |
| 90 value = ConsumeRay(range); | |
| 91 else | |
| 92 value = ConsumePathOrNone(range); | |
| 50 | 93 |
| 51 // Count when we receive a valid path other than 'none'. | 94 // Count when we receive a valid path other than 'none'. |
| 52 if (value && !value->IsIdentifierValue()) | 95 if (value && !value->IsIdentifierValue()) |
| 53 context->Count(UseCounter::kCSSOffsetInEffect); | 96 context->Count(UseCounter::kCSSOffsetInEffect); |
| 54 return value; | 97 return value; |
| 55 } | 98 } |
| 56 | 99 |
| 57 CSSValue* CSSPropertyOffsetPathUtils::ConsumePathOrNone( | 100 CSSValue* CSSPropertyOffsetPathUtils::ConsumePathOrNone( |
| 58 CSSParserTokenRange& range) { | 101 CSSParserTokenRange& range) { |
| 59 CSSValueID id = range.Peek().Id(); | 102 CSSValueID id = range.Peek().Id(); |
| 60 if (id == CSSValueNone) | 103 if (id == CSSValueNone) |
| 61 return CSSPropertyParserHelpers::ConsumeIdent(range); | 104 return CSSPropertyParserHelpers::ConsumeIdent(range); |
| 62 | 105 |
| 63 return ConsumePath(range); | 106 return ConsumePath(range); |
| 64 } | 107 } |
| 65 | 108 |
| 66 } // namespace blink | 109 } // namespace blink |
| OLD | NEW |