OLD | NEW |
(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/CSSShorthandPropertyAPIFontVariant.h" |
| 6 |
| 7 #include "core/css/CSSIdentifierValue.h" |
| 8 #include "core/css/parser/CSSPropertyParserHelpers.h" |
| 9 #include "core/css/parser/FontVariantLigaturesParser.h" |
| 10 #include "core/css/parser/FontVariantNumericParser.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 bool CSSShorthandPropertyAPIFontVariant::parseShorthand( |
| 15 bool important, |
| 16 CSSParserTokenRange& range, |
| 17 const CSSParserContext&, |
| 18 const CSSParserLocalContext&, |
| 19 HeapVector<CSSProperty, 256>& properties) { |
| 20 if (CSSPropertyParserHelpers::IdentMatches<CSSValueNormal, CSSValueNone>( |
| 21 range.Peek().Id())) { |
| 22 CSSPropertyParserHelpers::AddProperty( |
| 23 CSSPropertyFontVariantLigatures, CSSPropertyFontVariant, |
| 24 *CSSPropertyParserHelpers::ConsumeIdent(range), important, |
| 25 CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, properties); |
| 26 CSSPropertyParserHelpers::AddProperty( |
| 27 CSSPropertyFontVariantCaps, CSSPropertyFontVariant, |
| 28 *CSSIdentifierValue::Create(CSSValueNormal), important, |
| 29 CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, properties); |
| 30 return range.AtEnd(); |
| 31 } |
| 32 |
| 33 CSSIdentifierValue* caps_value = nullptr; |
| 34 FontVariantLigaturesParser ligatures_parser; |
| 35 FontVariantNumericParser numeric_parser; |
| 36 do { |
| 37 FontVariantLigaturesParser::ParseResult ligatures_parse_result = |
| 38 ligatures_parser.ConsumeLigature(range); |
| 39 FontVariantNumericParser::ParseResult numeric_parse_result = |
| 40 numeric_parser.ConsumeNumeric(range); |
| 41 if (ligatures_parse_result == |
| 42 FontVariantLigaturesParser::ParseResult::kConsumedValue || |
| 43 numeric_parse_result == |
| 44 FontVariantNumericParser::ParseResult::kConsumedValue) |
| 45 continue; |
| 46 |
| 47 if (ligatures_parse_result == |
| 48 FontVariantLigaturesParser::ParseResult::kDisallowedValue || |
| 49 numeric_parse_result == |
| 50 FontVariantNumericParser::ParseResult::kDisallowedValue) |
| 51 return false; |
| 52 |
| 53 CSSValueID id = range.Peek().Id(); |
| 54 switch (id) { |
| 55 case CSSValueSmallCaps: |
| 56 case CSSValueAllSmallCaps: |
| 57 case CSSValuePetiteCaps: |
| 58 case CSSValueAllPetiteCaps: |
| 59 case CSSValueUnicase: |
| 60 case CSSValueTitlingCaps: |
| 61 // Only one caps value permitted in font-variant grammar. |
| 62 if (caps_value) |
| 63 return false; |
| 64 caps_value = CSSPropertyParserHelpers::ConsumeIdent(range); |
| 65 break; |
| 66 default: |
| 67 return false; |
| 68 } |
| 69 } while (!range.AtEnd()); |
| 70 |
| 71 CSSPropertyParserHelpers::AddProperty( |
| 72 CSSPropertyFontVariantLigatures, CSSPropertyFontVariant, |
| 73 *ligatures_parser.FinalizeValue(), important, |
| 74 CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, properties); |
| 75 CSSPropertyParserHelpers::AddProperty( |
| 76 CSSPropertyFontVariantNumeric, CSSPropertyFontVariant, |
| 77 *numeric_parser.FinalizeValue(), important, |
| 78 CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, properties); |
| 79 CSSPropertyParserHelpers::AddProperty( |
| 80 CSSPropertyFontVariantCaps, CSSPropertyFontVariant, |
| 81 caps_value ? *caps_value : *CSSIdentifierValue::Create(CSSValueNormal), |
| 82 important, CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit, |
| 83 properties); |
| 84 return true; |
| 85 } |
| 86 } // namespace blink |
OLD | NEW |