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 "base/stl_util.h"
6 #include "third_party/blink/renderer/core/css/css_content_distribution_value.h"
7 #include "third_party/blink/renderer/core/css/css_font_family_value.h"
8 #include "third_party/blink/renderer/core/css/css_identifier_value.h"
9 #include "third_party/blink/renderer/core/css/css_initial_value.h"
10 #include "third_party/blink/renderer/core/css/css_numeric_literal_value.h"
11 #include "third_party/blink/renderer/core/css/css_primitive_value_mappings.h"
12 #include "third_party/blink/renderer/core/css/css_property_value.h"
13 #include "third_party/blink/renderer/core/css/css_value_pair.h"
14 #include "third_party/blink/renderer/core/css/parser/css_parser_context.h"
15 #include "third_party/blink/renderer/core/css/parser/css_parser_fast_paths.h"
16 #include "third_party/blink/renderer/core/css/parser/css_parser_local_context.h"
17 #include "third_party/blink/renderer/core/css/parser/css_property_parser_helpers.h"
18 #include "third_party/blink/renderer/core/css/parser/font_variant_east_asian_parser.h"
19 #include "third_party/blink/renderer/core/css/parser/font_variant_ligatures_parser.h"
20 #include "third_party/blink/renderer/core/css/parser/font_variant_numeric_parser.h"
21 #include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
22 #include "third_party/blink/renderer/core/css/properties/css_parsing_utils.h"
23 #include "third_party/blink/renderer/core/css/properties/longhand.h"
24 #include "third_party/blink/renderer/core/css/properties/shorthands.h"
25 #include "third_party/blink/renderer/core/css/zoom_adjusted_pixel_value.h"
26 #include "third_party/blink/renderer/core/layout/layout_object.h"
27 #include "third_party/blink/renderer/core/layout/layout_theme.h"
28 #include "third_party/blink/renderer/core/style/computed_style.h"
29 #include "third_party/blink/renderer/core/style_property_shorthand.h"
30 #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
31 
32 // Implementations of methods in Shorthand subclasses that aren't generated.
33 
34 namespace blink {
35 namespace css_shorthand {
36 
37 namespace {
38 
39 // Legacy parsing allows <string>s for animation-name.
ConsumeAnimationValue(CSSPropertyID property,CSSParserTokenRange & range,const CSSParserContext & context,bool use_legacy_parsing)40 CSSValue* ConsumeAnimationValue(CSSPropertyID property,
41                                 CSSParserTokenRange& range,
42                                 const CSSParserContext& context,
43                                 bool use_legacy_parsing) {
44   switch (property) {
45     case CSSPropertyID::kAnimationDelay:
46       return css_property_parser_helpers::ConsumeTime(range, context,
47                                                       kValueRangeAll);
48     case CSSPropertyID::kAnimationDirection:
49       return css_property_parser_helpers::ConsumeIdent<
50           CSSValueID::kNormal, CSSValueID::kAlternate, CSSValueID::kReverse,
51           CSSValueID::kAlternateReverse>(range);
52     case CSSPropertyID::kAnimationDuration:
53       return css_property_parser_helpers::ConsumeTime(range, context,
54                                                       kValueRangeNonNegative);
55     case CSSPropertyID::kAnimationFillMode:
56       return css_property_parser_helpers::ConsumeIdent<
57           CSSValueID::kNone, CSSValueID::kForwards, CSSValueID::kBackwards,
58           CSSValueID::kBoth>(range);
59     case CSSPropertyID::kAnimationIterationCount:
60       return css_parsing_utils::ConsumeAnimationIterationCount(range, context);
61     case CSSPropertyID::kAnimationName:
62       return css_parsing_utils::ConsumeAnimationName(range, context,
63                                                      use_legacy_parsing);
64     case CSSPropertyID::kAnimationPlayState:
65       return css_property_parser_helpers::ConsumeIdent<CSSValueID::kRunning,
66                                                        CSSValueID::kPaused>(
67           range);
68     case CSSPropertyID::kAnimationTimingFunction:
69       return css_parsing_utils::ConsumeAnimationTimingFunction(range, context);
70     default:
71       NOTREACHED();
72       return nullptr;
73   }
74 }
75 
76 }  // namespace
77 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const78 bool Animation::ParseShorthand(
79     bool important,
80     CSSParserTokenRange& range,
81     const CSSParserContext& context,
82     const CSSParserLocalContext& local_context,
83     HeapVector<CSSPropertyValue, 256>& properties) const {
84   const StylePropertyShorthand shorthand = animationShorthandForParsing();
85   const unsigned longhand_count = shorthand.length();
86 
87   HeapVector<Member<CSSValueList>, css_parsing_utils::kMaxNumAnimationLonghands>
88       longhands(longhand_count);
89   if (!css_parsing_utils::ConsumeAnimationShorthand(
90           shorthand, longhands, ConsumeAnimationValue, range, context,
91           local_context.UseAliasParsing())) {
92     return false;
93   }
94 
95   for (unsigned i = 0; i < longhand_count; ++i) {
96     css_property_parser_helpers::AddProperty(
97         shorthand.properties()[i]->PropertyID(), shorthand.id(), *longhands[i],
98         important,
99         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
100         properties);
101   }
102   return range.AtEnd();
103 }
104 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const105 const CSSValue* Animation::CSSValueFromComputedStyleInternal(
106     const ComputedStyle& style,
107     const SVGComputedStyle&,
108     const LayoutObject*,
109     bool allow_visited_style) const {
110   const CSSAnimationData* animation_data = style.Animations();
111   if (animation_data) {
112     CSSValueList* animations_list = CSSValueList::CreateCommaSeparated();
113     for (wtf_size_t i = 0; i < animation_data->NameList().size(); ++i) {
114       CSSValueList* list = CSSValueList::CreateSpaceSeparated();
115       list->Append(*CSSNumericLiteralValue::Create(
116           CSSTimingData::GetRepeated(animation_data->DurationList(), i),
117           CSSPrimitiveValue::UnitType::kSeconds));
118       list->Append(*ComputedStyleUtils::CreateTimingFunctionValue(
119           CSSTimingData::GetRepeated(animation_data->TimingFunctionList(), i)
120               .get()));
121       list->Append(*CSSNumericLiteralValue::Create(
122           CSSTimingData::GetRepeated(animation_data->DelayList(), i),
123           CSSPrimitiveValue::UnitType::kSeconds));
124       list->Append(*ComputedStyleUtils::ValueForAnimationIterationCount(
125           CSSTimingData::GetRepeated(animation_data->IterationCountList(), i)));
126       list->Append(*ComputedStyleUtils::ValueForAnimationDirection(
127           CSSTimingData::GetRepeated(animation_data->DirectionList(), i)));
128       list->Append(*ComputedStyleUtils::ValueForAnimationFillMode(
129           CSSTimingData::GetRepeated(animation_data->FillModeList(), i)));
130       list->Append(*ComputedStyleUtils::ValueForAnimationPlayState(
131           CSSTimingData::GetRepeated(animation_data->PlayStateList(), i)));
132       list->Append(*MakeGarbageCollected<CSSCustomIdentValue>(
133           animation_data->NameList()[i]));
134       animations_list->Append(*list);
135     }
136     return animations_list;
137   }
138 
139   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
140   // animation-name default value.
141   list->Append(*CSSIdentifierValue::Create(CSSValueID::kNone));
142   list->Append(
143       *CSSNumericLiteralValue::Create(CSSAnimationData::InitialDuration(),
144                                       CSSPrimitiveValue::UnitType::kSeconds));
145   list->Append(*ComputedStyleUtils::CreateTimingFunctionValue(
146       CSSAnimationData::InitialTimingFunction().get()));
147   list->Append(*CSSNumericLiteralValue::Create(
148       CSSAnimationData::InitialDelay(), CSSPrimitiveValue::UnitType::kSeconds));
149   list->Append(
150       *CSSNumericLiteralValue::Create(CSSAnimationData::InitialIterationCount(),
151                                       CSSPrimitiveValue::UnitType::kNumber));
152   list->Append(*ComputedStyleUtils::ValueForAnimationDirection(
153       CSSAnimationData::InitialDirection()));
154   list->Append(*ComputedStyleUtils::ValueForAnimationFillMode(
155       CSSAnimationData::InitialFillMode()));
156   // Initial animation-play-state.
157   list->Append(*CSSIdentifierValue::Create(CSSValueID::kRunning));
158   return list;
159 }
160 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const161 bool Background::ParseShorthand(
162     bool important,
163     CSSParserTokenRange& range,
164     const CSSParserContext& context,
165     const CSSParserLocalContext& local_context,
166     HeapVector<CSSPropertyValue, 256>& properties) const {
167   return css_parsing_utils::ParseBackgroundOrMask(important, range, context,
168                                                   local_context, properties);
169 }
170 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const171 const CSSValue* Background::CSSValueFromComputedStyleInternal(
172     const ComputedStyle& style,
173     const SVGComputedStyle&,
174     const LayoutObject* layout_object,
175     bool allow_visited_style) const {
176   return ComputedStyleUtils::ValuesForBackgroundShorthand(style, layout_object,
177                                                           allow_visited_style);
178 }
179 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const180 bool BackgroundPosition::ParseShorthand(
181     bool important,
182     CSSParserTokenRange& range,
183     const CSSParserContext& context,
184     const CSSParserLocalContext&,
185     HeapVector<CSSPropertyValue, 256>& properties) const {
186   CSSValue* result_x = nullptr;
187   CSSValue* result_y = nullptr;
188 
189   if (!css_parsing_utils::ConsumeBackgroundPosition(
190           range, context, css_property_parser_helpers::UnitlessQuirk::kAllow,
191           result_x, result_y) ||
192       !range.AtEnd())
193     return false;
194 
195   css_property_parser_helpers::AddProperty(
196       CSSPropertyID::kBackgroundPositionX, CSSPropertyID::kBackgroundPosition,
197       *result_x, important,
198       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
199       properties);
200 
201   css_property_parser_helpers::AddProperty(
202       CSSPropertyID::kBackgroundPositionY, CSSPropertyID::kBackgroundPosition,
203       *result_y, important,
204       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
205       properties);
206   return true;
207 }
208 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const209 const CSSValue* BackgroundPosition::CSSValueFromComputedStyleInternal(
210     const ComputedStyle& style,
211     const SVGComputedStyle&,
212     const LayoutObject*,
213     bool allow_visited_style) const {
214   return ComputedStyleUtils::BackgroundPositionOrWebkitMaskPosition(
215       *this, style, &style.BackgroundLayers());
216 }
217 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const218 bool BackgroundRepeat::ParseShorthand(
219     bool important,
220     CSSParserTokenRange& range,
221     const CSSParserContext& context,
222     const CSSParserLocalContext& local_context,
223     HeapVector<CSSPropertyValue, 256>& properties) const {
224   CSSValue* result_x = nullptr;
225   CSSValue* result_y = nullptr;
226   bool implicit = false;
227   if (!css_parsing_utils::ConsumeRepeatStyle(range, result_x, result_y,
228                                              implicit) ||
229       !range.AtEnd())
230     return false;
231 
232   css_property_parser_helpers::AddProperty(
233       CSSPropertyID::kBackgroundRepeatX, CSSPropertyID::kBackgroundRepeat,
234       *result_x, important,
235       implicit ? css_property_parser_helpers::IsImplicitProperty::kImplicit
236                : css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
237       properties);
238   css_property_parser_helpers::AddProperty(
239       CSSPropertyID::kBackgroundRepeatY, CSSPropertyID::kBackgroundRepeat,
240       *result_y, important,
241       implicit ? css_property_parser_helpers::IsImplicitProperty::kImplicit
242                : css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
243       properties);
244 
245   return true;
246 }
247 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const248 const CSSValue* BackgroundRepeat::CSSValueFromComputedStyleInternal(
249     const ComputedStyle& style,
250     const SVGComputedStyle&,
251     const LayoutObject*,
252     bool allow_visited_style) const {
253   return ComputedStyleUtils::BackgroundRepeatOrWebkitMaskRepeat(
254       &style.BackgroundLayers());
255 }
256 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const257 bool BorderBlockColor::ParseShorthand(
258     bool important,
259     CSSParserTokenRange& range,
260     const CSSParserContext& context,
261     const CSSParserLocalContext&,
262     HeapVector<CSSPropertyValue, 256>& properties) const {
263   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
264       borderBlockColorShorthand(), important, context, range, properties);
265 }
266 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const267 const CSSValue* BorderBlockColor::CSSValueFromComputedStyleInternal(
268     const ComputedStyle& style,
269     const SVGComputedStyle&,
270     const LayoutObject* layout_object,
271     bool allow_visited_style) const {
272   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
273       borderBlockColorShorthand(), style, layout_object, allow_visited_style);
274 }
275 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const276 bool BorderBlock::ParseShorthand(
277     bool important,
278     CSSParserTokenRange& range,
279     const CSSParserContext& context,
280     const CSSParserLocalContext&,
281     HeapVector<CSSPropertyValue, 256>& properties) const {
282   const CSSValue* width = nullptr;
283   const CSSValue* style = nullptr;
284   const CSSValue* color = nullptr;
285 
286   if (!css_property_parser_helpers::ConsumeBorderShorthand(
287           range, context, width, style, color)) {
288     return false;
289   };
290 
291   css_property_parser_helpers::AddExpandedPropertyForValue(
292       CSSPropertyID::kBorderBlockWidth, *width, important, properties);
293   css_property_parser_helpers::AddExpandedPropertyForValue(
294       CSSPropertyID::kBorderBlockStyle, *style, important, properties);
295   css_property_parser_helpers::AddExpandedPropertyForValue(
296       CSSPropertyID::kBorderBlockColor, *color, important, properties);
297 
298   return range.AtEnd();
299 }
300 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const301 const CSSValue* BorderBlock::CSSValueFromComputedStyleInternal(
302     const ComputedStyle& style,
303     const SVGComputedStyle&,
304     const LayoutObject* layout_object,
305     bool allow_visited_style) const {
306   const CSSValue* value_start =
307       GetCSSPropertyBorderBlockStart().CSSValueFromComputedStyle(
308           style, layout_object, allow_visited_style);
309   const CSSValue* value_end =
310       GetCSSPropertyBorderBlockEnd().CSSValueFromComputedStyle(
311           style, layout_object, allow_visited_style);
312   if (!DataEquivalent(value_start, value_end)) {
313     return nullptr;
314   }
315   return value_start;
316 }
317 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const318 bool BorderBlockEnd::ParseShorthand(
319     bool important,
320     CSSParserTokenRange& range,
321     const CSSParserContext& context,
322     const CSSParserLocalContext&,
323     HeapVector<CSSPropertyValue, 256>& properties) const {
324   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
325       borderBlockEndShorthand(), important, context, range, properties);
326 }
327 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const328 bool BorderBlockStart::ParseShorthand(
329     bool important,
330     CSSParserTokenRange& range,
331     const CSSParserContext& context,
332     const CSSParserLocalContext&,
333     HeapVector<CSSPropertyValue, 256>& properties) const {
334   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
335       borderBlockStartShorthand(), important, context, range, properties);
336 }
337 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const338 bool BorderBlockStyle::ParseShorthand(
339     bool important,
340     CSSParserTokenRange& range,
341     const CSSParserContext& context,
342     const CSSParserLocalContext&,
343     HeapVector<CSSPropertyValue, 256>& properties) const {
344   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
345       borderBlockStyleShorthand(), important, context, range, properties);
346 }
347 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const348 const CSSValue* BorderBlockStyle::CSSValueFromComputedStyleInternal(
349     const ComputedStyle& style,
350     const SVGComputedStyle&,
351     const LayoutObject* layout_object,
352     bool allow_visited_style) const {
353   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
354       borderBlockStyleShorthand(), style, layout_object, allow_visited_style);
355 }
356 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const357 bool BorderBlockWidth::ParseShorthand(
358     bool important,
359     CSSParserTokenRange& range,
360     const CSSParserContext& context,
361     const CSSParserLocalContext&,
362     HeapVector<CSSPropertyValue, 256>& properties) const {
363   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
364       borderBlockWidthShorthand(), important, context, range, properties);
365 }
366 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const367 const CSSValue* BorderBlockWidth::CSSValueFromComputedStyleInternal(
368     const ComputedStyle& style,
369     const SVGComputedStyle&,
370     const LayoutObject* layout_object,
371     bool allow_visited_style) const {
372   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
373       borderBlockWidthShorthand(), style, layout_object, allow_visited_style);
374 }
375 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const376 bool BorderBottom::ParseShorthand(
377     bool important,
378     CSSParserTokenRange& range,
379     const CSSParserContext& context,
380     const CSSParserLocalContext&,
381     HeapVector<CSSPropertyValue, 256>& properties) const {
382   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
383       borderBottomShorthand(), important, context, range, properties);
384 }
385 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const386 const CSSValue* BorderBottom::CSSValueFromComputedStyleInternal(
387     const ComputedStyle& style,
388     const SVGComputedStyle&,
389     const LayoutObject* layout_object,
390     bool allow_visited_style) const {
391   return ComputedStyleUtils::ValuesForShorthandProperty(
392       borderBottomShorthand(), style, layout_object, allow_visited_style);
393 }
394 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const395 bool BorderColor::ParseShorthand(
396     bool important,
397     CSSParserTokenRange& range,
398     const CSSParserContext& context,
399     const CSSParserLocalContext&,
400     HeapVector<CSSPropertyValue, 256>& properties) const {
401   return css_property_parser_helpers::ConsumeShorthandVia4Longhands(
402       borderColorShorthand(), important, context, range, properties);
403 }
404 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const405 const CSSValue* BorderColor::CSSValueFromComputedStyleInternal(
406     const ComputedStyle& style,
407     const SVGComputedStyle&,
408     const LayoutObject* layout_object,
409     bool allow_visited_style) const {
410   return ComputedStyleUtils::ValuesForSidesShorthand(
411       borderColorShorthand(), style, layout_object, allow_visited_style);
412 }
413 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const414 bool Border::ParseShorthand(
415     bool important,
416     CSSParserTokenRange& range,
417     const CSSParserContext& context,
418     const CSSParserLocalContext&,
419     HeapVector<CSSPropertyValue, 256>& properties) const {
420   const CSSValue* width = nullptr;
421   const CSSValue* style = nullptr;
422   const CSSValue* color = nullptr;
423 
424   if (!css_property_parser_helpers::ConsumeBorderShorthand(
425           range, context, width, style, color)) {
426     return false;
427   };
428 
429   css_property_parser_helpers::AddExpandedPropertyForValue(
430       CSSPropertyID::kBorderWidth, *width, important, properties);
431   css_property_parser_helpers::AddExpandedPropertyForValue(
432       CSSPropertyID::kBorderStyle, *style, important, properties);
433   css_property_parser_helpers::AddExpandedPropertyForValue(
434       CSSPropertyID::kBorderColor, *color, important, properties);
435   css_property_parser_helpers::AddExpandedPropertyForValue(
436       CSSPropertyID::kBorderImage, *CSSInitialValue::Create(), important,
437       properties);
438 
439   return range.AtEnd();
440 }
441 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const442 const CSSValue* Border::CSSValueFromComputedStyleInternal(
443     const ComputedStyle& style,
444     const SVGComputedStyle&,
445     const LayoutObject* layout_object,
446     bool allow_visited_style) const {
447   const CSSValue* value = GetCSSPropertyBorderTop().CSSValueFromComputedStyle(
448       style, layout_object, allow_visited_style);
449   static const CSSProperty* kProperties[3] = {&GetCSSPropertyBorderRight(),
450                                               &GetCSSPropertyBorderBottom(),
451                                               &GetCSSPropertyBorderLeft()};
452   for (size_t i = 0; i < base::size(kProperties); ++i) {
453     const CSSValue* value_for_side = kProperties[i]->CSSValueFromComputedStyle(
454         style, layout_object, allow_visited_style);
455     if (!DataEquivalent(value, value_for_side)) {
456       return nullptr;
457     }
458   }
459   return value;
460 }
461 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const462 bool BorderImage::ParseShorthand(
463     bool important,
464     CSSParserTokenRange& range,
465     const CSSParserContext& context,
466     const CSSParserLocalContext&,
467     HeapVector<CSSPropertyValue, 256>& properties) const {
468   CSSValue* source = nullptr;
469   CSSValue* slice = nullptr;
470   CSSValue* width = nullptr;
471   CSSValue* outset = nullptr;
472   CSSValue* repeat = nullptr;
473 
474   if (!css_parsing_utils::ConsumeBorderImageComponents(
475           range, context, source, slice, width, outset, repeat,
476           css_parsing_utils::DefaultFill::kNoFill)) {
477     return false;
478   }
479 
480   css_property_parser_helpers::AddProperty(
481       CSSPropertyID::kBorderImageSource, CSSPropertyID::kBorderImage,
482       source
483           ? *source
484           : *To<Longhand>(&GetCSSPropertyBorderImageSource())->InitialValue(),
485       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
486       properties);
487   css_property_parser_helpers::AddProperty(
488       CSSPropertyID::kBorderImageSlice, CSSPropertyID::kBorderImage,
489       slice ? *slice
490             : *To<Longhand>(&GetCSSPropertyBorderImageSlice())->InitialValue(),
491       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
492       properties);
493   css_property_parser_helpers::AddProperty(
494       CSSPropertyID::kBorderImageWidth, CSSPropertyID::kBorderImage,
495       width ? *width
496             : *To<Longhand>(&GetCSSPropertyBorderImageWidth())->InitialValue(),
497       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
498       properties);
499   css_property_parser_helpers::AddProperty(
500       CSSPropertyID::kBorderImageOutset, CSSPropertyID::kBorderImage,
501       outset
502           ? *outset
503           : *To<Longhand>(&GetCSSPropertyBorderImageOutset())->InitialValue(),
504       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
505       properties);
506   css_property_parser_helpers::AddProperty(
507       CSSPropertyID::kBorderImageRepeat, CSSPropertyID::kBorderImage,
508       repeat
509           ? *repeat
510           : *To<Longhand>(&GetCSSPropertyBorderImageRepeat())->InitialValue(),
511       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
512       properties);
513 
514   return true;
515 }
516 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const517 const CSSValue* BorderImage::CSSValueFromComputedStyleInternal(
518     const ComputedStyle& style,
519     const SVGComputedStyle&,
520     const LayoutObject*,
521     bool allow_visited_style) const {
522   return ComputedStyleUtils::ValueForNinePieceImage(style.BorderImage(), style,
523                                                     allow_visited_style);
524 }
525 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const526 bool BorderInlineColor::ParseShorthand(
527     bool important,
528     CSSParserTokenRange& range,
529     const CSSParserContext& context,
530     const CSSParserLocalContext&,
531     HeapVector<CSSPropertyValue, 256>& properties) const {
532   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
533       borderInlineColorShorthand(), important, context, range, properties);
534 }
535 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const536 const CSSValue* BorderInlineColor::CSSValueFromComputedStyleInternal(
537     const ComputedStyle& style,
538     const SVGComputedStyle&,
539     const LayoutObject* layout_object,
540     bool allow_visited_style) const {
541   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
542       borderInlineColorShorthand(), style, layout_object, allow_visited_style);
543 }
544 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const545 bool BorderInline::ParseShorthand(
546     bool important,
547     CSSParserTokenRange& range,
548     const CSSParserContext& context,
549     const CSSParserLocalContext&,
550     HeapVector<CSSPropertyValue, 256>& properties) const {
551   const CSSValue* width = nullptr;
552   const CSSValue* style = nullptr;
553   const CSSValue* color = nullptr;
554 
555   if (!css_property_parser_helpers::ConsumeBorderShorthand(
556           range, context, width, style, color)) {
557     return false;
558   };
559 
560   css_property_parser_helpers::AddExpandedPropertyForValue(
561       CSSPropertyID::kBorderInlineWidth, *width, important, properties);
562   css_property_parser_helpers::AddExpandedPropertyForValue(
563       CSSPropertyID::kBorderInlineStyle, *style, important, properties);
564   css_property_parser_helpers::AddExpandedPropertyForValue(
565       CSSPropertyID::kBorderInlineColor, *color, important, properties);
566 
567   return range.AtEnd();
568 }
569 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const570 const CSSValue* BorderInline::CSSValueFromComputedStyleInternal(
571     const ComputedStyle& style,
572     const SVGComputedStyle&,
573     const LayoutObject* layout_object,
574     bool allow_visited_style) const {
575   const CSSValue* value_start =
576       GetCSSPropertyBorderInlineStart().CSSValueFromComputedStyle(
577           style, layout_object, allow_visited_style);
578   const CSSValue* value_end =
579       GetCSSPropertyBorderInlineEnd().CSSValueFromComputedStyle(
580           style, layout_object, allow_visited_style);
581   if (!DataEquivalent(value_start, value_end)) {
582     return nullptr;
583   }
584   return value_start;
585 }
586 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const587 bool BorderInlineEnd::ParseShorthand(
588     bool important,
589     CSSParserTokenRange& range,
590     const CSSParserContext& context,
591     const CSSParserLocalContext&,
592     HeapVector<CSSPropertyValue, 256>& properties) const {
593   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
594       borderInlineEndShorthand(), important, context, range, properties);
595 }
596 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const597 bool BorderInlineStart::ParseShorthand(
598     bool important,
599     CSSParserTokenRange& range,
600     const CSSParserContext& context,
601     const CSSParserLocalContext&,
602     HeapVector<CSSPropertyValue, 256>& properties) const {
603   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
604       borderInlineStartShorthand(), important, context, range, properties);
605 }
606 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const607 bool BorderInlineStyle::ParseShorthand(
608     bool important,
609     CSSParserTokenRange& range,
610     const CSSParserContext& context,
611     const CSSParserLocalContext&,
612     HeapVector<CSSPropertyValue, 256>& properties) const {
613   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
614       borderInlineStyleShorthand(), important, context, range, properties);
615 }
616 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const617 const CSSValue* BorderInlineStyle::CSSValueFromComputedStyleInternal(
618     const ComputedStyle& style,
619     const SVGComputedStyle&,
620     const LayoutObject* layout_object,
621     bool allow_visited_style) const {
622   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
623       borderInlineStyleShorthand(), style, layout_object, allow_visited_style);
624 }
625 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const626 bool BorderInlineWidth::ParseShorthand(
627     bool important,
628     CSSParserTokenRange& range,
629     const CSSParserContext& context,
630     const CSSParserLocalContext&,
631     HeapVector<CSSPropertyValue, 256>& properties) const {
632   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
633       borderInlineWidthShorthand(), important, context, range, properties);
634 }
635 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const636 const CSSValue* BorderInlineWidth::CSSValueFromComputedStyleInternal(
637     const ComputedStyle& style,
638     const SVGComputedStyle&,
639     const LayoutObject* layout_object,
640     bool allow_visited_style) const {
641   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
642       borderInlineWidthShorthand(), style, layout_object, allow_visited_style);
643 }
644 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const645 bool BorderLeft::ParseShorthand(
646     bool important,
647     CSSParserTokenRange& range,
648     const CSSParserContext& context,
649     const CSSParserLocalContext&,
650     HeapVector<CSSPropertyValue, 256>& properties) const {
651   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
652       borderLeftShorthand(), important, context, range, properties);
653 }
654 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const655 const CSSValue* BorderLeft::CSSValueFromComputedStyleInternal(
656     const ComputedStyle& style,
657     const SVGComputedStyle&,
658     const LayoutObject* layout_object,
659     bool allow_visited_style) const {
660   return ComputedStyleUtils::ValuesForShorthandProperty(
661       borderLeftShorthand(), style, layout_object, allow_visited_style);
662 }
663 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const664 bool BorderRadius::ParseShorthand(
665     bool important,
666     CSSParserTokenRange& range,
667     const CSSParserContext& context,
668     const CSSParserLocalContext& local_context,
669     HeapVector<CSSPropertyValue, 256>& properties) const {
670   CSSValue* horizontal_radii[4] = {nullptr};
671   CSSValue* vertical_radii[4] = {nullptr};
672 
673   if (!css_parsing_utils::ConsumeRadii(horizontal_radii, vertical_radii, range,
674                                        context,
675                                        local_context.UseAliasParsing()))
676     return false;
677 
678   css_property_parser_helpers::AddProperty(
679       CSSPropertyID::kBorderTopLeftRadius, CSSPropertyID::kBorderRadius,
680       *MakeGarbageCollected<CSSValuePair>(horizontal_radii[0],
681                                           vertical_radii[0],
682                                           CSSValuePair::kDropIdenticalValues),
683       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
684       properties);
685   css_property_parser_helpers::AddProperty(
686       CSSPropertyID::kBorderTopRightRadius, CSSPropertyID::kBorderRadius,
687       *MakeGarbageCollected<CSSValuePair>(horizontal_radii[1],
688                                           vertical_radii[1],
689                                           CSSValuePair::kDropIdenticalValues),
690       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
691       properties);
692   css_property_parser_helpers::AddProperty(
693       CSSPropertyID::kBorderBottomRightRadius, CSSPropertyID::kBorderRadius,
694       *MakeGarbageCollected<CSSValuePair>(horizontal_radii[2],
695                                           vertical_radii[2],
696                                           CSSValuePair::kDropIdenticalValues),
697       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
698       properties);
699   css_property_parser_helpers::AddProperty(
700       CSSPropertyID::kBorderBottomLeftRadius, CSSPropertyID::kBorderRadius,
701       *MakeGarbageCollected<CSSValuePair>(horizontal_radii[3],
702                                           vertical_radii[3],
703                                           CSSValuePair::kDropIdenticalValues),
704       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
705       properties);
706   return true;
707 }
708 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const709 const CSSValue* BorderRadius::CSSValueFromComputedStyleInternal(
710     const ComputedStyle& style,
711     const SVGComputedStyle&,
712     const LayoutObject*,
713     bool allow_visited_style) const {
714   return ComputedStyleUtils::ValueForBorderRadiusShorthand(style);
715 }
716 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const717 bool BorderRight::ParseShorthand(
718     bool important,
719     CSSParserTokenRange& range,
720     const CSSParserContext& context,
721     const CSSParserLocalContext&,
722     HeapVector<CSSPropertyValue, 256>& properties) const {
723   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
724       borderRightShorthand(), important, context, range, properties);
725 }
726 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const727 const CSSValue* BorderRight::CSSValueFromComputedStyleInternal(
728     const ComputedStyle& style,
729     const SVGComputedStyle&,
730     const LayoutObject* layout_object,
731     bool allow_visited_style) const {
732   return ComputedStyleUtils::ValuesForShorthandProperty(
733       borderRightShorthand(), style, layout_object, allow_visited_style);
734 }
735 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const736 bool BorderSpacing::ParseShorthand(
737     bool important,
738     CSSParserTokenRange& range,
739     const CSSParserContext& context,
740     const CSSParserLocalContext&,
741     HeapVector<CSSPropertyValue, 256>& properties) const {
742   CSSValue* horizontal_spacing =
743       ConsumeLength(range, context, kValueRangeNonNegative,
744                     css_property_parser_helpers::UnitlessQuirk::kAllow);
745   if (!horizontal_spacing)
746     return false;
747   CSSValue* vertical_spacing = horizontal_spacing;
748   if (!range.AtEnd()) {
749     vertical_spacing =
750         ConsumeLength(range, context, kValueRangeNonNegative,
751                       css_property_parser_helpers::UnitlessQuirk::kAllow);
752   }
753   if (!vertical_spacing || !range.AtEnd())
754     return false;
755   css_property_parser_helpers::AddProperty(
756       CSSPropertyID::kWebkitBorderHorizontalSpacing,
757       CSSPropertyID::kBorderSpacing, *horizontal_spacing, important,
758       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
759       properties);
760   css_property_parser_helpers::AddProperty(
761       CSSPropertyID::kWebkitBorderVerticalSpacing,
762       CSSPropertyID::kBorderSpacing, *vertical_spacing, important,
763       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
764       properties);
765   return true;
766 }
767 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const768 const CSSValue* BorderSpacing::CSSValueFromComputedStyleInternal(
769     const ComputedStyle& style,
770     const SVGComputedStyle&,
771     const LayoutObject*,
772     bool allow_visited_style) const {
773   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
774   list->Append(*ZoomAdjustedPixelValue(style.HorizontalBorderSpacing(), style));
775   list->Append(*ZoomAdjustedPixelValue(style.VerticalBorderSpacing(), style));
776   return list;
777 }
778 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const779 bool BorderStyle::ParseShorthand(
780     bool important,
781     CSSParserTokenRange& range,
782     const CSSParserContext& context,
783     const CSSParserLocalContext&,
784     HeapVector<CSSPropertyValue, 256>& properties) const {
785   return css_property_parser_helpers::ConsumeShorthandVia4Longhands(
786       borderStyleShorthand(), important, context, range, properties);
787 }
788 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const789 const CSSValue* BorderStyle::CSSValueFromComputedStyleInternal(
790     const ComputedStyle& style,
791     const SVGComputedStyle&,
792     const LayoutObject* layout_object,
793     bool allow_visited_style) const {
794   return ComputedStyleUtils::ValuesForSidesShorthand(
795       borderStyleShorthand(), style, layout_object, allow_visited_style);
796 }
797 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const798 bool BorderTop::ParseShorthand(
799     bool important,
800     CSSParserTokenRange& range,
801     const CSSParserContext& context,
802     const CSSParserLocalContext&,
803     HeapVector<CSSPropertyValue, 256>& properties) const {
804   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
805       borderTopShorthand(), important, context, range, properties);
806 }
807 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const808 const CSSValue* BorderTop::CSSValueFromComputedStyleInternal(
809     const ComputedStyle& style,
810     const SVGComputedStyle&,
811     const LayoutObject* layout_object,
812     bool allow_visited_style) const {
813   return ComputedStyleUtils::ValuesForShorthandProperty(
814       borderTopShorthand(), style, layout_object, allow_visited_style);
815 }
816 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const817 bool BorderWidth::ParseShorthand(
818     bool important,
819     CSSParserTokenRange& range,
820     const CSSParserContext& context,
821     const CSSParserLocalContext&,
822     HeapVector<CSSPropertyValue, 256>& properties) const {
823   return css_property_parser_helpers::ConsumeShorthandVia4Longhands(
824       borderWidthShorthand(), important, context, range, properties);
825 }
826 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const827 const CSSValue* BorderWidth::CSSValueFromComputedStyleInternal(
828     const ComputedStyle& style,
829     const SVGComputedStyle&,
830     const LayoutObject* layout_object,
831     bool allow_visited_style) const {
832   return ComputedStyleUtils::ValuesForSidesShorthand(
833       borderWidthShorthand(), style, layout_object, allow_visited_style);
834 }
835 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const836 bool ColumnRule::ParseShorthand(
837     bool important,
838     CSSParserTokenRange& range,
839     const CSSParserContext& context,
840     const CSSParserLocalContext&,
841     HeapVector<CSSPropertyValue, 256>& properties) const {
842   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
843       columnRuleShorthand(), important, context, range, properties);
844 }
845 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const846 const CSSValue* ColumnRule::CSSValueFromComputedStyleInternal(
847     const ComputedStyle& style,
848     const SVGComputedStyle&,
849     const LayoutObject* layout_object,
850     bool allow_visited_style) const {
851   return ComputedStyleUtils::ValuesForShorthandProperty(
852       columnRuleShorthand(), style, layout_object, allow_visited_style);
853 }
854 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const855 bool Columns::ParseShorthand(
856     bool important,
857     CSSParserTokenRange& range,
858     const CSSParserContext& context,
859     const CSSParserLocalContext&,
860     HeapVector<CSSPropertyValue, 256>& properties) const {
861   CSSValue* column_width = nullptr;
862   CSSValue* column_count = nullptr;
863   if (!css_parsing_utils::ConsumeColumnWidthOrCount(range, context,
864                                                     column_width, column_count))
865     return false;
866   css_parsing_utils::ConsumeColumnWidthOrCount(range, context, column_width,
867                                                column_count);
868   if (!range.AtEnd())
869     return false;
870   if (!column_width)
871     column_width = CSSIdentifierValue::Create(CSSValueID::kAuto);
872   if (!column_count)
873     column_count = CSSIdentifierValue::Create(CSSValueID::kAuto);
874   css_property_parser_helpers::AddProperty(
875       CSSPropertyID::kColumnWidth, CSSPropertyID::kInvalid, *column_width,
876       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
877       properties);
878   css_property_parser_helpers::AddProperty(
879       CSSPropertyID::kColumnCount, CSSPropertyID::kInvalid, *column_count,
880       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
881       properties);
882   return true;
883 }
884 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const885 const CSSValue* Columns::CSSValueFromComputedStyleInternal(
886     const ComputedStyle& style,
887     const SVGComputedStyle&,
888     const LayoutObject* layout_object,
889     bool allow_visited_style) const {
890   return ComputedStyleUtils::ValuesForShorthandProperty(
891       columnsShorthand(), style, layout_object, allow_visited_style);
892 }
893 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const894 bool Flex::ParseShorthand(bool important,
895                           CSSParserTokenRange& range,
896                           const CSSParserContext& context,
897                           const CSSParserLocalContext&,
898                           HeapVector<CSSPropertyValue, 256>& properties) const {
899   static const double kUnsetValue = -1;
900   double flex_grow = kUnsetValue;
901   double flex_shrink = kUnsetValue;
902   CSSValue* flex_basis = nullptr;
903 
904   if (range.Peek().Id() == CSSValueID::kNone) {
905     flex_grow = 0;
906     flex_shrink = 0;
907     flex_basis = CSSIdentifierValue::Create(CSSValueID::kAuto);
908     range.ConsumeIncludingWhitespace();
909   } else {
910     unsigned index = 0;
911     while (!range.AtEnd() && index++ < 3) {
912       double num;
913       if (css_property_parser_helpers::ConsumeNumberRaw(range, context, num)) {
914         if (num < 0)
915           return false;
916         if (flex_grow == kUnsetValue) {
917           flex_grow = num;
918         } else if (flex_shrink == kUnsetValue) {
919           flex_shrink = num;
920         } else if (!num) {
921           // flex only allows a basis of 0 (sans units) if
922           // flex-grow and flex-shrink values have already been
923           // set.
924           flex_basis = CSSNumericLiteralValue::Create(
925               0, CSSPrimitiveValue::UnitType::kPixels);
926         } else {
927           return false;
928         }
929       } else if (!flex_basis) {
930         if (range.Peek().Id() == CSSValueID::kAuto)
931           flex_basis = css_property_parser_helpers::ConsumeIdent(range);
932         if (!flex_basis) {
933           flex_basis = css_property_parser_helpers::ConsumeLengthOrPercent(
934               range, context, kValueRangeNonNegative);
935         }
936         if (index == 2 && !range.AtEnd())
937           return false;
938       }
939     }
940     if (index == 0)
941       return false;
942     if (flex_grow == kUnsetValue)
943       flex_grow = 1;
944     if (flex_shrink == kUnsetValue)
945       flex_shrink = 1;
946     if (!flex_basis) {
947       flex_basis = CSSNumericLiteralValue::Create(
948           0, CSSPrimitiveValue::UnitType::kPercentage);
949     }
950   }
951 
952   if (!range.AtEnd())
953     return false;
954   css_property_parser_helpers::AddProperty(
955       CSSPropertyID::kFlexGrow, CSSPropertyID::kFlex,
956       *CSSNumericLiteralValue::Create(clampTo<float>(flex_grow),
957                                       CSSPrimitiveValue::UnitType::kNumber),
958       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
959       properties);
960   css_property_parser_helpers::AddProperty(
961       CSSPropertyID::kFlexShrink, CSSPropertyID::kFlex,
962       *CSSNumericLiteralValue::Create(clampTo<float>(flex_shrink),
963                                       CSSPrimitiveValue::UnitType::kNumber),
964       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
965       properties);
966 
967   css_property_parser_helpers::AddProperty(
968       CSSPropertyID::kFlexBasis, CSSPropertyID::kFlex, *flex_basis, important,
969       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
970       properties);
971 
972   return true;
973 }
974 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const975 const CSSValue* Flex::CSSValueFromComputedStyleInternal(
976     const ComputedStyle& style,
977     const SVGComputedStyle&,
978     const LayoutObject* layout_object,
979     bool allow_visited_style) const {
980   return ComputedStyleUtils::ValuesForShorthandProperty(
981       flexShorthand(), style, layout_object, allow_visited_style);
982 }
983 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const984 bool FlexFlow::ParseShorthand(
985     bool important,
986     CSSParserTokenRange& range,
987     const CSSParserContext& context,
988     const CSSParserLocalContext&,
989     HeapVector<CSSPropertyValue, 256>& properties) const {
990   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
991       flexFlowShorthand(), important, context, range, properties);
992 }
993 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const994 const CSSValue* FlexFlow::CSSValueFromComputedStyleInternal(
995     const ComputedStyle& style,
996     const SVGComputedStyle&,
997     const LayoutObject* layout_object,
998     bool allow_visited_style) const {
999   return ComputedStyleUtils::ValuesForShorthandProperty(
1000       flexFlowShorthand(), style, layout_object, allow_visited_style);
1001 }
1002 namespace {
1003 
ConsumeSystemFont(bool important,CSSParserTokenRange & range,HeapVector<CSSPropertyValue,256> & properties)1004 bool ConsumeSystemFont(bool important,
1005                        CSSParserTokenRange& range,
1006                        HeapVector<CSSPropertyValue, 256>& properties) {
1007   CSSValueID system_font_id = range.ConsumeIncludingWhitespace().Id();
1008   DCHECK_GE(system_font_id, CSSValueID::kCaption);
1009   DCHECK_LE(system_font_id, CSSValueID::kStatusBar);
1010   if (!range.AtEnd())
1011     return false;
1012 
1013   FontSelectionValue font_style = NormalSlopeValue();
1014   FontSelectionValue font_weight = NormalWeightValue();
1015   float font_size = 0;
1016   AtomicString font_family;
1017   LayoutTheme::GetTheme().SystemFont(system_font_id, font_style, font_weight,
1018                                      font_size, font_family);
1019 
1020   css_property_parser_helpers::AddProperty(
1021       CSSPropertyID::kFontStyle, CSSPropertyID::kFont,
1022       *CSSIdentifierValue::Create(font_style == ItalicSlopeValue()
1023                                       ? CSSValueID::kItalic
1024                                       : CSSValueID::kNormal),
1025       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1026       properties);
1027   css_property_parser_helpers::AddProperty(
1028       CSSPropertyID::kFontWeight, CSSPropertyID::kFont,
1029       *CSSNumericLiteralValue::Create(font_weight,
1030                                       CSSPrimitiveValue::UnitType::kNumber),
1031       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1032       properties);
1033   css_property_parser_helpers::AddProperty(
1034       CSSPropertyID::kFontSize, CSSPropertyID::kFont,
1035       *CSSNumericLiteralValue::Create(font_size,
1036                                       CSSPrimitiveValue::UnitType::kPixels),
1037       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1038       properties);
1039 
1040   CSSValueList* font_family_list = CSSValueList::CreateCommaSeparated();
1041   font_family_list->Append(*CSSFontFamilyValue::Create(font_family));
1042   css_property_parser_helpers::AddProperty(
1043       CSSPropertyID::kFontFamily, CSSPropertyID::kFont, *font_family_list,
1044       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1045       properties);
1046 
1047   css_property_parser_helpers::AddProperty(
1048       CSSPropertyID::kFontStretch, CSSPropertyID::kFont,
1049       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1050       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1051       properties);
1052   css_property_parser_helpers::AddProperty(
1053       CSSPropertyID::kFontVariantCaps, CSSPropertyID::kFont,
1054       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1055       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1056       properties);
1057   css_property_parser_helpers::AddProperty(
1058       CSSPropertyID::kFontVariantLigatures, CSSPropertyID::kFont,
1059       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1060       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1061       properties);
1062   css_property_parser_helpers::AddProperty(
1063       CSSPropertyID::kFontVariantNumeric, CSSPropertyID::kFont,
1064       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1065       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1066       properties);
1067   css_property_parser_helpers::AddProperty(
1068       CSSPropertyID::kFontVariantEastAsian, CSSPropertyID::kFont,
1069       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1070       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1071       properties);
1072   css_property_parser_helpers::AddProperty(
1073       CSSPropertyID::kLineHeight, CSSPropertyID::kFont,
1074       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1075       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1076       properties);
1077   return true;
1078 }
1079 
ConsumeFont(bool important,CSSParserTokenRange & range,const CSSParserContext & context,HeapVector<CSSPropertyValue,256> & properties)1080 bool ConsumeFont(bool important,
1081                  CSSParserTokenRange& range,
1082                  const CSSParserContext& context,
1083                  HeapVector<CSSPropertyValue, 256>& properties) {
1084   // Optional font-style, font-variant, font-stretch and font-weight.
1085   // Each may be normal.
1086   CSSValue* font_style = nullptr;
1087   CSSIdentifierValue* font_variant_caps = nullptr;
1088   CSSValue* font_weight = nullptr;
1089   CSSValue* font_stretch = nullptr;
1090   const int kNumReorderableFontProperties = 4;
1091   for (int i = 0; i < kNumReorderableFontProperties && !range.AtEnd(); ++i) {
1092     CSSValueID id = range.Peek().Id();
1093     if (id == CSSValueID::kNormal) {
1094       css_property_parser_helpers::ConsumeIdent(range);
1095       continue;
1096     }
1097     if (!font_style &&
1098         (id == CSSValueID::kItalic || id == CSSValueID::kOblique)) {
1099       font_style = css_parsing_utils::ConsumeFontStyle(range, context);
1100       if (!font_style)
1101         return false;
1102       continue;
1103     }
1104     if (!font_variant_caps && id == CSSValueID::kSmallCaps) {
1105       // Font variant in the shorthand is particular, it only accepts normal or
1106       // small-caps.
1107       // See https://drafts.csswg.org/css-fonts/#propdef-font
1108       font_variant_caps = css_parsing_utils::ConsumeFontVariantCSS21(range);
1109       if (font_variant_caps)
1110         continue;
1111     }
1112     if (!font_weight) {
1113       font_weight = css_parsing_utils::ConsumeFontWeight(range, context);
1114       if (font_weight)
1115         continue;
1116     }
1117     // Stretch in the font shorthand can only take the CSS Fonts Level 3
1118     // keywords, not arbitrary values, compare
1119     // https://drafts.csswg.org/css-fonts-4/#font-prop
1120     // Bail out if the last possible property of the set in this loop could not
1121     // be parsed, this closes the first block of optional values of the font
1122     // shorthand, compare: [ [ <‘font-style’> || <font-variant-css21> ||
1123     // <‘font-weight’> || <font-stretch-css3> ]?
1124     if (font_stretch ||
1125         !(font_stretch =
1126               css_parsing_utils::ConsumeFontStretchKeywordOnly(range)))
1127       break;
1128   }
1129 
1130   if (range.AtEnd())
1131     return false;
1132 
1133   css_property_parser_helpers::AddProperty(
1134       CSSPropertyID::kFontStyle, CSSPropertyID::kFont,
1135       font_style ? *font_style
1136                  : *CSSIdentifierValue::Create(CSSValueID::kNormal),
1137       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1138       properties);
1139   css_property_parser_helpers::AddProperty(
1140       CSSPropertyID::kFontVariantCaps, CSSPropertyID::kFont,
1141       font_variant_caps ? *font_variant_caps
1142                         : *CSSIdentifierValue::Create(CSSValueID::kNormal),
1143       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1144       properties);
1145   css_property_parser_helpers::AddProperty(
1146       CSSPropertyID::kFontVariantLigatures, CSSPropertyID::kFont,
1147       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1148       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1149       properties);
1150   css_property_parser_helpers::AddProperty(
1151       CSSPropertyID::kFontVariantNumeric, CSSPropertyID::kFont,
1152       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1153       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1154       properties);
1155   css_property_parser_helpers::AddProperty(
1156       CSSPropertyID::kFontVariantEastAsian, CSSPropertyID::kFont,
1157       *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1158       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1159       properties);
1160 
1161   css_property_parser_helpers::AddProperty(
1162       CSSPropertyID::kFontWeight, CSSPropertyID::kFont,
1163       font_weight ? *font_weight
1164                   : *CSSIdentifierValue::Create(CSSValueID::kNormal),
1165       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1166       properties);
1167   css_property_parser_helpers::AddProperty(
1168       CSSPropertyID::kFontStretch, CSSPropertyID::kFont,
1169       font_stretch ? *font_stretch
1170                    : *CSSIdentifierValue::Create(CSSValueID::kNormal),
1171       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1172       properties);
1173 
1174   // Now a font size _must_ come.
1175   CSSValue* font_size = css_parsing_utils::ConsumeFontSize(range, context);
1176   if (!font_size || range.AtEnd())
1177     return false;
1178 
1179   css_property_parser_helpers::AddProperty(
1180       CSSPropertyID::kFontSize, CSSPropertyID::kFont, *font_size, important,
1181       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1182       properties);
1183 
1184   if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) {
1185     CSSValue* line_height =
1186         css_parsing_utils::ConsumeLineHeight(range, context);
1187     if (!line_height)
1188       return false;
1189     css_property_parser_helpers::AddProperty(
1190         CSSPropertyID::kLineHeight, CSSPropertyID::kFont, *line_height,
1191         important,
1192         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1193         properties);
1194   } else {
1195     css_property_parser_helpers::AddProperty(
1196         CSSPropertyID::kLineHeight, CSSPropertyID::kFont,
1197         *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1198         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1199         properties);
1200   }
1201 
1202   // Font family must come now.
1203   CSSValue* parsed_family_value = css_parsing_utils::ConsumeFontFamily(range);
1204   if (!parsed_family_value)
1205     return false;
1206 
1207   css_property_parser_helpers::AddProperty(
1208       CSSPropertyID::kFontFamily, CSSPropertyID::kFont, *parsed_family_value,
1209       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1210       properties);
1211 
1212   // FIXME: http://www.w3.org/TR/2011/WD-css3-fonts-20110324/#font-prop requires
1213   // that "font-stretch", "font-size-adjust", and "font-kerning" be reset to
1214   // their initial values but we don't seem to support them at the moment. They
1215   // should also be added here once implemented.
1216   return range.AtEnd();
1217 }
1218 
1219 }  // namespace
1220 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1221 bool Font::ParseShorthand(bool important,
1222                           CSSParserTokenRange& range,
1223                           const CSSParserContext& context,
1224                           const CSSParserLocalContext&,
1225                           HeapVector<CSSPropertyValue, 256>& properties) const {
1226   const CSSParserToken& token = range.Peek();
1227   if (token.Id() >= CSSValueID::kCaption &&
1228       token.Id() <= CSSValueID::kStatusBar)
1229     return ConsumeSystemFont(important, range, properties);
1230   return ConsumeFont(important, range, context, properties);
1231 }
1232 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const1233 const CSSValue* Font::CSSValueFromComputedStyleInternal(
1234     const ComputedStyle& style,
1235     const SVGComputedStyle&,
1236     const LayoutObject*,
1237     bool allow_visited_style) const {
1238   return ComputedStyleUtils::ValueForFont(style);
1239 }
1240 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1241 bool FontVariant::ParseShorthand(
1242     bool important,
1243     CSSParserTokenRange& range,
1244     const CSSParserContext&,
1245     const CSSParserLocalContext&,
1246     HeapVector<CSSPropertyValue, 256>& properties) const {
1247   if (css_property_parser_helpers::IdentMatches<CSSValueID::kNormal,
1248                                                 CSSValueID::kNone>(
1249           range.Peek().Id())) {
1250     css_property_parser_helpers::AddProperty(
1251         CSSPropertyID::kFontVariantLigatures, CSSPropertyID::kFontVariant,
1252         *css_property_parser_helpers::ConsumeIdent(range), important,
1253         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1254         properties);
1255     css_property_parser_helpers::AddProperty(
1256         CSSPropertyID::kFontVariantCaps, CSSPropertyID::kFontVariant,
1257         *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1258         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1259         properties);
1260     css_property_parser_helpers::AddProperty(
1261         CSSPropertyID::kFontVariantNumeric, CSSPropertyID::kFontVariant,
1262         *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1263         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1264         properties);
1265     css_property_parser_helpers::AddProperty(
1266         CSSPropertyID::kFontVariantEastAsian, CSSPropertyID::kFontVariant,
1267         *CSSIdentifierValue::Create(CSSValueID::kNormal), important,
1268         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1269         properties);
1270     return range.AtEnd();
1271   }
1272 
1273   CSSIdentifierValue* caps_value = nullptr;
1274   FontVariantLigaturesParser ligatures_parser;
1275   FontVariantNumericParser numeric_parser;
1276   FontVariantEastAsianParser east_asian_parser;
1277   do {
1278     FontVariantLigaturesParser::ParseResult ligatures_parse_result =
1279         ligatures_parser.ConsumeLigature(range);
1280     FontVariantNumericParser::ParseResult numeric_parse_result =
1281         numeric_parser.ConsumeNumeric(range);
1282     FontVariantEastAsianParser::ParseResult east_asian_parse_result =
1283         east_asian_parser.ConsumeEastAsian(range);
1284     if (ligatures_parse_result ==
1285             FontVariantLigaturesParser::ParseResult::kConsumedValue ||
1286         numeric_parse_result ==
1287             FontVariantNumericParser::ParseResult::kConsumedValue ||
1288         east_asian_parse_result ==
1289             FontVariantEastAsianParser::ParseResult::kConsumedValue)
1290       continue;
1291 
1292     if (ligatures_parse_result ==
1293             FontVariantLigaturesParser::ParseResult::kDisallowedValue ||
1294         numeric_parse_result ==
1295             FontVariantNumericParser::ParseResult::kDisallowedValue ||
1296         east_asian_parse_result ==
1297             FontVariantEastAsianParser::ParseResult::kDisallowedValue)
1298       return false;
1299 
1300     CSSValueID id = range.Peek().Id();
1301     switch (id) {
1302       case CSSValueID::kSmallCaps:
1303       case CSSValueID::kAllSmallCaps:
1304       case CSSValueID::kPetiteCaps:
1305       case CSSValueID::kAllPetiteCaps:
1306       case CSSValueID::kUnicase:
1307       case CSSValueID::kTitlingCaps:
1308         // Only one caps value permitted in font-variant grammar.
1309         if (caps_value)
1310           return false;
1311         caps_value = css_property_parser_helpers::ConsumeIdent(range);
1312         break;
1313       default:
1314         return false;
1315     }
1316   } while (!range.AtEnd());
1317 
1318   css_property_parser_helpers::AddProperty(
1319       CSSPropertyID::kFontVariantLigatures, CSSPropertyID::kFontVariant,
1320       *ligatures_parser.FinalizeValue(), important,
1321       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1322       properties);
1323   css_property_parser_helpers::AddProperty(
1324       CSSPropertyID::kFontVariantNumeric, CSSPropertyID::kFontVariant,
1325       *numeric_parser.FinalizeValue(), important,
1326       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1327       properties);
1328   css_property_parser_helpers::AddProperty(
1329       CSSPropertyID::kFontVariantEastAsian, CSSPropertyID::kFontVariant,
1330       *east_asian_parser.FinalizeValue(), important,
1331       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1332       properties);
1333   css_property_parser_helpers::AddProperty(
1334       CSSPropertyID::kFontVariantCaps, CSSPropertyID::kFontVariant,
1335       caps_value ? *caps_value
1336                  : *CSSIdentifierValue::Create(CSSValueID::kNormal),
1337       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1338       properties);
1339   return true;
1340 }
1341 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1342 const CSSValue* FontVariant::CSSValueFromComputedStyleInternal(
1343     const ComputedStyle& style,
1344     const SVGComputedStyle&,
1345     const LayoutObject* layout_object,
1346     bool allow_visited_style) const {
1347   return ComputedStyleUtils::ValuesForFontVariantProperty(style, layout_object,
1348                                                           allow_visited_style);
1349 }
1350 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1351 bool Gap::ParseShorthand(bool important,
1352                          CSSParserTokenRange& range,
1353                          const CSSParserContext& context,
1354                          const CSSParserLocalContext&,
1355                          HeapVector<CSSPropertyValue, 256>& properties) const {
1356   DCHECK_EQ(shorthandForProperty(CSSPropertyID::kGap).length(), 2u);
1357   CSSValue* row_gap = css_parsing_utils::ConsumeGapLength(range, context);
1358   CSSValue* column_gap = css_parsing_utils::ConsumeGapLength(range, context);
1359   if (!row_gap || !range.AtEnd())
1360     return false;
1361   if (!column_gap)
1362     column_gap = row_gap;
1363   css_property_parser_helpers::AddProperty(
1364       CSSPropertyID::kRowGap, CSSPropertyID::kGap, *row_gap, important,
1365       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1366       properties);
1367   css_property_parser_helpers::AddProperty(
1368       CSSPropertyID::kColumnGap, CSSPropertyID::kGap, *column_gap, important,
1369       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1370       properties);
1371   return true;
1372 }
1373 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1374 const CSSValue* Gap::CSSValueFromComputedStyleInternal(
1375     const ComputedStyle& style,
1376     const SVGComputedStyle&,
1377     const LayoutObject* layout_object,
1378     bool allow_visited_style) const {
1379   return ComputedStyleUtils::ValuesForGapShorthand(
1380       gapShorthand(), style, layout_object, allow_visited_style);
1381 }
1382 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1383 bool GridArea::ParseShorthand(
1384     bool important,
1385     CSSParserTokenRange& range,
1386     const CSSParserContext& context,
1387     const CSSParserLocalContext&,
1388     HeapVector<CSSPropertyValue, 256>& properties) const {
1389   DCHECK_EQ(gridAreaShorthand().length(), 4u);
1390 
1391   CSSValue* row_start_value =
1392       css_parsing_utils::ConsumeGridLine(range, context);
1393   if (!row_start_value)
1394     return false;
1395   CSSValue* column_start_value = nullptr;
1396   CSSValue* row_end_value = nullptr;
1397   CSSValue* column_end_value = nullptr;
1398   if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) {
1399     column_start_value = css_parsing_utils::ConsumeGridLine(range, context);
1400     if (!column_start_value)
1401       return false;
1402     if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) {
1403       row_end_value = css_parsing_utils::ConsumeGridLine(range, context);
1404       if (!row_end_value)
1405         return false;
1406       if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) {
1407         column_end_value = css_parsing_utils::ConsumeGridLine(range, context);
1408         if (!column_end_value)
1409           return false;
1410       }
1411     }
1412   }
1413   if (!range.AtEnd())
1414     return false;
1415   if (!column_start_value) {
1416     column_start_value = row_start_value->IsCustomIdentValue()
1417                              ? row_start_value
1418                              : CSSIdentifierValue::Create(CSSValueID::kAuto);
1419   }
1420   if (!row_end_value) {
1421     row_end_value = row_start_value->IsCustomIdentValue()
1422                         ? row_start_value
1423                         : CSSIdentifierValue::Create(CSSValueID::kAuto);
1424   }
1425   if (!column_end_value) {
1426     column_end_value = column_start_value->IsCustomIdentValue()
1427                            ? column_start_value
1428                            : CSSIdentifierValue::Create(CSSValueID::kAuto);
1429   }
1430 
1431   css_property_parser_helpers::AddProperty(
1432       CSSPropertyID::kGridRowStart, CSSPropertyID::kGridArea, *row_start_value,
1433       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1434       properties);
1435   css_property_parser_helpers::AddProperty(
1436       CSSPropertyID::kGridColumnStart, CSSPropertyID::kGridArea,
1437       *column_start_value, important,
1438       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1439       properties);
1440   css_property_parser_helpers::AddProperty(
1441       CSSPropertyID::kGridRowEnd, CSSPropertyID::kGridArea, *row_end_value,
1442       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1443       properties);
1444   css_property_parser_helpers::AddProperty(
1445       CSSPropertyID::kGridColumnEnd, CSSPropertyID::kGridArea,
1446       *column_end_value, important,
1447       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1448       properties);
1449   return true;
1450 }
1451 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1452 const CSSValue* GridArea::CSSValueFromComputedStyleInternal(
1453     const ComputedStyle& style,
1454     const SVGComputedStyle&,
1455     const LayoutObject* layout_object,
1456     bool allow_visited_style) const {
1457   return ComputedStyleUtils::ValuesForGridShorthand(
1458       gridAreaShorthand(), style, layout_object, allow_visited_style);
1459 }
1460 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1461 bool GridColumn::ParseShorthand(
1462     bool important,
1463     CSSParserTokenRange& range,
1464     const CSSParserContext& context,
1465     const CSSParserLocalContext&,
1466     HeapVector<CSSPropertyValue, 256>& properties) const {
1467   const StylePropertyShorthand& shorthand =
1468       shorthandForProperty(CSSPropertyID::kGridColumn);
1469   DCHECK_EQ(shorthand.length(), 2u);
1470 
1471   CSSValue* start_value = nullptr;
1472   CSSValue* end_value = nullptr;
1473   if (!css_parsing_utils::ConsumeGridItemPositionShorthand(
1474           important, range, context, start_value, end_value)) {
1475     return false;
1476   }
1477 
1478   css_property_parser_helpers::AddProperty(
1479       shorthand.properties()[0]->PropertyID(), CSSPropertyID::kGridColumn,
1480       *start_value, important,
1481       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1482       properties);
1483   css_property_parser_helpers::AddProperty(
1484       shorthand.properties()[1]->PropertyID(), CSSPropertyID::kGridColumn,
1485       *end_value, important,
1486       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1487       properties);
1488 
1489   return true;
1490 }
1491 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1492 const CSSValue* GridColumn::CSSValueFromComputedStyleInternal(
1493     const ComputedStyle& style,
1494     const SVGComputedStyle&,
1495     const LayoutObject* layout_object,
1496     bool allow_visited_style) const {
1497   return ComputedStyleUtils::ValuesForGridShorthand(
1498       gridColumnShorthand(), style, layout_object, allow_visited_style);
1499 }
1500 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1501 bool GridColumnGap::ParseShorthand(
1502     bool important,
1503     CSSParserTokenRange& range,
1504     const CSSParserContext& context,
1505     const CSSParserLocalContext&,
1506     HeapVector<CSSPropertyValue, 256>& properties) const {
1507   CSSValue* gap_length = css_parsing_utils::ConsumeGapLength(range, context);
1508   if (!gap_length || !range.AtEnd())
1509     return false;
1510 
1511   css_property_parser_helpers::AddProperty(
1512       CSSPropertyID::kColumnGap, CSSPropertyID::kGridColumnGap, *gap_length,
1513       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1514       properties);
1515   return true;
1516 }
1517 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1518 const CSSValue* GridColumnGap::CSSValueFromComputedStyleInternal(
1519     const ComputedStyle& style,
1520     const SVGComputedStyle&,
1521     const LayoutObject* layout_object,
1522     bool allow_visited_style) const {
1523   return ComputedStyleUtils::ValuesForShorthandProperty(
1524       gridColumnGapShorthand(), style, layout_object, allow_visited_style);
1525 }
1526 
1527 namespace {
1528 
ConsumeImplicitAutoFlow(CSSParserTokenRange & range,const CSSValue & flow_direction)1529 CSSValueList* ConsumeImplicitAutoFlow(CSSParserTokenRange& range,
1530                                       const CSSValue& flow_direction) {
1531   // [ auto-flow && dense? ]
1532   CSSValue* dense_algorithm = nullptr;
1533   if ((css_property_parser_helpers::ConsumeIdent<CSSValueID::kAutoFlow>(
1534           range))) {
1535     dense_algorithm =
1536         css_property_parser_helpers::ConsumeIdent<CSSValueID::kDense>(range);
1537   } else {
1538     dense_algorithm =
1539         css_property_parser_helpers::ConsumeIdent<CSSValueID::kDense>(range);
1540     if (!dense_algorithm)
1541       return nullptr;
1542     if (!css_property_parser_helpers::ConsumeIdent<CSSValueID::kAutoFlow>(
1543             range))
1544       return nullptr;
1545   }
1546   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
1547   list->Append(flow_direction);
1548   if (dense_algorithm)
1549     list->Append(*dense_algorithm);
1550   return list;
1551 }
1552 
1553 }  // namespace
1554 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1555 bool Grid::ParseShorthand(bool important,
1556                           CSSParserTokenRange& range,
1557                           const CSSParserContext& context,
1558                           const CSSParserLocalContext&,
1559                           HeapVector<CSSPropertyValue, 256>& properties) const {
1560   DCHECK_EQ(shorthandForProperty(CSSPropertyID::kGrid).length(), 6u);
1561 
1562   CSSParserTokenRange range_copy = range;
1563 
1564   CSSValue* template_rows = nullptr;
1565   CSSValue* template_columns = nullptr;
1566   CSSValue* template_areas = nullptr;
1567 
1568   if (css_parsing_utils::ConsumeGridTemplateShorthand(
1569           important, range, context, template_rows, template_columns,
1570           template_areas)) {
1571     DCHECK(template_rows);
1572     DCHECK(template_columns);
1573     DCHECK(template_areas);
1574 
1575     css_property_parser_helpers::AddProperty(
1576         CSSPropertyID::kGridTemplateRows, CSSPropertyID::kGrid, *template_rows,
1577         important,
1578         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1579         properties);
1580     css_property_parser_helpers::AddProperty(
1581         CSSPropertyID::kGridTemplateColumns, CSSPropertyID::kGrid,
1582         *template_columns, important,
1583         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1584         properties);
1585     css_property_parser_helpers::AddProperty(
1586         CSSPropertyID::kGridTemplateAreas, CSSPropertyID::kGrid,
1587         *template_areas, important,
1588         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1589         properties);
1590 
1591     // It can only be specified the explicit or the implicit grid properties in
1592     // a single grid declaration. The sub-properties not specified are set to
1593     // their initial value, as normal for shorthands.
1594     css_property_parser_helpers::AddProperty(
1595         CSSPropertyID::kGridAutoFlow, CSSPropertyID::kGrid,
1596         *CSSInitialValue::Create(), important,
1597         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1598         properties);
1599     css_property_parser_helpers::AddProperty(
1600         CSSPropertyID::kGridAutoColumns, CSSPropertyID::kGrid,
1601         *CSSInitialValue::Create(), important,
1602         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1603         properties);
1604     css_property_parser_helpers::AddProperty(
1605         CSSPropertyID::kGridAutoRows, CSSPropertyID::kGrid,
1606         *CSSInitialValue::Create(), important,
1607         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1608         properties);
1609     return true;
1610   }
1611 
1612   range = range_copy;
1613 
1614   CSSValue* auto_columns_value = nullptr;
1615   CSSValue* auto_rows_value = nullptr;
1616   CSSValueList* grid_auto_flow = nullptr;
1617   template_rows = nullptr;
1618   template_columns = nullptr;
1619 
1620   if (css_property_parser_helpers::IdentMatches<CSSValueID::kDense,
1621                                                 CSSValueID::kAutoFlow>(
1622           range.Peek().Id())) {
1623     // 2- [ auto-flow && dense? ] <grid-auto-rows>? / <grid-template-columns>
1624     grid_auto_flow = ConsumeImplicitAutoFlow(
1625         range, *CSSIdentifierValue::Create(CSSValueID::kRow));
1626     if (!grid_auto_flow)
1627       return false;
1628     if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) {
1629       auto_rows_value = CSSInitialValue::Create();
1630     } else {
1631       auto_rows_value = css_parsing_utils::ConsumeGridTrackList(
1632           range, context, css_parsing_utils::TrackListType::kGridAuto);
1633       if (!auto_rows_value)
1634         return false;
1635       if (!css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range))
1636         return false;
1637     }
1638     if (!(template_columns =
1639               css_parsing_utils::ConsumeGridTemplatesRowsOrColumns(range,
1640                                                                    context)))
1641       return false;
1642     template_rows = CSSInitialValue::Create();
1643     auto_columns_value = CSSInitialValue::Create();
1644   } else {
1645     // 3- <grid-template-rows> / [ auto-flow && dense? ] <grid-auto-columns>?
1646     template_rows =
1647         css_parsing_utils::ConsumeGridTemplatesRowsOrColumns(range, context);
1648     if (!template_rows)
1649       return false;
1650     if (!css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range))
1651       return false;
1652     grid_auto_flow = ConsumeImplicitAutoFlow(
1653         range, *CSSIdentifierValue::Create(CSSValueID::kColumn));
1654     if (!grid_auto_flow)
1655       return false;
1656     if (range.AtEnd()) {
1657       auto_columns_value = CSSInitialValue::Create();
1658     } else {
1659       auto_columns_value = css_parsing_utils::ConsumeGridTrackList(
1660           range, context, css_parsing_utils::TrackListType::kGridAuto);
1661       if (!auto_columns_value)
1662         return false;
1663     }
1664     template_columns = CSSInitialValue::Create();
1665     auto_rows_value = CSSInitialValue::Create();
1666   }
1667 
1668   if (!range.AtEnd())
1669     return false;
1670 
1671   // It can only be specified the explicit or the implicit grid properties in a
1672   // single grid declaration. The sub-properties not specified are set to their
1673   // initial value, as normal for shorthands.
1674   css_property_parser_helpers::AddProperty(
1675       CSSPropertyID::kGridTemplateColumns, CSSPropertyID::kGrid,
1676       *template_columns, important,
1677       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1678       properties);
1679   css_property_parser_helpers::AddProperty(
1680       CSSPropertyID::kGridTemplateRows, CSSPropertyID::kGrid, *template_rows,
1681       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1682       properties);
1683   css_property_parser_helpers::AddProperty(
1684       CSSPropertyID::kGridTemplateAreas, CSSPropertyID::kGrid,
1685       *CSSInitialValue::Create(), important,
1686       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1687       properties);
1688   css_property_parser_helpers::AddProperty(
1689       CSSPropertyID::kGridAutoFlow, CSSPropertyID::kGrid, *grid_auto_flow,
1690       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1691       properties);
1692   css_property_parser_helpers::AddProperty(
1693       CSSPropertyID::kGridAutoColumns, CSSPropertyID::kGrid,
1694       *auto_columns_value, important,
1695       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1696       properties);
1697   css_property_parser_helpers::AddProperty(
1698       CSSPropertyID::kGridAutoRows, CSSPropertyID::kGrid, *auto_rows_value,
1699       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1700       properties);
1701   return true;
1702 }
1703 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const1704 bool Grid::IsLayoutDependent(const ComputedStyle* style,
1705                              LayoutObject* layout_object) const {
1706   return layout_object && layout_object->IsLayoutGrid();
1707 }
1708 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1709 const CSSValue* Grid::CSSValueFromComputedStyleInternal(
1710     const ComputedStyle& style,
1711     const SVGComputedStyle&,
1712     const LayoutObject* layout_object,
1713     bool allow_visited_style) const {
1714   return ComputedStyleUtils::ValuesForGridShorthand(
1715       gridShorthand(), style, layout_object, allow_visited_style);
1716 }
1717 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1718 bool GridGap::ParseShorthand(
1719     bool important,
1720     CSSParserTokenRange& range,
1721     const CSSParserContext& context,
1722     const CSSParserLocalContext&,
1723     HeapVector<CSSPropertyValue, 256>& properties) const {
1724   DCHECK_EQ(shorthandForProperty(CSSPropertyID::kGridGap).length(), 2u);
1725   CSSValue* row_gap = css_parsing_utils::ConsumeGapLength(range, context);
1726   CSSValue* column_gap = css_parsing_utils::ConsumeGapLength(range, context);
1727   if (!row_gap || !range.AtEnd())
1728     return false;
1729   if (!column_gap)
1730     column_gap = row_gap;
1731   css_property_parser_helpers::AddProperty(
1732       CSSPropertyID::kRowGap, CSSPropertyID::kGap, *row_gap, important,
1733       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1734       properties);
1735   css_property_parser_helpers::AddProperty(
1736       CSSPropertyID::kColumnGap, CSSPropertyID::kGap, *column_gap, important,
1737       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1738       properties);
1739   return true;
1740 }
1741 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1742 const CSSValue* GridGap::CSSValueFromComputedStyleInternal(
1743     const ComputedStyle& style,
1744     const SVGComputedStyle&,
1745     const LayoutObject* layout_object,
1746     bool allow_visited_style) const {
1747   return ComputedStyleUtils::ValuesForShorthandProperty(
1748       gridGapShorthand(), style, layout_object, allow_visited_style);
1749 }
1750 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1751 bool GridRow::ParseShorthand(
1752     bool important,
1753     CSSParserTokenRange& range,
1754     const CSSParserContext& context,
1755     const CSSParserLocalContext&,
1756     HeapVector<CSSPropertyValue, 256>& properties) const {
1757   const StylePropertyShorthand& shorthand =
1758       shorthandForProperty(CSSPropertyID::kGridRow);
1759   DCHECK_EQ(shorthand.length(), 2u);
1760 
1761   CSSValue* start_value = nullptr;
1762   CSSValue* end_value = nullptr;
1763   if (!css_parsing_utils::ConsumeGridItemPositionShorthand(
1764           important, range, context, start_value, end_value)) {
1765     return false;
1766   }
1767 
1768   css_property_parser_helpers::AddProperty(
1769       shorthand.properties()[0]->PropertyID(), CSSPropertyID::kGridRow,
1770       *start_value, important,
1771       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1772       properties);
1773   css_property_parser_helpers::AddProperty(
1774       shorthand.properties()[1]->PropertyID(), CSSPropertyID::kGridRow,
1775       *end_value, important,
1776       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1777       properties);
1778 
1779   return true;
1780 }
1781 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1782 const CSSValue* GridRow::CSSValueFromComputedStyleInternal(
1783     const ComputedStyle& style,
1784     const SVGComputedStyle&,
1785     const LayoutObject* layout_object,
1786     bool allow_visited_style) const {
1787   return ComputedStyleUtils::ValuesForGridShorthand(
1788       gridRowShorthand(), style, layout_object, allow_visited_style);
1789 }
1790 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1791 bool GridRowGap::ParseShorthand(
1792     bool important,
1793     CSSParserTokenRange& range,
1794     const CSSParserContext& context,
1795     const CSSParserLocalContext&,
1796     HeapVector<CSSPropertyValue, 256>& properties) const {
1797   CSSValue* gap_length = css_parsing_utils::ConsumeGapLength(range, context);
1798   if (!gap_length || !range.AtEnd())
1799     return false;
1800 
1801   css_property_parser_helpers::AddProperty(
1802       CSSPropertyID::kRowGap, CSSPropertyID::kGridRowGap, *gap_length,
1803       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1804       properties);
1805   return true;
1806 }
1807 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1808 const CSSValue* GridRowGap::CSSValueFromComputedStyleInternal(
1809     const ComputedStyle& style,
1810     const SVGComputedStyle&,
1811     const LayoutObject* layout_object,
1812     bool allow_visited_style) const {
1813   return ComputedStyleUtils::ValuesForShorthandProperty(
1814       gridRowGapShorthand(), style, layout_object, allow_visited_style);
1815 }
1816 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1817 bool GridTemplate::ParseShorthand(
1818     bool important,
1819     CSSParserTokenRange& range,
1820     const CSSParserContext& context,
1821     const CSSParserLocalContext&,
1822     HeapVector<CSSPropertyValue, 256>& properties) const {
1823   CSSValue* template_rows = nullptr;
1824   CSSValue* template_columns = nullptr;
1825   CSSValue* template_areas = nullptr;
1826   if (!css_parsing_utils::ConsumeGridTemplateShorthand(
1827           important, range, context, template_rows, template_columns,
1828           template_areas))
1829     return false;
1830 
1831   DCHECK(template_rows);
1832   DCHECK(template_columns);
1833   DCHECK(template_areas);
1834 
1835   css_property_parser_helpers::AddProperty(
1836       CSSPropertyID::kGridTemplateRows, CSSPropertyID::kGridTemplate,
1837       *template_rows, important,
1838       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1839       properties);
1840   css_property_parser_helpers::AddProperty(
1841       CSSPropertyID::kGridTemplateColumns, CSSPropertyID::kGridTemplate,
1842       *template_columns, important,
1843       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1844       properties);
1845   css_property_parser_helpers::AddProperty(
1846       CSSPropertyID::kGridTemplateAreas, CSSPropertyID::kGridTemplate,
1847       *template_areas, important,
1848       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1849       properties);
1850 
1851   return true;
1852 }
1853 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const1854 bool GridTemplate::IsLayoutDependent(const ComputedStyle* style,
1855                                      LayoutObject* layout_object) const {
1856   return layout_object && layout_object->IsLayoutGrid();
1857 }
1858 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1859 const CSSValue* GridTemplate::CSSValueFromComputedStyleInternal(
1860     const ComputedStyle& style,
1861     const SVGComputedStyle&,
1862     const LayoutObject* layout_object,
1863     bool allow_visited_style) const {
1864   return ComputedStyleUtils::ValuesForGridShorthand(
1865       gridTemplateShorthand(), style, layout_object, allow_visited_style);
1866 }
1867 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1868 bool InsetBlock::ParseShorthand(
1869     bool important,
1870     CSSParserTokenRange& range,
1871     const CSSParserContext& context,
1872     const CSSParserLocalContext&,
1873     HeapVector<CSSPropertyValue, 256>& properties) const {
1874   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
1875       insetBlockShorthand(), important, context, range, properties);
1876 }
1877 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1878 const CSSValue* InsetBlock::CSSValueFromComputedStyleInternal(
1879     const ComputedStyle& style,
1880     const SVGComputedStyle&,
1881     const LayoutObject* layout_object,
1882     bool allow_visited_style) const {
1883   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
1884       insetBlockShorthand(), style, layout_object, allow_visited_style);
1885 }
1886 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1887 bool Inset::ParseShorthand(
1888     bool important,
1889     CSSParserTokenRange& range,
1890     const CSSParserContext& context,
1891     const CSSParserLocalContext&,
1892     HeapVector<CSSPropertyValue, 256>& properties) const {
1893   return css_property_parser_helpers::ConsumeShorthandVia4Longhands(
1894       insetShorthand(), important, context, range, properties);
1895 }
1896 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1897 const CSSValue* Inset::CSSValueFromComputedStyleInternal(
1898     const ComputedStyle& style,
1899     const SVGComputedStyle&,
1900     const LayoutObject* layout_object,
1901     bool allow_visited_style) const {
1902   return ComputedStyleUtils::ValuesForSidesShorthand(
1903       insetShorthand(), style, layout_object, allow_visited_style);
1904 }
1905 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1906 bool InsetInline::ParseShorthand(
1907     bool important,
1908     CSSParserTokenRange& range,
1909     const CSSParserContext& context,
1910     const CSSParserLocalContext&,
1911     HeapVector<CSSPropertyValue, 256>& properties) const {
1912   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
1913       insetInlineShorthand(), important, context, range, properties);
1914 }
1915 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const1916 const CSSValue* InsetInline::CSSValueFromComputedStyleInternal(
1917     const ComputedStyle& style,
1918     const SVGComputedStyle&,
1919     const LayoutObject* layout_object,
1920     bool allow_visited_style) const {
1921   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
1922       insetInlineShorthand(), style, layout_object, allow_visited_style);
1923 }
1924 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const1925 bool ListStyle::ParseShorthand(
1926     bool important,
1927     CSSParserTokenRange& range,
1928     const CSSParserContext& context,
1929     const CSSParserLocalContext&,
1930     HeapVector<CSSPropertyValue, 256>& properties) const {
1931   const CSSValue* none = nullptr;
1932   const CSSValue* list_style_position = nullptr;
1933   const CSSValue* list_style_image = nullptr;
1934   const CSSValue* list_style_type = nullptr;
1935   do {
1936     if (!none) {
1937       none =
1938           css_property_parser_helpers::ConsumeIdent<CSSValueID::kNone>(range);
1939       if (none)
1940         continue;
1941     }
1942     if (!list_style_position) {
1943       list_style_position = css_property_parser_helpers::ParseLonghand(
1944           CSSPropertyID::kListStylePosition, CSSPropertyID::kListStyle, context,
1945           range);
1946       if (list_style_position)
1947         continue;
1948     }
1949     if (!list_style_image) {
1950       list_style_image = css_property_parser_helpers::ParseLonghand(
1951           CSSPropertyID::kListStyleImage, CSSPropertyID::kListStyle, context,
1952           range);
1953       if (list_style_image)
1954         continue;
1955     }
1956     if (!list_style_type) {
1957       list_style_type = css_property_parser_helpers::ParseLonghand(
1958           CSSPropertyID::kListStyleType, CSSPropertyID::kListStyle, context,
1959           range);
1960       if (list_style_type)
1961         continue;
1962     }
1963     return false;
1964   } while (!range.AtEnd());
1965   if (none) {
1966     if (!list_style_type)
1967       list_style_type = none;
1968     else if (!list_style_image)
1969       list_style_image = none;
1970     else
1971       return false;
1972   }
1973 
1974   if (list_style_position) {
1975     AddProperty(CSSPropertyID::kListStylePosition, CSSPropertyID::kListStyle,
1976                 *list_style_position, important,
1977                 css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1978                 properties);
1979   } else {
1980     AddProperty(CSSPropertyID::kListStylePosition, CSSPropertyID::kListStyle,
1981                 *CSSInitialValue::Create(), important,
1982                 css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1983                 properties);
1984   }
1985 
1986   if (list_style_image) {
1987     AddProperty(CSSPropertyID::kListStyleImage, CSSPropertyID::kListStyle,
1988                 *list_style_image, important,
1989                 css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1990                 properties);
1991   } else {
1992     AddProperty(CSSPropertyID::kListStyleImage, CSSPropertyID::kListStyle,
1993                 *CSSInitialValue::Create(), important,
1994                 css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
1995                 properties);
1996   }
1997 
1998   if (list_style_type) {
1999     AddProperty(CSSPropertyID::kListStyleType, CSSPropertyID::kListStyle,
2000                 *list_style_type, important,
2001                 css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2002                 properties);
2003   } else {
2004     AddProperty(CSSPropertyID::kListStyleType, CSSPropertyID::kListStyle,
2005                 *CSSInitialValue::Create(), important,
2006                 css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2007                 properties);
2008   }
2009 
2010   return true;
2011 }
2012 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2013 const CSSValue* ListStyle::CSSValueFromComputedStyleInternal(
2014     const ComputedStyle& style,
2015     const SVGComputedStyle&,
2016     const LayoutObject* layout_object,
2017     bool allow_visited_style) const {
2018   return ComputedStyleUtils::ValuesForShorthandProperty(
2019       listStyleShorthand(), style, layout_object, allow_visited_style);
2020 }
2021 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2022 bool MarginBlock::ParseShorthand(
2023     bool important,
2024     CSSParserTokenRange& range,
2025     const CSSParserContext& context,
2026     const CSSParserLocalContext&,
2027     HeapVector<CSSPropertyValue, 256>& properties) const {
2028   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2029       marginBlockShorthand(), important, context, range, properties);
2030 }
2031 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2032 const CSSValue* MarginBlock::CSSValueFromComputedStyleInternal(
2033     const ComputedStyle& style,
2034     const SVGComputedStyle&,
2035     const LayoutObject* layout_object,
2036     bool allow_visited_style) const {
2037   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
2038       marginBlockShorthand(), style, layout_object, allow_visited_style);
2039 }
2040 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2041 bool Margin::ParseShorthand(
2042     bool important,
2043     CSSParserTokenRange& range,
2044     const CSSParserContext& context,
2045     const CSSParserLocalContext&,
2046     HeapVector<CSSPropertyValue, 256>& properties) const {
2047   return css_property_parser_helpers::ConsumeShorthandVia4Longhands(
2048       marginShorthand(), important, context, range, properties);
2049 }
2050 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const2051 bool Margin::IsLayoutDependent(const ComputedStyle* style,
2052                                LayoutObject* layout_object) const {
2053   return layout_object && layout_object->IsBox() &&
2054          (!style || !style->MarginBottom().IsFixed() ||
2055           !style->MarginTop().IsFixed() || !style->MarginLeft().IsFixed() ||
2056           !style->MarginRight().IsFixed());
2057 }
2058 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2059 const CSSValue* Margin::CSSValueFromComputedStyleInternal(
2060     const ComputedStyle& style,
2061     const SVGComputedStyle&,
2062     const LayoutObject* layout_object,
2063     bool allow_visited_style) const {
2064   return ComputedStyleUtils::ValuesForSidesShorthand(
2065       marginShorthand(), style, layout_object, allow_visited_style);
2066 }
2067 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2068 bool MarginInline::ParseShorthand(
2069     bool important,
2070     CSSParserTokenRange& range,
2071     const CSSParserContext& context,
2072     const CSSParserLocalContext&,
2073     HeapVector<CSSPropertyValue, 256>& properties) const {
2074   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2075       marginInlineShorthand(), important, context, range, properties);
2076 }
2077 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2078 const CSSValue* MarginInline::CSSValueFromComputedStyleInternal(
2079     const ComputedStyle& style,
2080     const SVGComputedStyle&,
2081     const LayoutObject* layout_object,
2082     bool allow_visited_style) const {
2083   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
2084       marginInlineShorthand(), style, layout_object, allow_visited_style);
2085 }
2086 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2087 bool Marker::ParseShorthand(
2088     bool important,
2089     CSSParserTokenRange& range,
2090     const CSSParserContext& context,
2091     const CSSParserLocalContext&,
2092     HeapVector<CSSPropertyValue, 256>& properties) const {
2093   const CSSValue* marker = css_property_parser_helpers::ParseLonghand(
2094       CSSPropertyID::kMarkerStart, CSSPropertyID::kMarker, context, range);
2095   if (!marker || !range.AtEnd())
2096     return false;
2097 
2098   css_property_parser_helpers::AddProperty(
2099       CSSPropertyID::kMarkerStart, CSSPropertyID::kMarker, *marker, important,
2100       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2101       properties);
2102   css_property_parser_helpers::AddProperty(
2103       CSSPropertyID::kMarkerMid, CSSPropertyID::kMarker, *marker, important,
2104       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2105       properties);
2106   css_property_parser_helpers::AddProperty(
2107       CSSPropertyID::kMarkerEnd, CSSPropertyID::kMarker, *marker, important,
2108       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2109       properties);
2110   return true;
2111 }
2112 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle & svg_style,const LayoutObject * layout_object,bool allow_visited_style) const2113 const CSSValue* Marker::CSSValueFromComputedStyleInternal(
2114     const ComputedStyle& style,
2115     const SVGComputedStyle& svg_style,
2116     const LayoutObject* layout_object,
2117     bool allow_visited_style) const {
2118   const CSSValue* marker_start =
2119       ComputedStyleUtils::ValueForSVGResource(svg_style.MarkerStartResource());
2120   if (*marker_start == *ComputedStyleUtils::ValueForSVGResource(
2121                            svg_style.MarkerMidResource()) &&
2122       *marker_start == *ComputedStyleUtils::ValueForSVGResource(
2123                            svg_style.MarkerEndResource())) {
2124     return marker_start;
2125   }
2126   return nullptr;
2127 }
2128 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2129 bool Offset::ParseShorthand(
2130     bool important,
2131     CSSParserTokenRange& range,
2132     const CSSParserContext& context,
2133     const CSSParserLocalContext&,
2134     HeapVector<CSSPropertyValue, 256>& properties) const {
2135   // TODO(meade): The propertyID parameter isn't used - it can be removed
2136   // once all of the ParseSingleValue implementations have been moved to the
2137   // CSSPropertys, and the base CSSProperty::ParseSingleValue contains
2138   // no functionality.
2139   const CSSValue* offset_position =
2140       To<Longhand>(GetCSSPropertyOffsetPosition())
2141           .ParseSingleValue(range, context, CSSParserLocalContext());
2142   const CSSValue* offset_path =
2143       css_parsing_utils::ConsumeOffsetPath(range, context);
2144   const CSSValue* offset_distance = nullptr;
2145   const CSSValue* offset_rotate = nullptr;
2146   if (offset_path) {
2147     offset_distance = css_property_parser_helpers::ConsumeLengthOrPercent(
2148         range, context, kValueRangeAll);
2149     offset_rotate = css_parsing_utils::ConsumeOffsetRotate(range, context);
2150     if (offset_rotate && !offset_distance) {
2151       offset_distance = css_property_parser_helpers::ConsumeLengthOrPercent(
2152           range, context, kValueRangeAll);
2153     }
2154   }
2155   const CSSValue* offset_anchor = nullptr;
2156   if (css_property_parser_helpers::ConsumeSlashIncludingWhitespace(range)) {
2157     offset_anchor =
2158         To<Longhand>(GetCSSPropertyOffsetAnchor())
2159             .ParseSingleValue(range, context, CSSParserLocalContext());
2160     if (!offset_anchor)
2161       return false;
2162   }
2163   if ((!offset_position && !offset_path) || !range.AtEnd())
2164     return false;
2165 
2166   if ((offset_position || offset_anchor) &&
2167       !RuntimeEnabledFeatures::CSSOffsetPositionAnchorEnabled())
2168     return false;
2169 
2170   if (offset_position) {
2171     css_property_parser_helpers::AddProperty(
2172         CSSPropertyID::kOffsetPosition, CSSPropertyID::kOffset,
2173         *offset_position, important,
2174         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2175         properties);
2176   } else if (RuntimeEnabledFeatures::CSSOffsetPositionAnchorEnabled()) {
2177     css_property_parser_helpers::AddProperty(
2178         CSSPropertyID::kOffsetPosition, CSSPropertyID::kOffset,
2179         *CSSInitialValue::Create(), important,
2180         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2181         properties);
2182   }
2183 
2184   if (offset_path) {
2185     css_property_parser_helpers::AddProperty(
2186         CSSPropertyID::kOffsetPath, CSSPropertyID::kOffset, *offset_path,
2187         important,
2188         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2189         properties);
2190   } else {
2191     css_property_parser_helpers::AddProperty(
2192         CSSPropertyID::kOffsetPath, CSSPropertyID::kOffset,
2193         *CSSInitialValue::Create(), important,
2194         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2195         properties);
2196   }
2197 
2198   if (offset_distance) {
2199     css_property_parser_helpers::AddProperty(
2200         CSSPropertyID::kOffsetDistance, CSSPropertyID::kOffset,
2201         *offset_distance, important,
2202         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2203         properties);
2204   } else {
2205     css_property_parser_helpers::AddProperty(
2206         CSSPropertyID::kOffsetDistance, CSSPropertyID::kOffset,
2207         *CSSInitialValue::Create(), important,
2208         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2209         properties);
2210   }
2211 
2212   if (offset_rotate) {
2213     css_property_parser_helpers::AddProperty(
2214         CSSPropertyID::kOffsetRotate, CSSPropertyID::kOffset, *offset_rotate,
2215         important,
2216         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2217         properties);
2218   } else {
2219     css_property_parser_helpers::AddProperty(
2220         CSSPropertyID::kOffsetRotate, CSSPropertyID::kOffset,
2221         *CSSInitialValue::Create(), important,
2222         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2223         properties);
2224   }
2225 
2226   if (offset_anchor) {
2227     css_property_parser_helpers::AddProperty(
2228         CSSPropertyID::kOffsetAnchor, CSSPropertyID::kOffset, *offset_anchor,
2229         important,
2230         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2231         properties);
2232   } else if (RuntimeEnabledFeatures::CSSOffsetPositionAnchorEnabled()) {
2233     css_property_parser_helpers::AddProperty(
2234         CSSPropertyID::kOffsetAnchor, CSSPropertyID::kOffset,
2235         *CSSInitialValue::Create(), important,
2236         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2237         properties);
2238   }
2239 
2240   return true;
2241 }
2242 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2243 const CSSValue* Offset::CSSValueFromComputedStyleInternal(
2244     const ComputedStyle& style,
2245     const SVGComputedStyle&,
2246     const LayoutObject* layout_object,
2247     bool allow_visited_style) const {
2248   return ComputedStyleUtils::ValueForOffset(style, layout_object,
2249                                             allow_visited_style);
2250 }
2251 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2252 bool Outline::ParseShorthand(
2253     bool important,
2254     CSSParserTokenRange& range,
2255     const CSSParserContext& context,
2256     const CSSParserLocalContext&,
2257     HeapVector<CSSPropertyValue, 256>& properties) const {
2258   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
2259       outlineShorthand(), important, context, range, properties);
2260 }
2261 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2262 const CSSValue* Outline::CSSValueFromComputedStyleInternal(
2263     const ComputedStyle& style,
2264     const SVGComputedStyle&,
2265     const LayoutObject* layout_object,
2266     bool allow_visited_style) const {
2267   return ComputedStyleUtils::ValuesForShorthandProperty(
2268       outlineShorthand(), style, layout_object, allow_visited_style);
2269 }
2270 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2271 bool Overflow::ParseShorthand(
2272     bool important,
2273     CSSParserTokenRange& range,
2274     const CSSParserContext& context,
2275     const CSSParserLocalContext&,
2276     HeapVector<CSSPropertyValue, 256>& properties) const {
2277   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2278       overflowShorthand(), important, context, range, properties);
2279 }
2280 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2281 const CSSValue* Overflow::CSSValueFromComputedStyleInternal(
2282     const ComputedStyle& style,
2283     const SVGComputedStyle&,
2284     const LayoutObject*,
2285     bool allow_visited_style) const {
2286   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
2287   list->Append(*CSSIdentifierValue::Create(style.OverflowX()));
2288   if (style.OverflowX() != style.OverflowY())
2289     list->Append(*CSSIdentifierValue::Create(style.OverflowY()));
2290 
2291   return list;
2292 }
2293 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2294 bool OverscrollBehavior::ParseShorthand(
2295     bool important,
2296     CSSParserTokenRange& range,
2297     const CSSParserContext& context,
2298     const CSSParserLocalContext&,
2299     HeapVector<CSSPropertyValue, 256>& properties) const {
2300   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2301       overscrollBehaviorShorthand(), important, context, range, properties);
2302 }
2303 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2304 const CSSValue* OverscrollBehavior::CSSValueFromComputedStyleInternal(
2305     const ComputedStyle& style,
2306     const SVGComputedStyle&,
2307     const LayoutObject*,
2308     bool allow_visited_style) const {
2309   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
2310   list->Append(*CSSIdentifierValue::Create(style.OverscrollBehaviorX()));
2311   if (style.OverscrollBehaviorX() != style.OverscrollBehaviorY())
2312     list->Append(*CSSIdentifierValue::Create(style.OverscrollBehaviorY()));
2313 
2314   return list;
2315 }
2316 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2317 bool PaddingBlock::ParseShorthand(
2318     bool important,
2319     CSSParserTokenRange& range,
2320     const CSSParserContext& context,
2321     const CSSParserLocalContext&,
2322     HeapVector<CSSPropertyValue, 256>& properties) const {
2323   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2324       paddingBlockShorthand(), important, context, range, properties);
2325 }
2326 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2327 const CSSValue* PaddingBlock::CSSValueFromComputedStyleInternal(
2328     const ComputedStyle& style,
2329     const SVGComputedStyle&,
2330     const LayoutObject* layout_object,
2331     bool allow_visited_style) const {
2332   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
2333       paddingBlockShorthand(), style, layout_object, allow_visited_style);
2334 }
2335 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2336 bool Padding::ParseShorthand(
2337     bool important,
2338     CSSParserTokenRange& range,
2339     const CSSParserContext& context,
2340     const CSSParserLocalContext&,
2341     HeapVector<CSSPropertyValue, 256>& properties) const {
2342   return css_property_parser_helpers::ConsumeShorthandVia4Longhands(
2343       paddingShorthand(), important, context, range, properties);
2344 }
2345 
IsLayoutDependent(const ComputedStyle * style,LayoutObject * layout_object) const2346 bool Padding::IsLayoutDependent(const ComputedStyle* style,
2347                                 LayoutObject* layout_object) const {
2348   return layout_object && layout_object->IsBox() &&
2349          (!style || !style->PaddingBottom().IsFixed() ||
2350           !style->PaddingTop().IsFixed() || !style->PaddingLeft().IsFixed() ||
2351           !style->PaddingRight().IsFixed());
2352 }
2353 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2354 const CSSValue* Padding::CSSValueFromComputedStyleInternal(
2355     const ComputedStyle& style,
2356     const SVGComputedStyle&,
2357     const LayoutObject* layout_object,
2358     bool allow_visited_style) const {
2359   return ComputedStyleUtils::ValuesForSidesShorthand(
2360       paddingShorthand(), style, layout_object, allow_visited_style);
2361 }
2362 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2363 bool PaddingInline::ParseShorthand(
2364     bool important,
2365     CSSParserTokenRange& range,
2366     const CSSParserContext& context,
2367     const CSSParserLocalContext&,
2368     HeapVector<CSSPropertyValue, 256>& properties) const {
2369   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2370       paddingInlineShorthand(), important, context, range, properties);
2371 }
2372 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2373 const CSSValue* PaddingInline::CSSValueFromComputedStyleInternal(
2374     const ComputedStyle& style,
2375     const SVGComputedStyle&,
2376     const LayoutObject* layout_object,
2377     bool allow_visited_style) const {
2378   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
2379       paddingInlineShorthand(), style, layout_object, allow_visited_style);
2380 }
2381 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2382 bool PageBreakAfter::ParseShorthand(
2383     bool important,
2384     CSSParserTokenRange& range,
2385     const CSSParserContext&,
2386     const CSSParserLocalContext&,
2387     HeapVector<CSSPropertyValue, 256>& properties) const {
2388   CSSValueID value;
2389   if (!css_parsing_utils::ConsumeFromPageBreakBetween(range, value)) {
2390     return false;
2391   }
2392 
2393   DCHECK(IsValidCSSValueID(value));
2394   css_property_parser_helpers::AddProperty(
2395       CSSPropertyID::kBreakAfter, CSSPropertyID::kPageBreakAfter,
2396       *CSSIdentifierValue::Create(value), important,
2397       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2398       properties);
2399   return true;
2400 }
2401 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2402 const CSSValue* PageBreakAfter::CSSValueFromComputedStyleInternal(
2403     const ComputedStyle& style,
2404     const SVGComputedStyle&,
2405     const LayoutObject*,
2406     bool allow_visited_style) const {
2407   return ComputedStyleUtils::ValueForPageBreakBetween(style.BreakAfter());
2408 }
2409 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2410 bool PageBreakBefore::ParseShorthand(
2411     bool important,
2412     CSSParserTokenRange& range,
2413     const CSSParserContext&,
2414     const CSSParserLocalContext&,
2415     HeapVector<CSSPropertyValue, 256>& properties) const {
2416   CSSValueID value;
2417   if (!css_parsing_utils::ConsumeFromPageBreakBetween(range, value)) {
2418     return false;
2419   }
2420 
2421   DCHECK(IsValidCSSValueID(value));
2422   css_property_parser_helpers::AddProperty(
2423       CSSPropertyID::kBreakBefore, CSSPropertyID::kPageBreakBefore,
2424       *CSSIdentifierValue::Create(value), important,
2425       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2426       properties);
2427   return true;
2428 }
2429 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2430 const CSSValue* PageBreakBefore::CSSValueFromComputedStyleInternal(
2431     const ComputedStyle& style,
2432     const SVGComputedStyle&,
2433     const LayoutObject*,
2434     bool allow_visited_style) const {
2435   return ComputedStyleUtils::ValueForPageBreakBetween(style.BreakBefore());
2436 }
2437 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2438 bool PageBreakInside::ParseShorthand(
2439     bool important,
2440     CSSParserTokenRange& range,
2441     const CSSParserContext&,
2442     const CSSParserLocalContext&,
2443     HeapVector<CSSPropertyValue, 256>& properties) const {
2444   CSSValueID value;
2445   if (!css_parsing_utils::ConsumeFromColumnOrPageBreakInside(range, value)) {
2446     return false;
2447   }
2448 
2449   css_property_parser_helpers::AddProperty(
2450       CSSPropertyID::kBreakInside, CSSPropertyID::kPageBreakInside,
2451       *CSSIdentifierValue::Create(value), important,
2452       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2453       properties);
2454   return true;
2455 }
2456 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2457 const CSSValue* PageBreakInside::CSSValueFromComputedStyleInternal(
2458     const ComputedStyle& style,
2459     const SVGComputedStyle&,
2460     const LayoutObject*,
2461     bool allow_visited_style) const {
2462   return ComputedStyleUtils::ValueForPageBreakInside(style.BreakInside());
2463 }
2464 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const2465 bool PlaceContent::ParseShorthand(
2466     bool important,
2467     CSSParserTokenRange& range,
2468     const CSSParserContext& context,
2469     const CSSParserLocalContext& local_context,
2470     HeapVector<CSSPropertyValue, 256>& properties) const {
2471   DCHECK_EQ(shorthandForProperty(CSSPropertyID::kPlaceContent).length(), 2u);
2472 
2473   CSSParserTokenRange range_copy = range;
2474   bool is_baseline = css_parsing_utils::IsBaselineKeyword(range.Peek().Id());
2475   const CSSValue* align_content_value =
2476       To<Longhand>(GetCSSPropertyAlignContent())
2477           .ParseSingleValue(range, context, local_context);
2478   if (!align_content_value)
2479     return false;
2480 
2481   const CSSValue* justify_content_value = nullptr;
2482   if (range.AtEnd()) {
2483     if (is_baseline) {
2484       justify_content_value =
2485           MakeGarbageCollected<cssvalue::CSSContentDistributionValue>(
2486               CSSValueID::kInvalid, CSSValueID::kStart, CSSValueID::kInvalid);
2487     } else {
2488       range = range_copy;
2489     }
2490   }
2491   if (!justify_content_value) {
2492     justify_content_value =
2493         To<Longhand>(GetCSSPropertyJustifyContent())
2494             .ParseSingleValue(range, context, local_context);
2495   }
2496 
2497   if (!justify_content_value || !range.AtEnd())
2498     return false;
2499 
2500   DCHECK(align_content_value);
2501   DCHECK(justify_content_value);
2502 
2503   css_property_parser_helpers::AddProperty(
2504       CSSPropertyID::kAlignContent, CSSPropertyID::kPlaceContent,
2505       *align_content_value, important,
2506       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2507       properties);
2508   css_property_parser_helpers::AddProperty(
2509       CSSPropertyID::kJustifyContent, CSSPropertyID::kPlaceContent,
2510       *justify_content_value, important,
2511       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2512       properties);
2513 
2514   return true;
2515 }
2516 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2517 const CSSValue* PlaceContent::CSSValueFromComputedStyleInternal(
2518     const ComputedStyle& style,
2519     const SVGComputedStyle&,
2520     const LayoutObject* layout_object,
2521     bool allow_visited_style) const {
2522   return ComputedStyleUtils::ValuesForPlaceShorthand(
2523       placeContentShorthand(), style, layout_object, allow_visited_style);
2524 }
2525 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const2526 bool PlaceItems::ParseShorthand(
2527     bool important,
2528     CSSParserTokenRange& range,
2529     const CSSParserContext& context,
2530     const CSSParserLocalContext& local_context,
2531     HeapVector<CSSPropertyValue, 256>& properties) const {
2532   DCHECK_EQ(shorthandForProperty(CSSPropertyID::kPlaceItems).length(), 2u);
2533 
2534   CSSParserTokenRange range_copy = range;
2535   const CSSValue* align_items_value =
2536       To<Longhand>(GetCSSPropertyAlignItems())
2537           .ParseSingleValue(range, context, local_context);
2538   if (!align_items_value)
2539     return false;
2540 
2541   if (range.AtEnd())
2542     range = range_copy;
2543 
2544   const CSSValue* justify_items_value =
2545       To<Longhand>(GetCSSPropertyJustifyItems())
2546           .ParseSingleValue(range, context, local_context);
2547   if (!justify_items_value || !range.AtEnd())
2548     return false;
2549 
2550   DCHECK(align_items_value);
2551   DCHECK(justify_items_value);
2552 
2553   css_property_parser_helpers::AddProperty(
2554       CSSPropertyID::kAlignItems, CSSPropertyID::kPlaceItems,
2555       *align_items_value, important,
2556       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2557       properties);
2558   css_property_parser_helpers::AddProperty(
2559       CSSPropertyID::kJustifyItems, CSSPropertyID::kPlaceItems,
2560       *justify_items_value, important,
2561       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2562       properties);
2563 
2564   return true;
2565 }
2566 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2567 const CSSValue* PlaceItems::CSSValueFromComputedStyleInternal(
2568     const ComputedStyle& style,
2569     const SVGComputedStyle&,
2570     const LayoutObject* layout_object,
2571     bool allow_visited_style) const {
2572   return ComputedStyleUtils::ValuesForPlaceShorthand(
2573       placeItemsShorthand(), style, layout_object, allow_visited_style);
2574 }
2575 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const2576 bool PlaceSelf::ParseShorthand(
2577     bool important,
2578     CSSParserTokenRange& range,
2579     const CSSParserContext& context,
2580     const CSSParserLocalContext& local_context,
2581     HeapVector<CSSPropertyValue, 256>& properties) const {
2582   DCHECK_EQ(shorthandForProperty(CSSPropertyID::kPlaceSelf).length(), 2u);
2583 
2584   CSSParserTokenRange range_copy = range;
2585   const CSSValue* align_self_value =
2586       To<Longhand>(GetCSSPropertyAlignSelf())
2587           .ParseSingleValue(range, context, local_context);
2588   if (!align_self_value)
2589     return false;
2590 
2591   if (range.AtEnd())
2592     range = range_copy;
2593 
2594   const CSSValue* justify_self_value =
2595       To<Longhand>(GetCSSPropertyJustifySelf())
2596           .ParseSingleValue(range, context, local_context);
2597   if (!justify_self_value || !range.AtEnd())
2598     return false;
2599 
2600   DCHECK(align_self_value);
2601   DCHECK(justify_self_value);
2602 
2603   css_property_parser_helpers::AddProperty(
2604       CSSPropertyID::kAlignSelf, CSSPropertyID::kPlaceSelf, *align_self_value,
2605       important, css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2606       properties);
2607   css_property_parser_helpers::AddProperty(
2608       CSSPropertyID::kJustifySelf, CSSPropertyID::kPlaceSelf,
2609       *justify_self_value, important,
2610       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2611       properties);
2612 
2613   return true;
2614 }
2615 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2616 const CSSValue* PlaceSelf::CSSValueFromComputedStyleInternal(
2617     const ComputedStyle& style,
2618     const SVGComputedStyle&,
2619     const LayoutObject* layout_object,
2620     bool allow_visited_style) const {
2621   return ComputedStyleUtils::ValuesForPlaceShorthand(
2622       placeSelfShorthand(), style, layout_object, allow_visited_style);
2623 }
2624 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2625 bool ScrollMarginBlock::ParseShorthand(
2626     bool important,
2627     CSSParserTokenRange& range,
2628     const CSSParserContext& context,
2629     const CSSParserLocalContext&,
2630     HeapVector<CSSPropertyValue, 256>& properties) const {
2631   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2632       scrollMarginBlockShorthand(), important, context, range, properties);
2633 }
2634 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2635 const CSSValue* ScrollMarginBlock::CSSValueFromComputedStyleInternal(
2636     const ComputedStyle& style,
2637     const SVGComputedStyle&,
2638     const LayoutObject* layout_object,
2639     bool allow_visited_style) const {
2640   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
2641       scrollMarginBlockShorthand(), style, layout_object, allow_visited_style);
2642 }
2643 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2644 bool ScrollMargin::ParseShorthand(
2645     bool important,
2646     CSSParserTokenRange& range,
2647     const CSSParserContext& context,
2648     const CSSParserLocalContext&,
2649     HeapVector<CSSPropertyValue, 256>& properties) const {
2650   return css_property_parser_helpers::ConsumeShorthandVia4Longhands(
2651       scrollMarginShorthand(), important, context, range, properties);
2652 }
2653 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2654 const CSSValue* ScrollMargin::CSSValueFromComputedStyleInternal(
2655     const ComputedStyle& style,
2656     const SVGComputedStyle&,
2657     const LayoutObject* layout_object,
2658     bool allow_visited_style) const {
2659   return ComputedStyleUtils::ValuesForSidesShorthand(
2660       scrollMarginShorthand(), style, layout_object, allow_visited_style);
2661 }
2662 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2663 bool ScrollMarginInline::ParseShorthand(
2664     bool important,
2665     CSSParserTokenRange& range,
2666     const CSSParserContext& context,
2667     const CSSParserLocalContext&,
2668     HeapVector<CSSPropertyValue, 256>& properties) const {
2669   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2670       scrollMarginInlineShorthand(), important, context, range, properties);
2671 }
2672 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2673 const CSSValue* ScrollMarginInline::CSSValueFromComputedStyleInternal(
2674     const ComputedStyle& style,
2675     const SVGComputedStyle&,
2676     const LayoutObject* layout_object,
2677     bool allow_visited_style) const {
2678   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
2679       scrollMarginInlineShorthand(), style, layout_object, allow_visited_style);
2680 }
2681 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2682 bool ScrollPaddingBlock::ParseShorthand(
2683     bool important,
2684     CSSParserTokenRange& range,
2685     const CSSParserContext& context,
2686     const CSSParserLocalContext&,
2687     HeapVector<CSSPropertyValue, 256>& properties) const {
2688   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2689       scrollPaddingBlockShorthand(), important, context, range, properties);
2690 }
2691 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2692 const CSSValue* ScrollPaddingBlock::CSSValueFromComputedStyleInternal(
2693     const ComputedStyle& style,
2694     const SVGComputedStyle&,
2695     const LayoutObject* layout_object,
2696     bool allow_visited_style) const {
2697   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
2698       scrollPaddingBlockShorthand(), style, layout_object, allow_visited_style);
2699 }
2700 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2701 bool ScrollPadding::ParseShorthand(
2702     bool important,
2703     CSSParserTokenRange& range,
2704     const CSSParserContext& context,
2705     const CSSParserLocalContext&,
2706     HeapVector<CSSPropertyValue, 256>& properties) const {
2707   return css_property_parser_helpers::ConsumeShorthandVia4Longhands(
2708       scrollPaddingShorthand(), important, context, range, properties);
2709 }
2710 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2711 const CSSValue* ScrollPadding::CSSValueFromComputedStyleInternal(
2712     const ComputedStyle& style,
2713     const SVGComputedStyle&,
2714     const LayoutObject* layout_object,
2715     bool allow_visited_style) const {
2716   return ComputedStyleUtils::ValuesForSidesShorthand(
2717       scrollPaddingShorthand(), style, layout_object, allow_visited_style);
2718 }
2719 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2720 bool ScrollPaddingInline::ParseShorthand(
2721     bool important,
2722     CSSParserTokenRange& range,
2723     const CSSParserContext& context,
2724     const CSSParserLocalContext&,
2725     HeapVector<CSSPropertyValue, 256>& properties) const {
2726   return css_property_parser_helpers::ConsumeShorthandVia2Longhands(
2727       scrollPaddingInlineShorthand(), important, context, range, properties);
2728 }
2729 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2730 const CSSValue* ScrollPaddingInline::CSSValueFromComputedStyleInternal(
2731     const ComputedStyle& style,
2732     const SVGComputedStyle&,
2733     const LayoutObject* layout_object,
2734     bool allow_visited_style) const {
2735   return ComputedStyleUtils::ValuesForInlineBlockShorthand(
2736       scrollPaddingInlineShorthand(), style, layout_object,
2737       allow_visited_style);
2738 }
2739 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2740 bool TextDecoration::ParseShorthand(
2741     bool important,
2742     CSSParserTokenRange& range,
2743     const CSSParserContext& context,
2744     const CSSParserLocalContext&,
2745     HeapVector<CSSPropertyValue, 256>& properties) const {
2746   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
2747       textDecorationShorthand(), important, context, range, properties);
2748 }
2749 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject * layout_object,bool allow_visited_style) const2750 const CSSValue* TextDecoration::CSSValueFromComputedStyleInternal(
2751     const ComputedStyle& style,
2752     const SVGComputedStyle&,
2753     const LayoutObject* layout_object,
2754     bool allow_visited_style) const {
2755   return ComputedStyleUtils::ValuesForShorthandProperty(
2756       textDecorationShorthand(), style, layout_object, allow_visited_style);
2757 }
2758 
2759 namespace {
2760 
ConsumeTransitionValue(CSSPropertyID property,CSSParserTokenRange & range,const CSSParserContext & context,bool use_legacy_parsing)2761 CSSValue* ConsumeTransitionValue(CSSPropertyID property,
2762                                  CSSParserTokenRange& range,
2763                                  const CSSParserContext& context,
2764                                  bool use_legacy_parsing) {
2765   switch (property) {
2766     case CSSPropertyID::kTransitionDelay:
2767       return css_property_parser_helpers::ConsumeTime(range, context,
2768                                                       kValueRangeAll);
2769     case CSSPropertyID::kTransitionDuration:
2770       return css_property_parser_helpers::ConsumeTime(range, context,
2771                                                       kValueRangeNonNegative);
2772     case CSSPropertyID::kTransitionProperty:
2773       return css_parsing_utils::ConsumeTransitionProperty(range, context);
2774     case CSSPropertyID::kTransitionTimingFunction:
2775       return css_parsing_utils::ConsumeAnimationTimingFunction(range, context);
2776     default:
2777       NOTREACHED();
2778       return nullptr;
2779   }
2780 }
2781 
2782 }  // namespace
2783 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const2784 bool Transition::ParseShorthand(
2785     bool important,
2786     CSSParserTokenRange& range,
2787     const CSSParserContext& context,
2788     const CSSParserLocalContext& local_context,
2789     HeapVector<CSSPropertyValue, 256>& properties) const {
2790   const StylePropertyShorthand shorthand = transitionShorthandForParsing();
2791   const unsigned longhand_count = shorthand.length();
2792 
2793   HeapVector<Member<CSSValueList>, css_parsing_utils::kMaxNumAnimationLonghands>
2794       longhands(longhand_count);
2795   if (!css_parsing_utils::ConsumeAnimationShorthand(
2796           shorthand, longhands, ConsumeTransitionValue, range, context,
2797           local_context.UseAliasParsing())) {
2798     return false;
2799   }
2800 
2801   for (unsigned i = 0; i < longhand_count; ++i) {
2802     if (shorthand.properties()[i]->IDEquals(
2803             CSSPropertyID::kTransitionProperty) &&
2804         !css_parsing_utils::IsValidPropertyList(*longhands[i]))
2805       return false;
2806   }
2807 
2808   for (unsigned i = 0; i < longhand_count; ++i) {
2809     css_property_parser_helpers::AddProperty(
2810         shorthand.properties()[i]->PropertyID(), shorthand.id(), *longhands[i],
2811         important,
2812         css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2813         properties);
2814   }
2815 
2816   return range.AtEnd();
2817 }
2818 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2819 const CSSValue* Transition::CSSValueFromComputedStyleInternal(
2820     const ComputedStyle& style,
2821     const SVGComputedStyle&,
2822     const LayoutObject*,
2823     bool allow_visited_style) const {
2824   const CSSTransitionData* transition_data = style.Transitions();
2825   if (transition_data) {
2826     CSSValueList* transitions_list = CSSValueList::CreateCommaSeparated();
2827     for (wtf_size_t i = 0; i < transition_data->PropertyList().size(); ++i) {
2828       CSSValueList* list = CSSValueList::CreateSpaceSeparated();
2829       list->Append(*ComputedStyleUtils::CreateTransitionPropertyValue(
2830           transition_data->PropertyList()[i]));
2831       list->Append(*CSSNumericLiteralValue::Create(
2832           CSSTimingData::GetRepeated(transition_data->DurationList(), i),
2833           CSSPrimitiveValue::UnitType::kSeconds));
2834       list->Append(*ComputedStyleUtils::CreateTimingFunctionValue(
2835           CSSTimingData::GetRepeated(transition_data->TimingFunctionList(), i)
2836               .get()));
2837       list->Append(*CSSNumericLiteralValue::Create(
2838           CSSTimingData::GetRepeated(transition_data->DelayList(), i),
2839           CSSPrimitiveValue::UnitType::kSeconds));
2840       transitions_list->Append(*list);
2841     }
2842     return transitions_list;
2843   }
2844 
2845   CSSValueList* list = CSSValueList::CreateSpaceSeparated();
2846   // transition-property default value.
2847   list->Append(*CSSIdentifierValue::Create(CSSValueID::kAll));
2848   list->Append(
2849       *CSSNumericLiteralValue::Create(CSSTransitionData::InitialDuration(),
2850                                       CSSPrimitiveValue::UnitType::kSeconds));
2851   list->Append(*ComputedStyleUtils::CreateTimingFunctionValue(
2852       CSSTransitionData::InitialTimingFunction().get()));
2853   list->Append(
2854       *CSSNumericLiteralValue::Create(CSSTransitionData::InitialDelay(),
2855                                       CSSPrimitiveValue::UnitType::kSeconds));
2856   return list;
2857 }
2858 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2859 bool WebkitColumnBreakAfter::ParseShorthand(
2860     bool important,
2861     CSSParserTokenRange& range,
2862     const CSSParserContext&,
2863     const CSSParserLocalContext&,
2864     HeapVector<CSSPropertyValue, 256>& properties) const {
2865   CSSValueID value;
2866   if (!css_parsing_utils::ConsumeFromColumnBreakBetween(range, value)) {
2867     return false;
2868   }
2869 
2870   css_property_parser_helpers::AddProperty(
2871       CSSPropertyID::kBreakAfter, CSSPropertyID::kWebkitColumnBreakAfter,
2872       *CSSIdentifierValue::Create(value), important,
2873       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2874       properties);
2875   return true;
2876 }
2877 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2878 const CSSValue* WebkitColumnBreakAfter::CSSValueFromComputedStyleInternal(
2879     const ComputedStyle& style,
2880     const SVGComputedStyle&,
2881     const LayoutObject*,
2882     bool allow_visited_style) const {
2883   return ComputedStyleUtils::ValueForWebkitColumnBreakBetween(
2884       style.BreakAfter());
2885 }
2886 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2887 bool WebkitColumnBreakBefore::ParseShorthand(
2888     bool important,
2889     CSSParserTokenRange& range,
2890     const CSSParserContext&,
2891     const CSSParserLocalContext&,
2892     HeapVector<CSSPropertyValue, 256>& properties) const {
2893   CSSValueID value;
2894   if (!css_parsing_utils::ConsumeFromColumnBreakBetween(range, value)) {
2895     return false;
2896   }
2897 
2898   css_property_parser_helpers::AddProperty(
2899       CSSPropertyID::kBreakBefore, CSSPropertyID::kWebkitColumnBreakBefore,
2900       *CSSIdentifierValue::Create(value), important,
2901       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2902       properties);
2903   return true;
2904 }
2905 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2906 const CSSValue* WebkitColumnBreakBefore::CSSValueFromComputedStyleInternal(
2907     const ComputedStyle& style,
2908     const SVGComputedStyle&,
2909     const LayoutObject*,
2910     bool allow_visited_style) const {
2911   return ComputedStyleUtils::ValueForWebkitColumnBreakBetween(
2912       style.BreakBefore());
2913 }
2914 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext &,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2915 bool WebkitColumnBreakInside::ParseShorthand(
2916     bool important,
2917     CSSParserTokenRange& range,
2918     const CSSParserContext&,
2919     const CSSParserLocalContext&,
2920     HeapVector<CSSPropertyValue, 256>& properties) const {
2921   CSSValueID value;
2922   if (!css_parsing_utils::ConsumeFromColumnOrPageBreakInside(range, value)) {
2923     return false;
2924   }
2925 
2926   css_property_parser_helpers::AddProperty(
2927       CSSPropertyID::kBreakInside, CSSPropertyID::kWebkitColumnBreakInside,
2928       *CSSIdentifierValue::Create(value), important,
2929       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2930       properties);
2931   return true;
2932 }
2933 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2934 const CSSValue* WebkitColumnBreakInside::CSSValueFromComputedStyleInternal(
2935     const ComputedStyle& style,
2936     const SVGComputedStyle&,
2937     const LayoutObject*,
2938     bool allow_visited_style) const {
2939   return ComputedStyleUtils::ValueForWebkitColumnBreakInside(
2940       style.BreakInside());
2941 }
2942 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const2943 bool WebkitMaskBoxImage::ParseShorthand(
2944     bool important,
2945     CSSParserTokenRange& range,
2946     const CSSParserContext& context,
2947     const CSSParserLocalContext&,
2948     HeapVector<CSSPropertyValue, 256>& properties) const {
2949   CSSValue* source = nullptr;
2950   CSSValue* slice = nullptr;
2951   CSSValue* width = nullptr;
2952   CSSValue* outset = nullptr;
2953   CSSValue* repeat = nullptr;
2954 
2955   if (!css_parsing_utils::ConsumeBorderImageComponents(
2956           range, context, source, slice, width, outset, repeat,
2957           css_parsing_utils::DefaultFill::kFill)) {
2958     return false;
2959   }
2960 
2961   css_property_parser_helpers::AddProperty(
2962       CSSPropertyID::kWebkitMaskBoxImageSource,
2963       CSSPropertyID::kWebkitMaskBoxImage,
2964       source ? *source : *CSSInitialValue::Create(), important,
2965       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2966       properties);
2967   css_property_parser_helpers::AddProperty(
2968       CSSPropertyID::kWebkitMaskBoxImageSlice,
2969       CSSPropertyID::kWebkitMaskBoxImage,
2970       slice ? *slice : *CSSInitialValue::Create(), important,
2971       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2972       properties);
2973   css_property_parser_helpers::AddProperty(
2974       CSSPropertyID::kWebkitMaskBoxImageWidth,
2975       CSSPropertyID::kWebkitMaskBoxImage,
2976       width ? *width : *CSSInitialValue::Create(), important,
2977       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2978       properties);
2979   css_property_parser_helpers::AddProperty(
2980       CSSPropertyID::kWebkitMaskBoxImageOutset,
2981       CSSPropertyID::kWebkitMaskBoxImage,
2982       outset ? *outset : *CSSInitialValue::Create(), important,
2983       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2984       properties);
2985   css_property_parser_helpers::AddProperty(
2986       CSSPropertyID::kWebkitMaskBoxImageRepeat,
2987       CSSPropertyID::kWebkitMaskBoxImage,
2988       repeat ? *repeat : *CSSInitialValue::Create(), important,
2989       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
2990       properties);
2991 
2992   return true;
2993 }
2994 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const2995 const CSSValue* WebkitMaskBoxImage::CSSValueFromComputedStyleInternal(
2996     const ComputedStyle& style,
2997     const SVGComputedStyle&,
2998     const LayoutObject*,
2999     bool allow_visited_style) const {
3000   return ComputedStyleUtils::ValueForNinePieceImage(style.MaskBoxImage(), style,
3001                                                     allow_visited_style);
3002 }
3003 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const3004 bool WebkitMask::ParseShorthand(
3005     bool important,
3006     CSSParserTokenRange& range,
3007     const CSSParserContext& context,
3008     const CSSParserLocalContext& local_context,
3009     HeapVector<CSSPropertyValue, 256>& properties) const {
3010   return css_parsing_utils::ParseBackgroundOrMask(important, range, context,
3011                                                   local_context, properties);
3012 }
3013 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const3014 bool WebkitMaskPosition::ParseShorthand(
3015     bool important,
3016     CSSParserTokenRange& range,
3017     const CSSParserContext& context,
3018     const CSSParserLocalContext&,
3019     HeapVector<CSSPropertyValue, 256>& properties) const {
3020   CSSValue* result_x = nullptr;
3021   CSSValue* result_y = nullptr;
3022 
3023   if (!css_parsing_utils::ConsumeBackgroundPosition(
3024           range, context, css_property_parser_helpers::UnitlessQuirk::kAllow,
3025           result_x, result_y) ||
3026       !range.AtEnd())
3027     return false;
3028 
3029   css_property_parser_helpers::AddProperty(
3030       CSSPropertyID::kWebkitMaskPositionX, CSSPropertyID::kWebkitMaskPosition,
3031       *result_x, important,
3032       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
3033       properties);
3034 
3035   css_property_parser_helpers::AddProperty(
3036       CSSPropertyID::kWebkitMaskPositionY, CSSPropertyID::kWebkitMaskPosition,
3037       *result_y, important,
3038       css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
3039       properties);
3040   return true;
3041 }
3042 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3043 const CSSValue* WebkitMaskPosition::CSSValueFromComputedStyleInternal(
3044     const ComputedStyle& style,
3045     const SVGComputedStyle&,
3046     const LayoutObject*,
3047     bool allow_visited_style) const {
3048   return ComputedStyleUtils::BackgroundPositionOrWebkitMaskPosition(
3049       *this, style, &style.MaskLayers());
3050 }
3051 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext & local_context,HeapVector<CSSPropertyValue,256> & properties) const3052 bool WebkitMaskRepeat::ParseShorthand(
3053     bool important,
3054     CSSParserTokenRange& range,
3055     const CSSParserContext& context,
3056     const CSSParserLocalContext& local_context,
3057     HeapVector<CSSPropertyValue, 256>& properties) const {
3058   CSSValue* result_x = nullptr;
3059   CSSValue* result_y = nullptr;
3060   bool implicit = false;
3061   if (!css_parsing_utils::ConsumeRepeatStyle(range, result_x, result_y,
3062                                              implicit) ||
3063       !range.AtEnd())
3064     return false;
3065 
3066   css_property_parser_helpers::AddProperty(
3067       CSSPropertyID::kWebkitMaskRepeatX, CSSPropertyID::kWebkitMaskRepeat,
3068       *result_x, important,
3069       implicit ? css_property_parser_helpers::IsImplicitProperty::kImplicit
3070                : css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
3071       properties);
3072   css_property_parser_helpers::AddProperty(
3073       CSSPropertyID::kWebkitMaskRepeatY, CSSPropertyID::kWebkitMaskRepeat,
3074       *result_y, important,
3075       implicit ? css_property_parser_helpers::IsImplicitProperty::kImplicit
3076                : css_property_parser_helpers::IsImplicitProperty::kNotImplicit,
3077       properties);
3078 
3079   return true;
3080 }
3081 
CSSValueFromComputedStyleInternal(const ComputedStyle & style,const SVGComputedStyle &,const LayoutObject *,bool allow_visited_style) const3082 const CSSValue* WebkitMaskRepeat::CSSValueFromComputedStyleInternal(
3083     const ComputedStyle& style,
3084     const SVGComputedStyle&,
3085     const LayoutObject*,
3086     bool allow_visited_style) const {
3087   return ComputedStyleUtils::BackgroundRepeatOrWebkitMaskRepeat(
3088       &style.MaskLayers());
3089 }
3090 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const3091 bool WebkitTextEmphasis::ParseShorthand(
3092     bool important,
3093     CSSParserTokenRange& range,
3094     const CSSParserContext& context,
3095     const CSSParserLocalContext&,
3096     HeapVector<CSSPropertyValue, 256>& properties) const {
3097   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
3098       webkitTextEmphasisShorthand(), important, context, range, properties);
3099 }
3100 
ParseShorthand(bool important,CSSParserTokenRange & range,const CSSParserContext & context,const CSSParserLocalContext &,HeapVector<CSSPropertyValue,256> & properties) const3101 bool WebkitTextStroke::ParseShorthand(
3102     bool important,
3103     CSSParserTokenRange& range,
3104     const CSSParserContext& context,
3105     const CSSParserLocalContext&,
3106     HeapVector<CSSPropertyValue, 256>& properties) const {
3107   return css_property_parser_helpers::ConsumeShorthandGreedilyViaLonghands(
3108       webkitTextStrokeShorthand(), important, context, range, properties);
3109 }
3110 
3111 }  // namespace css_shorthand
3112 }  // namespace blink
3113