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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/CSSPropertyAPIFontVariationSettings.h"
6
7 #include "core/css/CSSFontVariationValue.h"
8 #include "core/css/CSSValueList.h"
9 #include "core/css/parser/CSSParserContext.h"
10 #include "core/css/parser/CSSPropertyParserHelpers.h"
11 #include "platform/RuntimeEnabledFeatures.h"
12
13 namespace blink {
14
15 namespace {
16
17 CSSFontVariationValue* consumeFontVariationTag(CSSParserTokenRange& range) {
18 // Feature tag name consists of 4-letter characters.
19 static const unsigned tagNameLength = 4;
20
21 const CSSParserToken& token = range.consumeIncludingWhitespace();
22 // Feature tag name comes first
23 if (token.type() != StringToken)
24 return nullptr;
25 if (token.value().length() != tagNameLength)
26 return nullptr;
27 AtomicString tag = token.value().toAtomicString();
28 for (unsigned i = 0; i < tagNameLength; ++i) {
29 // Limits the range of characters to 0x20-0x7E, following the tag name rules
30 // defined in the OpenType specification.
31 UChar character = tag[i];
32 if (character < 0x20 || character > 0x7E)
33 return nullptr;
34 }
35
36 double tagValue = 0;
37 if (!CSSPropertyParserHelpers::consumeNumberRaw(range, tagValue))
38 return nullptr;
39 return CSSFontVariationValue::create(tag, clampTo<float>(tagValue));
40 }
41
42 } // namespace
43
44 const CSSValue* CSSPropertyAPIFontVariationSettings::parseSingleValue(
45 CSSParserTokenRange& range,
46 const CSSParserContext& context) {
47 DCHECK(RuntimeEnabledFeatures::cssVariableFontsEnabled());
48 if (range.peek().id() == CSSValueNormal)
49 return CSSPropertyParserHelpers::consumeIdent(range);
50 CSSValueList* variationSettings = CSSValueList::createCommaSeparated();
51 do {
52 CSSFontVariationValue* fontVariationValue = consumeFontVariationTag(range);
53 if (!fontVariationValue)
54 return nullptr;
55 variationSettings->append(*fontVariationValue);
56 } while (CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range));
57 return variationSettings;
58 }
59
60 } // namespace blink
OLDNEW
« 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