Chromium Code Reviews| 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..a58fb75ff214b0960bc92dfdf0fcd0735d99e97a |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/css/properties/CSSShorthandPropertyAPIFontVariant.cpp |
| @@ -0,0 +1,88 @@ |
| +// 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 { |
| + |
| +class CSSParserContext; |
|
Bugs Nash
2017/06/16 03:51:51
as above, these class declarations are guaranteed
Jia
2017/06/19 03:54:41
Done.
|
| +class CSSParserLocalContext; |
| + |
| +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, |
| + false /* implicit */, properties); |
| + CSSPropertyParserHelpers::AddProperty( |
| + CSSPropertyFontVariantCaps, CSSPropertyFontVariant, |
| + *CSSIdentifierValue::Create(CSSValueNormal), important, |
| + false /* implicit */, 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, false /* implicit */, |
| + properties); |
| + CSSPropertyParserHelpers::AddProperty( |
| + CSSPropertyFontVariantNumeric, CSSPropertyFontVariant, |
| + *numeric_parser.FinalizeValue(), important, false /* implicit */, |
| + properties); |
| + CSSPropertyParserHelpers::AddProperty( |
| + CSSPropertyFontVariantCaps, CSSPropertyFontVariant, |
| + caps_value ? *caps_value : *CSSIdentifierValue::Create(CSSValueNormal), |
| + important, false /* implicit */, properties); |
| + return true; |
| +} |
| +} // namespace blink |