Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/WebKit/Source/core/css/properties/CSSPropertyOffsetPathUtils.cpp

Issue 2898133002: CSS: Use count unitless 0 supplied as <angle> (Closed)
Patch Set: Optional Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/CSSIdentifierValue.h"
8 #include "core/css/CSSPathValue.h" 8 #include "core/css/CSSPathValue.h"
9 #include "core/css/CSSPrimitiveValue.h" 9 #include "core/css/CSSPrimitiveValue.h"
10 #include "core/css/CSSRayValue.h" 10 #include "core/css/CSSRayValue.h"
11 #include "core/css/parser/CSSParserContext.h" 11 #include "core/css/parser/CSSParserContext.h"
12 #include "core/css/parser/CSSPropertyParserHelpers.h" 12 #include "core/css/parser/CSSPropertyParserHelpers.h"
13 #include "core/svg/SVGPathByteStream.h" 13 #include "core/svg/SVGPathByteStream.h"
14 #include "core/svg/SVGPathUtilities.h" 14 #include "core/svg/SVGPathUtilities.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 using namespace CSSPropertyParserHelpers;
19
18 namespace { 20 namespace {
19 21
20 CSSValue* ConsumePath(CSSParserTokenRange& range) { 22 CSSValue* ConsumePath(CSSParserTokenRange& range) {
21 // FIXME: Add support for <url>, <basic-shape>, <geometry-box>. 23 // FIXME: Add support for <url>, <basic-shape>, <geometry-box>.
22 if (range.Peek().FunctionId() != CSSValuePath) 24 if (range.Peek().FunctionId() != CSSValuePath)
23 return nullptr; 25 return nullptr;
24 26
25 CSSParserTokenRange function_range = range; 27 CSSParserTokenRange function_range = range;
26 CSSParserTokenRange function_args = 28 CSSParserTokenRange function_args = ConsumeFunction(function_range);
27 CSSPropertyParserHelpers::ConsumeFunction(function_range);
28 29
29 if (function_args.Peek().GetType() != kStringToken) 30 if (function_args.Peek().GetType() != kStringToken)
30 return nullptr; 31 return nullptr;
31 String path_string = 32 String path_string =
32 function_args.ConsumeIncludingWhitespace().Value().ToString(); 33 function_args.ConsumeIncludingWhitespace().Value().ToString();
33 34
34 std::unique_ptr<SVGPathByteStream> byte_stream = SVGPathByteStream::Create(); 35 std::unique_ptr<SVGPathByteStream> byte_stream = SVGPathByteStream::Create();
35 if (BuildByteStreamFromString(path_string, *byte_stream) != 36 if (BuildByteStreamFromString(path_string, *byte_stream) !=
36 SVGParseStatus::kNoError || 37 SVGParseStatus::kNoError ||
37 !function_args.AtEnd()) { 38 !function_args.AtEnd()) {
38 return nullptr; 39 return nullptr;
39 } 40 }
40 41
41 range = function_range; 42 range = function_range;
42 if (byte_stream->IsEmpty()) 43 if (byte_stream->IsEmpty())
43 return CSSIdentifierValue::Create(CSSValueNone); 44 return CSSIdentifierValue::Create(CSSValueNone);
44 return CSSPathValue::Create(std::move(byte_stream)); 45 return CSSPathValue::Create(std::move(byte_stream));
45 } 46 }
46 47
47 CSSValue* ConsumeRay(CSSParserTokenRange& range) { 48 CSSValue* ConsumeRay(CSSParserTokenRange& range,
49 const CSSParserContext* context) {
48 DCHECK_EQ(range.Peek().FunctionId(), CSSValueRay); 50 DCHECK_EQ(range.Peek().FunctionId(), CSSValueRay);
49 CSSParserTokenRange function_range = range; 51 CSSParserTokenRange function_range = range;
50 CSSParserTokenRange function_args = 52 CSSParserTokenRange function_args = ConsumeFunction(function_range);
51 CSSPropertyParserHelpers::ConsumeFunction(function_range);
52 53
53 CSSPrimitiveValue* angle = nullptr; 54 CSSPrimitiveValue* angle = nullptr;
54 CSSIdentifierValue* size = nullptr; 55 CSSIdentifierValue* size = nullptr;
55 CSSIdentifierValue* contain = nullptr; 56 CSSIdentifierValue* contain = nullptr;
56 while (!function_args.AtEnd()) { 57 while (!function_args.AtEnd()) {
57 if (!angle) { 58 if (!angle) {
58 angle = CSSPropertyParserHelpers::ConsumeAngle(function_args); 59 angle = ConsumeAngle(function_args, *context, UnitlessQuirk::kForbid,
60 WTF::Optional<UseCounter::Feature>());
59 if (angle) 61 if (angle)
60 continue; 62 continue;
61 } 63 }
62 if (!size) { 64 if (!size) {
63 size = CSSPropertyParserHelpers::ConsumeIdent< 65 size = ConsumeIdent<CSSValueClosestSide, CSSValueClosestCorner,
64 CSSValueClosestSide, CSSValueClosestCorner, CSSValueFarthestSide, 66 CSSValueFarthestSide, CSSValueFarthestCorner,
65 CSSValueFarthestCorner, CSSValueSides>(function_args); 67 CSSValueSides>(function_args);
66 if (size) 68 if (size)
67 continue; 69 continue;
68 } 70 }
69 if (RuntimeEnabledFeatures::cssOffsetPathRayContainEnabled() && !contain) { 71 if (RuntimeEnabledFeatures::cssOffsetPathRayContainEnabled() && !contain) {
70 contain = CSSPropertyParserHelpers::ConsumeIdent<CSSValueContain>( 72 contain = ConsumeIdent<CSSValueContain>(function_args);
71 function_args);
72 if (contain) 73 if (contain)
73 continue; 74 continue;
74 } 75 }
75 return nullptr; 76 return nullptr;
76 } 77 }
77 if (!angle || !size) 78 if (!angle || !size)
78 return nullptr; 79 return nullptr;
79 range = function_range; 80 range = function_range;
80 return CSSRayValue::Create(*angle, *size, contain); 81 return CSSRayValue::Create(*angle, *size, contain);
81 } 82 }
82 83
83 } // namespace 84 } // namespace
84 85
85 CSSValue* CSSPropertyOffsetPathUtils::ConsumeOffsetPath( 86 CSSValue* CSSPropertyOffsetPathUtils::ConsumeOffsetPath(
86 CSSParserTokenRange& range, 87 CSSParserTokenRange& range,
87 const CSSParserContext* context) { 88 const CSSParserContext* context) {
88 CSSValue* value = nullptr; 89 CSSValue* value = nullptr;
89 if (RuntimeEnabledFeatures::cssOffsetPathRayEnabled() && 90 if (RuntimeEnabledFeatures::cssOffsetPathRayEnabled() &&
90 range.Peek().FunctionId() == CSSValueRay) 91 range.Peek().FunctionId() == CSSValueRay)
91 value = ConsumeRay(range); 92 value = ConsumeRay(range, context);
92 else 93 else
93 value = ConsumePathOrNone(range); 94 value = ConsumePathOrNone(range);
94 95
95 // Count when we receive a valid path other than 'none'. 96 // Count when we receive a valid path other than 'none'.
96 if (value && !value->IsIdentifierValue()) 97 if (value && !value->IsIdentifierValue())
97 context->Count(UseCounter::kCSSOffsetInEffect); 98 context->Count(UseCounter::kCSSOffsetInEffect);
98 return value; 99 return value;
99 } 100 }
100 101
101 CSSValue* CSSPropertyOffsetPathUtils::ConsumePathOrNone( 102 CSSValue* CSSPropertyOffsetPathUtils::ConsumePathOrNone(
102 CSSParserTokenRange& range) { 103 CSSParserTokenRange& range) {
103 CSSValueID id = range.Peek().Id(); 104 CSSValueID id = range.Peek().Id();
104 if (id == CSSValueNone) 105 if (id == CSSValueNone)
105 return CSSPropertyParserHelpers::ConsumeIdent(range); 106 return ConsumeIdent(range);
106 107
107 return ConsumePath(range); 108 return ConsumePath(range);
108 } 109 }
109 110
110 } // namespace blink 111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698