1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// 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 "third_party/blink/renderer/core/css/properties/shorthands/font_variant.h"
#include "third_party/blink/renderer/core/css/css_identifier_value.h"
#include "third_party/blink/renderer/core/css/parser/css_property_parser_helpers.h"
#include "third_party/blink/renderer/core/css/parser/font_variant_east_asian_parser.h"
#include "third_party/blink/renderer/core/css/parser/font_variant_ligatures_parser.h"
#include "third_party/blink/renderer/core/css/parser/font_variant_numeric_parser.h"
#include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
namespace blink {
namespace css_shorthand {
bool FontVariant::ParseShorthand(
bool important,
CSSParserTokenRange& range,
const CSSParserContext&,
const CSSParserLocalContext&,
HeapVector<CSSPropertyValue, 256>& properties) const {
if (css_property_parser_helpers::IdentMatches<CSSValueNormal, CSSValueNone>(
range.Peek().Id())) {
css_property_parser_helpers::AddProperty(
CSSPropertyFontVariantLigatures, CSSPropertyFontVariant,
*css_property_parser_helpers::ConsumeIdent(range), important,
css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
properties);
css_property_parser_helpers::AddProperty(
CSSPropertyFontVariantCaps, CSSPropertyFontVariant,
*CSSIdentifierValue::Create(CSSValueNormal), important,
css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
properties);
css_property_parser_helpers::AddProperty(
CSSPropertyFontVariantNumeric, CSSPropertyFontVariant,
*CSSIdentifierValue::Create(CSSValueNormal), important,
css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
properties);
css_property_parser_helpers::AddProperty(
CSSPropertyFontVariantEastAsian, CSSPropertyFontVariant,
*CSSIdentifierValue::Create(CSSValueNormal), important,
css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
properties);
return range.AtEnd();
}
CSSIdentifierValue* caps_value = nullptr;
FontVariantLigaturesParser ligatures_parser;
FontVariantNumericParser numeric_parser;
FontVariantEastAsianParser east_asian_parser;
do {
FontVariantLigaturesParser::ParseResult ligatures_parse_result =
ligatures_parser.ConsumeLigature(range);
FontVariantNumericParser::ParseResult numeric_parse_result =
numeric_parser.ConsumeNumeric(range);
FontVariantEastAsianParser::ParseResult east_asian_parse_result =
east_asian_parser.ConsumeEastAsian(range);
if (ligatures_parse_result ==
FontVariantLigaturesParser::ParseResult::kConsumedValue ||
numeric_parse_result ==
FontVariantNumericParser::ParseResult::kConsumedValue ||
east_asian_parse_result ==
FontVariantEastAsianParser::ParseResult::kConsumedValue)
continue;
if (ligatures_parse_result ==
FontVariantLigaturesParser::ParseResult::kDisallowedValue ||
numeric_parse_result ==
FontVariantNumericParser::ParseResult::kDisallowedValue ||
east_asian_parse_result ==
FontVariantEastAsianParser::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 = css_property_parser_helpers::ConsumeIdent(range);
break;
default:
return false;
}
} while (!range.AtEnd());
css_property_parser_helpers::AddProperty(
CSSPropertyFontVariantLigatures, CSSPropertyFontVariant,
*ligatures_parser.FinalizeValue(), important,
css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
properties);
css_property_parser_helpers::AddProperty(
CSSPropertyFontVariantNumeric, CSSPropertyFontVariant,
*numeric_parser.FinalizeValue(), important,
css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
properties);
css_property_parser_helpers::AddProperty(
CSSPropertyFontVariantEastAsian, CSSPropertyFontVariant,
*east_asian_parser.FinalizeValue(), important,
css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
properties);
css_property_parser_helpers::AddProperty(
CSSPropertyFontVariantCaps, CSSPropertyFontVariant,
caps_value ? *caps_value : *CSSIdentifierValue::Create(CSSValueNormal),
important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
properties);
return true;
}
const CSSValue* FontVariant::CSSValueFromComputedStyleInternal(
const ComputedStyle& style,
const SVGComputedStyle&,
const LayoutObject* layout_object,
Node* styled_node,
bool allow_visited_style) const {
return ComputedStyleUtils::ValuesForFontVariantProperty(
style, layout_object, styled_node, allow_visited_style);
}
} // namespace css_shorthand
} // namespace blink
|