1 // Copyright 2019 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 "third_party/blink/renderer/core/css/basic_shape_functions.h"
6 #include "third_party/blink/renderer/core/css/css_axis_value.h"
7 #include "third_party/blink/renderer/core/css/css_color_value.h"
8 #include "third_party/blink/renderer/core/css/css_counter_value.h"
9 #include "third_party/blink/renderer/core/css/css_cursor_image_value.h"
10 #include "third_party/blink/renderer/core/css/css_custom_ident_value.h"
11 #include "third_party/blink/renderer/core/css/css_font_feature_value.h"
12 #include "third_party/blink/renderer/core/css/css_font_variation_value.h"
13 #include "third_party/blink/renderer/core/css/css_function_value.h"
14 #include "third_party/blink/renderer/core/css/css_grid_template_areas_value.h"
15 #include "third_party/blink/renderer/core/css/css_identifier_value.h"
16 #include "third_party/blink/renderer/core/css/css_layout_function_value.h"
17 #include "third_party/blink/renderer/core/css/css_numeric_literal_value.h"
18 #include "third_party/blink/renderer/core/css/css_primitive_value.h"
19 #include "third_party/blink/renderer/core/css/css_primitive_value_mappings.h"
20 #include "third_party/blink/renderer/core/css/css_quad_value.h"
21 #include "third_party/blink/renderer/core/css/css_reflect_value.h"
22 #include "third_party/blink/renderer/core/css/css_resolution_units.h"
23 #include "third_party/blink/renderer/core/css/css_string_value.h"
24 #include "third_party/blink/renderer/core/css/css_uri_value.h"
25 #include "third_party/blink/renderer/core/css/css_value_list.h"
26 #include "third_party/blink/renderer/core/css/css_value_pair.h"
27 #include "third_party/blink/renderer/core/css/parser/css_parser_context.h"
28 #include "third_party/blink/renderer/core/css/parser/css_parser_local_context.h"
29 #include "third_party/blink/renderer/core/css/parser/css_parser_mode.h"
30 #include "third_party/blink/renderer/core/css/parser/css_parser_token.h"
31 #include "third_party/blink/renderer/core/css/parser/css_parser_token_range.h"
32 #include "third_party/blink/renderer/core/css/parser/css_property_parser.h"
33 #include "third_party/blink/renderer/core/css/parser/css_property_parser_helpers.h"
34 #include "third_party/blink/renderer/core/css/parser/font_variant_east_asian_parser.h"
35 #include "third_party/blink/renderer/core/css/parser/font_variant_ligatures_parser.h"
36 #include "third_party/blink/renderer/core/css/parser/font_variant_numeric_parser.h"
37 #include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
38 #include "third_party/blink/renderer/core/css/properties/css_parsing_utils.h"
39 #include "third_party/blink/renderer/core/css/properties/longhands.h"
40 #include "third_party/blink/renderer/core/css/resolver/style_builder_converter.h"
41 #include "third_party/blink/renderer/core/css/resolver/style_resolver_state.h"
42 #include "third_party/blink/renderer/core/css/style_engine.h"
43 #include "third_party/blink/renderer/core/css/zoom_adjusted_pixel_value.h"
44 #include "third_party/blink/renderer/core/css_value_keywords.h"
45 #include "third_party/blink/renderer/core/frame/settings.h"
46 #include "third_party/blink/renderer/core/frame/web_feature.h"
47 #include "third_party/blink/renderer/core/layout/layout_box.h"
48 #include "third_party/blink/renderer/core/layout/layout_object.h"
49 #include "third_party/blink/renderer/core/style/computed_style.h"
50 #include "third_party/blink/renderer/core/style/grid_area.h"
51 #include "third_party/blink/renderer/core/style/reference_clip_path_operation.h"
52 #include "third_party/blink/renderer/core/style/shape_clip_path_operation.h"
53 #include "third_party/blink/renderer/core/style_property_shorthand.h"
54 #include "third_party/blink/renderer/platform/geometry/length.h"
55 #include "third_party/blink/renderer/platform/heap/heap.h"
56 #include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
57 #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
58 
59 // Implementations of methods in Longhand subclasses that aren't generated.
60 
61 namespace blink {
62 namespace css_longhand {
63 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const64 const CSSValue* AlignContent::ParseSingleValue(
65     CSSParserTokenRange& range,
66     const CSSParserContext& context,
67     const CSSParserLocalContext&) const {
68   return css_parsing_utils::ConsumeContentDistributionOverflowPosition(
69       range, css_parsing_utils::IsContentPositionKeyword);
70 }
71 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const72 const CSSValue* AlignContent::CSSValueFromComputedStyleInternal(
73     const ComputedStyle& style,
74     const SVGComputedStyle&,
75     const LayoutObject*,
76     bool allow_visited_style) const {
77   return ComputedStyleUtils::
78       ValueForContentPositionAndDistributionWithOverflowAlignment(
79           style.AlignContent());
80 }
81 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const82 const CSSValue* AlignItems::ParseSingleValue(
83     CSSParserTokenRange& range,
84     const CSSParserContext& context,
85     const CSSParserLocalContext&) const {
86   // align-items property does not allow the 'auto' value.
87   if (css_property_parser_helpers::IdentMatches<CSSValueID::kAuto>(
88           range.Peek().Id()))
89     return nullptr;
90   return css_parsing_utils::ConsumeSelfPositionOverflowPosition(
91       range, css_parsing_utils::IsSelfPositionKeyword);
92 }
93 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const94 const CSSValue* AlignItems::CSSValueFromComputedStyleInternal(
95     const ComputedStyle& style,
96     const SVGComputedStyle&,
97     const LayoutObject*,
98     bool allow_visited_style) const {
99   return ComputedStyleUtils::ValueForItemPositionWithOverflowAlignment(
100       style.AlignItems());
101 }
102 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const103 const CSSValue* AlignSelf::ParseSingleValue(
104     CSSParserTokenRange& range,
105     const CSSParserContext& context,
106     const CSSParserLocalContext&) const {
107   return css_parsing_utils::ConsumeSelfPositionOverflowPosition(
108       range, css_parsing_utils::IsSelfPositionKeyword);
109 }
110 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const111 const CSSValue* AlignSelf::CSSValueFromComputedStyleInternal(
112     const ComputedStyle& style,
113     const SVGComputedStyle&,
114     const LayoutObject*,
115     bool allow_visited_style) const {
116   return ComputedStyleUtils::ValueForItemPositionWithOverflowAlignment(
117       style.AlignSelf());
118 }
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const119 const CSSValue* AlignmentBaseline::CSSValueFromComputedStyleInternal(
120     const ComputedStyle& style,
121     const SVGComputedStyle& svg_style,
122     const LayoutObject*,
123     bool allow_visited_style) const {
124   return CSSIdentifierValue::Create(svg_style.AlignmentBaseline());
125 }
126 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const127 const CSSValue* AnimationDelay::ParseSingleValue(
128     CSSParserTokenRange& range,
129     const CSSParserContext& context,
130     const CSSParserLocalContext&) const {
131   return css_property_parser_helpers::ConsumeCommaSeparatedList(
132       css_property_parser_helpers::ConsumeTime, range, context, kValueRangeAll);
133 }
134 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const135 const CSSValue* AnimationDelay::CSSValueFromComputedStyleInternal(
136     const ComputedStyle& style,
137     const SVGComputedStyle&,
138     const LayoutObject*,
139     bool allow_visited_style) const {
140   return ComputedStyleUtils::ValueForAnimationDelay(style.Animations());
141 }
142 
InitialValue() const143 const CSSValue* AnimationDelay::InitialValue() const {
144   DEFINE_STATIC_LOCAL(
145       const Persistent<CSSValue>, value,
146       (CSSNumericLiteralValue::Create(CSSTimingData::InitialDelay(),
147                                       CSSPrimitiveValue::UnitType::kSeconds)));
148   return value;
149 }
150 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const151 const CSSValue* AnimationDirection::ParseSingleValue(
152     CSSParserTokenRange& range,
153     const CSSParserContext&,
154     const CSSParserLocalContext&) const {
155   return css_property_parser_helpers::ConsumeCommaSeparatedList(
156       css_property_parser_helpers::ConsumeIdent<
157           CSSValueID::kNormal, CSSValueID::kAlternate, CSSValueID::kReverse,
158           CSSValueID::kAlternateReverse>,
159       range);
160 }
161 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const162 const CSSValue* AnimationDirection::CSSValueFromComputedStyleInternal(
163     const ComputedStyle& style,
164     const SVGComputedStyle&,
165     const LayoutObject*,
166     bool allow_visited_style) const {
167   CSSValueList* list = CSSValueList::CreateCommaSeparated();
168   const CSSAnimationData* animation_data = style.Animations();
169   if (animation_data) {
170     for (wtf_size_t i = 0; i < animation_data->DirectionList().size(); ++i) {
171       list->Append(*ComputedStyleUtils::ValueForAnimationDirection(
172           animation_data->DirectionList()[i]));
173     }
174   } else {
175     list->Append(*InitialValue());
176   }
177   return list;
178 }
179 
InitialValue() const180 const CSSValue* AnimationDirection::InitialValue() const {
181   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
182                       (CSSIdentifierValue::Create(CSSValueID::kNormal)));
183   return value;
184 }
185 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const186 const CSSValue* AnimationDuration::ParseSingleValue(
187     CSSParserTokenRange& range,
188     const CSSParserContext& context,
189     const CSSParserLocalContext&) const {
190   return css_property_parser_helpers::ConsumeCommaSeparatedList(
191       css_property_parser_helpers::ConsumeTime, range, context,
192       kValueRangeNonNegative);
193 }
194 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const195 const CSSValue* AnimationDuration::CSSValueFromComputedStyleInternal(
196     const ComputedStyle& style,
197     const SVGComputedStyle&,
198     const LayoutObject*,
199     bool allow_visited_style) const {
200   return ComputedStyleUtils::ValueForAnimationDuration(style.Animations());
201 }
202 
InitialValue() const203 const CSSValue* AnimationDuration::InitialValue() const {
204   DEFINE_STATIC_LOCAL(
205       const Persistent<CSSValue>, value,
206       (CSSNumericLiteralValue::Create(CSSTimingData::InitialDuration(),
207                                       CSSPrimitiveValue::UnitType::kSeconds)));
208   return value;
209 }
210 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const211 const CSSValue* AnimationFillMode::ParseSingleValue(
212     CSSParserTokenRange& range,
213     const CSSParserContext&,
214     const CSSParserLocalContext&) const {
215   return css_property_parser_helpers::ConsumeCommaSeparatedList(
216       css_property_parser_helpers::ConsumeIdent<
217           CSSValueID::kNone, CSSValueID::kForwards, CSSValueID::kBackwards,
218           CSSValueID::kBoth>,
219       range);
220 }
221 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const222 const CSSValue* AnimationFillMode::CSSValueFromComputedStyleInternal(
223     const ComputedStyle& style,
224     const SVGComputedStyle&,
225     const LayoutObject*,
226     bool allow_visited_style) const {
227   CSSValueList* list = CSSValueList::CreateCommaSeparated();
228   const CSSAnimationData* animation_data = style.Animations();
229   if (animation_data) {
230     for (wtf_size_t i = 0; i < animation_data->FillModeList().size(); ++i) {
231       list->Append(*ComputedStyleUtils::ValueForAnimationFillMode(
232           animation_data->FillModeList()[i]));
233     }
234   } else {
235     list->Append(*InitialValue());
236   }
237   return list;
238 }
239 
InitialValue() const240 const CSSValue* AnimationFillMode::InitialValue() const {
241   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
242                       (CSSIdentifierValue::Create(CSSValueID::kNone)));
243   return value;
244 }
245 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const246 const CSSValue* AnimationIterationCount::ParseSingleValue(
247     CSSParserTokenRange& range,
248     const CSSParserContext& context,
249     const CSSParserLocalContext&) const {
250   return css_property_parser_helpers::ConsumeCommaSeparatedList(
251       css_parsing_utils::ConsumeAnimationIterationCount, range, context);
252 }
253 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const254 const CSSValue* AnimationIterationCount::CSSValueFromComputedStyleInternal(
255     const ComputedStyle& style,
256     const SVGComputedStyle&,
257     const LayoutObject*,
258     bool allow_visited_style) const {
259   CSSValueList* list = CSSValueList::CreateCommaSeparated();
260   const CSSAnimationData* animation_data = style.Animations();
261   if (animation_data) {
262     for (wtf_size_t i = 0; i < animation_data->IterationCountList().size();
263          ++i) {
264       list->Append(*ComputedStyleUtils::ValueForAnimationIterationCount(
265           animation_data->IterationCountList()[i]));
266     }
267   } else {
268     list->Append(*InitialValue());
269   }
270   return list;
271 }
272 
InitialValue() const273 const CSSValue* AnimationIterationCount::InitialValue() const {
274   DEFINE_STATIC_LOCAL(
275       const Persistent<CSSValue>, value,
276       (CSSNumericLiteralValue::Create(CSSAnimationData::InitialIterationCount(),
277                                       CSSPrimitiveValue::UnitType::kNumber)));
278   return value;
279 }
280 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const281 const CSSValue* AnimationName::ParseSingleValue(
282     CSSParserTokenRange& range,
283     const CSSParserContext& context,
284     const CSSParserLocalContext& local_context) const {
285   // Allow quoted name if this is an alias property.
286   return css_property_parser_helpers::ConsumeCommaSeparatedList(
287       css_parsing_utils::ConsumeAnimationName, range, context,
288       local_context.UseAliasParsing());
289 }
290 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const291 const CSSValue* AnimationName::CSSValueFromComputedStyleInternal(
292     const ComputedStyle& style,
293     const SVGComputedStyle&,
294     const LayoutObject*,
295     bool allow_visited_style) const {
296   CSSValueList* list = CSSValueList::CreateCommaSeparated();
297   const CSSAnimationData* animation_data = style.Animations();
298   if (animation_data) {
299     for (wtf_size_t i = 0; i < animation_data->NameList().size(); ++i) {
300       list->Append(*MakeGarbageCollected<CSSCustomIdentValue>(
301           animation_data->NameList()[i]));
302     }
303   } else {
304     list->Append(*InitialValue());
305   }
306   return list;
307 }
308 
InitialValue() const309 const CSSValue* AnimationName::InitialValue() const {
310   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
311                       (CSSIdentifierValue::Create(CSSValueID::kNone)));
312   return value;
313 }
314 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const315 const CSSValue* AnimationPlayState::ParseSingleValue(
316     CSSParserTokenRange& range,
317     const CSSParserContext&,
318     const CSSParserLocalContext&) const {
319   return css_property_parser_helpers::ConsumeCommaSeparatedList(
320       css_property_parser_helpers::ConsumeIdent<CSSValueID::kRunning,
321                                                 CSSValueID::kPaused>,
322       range);
323 }
324 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const325 const CSSValue* AnimationPlayState::CSSValueFromComputedStyleInternal(
326     const ComputedStyle& style,
327     const SVGComputedStyle&,
328     const LayoutObject*,
329     bool allow_visited_style) const {
330   CSSValueList* list = CSSValueList::CreateCommaSeparated();
331   const CSSAnimationData* animation_data = style.Animations();
332   if (animation_data) {
333     for (wtf_size_t i = 0; i < animation_data->PlayStateList().size(); ++i) {
334       list->Append(*ComputedStyleUtils::ValueForAnimationPlayState(
335           animation_data->PlayStateList()[i]));
336     }
337   } else {
338     list->Append(*InitialValue());
339   }
340   return list;
341 }
342 
InitialValue() const343 const CSSValue* AnimationPlayState::InitialValue() const {
344   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
345                       (CSSIdentifierValue::Create(CSSValueID::kRunning)));
346   return value;
347 }
348 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const349 const CSSValue* AnimationTimingFunction::ParseSingleValue(
350     CSSParserTokenRange& range,
351     const CSSParserContext& context,
352     const CSSParserLocalContext&) const {
353   return css_property_parser_helpers::ConsumeCommaSeparatedList(
354       css_parsing_utils::ConsumeAnimationTimingFunction, range, context);
355 }
356 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const357 const CSSValue* AnimationTimingFunction::CSSValueFromComputedStyleInternal(
358     const ComputedStyle& style,
359     const SVGComputedStyle&,
360     const LayoutObject*,
361     bool allow_visited_style) const {
362   return ComputedStyleUtils::ValueForAnimationTimingFunction(
363       style.Animations());
364 }
365 
InitialValue() const366 const CSSValue* AnimationTimingFunction::InitialValue() const {
367   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
368                       (CSSIdentifierValue::Create(CSSValueID::kEase)));
369   return value;
370 }
371 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const372 const CSSValue* AspectRatio::ParseSingleValue(
373     CSSParserTokenRange& range,
374     const CSSParserContext& context,
375     const CSSParserLocalContext&) const {
376   if (range.Peek().Id() == CSSValueID::kAuto)
377     return css_property_parser_helpers::ConsumeIdent(range);
378   CSSValue* width =
379       css_property_parser_helpers::ConsumePositiveInteger(range, context);
380   if (!width)
381     return nullptr;
382   if (!css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range))
383     return nullptr;
384   CSSValue* height =
385       css_property_parser_helpers::ConsumePositiveInteger(range, context);
386   if (!height)
387     return nullptr;
388   CSSValueList* list = CSSValueList::CreateSlashSeparated();
389   list->Append(*width);
390   list->Append(*height);
391   return list;
392 }
393 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const394 const CSSValue* AspectRatio::CSSValueFromComputedStyleInternal(
395     const ComputedStyle& style,
396     const SVGComputedStyle&,
397     const LayoutObject* layout_object,
398     bool allow_visited_style) const {
399   auto& ratio = style.AspectRatio();
400   if (!ratio.has_value())
401     return CSSIdentifierValue::Create(CSSValueID::kAuto);
402 
403   CSSValueList* list = CSSValueList::CreateSlashSeparated();
404   list->Append(*CSSNumericLiteralValue::Create(
405       ratio->Width(), CSSPrimitiveValue::UnitType::kInteger));
406   list->Append(*CSSNumericLiteralValue::Create(
407       ratio->Height(), CSSPrimitiveValue::UnitType::kInteger));
408   return list;
409 }
410 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const411 const CSSValue* BackdropFilter::ParseSingleValue(
412     CSSParserTokenRange& range,
413     const CSSParserContext& context,
414     const CSSParserLocalContext&) const {
415   return css_property_parser_helpers::ConsumeFilterFunctionList(range, context);
416 }
417 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const418 const CSSValue* BackdropFilter::CSSValueFromComputedStyleInternal(
419     const ComputedStyle& style,
420     const SVGComputedStyle&,
421     const LayoutObject*,
422     bool allow_visited_style) const {
423   return ComputedStyleUtils::ValueForFilter(style, style.BackdropFilter());
424 }
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const425 const CSSValue* BackfaceVisibility::CSSValueFromComputedStyleInternal(
426     const ComputedStyle& style,
427     const SVGComputedStyle&,
428     const LayoutObject*,
429     bool allow_visited_style) const {
430   return CSSIdentifierValue::Create(
431       (style.BackfaceVisibility() == EBackfaceVisibility::kHidden)
432           ? CSSValueID::kHidden
433           : CSSValueID::kVisible);
434 }
435 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const436 const CSSValue* BackgroundAttachment::ParseSingleValue(
437     CSSParserTokenRange& range,
438     const CSSParserContext&,
439     const CSSParserLocalContext&) const {
440   return css_property_parser_helpers::ConsumeCommaSeparatedList(
441       css_parsing_utils::ConsumeBackgroundAttachment, range);
442 }
443 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const444 const CSSValue* BackgroundAttachment::CSSValueFromComputedStyleInternal(
445     const ComputedStyle& style,
446     const SVGComputedStyle&,
447     const LayoutObject*,
448     bool allow_visited_style) const {
449   CSSValueList* list = CSSValueList::CreateCommaSeparated();
450   for (const FillLayer* curr_layer = &style.BackgroundLayers(); curr_layer;
451        curr_layer = curr_layer->Next())
452     list->Append(*CSSIdentifierValue::Create(curr_layer->Attachment()));
453   return list;
454 }
455 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const456 const CSSValue* BackgroundBlendMode::ParseSingleValue(
457     CSSParserTokenRange& range,
458     const CSSParserContext&,
459     const CSSParserLocalContext&) const {
460   return css_property_parser_helpers::ConsumeCommaSeparatedList(
461       css_parsing_utils::ConsumeBackgroundBlendMode, range);
462 }
463 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const464 const CSSValue* BackgroundBlendMode::CSSValueFromComputedStyleInternal(
465     const ComputedStyle& style,
466     const SVGComputedStyle&,
467     const LayoutObject*,
468     bool allow_visited_style) const {
469   CSSValueList* list = CSSValueList::CreateCommaSeparated();
470   for (const FillLayer* curr_layer = &style.BackgroundLayers(); curr_layer;
471        curr_layer = curr_layer->Next())
472     list->Append(*CSSIdentifierValue::Create(curr_layer->GetBlendMode()));
473   return list;
474 }
475 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext & local_context) const476 const CSSValue* BackgroundClip::ParseSingleValue(
477     CSSParserTokenRange& range,
478     const CSSParserContext&,
479     const CSSParserLocalContext& local_context) const {
480   return css_parsing_utils::ParseBackgroundBox(
481       range, local_context, css_parsing_utils::AllowTextValue::kAllow);
482 }
483 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const484 const CSSValue* BackgroundClip::CSSValueFromComputedStyleInternal(
485     const ComputedStyle& style,
486     const SVGComputedStyle&,
487     const LayoutObject*,
488     bool allow_visited_style) const {
489   CSSValueList* list = CSSValueList::CreateCommaSeparated();
490   const FillLayer* curr_layer = &style.BackgroundLayers();
491   for (; curr_layer; curr_layer = curr_layer->Next()) {
492     EFillBox box = curr_layer->Clip();
493     list->Append(*CSSIdentifierValue::Create(box));
494   }
495   return list;
496 }
497 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const498 const CSSValue* BackgroundColor::ParseSingleValue(
499     CSSParserTokenRange& range,
500     const CSSParserContext& context,
501     const CSSParserLocalContext&) const {
502   return css_property_parser_helpers::ConsumeColor(
503       range, context, IsQuirksModeBehavior(context.Mode()));
504 }
505 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const506 const blink::Color BackgroundColor::ColorIncludingFallback(
507     bool visited_link,
508     const ComputedStyle& style) const {
509   DCHECK(!visited_link);
510   return style.BackgroundColor().Resolve(style.GetColor());
511 }
512 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const513 const CSSValue* BackgroundColor::CSSValueFromComputedStyleInternal(
514     const ComputedStyle& style,
515     const SVGComputedStyle&,
516     const LayoutObject*,
517     bool allow_visited_style) const {
518   if (allow_visited_style) {
519     return cssvalue::CSSColorValue::Create(
520         style.VisitedDependentColor(*this).Rgb());
521   }
522 
523   return ComputedStyleUtils::CurrentColorOrValidColor(style,
524                                                       style.BackgroundColor());
525 }
526 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const527 const CSSValue* BackgroundImage::ParseSingleValue(
528     CSSParserTokenRange& range,
529     const CSSParserContext& context,
530     const CSSParserLocalContext&) const {
531   return css_property_parser_helpers::ConsumeCommaSeparatedList(
532       css_property_parser_helpers::ConsumeImageOrNone, range, context);
533 }
534 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const535 const CSSValue* BackgroundImage::CSSValueFromComputedStyleInternal(
536     const ComputedStyle& style,
537     const SVGComputedStyle&,
538     const LayoutObject*,
539     bool allow_visited_style) const {
540   const FillLayer& fill_layer = style.BackgroundLayers();
541   return ComputedStyleUtils::BackgroundImageOrWebkitMaskImage(
542       style, allow_visited_style, fill_layer);
543 }
544 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext & local_context) const545 const CSSValue* BackgroundOrigin::ParseSingleValue(
546     CSSParserTokenRange& range,
547     const CSSParserContext&,
548     const CSSParserLocalContext& local_context) const {
549   return css_parsing_utils::ParseBackgroundBox(
550       range, local_context, css_parsing_utils::AllowTextValue::kForbid);
551 }
552 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const553 const CSSValue* BackgroundOrigin::CSSValueFromComputedStyleInternal(
554     const ComputedStyle& style,
555     const SVGComputedStyle&,
556     const LayoutObject*,
557     bool allow_visited_style) const {
558   CSSValueList* list = CSSValueList::CreateCommaSeparated();
559   const FillLayer* curr_layer = &style.BackgroundLayers();
560   for (; curr_layer; curr_layer = curr_layer->Next()) {
561     EFillBox box = curr_layer->Origin();
562     list->Append(*CSSIdentifierValue::Create(box));
563   }
564   return list;
565 }
566 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const567 const CSSValue* BackgroundPositionX::ParseSingleValue(
568     CSSParserTokenRange& range,
569     const CSSParserContext& context,
570     const CSSParserLocalContext&) const {
571   return css_property_parser_helpers::ConsumeCommaSeparatedList(
572       css_parsing_utils::ConsumePositionLonghand<CSSValueID::kLeft,
573                                                  CSSValueID::kRight>,
574       range, context);
575 }
576 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const577 const CSSValue* BackgroundPositionX::CSSValueFromComputedStyleInternal(
578     const ComputedStyle& style,
579     const SVGComputedStyle&,
580     const LayoutObject*,
581     bool allow_visited_style) const {
582   const FillLayer* curr_layer = &style.BackgroundLayers();
583   return ComputedStyleUtils::BackgroundPositionXOrWebkitMaskPositionX(
584       style, curr_layer);
585 }
586 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const587 const CSSValue* BackgroundPositionY::ParseSingleValue(
588     CSSParserTokenRange& range,
589     const CSSParserContext& context,
590     const CSSParserLocalContext&) const {
591   return css_property_parser_helpers::ConsumeCommaSeparatedList(
592       css_parsing_utils::ConsumePositionLonghand<CSSValueID::kTop,
593                                                  CSSValueID::kBottom>,
594       range, context);
595 }
596 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const597 const CSSValue* BackgroundPositionY::CSSValueFromComputedStyleInternal(
598     const ComputedStyle& style,
599     const SVGComputedStyle&,
600     const LayoutObject*,
601     bool allow_visited_style) const {
602   const FillLayer* curr_layer = &style.BackgroundLayers();
603   return ComputedStyleUtils::BackgroundPositionYOrWebkitMaskPositionY(
604       style, curr_layer);
605 }
606 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const607 const CSSValue* BackgroundSize::ParseSingleValue(
608     CSSParserTokenRange& range,
609     const CSSParserContext& context,
610     const CSSParserLocalContext& local_context) const {
611   return css_parsing_utils::ParseBackgroundOrMaskSize(
612       range, context, local_context, WebFeature::kNegativeBackgroundSize);
613 }
614 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const615 const CSSValue* BackgroundSize::CSSValueFromComputedStyleInternal(
616     const ComputedStyle& style,
617     const SVGComputedStyle&,
618     const LayoutObject*,
619     bool allow_visited_style) const {
620   const FillLayer& fill_layer = style.BackgroundLayers();
621   return ComputedStyleUtils::BackgroundImageOrWebkitMaskSize(style, fill_layer);
622 }
623 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const624 const CSSValue* BaselineShift::ParseSingleValue(
625     CSSParserTokenRange& range,
626     const CSSParserContext& context,
627     const CSSParserLocalContext&) const {
628   CSSValueID id = range.Peek().Id();
629   if (id == CSSValueID::kBaseline || id == CSSValueID::kSub ||
630       id == CSSValueID::kSuper)
631     return css_property_parser_helpers::ConsumeIdent(range);
632   CSSParserContext::ParserModeOverridingScope scope(context, kSVGAttributeMode);
633   return css_property_parser_helpers::ConsumeLengthOrPercent(range, context,
634                                                              kValueRangeAll);
635 }
636 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const637 const CSSValue* BaselineShift::CSSValueFromComputedStyleInternal(
638     const ComputedStyle& style,
639     const SVGComputedStyle& svg_style,
640     const LayoutObject*,
641     bool allow_visited_style) const {
642   switch (svg_style.BaselineShift()) {
643     case BS_SUPER:
644       return CSSIdentifierValue::Create(CSSValueID::kSuper);
645     case BS_SUB:
646       return CSSIdentifierValue::Create(CSSValueID::kSub);
647     case BS_LENGTH:
648       return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
649           svg_style.BaselineShiftValue(), style);
650   }
651   NOTREACHED();
652   return nullptr;
653 }
654 
ApplyInherit(StyleResolverState & state) const655 void BaselineShift::ApplyInherit(StyleResolverState& state) const {
656   const SVGComputedStyle& parent_svg_style = state.ParentStyle()->SvgStyle();
657   EBaselineShift baseline_shift = parent_svg_style.BaselineShift();
658   SVGComputedStyle& svg_style = state.Style()->AccessSVGStyle();
659   svg_style.SetBaselineShift(baseline_shift);
660   if (baseline_shift == BS_LENGTH)
661     svg_style.SetBaselineShiftValue(parent_svg_style.BaselineShiftValue());
662 }
663 
ApplyValue(StyleResolverState & state,const CSSValue & value) const664 void BaselineShift::ApplyValue(StyleResolverState& state,
665                                const CSSValue& value) const {
666   SVGComputedStyle& svg_style = state.Style()->AccessSVGStyle();
667   auto* identifier_value = DynamicTo<CSSIdentifierValue>(value);
668   if (!identifier_value) {
669     svg_style.SetBaselineShift(BS_LENGTH);
670     svg_style.SetBaselineShiftValue(StyleBuilderConverter::ConvertLength(
671         state, To<CSSPrimitiveValue>(value)));
672     return;
673   }
674   switch (identifier_value->GetValueID()) {
675     case CSSValueID::kBaseline:
676       svg_style.SetBaselineShift(BS_LENGTH);
677       svg_style.SetBaselineShiftValue(Length::Fixed());
678       return;
679     case CSSValueID::kSub:
680       svg_style.SetBaselineShift(BS_SUB);
681       return;
682     case CSSValueID::kSuper:
683       svg_style.SetBaselineShift(BS_SUPER);
684       return;
685     default:
686       NOTREACHED();
687   }
688 }
689 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const690 const CSSValue* BlockSize::ParseSingleValue(
691     CSSParserTokenRange& range,
692     const CSSParserContext& context,
693     const CSSParserLocalContext&) const {
694   return css_parsing_utils::ConsumeWidthOrHeight(range, context);
695 }
696 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const697 bool BlockSize::IsLayoutDependent(const ComputedStyle* style,
698                                   LayoutObject* layout_object) const {
699   return layout_object && layout_object->IsBox();
700 }
701 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const702 const CSSValue* BorderBlockEndColor::ParseSingleValue(
703     CSSParserTokenRange& range,
704     const CSSParserContext& context,
705     const CSSParserLocalContext&) const {
706   return css_property_parser_helpers::ConsumeColor(range, context);
707 }
708 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const709 const CSSValue* BorderBlockEndWidth::ParseSingleValue(
710     CSSParserTokenRange& range,
711     const CSSParserContext& context,
712     const CSSParserLocalContext&) const {
713   return css_parsing_utils::ConsumeBorderWidth(
714       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
715 }
716 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const717 const CSSValue* BorderBlockStartColor::ParseSingleValue(
718     CSSParserTokenRange& range,
719     const CSSParserContext& context,
720     const CSSParserLocalContext&) const {
721   return css_property_parser_helpers::ConsumeColor(range, context);
722 }
723 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const724 const CSSValue* BorderBlockStartWidth::ParseSingleValue(
725     CSSParserTokenRange& range,
726     const CSSParserContext& context,
727     const CSSParserLocalContext&) const {
728   return css_parsing_utils::ConsumeBorderWidth(
729       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
730 }
731 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const732 const CSSValue* BorderBottomColor::ParseSingleValue(
733     CSSParserTokenRange& range,
734     const CSSParserContext& context,
735     const CSSParserLocalContext& local_context) const {
736   return css_parsing_utils::ConsumeBorderColorSide(range, context,
737                                                    local_context);
738 }
739 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const740 const blink::Color BorderBottomColor::ColorIncludingFallback(
741     bool visited_link,
742     const ComputedStyle& style) const {
743   DCHECK(!visited_link);
744   return ComputedStyleUtils::BorderSideColor(style, style.BorderBottomColor(),
745                                              style.BorderBottomStyle(),
746                                              visited_link);
747 }
748 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const749 const CSSValue* BorderBottomColor::CSSValueFromComputedStyleInternal(
750     const ComputedStyle& style,
751     const SVGComputedStyle&,
752     const LayoutObject*,
753     bool allow_visited_style) const {
754   return allow_visited_style ? cssvalue::CSSColorValue::Create(
755                                    style.VisitedDependentColor(*this).Rgb())
756                              : ComputedStyleUtils::CurrentColorOrValidColor(
757                                    style, style.BorderBottomColor());
758 }
759 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const760 const CSSValue* BorderBottomLeftRadius::ParseSingleValue(
761     CSSParserTokenRange& range,
762     const CSSParserContext& context,
763     const CSSParserLocalContext&) const {
764   return css_parsing_utils::ParseBorderRadiusCorner(range, context);
765 }
766 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const767 const CSSValue* BorderBottomLeftRadius::CSSValueFromComputedStyleInternal(
768     const ComputedStyle& style,
769     const SVGComputedStyle&,
770     const LayoutObject*,
771     bool allow_visited_style) const {
772   return ComputedStyleUtils::ValueForBorderRadiusCorner(
773       style.BorderBottomLeftRadius(), style);
774 }
775 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const776 const CSSValue* BorderBottomRightRadius::ParseSingleValue(
777     CSSParserTokenRange& range,
778     const CSSParserContext& context,
779     const CSSParserLocalContext&) const {
780   return css_parsing_utils::ParseBorderRadiusCorner(range, context);
781 }
782 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const783 const CSSValue* BorderBottomRightRadius::CSSValueFromComputedStyleInternal(
784     const ComputedStyle& style,
785     const SVGComputedStyle&,
786     const LayoutObject*,
787     bool allow_visited_style) const {
788   return ComputedStyleUtils::ValueForBorderRadiusCorner(
789       style.BorderBottomRightRadius(), style);
790 }
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const791 const CSSValue* BorderBottomStyle::CSSValueFromComputedStyleInternal(
792     const ComputedStyle& style,
793     const SVGComputedStyle&,
794     const LayoutObject*,
795     bool allow_visited_style) const {
796   return CSSIdentifierValue::Create(style.BorderBottomStyle());
797 }
798 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const799 const CSSValue* BorderBottomWidth::ParseSingleValue(
800     CSSParserTokenRange& range,
801     const CSSParserContext& context,
802     const CSSParserLocalContext& local_context) const {
803   return css_parsing_utils::ParseBorderWidthSide(range, context, local_context);
804 }
805 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const806 const CSSValue* BorderBottomWidth::CSSValueFromComputedStyleInternal(
807     const ComputedStyle& style,
808     const SVGComputedStyle&,
809     const LayoutObject*,
810     bool allow_visited_style) const {
811   return ZoomAdjustedPixelValue(style.BorderBottomWidth(), style);
812 }
813 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const814 const CSSValue* BorderCollapse::CSSValueFromComputedStyleInternal(
815     const ComputedStyle& style,
816     const SVGComputedStyle&,
817     const LayoutObject*,
818     bool allow_visited_style) const {
819   if (style.BorderCollapse() == EBorderCollapse::kCollapse)
820     return CSSIdentifierValue::Create(CSSValueID::kCollapse);
821   return CSSIdentifierValue::Create(CSSValueID::kSeparate);
822 }
823 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const824 const CSSValue* BorderImageOutset::ParseSingleValue(
825     CSSParserTokenRange& range,
826     const CSSParserContext& context,
827     const CSSParserLocalContext&) const {
828   return css_parsing_utils::ConsumeBorderImageOutset(range, context);
829 }
830 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const831 const CSSValue* BorderImageOutset::CSSValueFromComputedStyleInternal(
832     const ComputedStyle& style,
833     const SVGComputedStyle&,
834     const LayoutObject*,
835     bool allow_visited_style) const {
836   return ComputedStyleUtils::ValueForNinePieceImageQuad(
837       style.BorderImage().Outset(), style);
838 }
839 
InitialValue() const840 const CSSValue* BorderImageOutset::InitialValue() const {
841   DEFINE_STATIC_LOCAL(const Persistent<CSSQuadValue>, value,
842                       (MakeGarbageCollected<CSSQuadValue>(
843                           CSSNumericLiteralValue::Create(
844                               0, CSSPrimitiveValue::UnitType::kInteger),
845                           CSSQuadValue::kSerializeAsQuad)));
846   return value;
847 }
848 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const849 const CSSValue* BorderImageRepeat::ParseSingleValue(
850     CSSParserTokenRange& range,
851     const CSSParserContext&,
852     const CSSParserLocalContext&) const {
853   return css_parsing_utils::ConsumeBorderImageRepeat(range);
854 }
855 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const856 const CSSValue* BorderImageRepeat::CSSValueFromComputedStyleInternal(
857     const ComputedStyle& style,
858     const SVGComputedStyle&,
859     const LayoutObject*,
860     bool allow_visited_style) const {
861   return ComputedStyleUtils::ValueForNinePieceImageRepeat(style.BorderImage());
862 }
863 
InitialValue() const864 const CSSValue* BorderImageRepeat::InitialValue() const {
865   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
866                       (CSSIdentifierValue::Create(CSSValueID::kStretch)));
867   return value;
868 }
869 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const870 const CSSValue* BorderImageSlice::ParseSingleValue(
871     CSSParserTokenRange& range,
872     const CSSParserContext& context,
873     const CSSParserLocalContext&) const {
874   return css_parsing_utils::ConsumeBorderImageSlice(
875       range, context, css_parsing_utils::DefaultFill::kNoFill);
876 }
877 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const878 const CSSValue* BorderImageSlice::CSSValueFromComputedStyleInternal(
879     const ComputedStyle& style,
880     const SVGComputedStyle&,
881     const LayoutObject*,
882     bool allow_visited_style) const {
883   return ComputedStyleUtils::ValueForNinePieceImageSlice(style.BorderImage());
884 }
885 
InitialValue() const886 const CSSValue* BorderImageSlice::InitialValue() const {
887   DEFINE_STATIC_LOCAL(
888       const Persistent<cssvalue::CSSBorderImageSliceValue>, value,
889       (MakeGarbageCollected<cssvalue::CSSBorderImageSliceValue>(
890           MakeGarbageCollected<CSSQuadValue>(
891               CSSNumericLiteralValue::Create(
892                   100, CSSPrimitiveValue::UnitType::kPercentage),
893               CSSQuadValue::kSerializeAsQuad),
894           /* fill */ false)));
895   return value;
896 }
897 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const898 const CSSValue* BorderImageSource::ParseSingleValue(
899     CSSParserTokenRange& range,
900     const CSSParserContext& context,
901     const CSSParserLocalContext&) const {
902   return css_property_parser_helpers::ConsumeImageOrNone(range, context);
903 }
904 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const905 const CSSValue* BorderImageSource::CSSValueFromComputedStyleInternal(
906     const ComputedStyle& style,
907     const SVGComputedStyle&,
908     const LayoutObject*,
909     bool allow_visited_style) const {
910   if (style.BorderImageSource()) {
911     return style.BorderImageSource()->ComputedCSSValue(style,
912                                                        allow_visited_style);
913   }
914   return CSSIdentifierValue::Create(CSSValueID::kNone);
915 }
916 
InitialValue() const917 const CSSValue* BorderImageSource::InitialValue() const {
918   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
919                       (CSSIdentifierValue::Create(CSSValueID::kNone)));
920   return value;
921 }
922 
ApplyValue(StyleResolverState & state,const CSSValue & value) const923 void BorderImageSource::ApplyValue(StyleResolverState& state,
924                                    const CSSValue& value) const {
925   state.Style()->SetBorderImageSource(
926       state.GetStyleImage(CSSPropertyID::kBorderImageSource, value));
927 }
928 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const929 const CSSValue* BorderImageWidth::ParseSingleValue(
930     CSSParserTokenRange& range,
931     const CSSParserContext& context,
932     const CSSParserLocalContext&) const {
933   return css_parsing_utils::ConsumeBorderImageWidth(range, context);
934 }
935 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const936 const CSSValue* BorderImageWidth::CSSValueFromComputedStyleInternal(
937     const ComputedStyle& style,
938     const SVGComputedStyle&,
939     const LayoutObject*,
940     bool allow_visited_style) const {
941   return ComputedStyleUtils::ValueForNinePieceImageQuad(
942       style.BorderImage().BorderSlices(), style);
943 }
944 
InitialValue() const945 const CSSValue* BorderImageWidth::InitialValue() const {
946   DEFINE_STATIC_LOCAL(const Persistent<CSSQuadValue>, value,
947                       (MakeGarbageCollected<CSSQuadValue>(
948                           CSSNumericLiteralValue::Create(
949                               1, CSSPrimitiveValue::UnitType::kInteger),
950                           CSSQuadValue::kSerializeAsQuad)));
951   return value;
952 }
953 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const954 const CSSValue* BorderInlineEndColor::ParseSingleValue(
955     CSSParserTokenRange& range,
956     const CSSParserContext& context,
957     const CSSParserLocalContext&) const {
958   return css_property_parser_helpers::ConsumeColor(range, context);
959 }
960 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const961 const CSSValue* BorderInlineEndWidth::ParseSingleValue(
962     CSSParserTokenRange& range,
963     const CSSParserContext& context,
964     const CSSParserLocalContext&) const {
965   return css_parsing_utils::ConsumeBorderWidth(
966       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
967 }
968 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const969 const CSSValue* BorderInlineStartColor::ParseSingleValue(
970     CSSParserTokenRange& range,
971     const CSSParserContext& context,
972     const CSSParserLocalContext&) const {
973   return css_property_parser_helpers::ConsumeColor(range, context);
974 }
975 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const976 const CSSValue* BorderInlineStartWidth::ParseSingleValue(
977     CSSParserTokenRange& range,
978     const CSSParserContext& context,
979     const CSSParserLocalContext&) const {
980   return css_parsing_utils::ConsumeBorderWidth(
981       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
982 }
983 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const984 const CSSValue* BorderLeftColor::ParseSingleValue(
985     CSSParserTokenRange& range,
986     const CSSParserContext& context,
987     const CSSParserLocalContext& local_context) const {
988   return css_parsing_utils::ConsumeBorderColorSide(range, context,
989                                                    local_context);
990 }
991 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const992 const blink::Color BorderLeftColor::ColorIncludingFallback(
993     bool visited_link,
994     const ComputedStyle& style) const {
995   DCHECK(!visited_link);
996   return ComputedStyleUtils::BorderSideColor(
997       style, style.BorderLeftColor(), style.BorderLeftStyle(), visited_link);
998 }
999 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1000 const CSSValue* BorderLeftColor::CSSValueFromComputedStyleInternal(
1001     const ComputedStyle& style,
1002     const SVGComputedStyle&,
1003     const LayoutObject*,
1004     bool allow_visited_style) const {
1005   return allow_visited_style ? cssvalue::CSSColorValue::Create(
1006                                    style.VisitedDependentColor(*this).Rgb())
1007                              : ComputedStyleUtils::CurrentColorOrValidColor(
1008                                    style, style.BorderLeftColor());
1009 }
1010 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1011 const CSSValue* BorderLeftStyle::CSSValueFromComputedStyleInternal(
1012     const ComputedStyle& style,
1013     const SVGComputedStyle&,
1014     const LayoutObject*,
1015     bool allow_visited_style) const {
1016   return CSSIdentifierValue::Create(style.BorderLeftStyle());
1017 }
1018 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const1019 const CSSValue* BorderLeftWidth::ParseSingleValue(
1020     CSSParserTokenRange& range,
1021     const CSSParserContext& context,
1022     const CSSParserLocalContext& local_context) const {
1023   return css_parsing_utils::ParseBorderWidthSide(range, context, local_context);
1024 }
1025 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1026 const CSSValue* BorderLeftWidth::CSSValueFromComputedStyleInternal(
1027     const ComputedStyle& style,
1028     const SVGComputedStyle&,
1029     const LayoutObject*,
1030     bool allow_visited_style) const {
1031   return ZoomAdjustedPixelValue(style.BorderLeftWidth(), style);
1032 }
1033 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const1034 const CSSValue* BorderRightColor::ParseSingleValue(
1035     CSSParserTokenRange& range,
1036     const CSSParserContext& context,
1037     const CSSParserLocalContext& local_context) const {
1038   return css_parsing_utils::ConsumeBorderColorSide(range, context,
1039                                                    local_context);
1040 }
1041 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const1042 const blink::Color BorderRightColor::ColorIncludingFallback(
1043     bool visited_link,
1044     const ComputedStyle& style) const {
1045   DCHECK(!visited_link);
1046   return ComputedStyleUtils::BorderSideColor(
1047       style, style.BorderRightColor(), style.BorderRightStyle(), visited_link);
1048 }
1049 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1050 const CSSValue* BorderRightColor::CSSValueFromComputedStyleInternal(
1051     const ComputedStyle& style,
1052     const SVGComputedStyle&,
1053     const LayoutObject*,
1054     bool allow_visited_style) const {
1055   return allow_visited_style ? cssvalue::CSSColorValue::Create(
1056                                    style.VisitedDependentColor(*this).Rgb())
1057                              : ComputedStyleUtils::CurrentColorOrValidColor(
1058                                    style, style.BorderRightColor());
1059 }
1060 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1061 const CSSValue* BorderRightStyle::CSSValueFromComputedStyleInternal(
1062     const ComputedStyle& style,
1063     const SVGComputedStyle&,
1064     const LayoutObject*,
1065     bool allow_visited_style) const {
1066   return CSSIdentifierValue::Create(style.BorderRightStyle());
1067 }
1068 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const1069 const CSSValue* BorderRightWidth::ParseSingleValue(
1070     CSSParserTokenRange& range,
1071     const CSSParserContext& context,
1072     const CSSParserLocalContext& local_context) const {
1073   return css_parsing_utils::ParseBorderWidthSide(range, context, local_context);
1074 }
1075 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1076 const CSSValue* BorderRightWidth::CSSValueFromComputedStyleInternal(
1077     const ComputedStyle& style,
1078     const SVGComputedStyle&,
1079     const LayoutObject*,
1080     bool allow_visited_style) const {
1081   return ZoomAdjustedPixelValue(style.BorderRightWidth(), style);
1082 }
1083 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const1084 const CSSValue* BorderTopColor::ParseSingleValue(
1085     CSSParserTokenRange& range,
1086     const CSSParserContext& context,
1087     const CSSParserLocalContext& local_context) const {
1088   return css_parsing_utils::ConsumeBorderColorSide(range, context,
1089                                                    local_context);
1090 }
1091 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const1092 const blink::Color BorderTopColor::ColorIncludingFallback(
1093     bool visited_link,
1094     const ComputedStyle& style) const {
1095   DCHECK(!visited_link);
1096   return ComputedStyleUtils::BorderSideColor(
1097       style, style.BorderTopColor(), style.BorderTopStyle(), visited_link);
1098 }
1099 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1100 const CSSValue* BorderTopColor::CSSValueFromComputedStyleInternal(
1101     const ComputedStyle& style,
1102     const SVGComputedStyle&,
1103     const LayoutObject*,
1104     bool allow_visited_style) const {
1105   return allow_visited_style
1106              ? cssvalue::CSSColorValue::Create(
1107                    style.VisitedDependentColor(*this).Rgb())
1108              : ComputedStyleUtils::ComputedStyleUtils::CurrentColorOrValidColor(
1109                    style, style.BorderTopColor());
1110 }
1111 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1112 const CSSValue* BorderTopLeftRadius::ParseSingleValue(
1113     CSSParserTokenRange& range,
1114     const CSSParserContext& context,
1115     const CSSParserLocalContext&) const {
1116   return css_parsing_utils::ParseBorderRadiusCorner(range, context);
1117 }
1118 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1119 const CSSValue* BorderTopLeftRadius::CSSValueFromComputedStyleInternal(
1120     const ComputedStyle& style,
1121     const SVGComputedStyle&,
1122     const LayoutObject*,
1123     bool allow_visited_style) const {
1124   return ComputedStyleUtils::ValueForBorderRadiusCorner(
1125       style.BorderTopLeftRadius(), style);
1126 }
1127 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1128 const CSSValue* BorderTopRightRadius::ParseSingleValue(
1129     CSSParserTokenRange& range,
1130     const CSSParserContext& context,
1131     const CSSParserLocalContext&) const {
1132   return css_parsing_utils::ParseBorderRadiusCorner(range, context);
1133 }
1134 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1135 const CSSValue* BorderTopRightRadius::CSSValueFromComputedStyleInternal(
1136     const ComputedStyle& style,
1137     const SVGComputedStyle&,
1138     const LayoutObject*,
1139     bool allow_visited_style) const {
1140   return ComputedStyleUtils::ValueForBorderRadiusCorner(
1141       style.BorderTopRightRadius(), style);
1142 }
1143 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1144 const CSSValue* BorderTopStyle::CSSValueFromComputedStyleInternal(
1145     const ComputedStyle& style,
1146     const SVGComputedStyle&,
1147     const LayoutObject*,
1148     bool allow_visited_style) const {
1149   return CSSIdentifierValue::Create(style.BorderTopStyle());
1150 }
1151 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const1152 const CSSValue* BorderTopWidth::ParseSingleValue(
1153     CSSParserTokenRange& range,
1154     const CSSParserContext& context,
1155     const CSSParserLocalContext& local_context) const {
1156   return css_parsing_utils::ParseBorderWidthSide(range, context, local_context);
1157 }
1158 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1159 const CSSValue* BorderTopWidth::CSSValueFromComputedStyleInternal(
1160     const ComputedStyle& style,
1161     const SVGComputedStyle&,
1162     const LayoutObject*,
1163     bool allow_visited_style) const {
1164   return ZoomAdjustedPixelValue(style.BorderTopWidth(), style);
1165 }
1166 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const1167 const CSSValue* Bottom::ParseSingleValue(
1168     CSSParserTokenRange& range,
1169     const CSSParserContext& context,
1170     const CSSParserLocalContext& local_context) const {
1171   return css_parsing_utils::ConsumeMarginOrOffset(
1172       range, context,
1173       css_parsing_utils::UnitlessUnlessShorthand(local_context));
1174 }
1175 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const1176 bool Bottom::IsLayoutDependent(const ComputedStyle* style,
1177                                LayoutObject* layout_object) const {
1178   return layout_object && layout_object->IsBox();
1179 }
1180 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1181 const CSSValue* Bottom::CSSValueFromComputedStyleInternal(
1182     const ComputedStyle& style,
1183     const SVGComputedStyle&,
1184     const LayoutObject* layout_object,
1185     bool allow_visited_style) const {
1186   return ComputedStyleUtils::ValueForPositionOffset(style, *this,
1187                                                     layout_object);
1188 }
1189 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1190 const CSSValue* BoxShadow::ParseSingleValue(
1191     CSSParserTokenRange& range,
1192     const CSSParserContext& context,
1193     const CSSParserLocalContext&) const {
1194   return css_parsing_utils::ConsumeShadow(
1195       range, context, css_parsing_utils::AllowInsetAndSpread::kAllow);
1196 }
1197 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1198 const CSSValue* BoxShadow::CSSValueFromComputedStyleInternal(
1199     const ComputedStyle& style,
1200     const SVGComputedStyle&,
1201     const LayoutObject*,
1202     bool allow_visited_style) const {
1203   return ComputedStyleUtils::ValueForShadowList(style.BoxShadow(), style, true);
1204 }
1205 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1206 const CSSValue* BoxSizing::CSSValueFromComputedStyleInternal(
1207     const ComputedStyle& style,
1208     const SVGComputedStyle&,
1209     const LayoutObject*,
1210     bool allow_visited_style) const {
1211   if (style.BoxSizing() == EBoxSizing::kContentBox)
1212     return CSSIdentifierValue::Create(CSSValueID::kContentBox);
1213   return CSSIdentifierValue::Create(CSSValueID::kBorderBox);
1214 }
1215 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1216 const CSSValue* BreakAfter::CSSValueFromComputedStyleInternal(
1217     const ComputedStyle& style,
1218     const SVGComputedStyle&,
1219     const LayoutObject*,
1220     bool allow_visited_style) const {
1221   return CSSIdentifierValue::Create(style.BreakAfter());
1222 }
1223 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1224 const CSSValue* BreakBefore::CSSValueFromComputedStyleInternal(
1225     const ComputedStyle& style,
1226     const SVGComputedStyle&,
1227     const LayoutObject*,
1228     bool allow_visited_style) const {
1229   return CSSIdentifierValue::Create(style.BreakBefore());
1230 }
1231 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1232 const CSSValue* BreakInside::CSSValueFromComputedStyleInternal(
1233     const ComputedStyle& style,
1234     const SVGComputedStyle&,
1235     const LayoutObject*,
1236     bool allow_visited_style) const {
1237   return CSSIdentifierValue::Create(style.BreakInside());
1238 }
1239 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const1240 const CSSValue* BufferedRendering::CSSValueFromComputedStyleInternal(
1241     const ComputedStyle& style,
1242     const SVGComputedStyle& svg_style,
1243     const LayoutObject*,
1244     bool allow_visited_style) const {
1245   return CSSIdentifierValue::Create(svg_style.BufferedRendering());
1246 }
1247 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1248 const CSSValue* CaptionSide::CSSValueFromComputedStyleInternal(
1249     const ComputedStyle& style,
1250     const SVGComputedStyle&,
1251     const LayoutObject*,
1252     bool allow_visited_style) const {
1253   return CSSIdentifierValue::Create(style.CaptionSide());
1254 }
1255 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1256 const CSSValue* CaretColor::ParseSingleValue(
1257     CSSParserTokenRange& range,
1258     const CSSParserContext& context,
1259     const CSSParserLocalContext&) const {
1260   if (range.Peek().Id() == CSSValueID::kAuto)
1261     return css_property_parser_helpers::ConsumeIdent(range);
1262   return css_property_parser_helpers::ConsumeColor(range, context);
1263 }
1264 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const1265 const blink::Color CaretColor::ColorIncludingFallback(
1266     bool visited_link,
1267     const ComputedStyle& style) const {
1268   DCHECK(!visited_link);
1269   StyleAutoColor auto_color = style.CaretColor();
1270   // TODO(rego): We may want to adjust the caret color if it's the same as
1271   // the background to ensure good visibility and contrast.
1272   StyleColor result = auto_color.IsAutoColor() ? StyleColor::CurrentColor()
1273                                                : auto_color.ToStyleColor();
1274   return result.Resolve(style.GetColor());
1275 }
1276 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1277 const CSSValue* CaretColor::CSSValueFromComputedStyleInternal(
1278     const ComputedStyle& style,
1279     const SVGComputedStyle&,
1280     const LayoutObject*,
1281     bool allow_visited_style) const {
1282   blink::Color color;
1283   if (allow_visited_style)
1284     color = style.VisitedDependentColor(*this);
1285   else if (style.CaretColor().IsAutoColor())
1286     color = StyleColor::CurrentColor().Resolve(style.GetColor());
1287   else
1288     color = style.CaretColor().ToStyleColor().Resolve(style.GetColor());
1289   return cssvalue::CSSColorValue::Create(color.Rgb());
1290 }
1291 
ApplyInitial(StyleResolverState & state) const1292 void CaretColor::ApplyInitial(StyleResolverState& state) const {
1293   state.Style()->SetCaretColor(StyleAutoColor::AutoColor());
1294 }
1295 
ApplyInherit(StyleResolverState & state) const1296 void CaretColor::ApplyInherit(StyleResolverState& state) const {
1297   state.Style()->SetCaretColor(state.ParentStyle()->CaretColor());
1298 }
1299 
ApplyValue(StyleResolverState & state,const CSSValue & value) const1300 void CaretColor::ApplyValue(StyleResolverState& state,
1301                             const CSSValue& value) const {
1302   state.Style()->SetCaretColor(
1303       StyleBuilderConverter::ConvertStyleAutoColor(state, value));
1304 }
1305 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1306 const CSSValue* Clear::CSSValueFromComputedStyleInternal(
1307     const ComputedStyle& style,
1308     const SVGComputedStyle&,
1309     const LayoutObject*,
1310     bool allow_visited_style) const {
1311   return CSSIdentifierValue::Create(style.Clear());
1312 }
1313 
1314 namespace {
1315 
ConsumeClipComponent(CSSParserTokenRange & range,const CSSParserContext & context)1316 CSSValue* ConsumeClipComponent(CSSParserTokenRange& range,
1317                                const CSSParserContext& context) {
1318   if (range.Peek().Id() == CSSValueID::kAuto)
1319     return css_property_parser_helpers::ConsumeIdent(range);
1320   return css_property_parser_helpers::ConsumeLength(
1321       range, context, kValueRangeAll,
1322       css_property_parser_helpers::UnitlessQuirk::kAllow);
1323 }
1324 
1325 }  // namespace
1326 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1327 const CSSValue* Clip::ParseSingleValue(CSSParserTokenRange& range,
1328                                        const CSSParserContext& context,
1329                                        const CSSParserLocalContext&) const {
1330   if (range.Peek().Id() == CSSValueID::kAuto)
1331     return css_property_parser_helpers::ConsumeIdent(range);
1332 
1333   if (range.Peek().FunctionId() != CSSValueID::kRect)
1334     return nullptr;
1335 
1336   CSSParserTokenRange args =
1337       css_property_parser_helpers::ConsumeFunction(range);
1338   // rect(t, r, b, l) || rect(t r b l)
1339   CSSValue* top = ConsumeClipComponent(args, context);
1340   if (!top)
1341     return nullptr;
1342   bool needs_comma =
1343       css_property_parser_helpers::ConsumeCommaIncludingWhitespace(args);
1344   CSSValue* right = ConsumeClipComponent(args, context);
1345   if (!right ||
1346       (needs_comma &&
1347        !css_property_parser_helpers::ConsumeCommaIncludingWhitespace(args)))
1348     return nullptr;
1349   CSSValue* bottom = ConsumeClipComponent(args, context);
1350   if (!bottom ||
1351       (needs_comma &&
1352        !css_property_parser_helpers::ConsumeCommaIncludingWhitespace(args)))
1353     return nullptr;
1354   CSSValue* left = ConsumeClipComponent(args, context);
1355   if (!left || !args.AtEnd())
1356     return nullptr;
1357   return MakeGarbageCollected<CSSQuadValue>(top, right, bottom, left,
1358                                             CSSQuadValue::kSerializeAsRect);
1359 }
1360 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1361 const CSSValue* Clip::CSSValueFromComputedStyleInternal(
1362     const ComputedStyle& style,
1363     const SVGComputedStyle&,
1364     const LayoutObject*,
1365     bool allow_visited_style) const {
1366   if (style.HasAutoClip())
1367     return CSSIdentifierValue::Create(CSSValueID::kAuto);
1368   CSSValue* top = ComputedStyleUtils::ZoomAdjustedPixelValueOrAuto(
1369       style.Clip().Top(), style);
1370   CSSValue* right = ComputedStyleUtils::ZoomAdjustedPixelValueOrAuto(
1371       style.Clip().Right(), style);
1372   CSSValue* bottom = ComputedStyleUtils::ZoomAdjustedPixelValueOrAuto(
1373       style.Clip().Bottom(), style);
1374   CSSValue* left = ComputedStyleUtils::ZoomAdjustedPixelValueOrAuto(
1375       style.Clip().Left(), style);
1376   return MakeGarbageCollected<CSSQuadValue>(top, right, bottom, left,
1377                                             CSSQuadValue::kSerializeAsRect);
1378 }
1379 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1380 const CSSValue* ClipPath::ParseSingleValue(CSSParserTokenRange& range,
1381                                            const CSSParserContext& context,
1382                                            const CSSParserLocalContext&) const {
1383   if (range.Peek().Id() == CSSValueID::kNone)
1384     return css_property_parser_helpers::ConsumeIdent(range);
1385   if (cssvalue::CSSURIValue* url =
1386           css_property_parser_helpers::ConsumeUrl(range, context))
1387     return url;
1388   return css_parsing_utils::ConsumeBasicShape(range, context);
1389 }
1390 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1391 const CSSValue* ClipPath::CSSValueFromComputedStyleInternal(
1392     const ComputedStyle& style,
1393     const SVGComputedStyle&,
1394     const LayoutObject*,
1395     bool allow_visited_style) const {
1396   if (ClipPathOperation* operation = style.ClipPath()) {
1397     if (operation->GetType() == ClipPathOperation::SHAPE) {
1398       return ValueForBasicShape(
1399           style, To<ShapeClipPathOperation>(operation)->GetBasicShape());
1400     }
1401     if (operation->GetType() == ClipPathOperation::REFERENCE) {
1402       AtomicString url = To<ReferenceClipPathOperation>(operation)->Url();
1403       return MakeGarbageCollected<cssvalue::CSSURIValue>(url);
1404     }
1405   }
1406   return CSSIdentifierValue::Create(CSSValueID::kNone);
1407 }
1408 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const1409 const CSSValue* ClipRule::CSSValueFromComputedStyleInternal(
1410     const ComputedStyle& style,
1411     const SVGComputedStyle& svg_style,
1412     const LayoutObject*,
1413     bool allow_visited_style) const {
1414   return CSSIdentifierValue::Create(svg_style.ClipRule());
1415 }
1416 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1417 const CSSValue* Color::ParseSingleValue(CSSParserTokenRange& range,
1418                                         const CSSParserContext& context,
1419                                         const CSSParserLocalContext&) const {
1420   return css_property_parser_helpers::ConsumeColor(
1421       range, context, IsQuirksModeBehavior(context.Mode()));
1422 }
1423 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const1424 const blink::Color Color::ColorIncludingFallback(
1425     bool visited_link,
1426     const ComputedStyle& style) const {
1427   DCHECK(!visited_link);
1428   return style.GetColor();
1429 }
1430 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1431 const CSSValue* Color::CSSValueFromComputedStyleInternal(
1432     const ComputedStyle& style,
1433     const SVGComputedStyle&,
1434     const LayoutObject*,
1435     bool allow_visited_style) const {
1436   return cssvalue::CSSColorValue::Create(
1437       allow_visited_style ? style.VisitedDependentColor(*this).Rgb()
1438                           : style.GetColor().Rgb());
1439 }
1440 
ApplyInitial(StyleResolverState & state) const1441 void Color::ApplyInitial(StyleResolverState& state) const {
1442   if (!RuntimeEnabledFeatures::CSSCascadeEnabled()) {
1443     state.SetCascadedColorValue(
1444         CSSIdentifierValue::Create(CSSValueID::kInitial));
1445     return;
1446   }
1447   state.Style()->SetColor(state.Style()->InitialColorForColorScheme());
1448 }
1449 
ApplyInherit(StyleResolverState & state) const1450 void Color::ApplyInherit(StyleResolverState& state) const {
1451   if (!RuntimeEnabledFeatures::CSSCascadeEnabled()) {
1452     state.SetCascadedColorValue(
1453         CSSIdentifierValue::Create(CSSValueID::kInherit));
1454     return;
1455   }
1456   state.Style()->SetColor(state.ParentStyle()->GetColor());
1457 }
1458 
ApplyValue(StyleResolverState & state,const CSSValue & value) const1459 void Color::ApplyValue(StyleResolverState& state, const CSSValue& value) const {
1460   if (!RuntimeEnabledFeatures::CSSCascadeEnabled()) {
1461     state.SetCascadedColorValue(&value);
1462     return;
1463   }
1464   // As per the spec, 'color: currentColor' is treated as 'color: inherit'
1465   auto* identifier_value = DynamicTo<CSSIdentifierValue>(value);
1466   if (identifier_value &&
1467       identifier_value->GetValueID() == CSSValueID::kCurrentcolor) {
1468     ApplyInherit(state);
1469     return;
1470   }
1471   state.Style()->SetColor(StyleBuilderConverter::ConvertColor(state, value));
1472 }
1473 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const1474 const CSSValue* ColorInterpolation::CSSValueFromComputedStyleInternal(
1475     const ComputedStyle& style,
1476     const SVGComputedStyle& svg_style,
1477     const LayoutObject*,
1478     bool allow_visited_style) const {
1479   return CSSIdentifierValue::Create(svg_style.ColorInterpolation());
1480 }
1481 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const1482 const CSSValue* ColorInterpolationFilters::CSSValueFromComputedStyleInternal(
1483     const ComputedStyle& style,
1484     const SVGComputedStyle& svg_style,
1485     const LayoutObject*,
1486     bool allow_visited_style) const {
1487   return CSSIdentifierValue::Create(svg_style.ColorInterpolationFilters());
1488 }
1489 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const1490 const CSSValue* ColorRendering::CSSValueFromComputedStyleInternal(
1491     const ComputedStyle& style,
1492     const SVGComputedStyle& svg_style,
1493     const LayoutObject*,
1494     bool allow_visited_style) const {
1495   return CSSIdentifierValue::Create(svg_style.ColorRendering());
1496 }
1497 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1498 const CSSValue* ColorScheme::ParseSingleValue(
1499     CSSParserTokenRange& range,
1500     const CSSParserContext& context,
1501     const CSSParserLocalContext&) const {
1502   if (range.Peek().Id() == CSSValueID::kNormal)
1503     return css_property_parser_helpers::ConsumeIdent(range);
1504   if (range.Peek().Id() == CSSValueID::kOnly) {
1505     // Handle 'only light'
1506     CSSValueList* values = CSSValueList::CreateSpaceSeparated();
1507     values->Append(*css_property_parser_helpers::ConsumeIdent(range));
1508     if (range.Peek().Id() != CSSValueID::kLight)
1509       return nullptr;
1510     values->Append(*css_property_parser_helpers::ConsumeIdent(range));
1511     return values;
1512   }
1513 
1514   CSSValueList* values = CSSValueList::CreateSpaceSeparated();
1515   do {
1516     CSSValueID id = range.Peek().Id();
1517     // 'normal' is handled above, and 'default' is reserved for future use.
1518     // 'revert' is not yet implemented as a keyword, but still skip it for
1519     // compat and interop.
1520     if (id == CSSValueID::kNormal || id == CSSValueID::kRevert ||
1521         id == CSSValueID::kDefault) {
1522       return nullptr;
1523     }
1524     if (id == CSSValueID::kOnly) {
1525       values->Append(*css_property_parser_helpers::ConsumeIdent(range));
1526       // Has to be 'light only'
1527       if (range.AtEnd() && values->length() == 2 &&
1528           To<CSSIdentifierValue>(values->Item(0)).GetValueID() ==
1529               CSSValueID::kLight) {
1530         return values;
1531       }
1532       return nullptr;
1533     }
1534     CSSValue* value =
1535         css_property_parser_helpers::ConsumeIdent<CSSValueID::kDark,
1536                                                   CSSValueID::kLight>(range);
1537     if (!value)
1538       value = css_property_parser_helpers::ConsumeCustomIdent(range, context);
1539     if (!value)
1540       return nullptr;
1541     values->Append(*value);
1542   } while (!range.AtEnd());
1543   return values;
1544 }
1545 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1546 const CSSValue* ColorScheme::CSSValueFromComputedStyleInternal(
1547     const ComputedStyle& style,
1548     const SVGComputedStyle&,
1549     const LayoutObject*,
1550     bool allow_visited_style) const {
1551   if (style.ColorScheme().IsEmpty())
1552     return CSSIdentifierValue::Create(CSSValueID::kNormal);
1553   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
1554   for (auto ident : style.ColorScheme()) {
1555     list->Append(*MakeGarbageCollected<CSSCustomIdentValue>(ident));
1556   }
1557   return list;
1558 }
1559 
InitialValue() const1560 const CSSValue* ColorScheme::InitialValue() const {
1561   return CSSIdentifierValue::Create(CSSValueID::kNormal);
1562 }
1563 
ApplyInitial(StyleResolverState & state) const1564 void ColorScheme::ApplyInitial(StyleResolverState& state) const {
1565   state.Style()->SetColorScheme(Vector<AtomicString>());
1566   state.Style()->SetDarkColorScheme(false);
1567 }
1568 
ApplyInherit(StyleResolverState & state) const1569 void ColorScheme::ApplyInherit(StyleResolverState& state) const {
1570   state.Style()->SetColorScheme(state.ParentStyle()->ColorScheme());
1571   state.Style()->SetDarkColorScheme(state.ParentStyle()->DarkColorScheme());
1572 }
1573 
ApplyValue(StyleResolverState & state,const CSSValue & value) const1574 void ColorScheme::ApplyValue(StyleResolverState& state,
1575                              const CSSValue& value) const {
1576   if (const auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
1577     DCHECK(identifier_value->GetValueID() == CSSValueID::kNormal);
1578     state.Style()->SetColorScheme(Vector<AtomicString>());
1579     state.Style()->SetDarkColorScheme(false);
1580   } else if (const auto* scheme_list = DynamicTo<CSSValueList>(value)) {
1581     bool prefers_dark =
1582         state.GetDocument().GetStyleEngine().GetPreferredColorScheme() ==
1583         PreferredColorScheme::kDark;
1584     bool use_dark = false;
1585     Vector<AtomicString> color_schemes;
1586     for (auto& item : *scheme_list) {
1587       if (const auto* custom_ident = DynamicTo<CSSCustomIdentValue>(*item)) {
1588         color_schemes.push_back(custom_ident->Value());
1589       } else if (const auto* ident = DynamicTo<CSSIdentifierValue>(*item)) {
1590         color_schemes.push_back(ident->CssText());
1591         if (prefers_dark && ident->GetValueID() == CSSValueID::kDark)
1592           use_dark = true;
1593       } else {
1594         NOTREACHED();
1595       }
1596     }
1597     state.Style()->SetColorScheme(color_schemes);
1598     state.Style()->SetDarkColorScheme(use_dark);
1599   } else {
1600     NOTREACHED();
1601   }
1602 }
1603 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1604 const CSSValue* ColumnCount::ParseSingleValue(
1605     CSSParserTokenRange& range,
1606     const CSSParserContext& context,
1607     const CSSParserLocalContext&) const {
1608   return css_parsing_utils::ConsumeColumnCount(range, context);
1609 }
1610 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1611 const CSSValue* ColumnCount::CSSValueFromComputedStyleInternal(
1612     const ComputedStyle& style,
1613     const SVGComputedStyle&,
1614     const LayoutObject*,
1615     bool allow_visited_style) const {
1616   if (style.HasAutoColumnCount())
1617     return CSSIdentifierValue::Create(CSSValueID::kAuto);
1618   return CSSNumericLiteralValue::Create(style.ColumnCount(),
1619                                         CSSPrimitiveValue::UnitType::kNumber);
1620 }
1621 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1622 const CSSValue* ColumnFill::CSSValueFromComputedStyleInternal(
1623     const ComputedStyle& style,
1624     const SVGComputedStyle&,
1625     const LayoutObject*,
1626     bool allow_visited_style) const {
1627   return CSSIdentifierValue::Create(style.GetColumnFill());
1628 }
1629 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1630 const CSSValue* ColumnGap::ParseSingleValue(
1631     CSSParserTokenRange& range,
1632     const CSSParserContext& context,
1633     const CSSParserLocalContext&) const {
1634   return css_parsing_utils::ConsumeGapLength(range, context);
1635 }
1636 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool) const1637 const CSSValue* ColumnGap::CSSValueFromComputedStyleInternal(
1638     const ComputedStyle& style,
1639     const SVGComputedStyle&,
1640     const LayoutObject*,
1641     bool) const {
1642   return ComputedStyleUtils::ValueForGapLength(style.ColumnGap(), style);
1643 }
1644 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1645 const CSSValue* ColumnRuleColor::ParseSingleValue(
1646     CSSParserTokenRange& range,
1647     const CSSParserContext& context,
1648     const CSSParserLocalContext&) const {
1649   return css_property_parser_helpers::ConsumeColor(range, context);
1650 }
1651 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const1652 const blink::Color ColumnRuleColor::ColorIncludingFallback(
1653     bool visited_link,
1654     const ComputedStyle& style) const {
1655   DCHECK(!visited_link);
1656   return style.ColumnRuleColor().Resolve(style.GetColor());
1657 }
1658 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1659 const CSSValue* ColumnRuleColor::CSSValueFromComputedStyleInternal(
1660     const ComputedStyle& style,
1661     const SVGComputedStyle&,
1662     const LayoutObject*,
1663     bool allow_visited_style) const {
1664   return allow_visited_style ? cssvalue::CSSColorValue::Create(
1665                                    style.VisitedDependentColor(*this).Rgb())
1666                              : ComputedStyleUtils::CurrentColorOrValidColor(
1667                                    style, style.ColumnRuleColor());
1668 }
1669 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1670 const CSSValue* ColumnRuleStyle::CSSValueFromComputedStyleInternal(
1671     const ComputedStyle& style,
1672     const SVGComputedStyle&,
1673     const LayoutObject*,
1674     bool allow_visited_style) const {
1675   return CSSIdentifierValue::Create(style.ColumnRuleStyle());
1676 }
1677 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1678 const CSSValue* ColumnRuleWidth::ParseSingleValue(
1679     CSSParserTokenRange& range,
1680     const CSSParserContext& context,
1681     const CSSParserLocalContext&) const {
1682   return css_property_parser_helpers::ConsumeLineWidth(
1683       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
1684 }
1685 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1686 const CSSValue* ColumnRuleWidth::CSSValueFromComputedStyleInternal(
1687     const ComputedStyle& style,
1688     const SVGComputedStyle&,
1689     const LayoutObject*,
1690     bool allow_visited_style) const {
1691   return ZoomAdjustedPixelValue(style.ColumnRuleWidth(), style);
1692 }
1693 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1694 const CSSValue* ColumnSpan::ParseSingleValue(
1695     CSSParserTokenRange& range,
1696     const CSSParserContext& context,
1697     const CSSParserLocalContext&) const {
1698   return css_property_parser_helpers::ConsumeIdent<CSSValueID::kAll,
1699                                                    CSSValueID::kNone>(range);
1700 }
1701 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1702 const CSSValue* ColumnSpan::CSSValueFromComputedStyleInternal(
1703     const ComputedStyle& style,
1704     const SVGComputedStyle&,
1705     const LayoutObject*,
1706     bool allow_visited_style) const {
1707   return CSSIdentifierValue::Create(static_cast<unsigned>(style.GetColumnSpan())
1708                                         ? CSSValueID::kAll
1709                                         : CSSValueID::kNone);
1710 }
1711 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1712 const CSSValue* ColumnWidth::ParseSingleValue(
1713     CSSParserTokenRange& range,
1714     const CSSParserContext& context,
1715     const CSSParserLocalContext&) const {
1716   return css_parsing_utils::ConsumeColumnWidth(range, context);
1717 }
1718 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1719 const CSSValue* ColumnWidth::CSSValueFromComputedStyleInternal(
1720     const ComputedStyle& style,
1721     const SVGComputedStyle&,
1722     const LayoutObject*,
1723     bool allow_visited_style) const {
1724   if (style.HasAutoColumnWidth())
1725     return CSSIdentifierValue::Create(CSSValueID::kAuto);
1726   return ZoomAdjustedPixelValue(style.ColumnWidth(), style);
1727 }
1728 
1729 // none | strict | content | [ size || layout || style || paint ]
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1730 const CSSValue* Contain::ParseSingleValue(CSSParserTokenRange& range,
1731                                           const CSSParserContext& context,
1732                                           const CSSParserLocalContext&) const {
1733   CSSValueID id = range.Peek().Id();
1734   if (id == CSSValueID::kNone)
1735     return css_property_parser_helpers::ConsumeIdent(range);
1736 
1737   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
1738   if (id == CSSValueID::kStrict || id == CSSValueID::kContent) {
1739     list->Append(*css_property_parser_helpers::ConsumeIdent(range));
1740     return list;
1741   }
1742 
1743   CSSIdentifierValue* size = nullptr;
1744   CSSIdentifierValue* layout = nullptr;
1745   CSSIdentifierValue* style = nullptr;
1746   CSSIdentifierValue* paint = nullptr;
1747   while (true) {
1748     id = range.Peek().Id();
1749     if (id == CSSValueID::kSize && !size)
1750       size = css_property_parser_helpers::ConsumeIdent(range);
1751     else if (id == CSSValueID::kLayout && !layout)
1752       layout = css_property_parser_helpers::ConsumeIdent(range);
1753     else if (id == CSSValueID::kStyle && !style)
1754       style = css_property_parser_helpers::ConsumeIdent(range);
1755     else if (id == CSSValueID::kPaint && !paint)
1756       paint = css_property_parser_helpers::ConsumeIdent(range);
1757     else
1758       break;
1759   }
1760   if (size)
1761     list->Append(*size);
1762   if (layout)
1763     list->Append(*layout);
1764   if (style) {
1765     context.Count(WebFeature::kCSSValueContainStyle);
1766     list->Append(*style);
1767   }
1768   if (paint)
1769     list->Append(*paint);
1770   if (!list->length())
1771     return nullptr;
1772   return list;
1773 }
1774 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1775 const CSSValue* Contain::CSSValueFromComputedStyleInternal(
1776     const ComputedStyle& style,
1777     const SVGComputedStyle&,
1778     const LayoutObject*,
1779     bool allow_visited_style) const {
1780   if (!style.Contain())
1781     return CSSIdentifierValue::Create(CSSValueID::kNone);
1782   if (style.Contain() == kContainsStrict)
1783     return CSSIdentifierValue::Create(CSSValueID::kStrict);
1784   if (style.Contain() == kContainsContent)
1785     return CSSIdentifierValue::Create(CSSValueID::kContent);
1786 
1787   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
1788   if (style.ContainsSize())
1789     list->Append(*CSSIdentifierValue::Create(CSSValueID::kSize));
1790   if (style.Contain() & kContainsLayout)
1791     list->Append(*CSSIdentifierValue::Create(CSSValueID::kLayout));
1792   if (style.ContainsStyle())
1793     list->Append(*CSSIdentifierValue::Create(CSSValueID::kStyle));
1794   if (style.ContainsPaint())
1795     list->Append(*CSSIdentifierValue::Create(CSSValueID::kPaint));
1796   DCHECK(list->length());
1797   return list;
1798 }
1799 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1800 const CSSValue* ContainIntrinsicSize::ParseSingleValue(
1801     CSSParserTokenRange& range,
1802     const CSSParserContext& context,
1803     const CSSParserLocalContext&) const {
1804   if (range.Peek().Id() == CSSValueID::kAuto)
1805     return css_property_parser_helpers::ConsumeIdent(range);
1806   CSSValue* width = css_property_parser_helpers::ConsumeLength(
1807       range, context, kValueRangeNonNegative);
1808   if (!width)
1809     return nullptr;
1810   CSSValue* height = css_property_parser_helpers::ConsumeLength(
1811       range, context, kValueRangeNonNegative);
1812   if (!height)
1813     height = width;
1814   return MakeGarbageCollected<CSSValuePair>(width, height,
1815                                             CSSValuePair::kDropIdenticalValues);
1816 }
1817 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1818 const CSSValue* ContainIntrinsicSize::CSSValueFromComputedStyleInternal(
1819     const ComputedStyle& style,
1820     const SVGComputedStyle&,
1821     const LayoutObject* layout_object,
1822     bool allow_visited_style) const {
1823   auto& size = style.ContainIntrinsicSize();
1824   if (size.Width().IsAuto()) {
1825     DCHECK(size.Height().IsAuto());
1826     return CSSIdentifierValue::Create(CSSValueID::kAuto);
1827   }
1828   return MakeGarbageCollected<CSSValuePair>(
1829       ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
1830           style.ContainIntrinsicSize().Width(), style),
1831       ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
1832           style.ContainIntrinsicSize().Height(), style),
1833       CSSValuePair::kDropIdenticalValues);
1834 }
1835 
1836 namespace {
1837 
ConsumeAttr(CSSParserTokenRange args,const CSSParserContext & context)1838 CSSValue* ConsumeAttr(CSSParserTokenRange args,
1839                       const CSSParserContext& context) {
1840   if (args.Peek().GetType() != kIdentToken)
1841     return nullptr;
1842 
1843   AtomicString attr_name =
1844       args.ConsumeIncludingWhitespace().Value().ToAtomicString();
1845   if (!args.AtEnd())
1846     return nullptr;
1847 
1848   if (context.IsHTMLDocument())
1849     attr_name = attr_name.LowerASCII();
1850 
1851   CSSFunctionValue* attr_value =
1852       MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kAttr);
1853   attr_value->Append(*MakeGarbageCollected<CSSCustomIdentValue>(attr_name));
1854   return attr_value;
1855 }
1856 
ConsumeCounterContent(CSSParserTokenRange args,const CSSParserContext & context,bool counters)1857 CSSValue* ConsumeCounterContent(CSSParserTokenRange args,
1858                                 const CSSParserContext& context,
1859                                 bool counters) {
1860   CSSCustomIdentValue* identifier =
1861       css_property_parser_helpers::ConsumeCustomIdent(args, context);
1862   if (!identifier)
1863     return nullptr;
1864 
1865   CSSStringValue* separator = nullptr;
1866   if (!counters) {
1867     separator = MakeGarbageCollected<CSSStringValue>(String());
1868   } else {
1869     if (!css_property_parser_helpers::ConsumeCommaIncludingWhitespace(args) ||
1870         args.Peek().GetType() != kStringToken)
1871       return nullptr;
1872     separator = MakeGarbageCollected<CSSStringValue>(
1873         args.ConsumeIncludingWhitespace().Value().ToString());
1874   }
1875 
1876   CSSIdentifierValue* list_style = nullptr;
1877   if (css_property_parser_helpers::ConsumeCommaIncludingWhitespace(args)) {
1878     CSSValueID id = args.Peek().Id();
1879     if ((id != CSSValueID::kNone &&
1880          (id < CSSValueID::kDisc || id > CSSValueID::kKatakanaIroha)))
1881       return nullptr;
1882     list_style = css_property_parser_helpers::ConsumeIdent(args);
1883   } else {
1884     list_style = CSSIdentifierValue::Create(CSSValueID::kDecimal);
1885   }
1886 
1887   if (!args.AtEnd())
1888     return nullptr;
1889   return MakeGarbageCollected<cssvalue::CSSCounterValue>(identifier, list_style,
1890                                                          separator);
1891 }
1892 
1893 }  // namespace
1894 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const1895 const CSSValue* Content::ParseSingleValue(CSSParserTokenRange& range,
1896                                           const CSSParserContext& context,
1897                                           const CSSParserLocalContext&) const {
1898   if (css_property_parser_helpers::IdentMatches<CSSValueID::kNone,
1899                                                 CSSValueID::kNormal>(
1900           range.Peek().Id()))
1901     return css_property_parser_helpers::ConsumeIdent(range);
1902 
1903   CSSValueList* values = CSSValueList::CreateSpaceSeparated();
1904   CSSValueList* outer_list = CSSValueList::CreateSlashSeparated();
1905   bool alt_text_present = false;
1906   do {
1907     CSSValue* parsed_value =
1908         css_property_parser_helpers::ConsumeImage(range, context);
1909     if (!parsed_value) {
1910       parsed_value = css_property_parser_helpers::ConsumeIdent<
1911           CSSValueID::kOpenQuote, CSSValueID::kCloseQuote,
1912           CSSValueID::kNoOpenQuote, CSSValueID::kNoCloseQuote>(range);
1913     }
1914     if (!parsed_value)
1915       parsed_value = css_property_parser_helpers::ConsumeString(range);
1916     if (!parsed_value) {
1917       if (range.Peek().FunctionId() == CSSValueID::kAttr) {
1918         parsed_value = ConsumeAttr(
1919             css_property_parser_helpers::ConsumeFunction(range), context);
1920       } else if (range.Peek().FunctionId() == CSSValueID::kCounter) {
1921         parsed_value = ConsumeCounterContent(
1922             css_property_parser_helpers::ConsumeFunction(range), context,
1923             false);
1924       } else if (range.Peek().FunctionId() == CSSValueID::kCounters) {
1925         parsed_value = ConsumeCounterContent(
1926             css_property_parser_helpers::ConsumeFunction(range), context, true);
1927       }
1928     }
1929     if (!parsed_value) {
1930       if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) {
1931         // No values were parsed before the slash, so nothing to apply the
1932         // alternative text to.
1933         if (!values->length())
1934           return nullptr;
1935         alt_text_present = true;
1936       } else {
1937         return nullptr;
1938       }
1939     } else {
1940       values->Append(*parsed_value);
1941     }
1942   } while (!range.AtEnd() && !alt_text_present);
1943   outer_list->Append(*values);
1944   if (alt_text_present) {
1945     CSSStringValue* alt_text =
1946         css_property_parser_helpers::ConsumeString(range);
1947     if (!alt_text)
1948       return nullptr;
1949     outer_list->Append(*alt_text);
1950   }
1951   return outer_list;
1952 }
1953 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1954 const CSSValue* Content::CSSValueFromComputedStyleInternal(
1955     const ComputedStyle& style,
1956     const SVGComputedStyle&,
1957     const LayoutObject*,
1958     bool allow_visited_style) const {
1959   return ComputedStyleUtils::ValueForContentData(style, allow_visited_style);
1960 }
1961 
ApplyInitial(StyleResolverState & state) const1962 void Content::ApplyInitial(StyleResolverState& state) const {
1963   state.Style()->SetContent(nullptr);
1964 }
1965 
ApplyInherit(StyleResolverState & state) const1966 void Content::ApplyInherit(StyleResolverState& state) const {
1967   // FIXME: In CSS3, it will be possible to inherit content. In CSS2 it is not.
1968   // This note is a reminder that eventually "inherit" needs to be supported.
1969 }
1970 
ApplyValue(StyleResolverState & state,const CSSValue & value) const1971 void Content::ApplyValue(StyleResolverState& state,
1972                          const CSSValue& value) const {
1973   if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
1974     DCHECK(identifier_value->GetValueID() == CSSValueID::kNormal ||
1975            identifier_value->GetValueID() == CSSValueID::kNone);
1976     if (identifier_value->GetValueID() == CSSValueID::kNone)
1977       state.Style()->SetContent(MakeGarbageCollected<NoneContentData>());
1978     else
1979       state.Style()->SetContent(nullptr);
1980     return;
1981   }
1982   const CSSValueList& outer_list = To<CSSValueList>(value);
1983   ContentData* first_content = nullptr;
1984   ContentData* prev_content = nullptr;
1985   for (auto& item : To<CSSValueList>(outer_list.Item(0))) {
1986     ContentData* next_content = nullptr;
1987     if (item->IsImageGeneratorValue() || item->IsImageSetValue() ||
1988         item->IsImageValue()) {
1989       next_content = MakeGarbageCollected<ImageContentData>(
1990           state.GetStyleImage(CSSPropertyID::kContent, *item));
1991     } else if (const auto* counter_value =
1992                    DynamicTo<cssvalue::CSSCounterValue>(item.Get())) {
1993       const auto list_style_type =
1994           CssValueIDToPlatformEnum<EListStyleType>(counter_value->ListStyle());
1995       std::unique_ptr<CounterContent> counter =
1996           std::make_unique<CounterContent>(
1997               AtomicString(counter_value->Identifier()), list_style_type,
1998               AtomicString(counter_value->Separator()));
1999       next_content =
2000           MakeGarbageCollected<CounterContentData>(std::move(counter));
2001     } else if (auto* item_identifier_value =
2002                    DynamicTo<CSSIdentifierValue>(item.Get())) {
2003       QuoteType quote_type;
2004       switch (item_identifier_value->GetValueID()) {
2005         default:
2006           NOTREACHED();
2007           FALLTHROUGH;
2008         case CSSValueID::kOpenQuote:
2009           quote_type = QuoteType::kOpen;
2010           break;
2011         case CSSValueID::kCloseQuote:
2012           quote_type = QuoteType::kClose;
2013           break;
2014         case CSSValueID::kNoOpenQuote:
2015           quote_type = QuoteType::kNoOpen;
2016           break;
2017         case CSSValueID::kNoCloseQuote:
2018           quote_type = QuoteType::kNoClose;
2019           break;
2020       }
2021       next_content = MakeGarbageCollected<QuoteContentData>(quote_type);
2022     } else {
2023       String string;
2024       if (const auto* function_value =
2025               DynamicTo<CSSFunctionValue>(item.Get())) {
2026         DCHECK_EQ(function_value->FunctionType(), CSSValueID::kAttr);
2027         state.Style()->SetHasAttrContent();
2028         // TODO: Can a namespace be specified for an attr(foo)?
2029         QualifiedName attr(
2030             g_null_atom,
2031             To<CSSCustomIdentValue>(function_value->Item(0)).Value(),
2032             g_null_atom);
2033         const AtomicString& attr_value = state.GetElement().getAttribute(attr);
2034         string = attr_value.IsNull() ? g_empty_string : attr_value.GetString();
2035       } else {
2036         string = To<CSSStringValue>(*item).Value();
2037       }
2038       if (prev_content && prev_content->IsText()) {
2039         TextContentData* text_content = To<TextContentData>(prev_content);
2040         text_content->SetText(text_content->GetText() + string);
2041         continue;
2042       }
2043       next_content = MakeGarbageCollected<TextContentData>(string);
2044     }
2045 
2046     if (!first_content)
2047       first_content = next_content;
2048     else
2049       prev_content->SetNext(next_content);
2050 
2051     prev_content = next_content;
2052   }
2053   // If alt text was provided, it will be present as the final element of the
2054   // outer list.
2055   if (outer_list.length() > 1) {
2056     String string = To<CSSStringValue>(outer_list.Item(1)).Value();
2057     auto* alt_content = MakeGarbageCollected<AltTextContentData>(string);
2058     prev_content->SetNext(alt_content);
2059   }
2060   DCHECK(first_content);
2061   state.Style()->SetContent(first_content);
2062 }
2063 
2064 const int kCounterIncrementDefaultValue = 1;
2065 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2066 const CSSValue* CounterIncrement::ParseSingleValue(
2067     CSSParserTokenRange& range,
2068     const CSSParserContext& context,
2069     const CSSParserLocalContext&) const {
2070   return css_parsing_utils::ConsumeCounter(range, context,
2071                                            kCounterIncrementDefaultValue);
2072 }
2073 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2074 const CSSValue* CounterIncrement::CSSValueFromComputedStyleInternal(
2075     const ComputedStyle& style,
2076     const SVGComputedStyle&,
2077     const LayoutObject*,
2078     bool allow_visited_style) const {
2079   return ComputedStyleUtils::ValueForCounterDirectives(style, true);
2080 }
2081 
2082 const int kCounterResetDefaultValue = 0;
2083 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2084 const CSSValue* CounterReset::ParseSingleValue(
2085     CSSParserTokenRange& range,
2086     const CSSParserContext& context,
2087     const CSSParserLocalContext&) const {
2088   return css_parsing_utils::ConsumeCounter(range, context,
2089                                            kCounterResetDefaultValue);
2090 }
2091 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2092 const CSSValue* CounterReset::CSSValueFromComputedStyleInternal(
2093     const ComputedStyle& style,
2094     const SVGComputedStyle&,
2095     const LayoutObject*,
2096     bool allow_visited_style) const {
2097   return ComputedStyleUtils::ValueForCounterDirectives(style, false);
2098 }
2099 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2100 const CSSValue* Cursor::ParseSingleValue(CSSParserTokenRange& range,
2101                                          const CSSParserContext& context,
2102                                          const CSSParserLocalContext&) const {
2103   bool in_quirks_mode = IsQuirksModeBehavior(context.Mode());
2104   CSSValueList* list = nullptr;
2105   while (
2106       CSSValue* image = css_property_parser_helpers::ConsumeImage(
2107           range, context,
2108           css_property_parser_helpers::ConsumeGeneratedImagePolicy::kForbid)) {
2109     double num;
2110     IntPoint hot_spot(-1, -1);
2111     bool hot_spot_specified = false;
2112     if (css_property_parser_helpers::ConsumeNumberRaw(range, context, num)) {
2113       hot_spot.SetX(clampTo<int>(num));
2114       if (!css_property_parser_helpers::ConsumeNumberRaw(range, context, num))
2115         return nullptr;
2116       hot_spot.SetY(clampTo<int>(num));
2117       hot_spot_specified = true;
2118     }
2119 
2120     if (!list)
2121       list = CSSValueList::CreateCommaSeparated();
2122 
2123     list->Append(*MakeGarbageCollected<cssvalue::CSSCursorImageValue>(
2124         *image, hot_spot_specified, hot_spot));
2125     if (!css_property_parser_helpers::ConsumeCommaIncludingWhitespace(range))
2126       return nullptr;
2127   }
2128 
2129   CSSValueID id = range.Peek().Id();
2130   if (!range.AtEnd()) {
2131     if (id == CSSValueID::kWebkitZoomIn)
2132       context.Count(WebFeature::kPrefixedCursorZoomIn);
2133     else if (id == CSSValueID::kWebkitZoomOut)
2134       context.Count(WebFeature::kPrefixedCursorZoomOut);
2135     else if (id == CSSValueID::kWebkitGrab)
2136       context.Count(WebFeature::kPrefixedCursorGrab);
2137     else if (id == CSSValueID::kWebkitGrabbing)
2138       context.Count(WebFeature::kPrefixedCursorGrabbing);
2139   }
2140   CSSValue* cursor_type = nullptr;
2141   if (id == CSSValueID::kHand) {
2142     if (!in_quirks_mode)  // Non-standard behavior
2143       return nullptr;
2144     cursor_type = CSSIdentifierValue::Create(CSSValueID::kPointer);
2145     range.ConsumeIncludingWhitespace();
2146   } else if ((id >= CSSValueID::kAuto && id <= CSSValueID::kWebkitZoomOut) ||
2147              id == CSSValueID::kCopy || id == CSSValueID::kNone) {
2148     cursor_type = css_property_parser_helpers::ConsumeIdent(range);
2149   } else {
2150     return nullptr;
2151   }
2152 
2153   if (!list)
2154     return cursor_type;
2155   list->Append(*cursor_type);
2156   return list;
2157 }
2158 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2159 const CSSValue* Cursor::CSSValueFromComputedStyleInternal(
2160     const ComputedStyle& style,
2161     const SVGComputedStyle&,
2162     const LayoutObject*,
2163     bool allow_visited_style) const {
2164   CSSValueList* list = nullptr;
2165   CursorList* cursors = style.Cursors();
2166   if (cursors && cursors->size() > 0) {
2167     list = CSSValueList::CreateCommaSeparated();
2168     for (const CursorData& cursor : *cursors) {
2169       if (StyleImage* image = cursor.GetImage()) {
2170         list->Append(*MakeGarbageCollected<cssvalue::CSSCursorImageValue>(
2171             *image->ComputedCSSValue(style, allow_visited_style),
2172             cursor.HotSpotSpecified(), cursor.HotSpot()));
2173       }
2174     }
2175   }
2176   CSSValue* value = CSSIdentifierValue::Create(style.Cursor());
2177   if (list) {
2178     list->Append(*value);
2179     return list;
2180   }
2181   return value;
2182 }
2183 
ApplyInitial(StyleResolverState & state) const2184 void Cursor::ApplyInitial(StyleResolverState& state) const {
2185   state.Style()->ClearCursorList();
2186   state.Style()->SetCursor(ComputedStyleInitialValues::InitialCursor());
2187 }
2188 
ApplyInherit(StyleResolverState & state) const2189 void Cursor::ApplyInherit(StyleResolverState& state) const {
2190   state.Style()->SetCursor(state.ParentStyle()->Cursor());
2191   state.Style()->SetCursorList(state.ParentStyle()->Cursors());
2192 }
2193 
ApplyValue(StyleResolverState & state,const CSSValue & value) const2194 void Cursor::ApplyValue(StyleResolverState& state,
2195                         const CSSValue& value) const {
2196   state.Style()->ClearCursorList();
2197   if (auto* value_list = DynamicTo<CSSValueList>(value)) {
2198     state.Style()->SetCursor(ECursor::kAuto);
2199     for (const auto& item : *value_list) {
2200       if (const auto* cursor =
2201               DynamicTo<cssvalue::CSSCursorImageValue>(*item)) {
2202         const CSSValue& image = cursor->ImageValue();
2203         state.Style()->AddCursor(
2204             state.GetStyleImage(CSSPropertyID::kCursor, image),
2205             cursor->HotSpotSpecified(), cursor->HotSpot());
2206       } else {
2207         state.Style()->SetCursor(
2208             To<CSSIdentifierValue>(*item).ConvertTo<ECursor>());
2209       }
2210     }
2211   } else {
2212     state.Style()->SetCursor(
2213         To<CSSIdentifierValue>(value).ConvertTo<ECursor>());
2214   }
2215 }
2216 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2217 const CSSValue* Cx::ParseSingleValue(CSSParserTokenRange& range,
2218                                      const CSSParserContext& context,
2219                                      const CSSParserLocalContext&) const {
2220   return css_property_parser_helpers::ConsumeSVGGeometryPropertyLength(
2221       range, context, kValueRangeAll);
2222 }
2223 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const2224 const CSSValue* Cx::CSSValueFromComputedStyleInternal(
2225     const ComputedStyle& style,
2226     const SVGComputedStyle& svg_style,
2227     const LayoutObject*,
2228     bool allow_visited_style) const {
2229   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(svg_style.Cx(),
2230                                                              style);
2231 }
2232 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2233 const CSSValue* Cy::ParseSingleValue(CSSParserTokenRange& range,
2234                                      const CSSParserContext& context,
2235                                      const CSSParserLocalContext&) const {
2236   return css_property_parser_helpers::ConsumeSVGGeometryPropertyLength(
2237       range, context, kValueRangeAll);
2238 }
2239 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const2240 const CSSValue* Cy::CSSValueFromComputedStyleInternal(
2241     const ComputedStyle& style,
2242     const SVGComputedStyle& svg_style,
2243     const LayoutObject*,
2244     bool allow_visited_style) const {
2245   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(svg_style.Cy(),
2246                                                              style);
2247 }
2248 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const2249 const CSSValue* D::ParseSingleValue(CSSParserTokenRange& range,
2250                                     const CSSParserContext&,
2251                                     const CSSParserLocalContext&) const {
2252   return css_parsing_utils::ConsumePathOrNone(range);
2253 }
2254 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const2255 const CSSValue* D::CSSValueFromComputedStyleInternal(
2256     const ComputedStyle& style,
2257     const SVGComputedStyle& svg_style,
2258     const LayoutObject*,
2259     bool allow_visited_style) const {
2260   if (const StylePath* style_path = svg_style.D())
2261     return style_path->ComputedCSSValue();
2262   return CSSIdentifierValue::Create(CSSValueID::kNone);
2263 }
2264 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2265 const CSSValue* Direction::CSSValueFromComputedStyleInternal(
2266     const ComputedStyle& style,
2267     const SVGComputedStyle&,
2268     const LayoutObject*,
2269     bool allow_visited_style) const {
2270   return CSSIdentifierValue::Create(style.Direction());
2271 }
2272 
ApplyValue(StyleResolverState & state,const CSSValue & value) const2273 void Direction::ApplyValue(StyleResolverState& state,
2274                            const CSSValue& value) const {
2275   state.Style()->SetDirection(
2276       To<CSSIdentifierValue>(value).ConvertTo<TextDirection>());
2277 }
2278 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2279 const CSSValue* Display::ParseSingleValue(CSSParserTokenRange& range,
2280                                           const CSSParserContext& context,
2281                                           const CSSParserLocalContext&) const {
2282   // NOTE: All the keyword values for the display property are handled by the
2283   // CSSParserFastPaths.
2284   if (!RuntimeEnabledFeatures::CSSLayoutAPIEnabled())
2285     return nullptr;
2286 
2287   if (!context.IsSecureContext())
2288     return nullptr;
2289 
2290   CSSValueID function = range.Peek().FunctionId();
2291   if (function != CSSValueID::kLayout && function != CSSValueID::kInlineLayout)
2292     return nullptr;
2293 
2294   CSSParserTokenRange range_copy = range;
2295   CSSParserTokenRange args =
2296       css_property_parser_helpers::ConsumeFunction(range_copy);
2297   CSSCustomIdentValue* name =
2298       css_property_parser_helpers::ConsumeCustomIdent(args, context);
2299 
2300   // If we didn't get a custom-ident or didn't exhaust the function arguments
2301   // return nothing.
2302   if (!name || !args.AtEnd())
2303     return nullptr;
2304 
2305   range = range_copy;
2306   return MakeGarbageCollected<cssvalue::CSSLayoutFunctionValue>(
2307       name, /* is_inline */ function == CSSValueID::kInlineLayout);
2308 }
2309 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2310 const CSSValue* Display::CSSValueFromComputedStyleInternal(
2311     const ComputedStyle& style,
2312     const SVGComputedStyle&,
2313     const LayoutObject*,
2314     bool allow_visited_style) const {
2315   if (style.IsDisplayLayoutCustomBox()) {
2316     return MakeGarbageCollected<cssvalue::CSSLayoutFunctionValue>(
2317         MakeGarbageCollected<CSSCustomIdentValue>(
2318             style.DisplayLayoutCustomName()),
2319         style.IsDisplayInlineType());
2320   }
2321 
2322   return CSSIdentifierValue::Create(style.Display());
2323 }
2324 
ApplyInitial(StyleResolverState & state) const2325 void Display::ApplyInitial(StyleResolverState& state) const {
2326   state.Style()->SetDisplay(ComputedStyleInitialValues::InitialDisplay());
2327   state.Style()->SetDisplayLayoutCustomName(
2328       ComputedStyleInitialValues::InitialDisplayLayoutCustomName());
2329 }
2330 
ApplyInherit(StyleResolverState & state) const2331 void Display::ApplyInherit(StyleResolverState& state) const {
2332   state.Style()->SetDisplay(state.ParentStyle()->Display());
2333   state.Style()->SetDisplayLayoutCustomName(
2334       state.ParentStyle()->DisplayLayoutCustomName());
2335 }
2336 
ApplyValue(StyleResolverState & state,const CSSValue & value) const2337 void Display::ApplyValue(StyleResolverState& state,
2338                          const CSSValue& value) const {
2339   if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
2340     state.Style()->SetDisplay(identifier_value->ConvertTo<EDisplay>());
2341     state.Style()->SetDisplayLayoutCustomName(
2342         ComputedStyleInitialValues::InitialDisplayLayoutCustomName());
2343     return;
2344   }
2345 
2346   const auto& layout_function_value =
2347       To<cssvalue::CSSLayoutFunctionValue>(value);
2348 
2349   EDisplay display = layout_function_value.IsInline()
2350                          ? EDisplay::kInlineLayoutCustom
2351                          : EDisplay::kLayoutCustom;
2352   state.Style()->SetDisplay(display);
2353   state.Style()->SetDisplayLayoutCustomName(layout_function_value.GetName());
2354 }
2355 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const2356 const CSSValue* DominantBaseline::CSSValueFromComputedStyleInternal(
2357     const ComputedStyle& style,
2358     const SVGComputedStyle& svg_style,
2359     const LayoutObject*,
2360     bool allow_visited_style) const {
2361   return CSSIdentifierValue::Create(svg_style.DominantBaseline());
2362 }
2363 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2364 const CSSValue* EmptyCells::CSSValueFromComputedStyleInternal(
2365     const ComputedStyle& style,
2366     const SVGComputedStyle&,
2367     const LayoutObject*,
2368     bool allow_visited_style) const {
2369   return CSSIdentifierValue::Create(style.EmptyCells());
2370 }
2371 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2372 const CSSValue* Fill::ParseSingleValue(CSSParserTokenRange& range,
2373                                        const CSSParserContext& context,
2374                                        const CSSParserLocalContext&) const {
2375   return css_parsing_utils::ParsePaintStroke(range, context);
2376 }
2377 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const2378 const CSSValue* Fill::CSSValueFromComputedStyleInternal(
2379     const ComputedStyle& style,
2380     const SVGComputedStyle& svg_style,
2381     const LayoutObject*,
2382     bool allow_visited_style) const {
2383   return ComputedStyleUtils::AdjustSVGPaintForCurrentColor(
2384       svg_style.FillPaint(), style.GetColor());
2385 }
2386 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2387 const CSSValue* FillOpacity::ParseSingleValue(
2388     CSSParserTokenRange& range,
2389     const CSSParserContext& context,
2390     const CSSParserLocalContext&) const {
2391   return css_property_parser_helpers::ConsumeAlphaValue(range, context);
2392 }
2393 
CSSValueFromComputedStyleInternal(const ComputedStyle &,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const2394 const CSSValue* FillOpacity::CSSValueFromComputedStyleInternal(
2395     const ComputedStyle&,
2396     const SVGComputedStyle& svg_style,
2397     const LayoutObject*,
2398     bool allow_visited_style) const {
2399   return CSSNumericLiteralValue::Create(svg_style.FillOpacity(),
2400                                         CSSPrimitiveValue::UnitType::kNumber);
2401 }
2402 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const2403 const CSSValue* FillRule::CSSValueFromComputedStyleInternal(
2404     const ComputedStyle& style,
2405     const SVGComputedStyle& svg_style,
2406     const LayoutObject*,
2407     bool allow_visited_style) const {
2408   return CSSIdentifierValue::Create(svg_style.FillRule());
2409 }
2410 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2411 const CSSValue* Filter::ParseSingleValue(CSSParserTokenRange& range,
2412                                          const CSSParserContext& context,
2413                                          const CSSParserLocalContext&) const {
2414   return css_property_parser_helpers::ConsumeFilterFunctionList(range, context);
2415 }
2416 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2417 const CSSValue* Filter::CSSValueFromComputedStyleInternal(
2418     const ComputedStyle& style,
2419     const SVGComputedStyle&,
2420     const LayoutObject*,
2421     bool allow_visited_style) const {
2422   return ComputedStyleUtils::ValueForFilter(style, style.Filter());
2423 }
2424 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2425 const CSSValue* FlexBasis::ParseSingleValue(
2426     CSSParserTokenRange& range,
2427     const CSSParserContext& context,
2428     const CSSParserLocalContext&) const {
2429   // FIXME: Support intrinsic dimensions too.
2430   if (range.Peek().Id() == CSSValueID::kAuto)
2431     return css_property_parser_helpers::ConsumeIdent(range);
2432   return css_property_parser_helpers::ConsumeLengthOrPercent(
2433       range, context, kValueRangeNonNegative);
2434 }
2435 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2436 const CSSValue* FlexBasis::CSSValueFromComputedStyleInternal(
2437     const ComputedStyle& style,
2438     const SVGComputedStyle&,
2439     const LayoutObject*,
2440     bool allow_visited_style) const {
2441   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(style.FlexBasis(),
2442                                                              style);
2443 }
2444 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2445 const CSSValue* FlexDirection::CSSValueFromComputedStyleInternal(
2446     const ComputedStyle& style,
2447     const SVGComputedStyle&,
2448     const LayoutObject*,
2449     bool allow_visited_style) const {
2450   return CSSIdentifierValue::Create(style.FlexDirection());
2451 }
2452 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2453 const CSSValue* FlexGrow::ParseSingleValue(CSSParserTokenRange& range,
2454                                            const CSSParserContext& context,
2455                                            const CSSParserLocalContext&) const {
2456   return css_property_parser_helpers::ConsumeNumber(range, context,
2457                                                     kValueRangeNonNegative);
2458 }
2459 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2460 const CSSValue* FlexGrow::CSSValueFromComputedStyleInternal(
2461     const ComputedStyle& style,
2462     const SVGComputedStyle&,
2463     const LayoutObject*,
2464     bool allow_visited_style) const {
2465   return CSSNumericLiteralValue::Create(style.FlexGrow(),
2466                                         CSSPrimitiveValue::UnitType::kNumber);
2467 }
2468 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2469 const CSSValue* FlexShrink::ParseSingleValue(
2470     CSSParserTokenRange& range,
2471     const CSSParserContext& context,
2472     const CSSParserLocalContext&) const {
2473   return css_property_parser_helpers::ConsumeNumber(range, context,
2474                                                     kValueRangeNonNegative);
2475 }
2476 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2477 const CSSValue* FlexShrink::CSSValueFromComputedStyleInternal(
2478     const ComputedStyle& style,
2479     const SVGComputedStyle&,
2480     const LayoutObject*,
2481     bool allow_visited_style) const {
2482   return CSSNumericLiteralValue::Create(style.FlexShrink(),
2483                                         CSSPrimitiveValue::UnitType::kNumber);
2484 }
2485 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2486 const CSSValue* FlexWrap::CSSValueFromComputedStyleInternal(
2487     const ComputedStyle& style,
2488     const SVGComputedStyle&,
2489     const LayoutObject*,
2490     bool allow_visited_style) const {
2491   return CSSIdentifierValue::Create(style.FlexWrap());
2492 }
2493 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2494 const CSSValue* Float::CSSValueFromComputedStyleInternal(
2495     const ComputedStyle& style,
2496     const SVGComputedStyle&,
2497     const LayoutObject*,
2498     bool allow_visited_style) const {
2499   if (style.HasOutOfFlowPosition())
2500     return CSSIdentifierValue::Create(CSSValueID::kNone);
2501   return CSSIdentifierValue::Create(style.Floating());
2502 }
2503 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2504 const CSSValue* FloodColor::ParseSingleValue(
2505     CSSParserTokenRange& range,
2506     const CSSParserContext& context,
2507     const CSSParserLocalContext&) const {
2508   return css_property_parser_helpers::ConsumeColor(range, context);
2509 }
2510 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const2511 const blink::Color FloodColor::ColorIncludingFallback(
2512     bool visited_link,
2513     const ComputedStyle& style) const {
2514   StyleColor result = style.FloodColor();
2515   if (!result.IsCurrentColor())
2516     return result.GetColor();
2517   return visited_link ? style.InternalVisitedColor() : style.GetColor();
2518 }
2519 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2520 const CSSValue* FloodColor::CSSValueFromComputedStyleInternal(
2521     const ComputedStyle& style,
2522     const SVGComputedStyle&,
2523     const LayoutObject*,
2524     bool allow_visited_style) const {
2525   return ComputedStyleUtils::CurrentColorOrValidColor(style,
2526                                                       style.FloodColor());
2527 }
2528 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2529 const CSSValue* FloodOpacity::ParseSingleValue(
2530     CSSParserTokenRange& range,
2531     const CSSParserContext& context,
2532     const CSSParserLocalContext&) const {
2533   return css_property_parser_helpers::ConsumeAlphaValue(range, context);
2534 }
2535 
CSSValueFromComputedStyleInternal(const ComputedStyle &,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const2536 const CSSValue* FloodOpacity::CSSValueFromComputedStyleInternal(
2537     const ComputedStyle&,
2538     const SVGComputedStyle& svg_style,
2539     const LayoutObject*,
2540     bool allow_visited_style) const {
2541   return CSSNumericLiteralValue::Create(svg_style.FloodOpacity(),
2542                                         CSSPrimitiveValue::UnitType::kNumber);
2543 }
2544 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const2545 const CSSValue* FontFamily::ParseSingleValue(
2546     CSSParserTokenRange& range,
2547     const CSSParserContext&,
2548     const CSSParserLocalContext&) const {
2549   return css_parsing_utils::ConsumeFontFamily(range);
2550 }
2551 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2552 const CSSValue* FontFamily::CSSValueFromComputedStyleInternal(
2553     const ComputedStyle& style,
2554     const SVGComputedStyle&,
2555     const LayoutObject*,
2556     bool allow_visited_style) const {
2557   return ComputedStyleUtils::ValueForFontFamily(style);
2558 }
2559 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2560 const CSSValue* FontFeatureSettings::ParseSingleValue(
2561     CSSParserTokenRange& range,
2562     const CSSParserContext& context,
2563     const CSSParserLocalContext&) const {
2564   return css_parsing_utils::ConsumeFontFeatureSettings(range, context);
2565 }
2566 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2567 const CSSValue* FontFeatureSettings::CSSValueFromComputedStyleInternal(
2568     const ComputedStyle& style,
2569     const SVGComputedStyle&,
2570     const LayoutObject*,
2571     bool allow_visited_style) const {
2572   const blink::FontFeatureSettings* feature_settings =
2573       style.GetFontDescription().FeatureSettings();
2574   if (!feature_settings || !feature_settings->size())
2575     return CSSIdentifierValue::Create(CSSValueID::kNormal);
2576   CSSValueList* list = CSSValueList::CreateCommaSeparated();
2577   for (wtf_size_t i = 0; i < feature_settings->size(); ++i) {
2578     const FontFeature& feature = feature_settings->at(i);
2579     auto* feature_value = MakeGarbageCollected<cssvalue::CSSFontFeatureValue>(
2580         feature.Tag(), feature.Value());
2581     list->Append(*feature_value);
2582   }
2583   return list;
2584 }
2585 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2586 const CSSValue* FontKerning::CSSValueFromComputedStyleInternal(
2587     const ComputedStyle& style,
2588     const SVGComputedStyle&,
2589     const LayoutObject*,
2590     bool allow_visited_style) const {
2591   return CSSIdentifierValue::Create(style.GetFontDescription().GetKerning());
2592 }
2593 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2594 const CSSValue* FontOpticalSizing::CSSValueFromComputedStyleInternal(
2595     const ComputedStyle& style,
2596     const SVGComputedStyle&,
2597     const LayoutObject*,
2598     bool allow_visited_style) const {
2599   return CSSIdentifierValue::Create(
2600       style.GetFontDescription().FontOpticalSizing());
2601 }
2602 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2603 const CSSValue* FontSizeAdjust::ParseSingleValue(
2604     CSSParserTokenRange& range,
2605     const CSSParserContext& context,
2606     const CSSParserLocalContext&) const {
2607   DCHECK(RuntimeEnabledFeatures::CSSFontSizeAdjustEnabled());
2608   if (range.Peek().Id() == CSSValueID::kNone)
2609     return css_property_parser_helpers::ConsumeIdent(range);
2610   return css_property_parser_helpers::ConsumeNumber(range, context,
2611                                                     kValueRangeNonNegative);
2612 }
2613 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2614 const CSSValue* FontSizeAdjust::CSSValueFromComputedStyleInternal(
2615     const ComputedStyle& style,
2616     const SVGComputedStyle&,
2617     const LayoutObject*,
2618     bool allow_visited_style) const {
2619   if (style.HasFontSizeAdjust()) {
2620     return CSSNumericLiteralValue::Create(style.FontSizeAdjust(),
2621                                           CSSPrimitiveValue::UnitType::kNumber);
2622   }
2623   return CSSIdentifierValue::Create(CSSValueID::kNone);
2624 }
2625 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2626 const CSSValue* FontSize::ParseSingleValue(CSSParserTokenRange& range,
2627                                            const CSSParserContext& context,
2628                                            const CSSParserLocalContext&) const {
2629   return css_parsing_utils::ConsumeFontSize(
2630       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
2631 }
2632 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2633 const CSSValue* FontSize::CSSValueFromComputedStyleInternal(
2634     const ComputedStyle& style,
2635     const SVGComputedStyle&,
2636     const LayoutObject*,
2637     bool allow_visited_style) const {
2638   return ComputedStyleUtils::ValueForFontSize(style);
2639 }
2640 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2641 const CSSValue* FontStretch::ParseSingleValue(
2642     CSSParserTokenRange& range,
2643     const CSSParserContext& context,
2644     const CSSParserLocalContext&) const {
2645   return css_parsing_utils::ConsumeFontStretch(range, context);
2646 }
2647 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2648 const CSSValue* FontStretch::CSSValueFromComputedStyleInternal(
2649     const ComputedStyle& style,
2650     const SVGComputedStyle&,
2651     const LayoutObject*,
2652     bool allow_visited_style) const {
2653   return ComputedStyleUtils::ValueForFontStretch(style);
2654 }
2655 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2656 const CSSValue* FontStyle::ParseSingleValue(
2657     CSSParserTokenRange& range,
2658     const CSSParserContext& context,
2659     const CSSParserLocalContext&) const {
2660   return css_parsing_utils::ConsumeFontStyle(range, context);
2661 }
2662 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2663 const CSSValue* FontStyle::CSSValueFromComputedStyleInternal(
2664     const ComputedStyle& style,
2665     const SVGComputedStyle&,
2666     const LayoutObject*,
2667     bool allow_visited_style) const {
2668   return ComputedStyleUtils::ValueForFontStyle(style);
2669 }
2670 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2671 const CSSValue* FontVariantCaps::ParseSingleValue(
2672     CSSParserTokenRange& range,
2673     const CSSParserContext& context,
2674     const CSSParserLocalContext&) const {
2675   return css_property_parser_helpers::ConsumeIdent<
2676       CSSValueID::kNormal, CSSValueID::kSmallCaps, CSSValueID::kAllSmallCaps,
2677       CSSValueID::kPetiteCaps, CSSValueID::kAllPetiteCaps, CSSValueID::kUnicase,
2678       CSSValueID::kTitlingCaps>(range);
2679 }
2680 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2681 const CSSValue* FontVariantCaps::CSSValueFromComputedStyleInternal(
2682     const ComputedStyle& style,
2683     const SVGComputedStyle&,
2684     const LayoutObject*,
2685     bool allow_visited_style) const {
2686   return ComputedStyleUtils::ValueForFontVariantCaps(style);
2687 }
2688 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2689 const CSSValue* FontVariantEastAsian::ParseSingleValue(
2690     CSSParserTokenRange& range,
2691     const CSSParserContext& context,
2692     const CSSParserLocalContext&) const {
2693   if (range.Peek().Id() == CSSValueID::kNormal)
2694     return css_property_parser_helpers::ConsumeIdent(range);
2695 
2696   FontVariantEastAsianParser east_asian_parser;
2697   do {
2698     if (east_asian_parser.ConsumeEastAsian(range) !=
2699         FontVariantEastAsianParser::ParseResult::kConsumedValue)
2700       return nullptr;
2701   } while (!range.AtEnd());
2702 
2703   return east_asian_parser.FinalizeValue();
2704 }
2705 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2706 const CSSValue* FontVariantEastAsian::CSSValueFromComputedStyleInternal(
2707     const ComputedStyle& style,
2708     const SVGComputedStyle&,
2709     const LayoutObject*,
2710     bool allow_visited_style) const {
2711   return ComputedStyleUtils::ValueForFontVariantEastAsian(style);
2712 }
2713 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2714 const CSSValue* FontVariantLigatures::ParseSingleValue(
2715     CSSParserTokenRange& range,
2716     const CSSParserContext& context,
2717     const CSSParserLocalContext&) const {
2718   if (range.Peek().Id() == CSSValueID::kNormal ||
2719       range.Peek().Id() == CSSValueID::kNone)
2720     return css_property_parser_helpers::ConsumeIdent(range);
2721 
2722   FontVariantLigaturesParser ligatures_parser;
2723   do {
2724     if (ligatures_parser.ConsumeLigature(range) !=
2725         FontVariantLigaturesParser::ParseResult::kConsumedValue)
2726       return nullptr;
2727   } while (!range.AtEnd());
2728 
2729   return ligatures_parser.FinalizeValue();
2730 }
2731 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2732 const CSSValue* FontVariantLigatures::CSSValueFromComputedStyleInternal(
2733     const ComputedStyle& style,
2734     const SVGComputedStyle&,
2735     const LayoutObject*,
2736     bool allow_visited_style) const {
2737   return ComputedStyleUtils::ValueForFontVariantLigatures(style);
2738 }
2739 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2740 const CSSValue* FontVariantNumeric::ParseSingleValue(
2741     CSSParserTokenRange& range,
2742     const CSSParserContext& context,
2743     const CSSParserLocalContext&) const {
2744   if (range.Peek().Id() == CSSValueID::kNormal)
2745     return css_property_parser_helpers::ConsumeIdent(range);
2746 
2747   FontVariantNumericParser numeric_parser;
2748   do {
2749     if (numeric_parser.ConsumeNumeric(range) !=
2750         FontVariantNumericParser::ParseResult::kConsumedValue)
2751       return nullptr;
2752   } while (!range.AtEnd());
2753 
2754   return numeric_parser.FinalizeValue();
2755 }
2756 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2757 const CSSValue* FontVariantNumeric::CSSValueFromComputedStyleInternal(
2758     const ComputedStyle& style,
2759     const SVGComputedStyle&,
2760     const LayoutObject*,
2761     bool allow_visited_style) const {
2762   return ComputedStyleUtils::ValueForFontVariantNumeric(style);
2763 }
2764 
2765 namespace {
2766 
ConsumeFontVariationTag(CSSParserTokenRange & range,const CSSParserContext & context)2767 cssvalue::CSSFontVariationValue* ConsumeFontVariationTag(
2768     CSSParserTokenRange& range,
2769     const CSSParserContext& context) {
2770   // Feature tag name consists of 4-letter characters.
2771   static const wtf_size_t kTagNameLength = 4;
2772 
2773   const CSSParserToken& token = range.ConsumeIncludingWhitespace();
2774   // Feature tag name comes first
2775   if (token.GetType() != kStringToken)
2776     return nullptr;
2777   if (token.Value().length() != kTagNameLength)
2778     return nullptr;
2779   AtomicString tag = token.Value().ToAtomicString();
2780   for (wtf_size_t i = 0; i < kTagNameLength; ++i) {
2781     // Limits the range of characters to 0x20-0x7E, following the tag name rules
2782     // defined in the OpenType specification.
2783     UChar character = tag[i];
2784     if (character < 0x20 || character > 0x7E)
2785       return nullptr;
2786   }
2787 
2788   double tag_value = 0;
2789   if (!css_property_parser_helpers::ConsumeNumberRaw(range, context, tag_value))
2790     return nullptr;
2791   return MakeGarbageCollected<cssvalue::CSSFontVariationValue>(
2792       tag, clampTo<float>(tag_value));
2793 }
2794 
2795 }  // namespace
2796 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2797 const CSSValue* FontVariationSettings::ParseSingleValue(
2798     CSSParserTokenRange& range,
2799     const CSSParserContext& context,
2800     const CSSParserLocalContext&) const {
2801   if (range.Peek().Id() == CSSValueID::kNormal)
2802     return css_property_parser_helpers::ConsumeIdent(range);
2803   CSSValueList* variation_settings = CSSValueList::CreateCommaSeparated();
2804   do {
2805     cssvalue::CSSFontVariationValue* font_variation_value =
2806         ConsumeFontVariationTag(range, context);
2807     if (!font_variation_value)
2808       return nullptr;
2809     variation_settings->Append(*font_variation_value);
2810   } while (css_property_parser_helpers::ConsumeCommaIncludingWhitespace(range));
2811   return variation_settings;
2812 }
2813 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2814 const CSSValue* FontVariationSettings::CSSValueFromComputedStyleInternal(
2815     const ComputedStyle& style,
2816     const SVGComputedStyle&,
2817     const LayoutObject*,
2818     bool allow_visited_style) const {
2819   const blink::FontVariationSettings* variation_settings =
2820       style.GetFontDescription().VariationSettings();
2821   if (!variation_settings || !variation_settings->size())
2822     return CSSIdentifierValue::Create(CSSValueID::kNormal);
2823   CSSValueList* list = CSSValueList::CreateCommaSeparated();
2824   for (wtf_size_t i = 0; i < variation_settings->size(); ++i) {
2825     const FontVariationAxis& variation_axis = variation_settings->at(i);
2826     cssvalue::CSSFontVariationValue* variation_value =
2827         MakeGarbageCollected<cssvalue::CSSFontVariationValue>(
2828             variation_axis.Tag(), variation_axis.Value());
2829     list->Append(*variation_value);
2830   }
2831   return list;
2832 }
2833 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2834 const CSSValue* FontWeight::ParseSingleValue(
2835     CSSParserTokenRange& range,
2836     const CSSParserContext& context,
2837     const CSSParserLocalContext&) const {
2838   return css_parsing_utils::ConsumeFontWeight(range, context);
2839 }
2840 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2841 const CSSValue* FontWeight::CSSValueFromComputedStyleInternal(
2842     const ComputedStyle& style,
2843     const SVGComputedStyle&,
2844     const LayoutObject*,
2845     bool allow_visited_style) const {
2846   return ComputedStyleUtils::ValueForFontWeight(style);
2847 }
2848 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2849 const CSSValue* ForcedColorAdjust::CSSValueFromComputedStyleInternal(
2850     const ComputedStyle& style,
2851     const SVGComputedStyle&,
2852     const LayoutObject*,
2853     bool allow_visited_style) const {
2854   return CSSIdentifierValue::Create(style.ForcedColorAdjust());
2855 }
2856 
ApplyInitial(StyleResolverState & state) const2857 void InternalEffectiveZoom::ApplyInitial(StyleResolverState& state) const {
2858   auto initial = ComputedStyleInitialValues::InitialInternalEffectiveZoom();
2859   state.SetEffectiveZoom(initial);
2860 }
2861 
ApplyInherit(StyleResolverState & state) const2862 void InternalEffectiveZoom::ApplyInherit(StyleResolverState& state) const {
2863   state.SetEffectiveZoom(state.ParentStyle()->EffectiveZoom());
2864 }
2865 
ApplyValue(StyleResolverState & state,const CSSValue & value) const2866 void InternalEffectiveZoom::ApplyValue(StyleResolverState& state,
2867                                        const CSSValue& value) const {
2868   state.SetEffectiveZoom(StyleBuilderConverter::ConvertZoom(state, value));
2869 }
2870 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const2871 const CSSValue* InternalEffectiveZoom::ParseSingleValue(
2872     CSSParserTokenRange& range,
2873     const CSSParserContext& context,
2874     const CSSParserLocalContext& local_context) const {
2875   ValueRange value_range = kValueRangeNonNegative;
2876   return css_property_parser_helpers::ConsumeNumber(range, context,
2877                                                     value_range);
2878 }
2879 
ApplyInitial(StyleResolverState & state) const2880 void InternalVisitedColor::ApplyInitial(StyleResolverState& state) const {
2881   if (!RuntimeEnabledFeatures::CSSCascadeEnabled()) {
2882     state.SetCascadedVisitedColorValue(
2883         CSSIdentifierValue::Create(CSSValueID::kInitial));
2884     return;
2885   }
2886   state.Style()->SetInternalVisitedColor(
2887       state.Style()->InitialColorForColorScheme());
2888 }
2889 
ApplyInherit(StyleResolverState & state) const2890 void InternalVisitedColor::ApplyInherit(StyleResolverState& state) const {
2891   if (!RuntimeEnabledFeatures::CSSCascadeEnabled()) {
2892     state.SetCascadedVisitedColorValue(
2893         CSSIdentifierValue::Create(CSSValueID::kInherit));
2894     return;
2895   }
2896   auto color = state.ParentStyle()->GetColor();
2897   state.Style()->SetInternalVisitedColor(color);
2898 }
2899 
ApplyValue(StyleResolverState & state,const CSSValue & value) const2900 void InternalVisitedColor::ApplyValue(StyleResolverState& state,
2901                                       const CSSValue& value) const {
2902   if (!RuntimeEnabledFeatures::CSSCascadeEnabled()) {
2903     state.SetCascadedVisitedColorValue(&value);
2904     return;
2905   }
2906   auto* identifier_value = DynamicTo<CSSIdentifierValue>(value);
2907   if (identifier_value &&
2908       identifier_value->GetValueID() == CSSValueID::kCurrentcolor) {
2909     ApplyInherit(state);
2910     return;
2911   }
2912   state.Style()->SetInternalVisitedColor(
2913       StyleBuilderConverter::ConvertColor(state, value, true));
2914 }
2915 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const2916 const blink::Color InternalVisitedColor::ColorIncludingFallback(
2917     bool visited_link,
2918     const ComputedStyle& style) const {
2919   DCHECK(visited_link);
2920   return style.InternalVisitedColor();
2921 }
2922 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const2923 const CSSValue* InternalVisitedColor::ParseSingleValue(
2924     CSSParserTokenRange& range,
2925     const CSSParserContext& context,
2926     const CSSParserLocalContext& local_context) const {
2927   return css_property_parser_helpers::ConsumeColor(
2928       range, context, IsQuirksModeBehavior(context.Mode()));
2929 }
2930 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2931 const CSSValue* GridAutoColumns::ParseSingleValue(
2932     CSSParserTokenRange& range,
2933     const CSSParserContext& context,
2934     const CSSParserLocalContext&) const {
2935   return css_parsing_utils::ConsumeGridTrackList(
2936       range, context, css_parsing_utils::TrackListType::kGridAuto);
2937 }
2938 
2939 // Specs mention that getComputedStyle() should return the used value of the
2940 // property instead of the computed one for grid-template-{rows|columns} but
2941 // not for the grid-auto-{rows|columns} as things like grid-auto-columns:
2942 // 2fr; cannot be resolved to a value in pixels as the '2fr' means very
2943 // different things depending on the size of the explicit grid or the number
2944 // of implicit tracks added to the grid. See
2945 // http://lists.w3.org/Archives/Public/www-style/2013Nov/0014.html
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2946 const CSSValue* GridAutoColumns::CSSValueFromComputedStyleInternal(
2947     const ComputedStyle& style,
2948     const SVGComputedStyle&,
2949     const LayoutObject*,
2950     bool allow_visited_style) const {
2951   return ComputedStyleUtils::ValueForGridTrackSizeList(kForColumns, style);
2952 }
2953 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const2954 const CSSValue* GridAutoFlow::ParseSingleValue(
2955     CSSParserTokenRange& range,
2956     const CSSParserContext& context,
2957     const CSSParserLocalContext&) const {
2958   CSSIdentifierValue* row_or_column_value =
2959       css_property_parser_helpers::ConsumeIdent<CSSValueID::kRow,
2960                                                 CSSValueID::kColumn>(range);
2961   CSSIdentifierValue* dense_algorithm =
2962       css_property_parser_helpers::ConsumeIdent<CSSValueID::kDense>(range);
2963   if (!row_or_column_value) {
2964     row_or_column_value =
2965         css_property_parser_helpers::ConsumeIdent<CSSValueID::kRow,
2966                                                   CSSValueID::kColumn>(range);
2967     if (!row_or_column_value && !dense_algorithm)
2968       return nullptr;
2969   }
2970   CSSValueList* parsed_values = CSSValueList::CreateSpaceSeparated();
2971   if (row_or_column_value)
2972     parsed_values->Append(*row_or_column_value);
2973   if (dense_algorithm)
2974     parsed_values->Append(*dense_algorithm);
2975   return parsed_values;
2976 }
2977 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2978 const CSSValue* GridAutoFlow::CSSValueFromComputedStyleInternal(
2979     const ComputedStyle& style,
2980     const SVGComputedStyle&,
2981     const LayoutObject*,
2982     bool allow_visited_style) const {
2983   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
2984   switch (style.GetGridAutoFlow()) {
2985     case kAutoFlowRow:
2986     case kAutoFlowRowDense:
2987       list->Append(*CSSIdentifierValue::Create(CSSValueID::kRow));
2988       break;
2989     case kAutoFlowColumn:
2990     case kAutoFlowColumnDense:
2991       list->Append(*CSSIdentifierValue::Create(CSSValueID::kColumn));
2992       break;
2993     default:
2994       NOTREACHED();
2995   }
2996 
2997   switch (style.GetGridAutoFlow()) {
2998     case kAutoFlowRowDense:
2999     case kAutoFlowColumnDense:
3000       list->Append(*CSSIdentifierValue::Create(CSSValueID::kDense));
3001       break;
3002     default:
3003       // Do nothing.
3004       break;
3005   }
3006 
3007   return list;
3008 }
3009 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3010 const CSSValue* GridAutoRows::ParseSingleValue(
3011     CSSParserTokenRange& range,
3012     const CSSParserContext& context,
3013     const CSSParserLocalContext&) const {
3014   return css_parsing_utils::ConsumeGridTrackList(
3015       range, context, css_parsing_utils::TrackListType::kGridAuto);
3016 }
3017 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3018 const CSSValue* GridAutoRows::CSSValueFromComputedStyleInternal(
3019     const ComputedStyle& style,
3020     const SVGComputedStyle&,
3021     const LayoutObject*,
3022     bool allow_visited_style) const {
3023   return ComputedStyleUtils::ValueForGridTrackSizeList(kForRows, style);
3024 }
3025 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3026 const CSSValue* GridColumnEnd::ParseSingleValue(
3027     CSSParserTokenRange& range,
3028     const CSSParserContext& context,
3029     const CSSParserLocalContext&) const {
3030   return css_parsing_utils::ConsumeGridLine(range, context);
3031 }
3032 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3033 const CSSValue* GridColumnEnd::CSSValueFromComputedStyleInternal(
3034     const ComputedStyle& style,
3035     const SVGComputedStyle&,
3036     const LayoutObject*,
3037     bool allow_visited_style) const {
3038   return ComputedStyleUtils::ValueForGridPosition(style.GridColumnEnd());
3039 }
3040 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3041 const CSSValue* GridColumnStart::ParseSingleValue(
3042     CSSParserTokenRange& range,
3043     const CSSParserContext& context,
3044     const CSSParserLocalContext&) const {
3045   return css_parsing_utils::ConsumeGridLine(range, context);
3046 }
3047 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3048 const CSSValue* GridColumnStart::CSSValueFromComputedStyleInternal(
3049     const ComputedStyle& style,
3050     const SVGComputedStyle&,
3051     const LayoutObject*,
3052     bool allow_visited_style) const {
3053   return ComputedStyleUtils::ValueForGridPosition(style.GridColumnStart());
3054 }
3055 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3056 const CSSValue* GridRowEnd::ParseSingleValue(
3057     CSSParserTokenRange& range,
3058     const CSSParserContext& context,
3059     const CSSParserLocalContext&) const {
3060   return css_parsing_utils::ConsumeGridLine(range, context);
3061 }
3062 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3063 const CSSValue* GridRowEnd::CSSValueFromComputedStyleInternal(
3064     const ComputedStyle& style,
3065     const SVGComputedStyle&,
3066     const LayoutObject*,
3067     bool allow_visited_style) const {
3068   return ComputedStyleUtils::ValueForGridPosition(style.GridRowEnd());
3069 }
3070 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3071 const CSSValue* GridRowStart::ParseSingleValue(
3072     CSSParserTokenRange& range,
3073     const CSSParserContext& context,
3074     const CSSParserLocalContext&) const {
3075   return css_parsing_utils::ConsumeGridLine(range, context);
3076 }
3077 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3078 const CSSValue* GridRowStart::CSSValueFromComputedStyleInternal(
3079     const ComputedStyle& style,
3080     const SVGComputedStyle&,
3081     const LayoutObject*,
3082     bool allow_visited_style) const {
3083   return ComputedStyleUtils::ValueForGridPosition(style.GridRowStart());
3084 }
3085 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const3086 const CSSValue* GridTemplateAreas::ParseSingleValue(
3087     CSSParserTokenRange& range,
3088     const CSSParserContext&,
3089     const CSSParserLocalContext&) const {
3090   if (range.Peek().Id() == CSSValueID::kNone)
3091     return css_property_parser_helpers::ConsumeIdent(range);
3092 
3093   NamedGridAreaMap grid_area_map;
3094   size_t row_count = 0;
3095   size_t column_count = 0;
3096 
3097   while (range.Peek().GetType() == kStringToken) {
3098     if (!css_parsing_utils::ParseGridTemplateAreasRow(
3099             range.ConsumeIncludingWhitespace().Value().ToString(),
3100             grid_area_map, row_count, column_count))
3101       return nullptr;
3102     ++row_count;
3103   }
3104 
3105   if (row_count == 0)
3106     return nullptr;
3107   DCHECK(column_count);
3108   return MakeGarbageCollected<cssvalue::CSSGridTemplateAreasValue>(
3109       grid_area_map, row_count, column_count);
3110 }
3111 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3112 const CSSValue* GridTemplateAreas::CSSValueFromComputedStyleInternal(
3113     const ComputedStyle& style,
3114     const SVGComputedStyle&,
3115     const LayoutObject*,
3116     bool allow_visited_style) const {
3117   if (!style.NamedGridAreaRowCount()) {
3118     DCHECK(!style.NamedGridAreaColumnCount());
3119     return CSSIdentifierValue::Create(CSSValueID::kNone);
3120   }
3121 
3122   return MakeGarbageCollected<cssvalue::CSSGridTemplateAreasValue>(
3123       style.NamedGridArea(), style.NamedGridAreaRowCount(),
3124       style.NamedGridAreaColumnCount());
3125 }
3126 
ApplyInitial(StyleResolverState & state) const3127 void GridTemplateAreas::ApplyInitial(StyleResolverState& state) const {
3128   state.Style()->SetNamedGridArea(
3129       ComputedStyleInitialValues::InitialNamedGridArea());
3130   state.Style()->SetNamedGridAreaRowCount(
3131       ComputedStyleInitialValues::InitialNamedGridAreaRowCount());
3132   state.Style()->SetNamedGridAreaColumnCount(
3133       ComputedStyleInitialValues::InitialNamedGridAreaColumnCount());
3134 }
3135 
ApplyInherit(StyleResolverState & state) const3136 void GridTemplateAreas::ApplyInherit(StyleResolverState& state) const {
3137   state.Style()->SetNamedGridArea(state.ParentStyle()->NamedGridArea());
3138   state.Style()->SetNamedGridAreaRowCount(
3139       state.ParentStyle()->NamedGridAreaRowCount());
3140   state.Style()->SetNamedGridAreaColumnCount(
3141       state.ParentStyle()->NamedGridAreaColumnCount());
3142 }
3143 
ApplyValue(StyleResolverState & state,const CSSValue & value) const3144 void GridTemplateAreas::ApplyValue(StyleResolverState& state,
3145                                    const CSSValue& value) const {
3146   if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
3147     // FIXME: Shouldn't we clear the grid-area values
3148     DCHECK_EQ(identifier_value->GetValueID(), CSSValueID::kNone);
3149     return;
3150   }
3151 
3152   const auto& grid_template_areas_value =
3153       To<cssvalue::CSSGridTemplateAreasValue>(value);
3154   const NamedGridAreaMap& new_named_grid_areas =
3155       grid_template_areas_value.GridAreaMap();
3156 
3157   NamedGridLinesMap implicit_named_grid_column_lines;
3158   NamedGridLinesMap implicit_named_grid_row_lines;
3159   StyleBuilderConverter::CreateImplicitNamedGridLinesFromGridArea(
3160       new_named_grid_areas, implicit_named_grid_column_lines, kForColumns);
3161   StyleBuilderConverter::CreateImplicitNamedGridLinesFromGridArea(
3162       new_named_grid_areas, implicit_named_grid_row_lines, kForRows);
3163   state.Style()->SetImplicitNamedGridColumnLines(
3164       implicit_named_grid_column_lines);
3165   state.Style()->SetImplicitNamedGridRowLines(implicit_named_grid_row_lines);
3166 
3167   state.Style()->SetNamedGridArea(new_named_grid_areas);
3168   state.Style()->SetNamedGridAreaRowCount(grid_template_areas_value.RowCount());
3169   state.Style()->SetNamedGridAreaColumnCount(
3170       grid_template_areas_value.ColumnCount());
3171 }
3172 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3173 const CSSValue* GridTemplateColumns::ParseSingleValue(
3174     CSSParserTokenRange& range,
3175     const CSSParserContext& context,
3176     const CSSParserLocalContext&) const {
3177   return css_parsing_utils::ConsumeGridTemplatesRowsOrColumns(range, context);
3178 }
3179 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3180 bool GridTemplateColumns::IsLayoutDependent(const ComputedStyle* style,
3181                                             LayoutObject* layout_object) const {
3182   return layout_object && layout_object->IsLayoutGrid();
3183 }
3184 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const3185 const CSSValue* GridTemplateColumns::CSSValueFromComputedStyleInternal(
3186     const ComputedStyle& style,
3187     const SVGComputedStyle&,
3188     const LayoutObject* layout_object,
3189     bool allow_visited_style) const {
3190   return ComputedStyleUtils::ValueForGridTrackList(kForColumns, layout_object,
3191                                                    style);
3192 }
3193 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3194 const CSSValue* GridTemplateRows::ParseSingleValue(
3195     CSSParserTokenRange& range,
3196     const CSSParserContext& context,
3197     const CSSParserLocalContext&) const {
3198   return css_parsing_utils::ConsumeGridTemplatesRowsOrColumns(range, context);
3199 }
3200 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3201 bool GridTemplateRows::IsLayoutDependent(const ComputedStyle* style,
3202                                          LayoutObject* layout_object) const {
3203   return layout_object && layout_object->IsLayoutGrid();
3204 }
3205 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const3206 const CSSValue* GridTemplateRows::CSSValueFromComputedStyleInternal(
3207     const ComputedStyle& style,
3208     const SVGComputedStyle&,
3209     const LayoutObject* layout_object,
3210     bool allow_visited_style) const {
3211   return ComputedStyleUtils::ValueForGridTrackList(kForRows, layout_object,
3212                                                    style);
3213 }
3214 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3215 const CSSValue* Height::ParseSingleValue(CSSParserTokenRange& range,
3216                                          const CSSParserContext& context,
3217                                          const CSSParserLocalContext&) const {
3218   return css_parsing_utils::ConsumeWidthOrHeight(
3219       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
3220 }
3221 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3222 bool Height::IsLayoutDependent(const ComputedStyle* style,
3223                                LayoutObject* layout_object) const {
3224   return layout_object && (layout_object->IsBox() || layout_object->IsSVG());
3225 }
3226 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const3227 const CSSValue* Height::CSSValueFromComputedStyleInternal(
3228     const ComputedStyle& style,
3229     const SVGComputedStyle&,
3230     const LayoutObject* layout_object,
3231     bool allow_visited_style) const {
3232   if (ComputedStyleUtils::WidthOrHeightShouldReturnUsedValue(layout_object)) {
3233     return ZoomAdjustedPixelValue(
3234         ComputedStyleUtils::UsedBoxSize(*layout_object).Height(), style);
3235   }
3236   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(style.Height(),
3237                                                              style);
3238 }
3239 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3240 const CSSValue* Hyphens::CSSValueFromComputedStyleInternal(
3241     const ComputedStyle& style,
3242     const SVGComputedStyle&,
3243     const LayoutObject*,
3244     bool allow_visited_style) const {
3245   return CSSIdentifierValue::Create(style.GetHyphens());
3246 }
3247 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3248 const CSSValue* ImageOrientation::ParseSingleValue(
3249     CSSParserTokenRange& range,
3250     const CSSParserContext& context,
3251     const CSSParserLocalContext&) const {
3252   DCHECK(RuntimeEnabledFeatures::ImageOrientationEnabled());
3253   if (range.Peek().Id() == CSSValueID::kFromImage)
3254     return css_property_parser_helpers::ConsumeIdent(range);
3255   if (range.Peek().Id() == CSSValueID::kNone) {
3256     return css_property_parser_helpers::ConsumeIdent(range);
3257   }
3258   return nullptr;
3259 }
3260 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3261 const CSSValue* ImageOrientation::CSSValueFromComputedStyleInternal(
3262     const ComputedStyle& style,
3263     const SVGComputedStyle&,
3264     const LayoutObject*,
3265     bool allow_visited_style) const {
3266   if (style.RespectImageOrientation() == kRespectImageOrientation)
3267     return CSSIdentifierValue::Create(CSSValueID::kFromImage);
3268   return CSSIdentifierValue::Create(CSSValueID::kNone);
3269 }
3270 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3271 const CSSValue* ImageRendering::CSSValueFromComputedStyleInternal(
3272     const ComputedStyle& style,
3273     const SVGComputedStyle&,
3274     const LayoutObject*,
3275     bool allow_visited_style) const {
3276   return CSSIdentifierValue::Create(style.ImageRendering());
3277 }
3278 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3279 const CSSValue* InlineSize::ParseSingleValue(
3280     CSSParserTokenRange& range,
3281     const CSSParserContext& context,
3282     const CSSParserLocalContext&) const {
3283   return css_parsing_utils::ConsumeWidthOrHeight(range, context);
3284 }
3285 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3286 bool InlineSize::IsLayoutDependent(const ComputedStyle* style,
3287                                    LayoutObject* layout_object) const {
3288   return layout_object && layout_object->IsBox();
3289 }
3290 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3291 const CSSValue* InsetBlockEnd::ParseSingleValue(
3292     CSSParserTokenRange& range,
3293     const CSSParserContext& context,
3294     const CSSParserLocalContext&) const {
3295   return css_parsing_utils::ConsumeMarginOrOffset(
3296       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
3297 }
3298 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3299 const CSSValue* InsetBlockStart::ParseSingleValue(
3300     CSSParserTokenRange& range,
3301     const CSSParserContext& context,
3302     const CSSParserLocalContext&) const {
3303   return css_parsing_utils::ConsumeMarginOrOffset(
3304       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
3305 }
3306 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3307 const CSSValue* InsetInlineEnd::ParseSingleValue(
3308     CSSParserTokenRange& range,
3309     const CSSParserContext& context,
3310     const CSSParserLocalContext&) const {
3311   return css_parsing_utils::ConsumeMarginOrOffset(
3312       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
3313 }
3314 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3315 const CSSValue* InsetInlineStart::ParseSingleValue(
3316     CSSParserTokenRange& range,
3317     const CSSParserContext& context,
3318     const CSSParserLocalContext&) const {
3319   return css_parsing_utils::ConsumeMarginOrOffset(
3320       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
3321 }
3322 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3323 const blink::Color InternalVisitedBackgroundColor::ColorIncludingFallback(
3324     bool visited_link,
3325     const ComputedStyle& style) const {
3326   DCHECK(visited_link);
3327 
3328   blink::Color color = style.InternalVisitedBackgroundColor().Resolve(
3329       style.InternalVisitedColor());
3330 
3331   // TODO: Technically someone could explicitly specify the color
3332   // transparent, but for now we'll just assume that if the background color
3333   // is transparent that it wasn't set. Note that it's weird that we're
3334   // returning unvisited info for a visited link, but given our restriction
3335   // that the alpha values have to match, it makes more sense to return the
3336   // unvisited background color if specified than it does to return black.
3337   // This behavior matches what Firefox 4 does as well.
3338   if (color == blink::Color::kTransparent)
3339     return style.BackgroundColor().Resolve(style.GetColor());
3340 
3341   return color;
3342 }
3343 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3344 const CSSValue* InternalVisitedBackgroundColor::ParseSingleValue(
3345     CSSParserTokenRange& range,
3346     const CSSParserContext& context,
3347     const CSSParserLocalContext& local_context) const {
3348   return css_property_parser_helpers::ConsumeColor(
3349       range, context, IsQuirksModeBehavior(context.Mode()));
3350 }
3351 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3352 const blink::Color InternalVisitedBorderLeftColor::ColorIncludingFallback(
3353     bool visited_link,
3354     const ComputedStyle& style) const {
3355   DCHECK(visited_link);
3356   return style.InternalVisitedBorderLeftColor().Resolve(
3357       style.InternalVisitedColor());
3358 }
3359 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3360 const CSSValue* InternalVisitedBorderLeftColor::ParseSingleValue(
3361     CSSParserTokenRange& range,
3362     const CSSParserContext& context,
3363     const CSSParserLocalContext& local_context) const {
3364   return css_parsing_utils::ConsumeBorderColorSide(range, context,
3365                                                    local_context);
3366 }
3367 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3368 const blink::Color InternalVisitedBorderTopColor::ColorIncludingFallback(
3369     bool visited_link,
3370     const ComputedStyle& style) const {
3371   DCHECK(visited_link);
3372   return style.InternalVisitedBorderTopColor().Resolve(
3373       style.InternalVisitedColor());
3374 }
3375 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3376 const CSSValue* InternalVisitedBorderTopColor::ParseSingleValue(
3377     CSSParserTokenRange& range,
3378     const CSSParserContext& context,
3379     const CSSParserLocalContext& local_context) const {
3380   return css_parsing_utils::ConsumeBorderColorSide(range, context,
3381                                                    local_context);
3382 }
3383 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3384 const blink::Color InternalVisitedCaretColor::ColorIncludingFallback(
3385     bool visited_link,
3386     const ComputedStyle& style) const {
3387   DCHECK(visited_link);
3388   StyleAutoColor auto_color = style.InternalVisitedCaretColor();
3389   StyleColor result = auto_color.IsAutoColor() ? StyleColor::CurrentColor()
3390                                                : auto_color.ToStyleColor();
3391   return result.Resolve(style.InternalVisitedColor());
3392 }
3393 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3394 const CSSValue* InternalVisitedCaretColor::ParseSingleValue(
3395     CSSParserTokenRange& range,
3396     const CSSParserContext& context,
3397     const CSSParserLocalContext& local_context) const {
3398   return To<Longhand>(GetCSSPropertyCaretColor())
3399       .ParseSingleValue(range, context, local_context);
3400 }
3401 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3402 const blink::Color InternalVisitedBorderRightColor::ColorIncludingFallback(
3403     bool visited_link,
3404     const ComputedStyle& style) const {
3405   DCHECK(visited_link);
3406   return style.InternalVisitedBorderRightColor().Resolve(
3407       style.InternalVisitedColor());
3408 }
3409 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3410 const CSSValue* InternalVisitedBorderRightColor::ParseSingleValue(
3411     CSSParserTokenRange& range,
3412     const CSSParserContext& context,
3413     const CSSParserLocalContext& local_context) const {
3414   return css_parsing_utils::ConsumeBorderColorSide(range, context,
3415                                                    local_context);
3416 }
3417 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3418 const blink::Color InternalVisitedBorderBottomColor::ColorIncludingFallback(
3419     bool visited_link,
3420     const ComputedStyle& style) const {
3421   DCHECK(visited_link);
3422   return style.InternalVisitedBorderBottomColor().Resolve(
3423       style.InternalVisitedColor());
3424 }
3425 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3426 const CSSValue* InternalVisitedBorderBottomColor::ParseSingleValue(
3427     CSSParserTokenRange& range,
3428     const CSSParserContext& context,
3429     const CSSParserLocalContext& local_context) const {
3430   return css_parsing_utils::ConsumeBorderColorSide(range, context,
3431                                                    local_context);
3432 }
3433 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3434 const CSSValue* InternalVisitedBorderInlineStartColor::ParseSingleValue(
3435     CSSParserTokenRange& range,
3436     const CSSParserContext& context,
3437     const CSSParserLocalContext& local_context) const {
3438   return css_parsing_utils::ConsumeBorderColorSide(range, context,
3439                                                    local_context);
3440 }
3441 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3442 const CSSValue* InternalVisitedBorderInlineEndColor::ParseSingleValue(
3443     CSSParserTokenRange& range,
3444     const CSSParserContext& context,
3445     const CSSParserLocalContext& local_context) const {
3446   return css_parsing_utils::ConsumeBorderColorSide(range, context,
3447                                                    local_context);
3448 }
3449 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3450 const CSSValue* InternalVisitedBorderBlockStartColor::ParseSingleValue(
3451     CSSParserTokenRange& range,
3452     const CSSParserContext& context,
3453     const CSSParserLocalContext& local_context) const {
3454   return css_parsing_utils::ConsumeBorderColorSide(range, context,
3455                                                    local_context);
3456 }
3457 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3458 const CSSValue* InternalVisitedBorderBlockEndColor::ParseSingleValue(
3459     CSSParserTokenRange& range,
3460     const CSSParserContext& context,
3461     const CSSParserLocalContext& local_context) const {
3462   return css_parsing_utils::ConsumeBorderColorSide(range, context,
3463                                                    local_context);
3464 }
3465 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3466 const CSSValue* InternalVisitedFill::ParseSingleValue(
3467     CSSParserTokenRange& range,
3468     const CSSParserContext& context,
3469     const CSSParserLocalContext& local_context) const {
3470   return css_parsing_utils::ParsePaintStroke(range, context);
3471 }
3472 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3473 const blink::Color InternalVisitedColumnRuleColor::ColorIncludingFallback(
3474     bool visited_link,
3475     const ComputedStyle& style) const {
3476   DCHECK(visited_link);
3477   return style.InternalVisitedColumnRuleColor().Resolve(
3478       style.InternalVisitedColor());
3479 }
3480 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3481 const CSSValue* InternalVisitedColumnRuleColor::ParseSingleValue(
3482     CSSParserTokenRange& range,
3483     const CSSParserContext& context,
3484     const CSSParserLocalContext& local_context) const {
3485   return css_property_parser_helpers::ConsumeColor(range, context);
3486 }
3487 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3488 const blink::Color InternalVisitedOutlineColor::ColorIncludingFallback(
3489     bool visited_link,
3490     const ComputedStyle& style) const {
3491   DCHECK(visited_link);
3492   return style.InternalVisitedOutlineColor().Resolve(
3493       style.InternalVisitedColor());
3494 }
3495 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3496 const CSSValue* InternalVisitedOutlineColor::ParseSingleValue(
3497     CSSParserTokenRange& range,
3498     const CSSParserContext& context,
3499     const CSSParserLocalContext& local_context) const {
3500   return To<Longhand>(GetCSSPropertyOutlineColor())
3501       .ParseSingleValue(range, context, local_context);
3502 }
3503 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3504 const CSSValue* InternalVisitedStroke::ParseSingleValue(
3505     CSSParserTokenRange& range,
3506     const CSSParserContext& context,
3507     const CSSParserLocalContext& local_context) const {
3508   return css_parsing_utils::ParsePaintStroke(range, context);
3509 }
3510 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3511 const blink::Color InternalVisitedTextDecorationColor::ColorIncludingFallback(
3512     bool visited_link,
3513     const ComputedStyle& style) const {
3514   DCHECK(visited_link);
3515   return style.DecorationColorIncludingFallback(visited_link)
3516       .Resolve(style.InternalVisitedColor());
3517 }
3518 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3519 const CSSValue* InternalVisitedTextDecorationColor::ParseSingleValue(
3520     CSSParserTokenRange& range,
3521     const CSSParserContext& context,
3522     const CSSParserLocalContext& local_context) const {
3523   return css_property_parser_helpers::ConsumeColor(range, context);
3524 }
3525 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3526 const blink::Color InternalVisitedTextEmphasisColor::ColorIncludingFallback(
3527     bool visited_link,
3528     const ComputedStyle& style) const {
3529   DCHECK(visited_link);
3530   return style.InternalVisitedTextEmphasisColor().Resolve(
3531       style.InternalVisitedColor());
3532 }
3533 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3534 const CSSValue* InternalVisitedTextEmphasisColor::ParseSingleValue(
3535     CSSParserTokenRange& range,
3536     const CSSParserContext& context,
3537     const CSSParserLocalContext& local_context) const {
3538   return css_property_parser_helpers::ConsumeColor(range, context);
3539 }
3540 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3541 const blink::Color InternalVisitedTextFillColor::ColorIncludingFallback(
3542     bool visited_link,
3543     const ComputedStyle& style) const {
3544   DCHECK(visited_link);
3545   return style.InternalVisitedTextFillColor().Resolve(
3546       style.InternalVisitedColor());
3547 }
3548 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3549 const CSSValue* InternalVisitedTextFillColor::ParseSingleValue(
3550     CSSParserTokenRange& range,
3551     const CSSParserContext& context,
3552     const CSSParserLocalContext& local_context) const {
3553   return css_property_parser_helpers::ConsumeColor(range, context);
3554 }
3555 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3556 const blink::Color InternalVisitedTextStrokeColor::ColorIncludingFallback(
3557     bool visited_link,
3558     const ComputedStyle& style) const {
3559   DCHECK(visited_link);
3560   return style.InternalVisitedTextStrokeColor().Resolve(
3561       style.InternalVisitedColor());
3562 }
3563 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3564 const CSSValue* InternalVisitedTextStrokeColor::ParseSingleValue(
3565     CSSParserTokenRange& range,
3566     const CSSParserContext& context,
3567     const CSSParserLocalContext& local_context) const {
3568   return css_property_parser_helpers::ConsumeColor(range, context);
3569 }
3570 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3571 const CSSValue* Isolation::CSSValueFromComputedStyleInternal(
3572     const ComputedStyle& style,
3573     const SVGComputedStyle&,
3574     const LayoutObject*,
3575     bool allow_visited_style) const {
3576   return CSSIdentifierValue::Create(style.Isolation());
3577 }
3578 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3579 const CSSValue* JustifyContent::ParseSingleValue(
3580     CSSParserTokenRange& range,
3581     const CSSParserContext& context,
3582     const CSSParserLocalContext&) const {
3583   // justify-content property does not allow the <baseline-position> values.
3584   if (css_property_parser_helpers::IdentMatches<
3585           CSSValueID::kFirst, CSSValueID::kLast, CSSValueID::kBaseline>(
3586           range.Peek().Id()))
3587     return nullptr;
3588   return css_parsing_utils::ConsumeContentDistributionOverflowPosition(
3589       range, css_parsing_utils::IsContentPositionOrLeftOrRightKeyword);
3590 }
3591 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3592 const CSSValue* JustifyContent::CSSValueFromComputedStyleInternal(
3593     const ComputedStyle& style,
3594     const SVGComputedStyle&,
3595     const LayoutObject*,
3596     bool allow_visited_style) const {
3597   return ComputedStyleUtils::
3598       ValueForContentPositionAndDistributionWithOverflowAlignment(
3599           style.JustifyContent());
3600 }
3601 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3602 const CSSValue* JustifyItems::ParseSingleValue(
3603     CSSParserTokenRange& range,
3604     const CSSParserContext& context,
3605     const CSSParserLocalContext&) const {
3606   CSSParserTokenRange range_copy = range;
3607   // justify-items property does not allow the 'auto' value.
3608   if (css_property_parser_helpers::IdentMatches<CSSValueID::kAuto>(
3609           range.Peek().Id()))
3610     return nullptr;
3611   CSSIdentifierValue* legacy =
3612       css_property_parser_helpers::ConsumeIdent<CSSValueID::kLegacy>(
3613           range_copy);
3614   CSSIdentifierValue* position_keyword =
3615       css_property_parser_helpers::ConsumeIdent<
3616           CSSValueID::kCenter, CSSValueID::kLeft, CSSValueID::kRight>(
3617           range_copy);
3618   if (!legacy) {
3619     legacy = css_property_parser_helpers::ConsumeIdent<CSSValueID::kLegacy>(
3620         range_copy);
3621   }
3622   if (legacy) {
3623     range = range_copy;
3624     if (position_keyword) {
3625       context.Count(WebFeature::kCSSLegacyAlignment);
3626       return MakeGarbageCollected<CSSValuePair>(
3627           legacy, position_keyword, CSSValuePair::kDropIdenticalValues);
3628     }
3629     return legacy;
3630   }
3631 
3632   return css_parsing_utils::ConsumeSelfPositionOverflowPosition(
3633       range, css_parsing_utils::IsSelfPositionOrLeftOrRightKeyword);
3634 }
3635 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3636 const CSSValue* JustifyItems::CSSValueFromComputedStyleInternal(
3637     const ComputedStyle& style,
3638     const SVGComputedStyle&,
3639     const LayoutObject*,
3640     bool allow_visited_style) const {
3641   return ComputedStyleUtils::ValueForItemPositionWithOverflowAlignment(
3642       style.JustifyItems().GetPosition() == ItemPosition::kAuto
3643           ? ComputedStyleInitialValues::InitialDefaultAlignment()
3644           : style.JustifyItems());
3645 }
3646 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3647 const CSSValue* JustifySelf::ParseSingleValue(
3648     CSSParserTokenRange& range,
3649     const CSSParserContext& context,
3650     const CSSParserLocalContext&) const {
3651   return css_parsing_utils::ConsumeSelfPositionOverflowPosition(
3652       range, css_parsing_utils::IsSelfPositionOrLeftOrRightKeyword);
3653 }
3654 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3655 const CSSValue* JustifySelf::CSSValueFromComputedStyleInternal(
3656     const ComputedStyle& style,
3657     const SVGComputedStyle&,
3658     const LayoutObject*,
3659     bool allow_visited_style) const {
3660   return ComputedStyleUtils::ValueForItemPositionWithOverflowAlignment(
3661       style.JustifySelf());
3662 }
3663 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const3664 const CSSValue* Left::ParseSingleValue(
3665     CSSParserTokenRange& range,
3666     const CSSParserContext& context,
3667     const CSSParserLocalContext& local_context) const {
3668   return css_parsing_utils::ConsumeMarginOrOffset(
3669       range, context,
3670       css_parsing_utils::UnitlessUnlessShorthand(local_context));
3671 }
3672 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3673 bool Left::IsLayoutDependent(const ComputedStyle* style,
3674                              LayoutObject* layout_object) const {
3675   return layout_object && layout_object->IsBox();
3676 }
3677 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const3678 const CSSValue* Left::CSSValueFromComputedStyleInternal(
3679     const ComputedStyle& style,
3680     const SVGComputedStyle&,
3681     const LayoutObject* layout_object,
3682     bool allow_visited_style) const {
3683   return ComputedStyleUtils::ValueForPositionOffset(style, *this,
3684                                                     layout_object);
3685 }
3686 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3687 const CSSValue* LetterSpacing::ParseSingleValue(
3688     CSSParserTokenRange& range,
3689     const CSSParserContext& context,
3690     const CSSParserLocalContext&) const {
3691   return css_parsing_utils::ParseSpacing(range, context);
3692 }
3693 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3694 const CSSValue* LetterSpacing::CSSValueFromComputedStyleInternal(
3695     const ComputedStyle& style,
3696     const SVGComputedStyle&,
3697     const LayoutObject*,
3698     bool allow_visited_style) const {
3699   if (!style.LetterSpacing())
3700     return CSSIdentifierValue::Create(CSSValueID::kNormal);
3701   return ZoomAdjustedPixelValue(style.LetterSpacing(), style);
3702 }
3703 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3704 const CSSValue* LightingColor::ParseSingleValue(
3705     CSSParserTokenRange& range,
3706     const CSSParserContext& context,
3707     const CSSParserLocalContext&) const {
3708   return css_property_parser_helpers::ConsumeColor(range, context);
3709 }
3710 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const3711 const blink::Color LightingColor::ColorIncludingFallback(
3712     bool visited_link,
3713     const ComputedStyle& style) const {
3714   StyleColor result = style.LightingColor();
3715   if (!result.IsCurrentColor())
3716     return result.GetColor();
3717   return visited_link ? style.InternalVisitedColor() : style.GetColor();
3718 }
3719 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3720 const CSSValue* LightingColor::CSSValueFromComputedStyleInternal(
3721     const ComputedStyle& style,
3722     const SVGComputedStyle&,
3723     const LayoutObject*,
3724     bool allow_visited_style) const {
3725   return ComputedStyleUtils::CurrentColorOrValidColor(style,
3726                                                       style.LightingColor());
3727 }
3728 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3729 const CSSValue* LineBreak::CSSValueFromComputedStyleInternal(
3730     const ComputedStyle& style,
3731     const SVGComputedStyle&,
3732     const LayoutObject*,
3733     bool allow_visited_style) const {
3734   return CSSIdentifierValue::Create(style.GetLineBreak());
3735 }
3736 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3737 const CSSValue* LineHeight::ParseSingleValue(
3738     CSSParserTokenRange& range,
3739     const CSSParserContext& context,
3740     const CSSParserLocalContext&) const {
3741   return css_parsing_utils::ConsumeLineHeight(range, context);
3742 }
3743 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3744 const CSSValue* LineHeight::CSSValueFromComputedStyleInternal(
3745     const ComputedStyle& style,
3746     const SVGComputedStyle&,
3747     const LayoutObject*,
3748     bool allow_visited_style) const {
3749   return ComputedStyleUtils::ValueForLineHeight(style);
3750 }
3751 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3752 const CSSValue* LineHeightStep::ParseSingleValue(
3753     CSSParserTokenRange& range,
3754     const CSSParserContext& context,
3755     const CSSParserLocalContext&) const {
3756   return css_property_parser_helpers::ConsumeLength(range, context,
3757                                                     kValueRangeNonNegative);
3758 }
3759 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3760 const CSSValue* LineHeightStep::CSSValueFromComputedStyleInternal(
3761     const ComputedStyle& style,
3762     const SVGComputedStyle&,
3763     const LayoutObject*,
3764     bool allow_visited_style) const {
3765   return ZoomAdjustedPixelValue(style.LineHeightStep(), style);
3766 }
3767 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3768 const CSSValue* ListStyleImage::ParseSingleValue(
3769     CSSParserTokenRange& range,
3770     const CSSParserContext& context,
3771     const CSSParserLocalContext&) const {
3772   return css_property_parser_helpers::ConsumeImageOrNone(range, context);
3773 }
3774 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3775 const CSSValue* ListStyleImage::CSSValueFromComputedStyleInternal(
3776     const ComputedStyle& style,
3777     const SVGComputedStyle&,
3778     const LayoutObject*,
3779     bool allow_visited_style) const {
3780   if (style.ListStyleImage())
3781     return style.ListStyleImage()->ComputedCSSValue(style, allow_visited_style);
3782   return CSSIdentifierValue::Create(CSSValueID::kNone);
3783 }
3784 
ApplyValue(StyleResolverState & state,const CSSValue & value) const3785 void ListStyleImage::ApplyValue(StyleResolverState& state,
3786                                 const CSSValue& value) const {
3787   state.Style()->SetListStyleImage(
3788       state.GetStyleImage(CSSPropertyID::kListStyleImage, value));
3789 }
3790 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3791 const CSSValue* ListStylePosition::CSSValueFromComputedStyleInternal(
3792     const ComputedStyle& style,
3793     const SVGComputedStyle&,
3794     const LayoutObject*,
3795     bool allow_visited_style) const {
3796   return CSSIdentifierValue::Create(style.ListStylePosition());
3797 }
3798 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3799 const CSSValue* ListStyleType::ParseSingleValue(
3800     CSSParserTokenRange& range,
3801     const CSSParserContext& context,
3802     const CSSParserLocalContext&) const {
3803   // NOTE: All the keyword values for the list-style-type property are handled
3804   // by the CSSParserFastPaths.
3805   return css_property_parser_helpers::ConsumeString(range);
3806 }
3807 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3808 const CSSValue* ListStyleType::CSSValueFromComputedStyleInternal(
3809     const ComputedStyle& style,
3810     const SVGComputedStyle&,
3811     const LayoutObject*,
3812     bool allow_visited_style) const {
3813   if (style.ListStyleType() == EListStyleType::kString)
3814     return MakeGarbageCollected<CSSStringValue>(style.ListStyleStringValue());
3815   return CSSIdentifierValue::Create(style.ListStyleType());
3816 }
3817 
ApplyInitial(StyleResolverState & state) const3818 void ListStyleType::ApplyInitial(StyleResolverState& state) const {
3819   state.Style()->SetListStyleType(
3820       ComputedStyleInitialValues::InitialListStyleType());
3821   state.Style()->SetListStyleStringValue(
3822       ComputedStyleInitialValues::InitialListStyleStringValue());
3823 }
3824 
ApplyInherit(StyleResolverState & state) const3825 void ListStyleType::ApplyInherit(StyleResolverState& state) const {
3826   state.Style()->SetListStyleType(state.ParentStyle()->ListStyleType());
3827   state.Style()->SetListStyleStringValue(
3828       state.ParentStyle()->ListStyleStringValue());
3829 }
3830 
ApplyValue(StyleResolverState & state,const CSSValue & value) const3831 void ListStyleType::ApplyValue(StyleResolverState& state,
3832                                const CSSValue& value) const {
3833   if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
3834     state.Style()->SetListStyleType(
3835         identifier_value->ConvertTo<EListStyleType>());
3836     state.Style()->SetListStyleStringValue(
3837         ComputedStyleInitialValues::InitialListStyleStringValue());
3838     return;
3839   }
3840 
3841   state.Style()->SetListStyleType(EListStyleType::kString);
3842   state.Style()->SetListStyleStringValue(
3843       AtomicString(To<CSSStringValue>(value).Value()));
3844 }
3845 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3846 bool MarginBlockEnd::IsLayoutDependent(const ComputedStyle* style,
3847                                        LayoutObject* layout_object) const {
3848   return layout_object && layout_object->IsBox();
3849 }
3850 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3851 const CSSValue* MarginBlockEnd::ParseSingleValue(
3852     CSSParserTokenRange& range,
3853     const CSSParserContext& context,
3854     const CSSParserLocalContext&) const {
3855   return css_parsing_utils::ConsumeMarginOrOffset(
3856       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
3857 }
3858 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3859 bool MarginBlockStart::IsLayoutDependent(const ComputedStyle* style,
3860                                          LayoutObject* layout_object) const {
3861   return layout_object && layout_object->IsBox();
3862 }
3863 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3864 const CSSValue* MarginBlockStart::ParseSingleValue(
3865     CSSParserTokenRange& range,
3866     const CSSParserContext& context,
3867     const CSSParserLocalContext&) const {
3868   return css_parsing_utils::ConsumeMarginOrOffset(
3869       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
3870 }
3871 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3872 const CSSValue* MarginBottom::ParseSingleValue(
3873     CSSParserTokenRange& range,
3874     const CSSParserContext& context,
3875     const CSSParserLocalContext&) const {
3876   return css_parsing_utils::ConsumeMarginOrOffset(
3877       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
3878 }
3879 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3880 bool MarginBottom::IsLayoutDependent(const ComputedStyle* style,
3881                                      LayoutObject* layout_object) const {
3882   return layout_object && layout_object->IsBox() &&
3883          (!style || !style->MarginBottom().IsFixed());
3884 }
3885 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const3886 const CSSValue* MarginBottom::CSSValueFromComputedStyleInternal(
3887     const ComputedStyle& style,
3888     const SVGComputedStyle&,
3889     const LayoutObject* layout_object,
3890     bool allow_visited_style) const {
3891   const Length& margin_bottom = style.MarginBottom();
3892   if (margin_bottom.IsFixed() || !layout_object || !layout_object->IsBox()) {
3893     return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(margin_bottom,
3894                                                                style);
3895   }
3896   return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginBottom(),
3897                                 style);
3898 }
3899 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3900 bool MarginInlineEnd::IsLayoutDependent(const ComputedStyle* style,
3901                                         LayoutObject* layout_object) const {
3902   return layout_object && layout_object->IsBox();
3903 }
3904 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3905 const CSSValue* MarginInlineEnd::ParseSingleValue(
3906     CSSParserTokenRange& range,
3907     const CSSParserContext& context,
3908     const CSSParserLocalContext&) const {
3909   return css_parsing_utils::ConsumeMarginOrOffset(
3910       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
3911 }
3912 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3913 bool MarginInlineStart::IsLayoutDependent(const ComputedStyle* style,
3914                                           LayoutObject* layout_object) const {
3915   return layout_object && layout_object->IsBox();
3916 }
3917 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3918 const CSSValue* MarginInlineStart::ParseSingleValue(
3919     CSSParserTokenRange& range,
3920     const CSSParserContext& context,
3921     const CSSParserLocalContext&) const {
3922   return css_parsing_utils::ConsumeMarginOrOffset(
3923       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
3924 }
3925 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3926 const CSSValue* MarginLeft::ParseSingleValue(
3927     CSSParserTokenRange& range,
3928     const CSSParserContext& context,
3929     const CSSParserLocalContext&) const {
3930   return css_parsing_utils::ConsumeMarginOrOffset(
3931       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
3932 }
3933 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3934 bool MarginLeft::IsLayoutDependent(const ComputedStyle* style,
3935                                    LayoutObject* layout_object) const {
3936   return layout_object && layout_object->IsBox() &&
3937          (!style || !style->MarginLeft().IsFixed());
3938 }
3939 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const3940 const CSSValue* MarginLeft::CSSValueFromComputedStyleInternal(
3941     const ComputedStyle& style,
3942     const SVGComputedStyle&,
3943     const LayoutObject* layout_object,
3944     bool allow_visited_style) const {
3945   const Length& margin_left = style.MarginLeft();
3946   if (margin_left.IsFixed() || !layout_object || !layout_object->IsBox()) {
3947     return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(margin_left,
3948                                                                style);
3949   }
3950   return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginLeft(),
3951                                 style);
3952 }
3953 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3954 const CSSValue* MarginRight::ParseSingleValue(
3955     CSSParserTokenRange& range,
3956     const CSSParserContext& context,
3957     const CSSParserLocalContext&) const {
3958   return css_parsing_utils::ConsumeMarginOrOffset(
3959       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
3960 }
3961 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const3962 bool MarginRight::IsLayoutDependent(const ComputedStyle* style,
3963                                     LayoutObject* layout_object) const {
3964   return layout_object && layout_object->IsBox() &&
3965          (!style || !style->MarginRight().IsFixed());
3966 }
3967 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const3968 const CSSValue* MarginRight::CSSValueFromComputedStyleInternal(
3969     const ComputedStyle& style,
3970     const SVGComputedStyle&,
3971     const LayoutObject* layout_object,
3972     bool allow_visited_style) const {
3973   const Length& margin_right = style.MarginRight();
3974   if (margin_right.IsFixed() || !layout_object || !layout_object->IsBox()) {
3975     return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(margin_right,
3976                                                                style);
3977   }
3978   float value;
3979   if (margin_right.IsPercentOrCalc()) {
3980     // LayoutBox gives a marginRight() that is the distance between the
3981     // right-edge of the child box and the right-edge of the containing box,
3982     // when display == EDisplay::kBlock. Let's calculate the absolute value
3983     // of the specified margin-right % instead of relying on LayoutBox's
3984     // marginRight() value.
3985     value =
3986         MinimumValueForLength(
3987             margin_right,
3988             ToLayoutBox(layout_object)->ContainingBlockLogicalWidthForContent())
3989             .ToFloat();
3990   } else {
3991     value = ToLayoutBox(layout_object)->MarginRight().ToFloat();
3992   }
3993   return ZoomAdjustedPixelValue(value, style);
3994 }
3995 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const3996 const CSSValue* MarginTop::ParseSingleValue(
3997     CSSParserTokenRange& range,
3998     const CSSParserContext& context,
3999     const CSSParserLocalContext&) const {
4000   return css_parsing_utils::ConsumeMarginOrOffset(
4001       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
4002 }
4003 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4004 bool MarginTop::IsLayoutDependent(const ComputedStyle* style,
4005                                   LayoutObject* layout_object) const {
4006   return layout_object && layout_object->IsBox() &&
4007          (!style || !style->MarginTop().IsFixed());
4008 }
4009 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const4010 const CSSValue* MarginTop::CSSValueFromComputedStyleInternal(
4011     const ComputedStyle& style,
4012     const SVGComputedStyle&,
4013     const LayoutObject* layout_object,
4014     bool allow_visited_style) const {
4015   const Length& margin_top = style.MarginTop();
4016   if (margin_top.IsFixed() || !layout_object || !layout_object->IsBox()) {
4017     return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(margin_top,
4018                                                                style);
4019   }
4020   return ZoomAdjustedPixelValue(ToLayoutBox(layout_object)->MarginTop(), style);
4021 }
4022 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4023 const CSSValue* MarkerEnd::ParseSingleValue(
4024     CSSParserTokenRange& range,
4025     const CSSParserContext& context,
4026     const CSSParserLocalContext&) const {
4027   if (range.Peek().Id() == CSSValueID::kNone)
4028     return css_property_parser_helpers::ConsumeIdent(range);
4029   return css_property_parser_helpers::ConsumeUrl(range, context);
4030 }
4031 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const4032 const CSSValue* MarkerEnd::CSSValueFromComputedStyleInternal(
4033     const ComputedStyle& style,
4034     const SVGComputedStyle& svg_style,
4035     const LayoutObject*,
4036     bool allow_visited_style) const {
4037   return ComputedStyleUtils::ValueForSVGResource(svg_style.MarkerEndResource());
4038 }
4039 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4040 const CSSValue* MarkerMid::ParseSingleValue(
4041     CSSParserTokenRange& range,
4042     const CSSParserContext& context,
4043     const CSSParserLocalContext&) const {
4044   if (range.Peek().Id() == CSSValueID::kNone)
4045     return css_property_parser_helpers::ConsumeIdent(range);
4046   return css_property_parser_helpers::ConsumeUrl(range, context);
4047 }
4048 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const4049 const CSSValue* MarkerMid::CSSValueFromComputedStyleInternal(
4050     const ComputedStyle& style,
4051     const SVGComputedStyle& svg_style,
4052     const LayoutObject*,
4053     bool allow_visited_style) const {
4054   return ComputedStyleUtils::ValueForSVGResource(svg_style.MarkerMidResource());
4055 }
4056 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4057 const CSSValue* MarkerStart::ParseSingleValue(
4058     CSSParserTokenRange& range,
4059     const CSSParserContext& context,
4060     const CSSParserLocalContext&) const {
4061   if (range.Peek().Id() == CSSValueID::kNone)
4062     return css_property_parser_helpers::ConsumeIdent(range);
4063   return css_property_parser_helpers::ConsumeUrl(range, context);
4064 }
4065 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const4066 const CSSValue* MarkerStart::CSSValueFromComputedStyleInternal(
4067     const ComputedStyle& style,
4068     const SVGComputedStyle& svg_style,
4069     const LayoutObject*,
4070     bool allow_visited_style) const {
4071   return ComputedStyleUtils::ValueForSVGResource(
4072       svg_style.MarkerStartResource());
4073 }
4074 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4075 const CSSValue* Mask::ParseSingleValue(CSSParserTokenRange& range,
4076                                        const CSSParserContext& context,
4077                                        const CSSParserLocalContext&) const {
4078   if (range.Peek().Id() == CSSValueID::kNone)
4079     return css_property_parser_helpers::ConsumeIdent(range);
4080   return css_property_parser_helpers::ConsumeUrl(range, context);
4081 }
4082 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const4083 const CSSValue* Mask::CSSValueFromComputedStyleInternal(
4084     const ComputedStyle& style,
4085     const SVGComputedStyle& svg_style,
4086     const LayoutObject*,
4087     bool allow_visited_style) const {
4088   return ComputedStyleUtils::ValueForSVGResource(svg_style.MaskerResource());
4089 }
4090 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const4091 const CSSValue* MaskSourceType::ParseSingleValue(
4092     CSSParserTokenRange& range,
4093     const CSSParserContext&,
4094     const CSSParserLocalContext&) const {
4095   return css_property_parser_helpers::ConsumeCommaSeparatedList(
4096       css_parsing_utils::ConsumeMaskSourceType, range);
4097 }
4098 
ValueForFillSourceType(EMaskSourceType type)4099 static CSSValue* ValueForFillSourceType(EMaskSourceType type) {
4100   switch (type) {
4101     case EMaskSourceType::kAlpha:
4102       return CSSIdentifierValue::Create(CSSValueID::kAlpha);
4103     case EMaskSourceType::kLuminance:
4104       return CSSIdentifierValue::Create(CSSValueID::kLuminance);
4105   }
4106   NOTREACHED();
4107   return nullptr;
4108 }
4109 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4110 const CSSValue* MaskSourceType::CSSValueFromComputedStyleInternal(
4111     const ComputedStyle& style,
4112     const SVGComputedStyle&,
4113     const LayoutObject*,
4114     bool allow_visited_style) const {
4115   CSSValueList* list = CSSValueList::CreateCommaSeparated();
4116   for (const FillLayer* curr_layer = &style.MaskLayers(); curr_layer;
4117        curr_layer = curr_layer->Next())
4118     list->Append(*ValueForFillSourceType(curr_layer->MaskSourceType()));
4119   return list;
4120 }
4121 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const4122 const CSSValue* MaskType::CSSValueFromComputedStyleInternal(
4123     const ComputedStyle& style,
4124     const SVGComputedStyle& svg_style,
4125     const LayoutObject*,
4126     bool allow_visited_style) const {
4127   return CSSIdentifierValue::Create(svg_style.MaskType());
4128 }
4129 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4130 const CSSValue* MathStyle::CSSValueFromComputedStyleInternal(
4131     const ComputedStyle& style,
4132     const SVGComputedStyle&,
4133     const LayoutObject*,
4134     bool allow_visited_style) const {
4135   return CSSIdentifierValue::Create(style.MathStyle());
4136 }
4137 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4138 const CSSValue* MaxBlockSize::ParseSingleValue(
4139     CSSParserTokenRange& range,
4140     const CSSParserContext& context,
4141     const CSSParserLocalContext&) const {
4142   return css_parsing_utils::ConsumeMaxWidthOrHeight(range, context);
4143 }
4144 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4145 const CSSValue* MaxHeight::ParseSingleValue(
4146     CSSParserTokenRange& range,
4147     const CSSParserContext& context,
4148     const CSSParserLocalContext&) const {
4149   return css_parsing_utils::ConsumeMaxWidthOrHeight(
4150       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
4151 }
4152 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4153 const CSSValue* MaxHeight::CSSValueFromComputedStyleInternal(
4154     const ComputedStyle& style,
4155     const SVGComputedStyle&,
4156     const LayoutObject*,
4157     bool allow_visited_style) const {
4158   const Length& max_height = style.MaxHeight();
4159   if (max_height.IsNone())
4160     return CSSIdentifierValue::Create(CSSValueID::kNone);
4161   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(max_height, style);
4162 }
4163 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4164 const CSSValue* MaxInlineSize::ParseSingleValue(
4165     CSSParserTokenRange& range,
4166     const CSSParserContext& context,
4167     const CSSParserLocalContext&) const {
4168   return css_parsing_utils::ConsumeMaxWidthOrHeight(range, context);
4169 }
4170 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4171 const CSSValue* MaxWidth::ParseSingleValue(CSSParserTokenRange& range,
4172                                            const CSSParserContext& context,
4173                                            const CSSParserLocalContext&) const {
4174   return css_parsing_utils::ConsumeMaxWidthOrHeight(
4175       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
4176 }
4177 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4178 const CSSValue* MaxWidth::CSSValueFromComputedStyleInternal(
4179     const ComputedStyle& style,
4180     const SVGComputedStyle&,
4181     const LayoutObject*,
4182     bool allow_visited_style) const {
4183   const Length& max_width = style.MaxWidth();
4184   if (max_width.IsNone())
4185     return CSSIdentifierValue::Create(CSSValueID::kNone);
4186   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(max_width, style);
4187 }
4188 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4189 const CSSValue* MinBlockSize::ParseSingleValue(
4190     CSSParserTokenRange& range,
4191     const CSSParserContext& context,
4192     const CSSParserLocalContext&) const {
4193   return css_parsing_utils::ConsumeWidthOrHeight(range, context);
4194 }
4195 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4196 const CSSValue* MinHeight::ParseSingleValue(
4197     CSSParserTokenRange& range,
4198     const CSSParserContext& context,
4199     const CSSParserLocalContext&) const {
4200   return css_parsing_utils::ConsumeWidthOrHeight(
4201       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
4202 }
4203 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const4204 const CSSValue* MinHeight::CSSValueFromComputedStyleInternal(
4205     const ComputedStyle& style,
4206     const SVGComputedStyle&,
4207     const LayoutObject* layout_object,
4208     bool allow_visited_style) const {
4209   if (style.MinHeight().IsAuto())
4210     return ComputedStyleUtils::MinWidthOrMinHeightAuto(style);
4211   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(style.MinHeight(),
4212                                                              style);
4213 }
4214 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4215 const CSSValue* MinInlineSize::ParseSingleValue(
4216     CSSParserTokenRange& range,
4217     const CSSParserContext& context,
4218     const CSSParserLocalContext&) const {
4219   return css_parsing_utils::ConsumeWidthOrHeight(range, context);
4220 }
4221 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4222 const CSSValue* MinWidth::ParseSingleValue(CSSParserTokenRange& range,
4223                                            const CSSParserContext& context,
4224                                            const CSSParserLocalContext&) const {
4225   return css_parsing_utils::ConsumeWidthOrHeight(
4226       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
4227 }
4228 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const4229 const CSSValue* MinWidth::CSSValueFromComputedStyleInternal(
4230     const ComputedStyle& style,
4231     const SVGComputedStyle&,
4232     const LayoutObject* layout_object,
4233     bool allow_visited_style) const {
4234   if (style.MinWidth().IsAuto())
4235     return ComputedStyleUtils::MinWidthOrMinHeightAuto(style);
4236   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(style.MinWidth(),
4237                                                              style);
4238 }
4239 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4240 const CSSValue* MixBlendMode::CSSValueFromComputedStyleInternal(
4241     const ComputedStyle& style,
4242     const SVGComputedStyle&,
4243     const LayoutObject*,
4244     bool allow_visited_style) const {
4245   return CSSIdentifierValue::Create(style.GetBlendMode());
4246 }
4247 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4248 const CSSValue* ObjectFit::CSSValueFromComputedStyleInternal(
4249     const ComputedStyle& style,
4250     const SVGComputedStyle&,
4251     const LayoutObject*,
4252     bool allow_visited_style) const {
4253   return CSSIdentifierValue::Create(style.GetObjectFit());
4254 }
4255 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4256 const CSSValue* ObjectPosition::ParseSingleValue(
4257     CSSParserTokenRange& range,
4258     const CSSParserContext& context,
4259     const CSSParserLocalContext&) const {
4260   return ConsumePosition(range, context,
4261                          css_property_parser_helpers::UnitlessQuirk::kForbid,
4262                          base::Optional<WebFeature>());
4263 }
4264 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4265 const CSSValue* ObjectPosition::CSSValueFromComputedStyleInternal(
4266     const ComputedStyle& style,
4267     const SVGComputedStyle&,
4268     const LayoutObject*,
4269     bool allow_visited_style) const {
4270   return MakeGarbageCollected<CSSValuePair>(
4271       ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
4272           style.ObjectPosition().X(), style),
4273       ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
4274           style.ObjectPosition().Y(), style),
4275       CSSValuePair::kKeepIdenticalValues);
4276 }
4277 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4278 const CSSValue* OffsetAnchor::ParseSingleValue(
4279     CSSParserTokenRange& range,
4280     const CSSParserContext& context,
4281     const CSSParserLocalContext&) const {
4282   CSSValueID id = range.Peek().Id();
4283   if (id == CSSValueID::kAuto)
4284     return css_property_parser_helpers::ConsumeIdent(range);
4285   return css_property_parser_helpers::ConsumePosition(
4286       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid,
4287       base::Optional<WebFeature>());
4288 }
4289 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4290 const CSSValue* OffsetAnchor::CSSValueFromComputedStyleInternal(
4291     const ComputedStyle& style,
4292     const SVGComputedStyle&,
4293     const LayoutObject*,
4294     bool allow_visited_style) const {
4295   return ComputedStyleUtils::ValueForPosition(style.OffsetAnchor(), style);
4296 }
4297 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4298 const CSSValue* OffsetDistance::ParseSingleValue(
4299     CSSParserTokenRange& range,
4300     const CSSParserContext& context,
4301     const CSSParserLocalContext&) const {
4302   return css_property_parser_helpers::ConsumeLengthOrPercent(range, context,
4303                                                              kValueRangeAll);
4304 }
4305 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4306 const CSSValue* OffsetDistance::CSSValueFromComputedStyleInternal(
4307     const ComputedStyle& style,
4308     const SVGComputedStyle&,
4309     const LayoutObject*,
4310     bool allow_visited_style) const {
4311   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
4312       style.OffsetDistance(), style);
4313 }
4314 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4315 const CSSValue* OffsetPath::ParseSingleValue(
4316     CSSParserTokenRange& range,
4317     const CSSParserContext& context,
4318     const CSSParserLocalContext&) const {
4319   return css_parsing_utils::ConsumeOffsetPath(range, context);
4320 }
4321 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4322 const CSSValue* OffsetPath::CSSValueFromComputedStyleInternal(
4323     const ComputedStyle& style,
4324     const SVGComputedStyle&,
4325     const LayoutObject*,
4326     bool allow_visited_style) const {
4327   if (const BasicShape* style_motion_path = style.OffsetPath())
4328     return ValueForBasicShape(style, style_motion_path);
4329   return CSSIdentifierValue::Create(CSSValueID::kNone);
4330 }
4331 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4332 const CSSValue* OffsetPosition::ParseSingleValue(
4333     CSSParserTokenRange& range,
4334     const CSSParserContext& context,
4335     const CSSParserLocalContext&) const {
4336   CSSValueID id = range.Peek().Id();
4337   if (id == CSSValueID::kAuto)
4338     return css_property_parser_helpers::ConsumeIdent(range);
4339   CSSValue* value = css_property_parser_helpers::ConsumePosition(
4340       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid,
4341       base::Optional<WebFeature>());
4342 
4343   // Count when we receive a valid position other than 'auto'.
4344   if (value && value->IsValuePair())
4345     context.Count(WebFeature::kCSSOffsetInEffect);
4346   return value;
4347 }
4348 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4349 const CSSValue* OffsetPosition::CSSValueFromComputedStyleInternal(
4350     const ComputedStyle& style,
4351     const SVGComputedStyle&,
4352     const LayoutObject*,
4353     bool allow_visited_style) const {
4354   return ComputedStyleUtils::ValueForPosition(style.OffsetPosition(), style);
4355 }
4356 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4357 const CSSValue* OffsetRotate::ParseSingleValue(
4358     CSSParserTokenRange& range,
4359     const CSSParserContext& context,
4360     const CSSParserLocalContext&) const {
4361   return css_parsing_utils::ConsumeOffsetRotate(range, context);
4362 }
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4363 const CSSValue* OffsetRotate::CSSValueFromComputedStyleInternal(
4364     const ComputedStyle& style,
4365     const SVGComputedStyle&,
4366     const LayoutObject*,
4367     bool allow_visited_style) const {
4368   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
4369   if (style.OffsetRotate().type == OffsetRotationType::kAuto)
4370     list->Append(*CSSIdentifierValue::Create(CSSValueID::kAuto));
4371   list->Append(*CSSNumericLiteralValue::Create(
4372       style.OffsetRotate().angle, CSSPrimitiveValue::UnitType::kDegrees));
4373   return list;
4374 }
4375 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4376 const CSSValue* Opacity::ParseSingleValue(CSSParserTokenRange& range,
4377                                           const CSSParserContext& context,
4378                                           const CSSParserLocalContext&) const {
4379   return css_property_parser_helpers::ConsumeAlphaValue(range, context);
4380 }
4381 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4382 const CSSValue* Opacity::CSSValueFromComputedStyleInternal(
4383     const ComputedStyle& style,
4384     const SVGComputedStyle&,
4385     const LayoutObject*,
4386     bool allow_visited_style) const {
4387   return CSSNumericLiteralValue::Create(style.Opacity(),
4388                                         CSSPrimitiveValue::UnitType::kNumber);
4389 }
4390 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4391 const CSSValue* Order::ParseSingleValue(CSSParserTokenRange& range,
4392                                         const CSSParserContext& context,
4393                                         const CSSParserLocalContext&) const {
4394   return css_property_parser_helpers::ConsumeInteger(range, context);
4395 }
4396 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4397 const CSSValue* Order::CSSValueFromComputedStyleInternal(
4398     const ComputedStyle& style,
4399     const SVGComputedStyle&,
4400     const LayoutObject*,
4401     bool allow_visited_style) const {
4402   return CSSNumericLiteralValue::Create(style.Order(),
4403                                         CSSPrimitiveValue::UnitType::kNumber);
4404 }
4405 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4406 const CSSValue* OriginTrialTestProperty::CSSValueFromComputedStyleInternal(
4407     const ComputedStyle& style,
4408     const SVGComputedStyle&,
4409     const LayoutObject*,
4410     bool allow_visited_style) const {
4411   return CSSIdentifierValue::Create(style.OriginTrialTestProperty());
4412   ;
4413 }
4414 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4415 const CSSValue* Orphans::ParseSingleValue(CSSParserTokenRange& range,
4416                                           const CSSParserContext& context,
4417                                           const CSSParserLocalContext&) const {
4418   return css_property_parser_helpers::ConsumePositiveInteger(range, context);
4419 }
4420 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4421 const CSSValue* Orphans::CSSValueFromComputedStyleInternal(
4422     const ComputedStyle& style,
4423     const SVGComputedStyle&,
4424     const LayoutObject*,
4425     bool allow_visited_style) const {
4426   return CSSNumericLiteralValue::Create(style.Orphans(),
4427                                         CSSPrimitiveValue::UnitType::kNumber);
4428 }
4429 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4430 const CSSValue* OutlineColor::ParseSingleValue(
4431     CSSParserTokenRange& range,
4432     const CSSParserContext& context,
4433     const CSSParserLocalContext&) const {
4434   // Allow the special focus color even in HTML Standard parsing mode.
4435   if (range.Peek().Id() == CSSValueID::kWebkitFocusRingColor)
4436     return css_property_parser_helpers::ConsumeIdent(range);
4437   return css_property_parser_helpers::ConsumeColor(range, context);
4438 }
4439 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const4440 const blink::Color OutlineColor::ColorIncludingFallback(
4441     bool visited_link,
4442     const ComputedStyle& style) const {
4443   DCHECK(!visited_link);
4444   return style.OutlineColor().Resolve(style.GetColor());
4445 }
4446 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4447 const CSSValue* OutlineColor::CSSValueFromComputedStyleInternal(
4448     const ComputedStyle& style,
4449     const SVGComputedStyle&,
4450     const LayoutObject*,
4451     bool allow_visited_style) const {
4452   return allow_visited_style ? cssvalue::CSSColorValue::Create(
4453                                    style.VisitedDependentColor(*this).Rgb())
4454                              : ComputedStyleUtils::CurrentColorOrValidColor(
4455                                    style, style.OutlineColor());
4456 }
4457 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4458 const CSSValue* OutlineOffset::ParseSingleValue(
4459     CSSParserTokenRange& range,
4460     const CSSParserContext& context,
4461     const CSSParserLocalContext&) const {
4462   return css_property_parser_helpers::ConsumeLength(range, context,
4463                                                     kValueRangeAll);
4464 }
4465 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4466 const CSSValue* OutlineOffset::CSSValueFromComputedStyleInternal(
4467     const ComputedStyle& style,
4468     const SVGComputedStyle&,
4469     const LayoutObject*,
4470     bool allow_visited_style) const {
4471   return ZoomAdjustedPixelValue(style.OutlineOffset(), style);
4472 }
4473 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4474 const CSSValue* OutlineStyle::CSSValueFromComputedStyleInternal(
4475     const ComputedStyle& style,
4476     const SVGComputedStyle&,
4477     const LayoutObject*,
4478     bool allow_visited_style) const {
4479   if (style.OutlineStyleIsAuto())
4480     return CSSIdentifierValue::Create(CSSValueID::kAuto);
4481   return CSSIdentifierValue::Create(style.OutlineStyle());
4482 }
4483 
ApplyInitial(StyleResolverState & state) const4484 void OutlineStyle::ApplyInitial(StyleResolverState& state) const {
4485   state.Style()->SetOutlineStyleIsAuto(
4486       ComputedStyleInitialValues::InitialOutlineStyleIsAuto());
4487   state.Style()->SetOutlineStyle(EBorderStyle::kNone);
4488 }
4489 
ApplyInherit(StyleResolverState & state) const4490 void OutlineStyle::ApplyInherit(StyleResolverState& state) const {
4491   state.Style()->SetOutlineStyleIsAuto(
4492       state.ParentStyle()->OutlineStyleIsAuto());
4493   state.Style()->SetOutlineStyle(state.ParentStyle()->OutlineStyle());
4494 }
4495 
ApplyValue(StyleResolverState & state,const CSSValue & value) const4496 void OutlineStyle::ApplyValue(StyleResolverState& state,
4497                               const CSSValue& value) const {
4498   const auto& identifier_value = To<CSSIdentifierValue>(value);
4499   state.Style()->SetOutlineStyleIsAuto(
4500       static_cast<bool>(identifier_value.ConvertTo<OutlineIsAuto>()));
4501   state.Style()->SetOutlineStyle(identifier_value.ConvertTo<EBorderStyle>());
4502 }
4503 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4504 const CSSValue* OutlineWidth::ParseSingleValue(
4505     CSSParserTokenRange& range,
4506     const CSSParserContext& context,
4507     const CSSParserLocalContext&) const {
4508   return css_property_parser_helpers::ConsumeLineWidth(
4509       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
4510 }
4511 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4512 const CSSValue* OutlineWidth::CSSValueFromComputedStyleInternal(
4513     const ComputedStyle& style,
4514     const SVGComputedStyle&,
4515     const LayoutObject*,
4516     bool allow_visited_style) const {
4517   return ZoomAdjustedPixelValue(style.OutlineWidth(), style);
4518 }
4519 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4520 const CSSValue* OverflowAnchor::CSSValueFromComputedStyleInternal(
4521     const ComputedStyle& style,
4522     const SVGComputedStyle&,
4523     const LayoutObject*,
4524     bool allow_visited_style) const {
4525   return CSSIdentifierValue::Create(style.OverflowAnchor());
4526 }
4527 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4528 const CSSValue* OverflowWrap::CSSValueFromComputedStyleInternal(
4529     const ComputedStyle& style,
4530     const SVGComputedStyle&,
4531     const LayoutObject*,
4532     bool allow_visited_style) const {
4533   return CSSIdentifierValue::Create(style.OverflowWrap());
4534 }
4535 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4536 const CSSValue* OverflowX::CSSValueFromComputedStyleInternal(
4537     const ComputedStyle& style,
4538     const SVGComputedStyle&,
4539     const LayoutObject*,
4540     bool allow_visited_style) const {
4541   return CSSIdentifierValue::Create(style.OverflowX());
4542 }
4543 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4544 const CSSValue* OverflowY::CSSValueFromComputedStyleInternal(
4545     const ComputedStyle& style,
4546     const SVGComputedStyle&,
4547     const LayoutObject*,
4548     bool allow_visited_style) const {
4549   return CSSIdentifierValue::Create(style.OverflowY());
4550 }
4551 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4552 const CSSValue* OverscrollBehaviorX::CSSValueFromComputedStyleInternal(
4553     const ComputedStyle& style,
4554     const SVGComputedStyle&,
4555     const LayoutObject*,
4556     bool allow_visited_style) const {
4557   return CSSIdentifierValue::Create(style.OverscrollBehaviorX());
4558 }
4559 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4560 const CSSValue* OverscrollBehaviorY::CSSValueFromComputedStyleInternal(
4561     const ComputedStyle& style,
4562     const SVGComputedStyle&,
4563     const LayoutObject*,
4564     bool allow_visited_style) const {
4565   return CSSIdentifierValue::Create(style.OverscrollBehaviorY());
4566 }
4567 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4568 bool PaddingBlockEnd::IsLayoutDependent(const ComputedStyle* style,
4569                                         LayoutObject* layout_object) const {
4570   return layout_object && layout_object->IsBox();
4571 }
4572 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4573 const CSSValue* PaddingBlockEnd::ParseSingleValue(
4574     CSSParserTokenRange& range,
4575     const CSSParserContext& context,
4576     const CSSParserLocalContext&) const {
4577   return ConsumeLengthOrPercent(
4578       range, context, kValueRangeNonNegative,
4579       css_property_parser_helpers::UnitlessQuirk::kForbid);
4580 }
4581 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4582 bool PaddingBlockStart::IsLayoutDependent(const ComputedStyle* style,
4583                                           LayoutObject* layout_object) const {
4584   return layout_object && layout_object->IsBox();
4585 }
4586 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4587 const CSSValue* PaddingBlockStart::ParseSingleValue(
4588     CSSParserTokenRange& range,
4589     const CSSParserContext& context,
4590     const CSSParserLocalContext&) const {
4591   return ConsumeLengthOrPercent(
4592       range, context, kValueRangeNonNegative,
4593       css_property_parser_helpers::UnitlessQuirk::kForbid);
4594 }
4595 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4596 const CSSValue* PaddingBottom::ParseSingleValue(
4597     CSSParserTokenRange& range,
4598     const CSSParserContext& context,
4599     const CSSParserLocalContext&) const {
4600   return ConsumeLengthOrPercent(
4601       range, context, kValueRangeNonNegative,
4602       css_property_parser_helpers::UnitlessQuirk::kAllow);
4603 }
4604 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4605 bool PaddingBottom::IsLayoutDependent(const ComputedStyle* style,
4606                                       LayoutObject* layout_object) const {
4607   return layout_object && layout_object->IsBox() &&
4608          (!style || !style->PaddingBottom().IsFixed());
4609 }
4610 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const4611 const CSSValue* PaddingBottom::CSSValueFromComputedStyleInternal(
4612     const ComputedStyle& style,
4613     const SVGComputedStyle&,
4614     const LayoutObject* layout_object,
4615     bool allow_visited_style) const {
4616   const Length& padding_bottom = style.PaddingBottom();
4617   if (padding_bottom.IsFixed() || !layout_object || !layout_object->IsBox()) {
4618     return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(padding_bottom,
4619                                                                style);
4620   }
4621   return ZoomAdjustedPixelValue(
4622       ToLayoutBox(layout_object)->ComputedCSSPaddingBottom(), style);
4623 }
4624 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4625 bool PaddingInlineEnd::IsLayoutDependent(const ComputedStyle* style,
4626                                          LayoutObject* layout_object) const {
4627   return layout_object && layout_object->IsBox();
4628 }
4629 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4630 const CSSValue* PaddingInlineEnd::ParseSingleValue(
4631     CSSParserTokenRange& range,
4632     const CSSParserContext& context,
4633     const CSSParserLocalContext&) const {
4634   return ConsumeLengthOrPercent(
4635       range, context, kValueRangeNonNegative,
4636       css_property_parser_helpers::UnitlessQuirk::kForbid);
4637 }
4638 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4639 bool PaddingInlineStart::IsLayoutDependent(const ComputedStyle* style,
4640                                            LayoutObject* layout_object) const {
4641   return layout_object && layout_object->IsBox();
4642 }
4643 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4644 const CSSValue* PaddingInlineStart::ParseSingleValue(
4645     CSSParserTokenRange& range,
4646     const CSSParserContext& context,
4647     const CSSParserLocalContext&) const {
4648   return ConsumeLengthOrPercent(
4649       range, context, kValueRangeNonNegative,
4650       css_property_parser_helpers::UnitlessQuirk::kForbid);
4651 }
4652 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4653 const CSSValue* PaddingLeft::ParseSingleValue(
4654     CSSParserTokenRange& range,
4655     const CSSParserContext& context,
4656     const CSSParserLocalContext&) const {
4657   return ConsumeLengthOrPercent(
4658       range, context, kValueRangeNonNegative,
4659       css_property_parser_helpers::UnitlessQuirk::kAllow);
4660 }
4661 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4662 bool PaddingLeft::IsLayoutDependent(const ComputedStyle* style,
4663                                     LayoutObject* layout_object) const {
4664   return layout_object && layout_object->IsBox() &&
4665          (!style || !style->PaddingLeft().IsFixed());
4666 }
4667 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const4668 const CSSValue* PaddingLeft::CSSValueFromComputedStyleInternal(
4669     const ComputedStyle& style,
4670     const SVGComputedStyle&,
4671     const LayoutObject* layout_object,
4672     bool allow_visited_style) const {
4673   const Length& padding_left = style.PaddingLeft();
4674   if (padding_left.IsFixed() || !layout_object || !layout_object->IsBox()) {
4675     return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(padding_left,
4676                                                                style);
4677   }
4678   return ZoomAdjustedPixelValue(
4679       ToLayoutBox(layout_object)->ComputedCSSPaddingLeft(), style);
4680 }
4681 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4682 const CSSValue* PaddingRight::ParseSingleValue(
4683     CSSParserTokenRange& range,
4684     const CSSParserContext& context,
4685     const CSSParserLocalContext&) const {
4686   return ConsumeLengthOrPercent(
4687       range, context, kValueRangeNonNegative,
4688       css_property_parser_helpers::UnitlessQuirk::kAllow);
4689 }
4690 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4691 bool PaddingRight::IsLayoutDependent(const ComputedStyle* style,
4692                                      LayoutObject* layout_object) const {
4693   return layout_object && layout_object->IsBox() &&
4694          (!style || !style->PaddingRight().IsFixed());
4695 }
4696 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const4697 const CSSValue* PaddingRight::CSSValueFromComputedStyleInternal(
4698     const ComputedStyle& style,
4699     const SVGComputedStyle&,
4700     const LayoutObject* layout_object,
4701     bool allow_visited_style) const {
4702   const Length& padding_right = style.PaddingRight();
4703   if (padding_right.IsFixed() || !layout_object || !layout_object->IsBox()) {
4704     return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(padding_right,
4705                                                                style);
4706   }
4707   return ZoomAdjustedPixelValue(
4708       ToLayoutBox(layout_object)->ComputedCSSPaddingRight(), style);
4709 }
4710 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4711 const CSSValue* PaddingTop::ParseSingleValue(
4712     CSSParserTokenRange& range,
4713     const CSSParserContext& context,
4714     const CSSParserLocalContext&) const {
4715   return ConsumeLengthOrPercent(
4716       range, context, kValueRangeNonNegative,
4717       css_property_parser_helpers::UnitlessQuirk::kAllow);
4718 }
4719 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4720 bool PaddingTop::IsLayoutDependent(const ComputedStyle* style,
4721                                    LayoutObject* layout_object) const {
4722   return layout_object && layout_object->IsBox() &&
4723          (!style || !style->PaddingTop().IsFixed());
4724 }
4725 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const4726 const CSSValue* PaddingTop::CSSValueFromComputedStyleInternal(
4727     const ComputedStyle& style,
4728     const SVGComputedStyle&,
4729     const LayoutObject* layout_object,
4730     bool allow_visited_style) const {
4731   const Length& padding_top = style.PaddingTop();
4732   if (padding_top.IsFixed() || !layout_object || !layout_object->IsBox()) {
4733     return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(padding_top,
4734                                                                style);
4735   }
4736   return ZoomAdjustedPixelValue(
4737       ToLayoutBox(layout_object)->ComputedCSSPaddingTop(), style);
4738 }
4739 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4740 const CSSValue* Page::ParseSingleValue(CSSParserTokenRange& range,
4741                                        const CSSParserContext& context,
4742                                        const CSSParserLocalContext&) const {
4743   if (range.Peek().Id() == CSSValueID::kAuto)
4744     return css_property_parser_helpers::ConsumeIdent(range);
4745   return css_property_parser_helpers::ConsumeCustomIdent(range, context);
4746 }
4747 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4748 const CSSValue* Page::CSSValueFromComputedStyleInternal(
4749     const ComputedStyle& style,
4750     const SVGComputedStyle&,
4751     const LayoutObject*,
4752     bool allow_visited_style) const {
4753   if (style.Page().IsNull())
4754     return CSSIdentifierValue::Create(CSSValueID::kAuto);
4755   return MakeGarbageCollected<CSSCustomIdentValue>(style.Page());
4756 }
4757 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4758 const CSSValue* PaintOrder::ParseSingleValue(
4759     CSSParserTokenRange& range,
4760     const CSSParserContext& context,
4761     const CSSParserLocalContext&) const {
4762   if (range.Peek().Id() == CSSValueID::kNormal)
4763     return css_property_parser_helpers::ConsumeIdent(range);
4764 
4765   Vector<CSSValueID, 3> paint_type_list;
4766   CSSIdentifierValue* fill = nullptr;
4767   CSSIdentifierValue* stroke = nullptr;
4768   CSSIdentifierValue* markers = nullptr;
4769   do {
4770     CSSValueID id = range.Peek().Id();
4771     if (id == CSSValueID::kFill && !fill)
4772       fill = css_property_parser_helpers::ConsumeIdent(range);
4773     else if (id == CSSValueID::kStroke && !stroke)
4774       stroke = css_property_parser_helpers::ConsumeIdent(range);
4775     else if (id == CSSValueID::kMarkers && !markers)
4776       markers = css_property_parser_helpers::ConsumeIdent(range);
4777     else
4778       return nullptr;
4779     paint_type_list.push_back(id);
4780   } while (!range.AtEnd());
4781 
4782   // After parsing we serialize the paint-order list. Since it is not possible
4783   // to pop a last list items from CSSValueList without bigger cost, we create
4784   // the list after parsing.
4785   CSSValueID first_paint_order_type = paint_type_list.at(0);
4786   CSSValueList* paint_order_list = CSSValueList::CreateSpaceSeparated();
4787   switch (first_paint_order_type) {
4788     case CSSValueID::kFill:
4789     case CSSValueID::kStroke:
4790       paint_order_list->Append(
4791           first_paint_order_type == CSSValueID::kFill ? *fill : *stroke);
4792       if (paint_type_list.size() > 1) {
4793         if (paint_type_list.at(1) == CSSValueID::kMarkers)
4794           paint_order_list->Append(*markers);
4795       }
4796       break;
4797     case CSSValueID::kMarkers:
4798       paint_order_list->Append(*markers);
4799       if (paint_type_list.size() > 1) {
4800         if (paint_type_list.at(1) == CSSValueID::kStroke)
4801           paint_order_list->Append(*stroke);
4802       }
4803       break;
4804     default:
4805       NOTREACHED();
4806   }
4807 
4808   return paint_order_list;
4809 }
4810 
CSSValueFromComputedStyleInternal(const ComputedStyle &,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const4811 const CSSValue* PaintOrder::CSSValueFromComputedStyleInternal(
4812     const ComputedStyle&,
4813     const SVGComputedStyle& svg_style,
4814     const LayoutObject*,
4815     bool allow_visited_style) const {
4816   const EPaintOrder paint_order = svg_style.PaintOrder();
4817   if (paint_order == kPaintOrderNormal)
4818     return CSSIdentifierValue::Create(CSSValueID::kNormal);
4819 
4820   // Table mapping to the shortest (canonical) form of the property.
4821   //
4822   // Per spec, if any keyword is omitted it will be added last using
4823   // the standard ordering. So "stroke" implies an order "stroke fill
4824   // markers" etc. From a serialization PoV this means we never need
4825   // to emit the last keyword.
4826   //
4827   // https://svgwg.org/svg2-draft/painting.html#PaintOrder
4828   static const uint8_t canonical_form[][2] = {
4829       // kPaintOrderNormal is handled above.
4830       {PT_FILL, PT_NONE},       // kPaintOrderFillStrokeMarkers
4831       {PT_FILL, PT_MARKERS},    // kPaintOrderFillMarkersStroke
4832       {PT_STROKE, PT_NONE},     // kPaintOrderStrokeFillMarkers
4833       {PT_STROKE, PT_MARKERS},  // kPaintOrderStrokeMarkersFill
4834       {PT_MARKERS, PT_NONE},    // kPaintOrderMarkersFillStroke
4835       {PT_MARKERS, PT_STROKE},  // kPaintOrderMarkersStrokeFill
4836   };
4837   DCHECK_LT(static_cast<size_t>(paint_order) - 1, base::size(canonical_form));
4838   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
4839   for (const auto& keyword : canonical_form[paint_order - 1]) {
4840     const auto paint_order_type = static_cast<EPaintOrderType>(keyword);
4841     if (paint_order_type == PT_NONE)
4842       break;
4843     list->Append(*CSSIdentifierValue::Create(paint_order_type));
4844   }
4845   return list;
4846 }
4847 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & localContext) const4848 const CSSValue* Perspective::ParseSingleValue(
4849     CSSParserTokenRange& range,
4850     const CSSParserContext& context,
4851     const CSSParserLocalContext& localContext) const {
4852   if (range.Peek().Id() == CSSValueID::kNone)
4853     return css_property_parser_helpers::ConsumeIdent(range);
4854   CSSPrimitiveValue* parsed_value = css_property_parser_helpers::ConsumeLength(
4855       range, context, kValueRangeAll);
4856   bool use_legacy_parsing = localContext.UseAliasParsing();
4857   if (!parsed_value && use_legacy_parsing) {
4858     double perspective;
4859     if (!css_property_parser_helpers::ConsumeNumberRaw(range, context,
4860                                                        perspective))
4861       return nullptr;
4862     context.Count(WebFeature::kUnitlessPerspectiveInPerspectiveProperty);
4863     parsed_value = CSSNumericLiteralValue::Create(
4864         perspective, CSSPrimitiveValue::UnitType::kPixels);
4865   }
4866   if (parsed_value &&
4867       (parsed_value->IsCalculated() || parsed_value->GetDoubleValue() > 0))
4868     return parsed_value;
4869   return nullptr;
4870 }
4871 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4872 const CSSValue* Perspective::CSSValueFromComputedStyleInternal(
4873     const ComputedStyle& style,
4874     const SVGComputedStyle&,
4875     const LayoutObject*,
4876     bool allow_visited_style) const {
4877   if (!style.HasPerspective())
4878     return CSSIdentifierValue::Create(CSSValueID::kNone);
4879   return ZoomAdjustedPixelValue(style.Perspective(), style);
4880 }
4881 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4882 const CSSValue* PerspectiveOrigin::ParseSingleValue(
4883     CSSParserTokenRange& range,
4884     const CSSParserContext& context,
4885     const CSSParserLocalContext&) const {
4886   return ConsumePosition(range, context,
4887                          css_property_parser_helpers::UnitlessQuirk::kForbid,
4888                          base::Optional<WebFeature>());
4889 }
4890 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const4891 bool PerspectiveOrigin::IsLayoutDependent(const ComputedStyle* style,
4892                                           LayoutObject* layout_object) const {
4893   return layout_object && layout_object->IsBox();
4894 }
4895 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const4896 const CSSValue* PerspectiveOrigin::CSSValueFromComputedStyleInternal(
4897     const ComputedStyle& style,
4898     const SVGComputedStyle&,
4899     const LayoutObject* layout_object,
4900     bool allow_visited_style) const {
4901   if (layout_object) {
4902     LayoutRect box;
4903     if (layout_object->IsBox())
4904       box = ToLayoutBox(layout_object)->BorderBoxRect();
4905 
4906     return MakeGarbageCollected<CSSValuePair>(
4907         ZoomAdjustedPixelValue(
4908             MinimumValueForLength(style.PerspectiveOriginX(), box.Width()),
4909             style),
4910         ZoomAdjustedPixelValue(
4911             MinimumValueForLength(style.PerspectiveOriginY(), box.Height()),
4912             style),
4913         CSSValuePair::kKeepIdenticalValues);
4914   } else {
4915     return MakeGarbageCollected<CSSValuePair>(
4916         ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
4917             style.PerspectiveOriginX(), style),
4918         ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
4919             style.PerspectiveOriginY(), style),
4920         CSSValuePair::kKeepIdenticalValues);
4921   }
4922 }
4923 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4924 const CSSValue* PointerEvents::CSSValueFromComputedStyleInternal(
4925     const ComputedStyle& style,
4926     const SVGComputedStyle&,
4927     const LayoutObject*,
4928     bool allow_visited_style) const {
4929   return CSSIdentifierValue::Create(style.PointerEvents());
4930 }
4931 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4932 const CSSValue* Position::CSSValueFromComputedStyleInternal(
4933     const ComputedStyle& style,
4934     const SVGComputedStyle&,
4935     const LayoutObject*,
4936     bool allow_visited_style) const {
4937   return CSSIdentifierValue::Create(style.GetPosition());
4938 }
4939 
ApplyInherit(StyleResolverState & state) const4940 void Position::ApplyInherit(StyleResolverState& state) const {
4941   if (!state.ParentNode()->IsDocumentNode())
4942     state.Style()->SetPosition(state.ParentStyle()->GetPosition());
4943 }
4944 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4945 const CSSValue* Quotes::ParseSingleValue(CSSParserTokenRange& range,
4946                                          const CSSParserContext& context,
4947                                          const CSSParserLocalContext&) const {
4948   if (range.Peek().Id() == CSSValueID::kNone)
4949     return css_property_parser_helpers::ConsumeIdent(range);
4950   CSSValueList* values = CSSValueList::CreateSpaceSeparated();
4951   while (!range.AtEnd()) {
4952     CSSStringValue* parsed_value =
4953         css_property_parser_helpers::ConsumeString(range);
4954     if (!parsed_value)
4955       return nullptr;
4956     values->Append(*parsed_value);
4957   }
4958   if (values->length() && values->length() % 2 == 0)
4959     return values;
4960   return nullptr;
4961 }
4962 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const4963 const CSSValue* Quotes::CSSValueFromComputedStyleInternal(
4964     const ComputedStyle& style,
4965     const SVGComputedStyle&,
4966     const LayoutObject*,
4967     bool allow_visited_style) const {
4968   if (!style.Quotes()) {
4969     // TODO(ramya.v): We should return the quote values that we're actually
4970     // using.
4971     return nullptr;
4972   }
4973   if (style.Quotes()->size()) {
4974     CSSValueList* list = CSSValueList::CreateSpaceSeparated();
4975     for (int i = 0; i < style.Quotes()->size(); i++) {
4976       list->Append(*MakeGarbageCollected<CSSStringValue>(
4977           style.Quotes()->GetOpenQuote(i)));
4978       list->Append(*MakeGarbageCollected<CSSStringValue>(
4979           style.Quotes()->GetCloseQuote(i)));
4980     }
4981     return list;
4982   }
4983   return CSSIdentifierValue::Create(CSSValueID::kNone);
4984 }
4985 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const4986 const CSSValue* R::ParseSingleValue(CSSParserTokenRange& range,
4987                                     const CSSParserContext& context,
4988                                     const CSSParserLocalContext&) const {
4989   return css_property_parser_helpers::ConsumeSVGGeometryPropertyLength(
4990       range, context, kValueRangeNonNegative);
4991 }
4992 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const4993 const CSSValue* R::CSSValueFromComputedStyleInternal(
4994     const ComputedStyle& style,
4995     const SVGComputedStyle& svg_style,
4996     const LayoutObject*,
4997     bool allow_visited_style) const {
4998   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(svg_style.R(),
4999                                                              style);
5000 }
5001 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5002 const CSSValue* Resize::CSSValueFromComputedStyleInternal(
5003     const ComputedStyle& style,
5004     const SVGComputedStyle&,
5005     const LayoutObject*,
5006     bool allow_visited_style) const {
5007   return CSSIdentifierValue::Create(style.Resize());
5008 }
5009 
ApplyValue(StyleResolverState & state,const CSSValue & value) const5010 void Resize::ApplyValue(StyleResolverState& state,
5011                         const CSSValue& value) const {
5012   const CSSIdentifierValue& identifier_value = To<CSSIdentifierValue>(value);
5013 
5014   EResize r = EResize::kNone;
5015   if (identifier_value.GetValueID() == CSSValueID::kAuto) {
5016     if (Settings* settings = state.GetDocument().GetSettings()) {
5017       r = settings->GetTextAreasAreResizable() ? EResize::kBoth
5018                                                : EResize::kNone;
5019     }
5020     UseCounter::Count(state.GetDocument(), WebFeature::kCSSResizeAuto);
5021   } else {
5022     r = identifier_value.ConvertTo<EResize>();
5023   }
5024   state.Style()->SetResize(r);
5025 }
5026 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const5027 const CSSValue* Right::ParseSingleValue(
5028     CSSParserTokenRange& range,
5029     const CSSParserContext& context,
5030     const CSSParserLocalContext& local_context) const {
5031   return css_parsing_utils::ConsumeMarginOrOffset(
5032       range, context,
5033       css_parsing_utils::UnitlessUnlessShorthand(local_context));
5034 }
5035 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const5036 bool Right::IsLayoutDependent(const ComputedStyle* style,
5037                               LayoutObject* layout_object) const {
5038   return layout_object && layout_object->IsBox();
5039 }
5040 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const5041 const CSSValue* Right::CSSValueFromComputedStyleInternal(
5042     const ComputedStyle& style,
5043     const SVGComputedStyle&,
5044     const LayoutObject* layout_object,
5045     bool allow_visited_style) const {
5046   return ComputedStyleUtils::ValueForPositionOffset(style, *this,
5047                                                     layout_object);
5048 }
5049 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5050 const CSSValue* Rotate::ParseSingleValue(CSSParserTokenRange& range,
5051                                          const CSSParserContext& context,
5052                                          const CSSParserLocalContext&) const {
5053   DCHECK(RuntimeEnabledFeatures::CSSIndependentTransformPropertiesEnabled());
5054 
5055   CSSValueID id = range.Peek().Id();
5056   if (id == CSSValueID::kNone)
5057     return css_property_parser_helpers::ConsumeIdent(range);
5058 
5059   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
5060 
5061   CSSValue* rotation = css_property_parser_helpers::ConsumeAngle(
5062       range, context, base::Optional<WebFeature>());
5063 
5064   CSSValue* axis = css_property_parser_helpers::ConsumeAxis(range, context);
5065   if (axis)
5066     list->Append(*axis);
5067   else if (!rotation)
5068     return nullptr;
5069 
5070   if (!rotation) {
5071     rotation = css_property_parser_helpers::ConsumeAngle(
5072         range, context, base::Optional<WebFeature>());
5073     if (!rotation)
5074       return nullptr;
5075   }
5076   list->Append(*rotation);
5077 
5078   return list;
5079 }
5080 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5081 const CSSValue* Rotate::CSSValueFromComputedStyleInternal(
5082     const ComputedStyle& style,
5083     const SVGComputedStyle&,
5084     const LayoutObject*,
5085     bool allow_visited_style) const {
5086   if (!style.Rotate())
5087     return CSSIdentifierValue::Create(CSSValueID::kNone);
5088 
5089   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
5090   if (style.Rotate()->X() != 0 || style.Rotate()->Y() != 0 ||
5091       style.Rotate()->Z() != 1) {
5092     const cssvalue::CSSAxisValue* axis =
5093         MakeGarbageCollected<cssvalue::CSSAxisValue>(
5094             style.Rotate()->X(), style.Rotate()->Y(), style.Rotate()->Z());
5095     list->Append(*axis);
5096   }
5097   list->Append(*CSSNumericLiteralValue::Create(
5098       style.Rotate()->Angle(), CSSPrimitiveValue::UnitType::kDegrees));
5099   return list;
5100 }
5101 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5102 const CSSValue* RowGap::ParseSingleValue(CSSParserTokenRange& range,
5103                                          const CSSParserContext& context,
5104                                          const CSSParserLocalContext&) const {
5105   return css_parsing_utils::ConsumeGapLength(range, context);
5106 }
5107 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool) const5108 const CSSValue* RowGap::CSSValueFromComputedStyleInternal(
5109     const ComputedStyle& style,
5110     const SVGComputedStyle&,
5111     const LayoutObject*,
5112     bool) const {
5113   return ComputedStyleUtils::ValueForGapLength(style.RowGap(), style);
5114 }
5115 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5116 const CSSValue* Rx::ParseSingleValue(CSSParserTokenRange& range,
5117                                      const CSSParserContext& context,
5118                                      const CSSParserLocalContext&) const {
5119   if (range.Peek().Id() == CSSValueID::kAuto)
5120     return css_property_parser_helpers::ConsumeIdent(range);
5121   return css_property_parser_helpers::ConsumeSVGGeometryPropertyLength(
5122       range, context, kValueRangeNonNegative);
5123 }
5124 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5125 const CSSValue* Rx::CSSValueFromComputedStyleInternal(
5126     const ComputedStyle& style,
5127     const SVGComputedStyle& svg_style,
5128     const LayoutObject*,
5129     bool allow_visited_style) const {
5130   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(svg_style.Rx(),
5131                                                              style);
5132 }
5133 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5134 const CSSValue* Ry::ParseSingleValue(CSSParserTokenRange& range,
5135                                      const CSSParserContext& context,
5136                                      const CSSParserLocalContext&) const {
5137   if (range.Peek().Id() == CSSValueID::kAuto)
5138     return css_property_parser_helpers::ConsumeIdent(range);
5139   return css_property_parser_helpers::ConsumeSVGGeometryPropertyLength(
5140       range, context, kValueRangeNonNegative);
5141 }
5142 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5143 const CSSValue* Ry::CSSValueFromComputedStyleInternal(
5144     const ComputedStyle& style,
5145     const SVGComputedStyle& svg_style,
5146     const LayoutObject*,
5147     bool allow_visited_style) const {
5148   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(svg_style.Ry(),
5149                                                              style);
5150 }
5151 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5152 const CSSValue* Scale::ParseSingleValue(CSSParserTokenRange& range,
5153                                         const CSSParserContext& context,
5154                                         const CSSParserLocalContext&) const {
5155   DCHECK(RuntimeEnabledFeatures::CSSIndependentTransformPropertiesEnabled());
5156 
5157   CSSValueID id = range.Peek().Id();
5158   if (id == CSSValueID::kNone)
5159     return css_property_parser_helpers::ConsumeIdent(range);
5160 
5161   CSSValue* x_scale = css_property_parser_helpers::ConsumeNumber(
5162       range, context, kValueRangeAll);
5163   if (!x_scale)
5164     return nullptr;
5165 
5166   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
5167   list->Append(*x_scale);
5168 
5169   CSSValue* y_scale = css_property_parser_helpers::ConsumeNumber(
5170       range, context, kValueRangeAll);
5171   if (y_scale) {
5172     CSSValue* z_scale = css_property_parser_helpers::ConsumeNumber(
5173         range, context, kValueRangeAll);
5174     if (z_scale) {
5175       list->Append(*y_scale);
5176       list->Append(*z_scale);
5177     } else if (To<CSSPrimitiveValue>(x_scale)->GetDoubleValue() !=
5178                To<CSSPrimitiveValue>(y_scale)->GetDoubleValue()) {
5179       list->Append(*y_scale);
5180     }
5181   }
5182 
5183   return list;
5184 }
5185 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5186 const CSSValue* Scale::CSSValueFromComputedStyleInternal(
5187     const ComputedStyle& style,
5188     const SVGComputedStyle&,
5189     const LayoutObject*,
5190     bool allow_visited_style) const {
5191   ScaleTransformOperation* scale = style.Scale();
5192   if (!scale)
5193     return CSSIdentifierValue::Create(CSSValueID::kNone);
5194 
5195   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
5196   list->Append(*CSSNumericLiteralValue::Create(
5197       scale->X(), CSSPrimitiveValue::UnitType::kNumber));
5198 
5199   if (scale->Z() == 1) {
5200     if (scale->X() != scale->Y()) {
5201       list->Append(*CSSNumericLiteralValue::Create(
5202           scale->Y(), CSSPrimitiveValue::UnitType::kNumber));
5203     }
5204   } else {
5205     list->Append(*CSSNumericLiteralValue::Create(
5206         scale->Y(), CSSPrimitiveValue::UnitType::kNumber));
5207     list->Append(*CSSNumericLiteralValue::Create(
5208         scale->Z(), CSSNumericLiteralValue::UnitType::kNumber));
5209   }
5210   return list;
5211 }
5212 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5213 const CSSValue* ScrollBehavior::CSSValueFromComputedStyleInternal(
5214     const ComputedStyle& style,
5215     const SVGComputedStyle&,
5216     const LayoutObject*,
5217     bool allow_visited_style) const {
5218   return CSSIdentifierValue::Create(style.GetScrollBehavior());
5219 }
5220 
5221 namespace {
5222 
ConsumePan(CSSParserTokenRange & range,CSSValue ** pan_x,CSSValue ** pan_y)5223 static bool ConsumePan(CSSParserTokenRange& range,
5224                        CSSValue** pan_x,
5225                        CSSValue** pan_y) {
5226   CSSValueID id = range.Peek().Id();
5227   if ((id == CSSValueID::kPanX || id == CSSValueID::kPanRight ||
5228        id == CSSValueID::kPanLeft) &&
5229       !*pan_x) {
5230     *pan_x = css_property_parser_helpers::ConsumeIdent(range);
5231   } else if ((id == CSSValueID::kPanY || id == CSSValueID::kPanDown ||
5232               id == CSSValueID::kPanUp) &&
5233              !*pan_y) {
5234     *pan_y = css_property_parser_helpers::ConsumeIdent(range);
5235   } else {
5236     return false;
5237   }
5238   return true;
5239 }
5240 
5241 }  // namespace
5242 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5243 const CSSValue* ScrollCustomization::ParseSingleValue(
5244     CSSParserTokenRange& range,
5245     const CSSParserContext& context,
5246     const CSSParserLocalContext&) const {
5247   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
5248   CSSValueID id = range.Peek().Id();
5249   if (id == CSSValueID::kAuto || id == CSSValueID::kNone) {
5250     list->Append(*css_property_parser_helpers::ConsumeIdent(range));
5251     return list;
5252   }
5253 
5254   CSSValue* pan_x = nullptr;
5255   CSSValue* pan_y = nullptr;
5256   if (!ConsumePan(range, &pan_x, &pan_y))
5257     return nullptr;
5258   if (!range.AtEnd() && !ConsumePan(range, &pan_x, &pan_y))
5259     return nullptr;
5260 
5261   if (pan_x)
5262     list->Append(*pan_x);
5263   if (pan_y)
5264     list->Append(*pan_y);
5265   return list;
5266 }
5267 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5268 const CSSValue* ScrollCustomization::CSSValueFromComputedStyleInternal(
5269     const ComputedStyle& style,
5270     const SVGComputedStyle&,
5271     const LayoutObject*,
5272     bool allow_visited_style) const {
5273   return ComputedStyleUtils::ScrollCustomizationFlagsToCSSValue(
5274       style.ScrollCustomization());
5275 }
5276 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5277 const CSSValue* ScrollMarginBlockEnd::ParseSingleValue(
5278     CSSParserTokenRange& range,
5279     const CSSParserContext& context,
5280     const CSSParserLocalContext&) const {
5281   return ConsumeLength(range, context, kValueRangeAll,
5282                        css_property_parser_helpers::UnitlessQuirk::kForbid);
5283 }
5284 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5285 const CSSValue* ScrollMarginBlockStart::ParseSingleValue(
5286     CSSParserTokenRange& range,
5287     const CSSParserContext& context,
5288     const CSSParserLocalContext&) const {
5289   return ConsumeLength(range, context, kValueRangeAll,
5290                        css_property_parser_helpers::UnitlessQuirk::kForbid);
5291 }
5292 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5293 const CSSValue* ScrollMarginBottom::ParseSingleValue(
5294     CSSParserTokenRange& range,
5295     const CSSParserContext& context,
5296     const CSSParserLocalContext&) const {
5297   return ConsumeLength(range, context, kValueRangeAll,
5298                        css_property_parser_helpers::UnitlessQuirk::kForbid);
5299 }
5300 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5301 const CSSValue* ScrollMarginBottom::CSSValueFromComputedStyleInternal(
5302     const ComputedStyle& style,
5303     const SVGComputedStyle&,
5304     const LayoutObject*,
5305     bool allow_visited_style) const {
5306   return ZoomAdjustedPixelValue(style.ScrollMarginBottom(), style);
5307 }
5308 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5309 const CSSValue* ScrollMarginInlineEnd::ParseSingleValue(
5310     CSSParserTokenRange& range,
5311     const CSSParserContext& context,
5312     const CSSParserLocalContext&) const {
5313   return ConsumeLength(range, context, kValueRangeAll,
5314                        css_property_parser_helpers::UnitlessQuirk::kForbid);
5315 }
5316 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5317 const CSSValue* ScrollMarginInlineStart::ParseSingleValue(
5318     CSSParserTokenRange& range,
5319     const CSSParserContext& context,
5320     const CSSParserLocalContext&) const {
5321   return ConsumeLength(range, context, kValueRangeAll,
5322                        css_property_parser_helpers::UnitlessQuirk::kForbid);
5323 }
5324 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5325 const CSSValue* ScrollMarginLeft::ParseSingleValue(
5326     CSSParserTokenRange& range,
5327     const CSSParserContext& context,
5328     const CSSParserLocalContext&) const {
5329   return ConsumeLength(range, context, kValueRangeAll,
5330                        css_property_parser_helpers::UnitlessQuirk::kForbid);
5331 }
5332 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5333 const CSSValue* ScrollMarginLeft::CSSValueFromComputedStyleInternal(
5334     const ComputedStyle& style,
5335     const SVGComputedStyle&,
5336     const LayoutObject*,
5337     bool allow_visited_style) const {
5338   return ZoomAdjustedPixelValue(style.ScrollMarginLeft(), style);
5339 }
5340 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5341 const CSSValue* ScrollMarginRight::ParseSingleValue(
5342     CSSParserTokenRange& range,
5343     const CSSParserContext& context,
5344     const CSSParserLocalContext&) const {
5345   return ConsumeLength(range, context, kValueRangeAll,
5346                        css_property_parser_helpers::UnitlessQuirk::kForbid);
5347 }
5348 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5349 const CSSValue* ScrollMarginRight::CSSValueFromComputedStyleInternal(
5350     const ComputedStyle& style,
5351     const SVGComputedStyle&,
5352     const LayoutObject*,
5353     bool allow_visited_style) const {
5354   return ZoomAdjustedPixelValue(style.ScrollMarginRight(), style);
5355 }
5356 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5357 const CSSValue* ScrollMarginTop::ParseSingleValue(
5358     CSSParserTokenRange& range,
5359     const CSSParserContext& context,
5360     const CSSParserLocalContext&) const {
5361   return ConsumeLength(range, context, kValueRangeAll,
5362                        css_property_parser_helpers::UnitlessQuirk::kForbid);
5363 }
5364 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5365 const CSSValue* ScrollMarginTop::CSSValueFromComputedStyleInternal(
5366     const ComputedStyle& style,
5367     const SVGComputedStyle&,
5368     const LayoutObject*,
5369     bool allow_visited_style) const {
5370   return ZoomAdjustedPixelValue(style.ScrollMarginTop(), style);
5371 }
5372 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5373 const CSSValue* ScrollPaddingBlockEnd::ParseSingleValue(
5374     CSSParserTokenRange& range,
5375     const CSSParserContext& context,
5376     const CSSParserLocalContext&) const {
5377   return css_parsing_utils::ConsumeScrollPadding(range, context);
5378 }
5379 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5380 const CSSValue* ScrollPaddingBlockStart::ParseSingleValue(
5381     CSSParserTokenRange& range,
5382     const CSSParserContext& context,
5383     const CSSParserLocalContext&) const {
5384   return css_parsing_utils::ConsumeScrollPadding(range, context);
5385 }
5386 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5387 const CSSValue* ScrollPaddingBottom::ParseSingleValue(
5388     CSSParserTokenRange& range,
5389     const CSSParserContext& context,
5390     const CSSParserLocalContext&) const {
5391   return css_parsing_utils::ConsumeScrollPadding(range, context);
5392 }
5393 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5394 const CSSValue* ScrollPaddingBottom::CSSValueFromComputedStyleInternal(
5395     const ComputedStyle& style,
5396     const SVGComputedStyle&,
5397     const LayoutObject*,
5398     bool allow_visited_style) const {
5399   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
5400       style.ScrollPaddingBottom(), style);
5401 }
5402 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5403 const CSSValue* ScrollPaddingInlineEnd::ParseSingleValue(
5404     CSSParserTokenRange& range,
5405     const CSSParserContext& context,
5406     const CSSParserLocalContext&) const {
5407   return css_parsing_utils::ConsumeScrollPadding(range, context);
5408 }
5409 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5410 const CSSValue* ScrollPaddingInlineStart::ParseSingleValue(
5411     CSSParserTokenRange& range,
5412     const CSSParserContext& context,
5413     const CSSParserLocalContext&) const {
5414   return css_parsing_utils::ConsumeScrollPadding(range, context);
5415 }
5416 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5417 const CSSValue* ScrollPaddingLeft::ParseSingleValue(
5418     CSSParserTokenRange& range,
5419     const CSSParserContext& context,
5420     const CSSParserLocalContext&) const {
5421   return css_parsing_utils::ConsumeScrollPadding(range, context);
5422 }
5423 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5424 const CSSValue* ScrollPaddingLeft::CSSValueFromComputedStyleInternal(
5425     const ComputedStyle& style,
5426     const SVGComputedStyle&,
5427     const LayoutObject*,
5428     bool allow_visited_style) const {
5429   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
5430       style.ScrollPaddingLeft(), style);
5431 }
5432 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5433 const CSSValue* ScrollPaddingRight::ParseSingleValue(
5434     CSSParserTokenRange& range,
5435     const CSSParserContext& context,
5436     const CSSParserLocalContext&) const {
5437   return css_parsing_utils::ConsumeScrollPadding(range, context);
5438 }
5439 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5440 const CSSValue* ScrollPaddingRight::CSSValueFromComputedStyleInternal(
5441     const ComputedStyle& style,
5442     const SVGComputedStyle&,
5443     const LayoutObject*,
5444     bool allow_visited_style) const {
5445   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
5446       style.ScrollPaddingRight(), style);
5447 }
5448 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5449 const CSSValue* ScrollPaddingTop::ParseSingleValue(
5450     CSSParserTokenRange& range,
5451     const CSSParserContext& context,
5452     const CSSParserLocalContext&) const {
5453   return css_parsing_utils::ConsumeScrollPadding(range, context);
5454 }
5455 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5456 const CSSValue* ScrollPaddingTop::CSSValueFromComputedStyleInternal(
5457     const ComputedStyle& style,
5458     const SVGComputedStyle&,
5459     const LayoutObject*,
5460     bool allow_visited_style) const {
5461   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
5462       style.ScrollPaddingTop(), style);
5463 }
5464 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5465 const CSSValue* ScrollSnapAlign::ParseSingleValue(
5466     CSSParserTokenRange& range,
5467     const CSSParserContext& context,
5468     const CSSParserLocalContext&) const {
5469   CSSValue* block_value = css_property_parser_helpers::ConsumeIdent<
5470       CSSValueID::kNone, CSSValueID::kStart, CSSValueID::kEnd,
5471       CSSValueID::kCenter>(range);
5472   if (!block_value)
5473     return nullptr;
5474   if (range.AtEnd())
5475     return block_value;
5476 
5477   CSSValue* inline_value = css_property_parser_helpers::ConsumeIdent<
5478       CSSValueID::kNone, CSSValueID::kStart, CSSValueID::kEnd,
5479       CSSValueID::kCenter>(range);
5480   if (!inline_value)
5481     return block_value;
5482   auto* pair = MakeGarbageCollected<CSSValuePair>(
5483       block_value, inline_value, CSSValuePair::kDropIdenticalValues);
5484   return pair;
5485 }
5486 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5487 const CSSValue* ScrollSnapAlign::CSSValueFromComputedStyleInternal(
5488     const ComputedStyle& style,
5489     const SVGComputedStyle&,
5490     const LayoutObject*,
5491     bool allow_visited_style) const {
5492   return ComputedStyleUtils::ValueForScrollSnapAlign(style.GetScrollSnapAlign(),
5493                                                      style);
5494 }
5495 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5496 const CSSValue* ScrollSnapStop::CSSValueFromComputedStyleInternal(
5497     const ComputedStyle& style,
5498     const SVGComputedStyle&,
5499     const LayoutObject*,
5500     bool allow_visited_style) const {
5501   return CSSIdentifierValue::Create(style.ScrollSnapStop());
5502 }
5503 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5504 const CSSValue* ScrollSnapType::ParseSingleValue(
5505     CSSParserTokenRange& range,
5506     const CSSParserContext& context,
5507     const CSSParserLocalContext&) const {
5508   CSSValueID axis_id = range.Peek().Id();
5509   if (axis_id != CSSValueID::kNone && axis_id != CSSValueID::kX &&
5510       axis_id != CSSValueID::kY && axis_id != CSSValueID::kBlock &&
5511       axis_id != CSSValueID::kInline && axis_id != CSSValueID::kBoth)
5512     return nullptr;
5513   CSSValue* axis_value = css_property_parser_helpers::ConsumeIdent(range);
5514   if (range.AtEnd() || axis_id == CSSValueID::kNone)
5515     return axis_value;
5516 
5517   CSSValueID strictness_id = range.Peek().Id();
5518   if (strictness_id != CSSValueID::kProximity &&
5519       strictness_id != CSSValueID::kMandatory)
5520     return axis_value;
5521   CSSValue* strictness_value = css_property_parser_helpers::ConsumeIdent(range);
5522   if (strictness_id == CSSValueID::kProximity)
5523     return axis_value;  // Shortest serialization.
5524   auto* pair = MakeGarbageCollected<CSSValuePair>(
5525       axis_value, strictness_value, CSSValuePair::kDropIdenticalValues);
5526   return pair;
5527 }
5528 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5529 const CSSValue* ScrollSnapType::CSSValueFromComputedStyleInternal(
5530     const ComputedStyle& style,
5531     const SVGComputedStyle&,
5532     const LayoutObject*,
5533     bool allow_visited_style) const {
5534   return ComputedStyleUtils::ValueForScrollSnapType(style.GetScrollSnapType(),
5535                                                     style);
5536 }
5537 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5538 const CSSValue* ShapeImageThreshold::ParseSingleValue(
5539     CSSParserTokenRange& range,
5540     const CSSParserContext& context,
5541     const CSSParserLocalContext&) const {
5542   return css_property_parser_helpers::ConsumeAlphaValue(range, context);
5543 }
5544 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5545 const CSSValue* ShapeImageThreshold::CSSValueFromComputedStyleInternal(
5546     const ComputedStyle& style,
5547     const SVGComputedStyle&,
5548     const LayoutObject*,
5549     bool allow_visited_style) const {
5550   return CSSNumericLiteralValue::Create(style.ShapeImageThreshold(),
5551                                         CSSPrimitiveValue::UnitType::kNumber);
5552 }
5553 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5554 const CSSValue* ShapeMargin::ParseSingleValue(
5555     CSSParserTokenRange& range,
5556     const CSSParserContext& context,
5557     const CSSParserLocalContext&) const {
5558   return css_property_parser_helpers::ConsumeLengthOrPercent(
5559       range, context, kValueRangeNonNegative);
5560 }
5561 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5562 const CSSValue* ShapeMargin::CSSValueFromComputedStyleInternal(
5563     const ComputedStyle& style,
5564     const SVGComputedStyle&,
5565     const LayoutObject*,
5566     bool allow_visited_style) const {
5567   return CSSValue::Create(style.ShapeMargin(), style.EffectiveZoom());
5568 }
5569 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5570 const CSSValue* ShapeOutside::ParseSingleValue(
5571     CSSParserTokenRange& range,
5572     const CSSParserContext& context,
5573     const CSSParserLocalContext&) const {
5574   if (CSSValue* image_value =
5575           css_property_parser_helpers::ConsumeImageOrNone(range, context))
5576     return image_value;
5577   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
5578   CSSValue* box_value = css_property_parser_helpers::ConsumeShapeBox(range);
5579   if (CSSValue* shape_value =
5580           css_parsing_utils::ConsumeBasicShape(range, context)) {
5581     list->Append(*shape_value);
5582     if (!box_value) {
5583       box_value = css_property_parser_helpers::ConsumeShapeBox(range);
5584     }
5585   }
5586   if (box_value)
5587     list->Append(*box_value);
5588   if (!list->length())
5589     return nullptr;
5590   return list;
5591 }
5592 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5593 const CSSValue* ShapeOutside::CSSValueFromComputedStyleInternal(
5594     const ComputedStyle& style,
5595     const SVGComputedStyle&,
5596     const LayoutObject*,
5597     bool allow_visited_style) const {
5598   return ComputedStyleUtils::ValueForShape(style, allow_visited_style,
5599                                            style.ShapeOutside());
5600 }
5601 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5602 const CSSValue* ShapeRendering::CSSValueFromComputedStyleInternal(
5603     const ComputedStyle& style,
5604     const SVGComputedStyle& svg_style,
5605     const LayoutObject*,
5606     bool allow_visited_style) const {
5607   return CSSIdentifierValue::Create(svg_style.ShapeRendering());
5608 }
5609 
ConsumePageSize(CSSParserTokenRange & range)5610 static CSSValue* ConsumePageSize(CSSParserTokenRange& range) {
5611   return css_property_parser_helpers::ConsumeIdent<
5612       CSSValueID::kA3, CSSValueID::kA4, CSSValueID::kA5, CSSValueID::kB4,
5613       CSSValueID::kB5, CSSValueID::kJisB5, CSSValueID::kJisB4,
5614       CSSValueID::kLedger, CSSValueID::kLegal, CSSValueID::kLetter>(range);
5615 }
5616 
MmToPx(float mm)5617 static float MmToPx(float mm) {
5618   return mm * kCssPixelsPerMillimeter;
5619 }
InchToPx(float inch)5620 static float InchToPx(float inch) {
5621   return inch * kCssPixelsPerInch;
5622 }
GetPageSizeFromName(const CSSIdentifierValue & page_size_name)5623 static FloatSize GetPageSizeFromName(const CSSIdentifierValue& page_size_name) {
5624   switch (page_size_name.GetValueID()) {
5625     case CSSValueID::kA5:
5626       return FloatSize(MmToPx(148), MmToPx(210));
5627     case CSSValueID::kA4:
5628       return FloatSize(MmToPx(210), MmToPx(297));
5629     case CSSValueID::kA3:
5630       return FloatSize(MmToPx(297), MmToPx(420));
5631     case CSSValueID::kB5:
5632       return FloatSize(MmToPx(176), MmToPx(250));
5633     case CSSValueID::kB4:
5634       return FloatSize(MmToPx(250), MmToPx(353));
5635     case CSSValueID::kJisB5:
5636       return FloatSize(MmToPx(182), MmToPx(257));
5637     case CSSValueID::kJisB4:
5638       return FloatSize(MmToPx(257), MmToPx(364));
5639     case CSSValueID::kLetter:
5640       return FloatSize(InchToPx(8.5), InchToPx(11));
5641     case CSSValueID::kLegal:
5642       return FloatSize(InchToPx(8.5), InchToPx(14));
5643     case CSSValueID::kLedger:
5644       return FloatSize(InchToPx(11), InchToPx(17));
5645     default:
5646       NOTREACHED();
5647       return FloatSize(0, 0);
5648   }
5649 }
5650 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5651 const CSSValue* Size::ParseSingleValue(CSSParserTokenRange& range,
5652                                        const CSSParserContext& context,
5653                                        const CSSParserLocalContext&) const {
5654   CSSValueList* result = CSSValueList::CreateSpaceSeparated();
5655 
5656   if (range.Peek().Id() == CSSValueID::kAuto) {
5657     result->Append(*css_property_parser_helpers::ConsumeIdent(range));
5658     return result;
5659   }
5660 
5661   if (CSSValue* width = css_property_parser_helpers::ConsumeLength(
5662           range, context, kValueRangeNonNegative)) {
5663     CSSValue* height = css_property_parser_helpers::ConsumeLength(
5664         range, context, kValueRangeNonNegative);
5665     result->Append(*width);
5666     if (height)
5667       result->Append(*height);
5668     return result;
5669   }
5670 
5671   CSSValue* page_size = ConsumePageSize(range);
5672   CSSValue* orientation =
5673       css_property_parser_helpers::ConsumeIdent<CSSValueID::kPortrait,
5674                                                 CSSValueID::kLandscape>(range);
5675   if (!page_size)
5676     page_size = ConsumePageSize(range);
5677 
5678   if (!orientation && !page_size)
5679     return nullptr;
5680   if (page_size)
5681     result->Append(*page_size);
5682   if (orientation)
5683     result->Append(*orientation);
5684   return result;
5685 }
5686 
ApplyInitial(StyleResolverState & state) const5687 void Size::ApplyInitial(StyleResolverState& state) const {}
5688 
ApplyInherit(StyleResolverState & state) const5689 void Size::ApplyInherit(StyleResolverState& state) const {}
5690 
ApplyValue(StyleResolverState & state,const CSSValue & value) const5691 void Size::ApplyValue(StyleResolverState& state, const CSSValue& value) const {
5692   state.Style()->ResetPageSizeType();
5693   FloatSize size;
5694   PageSizeType page_size_type = PageSizeType::kAuto;
5695   const auto& list = To<CSSValueList>(value);
5696   if (list.length() == 2) {
5697     // <length>{2} | <page-size> <orientation>
5698     const CSSValue& first = list.Item(0);
5699     const CSSValue& second = list.Item(1);
5700     auto* first_primitive_value = DynamicTo<CSSPrimitiveValue>(first);
5701     if (first_primitive_value && first_primitive_value->IsLength()) {
5702       // <length>{2}
5703       size = FloatSize(
5704           first_primitive_value->ComputeLength<float>(
5705               state.CssToLengthConversionData().CopyWithAdjustedZoom(1.0)),
5706           To<CSSPrimitiveValue>(second).ComputeLength<float>(
5707               state.CssToLengthConversionData().CopyWithAdjustedZoom(1.0)));
5708     } else {
5709       // <page-size> <orientation>
5710       size = GetPageSizeFromName(To<CSSIdentifierValue>(first));
5711 
5712       DCHECK(To<CSSIdentifierValue>(second).GetValueID() ==
5713                  CSSValueID::kLandscape ||
5714              To<CSSIdentifierValue>(second).GetValueID() ==
5715                  CSSValueID::kPortrait);
5716       if (To<CSSIdentifierValue>(second).GetValueID() == CSSValueID::kLandscape)
5717         size = size.TransposedSize();
5718     }
5719     page_size_type = PageSizeType::kFixed;
5720   } else {
5721     DCHECK_EQ(list.length(), 1U);
5722     // <length> | auto | <page-size> | [ portrait | landscape]
5723     const CSSValue& first = list.Item(0);
5724     auto* first_primitive_value = DynamicTo<CSSPrimitiveValue>(first);
5725     if (first_primitive_value && first_primitive_value->IsLength()) {
5726       // <length>
5727       page_size_type = PageSizeType::kFixed;
5728       float width = first_primitive_value->ComputeLength<float>(
5729           state.CssToLengthConversionData().CopyWithAdjustedZoom(1.0));
5730       size = FloatSize(width, width);
5731     } else {
5732       const auto& ident = To<CSSIdentifierValue>(first);
5733       switch (ident.GetValueID()) {
5734         case CSSValueID::kAuto:
5735           page_size_type = PageSizeType::kAuto;
5736           break;
5737         case CSSValueID::kPortrait:
5738           page_size_type = PageSizeType::kPortrait;
5739           break;
5740         case CSSValueID::kLandscape:
5741           page_size_type = PageSizeType::kLandscape;
5742           break;
5743         default:
5744           // <page-size>
5745           page_size_type = PageSizeType::kFixed;
5746           size = GetPageSizeFromName(ident);
5747       }
5748     }
5749   }
5750   state.Style()->SetPageSizeType(page_size_type);
5751   state.Style()->SetPageSize(size);
5752 }
5753 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5754 const CSSValue* Speak::CSSValueFromComputedStyleInternal(
5755     const ComputedStyle& style,
5756     const SVGComputedStyle&,
5757     const LayoutObject*,
5758     bool allow_visited_style) const {
5759   return CSSIdentifierValue::Create(style.Speak());
5760 }
5761 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5762 const CSSValue* StopColor::ParseSingleValue(
5763     CSSParserTokenRange& range,
5764     const CSSParserContext& context,
5765     const CSSParserLocalContext&) const {
5766   return css_property_parser_helpers::ConsumeColor(range, context);
5767 }
5768 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const5769 const blink::Color StopColor::ColorIncludingFallback(
5770     bool visited_link,
5771     const ComputedStyle& style) const {
5772   StyleColor result = style.StopColor();
5773   if (!result.IsCurrentColor())
5774     return result.GetColor();
5775   return visited_link ? style.InternalVisitedColor() : style.GetColor();
5776 }
5777 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5778 const CSSValue* StopColor::CSSValueFromComputedStyleInternal(
5779     const ComputedStyle& style,
5780     const SVGComputedStyle&,
5781     const LayoutObject*,
5782     bool allow_visited_style) const {
5783   return ComputedStyleUtils::CurrentColorOrValidColor(style, style.StopColor());
5784 }
5785 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5786 const CSSValue* StopOpacity::ParseSingleValue(
5787     CSSParserTokenRange& range,
5788     const CSSParserContext& context,
5789     const CSSParserLocalContext&) const {
5790   return css_property_parser_helpers::ConsumeAlphaValue(range, context);
5791 }
5792 
CSSValueFromComputedStyleInternal(const ComputedStyle &,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5793 const CSSValue* StopOpacity::CSSValueFromComputedStyleInternal(
5794     const ComputedStyle&,
5795     const SVGComputedStyle& svg_style,
5796     const LayoutObject*,
5797     bool allow_visited_style) const {
5798   return CSSNumericLiteralValue::Create(svg_style.StopOpacity(),
5799                                         CSSPrimitiveValue::UnitType::kNumber);
5800 }
5801 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5802 const CSSValue* Stroke::ParseSingleValue(CSSParserTokenRange& range,
5803                                          const CSSParserContext& context,
5804                                          const CSSParserLocalContext&) const {
5805   return css_parsing_utils::ParsePaintStroke(range, context);
5806 }
5807 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5808 const CSSValue* Stroke::CSSValueFromComputedStyleInternal(
5809     const ComputedStyle& style,
5810     const SVGComputedStyle& svg_style,
5811     const LayoutObject*,
5812     bool allow_visited_style) const {
5813   return ComputedStyleUtils::AdjustSVGPaintForCurrentColor(
5814       svg_style.StrokePaint(), style.GetColor());
5815 }
5816 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5817 const CSSValue* StrokeDasharray::ParseSingleValue(
5818     CSSParserTokenRange& range,
5819     const CSSParserContext& context,
5820     const CSSParserLocalContext&) const {
5821   CSSValueID id = range.Peek().Id();
5822   if (id == CSSValueID::kNone)
5823     return css_property_parser_helpers::ConsumeIdent(range);
5824 
5825   CSSParserContext::ParserModeOverridingScope scope(context, kSVGAttributeMode);
5826   CSSValueList* dashes = CSSValueList::CreateCommaSeparated();
5827   do {
5828     CSSPrimitiveValue* dash =
5829         css_property_parser_helpers::ConsumeLengthOrPercent(
5830             range, context, kValueRangeNonNegative);
5831     if (!dash ||
5832         (css_property_parser_helpers::ConsumeCommaIncludingWhitespace(range) &&
5833          range.AtEnd()))
5834       return nullptr;
5835     dashes->Append(*dash);
5836   } while (!range.AtEnd());
5837   return dashes;
5838 }
5839 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5840 const CSSValue* StrokeDasharray::CSSValueFromComputedStyleInternal(
5841     const ComputedStyle& style,
5842     const SVGComputedStyle& svg_style,
5843     const LayoutObject*,
5844     bool allow_visited_style) const {
5845   return ComputedStyleUtils::StrokeDashArrayToCSSValueList(
5846       *svg_style.StrokeDashArray(), style);
5847 }
5848 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5849 const CSSValue* StrokeDashoffset::ParseSingleValue(
5850     CSSParserTokenRange& range,
5851     const CSSParserContext& context,
5852     const CSSParserLocalContext&) const {
5853   CSSParserContext::ParserModeOverridingScope scope(context, kSVGAttributeMode);
5854   return css_property_parser_helpers::ConsumeLengthOrPercent(
5855       range, context, kValueRangeAll,
5856       css_property_parser_helpers::UnitlessQuirk::kForbid);
5857 }
5858 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5859 const CSSValue* StrokeDashoffset::CSSValueFromComputedStyleInternal(
5860     const ComputedStyle& style,
5861     const SVGComputedStyle&,
5862     const LayoutObject*,
5863     bool allow_visited_style) const {
5864   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
5865       style.StrokeDashOffset(), style);
5866 }
5867 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5868 const CSSValue* StrokeLinecap::CSSValueFromComputedStyleInternal(
5869     const ComputedStyle& style,
5870     const SVGComputedStyle& svg_style,
5871     const LayoutObject*,
5872     bool allow_visited_style) const {
5873   return CSSIdentifierValue::Create(svg_style.CapStyle());
5874 }
5875 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5876 const CSSValue* StrokeLinejoin::CSSValueFromComputedStyleInternal(
5877     const ComputedStyle& style,
5878     const SVGComputedStyle& svg_style,
5879     const LayoutObject*,
5880     bool allow_visited_style) const {
5881   return CSSIdentifierValue::Create(svg_style.JoinStyle());
5882 }
5883 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5884 const CSSValue* StrokeMiterlimit::ParseSingleValue(
5885     CSSParserTokenRange& range,
5886     const CSSParserContext& context,
5887     const CSSParserLocalContext&) const {
5888   return css_property_parser_helpers::ConsumeNumber(range, context,
5889                                                     kValueRangeNonNegative);
5890 }
5891 
CSSValueFromComputedStyleInternal(const ComputedStyle &,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5892 const CSSValue* StrokeMiterlimit::CSSValueFromComputedStyleInternal(
5893     const ComputedStyle&,
5894     const SVGComputedStyle& svg_style,
5895     const LayoutObject*,
5896     bool allow_visited_style) const {
5897   return CSSNumericLiteralValue::Create(svg_style.StrokeMiterLimit(),
5898                                         CSSPrimitiveValue::UnitType::kNumber);
5899 }
5900 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5901 const CSSValue* StrokeOpacity::ParseSingleValue(
5902     CSSParserTokenRange& range,
5903     const CSSParserContext& context,
5904     const CSSParserLocalContext&) const {
5905   return css_property_parser_helpers::ConsumeAlphaValue(range, context);
5906 }
5907 
CSSValueFromComputedStyleInternal(const ComputedStyle &,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5908 const CSSValue* StrokeOpacity::CSSValueFromComputedStyleInternal(
5909     const ComputedStyle&,
5910     const SVGComputedStyle& svg_style,
5911     const LayoutObject*,
5912     bool allow_visited_style) const {
5913   return CSSNumericLiteralValue::Create(svg_style.StrokeOpacity(),
5914                                         CSSPrimitiveValue::UnitType::kNumber);
5915 }
5916 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5917 const CSSValue* StrokeWidth::ParseSingleValue(
5918     CSSParserTokenRange& range,
5919     const CSSParserContext& context,
5920     const CSSParserLocalContext&) const {
5921   CSSParserContext::ParserModeOverridingScope scope(context, kSVGAttributeMode);
5922   return css_property_parser_helpers::ConsumeLengthOrPercent(
5923       range, context, kValueRangeNonNegative,
5924       css_property_parser_helpers::UnitlessQuirk::kForbid);
5925 }
5926 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const5927 const CSSValue* StrokeWidth::CSSValueFromComputedStyleInternal(
5928     const ComputedStyle& style,
5929     const SVGComputedStyle& svg_style,
5930     const LayoutObject*,
5931     bool allow_visited_style) const {
5932   // We store the unzoomed stroke-width value using ConvertUnzoomedLength().
5933   // Don't apply zoom here either.
5934   return CSSValue::Create(svg_style.StrokeWidth().length(), 1);
5935 }
5936 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5937 const CSSValue* SubtreeVisibility::CSSValueFromComputedStyleInternal(
5938     const ComputedStyle& style,
5939     const SVGComputedStyle&,
5940     const LayoutObject*,
5941     bool allow_visited_style) const {
5942   return CSSIdentifierValue::Create(style.SubtreeVisibility());
5943 }
5944 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5945 const CSSValue* SubtreeVisibility::ParseSingleValue(
5946     CSSParserTokenRange& range,
5947     const CSSParserContext& context,
5948     const CSSParserLocalContext&) const {
5949   auto id = range.Peek().Id();
5950   if (id == CSSValueID::kHiddenMatchable &&
5951       !RuntimeEnabledFeatures::CSSSubtreeVisibilityHiddenMatchableEnabled()) {
5952     return nullptr;
5953   }
5954   if (!css_property_parser_helpers::IdentMatches<
5955           CSSValueID::kVisible, CSSValueID::kAuto, CSSValueID::kHidden,
5956           CSSValueID::kHiddenMatchable>(id)) {
5957     return nullptr;
5958   }
5959   return css_property_parser_helpers::ConsumeIdent(range);
5960 }
5961 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const5962 const CSSValue* TabSize::ParseSingleValue(CSSParserTokenRange& range,
5963                                           const CSSParserContext& context,
5964                                           const CSSParserLocalContext&) const {
5965   CSSPrimitiveValue* parsed_value = css_property_parser_helpers::ConsumeNumber(
5966       range, context, kValueRangeNonNegative);
5967   if (parsed_value)
5968     return parsed_value;
5969   return css_property_parser_helpers::ConsumeLength(range, context,
5970                                                     kValueRangeNonNegative);
5971 }
5972 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5973 const CSSValue* TabSize::CSSValueFromComputedStyleInternal(
5974     const ComputedStyle& style,
5975     const SVGComputedStyle&,
5976     const LayoutObject*,
5977     bool allow_visited_style) const {
5978   return CSSNumericLiteralValue::Create(
5979       style.GetTabSize().GetPixelSize(1.0),
5980       style.GetTabSize().IsSpaces() ? CSSPrimitiveValue::UnitType::kNumber
5981                                     : CSSPrimitiveValue::UnitType::kPixels);
5982 }
5983 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5984 const CSSValue* TableLayout::CSSValueFromComputedStyleInternal(
5985     const ComputedStyle& style,
5986     const SVGComputedStyle&,
5987     const LayoutObject*,
5988     bool allow_visited_style) const {
5989   return CSSIdentifierValue::Create(style.TableLayout());
5990 }
5991 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const5992 const CSSValue* TextAlign::CSSValueFromComputedStyleInternal(
5993     const ComputedStyle& style,
5994     const SVGComputedStyle&,
5995     const LayoutObject*,
5996     bool allow_visited_style) const {
5997   return CSSIdentifierValue::Create(style.GetTextAlign());
5998 }
5999 
ApplyValue(StyleResolverState & state,const CSSValue & value) const6000 void TextAlign::ApplyValue(StyleResolverState& state,
6001                            const CSSValue& value) const {
6002   const auto* ident_value = DynamicTo<CSSIdentifierValue>(value);
6003   if (ident_value &&
6004       ident_value->GetValueID() != CSSValueID::kWebkitMatchParent) {
6005     // Special case for th elements - UA stylesheet text-align does not apply if
6006     // parent's computed value for text-align is not its initial value
6007     // https://html.spec.whatwg.org/C/#tables-2
6008     if (ident_value->GetValueID() == CSSValueID::kInternalCenter &&
6009         state.ParentStyle()->GetTextAlign() !=
6010             ComputedStyleInitialValues::InitialTextAlign())
6011       state.Style()->SetTextAlign(state.ParentStyle()->GetTextAlign());
6012     else
6013       state.Style()->SetTextAlign(ident_value->ConvertTo<ETextAlign>());
6014   } else if (state.ParentStyle()->GetTextAlign() == ETextAlign::kStart) {
6015     state.Style()->SetTextAlign(state.ParentStyle()->IsLeftToRightDirection()
6016                                     ? ETextAlign::kLeft
6017                                     : ETextAlign::kRight);
6018   } else if (state.ParentStyle()->GetTextAlign() == ETextAlign::kEnd) {
6019     state.Style()->SetTextAlign(state.ParentStyle()->IsLeftToRightDirection()
6020                                     ? ETextAlign::kRight
6021                                     : ETextAlign::kLeft);
6022   } else {
6023     state.Style()->SetTextAlign(state.ParentStyle()->GetTextAlign());
6024   }
6025 }
6026 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6027 const CSSValue* TextAlignLast::CSSValueFromComputedStyleInternal(
6028     const ComputedStyle& style,
6029     const SVGComputedStyle&,
6030     const LayoutObject*,
6031     bool allow_visited_style) const {
6032   return CSSIdentifierValue::Create(style.TextAlignLast());
6033 }
6034 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const6035 const CSSValue* TextAnchor::CSSValueFromComputedStyleInternal(
6036     const ComputedStyle& style,
6037     const SVGComputedStyle& svg_style,
6038     const LayoutObject*,
6039     bool allow_visited_style) const {
6040   return CSSIdentifierValue::Create(svg_style.TextAnchor());
6041 }
6042 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6043 const CSSValue* TextCombineUpright::CSSValueFromComputedStyleInternal(
6044     const ComputedStyle& style,
6045     const SVGComputedStyle&,
6046     const LayoutObject*,
6047     bool allow_visited_style) const {
6048   return CSSIdentifierValue::Create(style.TextCombine());
6049 }
6050 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6051 const CSSValue* TextDecorationColor::ParseSingleValue(
6052     CSSParserTokenRange& range,
6053     const CSSParserContext& context,
6054     const CSSParserLocalContext&) const {
6055   return css_property_parser_helpers::ConsumeColor(range, context);
6056 }
6057 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const6058 const blink::Color TextDecorationColor::ColorIncludingFallback(
6059     bool visited_link,
6060     const ComputedStyle& style) const {
6061   DCHECK(!visited_link);
6062   return style.DecorationColorIncludingFallback(visited_link)
6063       .Resolve(style.GetColor());
6064 }
6065 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6066 const CSSValue* TextDecorationColor::CSSValueFromComputedStyleInternal(
6067     const ComputedStyle& style,
6068     const SVGComputedStyle&,
6069     const LayoutObject*,
6070     bool allow_visited_style) const {
6071   return ComputedStyleUtils::CurrentColorOrValidColor(
6072       style, style.TextDecorationColor());
6073 }
6074 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const6075 const CSSValue* TextDecorationLine::ParseSingleValue(
6076     CSSParserTokenRange& range,
6077     const CSSParserContext&,
6078     const CSSParserLocalContext&) const {
6079   return css_parsing_utils::ConsumeTextDecorationLine(range);
6080 }
6081 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6082 const CSSValue* TextDecorationLine::CSSValueFromComputedStyleInternal(
6083     const ComputedStyle& style,
6084     const SVGComputedStyle&,
6085     const LayoutObject*,
6086     bool allow_visited_style) const {
6087   return ComputedStyleUtils::RenderTextDecorationFlagsToCSSValue(
6088       style.GetTextDecoration());
6089 }
6090 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6091 const CSSValue* TextDecorationSkipInk::CSSValueFromComputedStyleInternal(
6092     const ComputedStyle& style,
6093     const SVGComputedStyle&,
6094     const LayoutObject*,
6095     bool allow_visited_style) const {
6096   return ComputedStyleUtils::ValueForTextDecorationSkipInk(
6097       style.TextDecorationSkipInk());
6098 }
6099 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const6100 const CSSValue* TextDecorationStyle::CSSValueFromComputedStyleInternal(
6101     const ComputedStyle& style,
6102     const SVGComputedStyle&,
6103     const LayoutObject* layout_object,
6104     bool allow_visited_style) const {
6105   return ComputedStyleUtils::ValueForTextDecorationStyle(
6106       style.TextDecorationStyle());
6107 }
6108 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6109 const CSSValue* TextIndent::ParseSingleValue(
6110     CSSParserTokenRange& range,
6111     const CSSParserContext& context,
6112     const CSSParserLocalContext&) const {
6113   // [ <length> | <percentage> ] && hanging? && each-line?
6114   // Keywords only allowed when css3Text is enabled.
6115   CSSValue* length_percentage = nullptr;
6116   CSSValue* hanging = nullptr;
6117   CSSValue* each_line = nullptr;
6118   do {
6119     if (!length_percentage) {
6120       length_percentage = css_property_parser_helpers::ConsumeLengthOrPercent(
6121           range, context, kValueRangeAll,
6122           css_property_parser_helpers::UnitlessQuirk::kAllow);
6123       if (length_percentage) {
6124         continue;
6125       }
6126     }
6127 
6128     if (RuntimeEnabledFeatures::CSS3TextEnabled()) {
6129       CSSValueID id = range.Peek().Id();
6130       if (!hanging && id == CSSValueID::kHanging) {
6131         hanging = css_property_parser_helpers::ConsumeIdent(range);
6132         continue;
6133       }
6134       if (!each_line && id == CSSValueID::kEachLine) {
6135         each_line = css_property_parser_helpers::ConsumeIdent(range);
6136         continue;
6137       }
6138     }
6139     return nullptr;
6140   } while (!range.AtEnd());
6141 
6142   if (!length_percentage)
6143     return nullptr;
6144   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6145   list->Append(*length_percentage);
6146 
6147   if (hanging)
6148     list->Append(*hanging);
6149 
6150   if (each_line)
6151     list->Append(*each_line);
6152 
6153   return list;
6154 }
6155 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6156 const CSSValue* TextIndent::CSSValueFromComputedStyleInternal(
6157     const ComputedStyle& style,
6158     const SVGComputedStyle&,
6159     const LayoutObject*,
6160     bool allow_visited_style) const {
6161   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6162   list->Append(*ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
6163       style.TextIndent(), style));
6164   if (RuntimeEnabledFeatures::CSS3TextEnabled()) {
6165     if (style.GetTextIndentType() == TextIndentType::kHanging)
6166       list->Append(*CSSIdentifierValue::Create(CSSValueID::kHanging));
6167     if (style.GetTextIndentLine() == TextIndentLine::kEachLine)
6168       list->Append(*CSSIdentifierValue::Create(CSSValueID::kEachLine));
6169   }
6170   return list;
6171 }
6172 
ApplyInitial(StyleResolverState & state) const6173 void TextIndent::ApplyInitial(StyleResolverState& state) const {
6174   state.Style()->SetTextIndent(ComputedStyleInitialValues::InitialTextIndent());
6175   state.Style()->SetTextIndentLine(
6176       ComputedStyleInitialValues::InitialTextIndentLine());
6177   state.Style()->SetTextIndentType(
6178       ComputedStyleInitialValues::InitialTextIndentType());
6179 }
6180 
ApplyInherit(StyleResolverState & state) const6181 void TextIndent::ApplyInherit(StyleResolverState& state) const {
6182   state.Style()->SetTextIndent(state.ParentStyle()->TextIndent());
6183   state.Style()->SetTextIndentLine(state.ParentStyle()->GetTextIndentLine());
6184   state.Style()->SetTextIndentType(state.ParentStyle()->GetTextIndentType());
6185 }
6186 
ApplyValue(StyleResolverState & state,const CSSValue & value) const6187 void TextIndent::ApplyValue(StyleResolverState& state,
6188                             const CSSValue& value) const {
6189   Length length_or_percentage_value;
6190   TextIndentLine text_indent_line_value =
6191       ComputedStyleInitialValues::InitialTextIndentLine();
6192   TextIndentType text_indent_type_value =
6193       ComputedStyleInitialValues::InitialTextIndentType();
6194 
6195   for (auto& list_value : To<CSSValueList>(value)) {
6196     if (auto* list_primitive_value =
6197             DynamicTo<CSSPrimitiveValue>(*list_value)) {
6198       length_or_percentage_value = list_primitive_value->ConvertToLength(
6199           state.CssToLengthConversionData());
6200     } else if (To<CSSIdentifierValue>(*list_value).GetValueID() ==
6201                CSSValueID::kEachLine) {
6202       text_indent_line_value = TextIndentLine::kEachLine;
6203     } else if (To<CSSIdentifierValue>(*list_value).GetValueID() ==
6204                CSSValueID::kHanging) {
6205       text_indent_type_value = TextIndentType::kHanging;
6206     } else {
6207       NOTREACHED();
6208     }
6209   }
6210 
6211   state.Style()->SetTextIndent(length_or_percentage_value);
6212   state.Style()->SetTextIndentLine(text_indent_line_value);
6213   state.Style()->SetTextIndentType(text_indent_type_value);
6214 }
6215 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6216 const CSSValue* TextJustify::CSSValueFromComputedStyleInternal(
6217     const ComputedStyle& style,
6218     const SVGComputedStyle&,
6219     const LayoutObject*,
6220     bool allow_visited_style) const {
6221   return CSSIdentifierValue::Create(style.GetTextJustify());
6222 }
6223 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6224 const CSSValue* TextOrientation::CSSValueFromComputedStyleInternal(
6225     const ComputedStyle& style,
6226     const SVGComputedStyle&,
6227     const LayoutObject*,
6228     bool allow_visited_style) const {
6229   return CSSIdentifierValue::Create(style.GetTextOrientation());
6230 }
6231 
ApplyValue(StyleResolverState & state,const CSSValue & value) const6232 void TextOrientation::ApplyValue(StyleResolverState& state,
6233                                  const CSSValue& value) const {
6234   state.SetTextOrientation(
6235       To<CSSIdentifierValue>(value).ConvertTo<ETextOrientation>());
6236 }
6237 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6238 const CSSValue* TextOverflow::CSSValueFromComputedStyleInternal(
6239     const ComputedStyle& style,
6240     const SVGComputedStyle&,
6241     const LayoutObject*,
6242     bool allow_visited_style) const {
6243   if (style.TextOverflow() != ETextOverflow::kClip)
6244     return CSSIdentifierValue::Create(CSSValueID::kEllipsis);
6245   return CSSIdentifierValue::Create(CSSValueID::kClip);
6246 }
6247 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6248 const CSSValue* TextRendering::CSSValueFromComputedStyleInternal(
6249     const ComputedStyle& style,
6250     const SVGComputedStyle&,
6251     const LayoutObject*,
6252     bool allow_visited_style) const {
6253   return CSSIdentifierValue::Create(style.GetFontDescription().TextRendering());
6254 }
6255 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6256 const CSSValue* TextShadow::ParseSingleValue(
6257     CSSParserTokenRange& range,
6258     const CSSParserContext& context,
6259     const CSSParserLocalContext&) const {
6260   return css_parsing_utils::ConsumeShadow(
6261       range, context, css_parsing_utils::AllowInsetAndSpread::kForbid);
6262 }
6263 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6264 const CSSValue* TextShadow::CSSValueFromComputedStyleInternal(
6265     const ComputedStyle& style,
6266     const SVGComputedStyle&,
6267     const LayoutObject*,
6268     bool allow_visited_style) const {
6269   return ComputedStyleUtils::ValueForShadowList(style.TextShadow(), style,
6270                                                 false);
6271 }
6272 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6273 const CSSValue* TextSizeAdjust::ParseSingleValue(
6274     CSSParserTokenRange& range,
6275     const CSSParserContext& context,
6276     const CSSParserLocalContext&) const {
6277   if (range.Peek().Id() == CSSValueID::kAuto)
6278     return css_property_parser_helpers::ConsumeIdent(range);
6279   if (range.Peek().Id() == CSSValueID::kNone)
6280     return css_property_parser_helpers::ConsumeIdent(range);
6281   return css_property_parser_helpers::ConsumePercent(range, context,
6282                                                      kValueRangeNonNegative);
6283 }
6284 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6285 const CSSValue* TextSizeAdjust::CSSValueFromComputedStyleInternal(
6286     const ComputedStyle& style,
6287     const SVGComputedStyle&,
6288     const LayoutObject*,
6289     bool allow_visited_style) const {
6290   if (style.GetTextSizeAdjust().IsAuto())
6291     return CSSIdentifierValue::Create(CSSValueID::kAuto);
6292   return CSSNumericLiteralValue::Create(
6293       style.GetTextSizeAdjust().Multiplier() * 100,
6294       CSSPrimitiveValue::UnitType::kPercentage);
6295 }
6296 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6297 const CSSValue* TextTransform::CSSValueFromComputedStyleInternal(
6298     const ComputedStyle& style,
6299     const SVGComputedStyle&,
6300     const LayoutObject*,
6301     bool allow_visited_style) const {
6302   return CSSIdentifierValue::Create(style.TextTransform());
6303 }
6304 
6305 // https://drafts.csswg.org/css-text-decor-4/#text-underline-position-property
6306 // auto | [ from-font | under ] || [ left | right ] - default: auto
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6307 const CSSValue* TextUnderlinePosition::ParseSingleValue(
6308     CSSParserTokenRange& range,
6309     const CSSParserContext& context,
6310     const CSSParserLocalContext&) const {
6311   if (range.Peek().Id() == CSSValueID::kAuto)
6312     return css_property_parser_helpers::ConsumeIdent(range);
6313 
6314   CSSIdentifierValue* from_font_or_under_value =
6315       RuntimeEnabledFeatures::UnderlineOffsetThicknessEnabled()
6316           ? css_property_parser_helpers::ConsumeIdent<CSSValueID::kFromFont,
6317                                                       CSSValueID::kUnder>(range)
6318           : css_property_parser_helpers::ConsumeIdent<CSSValueID::kUnder>(
6319                 range);
6320   CSSIdentifierValue* left_or_right_value =
6321       css_property_parser_helpers::ConsumeIdent<CSSValueID::kLeft,
6322                                                 CSSValueID::kRight>(range);
6323   if (left_or_right_value && !from_font_or_under_value) {
6324     from_font_or_under_value =
6325         RuntimeEnabledFeatures::UnderlineOffsetThicknessEnabled()
6326             ? css_property_parser_helpers::ConsumeIdent<CSSValueID::kFromFont,
6327                                                         CSSValueID::kUnder>(
6328                   range)
6329             : css_property_parser_helpers::ConsumeIdent<CSSValueID::kUnder>(
6330                   range);
6331   }
6332   if (!from_font_or_under_value && !left_or_right_value)
6333     return nullptr;
6334   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6335   if (from_font_or_under_value)
6336     list->Append(*from_font_or_under_value);
6337   if (left_or_right_value)
6338     list->Append(*left_or_right_value);
6339   return list;
6340 }
6341 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6342 const CSSValue* TextUnderlinePosition::CSSValueFromComputedStyleInternal(
6343     const ComputedStyle& style,
6344     const SVGComputedStyle&,
6345     const LayoutObject*,
6346     bool allow_visited_style) const {
6347   auto text_underline_position = style.TextUnderlinePosition();
6348   if (text_underline_position == kTextUnderlinePositionAuto)
6349     return CSSIdentifierValue::Create(CSSValueID::kAuto);
6350   if (text_underline_position == kTextUnderlinePositionFromFont)
6351     return CSSIdentifierValue::Create(CSSValueID::kFromFont);
6352   if (text_underline_position == kTextUnderlinePositionUnder)
6353     return CSSIdentifierValue::Create(CSSValueID::kUnder);
6354   if (text_underline_position == kTextUnderlinePositionLeft)
6355     return CSSIdentifierValue::Create(CSSValueID::kLeft);
6356   if (text_underline_position == kTextUnderlinePositionRight)
6357     return CSSIdentifierValue::Create(CSSValueID::kRight);
6358 
6359   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6360   if (text_underline_position & kTextUnderlinePositionFromFont) {
6361     list->Append(*CSSIdentifierValue::Create(CSSValueID::kFromFont));
6362   } else {
6363     DCHECK(text_underline_position & kTextUnderlinePositionUnder);
6364     list->Append(*CSSIdentifierValue::Create(CSSValueID::kUnder));
6365   }
6366   if (text_underline_position & kTextUnderlinePositionLeft)
6367     list->Append(*CSSIdentifierValue::Create(CSSValueID::kLeft));
6368   if (text_underline_position & kTextUnderlinePositionRight)
6369     list->Append(*CSSIdentifierValue::Create(CSSValueID::kRight));
6370   DCHECK_EQ(list->length(), 2U);
6371   return list;
6372 }
6373 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const6374 const CSSValue* Top::ParseSingleValue(
6375     CSSParserTokenRange& range,
6376     const CSSParserContext& context,
6377     const CSSParserLocalContext& local_context) const {
6378   return css_parsing_utils::ConsumeMarginOrOffset(
6379       range, context,
6380       css_parsing_utils::UnitlessUnlessShorthand(local_context));
6381 }
6382 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const6383 bool Top::IsLayoutDependent(const ComputedStyle* style,
6384                             LayoutObject* layout_object) const {
6385   return layout_object && layout_object->IsBox();
6386 }
6387 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const6388 const CSSValue* Top::CSSValueFromComputedStyleInternal(
6389     const ComputedStyle& style,
6390     const SVGComputedStyle&,
6391     const LayoutObject* layout_object,
6392     bool allow_visited_style) const {
6393   return ComputedStyleUtils::ValueForPositionOffset(style, *this,
6394                                                     layout_object);
6395 }
6396 
6397 namespace {
6398 
ConsumePan(CSSParserTokenRange & range,CSSValue * & pan_x,CSSValue * & pan_y,CSSValue * & pinch_zoom)6399 static bool ConsumePan(CSSParserTokenRange& range,
6400                        CSSValue*& pan_x,
6401                        CSSValue*& pan_y,
6402                        CSSValue*& pinch_zoom) {
6403   CSSValueID id = range.Peek().Id();
6404   if ((id == CSSValueID::kPanX || id == CSSValueID::kPanRight ||
6405        id == CSSValueID::kPanLeft) &&
6406       !pan_x) {
6407     pan_x = css_property_parser_helpers::ConsumeIdent(range);
6408   } else if ((id == CSSValueID::kPanY || id == CSSValueID::kPanDown ||
6409               id == CSSValueID::kPanUp) &&
6410              !pan_y) {
6411     pan_y = css_property_parser_helpers::ConsumeIdent(range);
6412   } else if (id == CSSValueID::kPinchZoom && !pinch_zoom) {
6413     pinch_zoom = css_property_parser_helpers::ConsumeIdent(range);
6414   } else {
6415     return false;
6416   }
6417   return true;
6418 }
6419 
6420 }  // namespace
6421 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6422 const CSSValue* TouchAction::ParseSingleValue(
6423     CSSParserTokenRange& range,
6424     const CSSParserContext& context,
6425     const CSSParserLocalContext&) const {
6426   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6427   CSSValueID id = range.Peek().Id();
6428   if (id == CSSValueID::kAuto || id == CSSValueID::kNone ||
6429       id == CSSValueID::kManipulation) {
6430     list->Append(*css_property_parser_helpers::ConsumeIdent(range));
6431     return list;
6432   }
6433 
6434   CSSValue* pan_x = nullptr;
6435   CSSValue* pan_y = nullptr;
6436   CSSValue* pinch_zoom = nullptr;
6437   if (!ConsumePan(range, pan_x, pan_y, pinch_zoom))
6438     return nullptr;
6439   if (!range.AtEnd() && !ConsumePan(range, pan_x, pan_y, pinch_zoom))
6440     return nullptr;
6441   if (!range.AtEnd() && !ConsumePan(range, pan_x, pan_y, pinch_zoom))
6442     return nullptr;
6443 
6444   if (pan_x)
6445     list->Append(*pan_x);
6446   if (pan_y)
6447     list->Append(*pan_y);
6448   if (pinch_zoom)
6449     list->Append(*pinch_zoom);
6450   return list;
6451 }
6452 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6453 const CSSValue* TouchAction::CSSValueFromComputedStyleInternal(
6454     const ComputedStyle& style,
6455     const SVGComputedStyle&,
6456     const LayoutObject*,
6457     bool allow_visited_style) const {
6458   return ComputedStyleUtils::TouchActionFlagsToCSSValue(style.GetTouchAction());
6459 }
6460 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6461 const CSSValue* TransformBox::CSSValueFromComputedStyleInternal(
6462     const ComputedStyle& style,
6463     const SVGComputedStyle&,
6464     const LayoutObject*,
6465     bool allow_visited_style) const {
6466   return CSSIdentifierValue::Create(style.TransformBox());
6467 }
6468 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const6469 const CSSValue* Transform::ParseSingleValue(
6470     CSSParserTokenRange& range,
6471     const CSSParserContext& context,
6472     const CSSParserLocalContext& local_context) const {
6473   return css_parsing_utils::ConsumeTransformList(range, context, local_context);
6474 }
6475 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const6476 bool Transform::IsLayoutDependent(const ComputedStyle* style,
6477                                   LayoutObject* layout_object) const {
6478   return layout_object &&
6479          (layout_object->IsBox() || layout_object->IsSVGChild());
6480 }
6481 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const6482 const CSSValue* Transform::CSSValueFromComputedStyleInternal(
6483     const ComputedStyle& style,
6484     const SVGComputedStyle&,
6485     const LayoutObject* layout_object,
6486     bool allow_visited_style) const {
6487   return ComputedStyleUtils::ComputedTransform(layout_object, style);
6488 }
6489 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6490 const CSSValue* TransformOrigin::ParseSingleValue(
6491     CSSParserTokenRange& range,
6492     const CSSParserContext& context,
6493     const CSSParserLocalContext&) const {
6494   CSSValue* result_x = nullptr;
6495   CSSValue* result_y = nullptr;
6496   if (css_property_parser_helpers::ConsumeOneOrTwoValuedPosition(
6497           range, context, css_property_parser_helpers::UnitlessQuirk::kForbid,
6498           result_x, result_y)) {
6499     CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6500     list->Append(*result_x);
6501     list->Append(*result_y);
6502     CSSValue* result_z = css_property_parser_helpers::ConsumeLength(
6503         range, context, kValueRangeAll);
6504     if (result_z)
6505       list->Append(*result_z);
6506     return list;
6507   }
6508   return nullptr;
6509 }
6510 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const6511 bool TransformOrigin::IsLayoutDependent(const ComputedStyle* style,
6512                                         LayoutObject* layout_object) const {
6513   return layout_object &&
6514          (layout_object->IsBox() || layout_object->IsSVGChild());
6515 }
6516 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const6517 const CSSValue* TransformOrigin::CSSValueFromComputedStyleInternal(
6518     const ComputedStyle& style,
6519     const SVGComputedStyle&,
6520     const LayoutObject* layout_object,
6521     bool allow_visited_style) const {
6522   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6523   if (layout_object) {
6524     FloatRect reference_box = ComputedStyleUtils::ReferenceBoxForTransform(
6525         *layout_object, ComputedStyleUtils::kDontUsePixelSnappedBox);
6526     FloatSize resolved_origin(
6527         FloatValueForLength(style.TransformOriginX(), reference_box.Width()),
6528         FloatValueForLength(style.TransformOriginY(), reference_box.Height()));
6529     list->Append(*ZoomAdjustedPixelValue(resolved_origin.Width(), style));
6530     list->Append(*ZoomAdjustedPixelValue(resolved_origin.Height(), style));
6531   } else {
6532     list->Append(*ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
6533         style.TransformOriginX(), style));
6534     list->Append(*ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
6535         style.TransformOriginY(), style));
6536   }
6537   if (style.TransformOriginZ() != 0)
6538     list->Append(*ZoomAdjustedPixelValue(style.TransformOriginZ(), style));
6539   return list;
6540 }
6541 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6542 const CSSValue* TransformStyle::CSSValueFromComputedStyleInternal(
6543     const ComputedStyle& style,
6544     const SVGComputedStyle&,
6545     const LayoutObject*,
6546     bool allow_visited_style) const {
6547   return CSSIdentifierValue::Create(
6548       (style.TransformStyle3D() == ETransformStyle3D::kPreserve3d)
6549           ? CSSValueID::kPreserve3d
6550           : CSSValueID::kFlat);
6551 }
6552 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6553 const CSSValue* TransitionDelay::ParseSingleValue(
6554     CSSParserTokenRange& range,
6555     const CSSParserContext& context,
6556     const CSSParserLocalContext&) const {
6557   return css_property_parser_helpers::ConsumeCommaSeparatedList(
6558       css_property_parser_helpers::ConsumeTime, range, context, kValueRangeAll);
6559 }
6560 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6561 const CSSValue* TransitionDelay::CSSValueFromComputedStyleInternal(
6562     const ComputedStyle& style,
6563     const SVGComputedStyle&,
6564     const LayoutObject*,
6565     bool allow_visited_style) const {
6566   return ComputedStyleUtils::ValueForAnimationDelay(style.Transitions());
6567 }
6568 
InitialValue() const6569 const CSSValue* TransitionDelay::InitialValue() const {
6570   DEFINE_STATIC_LOCAL(
6571       const Persistent<CSSValue>, value,
6572       (CSSNumericLiteralValue::Create(CSSTimingData::InitialDelay(),
6573                                       CSSPrimitiveValue::UnitType::kSeconds)));
6574   return value;
6575 }
6576 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6577 const CSSValue* TransitionDuration::ParseSingleValue(
6578     CSSParserTokenRange& range,
6579     const CSSParserContext& context,
6580     const CSSParserLocalContext&) const {
6581   return css_property_parser_helpers::ConsumeCommaSeparatedList(
6582       css_property_parser_helpers::ConsumeTime, range, context,
6583       kValueRangeNonNegative);
6584 }
6585 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6586 const CSSValue* TransitionDuration::CSSValueFromComputedStyleInternal(
6587     const ComputedStyle& style,
6588     const SVGComputedStyle&,
6589     const LayoutObject*,
6590     bool allow_visited_style) const {
6591   return ComputedStyleUtils::ValueForAnimationDuration(style.Transitions());
6592 }
6593 
InitialValue() const6594 const CSSValue* TransitionDuration::InitialValue() const {
6595   DEFINE_STATIC_LOCAL(
6596       const Persistent<CSSValue>, value,
6597       (CSSNumericLiteralValue::Create(CSSTimingData::InitialDuration(),
6598                                       CSSPrimitiveValue::UnitType::kSeconds)));
6599   return value;
6600 }
6601 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6602 const CSSValue* TransitionProperty::ParseSingleValue(
6603     CSSParserTokenRange& range,
6604     const CSSParserContext& context,
6605     const CSSParserLocalContext&) const {
6606   CSSValueList* list = css_property_parser_helpers::ConsumeCommaSeparatedList(
6607       css_parsing_utils::ConsumeTransitionProperty, range, context);
6608   if (!list || !css_parsing_utils::IsValidPropertyList(*list))
6609     return nullptr;
6610   return list;
6611 }
6612 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6613 const CSSValue* TransitionProperty::CSSValueFromComputedStyleInternal(
6614     const ComputedStyle& style,
6615     const SVGComputedStyle&,
6616     const LayoutObject*,
6617     bool allow_visited_style) const {
6618   return ComputedStyleUtils::ValueForTransitionProperty(style.Transitions());
6619 }
6620 
InitialValue() const6621 const CSSValue* TransitionProperty::InitialValue() const {
6622   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
6623                       (CSSIdentifierValue::Create(CSSValueID::kAll)));
6624   return value;
6625 }
6626 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6627 const CSSValue* TransitionTimingFunction::ParseSingleValue(
6628     CSSParserTokenRange& range,
6629     const CSSParserContext& context,
6630     const CSSParserLocalContext&) const {
6631   return css_property_parser_helpers::ConsumeCommaSeparatedList(
6632       css_parsing_utils::ConsumeAnimationTimingFunction, range, context);
6633 }
6634 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6635 const CSSValue* TransitionTimingFunction::CSSValueFromComputedStyleInternal(
6636     const ComputedStyle& style,
6637     const SVGComputedStyle&,
6638     const LayoutObject*,
6639     bool allow_visited_style) const {
6640   return ComputedStyleUtils::ValueForAnimationTimingFunction(
6641       style.Transitions());
6642 }
6643 
InitialValue() const6644 const CSSValue* TransitionTimingFunction::InitialValue() const {
6645   DEFINE_STATIC_LOCAL(const Persistent<CSSValue>, value,
6646                       (CSSIdentifierValue::Create(CSSValueID::kEase)));
6647   return value;
6648 }
6649 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6650 const CSSValue* Translate::ParseSingleValue(
6651     CSSParserTokenRange& range,
6652     const CSSParserContext& context,
6653     const CSSParserLocalContext&) const {
6654   DCHECK(RuntimeEnabledFeatures::CSSIndependentTransformPropertiesEnabled());
6655   CSSValueID id = range.Peek().Id();
6656   if (id == CSSValueID::kNone)
6657     return css_property_parser_helpers::ConsumeIdent(range);
6658 
6659   CSSValue* translate_x = css_property_parser_helpers::ConsumeLengthOrPercent(
6660       range, context, kValueRangeAll);
6661   if (!translate_x)
6662     return nullptr;
6663   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6664   list->Append(*translate_x);
6665   CSSPrimitiveValue* translate_y =
6666       css_property_parser_helpers::ConsumeLengthOrPercent(range, context,
6667                                                           kValueRangeAll);
6668   if (translate_y) {
6669     CSSValue* translate_z = css_property_parser_helpers::ConsumeLength(
6670         range, context, kValueRangeAll);
6671     if (translate_y->IsZero() && !translate_z)
6672       return list;
6673 
6674     list->Append(*translate_y);
6675     if (translate_z) {
6676       list->Append(*translate_z);
6677     }
6678   }
6679 
6680   return list;
6681 }
6682 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const6683 bool Translate::IsLayoutDependent(const ComputedStyle* style,
6684                                   LayoutObject* layout_object) const {
6685   return layout_object && layout_object->IsBox();
6686 }
6687 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const6688 const CSSValue* Translate::CSSValueFromComputedStyleInternal(
6689     const ComputedStyle& style,
6690     const SVGComputedStyle&,
6691     const LayoutObject* layout_object,
6692     bool allow_visited_style) const {
6693   if (!style.Translate())
6694     return CSSIdentifierValue::Create(CSSValueID::kNone);
6695 
6696   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
6697   list->Append(*ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
6698       style.Translate()->X(), style));
6699 
6700   if (!style.Translate()->Y().IsZero() || style.Translate()->Z() != 0) {
6701     list->Append(*ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
6702         style.Translate()->Y(), style));
6703   }
6704 
6705   if (style.Translate()->Z() != 0)
6706     list->Append(*ZoomAdjustedPixelValue(style.Translate()->Z(), style));
6707 
6708   return list;
6709 }
6710 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6711 const CSSValue* UnicodeBidi::CSSValueFromComputedStyleInternal(
6712     const ComputedStyle& style,
6713     const SVGComputedStyle&,
6714     const LayoutObject*,
6715     bool allow_visited_style) const {
6716   return CSSIdentifierValue::Create(style.GetUnicodeBidi());
6717 }
6718 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6719 const CSSValue* UserSelect::CSSValueFromComputedStyleInternal(
6720     const ComputedStyle& style,
6721     const SVGComputedStyle&,
6722     const LayoutObject*,
6723     bool allow_visited_style) const {
6724   return CSSIdentifierValue::Create(style.UserSelect());
6725 }
6726 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const6727 const CSSValue* VectorEffect::CSSValueFromComputedStyleInternal(
6728     const ComputedStyle& style,
6729     const SVGComputedStyle& svg_style,
6730     const LayoutObject*,
6731     bool allow_visited_style) const {
6732   return CSSIdentifierValue::Create(svg_style.VectorEffect());
6733 }
6734 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6735 const CSSValue* VerticalAlign::ParseSingleValue(
6736     CSSParserTokenRange& range,
6737     const CSSParserContext& context,
6738     const CSSParserLocalContext&) const {
6739   CSSValue* parsed_value = css_property_parser_helpers::ConsumeIdentRange(
6740       range, CSSValueID::kBaseline, CSSValueID::kWebkitBaselineMiddle);
6741   if (!parsed_value) {
6742     parsed_value = css_property_parser_helpers::ConsumeLengthOrPercent(
6743         range, context, kValueRangeAll,
6744         css_property_parser_helpers::UnitlessQuirk::kAllow);
6745   }
6746   return parsed_value;
6747 }
6748 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6749 const CSSValue* VerticalAlign::CSSValueFromComputedStyleInternal(
6750     const ComputedStyle& style,
6751     const SVGComputedStyle&,
6752     const LayoutObject*,
6753     bool allow_visited_style) const {
6754   switch (style.VerticalAlign()) {
6755     case EVerticalAlign::kBaseline:
6756       return CSSIdentifierValue::Create(CSSValueID::kBaseline);
6757     case EVerticalAlign::kMiddle:
6758       return CSSIdentifierValue::Create(CSSValueID::kMiddle);
6759     case EVerticalAlign::kSub:
6760       return CSSIdentifierValue::Create(CSSValueID::kSub);
6761     case EVerticalAlign::kSuper:
6762       return CSSIdentifierValue::Create(CSSValueID::kSuper);
6763     case EVerticalAlign::kTextTop:
6764       return CSSIdentifierValue::Create(CSSValueID::kTextTop);
6765     case EVerticalAlign::kTextBottom:
6766       return CSSIdentifierValue::Create(CSSValueID::kTextBottom);
6767     case EVerticalAlign::kTop:
6768       return CSSIdentifierValue::Create(CSSValueID::kTop);
6769     case EVerticalAlign::kBottom:
6770       return CSSIdentifierValue::Create(CSSValueID::kBottom);
6771     case EVerticalAlign::kBaselineMiddle:
6772       return CSSIdentifierValue::Create(CSSValueID::kWebkitBaselineMiddle);
6773     case EVerticalAlign::kLength:
6774       return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(
6775           style.GetVerticalAlignLength(), style);
6776   }
6777   NOTREACHED();
6778   return nullptr;
6779 }
6780 
ApplyInherit(StyleResolverState & state) const6781 void VerticalAlign::ApplyInherit(StyleResolverState& state) const {
6782   EVerticalAlign vertical_align = state.ParentStyle()->VerticalAlign();
6783   state.Style()->SetVerticalAlign(vertical_align);
6784   if (vertical_align == EVerticalAlign::kLength) {
6785     state.Style()->SetVerticalAlignLength(
6786         state.ParentStyle()->GetVerticalAlignLength());
6787   }
6788 }
6789 
ApplyValue(StyleResolverState & state,const CSSValue & value) const6790 void VerticalAlign::ApplyValue(StyleResolverState& state,
6791                                const CSSValue& value) const {
6792   if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
6793     state.Style()->SetVerticalAlign(
6794         identifier_value->ConvertTo<EVerticalAlign>());
6795   } else {
6796     state.Style()->SetVerticalAlignLength(
6797         To<CSSPrimitiveValue>(value).ConvertToLength(
6798             state.CssToLengthConversionData()));
6799   }
6800 }
6801 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6802 const CSSValue* Visibility::CSSValueFromComputedStyleInternal(
6803     const ComputedStyle& style,
6804     const SVGComputedStyle&,
6805     const LayoutObject*,
6806     bool allow_visited_style) const {
6807   return CSSIdentifierValue::Create(style.Visibility());
6808 }
6809 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6810 const CSSValue* WebkitAppRegion::CSSValueFromComputedStyleInternal(
6811     const ComputedStyle& style,
6812     const SVGComputedStyle&,
6813     const LayoutObject*,
6814     bool allow_visited_style) const {
6815   if (style.DraggableRegionMode() == EDraggableRegionMode::kNone)
6816     return CSSIdentifierValue::Create(CSSValueID::kNone);
6817   return CSSIdentifierValue::Create(style.DraggableRegionMode() ==
6818                                             EDraggableRegionMode::kDrag
6819                                         ? CSSValueID::kDrag
6820                                         : CSSValueID::kNoDrag);
6821 }
6822 
ApplyInitial(StyleResolverState & state) const6823 void WebkitAppRegion::ApplyInitial(StyleResolverState& state) const {}
6824 
ApplyInherit(StyleResolverState & state) const6825 void WebkitAppRegion::ApplyInherit(StyleResolverState& state) const {}
6826 
ApplyValue(StyleResolverState & state,const CSSValue & value) const6827 void WebkitAppRegion::ApplyValue(StyleResolverState& state,
6828                                  const CSSValue& value) const {
6829   const auto& identifier_value = To<CSSIdentifierValue>(value);
6830   state.Style()->SetDraggableRegionMode(identifier_value.GetValueID() ==
6831                                                 CSSValueID::kDrag
6832                                             ? EDraggableRegionMode::kDrag
6833                                             : EDraggableRegionMode::kNoDrag);
6834   state.GetDocument().SetHasAnnotatedRegions(true);
6835 }
6836 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6837 const CSSValue* WebkitAppearance::CSSValueFromComputedStyleInternal(
6838     const ComputedStyle& style,
6839     const SVGComputedStyle&,
6840     const LayoutObject*,
6841     bool allow_visited_style) const {
6842   return CSSIdentifierValue::Create(style.Appearance());
6843 }
6844 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6845 const CSSValue* WebkitBorderHorizontalSpacing::ParseSingleValue(
6846     CSSParserTokenRange& range,
6847     const CSSParserContext& context,
6848     const CSSParserLocalContext&) const {
6849   return css_property_parser_helpers::ConsumeLength(range, context,
6850                                                     kValueRangeNonNegative);
6851 }
6852 
6853 const CSSValue*
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6854 WebkitBorderHorizontalSpacing::CSSValueFromComputedStyleInternal(
6855     const ComputedStyle& style,
6856     const SVGComputedStyle&,
6857     const LayoutObject*,
6858     bool allow_visited_style) const {
6859   return ZoomAdjustedPixelValue(style.HorizontalBorderSpacing(), style);
6860 }
6861 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6862 const CSSValue* WebkitBorderImage::ParseSingleValue(
6863     CSSParserTokenRange& range,
6864     const CSSParserContext& context,
6865     const CSSParserLocalContext&) const {
6866   return css_parsing_utils::ConsumeWebkitBorderImage(range, context);
6867 }
6868 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6869 const CSSValue* WebkitBorderImage::CSSValueFromComputedStyleInternal(
6870     const ComputedStyle& style,
6871     const SVGComputedStyle&,
6872     const LayoutObject*,
6873     bool allow_visited_style) const {
6874   return ComputedStyleUtils::ValueForNinePieceImage(style.BorderImage(), style,
6875                                                     allow_visited_style);
6876 }
6877 
ApplyValue(StyleResolverState & state,const CSSValue & value) const6878 void WebkitBorderImage::ApplyValue(StyleResolverState& state,
6879                                    const CSSValue& value) const {
6880   NinePieceImage image;
6881   CSSToStyleMap::MapNinePieceImage(state, CSSPropertyID::kWebkitBorderImage,
6882                                    value, image);
6883   state.Style()->SetBorderImage(image);
6884 }
6885 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6886 const CSSValue* WebkitBorderVerticalSpacing::ParseSingleValue(
6887     CSSParserTokenRange& range,
6888     const CSSParserContext& context,
6889     const CSSParserLocalContext&) const {
6890   return css_property_parser_helpers::ConsumeLength(range, context,
6891                                                     kValueRangeNonNegative);
6892 }
6893 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6894 const CSSValue* WebkitBorderVerticalSpacing::CSSValueFromComputedStyleInternal(
6895     const ComputedStyle& style,
6896     const SVGComputedStyle&,
6897     const LayoutObject*,
6898     bool allow_visited_style) const {
6899   return ZoomAdjustedPixelValue(style.VerticalBorderSpacing(), style);
6900 }
6901 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6902 const CSSValue* WebkitBoxAlign::CSSValueFromComputedStyleInternal(
6903     const ComputedStyle& style,
6904     const SVGComputedStyle&,
6905     const LayoutObject*,
6906     bool allow_visited_style) const {
6907   return CSSIdentifierValue::Create(style.BoxAlign());
6908 }
6909 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6910 const CSSValue* WebkitBoxDecorationBreak::CSSValueFromComputedStyleInternal(
6911     const ComputedStyle& style,
6912     const SVGComputedStyle&,
6913     const LayoutObject*,
6914     bool allow_visited_style) const {
6915   if (style.BoxDecorationBreak() == EBoxDecorationBreak::kSlice)
6916     return CSSIdentifierValue::Create(CSSValueID::kSlice);
6917   return CSSIdentifierValue::Create(CSSValueID::kClone);
6918 }
6919 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6920 const CSSValue* WebkitBoxDirection::CSSValueFromComputedStyleInternal(
6921     const ComputedStyle& style,
6922     const SVGComputedStyle&,
6923     const LayoutObject*,
6924     bool allow_visited_style) const {
6925   return CSSIdentifierValue::Create(style.BoxDirection());
6926 }
6927 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6928 const CSSValue* WebkitBoxFlex::ParseSingleValue(
6929     CSSParserTokenRange& range,
6930     const CSSParserContext& context,
6931     const CSSParserLocalContext&) const {
6932   return css_property_parser_helpers::ConsumeNumber(range, context,
6933                                                     kValueRangeAll);
6934 }
6935 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6936 const CSSValue* WebkitBoxFlex::CSSValueFromComputedStyleInternal(
6937     const ComputedStyle& style,
6938     const SVGComputedStyle&,
6939     const LayoutObject*,
6940     bool allow_visited_style) const {
6941   return CSSNumericLiteralValue::Create(style.BoxFlex(),
6942                                         CSSPrimitiveValue::UnitType::kNumber);
6943 }
6944 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const6945 const CSSValue* WebkitBoxOrdinalGroup::ParseSingleValue(
6946     CSSParserTokenRange& range,
6947     const CSSParserContext& context,
6948     const CSSParserLocalContext&) const {
6949   return css_property_parser_helpers::ConsumePositiveInteger(range, context);
6950 }
6951 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6952 const CSSValue* WebkitBoxOrdinalGroup::CSSValueFromComputedStyleInternal(
6953     const ComputedStyle& style,
6954     const SVGComputedStyle&,
6955     const LayoutObject*,
6956     bool allow_visited_style) const {
6957   return CSSNumericLiteralValue::Create(style.BoxOrdinalGroup(),
6958                                         CSSPrimitiveValue::UnitType::kNumber);
6959 }
6960 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6961 const CSSValue* WebkitBoxOrient::CSSValueFromComputedStyleInternal(
6962     const ComputedStyle& style,
6963     const SVGComputedStyle&,
6964     const LayoutObject*,
6965     bool allow_visited_style) const {
6966   return CSSIdentifierValue::Create(style.BoxOrient());
6967 }
6968 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const6969 const CSSValue* WebkitBoxPack::CSSValueFromComputedStyleInternal(
6970     const ComputedStyle& style,
6971     const SVGComputedStyle&,
6972     const LayoutObject*,
6973     bool allow_visited_style) const {
6974   return CSSIdentifierValue::Create(style.BoxPack());
6975 }
6976 
6977 namespace {
6978 
ConsumeReflect(CSSParserTokenRange & range,const CSSParserContext & context)6979 CSSValue* ConsumeReflect(CSSParserTokenRange& range,
6980                          const CSSParserContext& context) {
6981   CSSIdentifierValue* direction = css_property_parser_helpers::ConsumeIdent<
6982       CSSValueID::kAbove, CSSValueID::kBelow, CSSValueID::kLeft,
6983       CSSValueID::kRight>(range);
6984   if (!direction)
6985     return nullptr;
6986 
6987   CSSPrimitiveValue* offset = nullptr;
6988   if (range.AtEnd()) {
6989     offset =
6990         CSSNumericLiteralValue::Create(0, CSSPrimitiveValue::UnitType::kPixels);
6991   } else {
6992     offset = ConsumeLengthOrPercent(
6993         range, context, kValueRangeAll,
6994         css_property_parser_helpers::UnitlessQuirk::kForbid);
6995     if (!offset)
6996       return nullptr;
6997   }
6998 
6999   CSSValue* mask = nullptr;
7000   if (!range.AtEnd()) {
7001     mask = css_parsing_utils::ConsumeWebkitBorderImage(range, context);
7002     if (!mask)
7003       return nullptr;
7004   }
7005   return MakeGarbageCollected<cssvalue::CSSReflectValue>(direction, offset,
7006                                                          mask);
7007 }
7008 
7009 }  // namespace
7010 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7011 const CSSValue* WebkitBoxReflect::ParseSingleValue(
7012     CSSParserTokenRange& range,
7013     const CSSParserContext& context,
7014     const CSSParserLocalContext&) const {
7015   return ConsumeReflect(range, context);
7016 }
7017 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7018 const CSSValue* WebkitBoxReflect::CSSValueFromComputedStyleInternal(
7019     const ComputedStyle& style,
7020     const SVGComputedStyle&,
7021     const LayoutObject*,
7022     bool allow_visited_style) const {
7023   return ComputedStyleUtils::ValueForReflection(style.BoxReflect(), style,
7024                                                 allow_visited_style);
7025 }
7026 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7027 const CSSValue* WebkitFontSizeDelta::ParseSingleValue(
7028     CSSParserTokenRange& range,
7029     const CSSParserContext& context,
7030     const CSSParserLocalContext&) const {
7031   return css_property_parser_helpers::ConsumeLength(
7032       range, context, kValueRangeAll,
7033       css_property_parser_helpers::UnitlessQuirk::kAllow);
7034 }
7035 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7036 const CSSValue* WebkitFontSmoothing::CSSValueFromComputedStyleInternal(
7037     const ComputedStyle& style,
7038     const SVGComputedStyle&,
7039     const LayoutObject*,
7040     bool allow_visited_style) const {
7041   return CSSIdentifierValue::Create(style.GetFontDescription().FontSmoothing());
7042 }
7043 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7044 const CSSValue* WebkitHighlight::ParseSingleValue(
7045     CSSParserTokenRange& range,
7046     const CSSParserContext& context,
7047     const CSSParserLocalContext&) const {
7048   if (range.Peek().Id() == CSSValueID::kNone)
7049     return css_property_parser_helpers::ConsumeIdent(range);
7050   return css_property_parser_helpers::ConsumeString(range);
7051 }
7052 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7053 const CSSValue* WebkitHighlight::CSSValueFromComputedStyleInternal(
7054     const ComputedStyle& style,
7055     const SVGComputedStyle&,
7056     const LayoutObject*,
7057     bool allow_visited_style) const {
7058   if (style.Highlight() == g_null_atom)
7059     return CSSIdentifierValue::Create(CSSValueID::kNone);
7060   return MakeGarbageCollected<CSSStringValue>(style.Highlight());
7061 }
7062 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const7063 const CSSValue* WebkitHyphenateCharacter::ParseSingleValue(
7064     CSSParserTokenRange& range,
7065     const CSSParserContext&,
7066     const CSSParserLocalContext&) const {
7067   if (range.Peek().Id() == CSSValueID::kAuto)
7068     return css_property_parser_helpers::ConsumeIdent(range);
7069   return css_property_parser_helpers::ConsumeString(range);
7070 }
7071 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7072 const CSSValue* WebkitHyphenateCharacter::CSSValueFromComputedStyleInternal(
7073     const ComputedStyle& style,
7074     const SVGComputedStyle&,
7075     const LayoutObject*,
7076     bool allow_visited_style) const {
7077   if (style.HyphenationString().IsNull())
7078     return CSSIdentifierValue::Create(CSSValueID::kAuto);
7079   return MakeGarbageCollected<CSSStringValue>(style.HyphenationString());
7080 }
7081 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7082 const CSSValue* WebkitLineBreak::CSSValueFromComputedStyleInternal(
7083     const ComputedStyle& style,
7084     const SVGComputedStyle&,
7085     const LayoutObject*,
7086     bool allow_visited_style) const {
7087   return CSSIdentifierValue::Create(style.GetLineBreak());
7088 }
7089 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7090 const CSSValue* WebkitLineClamp::ParseSingleValue(
7091     CSSParserTokenRange& range,
7092     const CSSParserContext& context,
7093     const CSSParserLocalContext&) const {
7094   // When specifying number of lines, don't allow 0 as a valid value.
7095   return css_property_parser_helpers::ConsumePositiveInteger(range, context);
7096 }
7097 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7098 const CSSValue* WebkitLineClamp::CSSValueFromComputedStyleInternal(
7099     const ComputedStyle& style,
7100     const SVGComputedStyle&,
7101     const LayoutObject*,
7102     bool allow_visited_style) const {
7103   if (!style.HasLineClamp())
7104     return CSSIdentifierValue::Create(CSSValueID::kNone);
7105   return CSSNumericLiteralValue::Create(style.LineClamp(),
7106                                         CSSPrimitiveValue::UnitType::kNumber);
7107 }
7108 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const7109 const CSSValue* WebkitLocale::ParseSingleValue(
7110     CSSParserTokenRange& range,
7111     const CSSParserContext&,
7112     const CSSParserLocalContext&) const {
7113   if (range.Peek().Id() == CSSValueID::kAuto)
7114     return css_property_parser_helpers::ConsumeIdent(range);
7115   return css_property_parser_helpers::ConsumeString(range);
7116 }
7117 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7118 const CSSValue* WebkitLocale::CSSValueFromComputedStyleInternal(
7119     const ComputedStyle& style,
7120     const SVGComputedStyle&,
7121     const LayoutObject*,
7122     bool allow_visited_style) const {
7123   if (style.Locale().IsNull())
7124     return CSSIdentifierValue::Create(CSSValueID::kAuto);
7125   return MakeGarbageCollected<CSSStringValue>(style.Locale());
7126 }
7127 
ApplyValue(StyleResolverState & state,const CSSValue & value) const7128 void WebkitLocale::ApplyValue(StyleResolverState& state,
7129                               const CSSValue& value) const {
7130   if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
7131     DCHECK_EQ(identifier_value->GetValueID(), CSSValueID::kAuto);
7132     state.GetFontBuilder().SetLocale(nullptr);
7133   } else {
7134     state.GetFontBuilder().SetLocale(
7135         LayoutLocale::Get(AtomicString(To<CSSStringValue>(value).Value())));
7136   }
7137 }
7138 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7139 const CSSValue* WebkitMaskBoxImageOutset::ParseSingleValue(
7140     CSSParserTokenRange& range,
7141     const CSSParserContext& context,
7142     const CSSParserLocalContext&) const {
7143   return css_parsing_utils::ConsumeBorderImageOutset(range, context);
7144 }
7145 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7146 const CSSValue* WebkitMaskBoxImageOutset::CSSValueFromComputedStyleInternal(
7147     const ComputedStyle& style,
7148     const SVGComputedStyle&,
7149     const LayoutObject*,
7150     bool allow_visited_style) const {
7151   return ComputedStyleUtils::ValueForNinePieceImageQuad(
7152       style.MaskBoxImage().Outset(), style);
7153 }
7154 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const7155 const CSSValue* WebkitMaskBoxImageRepeat::ParseSingleValue(
7156     CSSParserTokenRange& range,
7157     const CSSParserContext&,
7158     const CSSParserLocalContext&) const {
7159   return css_parsing_utils::ConsumeBorderImageRepeat(range);
7160 }
7161 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7162 const CSSValue* WebkitMaskBoxImageRepeat::CSSValueFromComputedStyleInternal(
7163     const ComputedStyle& style,
7164     const SVGComputedStyle&,
7165     const LayoutObject*,
7166     bool allow_visited_style) const {
7167   return ComputedStyleUtils::ValueForNinePieceImageRepeat(style.MaskBoxImage());
7168 }
7169 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7170 const CSSValue* WebkitMaskBoxImageSlice::ParseSingleValue(
7171     CSSParserTokenRange& range,
7172     const CSSParserContext& context,
7173     const CSSParserLocalContext&) const {
7174   return css_parsing_utils::ConsumeBorderImageSlice(
7175       range, context, css_parsing_utils::DefaultFill::kNoFill);
7176 }
7177 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7178 const CSSValue* WebkitMaskBoxImageSlice::CSSValueFromComputedStyleInternal(
7179     const ComputedStyle& style,
7180     const SVGComputedStyle&,
7181     const LayoutObject*,
7182     bool allow_visited_style) const {
7183   return ComputedStyleUtils::ValueForNinePieceImageSlice(style.MaskBoxImage());
7184 }
7185 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7186 const CSSValue* WebkitMaskBoxImageSource::ParseSingleValue(
7187     CSSParserTokenRange& range,
7188     const CSSParserContext& context,
7189     const CSSParserLocalContext&) const {
7190   return css_property_parser_helpers::ConsumeImageOrNone(range, context);
7191 }
7192 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7193 const CSSValue* WebkitMaskBoxImageSource::CSSValueFromComputedStyleInternal(
7194     const ComputedStyle& style,
7195     const SVGComputedStyle&,
7196     const LayoutObject*,
7197     bool allow_visited_style) const {
7198   if (style.MaskBoxImageSource()) {
7199     return style.MaskBoxImageSource()->ComputedCSSValue(style,
7200                                                         allow_visited_style);
7201   }
7202   return CSSIdentifierValue::Create(CSSValueID::kNone);
7203 }
7204 
ApplyValue(StyleResolverState & state,const CSSValue & value) const7205 void WebkitMaskBoxImageSource::ApplyValue(StyleResolverState& state,
7206                                           const CSSValue& value) const {
7207   state.Style()->SetMaskBoxImageSource(
7208       state.GetStyleImage(CSSPropertyID::kWebkitMaskBoxImageSource, value));
7209 }
7210 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7211 const CSSValue* WebkitMaskBoxImageWidth::ParseSingleValue(
7212     CSSParserTokenRange& range,
7213     const CSSParserContext& context,
7214     const CSSParserLocalContext&) const {
7215   return css_parsing_utils::ConsumeBorderImageWidth(range, context);
7216 }
7217 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7218 const CSSValue* WebkitMaskBoxImageWidth::CSSValueFromComputedStyleInternal(
7219     const ComputedStyle& style,
7220     const SVGComputedStyle&,
7221     const LayoutObject*,
7222     bool allow_visited_style) const {
7223   return ComputedStyleUtils::ValueForNinePieceImageQuad(
7224       style.MaskBoxImage().BorderSlices(), style);
7225 }
7226 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const7227 const CSSValue* WebkitMaskClip::ParseSingleValue(
7228     CSSParserTokenRange& range,
7229     const CSSParserContext&,
7230     const CSSParserLocalContext&) const {
7231   return css_property_parser_helpers::ConsumeCommaSeparatedList(
7232       css_parsing_utils::ConsumePrefixedBackgroundBox, range,
7233       css_parsing_utils::AllowTextValue::kAllow);
7234 }
7235 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7236 const CSSValue* WebkitMaskClip::CSSValueFromComputedStyleInternal(
7237     const ComputedStyle& style,
7238     const SVGComputedStyle&,
7239     const LayoutObject*,
7240     bool allow_visited_style) const {
7241   CSSValueList* list = CSSValueList::CreateCommaSeparated();
7242   const FillLayer* curr_layer = &style.MaskLayers();
7243   for (; curr_layer; curr_layer = curr_layer->Next()) {
7244     EFillBox box = curr_layer->Clip();
7245     list->Append(*CSSIdentifierValue::Create(box));
7246   }
7247   return list;
7248 }
7249 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const7250 const CSSValue* WebkitMaskComposite::ParseSingleValue(
7251     CSSParserTokenRange& range,
7252     const CSSParserContext&,
7253     const CSSParserLocalContext&) const {
7254   return css_property_parser_helpers::ConsumeCommaSeparatedList(
7255       css_parsing_utils::ConsumeBackgroundComposite, range);
7256 }
7257 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7258 const CSSValue* WebkitMaskComposite::CSSValueFromComputedStyleInternal(
7259     const ComputedStyle& style,
7260     const SVGComputedStyle&,
7261     const LayoutObject*,
7262     bool allow_visited_style) const {
7263   CSSValueList* list = CSSValueList::CreateCommaSeparated();
7264   const FillLayer* curr_layer = &style.MaskLayers();
7265   for (; curr_layer; curr_layer = curr_layer->Next())
7266     list->Append(*CSSIdentifierValue::Create(curr_layer->Composite()));
7267   return list;
7268 }
7269 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7270 const CSSValue* WebkitMaskImage::ParseSingleValue(
7271     CSSParserTokenRange& range,
7272     const CSSParserContext& context,
7273     const CSSParserLocalContext&) const {
7274   return css_property_parser_helpers::ConsumeCommaSeparatedList(
7275       css_property_parser_helpers::ConsumeImageOrNone, range, context);
7276 }
7277 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7278 const CSSValue* WebkitMaskImage::CSSValueFromComputedStyleInternal(
7279     const ComputedStyle& style,
7280     const SVGComputedStyle&,
7281     const LayoutObject*,
7282     bool allow_visited_style) const {
7283   const FillLayer& fill_layer = style.MaskLayers();
7284   return ComputedStyleUtils::BackgroundImageOrWebkitMaskImage(
7285       style, allow_visited_style, fill_layer);
7286 }
7287 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const7288 const CSSValue* WebkitMaskOrigin::ParseSingleValue(
7289     CSSParserTokenRange& range,
7290     const CSSParserContext&,
7291     const CSSParserLocalContext&) const {
7292   return css_property_parser_helpers::ConsumeCommaSeparatedList(
7293       css_parsing_utils::ConsumePrefixedBackgroundBox, range,
7294       css_parsing_utils::AllowTextValue::kForbid);
7295 }
7296 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7297 const CSSValue* WebkitMaskOrigin::CSSValueFromComputedStyleInternal(
7298     const ComputedStyle& style,
7299     const SVGComputedStyle&,
7300     const LayoutObject*,
7301     bool allow_visited_style) const {
7302   CSSValueList* list = CSSValueList::CreateCommaSeparated();
7303   const FillLayer* curr_layer = &style.MaskLayers();
7304   for (; curr_layer; curr_layer = curr_layer->Next()) {
7305     EFillBox box = curr_layer->Origin();
7306     list->Append(*CSSIdentifierValue::Create(box));
7307   }
7308   return list;
7309 }
7310 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7311 const CSSValue* WebkitMaskPositionX::ParseSingleValue(
7312     CSSParserTokenRange& range,
7313     const CSSParserContext& context,
7314     const CSSParserLocalContext&) const {
7315   return css_property_parser_helpers::ConsumeCommaSeparatedList(
7316       css_parsing_utils::ConsumePositionLonghand<CSSValueID::kLeft,
7317                                                  CSSValueID::kRight>,
7318       range, context);
7319 }
7320 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7321 const CSSValue* WebkitMaskPositionX::CSSValueFromComputedStyleInternal(
7322     const ComputedStyle& style,
7323     const SVGComputedStyle&,
7324     const LayoutObject*,
7325     bool allow_visited_style) const {
7326   const FillLayer* curr_layer = &style.MaskLayers();
7327   return ComputedStyleUtils::BackgroundPositionXOrWebkitMaskPositionX(
7328       style, curr_layer);
7329 }
7330 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7331 const CSSValue* WebkitMaskPositionY::ParseSingleValue(
7332     CSSParserTokenRange& range,
7333     const CSSParserContext& context,
7334     const CSSParserLocalContext&) const {
7335   return css_property_parser_helpers::ConsumeCommaSeparatedList(
7336       css_parsing_utils::ConsumePositionLonghand<CSSValueID::kTop,
7337                                                  CSSValueID::kBottom>,
7338       range, context);
7339 }
7340 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7341 const CSSValue* WebkitMaskPositionY::CSSValueFromComputedStyleInternal(
7342     const ComputedStyle& style,
7343     const SVGComputedStyle&,
7344     const LayoutObject*,
7345     bool allow_visited_style) const {
7346   const FillLayer* curr_layer = &style.MaskLayers();
7347   return ComputedStyleUtils::BackgroundPositionYOrWebkitMaskPositionY(
7348       style, curr_layer);
7349 }
7350 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context) const7351 const CSSValue* WebkitMaskSize::ParseSingleValue(
7352     CSSParserTokenRange& range,
7353     const CSSParserContext& context,
7354     const CSSParserLocalContext& local_context) const {
7355   return css_parsing_utils::ParseBackgroundOrMaskSize(
7356       range, context, local_context, WebFeature::kNegativeMaskSize);
7357 }
7358 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7359 const CSSValue* WebkitMaskSize::CSSValueFromComputedStyleInternal(
7360     const ComputedStyle& style,
7361     const SVGComputedStyle&,
7362     const LayoutObject*,
7363     bool allow_visited_style) const {
7364   const FillLayer& fill_layer = style.MaskLayers();
7365   return ComputedStyleUtils::BackgroundImageOrWebkitMaskSize(style, fill_layer);
7366 }
7367 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7368 const CSSValue* WebkitPerspectiveOriginX::ParseSingleValue(
7369     CSSParserTokenRange& range,
7370     const CSSParserContext& context,
7371     const CSSParserLocalContext&) const {
7372   return css_parsing_utils::ConsumePositionLonghand<CSSValueID::kLeft,
7373                                                     CSSValueID::kRight>(
7374       range, context);
7375 }
7376 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7377 const CSSValue* WebkitPerspectiveOriginY::ParseSingleValue(
7378     CSSParserTokenRange& range,
7379     const CSSParserContext& context,
7380     const CSSParserLocalContext&) const {
7381   return css_parsing_utils::ConsumePositionLonghand<CSSValueID::kTop,
7382                                                     CSSValueID::kBottom>(
7383       range, context);
7384 }
7385 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7386 const CSSValue* WebkitPrintColorAdjust::CSSValueFromComputedStyleInternal(
7387     const ComputedStyle& style,
7388     const SVGComputedStyle&,
7389     const LayoutObject*,
7390     bool allow_visited_style) const {
7391   return CSSIdentifierValue::Create(style.PrintColorAdjust());
7392 }
7393 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7394 const CSSValue* WebkitRtlOrdering::CSSValueFromComputedStyleInternal(
7395     const ComputedStyle& style,
7396     const SVGComputedStyle&,
7397     const LayoutObject*,
7398     bool allow_visited_style) const {
7399   return CSSIdentifierValue::Create(style.RtlOrdering() == EOrder::kVisual
7400                                         ? CSSValueID::kVisual
7401                                         : CSSValueID::kLogical);
7402 }
7403 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7404 const CSSValue* WebkitRubyPosition::CSSValueFromComputedStyleInternal(
7405     const ComputedStyle& style,
7406     const SVGComputedStyle&,
7407     const LayoutObject*,
7408     bool allow_visited_style) const {
7409   return CSSIdentifierValue::Create(style.GetRubyPosition());
7410 }
7411 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7412 const CSSValue* WebkitTapHighlightColor::ParseSingleValue(
7413     CSSParserTokenRange& range,
7414     const CSSParserContext& context,
7415     const CSSParserLocalContext&) const {
7416   return css_property_parser_helpers::ConsumeColor(range, context);
7417 }
7418 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const7419 const blink::Color WebkitTapHighlightColor::ColorIncludingFallback(
7420     bool visited_link,
7421     const ComputedStyle& style) const {
7422   StyleColor result = style.TapHighlightColor();
7423   if (!result.IsCurrentColor())
7424     return result.GetColor();
7425   return visited_link ? style.InternalVisitedColor() : style.GetColor();
7426 }
7427 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7428 const CSSValue* WebkitTapHighlightColor::CSSValueFromComputedStyleInternal(
7429     const ComputedStyle& style,
7430     const SVGComputedStyle&,
7431     const LayoutObject*,
7432     bool allow_visited_style) const {
7433   return ComputedStyleUtils::CurrentColorOrValidColor(
7434       style, style.TapHighlightColor());
7435 }
7436 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7437 const CSSValue* WebkitTextCombine::CSSValueFromComputedStyleInternal(
7438     const ComputedStyle& style,
7439     const SVGComputedStyle&,
7440     const LayoutObject*,
7441     bool allow_visited_style) const {
7442   if (style.TextCombine() == ETextCombine::kAll)
7443     return CSSIdentifierValue::Create(CSSValueID::kHorizontal);
7444   return CSSIdentifierValue::Create(style.TextCombine());
7445 }
7446 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const7447 const CSSValue* WebkitTextDecorationsInEffect::ParseSingleValue(
7448     CSSParserTokenRange& range,
7449     const CSSParserContext&,
7450     const CSSParserLocalContext&) const {
7451   return css_parsing_utils::ConsumeTextDecorationLine(range);
7452 }
7453 
7454 const CSSValue*
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7455 WebkitTextDecorationsInEffect::CSSValueFromComputedStyleInternal(
7456     const ComputedStyle& style,
7457     const SVGComputedStyle&,
7458     const LayoutObject*,
7459     bool allow_visited_style) const {
7460   return ComputedStyleUtils::RenderTextDecorationFlagsToCSSValue(
7461       style.TextDecorationsInEffect());
7462 }
7463 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7464 const CSSValue* WebkitTextEmphasisColor::ParseSingleValue(
7465     CSSParserTokenRange& range,
7466     const CSSParserContext& context,
7467     const CSSParserLocalContext&) const {
7468   return css_property_parser_helpers::ConsumeColor(range, context);
7469 }
7470 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const7471 const blink::Color WebkitTextEmphasisColor::ColorIncludingFallback(
7472     bool visited_link,
7473     const ComputedStyle& style) const {
7474   DCHECK(!visited_link);
7475   return style.TextEmphasisColor().Resolve(style.GetColor());
7476 }
7477 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7478 const CSSValue* WebkitTextEmphasisColor::CSSValueFromComputedStyleInternal(
7479     const ComputedStyle& style,
7480     const SVGComputedStyle&,
7481     const LayoutObject*,
7482     bool allow_visited_style) const {
7483   return ComputedStyleUtils::CurrentColorOrValidColor(
7484       style, style.TextEmphasisColor());
7485 }
7486 
7487 // [ over | under ] && [ right | left ]?
7488 // If [ right | left ] is omitted, it defaults to right.
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7489 const CSSValue* WebkitTextEmphasisPosition::ParseSingleValue(
7490     CSSParserTokenRange& range,
7491     const CSSParserContext& context,
7492     const CSSParserLocalContext&) const {
7493   CSSIdentifierValue* values[2] = {
7494       css_property_parser_helpers::ConsumeIdent<
7495           CSSValueID::kOver, CSSValueID::kUnder, CSSValueID::kRight,
7496           CSSValueID::kLeft>(range),
7497       nullptr};
7498   if (!values[0])
7499     return nullptr;
7500   values[1] = css_property_parser_helpers::ConsumeIdent<
7501       CSSValueID::kOver, CSSValueID::kUnder, CSSValueID::kRight,
7502       CSSValueID::kLeft>(range);
7503   CSSIdentifierValue* over_under = nullptr;
7504   CSSIdentifierValue* left_right = nullptr;
7505 
7506   for (auto* value : values) {
7507     if (!value)
7508       break;
7509     switch (value->GetValueID()) {
7510       case CSSValueID::kOver:
7511       case CSSValueID::kUnder:
7512         if (over_under)
7513           return nullptr;
7514         over_under = value;
7515         break;
7516       case CSSValueID::kLeft:
7517       case CSSValueID::kRight:
7518         if (left_right)
7519           return nullptr;
7520         left_right = value;
7521         break;
7522       default:
7523         NOTREACHED();
7524         break;
7525     }
7526   }
7527   if (!over_under)
7528     return nullptr;
7529   if (!left_right)
7530     left_right = CSSIdentifierValue::Create(CSSValueID::kRight);
7531   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
7532   list->Append(*over_under);
7533   list->Append(*left_right);
7534   return list;
7535 }
7536 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7537 const CSSValue* WebkitTextEmphasisPosition::CSSValueFromComputedStyleInternal(
7538     const ComputedStyle& style,
7539     const SVGComputedStyle&,
7540     const LayoutObject*,
7541     bool allow_visited_style) const {
7542   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
7543   switch (style.GetTextEmphasisPosition()) {
7544     case TextEmphasisPosition::kOverRight:
7545       list->Append(*CSSIdentifierValue::Create(CSSValueID::kOver));
7546       list->Append(*CSSIdentifierValue::Create(CSSValueID::kRight));
7547       break;
7548     case TextEmphasisPosition::kOverLeft:
7549       list->Append(*CSSIdentifierValue::Create(CSSValueID::kOver));
7550       list->Append(*CSSIdentifierValue::Create(CSSValueID::kLeft));
7551       break;
7552     case TextEmphasisPosition::kUnderRight:
7553       list->Append(*CSSIdentifierValue::Create(CSSValueID::kUnder));
7554       list->Append(*CSSIdentifierValue::Create(CSSValueID::kRight));
7555       break;
7556     case TextEmphasisPosition::kUnderLeft:
7557       list->Append(*CSSIdentifierValue::Create(CSSValueID::kUnder));
7558       list->Append(*CSSIdentifierValue::Create(CSSValueID::kLeft));
7559       break;
7560   }
7561   return list;
7562 }
7563 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7564 const CSSValue* WebkitTextEmphasisStyle::ParseSingleValue(
7565     CSSParserTokenRange& range,
7566     const CSSParserContext& context,
7567     const CSSParserLocalContext&) const {
7568   CSSValueID id = range.Peek().Id();
7569   if (id == CSSValueID::kNone)
7570     return css_property_parser_helpers::ConsumeIdent(range);
7571 
7572   if (CSSValue* text_emphasis_style =
7573           css_property_parser_helpers::ConsumeString(range))
7574     return text_emphasis_style;
7575 
7576   CSSIdentifierValue* fill =
7577       css_property_parser_helpers::ConsumeIdent<CSSValueID::kFilled,
7578                                                 CSSValueID::kOpen>(range);
7579   CSSIdentifierValue* shape = css_property_parser_helpers::ConsumeIdent<
7580       CSSValueID::kDot, CSSValueID::kCircle, CSSValueID::kDoubleCircle,
7581       CSSValueID::kTriangle, CSSValueID::kSesame>(range);
7582   if (!fill) {
7583     fill = css_property_parser_helpers::ConsumeIdent<CSSValueID::kFilled,
7584                                                      CSSValueID::kOpen>(range);
7585   }
7586   if (fill && shape) {
7587     CSSValueList* parsed_values = CSSValueList::CreateSpaceSeparated();
7588     parsed_values->Append(*fill);
7589     parsed_values->Append(*shape);
7590     return parsed_values;
7591   }
7592   if (fill)
7593     return fill;
7594   if (shape)
7595     return shape;
7596   return nullptr;
7597 }
7598 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7599 const CSSValue* WebkitTextEmphasisStyle::CSSValueFromComputedStyleInternal(
7600     const ComputedStyle& style,
7601     const SVGComputedStyle&,
7602     const LayoutObject*,
7603     bool allow_visited_style) const {
7604   switch (style.GetTextEmphasisMark()) {
7605     case TextEmphasisMark::kNone:
7606       return CSSIdentifierValue::Create(CSSValueID::kNone);
7607     case TextEmphasisMark::kCustom:
7608       return MakeGarbageCollected<CSSStringValue>(
7609           style.TextEmphasisCustomMark());
7610     case TextEmphasisMark::kAuto:
7611       NOTREACHED();
7612       FALLTHROUGH;
7613     case TextEmphasisMark::kDot:
7614     case TextEmphasisMark::kCircle:
7615     case TextEmphasisMark::kDoubleCircle:
7616     case TextEmphasisMark::kTriangle:
7617     case TextEmphasisMark::kSesame: {
7618       CSSValueList* list = CSSValueList::CreateSpaceSeparated();
7619       list->Append(*CSSIdentifierValue::Create(style.GetTextEmphasisFill()));
7620       list->Append(*CSSIdentifierValue::Create(style.GetTextEmphasisMark()));
7621       return list;
7622     }
7623   }
7624   NOTREACHED();
7625   return nullptr;
7626 }
7627 
ApplyInitial(StyleResolverState & state) const7628 void WebkitTextEmphasisStyle::ApplyInitial(StyleResolverState& state) const {
7629   state.Style()->SetTextEmphasisFill(
7630       ComputedStyleInitialValues::InitialTextEmphasisFill());
7631   state.Style()->SetTextEmphasisMark(
7632       ComputedStyleInitialValues::InitialTextEmphasisMark());
7633   state.Style()->SetTextEmphasisCustomMark(
7634       ComputedStyleInitialValues::InitialTextEmphasisCustomMark());
7635 }
7636 
ApplyInherit(StyleResolverState & state) const7637 void WebkitTextEmphasisStyle::ApplyInherit(StyleResolverState& state) const {
7638   state.Style()->SetTextEmphasisFill(
7639       state.ParentStyle()->GetTextEmphasisFill());
7640   state.Style()->SetTextEmphasisMark(
7641       state.ParentStyle()->GetTextEmphasisMark());
7642   state.Style()->SetTextEmphasisCustomMark(
7643       state.ParentStyle()->TextEmphasisCustomMark());
7644 }
7645 
ApplyValue(StyleResolverState & state,const CSSValue & value) const7646 void WebkitTextEmphasisStyle::ApplyValue(StyleResolverState& state,
7647                                          const CSSValue& value) const {
7648   if (const auto* list = DynamicTo<CSSValueList>(value)) {
7649     DCHECK_EQ(list->length(), 2U);
7650     for (unsigned i = 0; i < 2; ++i) {
7651       const auto& ident_value = To<CSSIdentifierValue>(list->Item(i));
7652       if (ident_value.GetValueID() == CSSValueID::kFilled ||
7653           ident_value.GetValueID() == CSSValueID::kOpen) {
7654         state.Style()->SetTextEmphasisFill(
7655             ident_value.ConvertTo<TextEmphasisFill>());
7656       } else {
7657         state.Style()->SetTextEmphasisMark(
7658             ident_value.ConvertTo<TextEmphasisMark>());
7659       }
7660     }
7661     state.Style()->SetTextEmphasisCustomMark(g_null_atom);
7662     return;
7663   }
7664 
7665   if (auto* string_value = DynamicTo<CSSStringValue>(value)) {
7666     state.Style()->SetTextEmphasisFill(TextEmphasisFill::kFilled);
7667     state.Style()->SetTextEmphasisMark(TextEmphasisMark::kCustom);
7668     state.Style()->SetTextEmphasisCustomMark(
7669         AtomicString(string_value->Value()));
7670     return;
7671   }
7672 
7673   const auto& identifier_value = To<CSSIdentifierValue>(value);
7674 
7675   state.Style()->SetTextEmphasisCustomMark(g_null_atom);
7676 
7677   if (identifier_value.GetValueID() == CSSValueID::kFilled ||
7678       identifier_value.GetValueID() == CSSValueID::kOpen) {
7679     state.Style()->SetTextEmphasisFill(
7680         identifier_value.ConvertTo<TextEmphasisFill>());
7681     state.Style()->SetTextEmphasisMark(TextEmphasisMark::kAuto);
7682   } else {
7683     state.Style()->SetTextEmphasisFill(TextEmphasisFill::kFilled);
7684     state.Style()->SetTextEmphasisMark(
7685         identifier_value.ConvertTo<TextEmphasisMark>());
7686   }
7687 }
7688 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7689 const CSSValue* WebkitTextFillColor::ParseSingleValue(
7690     CSSParserTokenRange& range,
7691     const CSSParserContext& context,
7692     const CSSParserLocalContext&) const {
7693   return css_property_parser_helpers::ConsumeColor(range, context);
7694 }
7695 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const7696 const blink::Color WebkitTextFillColor::ColorIncludingFallback(
7697     bool visited_link,
7698     const ComputedStyle& style) const {
7699   DCHECK(!visited_link);
7700   return style.TextFillColor().Resolve(style.GetColor());
7701 }
7702 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7703 const CSSValue* WebkitTextFillColor::CSSValueFromComputedStyleInternal(
7704     const ComputedStyle& style,
7705     const SVGComputedStyle&,
7706     const LayoutObject*,
7707     bool allow_visited_style) const {
7708   return ComputedStyleUtils::CurrentColorOrValidColor(style,
7709                                                       style.TextFillColor());
7710 }
7711 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7712 const CSSValue* WebkitTextOrientation::CSSValueFromComputedStyleInternal(
7713     const ComputedStyle& style,
7714     const SVGComputedStyle&,
7715     const LayoutObject*,
7716     bool allow_visited_style) const {
7717   if (style.GetTextOrientation() == ETextOrientation::kMixed)
7718     return CSSIdentifierValue::Create(CSSValueID::kVerticalRight);
7719   return CSSIdentifierValue::Create(style.GetTextOrientation());
7720 }
7721 
ApplyValue(StyleResolverState & state,const CSSValue & value) const7722 void WebkitTextOrientation::ApplyValue(StyleResolverState& state,
7723                                        const CSSValue& value) const {
7724   state.SetTextOrientation(
7725       To<CSSIdentifierValue>(value).ConvertTo<ETextOrientation>());
7726 }
7727 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7728 const CSSValue* WebkitTextSecurity::CSSValueFromComputedStyleInternal(
7729     const ComputedStyle& style,
7730     const SVGComputedStyle&,
7731     const LayoutObject*,
7732     bool allow_visited_style) const {
7733   return CSSIdentifierValue::Create(style.TextSecurity());
7734 }
7735 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7736 const CSSValue* WebkitTextStrokeColor::ParseSingleValue(
7737     CSSParserTokenRange& range,
7738     const CSSParserContext& context,
7739     const CSSParserLocalContext&) const {
7740   return css_property_parser_helpers::ConsumeColor(range, context);
7741 }
7742 
ColorIncludingFallback(bool visited_link,const ComputedStyle & style) const7743 const blink::Color WebkitTextStrokeColor::ColorIncludingFallback(
7744     bool visited_link,
7745     const ComputedStyle& style) const {
7746   DCHECK(!visited_link);
7747   return style.TextStrokeColor().Resolve(style.GetColor());
7748 }
7749 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7750 const CSSValue* WebkitTextStrokeColor::CSSValueFromComputedStyleInternal(
7751     const ComputedStyle& style,
7752     const SVGComputedStyle&,
7753     const LayoutObject*,
7754     bool allow_visited_style) const {
7755   return ComputedStyleUtils::CurrentColorOrValidColor(style,
7756                                                       style.TextStrokeColor());
7757 }
7758 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7759 const CSSValue* WebkitTextStrokeWidth::ParseSingleValue(
7760     CSSParserTokenRange& range,
7761     const CSSParserContext& context,
7762     const CSSParserLocalContext&) const {
7763   return css_property_parser_helpers::ConsumeLineWidth(
7764       range, context, css_property_parser_helpers::UnitlessQuirk::kForbid);
7765 }
7766 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7767 const CSSValue* WebkitTextStrokeWidth::CSSValueFromComputedStyleInternal(
7768     const ComputedStyle& style,
7769     const SVGComputedStyle&,
7770     const LayoutObject*,
7771     bool allow_visited_style) const {
7772   return ZoomAdjustedPixelValue(style.TextStrokeWidth(), style);
7773 }
7774 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7775 const CSSValue* WebkitTransformOriginX::ParseSingleValue(
7776     CSSParserTokenRange& range,
7777     const CSSParserContext& context,
7778     const CSSParserLocalContext&) const {
7779   return css_parsing_utils::ConsumePositionLonghand<CSSValueID::kLeft,
7780                                                     CSSValueID::kRight>(
7781       range, context);
7782 }
7783 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7784 const CSSValue* WebkitTransformOriginY::ParseSingleValue(
7785     CSSParserTokenRange& range,
7786     const CSSParserContext& context,
7787     const CSSParserLocalContext&) const {
7788   return css_parsing_utils::ConsumePositionLonghand<CSSValueID::kTop,
7789                                                     CSSValueID::kBottom>(
7790       range, context);
7791 }
7792 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7793 const CSSValue* WebkitTransformOriginZ::ParseSingleValue(
7794     CSSParserTokenRange& range,
7795     const CSSParserContext& context,
7796     const CSSParserLocalContext&) const {
7797   return css_property_parser_helpers::ConsumeLength(range, context,
7798                                                     kValueRangeAll);
7799 }
7800 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7801 const CSSValue* WebkitUserDrag::CSSValueFromComputedStyleInternal(
7802     const ComputedStyle& style,
7803     const SVGComputedStyle&,
7804     const LayoutObject*,
7805     bool allow_visited_style) const {
7806   return CSSIdentifierValue::Create(style.UserDrag());
7807 }
7808 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7809 const CSSValue* WebkitUserModify::CSSValueFromComputedStyleInternal(
7810     const ComputedStyle& style,
7811     const SVGComputedStyle&,
7812     const LayoutObject*,
7813     bool allow_visited_style) const {
7814   return CSSIdentifierValue::Create(style.UserModify());
7815 }
7816 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7817 const CSSValue* WebkitWritingMode::CSSValueFromComputedStyleInternal(
7818     const ComputedStyle& style,
7819     const SVGComputedStyle&,
7820     const LayoutObject*,
7821     bool allow_visited_style) const {
7822   return CSSIdentifierValue::Create(style.GetWritingMode());
7823 }
7824 
ApplyValue(StyleResolverState & state,const CSSValue & value) const7825 void WebkitWritingMode::ApplyValue(StyleResolverState& state,
7826                                    const CSSValue& value) const {
7827   state.SetWritingMode(
7828       To<CSSIdentifierValue>(value).ConvertTo<blink::WritingMode>());
7829 }
7830 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7831 const CSSValue* WhiteSpace::CSSValueFromComputedStyleInternal(
7832     const ComputedStyle& style,
7833     const SVGComputedStyle&,
7834     const LayoutObject*,
7835     bool allow_visited_style) const {
7836   return CSSIdentifierValue::Create(style.WhiteSpace());
7837 }
7838 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7839 const CSSValue* Widows::ParseSingleValue(CSSParserTokenRange& range,
7840                                          const CSSParserContext& context,
7841                                          const CSSParserLocalContext&) const {
7842   return css_property_parser_helpers::ConsumePositiveInteger(range, context);
7843 }
7844 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7845 const CSSValue* Widows::CSSValueFromComputedStyleInternal(
7846     const ComputedStyle& style,
7847     const SVGComputedStyle&,
7848     const LayoutObject*,
7849     bool allow_visited_style) const {
7850   return CSSNumericLiteralValue::Create(style.Widows(),
7851                                         CSSPrimitiveValue::UnitType::kNumber);
7852 }
7853 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7854 const CSSValue* Width::ParseSingleValue(CSSParserTokenRange& range,
7855                                         const CSSParserContext& context,
7856                                         const CSSParserLocalContext&) const {
7857   return css_parsing_utils::ConsumeWidthOrHeight(
7858       range, context, css_property_parser_helpers::UnitlessQuirk::kAllow);
7859 }
7860 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const7861 bool Width::IsLayoutDependent(const ComputedStyle* style,
7862                               LayoutObject* layout_object) const {
7863   return layout_object && (layout_object->IsBox() || layout_object->IsSVG());
7864 }
7865 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const7866 const CSSValue* Width::CSSValueFromComputedStyleInternal(
7867     const ComputedStyle& style,
7868     const SVGComputedStyle&,
7869     const LayoutObject* layout_object,
7870     bool allow_visited_style) const {
7871   if (ComputedStyleUtils::WidthOrHeightShouldReturnUsedValue(layout_object)) {
7872     return ZoomAdjustedPixelValue(
7873         ComputedStyleUtils::UsedBoxSize(*layout_object).Width(), style);
7874   }
7875   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(style.Width(),
7876                                                              style);
7877 }
7878 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const7879 const CSSValue* WillChange::ParseSingleValue(
7880     CSSParserTokenRange& range,
7881     const CSSParserContext& context,
7882     const CSSParserLocalContext&) const {
7883   if (range.Peek().Id() == CSSValueID::kAuto)
7884     return css_property_parser_helpers::ConsumeIdent(range);
7885 
7886   CSSValueList* values = CSSValueList::CreateCommaSeparated();
7887   // Every comma-separated list of identifiers is a valid will-change value,
7888   // unless the list includes an explicitly disallowed identifier.
7889   while (true) {
7890     if (range.Peek().GetType() != kIdentToken)
7891       return nullptr;
7892     CSSPropertyID unresolved_property = UnresolvedCSSPropertyID(
7893         context.GetExecutionContext(), range.Peek().Value());
7894     if (unresolved_property != CSSPropertyID::kInvalid &&
7895         unresolved_property != CSSPropertyID::kVariable) {
7896 #if DCHECK_IS_ON()
7897       DCHECK(CSSProperty::Get(resolveCSSPropertyID(unresolved_property))
7898                  .IsWebExposed(context.GetExecutionContext()));
7899 #endif
7900       // Now "all" is used by both CSSValue and CSSPropertyValue.
7901       // Need to return nullptr when currentValue is CSSPropertyID::kAll.
7902       if (unresolved_property == CSSPropertyID::kWillChange ||
7903           unresolved_property == CSSPropertyID::kAll)
7904         return nullptr;
7905       values->Append(
7906           *MakeGarbageCollected<CSSCustomIdentValue>(unresolved_property));
7907       range.ConsumeIncludingWhitespace();
7908     } else {
7909       switch (range.Peek().Id()) {
7910         case CSSValueID::kNone:
7911         case CSSValueID::kAll:
7912         case CSSValueID::kAuto:
7913         case CSSValueID::kDefault:
7914         case CSSValueID::kInitial:
7915         case CSSValueID::kInherit:
7916           return nullptr;
7917         case CSSValueID::kContents:
7918         case CSSValueID::kScrollPosition:
7919           values->Append(*css_property_parser_helpers::ConsumeIdent(range));
7920           break;
7921         default:
7922           range.ConsumeIncludingWhitespace();
7923           break;
7924       }
7925     }
7926 
7927     if (range.AtEnd())
7928       break;
7929     if (!css_property_parser_helpers::ConsumeCommaIncludingWhitespace(range))
7930       return nullptr;
7931   }
7932 
7933   return values;
7934 }
7935 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7936 const CSSValue* WillChange::CSSValueFromComputedStyleInternal(
7937     const ComputedStyle& style,
7938     const SVGComputedStyle&,
7939     const LayoutObject*,
7940     bool allow_visited_style) const {
7941   return ComputedStyleUtils::ValueForWillChange(
7942       style.WillChangeProperties(), style.WillChangeContents(),
7943       style.WillChangeScrollPosition());
7944 }
7945 
ApplyInitial(StyleResolverState & state) const7946 void WillChange::ApplyInitial(StyleResolverState& state) const {
7947   state.Style()->SetWillChangeContents(false);
7948   state.Style()->SetWillChangeScrollPosition(false);
7949   state.Style()->SetWillChangeProperties(Vector<CSSPropertyID>());
7950   state.Style()->SetSubtreeWillChangeContents(
7951       state.ParentStyle()->SubtreeWillChangeContents());
7952 }
7953 
ApplyInherit(StyleResolverState & state) const7954 void WillChange::ApplyInherit(StyleResolverState& state) const {
7955   state.Style()->SetWillChangeContents(
7956       state.ParentStyle()->WillChangeContents());
7957   state.Style()->SetWillChangeScrollPosition(
7958       state.ParentStyle()->WillChangeScrollPosition());
7959   state.Style()->SetWillChangeProperties(
7960       state.ParentStyle()->WillChangeProperties());
7961   state.Style()->SetSubtreeWillChangeContents(
7962       state.ParentStyle()->SubtreeWillChangeContents());
7963 }
7964 
ApplyValue(StyleResolverState & state,const CSSValue & value) const7965 void WillChange::ApplyValue(StyleResolverState& state,
7966                             const CSSValue& value) const {
7967   bool will_change_contents = false;
7968   bool will_change_scroll_position = false;
7969   Vector<CSSPropertyID> will_change_properties;
7970 
7971   if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
7972     DCHECK_EQ(identifier_value->GetValueID(), CSSValueID::kAuto);
7973   } else {
7974     for (auto& will_change_value : To<CSSValueList>(value)) {
7975       if (auto* ident_value =
7976               DynamicTo<CSSCustomIdentValue>(will_change_value.Get())) {
7977         will_change_properties.push_back(ident_value->ValueAsPropertyID());
7978       } else if (To<CSSIdentifierValue>(*will_change_value).GetValueID() ==
7979                  CSSValueID::kContents) {
7980         will_change_contents = true;
7981       } else if (To<CSSIdentifierValue>(*will_change_value).GetValueID() ==
7982                  CSSValueID::kScrollPosition) {
7983         will_change_scroll_position = true;
7984       } else {
7985         NOTREACHED();
7986       }
7987     }
7988   }
7989   state.Style()->SetWillChangeContents(will_change_contents);
7990   state.Style()->SetWillChangeScrollPosition(will_change_scroll_position);
7991   state.Style()->SetWillChangeProperties(will_change_properties);
7992   state.Style()->SetSubtreeWillChangeContents(
7993       will_change_contents || state.ParentStyle()->SubtreeWillChangeContents());
7994 }
7995 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const7996 const CSSValue* WordBreak::CSSValueFromComputedStyleInternal(
7997     const ComputedStyle& style,
7998     const SVGComputedStyle&,
7999     const LayoutObject*,
8000     bool allow_visited_style) const {
8001   return CSSIdentifierValue::Create(style.WordBreak());
8002 }
8003 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const8004 const CSSValue* WordSpacing::ParseSingleValue(
8005     CSSParserTokenRange& range,
8006     const CSSParserContext& context,
8007     const CSSParserLocalContext&) const {
8008   return css_parsing_utils::ParseSpacing(range, context);
8009 }
8010 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const8011 const CSSValue* WordSpacing::CSSValueFromComputedStyleInternal(
8012     const ComputedStyle& style,
8013     const SVGComputedStyle&,
8014     const LayoutObject*,
8015     bool allow_visited_style) const {
8016   return ZoomAdjustedPixelValue(style.WordSpacing(), style);
8017 }
8018 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const8019 const CSSValue* WritingMode::CSSValueFromComputedStyleInternal(
8020     const ComputedStyle& style,
8021     const SVGComputedStyle&,
8022     const LayoutObject*,
8023     bool allow_visited_style) const {
8024   return CSSIdentifierValue::Create(style.GetWritingMode());
8025 }
8026 
ApplyValue(StyleResolverState & state,const CSSValue & value) const8027 void WritingMode::ApplyValue(StyleResolverState& state,
8028                              const CSSValue& value) const {
8029   state.SetWritingMode(
8030       To<CSSIdentifierValue>(value).ConvertTo<blink::WritingMode>());
8031 }
8032 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const8033 const CSSValue* X::ParseSingleValue(CSSParserTokenRange& range,
8034                                     const CSSParserContext& context,
8035                                     const CSSParserLocalContext&) const {
8036   return css_property_parser_helpers::ConsumeSVGGeometryPropertyLength(
8037       range, context, kValueRangeAll);
8038 }
8039 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const8040 const CSSValue* X::CSSValueFromComputedStyleInternal(
8041     const ComputedStyle& style,
8042     const SVGComputedStyle& svg_style,
8043     const LayoutObject*,
8044     bool allow_visited_style) const {
8045   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(svg_style.X(),
8046                                                              style);
8047 }
8048 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const8049 const CSSValue* Y::ParseSingleValue(CSSParserTokenRange& range,
8050                                     const CSSParserContext& context,
8051                                     const CSSParserLocalContext&) const {
8052   return css_property_parser_helpers::ConsumeSVGGeometryPropertyLength(
8053       range, context, kValueRangeAll);
8054 }
8055 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject *,bool allow_visited_style) const8056 const CSSValue* Y::CSSValueFromComputedStyleInternal(
8057     const ComputedStyle& style,
8058     const SVGComputedStyle& svg_style,
8059     const LayoutObject*,
8060     bool allow_visited_style) const {
8061   return ComputedStyleUtils::ZoomAdjustedPixelValueForLength(svg_style.Y(),
8062                                                              style);
8063 }
8064 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const8065 const CSSValue* ZIndex::ParseSingleValue(CSSParserTokenRange& range,
8066                                          const CSSParserContext& context,
8067                                          const CSSParserLocalContext&) const {
8068   if (range.Peek().Id() == CSSValueID::kAuto)
8069     return css_property_parser_helpers::ConsumeIdent(range);
8070   return css_property_parser_helpers::ConsumeInteger(range, context);
8071 }
8072 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const8073 const CSSValue* ZIndex::CSSValueFromComputedStyleInternal(
8074     const ComputedStyle& style,
8075     const SVGComputedStyle&,
8076     const LayoutObject*,
8077     bool allow_visited_style) const {
8078   if (style.HasAutoZIndex() || !style.IsStackingContext())
8079     return CSSIdentifierValue::Create(CSSValueID::kAuto);
8080   return CSSNumericLiteralValue::Create(style.ZIndex(),
8081                                         CSSPrimitiveValue::UnitType::kInteger);
8082 }
8083 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &) const8084 const CSSValue* Zoom::ParseSingleValue(CSSParserTokenRange& range,
8085                                        const CSSParserContext& context,
8086                                        const CSSParserLocalContext&) const {
8087   const CSSParserToken& token = range.Peek();
8088   CSSValue* zoom = nullptr;
8089   if (token.GetType() == kIdentToken) {
8090     zoom =
8091         css_property_parser_helpers::ConsumeIdent<CSSValueID::kNormal>(range);
8092   } else {
8093     zoom = css_property_parser_helpers::ConsumePercent(range, context,
8094                                                        kValueRangeNonNegative);
8095     if (!zoom) {
8096       zoom = css_property_parser_helpers::ConsumeNumber(range, context,
8097                                                         kValueRangeNonNegative);
8098     }
8099   }
8100   if (zoom) {
8101     if (!(token.Id() == CSSValueID::kNormal ||
8102           (token.GetType() == kNumberToken &&
8103            To<CSSPrimitiveValue>(zoom)->GetDoubleValue() == 1) ||
8104           (token.GetType() == kPercentageToken &&
8105            To<CSSPrimitiveValue>(zoom)->GetDoubleValue() == 100)))
8106       context.Count(WebFeature::kCSSZoomNotEqualToOne);
8107   }
8108   return zoom;
8109 }
8110 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const8111 const CSSValue* Zoom::CSSValueFromComputedStyleInternal(
8112     const ComputedStyle& style,
8113     const SVGComputedStyle&,
8114     const LayoutObject*,
8115     bool allow_visited_style) const {
8116   return CSSNumericLiteralValue::Create(style.Zoom(),
8117                                         CSSPrimitiveValue::UnitType::kNumber);
8118 }
8119 
ApplyInitial(StyleResolverState & state) const8120 void Zoom::ApplyInitial(StyleResolverState& state) const {
8121   state.SetZoom(ComputedStyleInitialValues::InitialZoom());
8122 }
8123 
ApplyInherit(StyleResolverState & state) const8124 void Zoom::ApplyInherit(StyleResolverState& state) const {
8125   state.SetZoom(state.ParentStyle()->Zoom());
8126 }
8127 
ApplyValue(StyleResolverState & state,const CSSValue & value) const8128 void Zoom::ApplyValue(StyleResolverState& state, const CSSValue& value) const {
8129   state.SetZoom(StyleBuilderConverter::ConvertZoom(state, value));
8130 }
8131 
ParseSingleValue(CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &) const8132 const CSSValue* InternalEmptyLineHeight::ParseSingleValue(
8133     CSSParserTokenRange& range,
8134     const CSSParserContext&,
8135     const CSSParserLocalContext&) const {
8136   return css_property_parser_helpers::ConsumeIdent<CSSValueID::kFabricated,
8137                                                    CSSValueID::kNone>(range);
8138 }
8139 
8140 }  // namespace css_longhand
8141 }  // namespace blink
8142