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

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

Issue 2816903003: Added CSSPropertyOffsetPathUtils which holds shared parsing logic. (Closed)
Patch Set: rebased Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/css/properties/CSSPropertyOffsetPathUtils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/css/properties/CSSPropertyOffsetPathUtils.cpp
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyOffsetPathUtils.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyOffsetPathUtils.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a6a31a68c4f78e09bd26748259ee097ff92da9f2
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyOffsetPathUtils.cpp
@@ -0,0 +1,72 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/css/properties/CSSPropertyOffsetPathUtils.h"
+
+#include "core/css/CSSPathValue.h"
+#include "core/css/parser/CSSParserContext.h"
+#include "core/css/parser/CSSPropertyParserHelpers.h"
+#include "core/svg/SVGPathByteStream.h"
+#include "core/svg/SVGPathUtilities.h"
+
+namespace blink {
+
+namespace {
+
+CSSValue* ConsumePath(CSSParserTokenRange& range) {
+ // FIXME: Add support for <url>, <basic-shape>, <geometry-box>.
+ if (range.Peek().FunctionId() != CSSValuePath)
+ return nullptr;
+
+ CSSParserTokenRange function_range = range;
+ CSSParserTokenRange function_args =
+ CSSPropertyParserHelpers::ConsumeFunction(function_range);
+
+ if (function_args.Peek().GetType() != kStringToken)
+ return nullptr;
+ String path_string =
+ function_args.ConsumeIncludingWhitespace().Value().ToString();
+
+ std::unique_ptr<SVGPathByteStream> byte_stream = SVGPathByteStream::Create();
+ if (BuildByteStreamFromString(path_string, *byte_stream) !=
+ SVGParseStatus::kNoError ||
+ !function_args.AtEnd()) {
+ return nullptr;
+ }
+
+ range = function_range;
+ if (byte_stream->IsEmpty())
+ return CSSIdentifierValue::Create(CSSValueNone);
+ return CSSPathValue::Create(std::move(byte_stream));
+}
+
+} // namespace
+
+CSSValue* CSSPropertyOffsetPathUtils::ConsumeOffsetPath(
+ CSSParserTokenRange& range,
+ const CSSParserContext* context,
+ bool is_motion_path) {
+ CSSValue* value = ConsumePathOrNone(range);
+
+ // Count when we receive a valid path other than 'none'.
+ if (value && !value->IsIdentifierValue()) {
+ if (is_motion_path) {
+ context->Count(UseCounter::kCSSMotionInEffect);
+ } else {
+ context->Count(UseCounter::kCSSOffsetInEffect);
+ }
+ }
+ return value;
+}
+
+CSSValue* CSSPropertyOffsetPathUtils::ConsumePathOrNone(
+ CSSParserTokenRange& range) {
+ CSSValueID id = range.Peek().Id();
+ if (id == CSSValueNone)
+ return CSSPropertyParserHelpers::ConsumeIdent(range);
+
+ return ConsumePath(range);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/css/properties/CSSPropertyOffsetPathUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698