| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/css/properties/CSSPropertyOffsetPathUtils.h" |
| 6 |
| 7 #include "core/css/CSSPathValue.h" |
| 8 #include "core/css/parser/CSSParserContext.h" |
| 9 #include "core/css/parser/CSSPropertyParserHelpers.h" |
| 10 #include "core/svg/SVGPathByteStream.h" |
| 11 #include "core/svg/SVGPathUtilities.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 namespace { |
| 16 |
| 17 CSSValue* ConsumePath(CSSParserTokenRange& range) { |
| 18 // FIXME: Add support for <url>, <basic-shape>, <geometry-box>. |
| 19 if (range.Peek().FunctionId() != CSSValuePath) |
| 20 return nullptr; |
| 21 |
| 22 CSSParserTokenRange function_range = range; |
| 23 CSSParserTokenRange function_args = |
| 24 CSSPropertyParserHelpers::ConsumeFunction(function_range); |
| 25 |
| 26 if (function_args.Peek().GetType() != kStringToken) |
| 27 return nullptr; |
| 28 String path_string = |
| 29 function_args.ConsumeIncludingWhitespace().Value().ToString(); |
| 30 |
| 31 std::unique_ptr<SVGPathByteStream> byte_stream = SVGPathByteStream::Create(); |
| 32 if (BuildByteStreamFromString(path_string, *byte_stream) != |
| 33 SVGParseStatus::kNoError || |
| 34 !function_args.AtEnd()) { |
| 35 return nullptr; |
| 36 } |
| 37 |
| 38 range = function_range; |
| 39 if (byte_stream->IsEmpty()) |
| 40 return CSSIdentifierValue::Create(CSSValueNone); |
| 41 return CSSPathValue::Create(std::move(byte_stream)); |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 46 CSSValue* CSSPropertyOffsetPathUtils::ConsumeOffsetPath( |
| 47 CSSParserTokenRange& range, |
| 48 const CSSParserContext* context, |
| 49 bool is_motion_path) { |
| 50 CSSValue* value = ConsumePathOrNone(range); |
| 51 |
| 52 // Count when we receive a valid path other than 'none'. |
| 53 if (value && !value->IsIdentifierValue()) { |
| 54 if (is_motion_path) { |
| 55 context->Count(UseCounter::kCSSMotionInEffect); |
| 56 } else { |
| 57 context->Count(UseCounter::kCSSOffsetInEffect); |
| 58 } |
| 59 } |
| 60 return value; |
| 61 } |
| 62 |
| 63 CSSValue* CSSPropertyOffsetPathUtils::ConsumePathOrNone( |
| 64 CSSParserTokenRange& range) { |
| 65 CSSValueID id = range.Peek().Id(); |
| 66 if (id == CSSValueNone) |
| 67 return CSSPropertyParserHelpers::ConsumeIdent(range); |
| 68 |
| 69 return ConsumePath(range); |
| 70 } |
| 71 |
| 72 } // namespace blink |
| OLD | NEW |