Index: third_party/WebKit/Source/core/css/properties/CSSShorthandPropertyAPIFontVariant.cpp |
diff --git a/third_party/WebKit/Source/core/css/properties/CSSShorthandPropertyAPIFontVariant.cpp b/third_party/WebKit/Source/core/css/properties/CSSShorthandPropertyAPIFontVariant.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e49f40123cdf75b876bdd0334530affe59684f94 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/css/properties/CSSShorthandPropertyAPIFontVariant.cpp |
@@ -0,0 +1,86 @@ |
+// 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/CSSShorthandPropertyAPIFontVariant.h" |
+ |
+#include "core/css/CSSIdentifierValue.h" |
+#include "core/css/parser/CSSPropertyParserHelpers.h" |
+#include "core/css/parser/FontVariantLigaturesParser.h" |
+#include "core/css/parser/FontVariantNumericParser.h" |
+ |
+namespace blink { |
+ |
+bool CSSShorthandPropertyAPIFontVariant::parseShorthand( |
+ bool important, |
+ CSSParserTokenRange& range, |
+ const CSSParserContext&, |
+ const CSSParserLocalContext&, |
+ HeapVector<CSSProperty, 256>& properties) { |
+ if (CSSPropertyParserHelpers::IdentMatches<CSSValueNormal, CSSValueNone>( |
+ range.Peek().Id())) { |
+ CSSPropertyParserHelpers::AddProperty( |
+ CSSPropertyFontVariantLigatures, CSSPropertyFontVariant, |
+ *CSSPropertyParserHelpers::ConsumeIdent(range), important, |
+ CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, properties); |
+ CSSPropertyParserHelpers::AddProperty( |
+ CSSPropertyFontVariantCaps, CSSPropertyFontVariant, |
+ *CSSIdentifierValue::Create(CSSValueNormal), important, |
+ CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, properties); |
+ return range.AtEnd(); |
+ } |
+ |
+ CSSIdentifierValue* caps_value = nullptr; |
+ FontVariantLigaturesParser ligatures_parser; |
+ FontVariantNumericParser numeric_parser; |
+ do { |
+ FontVariantLigaturesParser::ParseResult ligatures_parse_result = |
+ ligatures_parser.ConsumeLigature(range); |
+ FontVariantNumericParser::ParseResult numeric_parse_result = |
+ numeric_parser.ConsumeNumeric(range); |
+ if (ligatures_parse_result == |
+ FontVariantLigaturesParser::ParseResult::kConsumedValue || |
+ numeric_parse_result == |
+ FontVariantNumericParser::ParseResult::kConsumedValue) |
+ continue; |
+ |
+ if (ligatures_parse_result == |
+ FontVariantLigaturesParser::ParseResult::kDisallowedValue || |
+ numeric_parse_result == |
+ FontVariantNumericParser::ParseResult::kDisallowedValue) |
+ return false; |
+ |
+ CSSValueID id = range.Peek().Id(); |
+ switch (id) { |
+ case CSSValueSmallCaps: |
+ case CSSValueAllSmallCaps: |
+ case CSSValuePetiteCaps: |
+ case CSSValueAllPetiteCaps: |
+ case CSSValueUnicase: |
+ case CSSValueTitlingCaps: |
+ // Only one caps value permitted in font-variant grammar. |
+ if (caps_value) |
+ return false; |
+ caps_value = CSSPropertyParserHelpers::ConsumeIdent(range); |
+ break; |
+ default: |
+ return false; |
+ } |
+ } while (!range.AtEnd()); |
+ |
+ CSSPropertyParserHelpers::AddProperty( |
+ CSSPropertyFontVariantLigatures, CSSPropertyFontVariant, |
+ *ligatures_parser.FinalizeValue(), important, |
+ CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, properties); |
+ CSSPropertyParserHelpers::AddProperty( |
+ CSSPropertyFontVariantNumeric, CSSPropertyFontVariant, |
+ *numeric_parser.FinalizeValue(), important, |
+ CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, properties); |
+ CSSPropertyParserHelpers::AddProperty( |
+ CSSPropertyFontVariantCaps, CSSPropertyFontVariant, |
+ caps_value ? *caps_value : *CSSIdentifierValue::Create(CSSValueNormal), |
+ important, CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, |
+ properties); |
+ return true; |
+} |
+} // namespace blink |