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

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

Issue 2613723003: Implements CSSPropertyAPI for the font-variation-settings property. (Closed)
Patch Set: rebase Created 3 years, 11 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/parser/CSSPropertyParser.cpp ('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/CSSPropertyAPIFontVariationSettings.cpp
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontVariationSettings.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontVariationSettings.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9097438880bac2e33c5515480d74f617a80dde1d
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIFontVariationSettings.cpp
@@ -0,0 +1,60 @@
+// 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/CSSPropertyAPIFontVariationSettings.h"
+
+#include "core/css/CSSFontVariationValue.h"
+#include "core/css/CSSValueList.h"
+#include "core/css/parser/CSSParserContext.h"
+#include "core/css/parser/CSSPropertyParserHelpers.h"
+#include "platform/RuntimeEnabledFeatures.h"
+
+namespace blink {
+
+namespace {
+
+CSSFontVariationValue* consumeFontVariationTag(CSSParserTokenRange& range) {
+ // Feature tag name consists of 4-letter characters.
+ static const unsigned tagNameLength = 4;
+
+ const CSSParserToken& token = range.consumeIncludingWhitespace();
+ // Feature tag name comes first
+ if (token.type() != StringToken)
+ return nullptr;
+ if (token.value().length() != tagNameLength)
+ return nullptr;
+ AtomicString tag = token.value().toAtomicString();
+ for (unsigned i = 0; i < tagNameLength; ++i) {
+ // Limits the range of characters to 0x20-0x7E, following the tag name rules
+ // defined in the OpenType specification.
+ UChar character = tag[i];
+ if (character < 0x20 || character > 0x7E)
+ return nullptr;
+ }
+
+ double tagValue = 0;
+ if (!CSSPropertyParserHelpers::consumeNumberRaw(range, tagValue))
+ return nullptr;
+ return CSSFontVariationValue::create(tag, clampTo<float>(tagValue));
+}
+
+} // namespace
+
+const CSSValue* CSSPropertyAPIFontVariationSettings::parseSingleValue(
+ CSSParserTokenRange& range,
+ const CSSParserContext& context) {
+ DCHECK(RuntimeEnabledFeatures::cssVariableFontsEnabled());
+ if (range.peek().id() == CSSValueNormal)
+ return CSSPropertyParserHelpers::consumeIdent(range);
+ CSSValueList* variationSettings = CSSValueList::createCommaSeparated();
+ do {
+ CSSFontVariationValue* fontVariationValue = consumeFontVariationTag(range);
+ if (!fontVariationValue)
+ return nullptr;
+ variationSettings->append(*fontVariationValue);
+ } while (CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range));
+ return variationSettings;
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698