[css-grid] Store auto-repeat information in style
[WebKit-https.git] / Source / WebCore / css / CSSComputedStyleDeclaration.cpp
1 /*
2  * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3  * Copyright (C) 2004-2014 Apple Inc. All rights reserved.
4  * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5  * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6  * Copyright (C) 2011 Sencha, Inc. All rights reserved.
7  * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301  USA
23  */
24
25 #include "config.h"
26 #include "CSSComputedStyleDeclaration.h"
27
28 #include "AnimationController.h"
29 #include "BasicShapeFunctions.h"
30 #include "BasicShapes.h"
31 #include "CSSAnimationTriggerScrollValue.h"
32 #include "CSSAspectRatioValue.h"
33 #include "CSSBasicShapes.h"
34 #include "CSSBorderImage.h"
35 #include "CSSCustomPropertyValue.h"
36 #include "CSSFontFeatureValue.h"
37 #include "CSSFontValue.h"
38 #include "CSSFunctionValue.h"
39 #include "CSSLineBoxContainValue.h"
40 #include "CSSParser.h"
41 #include "CSSPrimitiveValue.h"
42 #include "CSSPrimitiveValueMappings.h"
43 #include "CSSPropertyNames.h"
44 #include "CSSReflectValue.h"
45 #include "CSSSelector.h"
46 #include "CSSShadowValue.h"
47 #include "CSSTimingFunctionValue.h"
48 #include "CSSValueList.h"
49 #include "CSSValuePool.h"
50 #include "ContentData.h"
51 #include "CounterContent.h"
52 #include "CursorList.h"
53 #include "Document.h"
54 #include "ExceptionCode.h"
55 #include "FontFeatureSettings.h"
56 #include "HTMLFrameOwnerElement.h"
57 #include "Pair.h"
58 #include "PseudoElement.h"
59 #include "Rect.h"
60 #include "RenderBlock.h"
61 #include "RenderBox.h"
62 #include "RenderStyle.h"
63 #include "SVGElement.h"
64 #include "StyleInheritedData.h"
65 #include "StyleProperties.h"
66 #include "StylePropertyShorthand.h"
67 #include "StyleResolver.h"
68 #include "WebKitCSSFilterValue.h"
69 #include "WebKitCSSTransformValue.h"
70 #include "WebKitFontFamilyNames.h"
71 #include "WillChangeData.h"
72 #include <wtf/NeverDestroyed.h>
73 #include <wtf/text/StringBuilder.h>
74
75 #if ENABLE(CSS_GRID_LAYOUT)
76 #include "CSSGridLineNamesValue.h"
77 #include "CSSGridTemplateAreasValue.h"
78 #include "RenderGrid.h"
79 #endif
80
81 #if ENABLE(CSS_SHAPES)
82 #include "ShapeValue.h"
83 #endif
84
85 #if ENABLE(DASHBOARD_SUPPORT)
86 #include "DashboardRegion.h"
87 #endif
88
89 #if ENABLE(CSS_SCROLL_SNAP)
90 #include "LengthRepeat.h"
91 #include "StyleScrollSnapPoints.h"
92 #endif
93
94 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
95 #include "AnimationTrigger.h"
96 #endif
97
98 namespace WebCore {
99
100 // List of all properties we know how to compute, omitting shorthands.
101 static const CSSPropertyID computedProperties[] = {
102     CSSPropertyAlt,
103     CSSPropertyAnimationDelay,
104     CSSPropertyAnimationDirection,
105     CSSPropertyAnimationDuration,
106     CSSPropertyAnimationFillMode,
107     CSSPropertyAnimationIterationCount,
108     CSSPropertyAnimationName,
109     CSSPropertyAnimationPlayState,
110     CSSPropertyAnimationTimingFunction,
111     CSSPropertyBackgroundAttachment,
112     CSSPropertyBackgroundBlendMode,
113     CSSPropertyBackgroundClip,
114     CSSPropertyBackgroundColor,
115     CSSPropertyBackgroundImage,
116     CSSPropertyBackgroundOrigin,
117     CSSPropertyBackgroundPosition, // more-specific background-position-x/y are non-standard
118     CSSPropertyBackgroundRepeat,
119     CSSPropertyBackgroundSize,
120     CSSPropertyBorderBottomColor,
121     CSSPropertyBorderBottomLeftRadius,
122     CSSPropertyBorderBottomRightRadius,
123     CSSPropertyBorderBottomStyle,
124     CSSPropertyBorderBottomWidth,
125     CSSPropertyBorderCollapse,
126     CSSPropertyBorderImageOutset,
127     CSSPropertyBorderImageRepeat,
128     CSSPropertyBorderImageSlice,
129     CSSPropertyBorderImageSource,
130     CSSPropertyBorderImageWidth,
131     CSSPropertyBorderLeftColor,
132     CSSPropertyBorderLeftStyle,
133     CSSPropertyBorderLeftWidth,
134     CSSPropertyBorderRightColor,
135     CSSPropertyBorderRightStyle,
136     CSSPropertyBorderRightWidth,
137     CSSPropertyBorderTopColor,
138     CSSPropertyBorderTopLeftRadius,
139     CSSPropertyBorderTopRightRadius,
140     CSSPropertyBorderTopStyle,
141     CSSPropertyBorderTopWidth,
142     CSSPropertyBottom,
143     CSSPropertyBoxShadow,
144     CSSPropertyBoxSizing,
145     CSSPropertyCaptionSide,
146     CSSPropertyClear,
147     CSSPropertyClip,
148     CSSPropertyColor,
149     CSSPropertyContent,
150     CSSPropertyCursor,
151     CSSPropertyDirection,
152     CSSPropertyDisplay,
153     CSSPropertyEmptyCells,
154     CSSPropertyFloat,
155     CSSPropertyFontFamily,
156     CSSPropertyFontSize,
157     CSSPropertyFontStyle,
158     CSSPropertyFontSynthesis,
159     CSSPropertyFontVariant,
160     CSSPropertyFontWeight,
161     CSSPropertyHeight,
162 #if ENABLE(CSS_IMAGE_ORIENTATION)
163     CSSPropertyImageOrientation,
164 #endif
165     CSSPropertyImageRendering,
166 #if ENABLE(CSS_IMAGE_RESOLUTION)
167     CSSPropertyImageResolution,
168 #endif
169     CSSPropertyLeft,
170     CSSPropertyLetterSpacing,
171     CSSPropertyLineHeight,
172     CSSPropertyListStyleImage,
173     CSSPropertyListStylePosition,
174     CSSPropertyListStyleType,
175     CSSPropertyMarginBottom,
176     CSSPropertyMarginLeft,
177     CSSPropertyMarginRight,
178     CSSPropertyMarginTop,
179     CSSPropertyMaxHeight,
180     CSSPropertyMaxWidth,
181     CSSPropertyMinHeight,
182     CSSPropertyMinWidth,
183     CSSPropertyOpacity,
184     CSSPropertyOrphans,
185     CSSPropertyOutlineColor,
186     CSSPropertyOutlineOffset,
187     CSSPropertyOutlineStyle,
188     CSSPropertyOutlineWidth,
189     CSSPropertyOverflowWrap,
190     CSSPropertyOverflowX,
191     CSSPropertyOverflowY,
192     CSSPropertyPaddingBottom,
193     CSSPropertyPaddingLeft,
194     CSSPropertyPaddingRight,
195     CSSPropertyPaddingTop,
196     CSSPropertyPageBreakAfter,
197     CSSPropertyPageBreakBefore,
198     CSSPropertyPageBreakInside,
199     CSSPropertyPointerEvents,
200     CSSPropertyPosition,
201     CSSPropertyResize,
202     CSSPropertyRight,
203     CSSPropertySpeak,
204     CSSPropertyTableLayout,
205     CSSPropertyTabSize,
206     CSSPropertyTextAlign,
207     CSSPropertyTextDecoration,
208 #if ENABLE(CSS3_TEXT)
209     CSSPropertyWebkitTextAlignLast,
210     CSSPropertyWebkitTextJustify,
211 #endif // CSS3_TEXT
212     CSSPropertyWebkitTextDecorationLine,
213     CSSPropertyWebkitTextDecorationStyle,
214     CSSPropertyWebkitTextDecorationColor,
215     CSSPropertyWebkitTextDecorationSkip,
216     CSSPropertyWebkitTextUnderlinePosition,
217     CSSPropertyTextIndent,
218     CSSPropertyTextRendering,
219     CSSPropertyTextShadow,
220     CSSPropertyTextOverflow,
221     CSSPropertyTextTransform,
222     CSSPropertyTop,
223     CSSPropertyTransform,
224     CSSPropertyTransformOrigin,
225     CSSPropertyTransformStyle,
226     CSSPropertyTransitionDelay,
227     CSSPropertyTransitionDuration,
228     CSSPropertyTransitionProperty,
229     CSSPropertyTransitionTimingFunction,
230     CSSPropertyUnicodeBidi,
231     CSSPropertyVerticalAlign,
232     CSSPropertyVisibility,
233     CSSPropertyWhiteSpace,
234     CSSPropertyWidows,
235     CSSPropertyWidth,
236     CSSPropertyWordBreak,
237     CSSPropertyWordSpacing,
238     CSSPropertyWordWrap,
239 #if ENABLE(CSS_SCROLL_SNAP)
240     CSSPropertyWebkitScrollSnapType,
241     CSSPropertyWebkitScrollSnapPointsX,
242     CSSPropertyWebkitScrollSnapPointsY,
243     CSSPropertyWebkitScrollSnapDestination,
244     CSSPropertyWebkitScrollSnapCoordinate,
245 #endif
246     CSSPropertyZIndex,
247     CSSPropertyZoom,
248     CSSPropertyWebkitAnimationDelay,
249     CSSPropertyWebkitAnimationDirection,
250     CSSPropertyWebkitAnimationDuration,
251     CSSPropertyWebkitAnimationFillMode,
252     CSSPropertyWebkitAnimationIterationCount,
253     CSSPropertyWebkitAnimationName,
254     CSSPropertyWebkitAnimationPlayState,
255     CSSPropertyWebkitAnimationTimingFunction,
256 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
257     CSSPropertyWebkitAnimationTrigger,
258 #endif
259     CSSPropertyWebkitAppearance,
260     CSSPropertyWebkitBackfaceVisibility,
261     CSSPropertyWebkitBackgroundClip,
262     CSSPropertyWebkitBackgroundComposite,
263     CSSPropertyWebkitBackgroundOrigin,
264     CSSPropertyWebkitBackgroundSize,
265 #if ENABLE(CSS_COMPOSITING)
266     CSSPropertyMixBlendMode,
267     CSSPropertyIsolation,
268 #endif
269     CSSPropertyWebkitBorderFit,
270     CSSPropertyWebkitBorderHorizontalSpacing,
271     CSSPropertyWebkitBorderImage,
272     CSSPropertyWebkitBorderVerticalSpacing,
273     CSSPropertyWebkitBoxAlign,
274 #if ENABLE(CSS_BOX_DECORATION_BREAK)
275     CSSPropertyWebkitBoxDecorationBreak,
276 #endif
277     CSSPropertyWebkitBoxDirection,
278     CSSPropertyWebkitBoxFlex,
279     CSSPropertyWebkitBoxFlexGroup,
280     CSSPropertyWebkitBoxLines,
281     CSSPropertyWebkitBoxOrdinalGroup,
282     CSSPropertyWebkitBoxOrient,
283     CSSPropertyWebkitBoxPack,
284     CSSPropertyWebkitBoxReflect,
285     CSSPropertyWebkitBoxShadow,
286     CSSPropertyWebkitClipPath,
287     CSSPropertyWebkitColumnBreakAfter,
288     CSSPropertyWebkitColumnBreakBefore,
289     CSSPropertyWebkitColumnBreakInside,
290     CSSPropertyWebkitColumnAxis,
291     CSSPropertyColumnCount,
292     CSSPropertyColumnFill,
293     CSSPropertyColumnGap,
294     CSSPropertyColumnProgression,
295     CSSPropertyColumnRuleColor,
296     CSSPropertyColumnRuleStyle,
297     CSSPropertyColumnRuleWidth,
298     CSSPropertyColumnSpan,
299     CSSPropertyColumnWidth,
300 #if ENABLE(CURSOR_VISIBILITY)
301     CSSPropertyWebkitCursorVisibility,
302 #endif
303 #if ENABLE(DASHBOARD_SUPPORT)
304     CSSPropertyWebkitDashboardRegion,
305 #endif
306     CSSPropertyAlignContent,
307     CSSPropertyAlignItems,
308     CSSPropertyAlignSelf,
309     CSSPropertyFilter,
310     CSSPropertyFlexBasis,
311     CSSPropertyFlexGrow,
312     CSSPropertyFlexShrink,
313     CSSPropertyFlexDirection,
314     CSSPropertyFlexWrap,
315     CSSPropertyJustifyContent,
316     CSSPropertyJustifySelf,
317     CSSPropertyJustifyItems,
318 #if ENABLE(FILTERS_LEVEL_2)
319     CSSPropertyWebkitBackdropFilter,
320 #endif
321     CSSPropertyWebkitFontKerning,
322     CSSPropertyWebkitFontSmoothing,
323     CSSPropertyFontVariantLigatures,
324     CSSPropertyFontVariantPosition,
325     CSSPropertyFontVariantCaps,
326     CSSPropertyFontVariantNumeric,
327     CSSPropertyFontVariantAlternates,
328     CSSPropertyFontVariantEastAsian,
329 #if ENABLE(CSS_GRID_LAYOUT)
330     CSSPropertyWebkitGridAutoColumns,
331     CSSPropertyWebkitGridAutoFlow,
332     CSSPropertyWebkitGridAutoRows,
333     CSSPropertyWebkitGridColumnEnd,
334     CSSPropertyWebkitGridColumnStart,
335     CSSPropertyWebkitGridTemplateAreas,
336     CSSPropertyWebkitGridTemplateColumns,
337     CSSPropertyWebkitGridTemplateRows,
338     CSSPropertyWebkitGridRowEnd,
339     CSSPropertyWebkitGridRowStart,
340     CSSPropertyWebkitGridColumnGap,
341     CSSPropertyWebkitGridRowGap,
342 #endif
343     CSSPropertyWebkitHyphenateCharacter,
344     CSSPropertyWebkitHyphenateLimitAfter,
345     CSSPropertyWebkitHyphenateLimitBefore,
346     CSSPropertyWebkitHyphenateLimitLines,
347     CSSPropertyWebkitHyphens,
348     CSSPropertyWebkitInitialLetter,
349     CSSPropertyWebkitLineAlign,
350     CSSPropertyWebkitLineBoxContain,
351     CSSPropertyWebkitLineBreak,
352     CSSPropertyWebkitLineClamp,
353     CSSPropertyWebkitLineGrid,
354     CSSPropertyWebkitLineSnap,
355     CSSPropertyWebkitLocale,
356     CSSPropertyWebkitMarginBeforeCollapse,
357     CSSPropertyWebkitMarginAfterCollapse,
358     CSSPropertyWebkitMarqueeDirection,
359     CSSPropertyWebkitMarqueeIncrement,
360     CSSPropertyWebkitMarqueeRepetition,
361     CSSPropertyWebkitMarqueeStyle,
362     CSSPropertyWebkitMaskBoxImage,
363     CSSPropertyWebkitMaskBoxImageOutset,
364     CSSPropertyWebkitMaskBoxImageRepeat,
365     CSSPropertyWebkitMaskBoxImageSlice,
366     CSSPropertyWebkitMaskBoxImageSource,
367     CSSPropertyWebkitMaskBoxImageWidth,
368     CSSPropertyWebkitMaskClip,
369     CSSPropertyWebkitMaskComposite,
370     CSSPropertyWebkitMaskImage,
371     CSSPropertyWebkitMaskOrigin,
372     CSSPropertyWebkitMaskPosition,
373     CSSPropertyWebkitMaskRepeat,
374     CSSPropertyWebkitMaskSize,
375     CSSPropertyWebkitMaskSourceType,
376     CSSPropertyWebkitNbspMode,
377     CSSPropertyOrder,
378 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
379     CSSPropertyWebkitOverflowScrolling,
380 #endif
381     CSSPropertyPerspective,
382     CSSPropertyPerspectiveOrigin,
383     CSSPropertyWebkitPrintColorAdjust,
384     CSSPropertyWebkitRtlOrdering,
385 #if PLATFORM(IOS)
386     CSSPropertyWebkitTouchCallout,
387 #endif
388 #if ENABLE(CSS_SHAPES)
389     CSSPropertyWebkitShapeOutside,
390 #endif
391 #if ENABLE(TOUCH_EVENTS)
392     CSSPropertyWebkitTapHighlightColor,
393 #endif
394     CSSPropertyWebkitTextCombine,
395     CSSPropertyWebkitTextDecorationsInEffect,
396     CSSPropertyWebkitTextEmphasisColor,
397     CSSPropertyWebkitTextEmphasisPosition,
398     CSSPropertyWebkitTextEmphasisStyle,
399     CSSPropertyWebkitTextFillColor,
400     CSSPropertyWebkitTextOrientation,
401     CSSPropertyWebkitTextSecurity,
402 #if ENABLE(IOS_TEXT_AUTOSIZING)
403     CSSPropertyWebkitTextSizeAdjust,
404 #endif
405     CSSPropertyWebkitTextStrokeColor,
406     CSSPropertyWebkitTextStrokeWidth,
407     CSSPropertyWebkitTextZoom,
408     CSSPropertyWebkitTransformStyle,
409     CSSPropertyWebkitTransitionDelay,
410     CSSPropertyWebkitTransitionDuration,
411     CSSPropertyWebkitTransitionProperty,
412     CSSPropertyWebkitTransitionTimingFunction,
413     CSSPropertyWebkitUserDrag,
414     CSSPropertyWebkitUserModify,
415     CSSPropertyWebkitUserSelect,
416     CSSPropertyWebkitWritingMode,
417 #if ENABLE(CSS_REGIONS)
418     CSSPropertyWebkitFlowInto,
419     CSSPropertyWebkitFlowFrom,
420     CSSPropertyWebkitRegionBreakAfter,
421     CSSPropertyWebkitRegionBreakBefore,
422     CSSPropertyWebkitRegionBreakInside,
423     CSSPropertyWebkitRegionFragment,
424 #endif
425 #if ENABLE(CSS_SHAPES)
426     CSSPropertyWebkitShapeMargin,
427     CSSPropertyWebkitShapeImageThreshold,
428 #endif
429     CSSPropertyBufferedRendering,
430     CSSPropertyClipPath,
431     CSSPropertyClipRule,
432     CSSPropertyCx,
433     CSSPropertyCy,
434     CSSPropertyMask,
435     CSSPropertyFilter,
436     CSSPropertyFloodColor,
437     CSSPropertyFloodOpacity,
438     CSSPropertyLightingColor,
439     CSSPropertyStopColor,
440     CSSPropertyStopOpacity,
441     CSSPropertyColorInterpolation,
442     CSSPropertyColorInterpolationFilters,
443     CSSPropertyColorRendering,
444     CSSPropertyFill,
445     CSSPropertyFillOpacity,
446     CSSPropertyFillRule,
447     CSSPropertyMarkerEnd,
448     CSSPropertyMarkerMid,
449     CSSPropertyMarkerStart,
450     CSSPropertyMaskType,
451     CSSPropertyPaintOrder,
452     CSSPropertyR,
453     CSSPropertyRx,
454     CSSPropertyRy,
455     CSSPropertyShapeRendering,
456     CSSPropertyStroke,
457     CSSPropertyStrokeDasharray,
458     CSSPropertyStrokeDashoffset,
459     CSSPropertyStrokeLinecap,
460     CSSPropertyStrokeLinejoin,
461     CSSPropertyStrokeMiterlimit,
462     CSSPropertyStrokeOpacity,
463     CSSPropertyStrokeWidth,
464     CSSPropertyAlignmentBaseline,
465     CSSPropertyBaselineShift,
466     CSSPropertyDominantBaseline,
467     CSSPropertyKerning,
468     CSSPropertyTextAnchor,
469     CSSPropertyWritingMode,
470     CSSPropertyGlyphOrientationHorizontal,
471     CSSPropertyGlyphOrientationVertical,
472     CSSPropertyWebkitSvgShadow,
473     CSSPropertyVectorEffect,
474     CSSPropertyX,
475     CSSPropertyY
476 };
477
478 const unsigned numComputedProperties = WTF_ARRAY_LENGTH(computedProperties);
479
480 static CSSValueID valueForRepeatRule(int rule)
481 {
482     switch (rule) {
483         case RepeatImageRule:
484             return CSSValueRepeat;
485         case RoundImageRule:
486             return CSSValueRound;
487         case SpaceImageRule:
488             return CSSValueSpace;
489         default:
490             return CSSValueStretch;
491     }
492 }
493
494 static Ref<CSSPrimitiveValue> valueForImageSliceSide(const Length& length)
495 {
496     // These values can be percentages, numbers, or while an animation of mixed types is in progress,
497     // a calculation that combines a percentage and a number.
498     if (length.isPercent())
499         return CSSValuePool::singleton().createValue(length.percent(), CSSPrimitiveValue::CSS_PERCENTAGE);
500     if (length.isFixed())
501         return CSSValuePool::singleton().createValue(length.value(), CSSPrimitiveValue::CSS_NUMBER);
502
503     // Calculating the actual length currently in use would require most of the code from RenderBoxModelObject::paintNinePieceImage.
504     // And even if we could do that, it's not clear if that's exactly what we'd want during animation.
505     // FIXME: For now, just return 0.
506     ASSERT(length.isCalculated());
507     return CSSValuePool::singleton().createValue(0, CSSPrimitiveValue::CSS_NUMBER);
508 }
509
510 static Ref<CSSBorderImageSliceValue> valueForNinePieceImageSlice(const NinePieceImage& image)
511 {
512     auto& slices = image.imageSlices();
513
514     RefPtr<CSSPrimitiveValue> top = valueForImageSliceSide(slices.top());
515
516     RefPtr<CSSPrimitiveValue> right;
517     RefPtr<CSSPrimitiveValue> bottom;
518     RefPtr<CSSPrimitiveValue> left;
519
520     if (slices.right() == slices.top() && slices.bottom() == slices.top() && slices.left() == slices.top()) {
521         right = top;
522         bottom = top;
523         left = top;
524     } else {
525         right = valueForImageSliceSide(slices.right());
526
527         if (slices.bottom() == slices.top() && slices.right() == slices.left()) {
528             bottom = top;
529             left = right;
530         } else {
531             bottom = valueForImageSliceSide(slices.bottom());
532
533             if (slices.left() == slices.right())
534                 left = right;
535             else
536                 left = valueForImageSliceSide(slices.left());
537         }
538     }
539
540     auto quad = Quad::create();
541     quad->setTop(top.release());
542     quad->setRight(right.release());
543     quad->setBottom(bottom.release());
544     quad->setLeft(left.release());
545
546     return CSSBorderImageSliceValue::create(CSSValuePool::singleton().createValue(WTFMove(quad)), image.fill());
547 }
548
549 static Ref<CSSPrimitiveValue> valueForNinePieceImageQuad(const LengthBox& box)
550 {
551     RefPtr<CSSPrimitiveValue> top;
552     RefPtr<CSSPrimitiveValue> right;
553     RefPtr<CSSPrimitiveValue> bottom;
554     RefPtr<CSSPrimitiveValue> left;
555
556     auto& cssValuePool = CSSValuePool::singleton();
557
558     if (box.top().isRelative())
559         top = cssValuePool.createValue(box.top().value(), CSSPrimitiveValue::CSS_NUMBER);
560     else
561         top = cssValuePool.createValue(box.top());
562
563     if (box.right() == box.top() && box.bottom() == box.top() && box.left() == box.top()) {
564         right = top;
565         bottom = top;
566         left = top;
567     } else {
568         if (box.right().isRelative())
569             right = cssValuePool.createValue(box.right().value(), CSSPrimitiveValue::CSS_NUMBER);
570         else
571             right = cssValuePool.createValue(box.right());
572
573         if (box.bottom() == box.top() && box.right() == box.left()) {
574             bottom = top;
575             left = right;
576         } else {
577             if (box.bottom().isRelative())
578                 bottom = cssValuePool.createValue(box.bottom().value(), CSSPrimitiveValue::CSS_NUMBER);
579             else
580                 bottom = cssValuePool.createValue(box.bottom());
581
582             if (box.left() == box.right())
583                 left = right;
584             else {
585                 if (box.left().isRelative())
586                     left = cssValuePool.createValue(box.left().value(), CSSPrimitiveValue::CSS_NUMBER);
587                 else
588                     left = cssValuePool.createValue(box.left());
589             }
590         }
591     }
592
593     auto quad = Quad::create();
594     quad->setTop(top);
595     quad->setRight(right);
596     quad->setBottom(bottom);
597     quad->setLeft(left);
598
599     return cssValuePool.createValue(WTFMove(quad));
600 }
601
602 static Ref<CSSValue> valueForNinePieceImageRepeat(const NinePieceImage& image)
603 {
604     auto& cssValuePool = CSSValuePool::singleton();
605     RefPtr<CSSPrimitiveValue> horizontalRepeat = cssValuePool.createIdentifierValue(valueForRepeatRule(image.horizontalRule()));
606
607     RefPtr<CSSPrimitiveValue> verticalRepeat;
608     if (image.horizontalRule() == image.verticalRule())
609         verticalRepeat = horizontalRepeat;
610     else
611         verticalRepeat = cssValuePool.createIdentifierValue(valueForRepeatRule(image.verticalRule()));
612     return cssValuePool.createValue(Pair::create(horizontalRepeat.release(), verticalRepeat.release()));
613 }
614
615 static Ref<CSSValue> valueForNinePieceImage(const NinePieceImage& image)
616 {
617     if (!image.hasImage())
618         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
619
620     // Image first.
621     RefPtr<CSSValue> imageValue;
622     if (image.image())
623         imageValue = image.image()->cssValue();
624
625     // Create the image slice.
626     RefPtr<CSSBorderImageSliceValue> imageSlices = valueForNinePieceImageSlice(image);
627
628     // Create the border area slices.
629     RefPtr<CSSValue> borderSlices = valueForNinePieceImageQuad(image.borderSlices());
630
631     // Create the border outset.
632     RefPtr<CSSValue> outset = valueForNinePieceImageQuad(image.outset());
633
634     // Create the repeat rules.
635     RefPtr<CSSValue> repeat = valueForNinePieceImageRepeat(image);
636
637     return createBorderImageValue(imageValue.release(), imageSlices.release(), borderSlices.release(), outset.release(), repeat.release());
638 }
639
640 inline static Ref<CSSPrimitiveValue> zoomAdjustedPixelValue(double value, const RenderStyle& style)
641 {
642     return CSSValuePool::singleton().createValue(adjustFloatForAbsoluteZoom(value, style), CSSPrimitiveValue::CSS_PX);
643 }
644
645 inline static Ref<CSSPrimitiveValue> zoomAdjustedNumberValue(double value, const RenderStyle& style)
646 {
647     return CSSValuePool::singleton().createValue(value / style.effectiveZoom(), CSSPrimitiveValue::CSS_NUMBER);
648 }
649
650 static Ref<CSSValue> zoomAdjustedPixelValueForLength(const Length& length, const RenderStyle& style)
651 {
652     if (length.isFixed())
653         return zoomAdjustedPixelValue(length.value(), style);
654     return CSSValuePool::singleton().createValue(length, style);
655 }
656
657 static Ref<CSSValue> valueForReflection(const StyleReflection* reflection, const RenderStyle& style)
658 {
659     if (!reflection)
660         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
661
662     RefPtr<CSSPrimitiveValue> offset;
663     if (reflection->offset().isPercentOrCalculated())
664         offset = CSSValuePool::singleton().createValue(reflection->offset().percent(), CSSPrimitiveValue::CSS_PERCENTAGE);
665     else
666         offset = zoomAdjustedPixelValue(reflection->offset().value(), style);
667
668     RefPtr<CSSPrimitiveValue> direction;
669     switch (reflection->direction()) {
670     case ReflectionBelow:
671         direction = CSSValuePool::singleton().createIdentifierValue(CSSValueBelow);
672         break;
673     case ReflectionAbove:
674         direction = CSSValuePool::singleton().createIdentifierValue(CSSValueAbove);
675         break;
676     case ReflectionLeft:
677         direction = CSSValuePool::singleton().createIdentifierValue(CSSValueLeft);
678         break;
679     case ReflectionRight:
680         direction = CSSValuePool::singleton().createIdentifierValue(CSSValueRight);
681         break;
682     }
683
684     return CSSReflectValue::create(direction.release(), offset.release(), valueForNinePieceImage(reflection->mask()));
685 }
686
687 static Ref<CSSValueList> createPositionListForLayer(CSSPropertyID propertyID, const FillLayer* layer, const RenderStyle& style)
688 {
689     auto positionList = CSSValueList::createSpaceSeparated();
690     if (layer->isBackgroundOriginSet()) {
691         ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPosition || propertyID == CSSPropertyWebkitMaskPosition);
692         positionList.get().append(CSSValuePool::singleton().createValue(layer->backgroundXOrigin()));
693     }
694     positionList.get().append(zoomAdjustedPixelValueForLength(layer->xPosition(), style));
695     if (layer->isBackgroundOriginSet()) {
696         ASSERT(propertyID == CSSPropertyBackgroundPosition || propertyID == CSSPropertyWebkitMaskPosition);
697         positionList.get().append(CSSValuePool::singleton().createValue(layer->backgroundYOrigin()));
698     }
699     positionList.get().append(zoomAdjustedPixelValueForLength(layer->yPosition(), style));
700     return positionList;
701 }
702
703 static RefPtr<CSSValue> positionOffsetValue(const RenderStyle& style, CSSPropertyID propertyID)
704 {
705     Length length;
706     switch (propertyID) {
707         case CSSPropertyLeft:
708             length = style.left();
709             break;
710         case CSSPropertyRight:
711             length = style.right();
712             break;
713         case CSSPropertyTop:
714             length = style.top();
715             break;
716         case CSSPropertyBottom:
717             length = style.bottom();
718             break;
719         default:
720             return nullptr;
721     }
722
723     if (style.hasOutOfFlowPosition()) {
724         if (length.isFixed())
725             return zoomAdjustedPixelValue(length.value(), style);
726
727         return CSSValuePool::singleton().createValue(length);
728     }
729
730     if (style.hasInFlowPosition()) {
731         // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined.
732         // In other words if left is auto and right is not auto, then left's computed value is negative right().
733         // So we should get the opposite length unit and see if it is auto.
734         return CSSValuePool::singleton().createValue(length);
735     }
736
737     return CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
738 }
739
740 RefPtr<CSSPrimitiveValue> ComputedStyleExtractor::currentColorOrValidColor(const RenderStyle* style, const Color& color) const
741 {
742     // This function does NOT look at visited information, so that computed style doesn't expose that.
743     if (!color.isValid())
744         return CSSValuePool::singleton().createColorValue(style->color().rgb());
745     return CSSValuePool::singleton().createColorValue(color.rgb());
746 }
747
748 static Ref<CSSPrimitiveValue> percentageOrZoomAdjustedValue(Length length, const RenderStyle& style)
749 {
750     if (length.isPercent())
751         return CSSValuePool::singleton().createValue(length.percent(), CSSPrimitiveValue::CSS_PERCENTAGE);
752     
753     return zoomAdjustedPixelValue(valueForLength(length, 0), style);
754 }
755
756 static Ref<CSSPrimitiveValue> autoOrZoomAdjustedValue(Length length, const RenderStyle& style)
757 {
758     if (length.isAuto())
759         return CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
760
761     return zoomAdjustedPixelValue(valueForLength(length, 0), style);
762 }
763
764 static Ref<CSSValueList> getBorderRadiusCornerValues(const LengthSize& radius, const RenderStyle& style)
765 {
766     auto list = CSSValueList::createSpaceSeparated();
767     list.get().append(percentageOrZoomAdjustedValue(radius.width(), style));
768     list.get().append(percentageOrZoomAdjustedValue(radius.height(), style));
769     return list;
770 }
771
772 static Ref<CSSValue> getBorderRadiusCornerValue(const LengthSize& radius, const RenderStyle& style)
773 {
774     if (radius.width() == radius.height())
775         return percentageOrZoomAdjustedValue(radius.width(), style);
776
777     return getBorderRadiusCornerValues(radius, style);
778 }
779
780 static Ref<CSSValueList> getBorderRadiusShorthandValue(const RenderStyle& style)
781 {
782     auto list = CSSValueList::createSlashSeparated();
783     bool showHorizontalBottomLeft = style.borderTopRightRadius().width() != style.borderBottomLeftRadius().width();
784     bool showHorizontalBottomRight = showHorizontalBottomLeft || (style.borderBottomRightRadius().width() != style.borderTopLeftRadius().width());
785     bool showHorizontalTopRight = showHorizontalBottomRight || (style.borderTopRightRadius().width() != style.borderTopLeftRadius().width());
786
787     bool showVerticalBottomLeft = style.borderTopRightRadius().height() != style.borderBottomLeftRadius().height();
788     bool showVerticalBottomRight = showVerticalBottomLeft || (style.borderBottomRightRadius().height() != style.borderTopLeftRadius().height());
789     bool showVerticalTopRight = showVerticalBottomRight || (style.borderTopRightRadius().height() != style.borderTopLeftRadius().height());
790
791     RefPtr<CSSValueList> topLeftRadius = getBorderRadiusCornerValues(style.borderTopLeftRadius(), style);
792     RefPtr<CSSValueList> topRightRadius = getBorderRadiusCornerValues(style.borderTopRightRadius(), style);
793     RefPtr<CSSValueList> bottomRightRadius = getBorderRadiusCornerValues(style.borderBottomRightRadius(), style);
794     RefPtr<CSSValueList> bottomLeftRadius = getBorderRadiusCornerValues(style.borderBottomLeftRadius(), style);
795
796     RefPtr<CSSValueList> horizontalRadii = CSSValueList::createSpaceSeparated();
797     horizontalRadii->append(*topLeftRadius->item(0));
798     if (showHorizontalTopRight)
799         horizontalRadii->append(*topRightRadius->item(0));
800     if (showHorizontalBottomRight)
801         horizontalRadii->append(*bottomRightRadius->item(0));
802     if (showHorizontalBottomLeft)
803         horizontalRadii->append(*bottomLeftRadius->item(0));
804
805     list.get().append(horizontalRadii.releaseNonNull());
806
807     RefPtr<CSSValueList> verticalRadiiList = CSSValueList::createSpaceSeparated();
808     verticalRadiiList->append(*topLeftRadius->item(1));
809     if (showVerticalTopRight)
810         verticalRadiiList->append(*topRightRadius->item(1));
811     if (showVerticalBottomRight)
812         verticalRadiiList->append(*bottomRightRadius->item(1));
813     if (showVerticalBottomLeft)
814         verticalRadiiList->append(*bottomLeftRadius->item(1));
815
816     if (!verticalRadiiList->equals(downcast<CSSValueList>(*list.get().item(0))))
817         list.get().append(verticalRadiiList.releaseNonNull());
818
819     return list;
820 }
821
822 static LayoutRect sizingBox(RenderObject& renderer)
823 {
824     if (!is<RenderBox>(renderer))
825         return LayoutRect();
826
827     auto& box = downcast<RenderBox>(renderer);
828     return box.style().boxSizing() == BORDER_BOX ? box.borderBoxRect() : box.computedCSSContentBoxRect();
829 }
830
831 static Ref<WebKitCSSTransformValue> matrixTransformValue(const TransformationMatrix& transform, const RenderStyle& style)
832 {
833     RefPtr<WebKitCSSTransformValue> transformValue;
834     auto& cssValuePool = CSSValuePool::singleton();
835     if (transform.isAffine()) {
836         transformValue = WebKitCSSTransformValue::create(WebKitCSSTransformValue::MatrixTransformOperation);
837
838         transformValue->append(cssValuePool.createValue(transform.a(), CSSPrimitiveValue::CSS_NUMBER));
839         transformValue->append(cssValuePool.createValue(transform.b(), CSSPrimitiveValue::CSS_NUMBER));
840         transformValue->append(cssValuePool.createValue(transform.c(), CSSPrimitiveValue::CSS_NUMBER));
841         transformValue->append(cssValuePool.createValue(transform.d(), CSSPrimitiveValue::CSS_NUMBER));
842         transformValue->append(zoomAdjustedNumberValue(transform.e(), style));
843         transformValue->append(zoomAdjustedNumberValue(transform.f(), style));
844     } else {
845         transformValue = WebKitCSSTransformValue::create(WebKitCSSTransformValue::Matrix3DTransformOperation);
846
847         transformValue->append(cssValuePool.createValue(transform.m11(), CSSPrimitiveValue::CSS_NUMBER));
848         transformValue->append(cssValuePool.createValue(transform.m12(), CSSPrimitiveValue::CSS_NUMBER));
849         transformValue->append(cssValuePool.createValue(transform.m13(), CSSPrimitiveValue::CSS_NUMBER));
850         transformValue->append(cssValuePool.createValue(transform.m14(), CSSPrimitiveValue::CSS_NUMBER));
851
852         transformValue->append(cssValuePool.createValue(transform.m21(), CSSPrimitiveValue::CSS_NUMBER));
853         transformValue->append(cssValuePool.createValue(transform.m22(), CSSPrimitiveValue::CSS_NUMBER));
854         transformValue->append(cssValuePool.createValue(transform.m23(), CSSPrimitiveValue::CSS_NUMBER));
855         transformValue->append(cssValuePool.createValue(transform.m24(), CSSPrimitiveValue::CSS_NUMBER));
856
857         transformValue->append(cssValuePool.createValue(transform.m31(), CSSPrimitiveValue::CSS_NUMBER));
858         transformValue->append(cssValuePool.createValue(transform.m32(), CSSPrimitiveValue::CSS_NUMBER));
859         transformValue->append(cssValuePool.createValue(transform.m33(), CSSPrimitiveValue::CSS_NUMBER));
860         transformValue->append(cssValuePool.createValue(transform.m34(), CSSPrimitiveValue::CSS_NUMBER));
861
862         transformValue->append(zoomAdjustedNumberValue(transform.m41(), style));
863         transformValue->append(zoomAdjustedNumberValue(transform.m42(), style));
864         transformValue->append(zoomAdjustedNumberValue(transform.m43(), style));
865         transformValue->append(cssValuePool.createValue(transform.m44(), CSSPrimitiveValue::CSS_NUMBER));
866     }
867
868     return transformValue.releaseNonNull();
869 }
870
871 static Ref<CSSValue> computedTransform(RenderObject* renderer, const RenderStyle& style)
872 {
873     if (!renderer || !renderer->hasTransform())
874         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
875
876     FloatRect pixelSnappedRect;
877     if (is<RenderBox>(*renderer))
878         pixelSnappedRect = snapRectToDevicePixels(downcast<RenderBox>(*renderer).borderBoxRect(), renderer->document().deviceScaleFactor());
879
880     TransformationMatrix transform;
881     style.applyTransform(transform, pixelSnappedRect, RenderStyle::ExcludeTransformOrigin);
882     // Note that this does not flatten to an affine transform if ENABLE(3D_TRANSFORMS) is off, by design.
883
884     // FIXME: Need to print out individual functions (https://bugs.webkit.org/show_bug.cgi?id=23924)
885     auto list = CSSValueList::createSpaceSeparated();
886     list.get().append(matrixTransformValue(transform, style));
887     return WTFMove(list);
888 }
889
890 static inline Ref<CSSPrimitiveValue> adjustLengthForZoom(double length, const RenderStyle& style, AdjustPixelValuesForComputedStyle adjust)
891 {
892     return adjust == AdjustPixelValues ? zoomAdjustedPixelValue(length, style) : CSSValuePool::singleton().createValue(length, CSSPrimitiveValue::CSS_PX);
893 }
894
895 static inline Ref<CSSPrimitiveValue> adjustLengthForZoom(const Length& length, const RenderStyle& style, AdjustPixelValuesForComputedStyle adjust)
896 {
897     return adjust == AdjustPixelValues ? zoomAdjustedPixelValue(length.value(), style) : CSSValuePool::singleton().createValue(length);
898 }
899
900 Ref<CSSValue> ComputedStyleExtractor::valueForShadow(const ShadowData* shadow, CSSPropertyID propertyID, const RenderStyle& style, AdjustPixelValuesForComputedStyle adjust)
901 {
902     auto& cssValuePool = CSSValuePool::singleton();
903     if (!shadow)
904         return cssValuePool.createIdentifierValue(CSSValueNone);
905
906     auto list = CSSValueList::createCommaSeparated();
907     for (const ShadowData* currShadowData = shadow; currShadowData; currShadowData = currShadowData->next()) {
908         RefPtr<CSSPrimitiveValue> x = adjustLengthForZoom(currShadowData->x(), style, adjust);
909         RefPtr<CSSPrimitiveValue> y = adjustLengthForZoom(currShadowData->y(), style, adjust);
910         RefPtr<CSSPrimitiveValue> blur = adjustLengthForZoom(currShadowData->radius(), style, adjust);
911         RefPtr<CSSPrimitiveValue> spread = propertyID == CSSPropertyTextShadow ? PassRefPtr<CSSPrimitiveValue>() : adjustLengthForZoom(currShadowData->spread(), style, adjust);
912         RefPtr<CSSPrimitiveValue> style = propertyID == CSSPropertyTextShadow || currShadowData->style() == Normal ? PassRefPtr<CSSPrimitiveValue>() : cssValuePool.createIdentifierValue(CSSValueInset);
913         RefPtr<CSSPrimitiveValue> color = cssValuePool.createColorValue(currShadowData->color().rgb());
914         list.get().prepend(CSSShadowValue::create(x.release(), y.release(), blur.release(), spread.release(), style.release(), color.release()));
915     }
916     return WTFMove(list);
917 }
918
919 Ref<CSSValue> ComputedStyleExtractor::valueForFilter(const RenderStyle& style, const FilterOperations& filterOperations, AdjustPixelValuesForComputedStyle adjust)
920 {
921     auto& cssValuePool = CSSValuePool::singleton();
922     if (filterOperations.operations().isEmpty())
923         return cssValuePool.createIdentifierValue(CSSValueNone);
924
925     auto list = CSSValueList::createSpaceSeparated();
926
927     RefPtr<WebKitCSSFilterValue> filterValue;
928
929     Vector<RefPtr<FilterOperation>>::const_iterator end = filterOperations.operations().end();
930     for (Vector<RefPtr<FilterOperation>>::const_iterator it = filterOperations.operations().begin(); it != end; ++it) {
931         FilterOperation& filterOperation = **it;
932         switch (filterOperation.type()) {
933         case FilterOperation::REFERENCE: {
934             ReferenceFilterOperation& referenceOperation = downcast<ReferenceFilterOperation>(filterOperation);
935             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::ReferenceFilterOperation);
936             filterValue->append(cssValuePool.createValue(referenceOperation.url(), CSSPrimitiveValue::CSS_URI));
937             break;
938         }
939         case FilterOperation::GRAYSCALE: {
940             BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
941             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::GrayscaleFilterOperation);
942             filterValue->append(cssValuePool.createValue(colorMatrixOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
943             break;
944         }
945         case FilterOperation::SEPIA: {
946             BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
947             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::SepiaFilterOperation);
948             filterValue->append(cssValuePool.createValue(colorMatrixOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
949             break;
950         }
951         case FilterOperation::SATURATE: {
952             BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
953             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::SaturateFilterOperation);
954             filterValue->append(cssValuePool.createValue(colorMatrixOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
955             break;
956         }
957         case FilterOperation::HUE_ROTATE: {
958             BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
959             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::HueRotateFilterOperation);
960             filterValue->append(cssValuePool.createValue(colorMatrixOperation.amount(), CSSPrimitiveValue::CSS_DEG));
961             break;
962         }
963         case FilterOperation::INVERT: {
964             BasicComponentTransferFilterOperation& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
965             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::InvertFilterOperation);
966             filterValue->append(cssValuePool.createValue(componentTransferOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
967             break;
968         }
969         case FilterOperation::OPACITY: {
970             BasicComponentTransferFilterOperation& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
971             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::OpacityFilterOperation);
972             filterValue->append(cssValuePool.createValue(componentTransferOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
973             break;
974         }
975         case FilterOperation::BRIGHTNESS: {
976             BasicComponentTransferFilterOperation& brightnessOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
977             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::BrightnessFilterOperation);
978             filterValue->append(cssValuePool.createValue(brightnessOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
979             break;
980         }
981         case FilterOperation::CONTRAST: {
982             BasicComponentTransferFilterOperation& contrastOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
983             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::ContrastFilterOperation);
984             filterValue->append(cssValuePool.createValue(contrastOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
985             break;
986         }
987         case FilterOperation::BLUR: {
988             BlurFilterOperation& blurOperation = downcast<BlurFilterOperation>(filterOperation);
989             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::BlurFilterOperation);
990             filterValue->append(adjustLengthForZoom(blurOperation.stdDeviation(), style, adjust));
991             break;
992         }
993         case FilterOperation::DROP_SHADOW: {
994             DropShadowFilterOperation& dropShadowOperation = downcast<DropShadowFilterOperation>(filterOperation);
995             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::DropShadowFilterOperation);
996             // We want our computed style to look like that of a text shadow (has neither spread nor inset style).
997             ShadowData shadowData = ShadowData(dropShadowOperation.location(), dropShadowOperation.stdDeviation(), 0, Normal, false, dropShadowOperation.color());
998             filterValue->append(valueForShadow(&shadowData, CSSPropertyTextShadow, style, adjust));
999             break;
1000         }
1001         default:
1002             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::UnknownFilterOperation);
1003             break;
1004         }
1005         list.get().append(filterValue.releaseNonNull());
1006     }
1007
1008     return WTFMove(list);
1009 }
1010
1011 #if ENABLE(CSS_GRID_LAYOUT)
1012 static Ref<CSSValue> specifiedValueForGridTrackBreadth(const GridLength& trackBreadth, const RenderStyle& style)
1013 {
1014     if (!trackBreadth.isLength())
1015         return CSSValuePool::singleton().createValue(trackBreadth.flex(), CSSPrimitiveValue::CSS_FR);
1016
1017     const Length& trackBreadthLength = trackBreadth.length();
1018     if (trackBreadthLength.isAuto())
1019         return CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
1020     return zoomAdjustedPixelValueForLength(trackBreadthLength, style);
1021 }
1022
1023 static Ref<CSSValue> specifiedValueForGridTrackSize(const GridTrackSize& trackSize, const RenderStyle& style)
1024 {
1025     switch (trackSize.type()) {
1026     case LengthTrackSizing:
1027         return specifiedValueForGridTrackBreadth(trackSize.length(), style);
1028     default:
1029         ASSERT(trackSize.type() == MinMaxTrackSizing);
1030         RefPtr<CSSValueList> minMaxTrackBreadths = CSSValueList::createCommaSeparated();
1031         minMaxTrackBreadths->append(specifiedValueForGridTrackBreadth(trackSize.minTrackBreadth(), style));
1032         minMaxTrackBreadths->append(specifiedValueForGridTrackBreadth(trackSize.maxTrackBreadth(), style));
1033         return CSSFunctionValue::create("minmax(", minMaxTrackBreadths);
1034     }
1035 }
1036
1037 static void addValuesForNamedGridLinesAtIndex(const OrderedNamedGridLinesMap& orderedNamedGridLines, size_t i, CSSValueList& list)
1038 {
1039     const Vector<String>& namedGridLines = orderedNamedGridLines.get(i);
1040     if (namedGridLines.isEmpty())
1041         return;
1042
1043     auto& cssValuePool = CSSValuePool::singleton();
1044     RefPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue::create();
1045     for (auto& name : namedGridLines)
1046         lineNames->append(cssValuePool.createValue(name, CSSPrimitiveValue::CSS_STRING));
1047     list.append(lineNames.releaseNonNull());
1048 }
1049
1050 static Ref<CSSValue> valueForGridTrackList(GridTrackSizingDirection direction, RenderObject* renderer, const RenderStyle& style)
1051 {
1052     bool isRowAxis = direction == ForColumns;
1053     bool isRenderGrid = is<RenderGrid>(renderer);
1054     auto& trackSizes = isRowAxis ? style.gridColumns() : style.gridRows();
1055     auto& autoRepeatTrackSizes = isRowAxis ? style.gridAutoRepeatColumns() : style.gridAutoRepeatRows();
1056     auto& orderedNamedGridLines = isRowAxis ? style.orderedNamedGridColumnLines() : style.orderedNamedGridRowLines();
1057
1058     // Handle the 'none' case.
1059     bool trackListIsEmpty = trackSizes.isEmpty() && autoRepeatTrackSizes.isEmpty();
1060     if (isRenderGrid && trackListIsEmpty) {
1061         // For grids we should consider every listed track, whether implicitly or explicitly created. If we don't have
1062         // any explicit track and there are no children then there are no implicit tracks. We cannot simply check the
1063         // number of rows/columns in our internal grid representation because it's always at least 1x1 (see r143331).
1064         trackListIsEmpty = !downcast<RenderBlock>(*renderer).firstChild();
1065     }
1066
1067     if (trackListIsEmpty) {
1068         ASSERT(orderedNamedGridLines.isEmpty());
1069         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
1070     }
1071
1072     auto list = CSSValueList::createSpaceSeparated();
1073     unsigned insertionIndex;
1074     if (isRenderGrid) {
1075         auto& grid = downcast<RenderGrid>(*renderer);
1076         const auto& trackPositions = direction == ForColumns ? grid.columnPositions() : grid.rowPositions();
1077         // There are at least #tracks + 1 grid lines (trackPositions). Apart from that, the grid container can generate implicit grid tracks,
1078         // so we'll have more trackPositions than trackSizes as the latter only contain the explicit grid.
1079         ASSERT(trackPositions.size() - 1 >= trackSizes.size());
1080
1081         unsigned i = 0;
1082         LayoutUnit gutterSize = grid.guttersSize(direction, 2);
1083         LayoutUnit offsetBetweenTracks = grid.offsetBetweenTracks(direction);
1084         for (; i < trackPositions.size() - 2; ++i) {
1085             addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, i, list.get());
1086             list.get().append(zoomAdjustedPixelValue(trackPositions[i + 1] - trackPositions[i] - gutterSize - offsetBetweenTracks, style));
1087         }
1088         // Last track line does not have any gutter or distribution offset.
1089         addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, i, list.get());
1090         list.get().append(zoomAdjustedPixelValue(trackPositions[i + 1] - trackPositions[i], style));
1091         insertionIndex = trackPositions.size() - 1;
1092     } else {
1093         for (unsigned i = 0; i < trackSizes.size(); ++i) {
1094             addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, i, list.get());
1095             list.get().append(specifiedValueForGridTrackSize(trackSizes[i], style));
1096         }
1097         insertionIndex = trackSizes.size();
1098     }
1099
1100     // Those are the trailing <ident>* allowed in the syntax.
1101     addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, insertionIndex, list.get());
1102     return WTFMove(list);
1103 }
1104
1105 static Ref<CSSValue> valueForGridPosition(const GridPosition& position)
1106 {
1107     auto& cssValuePool = CSSValuePool::singleton();
1108     if (position.isAuto())
1109         return cssValuePool.createIdentifierValue(CSSValueAuto);
1110
1111     if (position.isNamedGridArea())
1112         return cssValuePool.createValue(position.namedGridLine(), CSSPrimitiveValue::CSS_STRING);
1113
1114     auto list = CSSValueList::createSpaceSeparated();
1115     if (position.isSpan()) {
1116         list.get().append(cssValuePool.createIdentifierValue(CSSValueSpan));
1117         list.get().append(cssValuePool.createValue(position.spanPosition(), CSSPrimitiveValue::CSS_NUMBER));
1118     } else
1119         list.get().append(cssValuePool.createValue(position.integerPosition(), CSSPrimitiveValue::CSS_NUMBER));
1120
1121     if (!position.namedGridLine().isNull())
1122         list.get().append(cssValuePool.createValue(position.namedGridLine(), CSSPrimitiveValue::CSS_STRING));
1123     return WTFMove(list);
1124 }
1125 #endif
1126
1127 static Ref<CSSValue> createTransitionPropertyValue(const Animation& animation)
1128 {
1129     if (animation.animationMode() == Animation::AnimateNone)
1130         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
1131     if (animation.animationMode() == Animation::AnimateAll)
1132         return CSSValuePool::singleton().createIdentifierValue(CSSValueAll);
1133     return CSSValuePool::singleton().createValue(getPropertyNameString(animation.property()), CSSPrimitiveValue::CSS_STRING);
1134 }
1135
1136 static Ref<CSSValueList> getTransitionPropertyValue(const AnimationList* animList)
1137 {
1138     auto list = CSSValueList::createCommaSeparated();
1139     if (animList) {
1140         for (size_t i = 0; i < animList->size(); ++i)
1141             list.get().append(createTransitionPropertyValue(animList->animation(i)));
1142     } else
1143         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueAll));
1144     return list;
1145 }
1146
1147 #if ENABLE(CSS_SCROLL_SNAP)
1148 static Ref<CSSValueList> scrollSnapDestination(const RenderStyle& style, const LengthSize& destination)
1149 {
1150     auto list = CSSValueList::createSpaceSeparated();
1151     list.get().append(zoomAdjustedPixelValueForLength(destination.width(), style));
1152     list.get().append(zoomAdjustedPixelValueForLength(destination.height(), style));
1153     return list;
1154 }
1155
1156 static Ref<CSSValue> scrollSnapPoints(const RenderStyle& style, const ScrollSnapPoints* points)
1157 {
1158     if (!points)
1159         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
1160
1161     if (points->usesElements)
1162         return CSSValuePool::singleton().createIdentifierValue(CSSValueElements);
1163     auto list = CSSValueList::createSpaceSeparated();
1164     for (auto& point : points->offsets)
1165         list.get().append(zoomAdjustedPixelValueForLength(point, style));
1166     if (points->hasRepeat)
1167         list.get().append(CSSValuePool::singleton().createValue(LengthRepeat::create(zoomAdjustedPixelValueForLength(points->repeatOffset, style))));
1168     return WTFMove(list);
1169 }
1170
1171 static Ref<CSSValue> scrollSnapCoordinates(const RenderStyle& style, const Vector<LengthSize>& coordinates)
1172 {
1173     if (coordinates.isEmpty())
1174         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
1175
1176     auto list = CSSValueList::createCommaSeparated();
1177
1178     for (auto& coordinate : coordinates) {
1179         auto pair = CSSValueList::createSpaceSeparated();
1180         pair.get().append(zoomAdjustedPixelValueForLength(coordinate.width(), style));
1181         pair.get().append(zoomAdjustedPixelValueForLength(coordinate.height(), style));
1182         list.get().append(WTFMove(pair));
1183     }
1184
1185     return WTFMove(list);
1186 }
1187 #endif
1188
1189 static Ref<CSSValue> getWillChangePropertyValue(const WillChangeData* willChangeData)
1190 {
1191     auto& cssValuePool = CSSValuePool::singleton();
1192     if (!willChangeData || !willChangeData->numFeatures())
1193         return cssValuePool.createIdentifierValue(CSSValueAuto);
1194
1195     auto list = CSSValueList::createCommaSeparated();
1196     for (size_t i = 0; i < willChangeData->numFeatures(); ++i) {
1197         WillChangeData::FeaturePropertyPair feature = willChangeData->featureAt(i);
1198         switch (feature.first) {
1199         case WillChangeData::ScrollPosition:
1200             list.get().append(cssValuePool.createIdentifierValue(CSSValueScrollPosition));
1201             break;
1202         case WillChangeData::Contents:
1203             list.get().append(cssValuePool.createIdentifierValue(CSSValueContents));
1204             break;
1205         case WillChangeData::Property:
1206             list.get().append(cssValuePool.createIdentifierValue(feature.second));
1207             break;
1208         case WillChangeData::Invalid:
1209             ASSERT_NOT_REACHED();
1210             break;
1211         }
1212     }
1213
1214     return WTFMove(list);
1215 }
1216
1217 static inline void appendLigaturesValue(CSSValueList& list, FontVariantLigatures value, CSSValueID yesValue, CSSValueID noValue)
1218 {
1219     switch (value) {
1220     case FontVariantLigatures::Normal:
1221         return;
1222     case FontVariantLigatures::No:
1223         list.append(CSSValuePool::singleton().createIdentifierValue(noValue));
1224         return;
1225     case FontVariantLigatures::Yes:
1226         list.append(CSSValuePool::singleton().createIdentifierValue(yesValue));
1227         return;
1228     }
1229     ASSERT_NOT_REACHED();
1230 }
1231
1232 static Ref<CSSValue> fontVariantLigaturesPropertyValue(FontVariantLigatures common, FontVariantLigatures discretionary, FontVariantLigatures historical, FontVariantLigatures contextualAlternates)
1233 {
1234     auto& cssValuePool = CSSValuePool::singleton();
1235     if (common == FontVariantLigatures::No && discretionary == FontVariantLigatures::No && historical == FontVariantLigatures::No && contextualAlternates == FontVariantLigatures::No)
1236         return cssValuePool.createIdentifierValue(CSSValueNone);
1237     if (common == FontVariantLigatures::Normal && discretionary == FontVariantLigatures::Normal && historical == FontVariantLigatures::Normal && contextualAlternates == FontVariantLigatures::Normal)
1238         return cssValuePool.createIdentifierValue(CSSValueNormal);
1239
1240     auto valueList = CSSValueList::createSpaceSeparated();
1241     appendLigaturesValue(valueList, common, CSSValueCommonLigatures, CSSValueNoCommonLigatures);
1242     appendLigaturesValue(valueList, discretionary, CSSValueDiscretionaryLigatures, CSSValueNoDiscretionaryLigatures);
1243     appendLigaturesValue(valueList, historical, CSSValueHistoricalLigatures, CSSValueNoHistoricalLigatures);
1244     appendLigaturesValue(valueList, contextualAlternates, CSSValueContextual, CSSValueNoContextual);
1245     return WTFMove(valueList);
1246 }
1247
1248 static Ref<CSSValue> fontVariantPositionPropertyValue(FontVariantPosition position)
1249 {
1250     auto& cssValuePool = CSSValuePool::singleton();
1251     CSSValueID valueID = CSSValueNormal;
1252     switch (position) {
1253     case FontVariantPosition::Normal:
1254         break;
1255     case FontVariantPosition::Subscript:
1256         valueID = CSSValueSub;
1257         break;
1258     case FontVariantPosition::Superscript:
1259         valueID = CSSValueSuper;
1260         break;
1261     }
1262     return cssValuePool.createIdentifierValue(valueID);
1263 }
1264
1265 static Ref<CSSValue> fontVariantCapsPropertyValue(FontVariantCaps caps)
1266 {
1267     auto& cssValuePool = CSSValuePool::singleton();
1268     CSSValueID valueID = CSSValueNormal;
1269     switch (caps) {
1270     case FontVariantCaps::Normal:
1271         break;
1272     case FontVariantCaps::Small:
1273         valueID = CSSValueSmallCaps;
1274         break;
1275     case FontVariantCaps::AllSmall:
1276         valueID = CSSValueAllSmallCaps;
1277         break;
1278     case FontVariantCaps::Petite:
1279         valueID = CSSValuePetiteCaps;
1280         break;
1281     case FontVariantCaps::AllPetite:
1282         valueID = CSSValueAllPetiteCaps;
1283         break;
1284     case FontVariantCaps::Unicase:
1285         valueID = CSSValueUnicase;
1286         break;
1287     case FontVariantCaps::Titling:
1288         valueID = CSSValueTitlingCaps;
1289         break;
1290     }
1291     return cssValuePool.createIdentifierValue(valueID);
1292 }
1293
1294 static Ref<CSSValue> fontVariantNumericPropertyValue(FontVariantNumericFigure figure, FontVariantNumericSpacing spacing, FontVariantNumericFraction fraction, FontVariantNumericOrdinal ordinal, FontVariantNumericSlashedZero slashedZero)
1295 {
1296     auto& cssValuePool = CSSValuePool::singleton();
1297     if (figure == FontVariantNumericFigure::Normal && spacing == FontVariantNumericSpacing::Normal && fraction == FontVariantNumericFraction::Normal && ordinal == FontVariantNumericOrdinal::Normal && slashedZero == FontVariantNumericSlashedZero::Normal)
1298         return cssValuePool.createIdentifierValue(CSSValueNormal);
1299
1300     auto valueList = CSSValueList::createSpaceSeparated();
1301     switch (figure) {
1302     case FontVariantNumericFigure::Normal:
1303         break;
1304     case FontVariantNumericFigure::LiningNumbers:
1305         valueList->append(cssValuePool.createIdentifierValue(CSSValueLiningNums));
1306         break;
1307     case FontVariantNumericFigure::OldStyleNumbers:
1308         valueList->append(cssValuePool.createIdentifierValue(CSSValueOldstyleNums));
1309         break;
1310     }
1311
1312     switch (spacing) {
1313     case FontVariantNumericSpacing::Normal:
1314         break;
1315     case FontVariantNumericSpacing::ProportionalNumbers:
1316         valueList->append(cssValuePool.createIdentifierValue(CSSValueProportionalNums));
1317         break;
1318     case FontVariantNumericSpacing::TabularNumbers:
1319         valueList->append(cssValuePool.createIdentifierValue(CSSValueTabularNums));
1320         break;
1321     }
1322
1323     switch (fraction) {
1324     case FontVariantNumericFraction::Normal:
1325         break;
1326     case FontVariantNumericFraction::DiagonalFractions:
1327         valueList->append(cssValuePool.createIdentifierValue(CSSValueDiagonalFractions));
1328         break;
1329     case FontVariantNumericFraction::StackedFractions:
1330         valueList->append(cssValuePool.createIdentifierValue(CSSValueStackedFractions));
1331         break;
1332     }
1333
1334     if (ordinal == FontVariantNumericOrdinal::Yes)
1335         valueList->append(cssValuePool.createIdentifierValue(CSSValueOrdinal));
1336     if (slashedZero == FontVariantNumericSlashedZero::Yes)
1337         valueList->append(cssValuePool.createIdentifierValue(CSSValueSlashedZero));
1338
1339     return WTFMove(valueList);
1340 }
1341
1342 static Ref<CSSValue> fontVariantAlternatesPropertyValue(FontVariantAlternates alternates)
1343 {
1344     auto& cssValuePool = CSSValuePool::singleton();
1345     CSSValueID valueID = CSSValueNormal;
1346     switch (alternates) {
1347     case FontVariantAlternates::Normal:
1348         break;
1349     case FontVariantAlternates::HistoricalForms:
1350         valueID = CSSValueHistoricalForms;
1351         break;
1352     }
1353     return cssValuePool.createIdentifierValue(valueID);
1354 }
1355
1356 static Ref<CSSValue> fontVariantEastAsianPropertyValue(FontVariantEastAsianVariant variant, FontVariantEastAsianWidth width, FontVariantEastAsianRuby ruby)
1357 {
1358     auto& cssValuePool = CSSValuePool::singleton();
1359     if (variant == FontVariantEastAsianVariant::Normal && width == FontVariantEastAsianWidth::Normal && ruby == FontVariantEastAsianRuby::Normal)
1360         return cssValuePool.createIdentifierValue(CSSValueNormal);
1361
1362     auto valueList = CSSValueList::createSpaceSeparated();
1363     switch (variant) {
1364     case FontVariantEastAsianVariant::Normal:
1365         break;
1366     case FontVariantEastAsianVariant::Jis78:
1367         valueList->append(cssValuePool.createIdentifierValue(CSSValueJis78));
1368         break;
1369     case FontVariantEastAsianVariant::Jis83:
1370         valueList->append(cssValuePool.createIdentifierValue(CSSValueJis83));
1371         break;
1372     case FontVariantEastAsianVariant::Jis90:
1373         valueList->append(cssValuePool.createIdentifierValue(CSSValueJis90));
1374         break;
1375     case FontVariantEastAsianVariant::Jis04:
1376         valueList->append(cssValuePool.createIdentifierValue(CSSValueJis04));
1377         break;
1378     case FontVariantEastAsianVariant::Simplified:
1379         valueList->append(cssValuePool.createIdentifierValue(CSSValueSimplified));
1380         break;
1381     case FontVariantEastAsianVariant::Traditional:
1382         valueList->append(cssValuePool.createIdentifierValue(CSSValueTraditional));
1383         break;
1384     }
1385
1386     switch (width) {
1387     case FontVariantEastAsianWidth::Normal:
1388         break;
1389     case FontVariantEastAsianWidth::Full:
1390         valueList->append(cssValuePool.createIdentifierValue(CSSValueFullWidth));
1391         break;
1392     case FontVariantEastAsianWidth::Proportional:
1393         valueList->append(cssValuePool.createIdentifierValue(CSSValueProportionalWidth));
1394         break;
1395     }
1396
1397     if (ruby == FontVariantEastAsianRuby::Yes)
1398         valueList->append(cssValuePool.createIdentifierValue(CSSValueRuby));
1399
1400     return WTFMove(valueList);
1401 }
1402
1403 static Ref<CSSValueList> getDelayValue(const AnimationList* animList)
1404 {
1405     auto& cssValuePool = CSSValuePool::singleton();
1406     auto list = CSSValueList::createCommaSeparated();
1407     if (animList) {
1408         for (size_t i = 0; i < animList->size(); ++i)
1409             list.get().append(cssValuePool.createValue(animList->animation(i).delay(), CSSPrimitiveValue::CSS_S));
1410     } else {
1411         // Note that initialAnimationDelay() is used for both transitions and animations
1412         list.get().append(cssValuePool.createValue(Animation::initialDelay(), CSSPrimitiveValue::CSS_S));
1413     }
1414     return list;
1415 }
1416
1417 static Ref<CSSValueList> getDurationValue(const AnimationList* animList)
1418 {
1419     auto& cssValuePool = CSSValuePool::singleton();
1420     auto list = CSSValueList::createCommaSeparated();
1421     if (animList) {
1422         for (size_t i = 0; i < animList->size(); ++i)
1423             list.get().append(cssValuePool.createValue(animList->animation(i).duration(), CSSPrimitiveValue::CSS_S));
1424     } else {
1425         // Note that initialAnimationDuration() is used for both transitions and animations
1426         list.get().append(cssValuePool.createValue(Animation::initialDuration(), CSSPrimitiveValue::CSS_S));
1427     }
1428     return list;
1429 }
1430
1431 static Ref<CSSValue> createTimingFunctionValue(const TimingFunction* timingFunction)
1432 {
1433     switch (timingFunction->type()) {
1434     case TimingFunction::CubicBezierFunction: {
1435         const CubicBezierTimingFunction* bezierTimingFunction = static_cast<const CubicBezierTimingFunction*>(timingFunction);
1436         if (bezierTimingFunction->timingFunctionPreset() != CubicBezierTimingFunction::Custom) {
1437             CSSValueID valueId = CSSValueInvalid;
1438             switch (bezierTimingFunction->timingFunctionPreset()) {
1439             case CubicBezierTimingFunction::Ease:
1440                 valueId = CSSValueEase;
1441                 break;
1442             case CubicBezierTimingFunction::EaseIn:
1443                 valueId = CSSValueEaseIn;
1444                 break;
1445             case CubicBezierTimingFunction::EaseOut:
1446                 valueId = CSSValueEaseOut;
1447                 break;
1448             default:
1449                 ASSERT(bezierTimingFunction->timingFunctionPreset() == CubicBezierTimingFunction::EaseInOut);
1450                 valueId = CSSValueEaseInOut;
1451                 break;
1452             }
1453             return CSSValuePool::singleton().createIdentifierValue(valueId);
1454         }
1455         return CSSCubicBezierTimingFunctionValue::create(bezierTimingFunction->x1(), bezierTimingFunction->y1(), bezierTimingFunction->x2(), bezierTimingFunction->y2());
1456     }
1457     case TimingFunction::StepsFunction: {
1458         const StepsTimingFunction* stepsTimingFunction = static_cast<const StepsTimingFunction*>(timingFunction);
1459         return CSSStepsTimingFunctionValue::create(stepsTimingFunction->numberOfSteps(), stepsTimingFunction->stepAtStart());
1460     }
1461     default:
1462         ASSERT(timingFunction->type() == TimingFunction::LinearFunction);
1463         return CSSValuePool::singleton().createIdentifierValue(CSSValueLinear);
1464     }
1465 }
1466
1467 static Ref<CSSValueList> getTimingFunctionValue(const AnimationList* animList)
1468 {
1469     auto list = CSSValueList::createCommaSeparated();
1470     if (animList) {
1471         for (size_t i = 0; i < animList->size(); ++i)
1472             list.get().append(createTimingFunctionValue(animList->animation(i).timingFunction().get()));
1473     } else
1474         // Note that initialAnimationTimingFunction() is used for both transitions and animations
1475         list.get().append(createTimingFunctionValue(Animation::initialTimingFunction().get()));
1476     return list;
1477 }
1478
1479 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
1480 static Ref<CSSValue> createAnimationTriggerValue(const AnimationTrigger* trigger, const RenderStyle& style)
1481 {
1482     switch (trigger->type()) {
1483     case AnimationTrigger::AnimationTriggerType::ScrollAnimationTriggerType: {
1484         auto& scrollAnimationTrigger = downcast<ScrollAnimationTrigger>(*trigger);
1485         if (scrollAnimationTrigger.endValue().isAuto())
1486             return CSSAnimationTriggerScrollValue::create(zoomAdjustedPixelValueForLength(scrollAnimationTrigger.startValue(), style));
1487         return CSSAnimationTriggerScrollValue::create(zoomAdjustedPixelValueForLength(scrollAnimationTrigger.startValue(), style),
1488                                                       zoomAdjustedPixelValueForLength(scrollAnimationTrigger.endValue(), style));
1489     }
1490     default:
1491         ASSERT(trigger->type() == AnimationTrigger::AnimationTriggerType::AutoAnimationTriggerType);
1492         return CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
1493     }
1494 }
1495
1496 static Ref<CSSValueList> getAnimationTriggerValue(const AnimationList* animList, const RenderStyle& style)
1497 {
1498     auto list = CSSValueList::createCommaSeparated();
1499     if (animList) {
1500         for (size_t i = 0; i < animList->size(); ++i)
1501             list.get().append(createAnimationTriggerValue(animList->animation(i).trigger().get(), style));
1502     } else
1503         list.get().append(createAnimationTriggerValue(Animation::initialTrigger().get(), style));
1504
1505     return list;
1506 }
1507 #endif
1508
1509 static Ref<CSSValue> createLineBoxContainValue(unsigned lineBoxContain)
1510 {
1511     if (!lineBoxContain)
1512         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
1513     return CSSLineBoxContainValue::create(lineBoxContain);
1514 }
1515
1516 ComputedStyleExtractor::ComputedStyleExtractor(PassRefPtr<Node> node, bool allowVisitedStyle, PseudoId pseudoElementSpecifier)
1517     : m_node(node)
1518     , m_pseudoElementSpecifier(pseudoElementSpecifier)
1519     , m_allowVisitedStyle(allowVisitedStyle)
1520 {
1521 }
1522
1523
1524 CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(PassRefPtr<Node> n, bool allowVisitedStyle, const String& pseudoElementName)
1525     : m_node(n)
1526     , m_allowVisitedStyle(allowVisitedStyle)
1527     , m_refCount(1)
1528 {
1529     unsigned nameWithoutColonsStart = pseudoElementName[0] == ':' ? (pseudoElementName[1] == ':' ? 2 : 1) : 0;
1530     m_pseudoElementSpecifier = CSSSelector::pseudoId(CSSSelector::parsePseudoElementType(
1531     (pseudoElementName.substringSharingImpl(nameWithoutColonsStart))));
1532 }
1533
1534 CSSComputedStyleDeclaration::~CSSComputedStyleDeclaration()
1535 {
1536 }
1537
1538 void CSSComputedStyleDeclaration::ref()
1539 {
1540     ++m_refCount;
1541 }
1542
1543 void CSSComputedStyleDeclaration::deref()
1544 {
1545     ASSERT(m_refCount);
1546     if (!--m_refCount)
1547         delete this;
1548 }
1549
1550 String CSSComputedStyleDeclaration::cssText() const
1551 {
1552     StringBuilder result;
1553
1554     for (unsigned i = 0; i < numComputedProperties; i++) {
1555         if (i)
1556             result.append(' ');
1557         result.append(getPropertyName(computedProperties[i]));
1558         result.appendLiteral(": ");
1559         result.append(getPropertyValue(computedProperties[i]));
1560         result.append(';');
1561     }
1562
1563     return result.toString();
1564 }
1565
1566 void CSSComputedStyleDeclaration::setCssText(const String&, ExceptionCode& ec)
1567 {
1568     ec = NO_MODIFICATION_ALLOWED_ERR;
1569 }
1570
1571 RefPtr<CSSPrimitiveValue> ComputedStyleExtractor::getFontSizeCSSValuePreferringKeyword() const
1572 {
1573     if (!m_node)
1574         return nullptr;
1575
1576     m_node->document().updateLayoutIgnorePendingStylesheets();
1577
1578     auto* style = m_node->computedStyle(m_pseudoElementSpecifier);
1579     if (!style)
1580         return nullptr;
1581
1582     if (CSSValueID sizeIdentifier = style->fontDescription().keywordSizeAsIdentifier())
1583         return CSSValuePool::singleton().createIdentifierValue(sizeIdentifier);
1584
1585     return zoomAdjustedPixelValue(style->fontDescription().computedSize(), *style);
1586 }
1587
1588 bool ComputedStyleExtractor::useFixedFontDefaultSize() const
1589 {
1590     if (!m_node)
1591         return false;
1592
1593     auto* style = m_node->computedStyle(m_pseudoElementSpecifier);
1594     if (!style)
1595         return false;
1596
1597     return style->fontDescription().useFixedDefaultSize();
1598 }
1599
1600
1601 static CSSValueID identifierForFamily(const AtomicString& family)
1602 {
1603     if (family == cursiveFamily)
1604         return CSSValueCursive;
1605     if (family == fantasyFamily)
1606         return CSSValueFantasy;
1607     if (family == monospaceFamily)
1608         return CSSValueMonospace;
1609     if (family == pictographFamily)
1610         return CSSValueWebkitPictograph;
1611     if (family == sansSerifFamily)
1612         return CSSValueSansSerif;
1613     if (family == serifFamily)
1614         return CSSValueSerif;
1615     return CSSValueInvalid;
1616 }
1617
1618 static Ref<CSSPrimitiveValue> valueForFamily(const AtomicString& family)
1619 {
1620     if (CSSValueID familyIdentifier = identifierForFamily(family))
1621         return CSSValuePool::singleton().createIdentifierValue(familyIdentifier);
1622     return CSSValuePool::singleton().createFontFamilyValue(family);
1623 }
1624
1625 static Ref<CSSValue> renderTextDecorationFlagsToCSSValue(int textDecoration)
1626 {
1627     auto& cssValuePool = CSSValuePool::singleton();
1628     // Blink value is ignored.
1629     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1630     if (textDecoration & TextDecorationUnderline)
1631         list->append(cssValuePool.createIdentifierValue(CSSValueUnderline));
1632     if (textDecoration & TextDecorationOverline)
1633         list->append(cssValuePool.createIdentifierValue(CSSValueOverline));
1634     if (textDecoration & TextDecorationLineThrough)
1635         list->append(cssValuePool.createIdentifierValue(CSSValueLineThrough));
1636 #if ENABLE(LETTERPRESS)
1637     if (textDecoration & TextDecorationLetterpress)
1638         list->append(cssValuePool.createIdentifierValue(CSSValueWebkitLetterpress));
1639 #endif
1640
1641     if (!list->length())
1642         return cssValuePool.createIdentifierValue(CSSValueNone);
1643     return list.releaseNonNull();
1644 }
1645
1646 static Ref<CSSValue> renderTextDecorationStyleFlagsToCSSValue(TextDecorationStyle textDecorationStyle)
1647 {
1648     switch (textDecorationStyle) {
1649     case TextDecorationStyleSolid:
1650         return CSSValuePool::singleton().createIdentifierValue(CSSValueSolid);
1651     case TextDecorationStyleDouble:
1652         return CSSValuePool::singleton().createIdentifierValue(CSSValueDouble);
1653     case TextDecorationStyleDotted:
1654         return CSSValuePool::singleton().createIdentifierValue(CSSValueDotted);
1655     case TextDecorationStyleDashed:
1656         return CSSValuePool::singleton().createIdentifierValue(CSSValueDashed);
1657     case TextDecorationStyleWavy:
1658         return CSSValuePool::singleton().createIdentifierValue(CSSValueWavy);
1659     }
1660
1661     ASSERT_NOT_REACHED();
1662     return CSSValuePool::singleton().createExplicitInitialValue();
1663 }
1664
1665 static Ref<CSSValue> renderTextDecorationSkipFlagsToCSSValue(TextDecorationSkip textDecorationSkip)
1666 {
1667     switch (textDecorationSkip) {
1668     case TextDecorationSkipAuto:
1669         return CSSValuePool::singleton().createIdentifierValue(CSSValueAuto);
1670     case TextDecorationSkipNone:
1671         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
1672     case TextDecorationSkipInk:
1673         return CSSValuePool::singleton().createIdentifierValue(CSSValueInk);
1674     case TextDecorationSkipObjects:
1675         return CSSValuePool::singleton().createIdentifierValue(CSSValueObjects);
1676     }
1677
1678     ASSERT_NOT_REACHED();
1679     return CSSValuePool::singleton().createExplicitInitialValue();
1680 }
1681
1682 static Ref<CSSValue> renderEmphasisPositionFlagsToCSSValue(TextEmphasisPosition textEmphasisPosition)
1683 {
1684     ASSERT(!((textEmphasisPosition & TextEmphasisPositionOver) && (textEmphasisPosition & TextEmphasisPositionUnder)));
1685     ASSERT(!((textEmphasisPosition & TextEmphasisPositionLeft) && (textEmphasisPosition & TextEmphasisPositionRight)));
1686     auto& cssValuePool = CSSValuePool::singleton();
1687     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1688     if (textEmphasisPosition & TextEmphasisPositionOver)
1689         list->append(cssValuePool.createIdentifierValue(CSSValueOver));
1690     if (textEmphasisPosition & TextEmphasisPositionUnder)
1691         list->append(cssValuePool.createIdentifierValue(CSSValueUnder));
1692     if (textEmphasisPosition & TextEmphasisPositionLeft)
1693         list->append(cssValuePool.createIdentifierValue(CSSValueLeft));
1694     if (textEmphasisPosition & TextEmphasisPositionRight)
1695         list->append(cssValuePool.createIdentifierValue(CSSValueRight));
1696
1697     if (!list->length())
1698         return cssValuePool.createIdentifierValue(CSSValueNone);
1699     return list.releaseNonNull();
1700 }
1701
1702 static Ref<CSSValue> hangingPunctuationToCSSValue(HangingPunctuation hangingPunctuation)
1703 {
1704     auto& cssValuePool = CSSValuePool::singleton();
1705     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1706     if (hangingPunctuation & FirstHangingPunctuation)
1707         list->append(cssValuePool.createIdentifierValue(CSSValueFirst));
1708     if (hangingPunctuation & AllowEndHangingPunctuation)
1709         list->append(cssValuePool.createIdentifierValue(CSSValueAllowEnd));
1710     if (hangingPunctuation & ForceEndHangingPunctuation)
1711         list->append(cssValuePool.createIdentifierValue(CSSValueForceEnd));
1712     if (hangingPunctuation & LastHangingPunctuation)
1713         list->append(cssValuePool.createIdentifierValue(CSSValueLast));
1714     if (!list->length())
1715         return cssValuePool.createIdentifierValue(CSSValueNone);
1716     return list.releaseNonNull();
1717 }
1718     
1719 static Ref<CSSValue> fillRepeatToCSSValue(EFillRepeat xRepeat, EFillRepeat yRepeat)
1720 {
1721     // For backwards compatibility, if both values are equal, just return one of them. And
1722     // if the two values are equivalent to repeat-x or repeat-y, just return the shorthand.
1723     auto& cssValuePool = CSSValuePool::singleton();
1724     if (xRepeat == yRepeat)
1725         return cssValuePool.createValue(xRepeat);
1726     if (xRepeat == RepeatFill && yRepeat == NoRepeatFill)
1727         return cssValuePool.createIdentifierValue(CSSValueRepeatX);
1728     if (xRepeat == NoRepeatFill && yRepeat == RepeatFill)
1729         return cssValuePool.createIdentifierValue(CSSValueRepeatY);
1730
1731     auto list = CSSValueList::createSpaceSeparated();
1732     list.get().append(cssValuePool.createValue(xRepeat));
1733     list.get().append(cssValuePool.createValue(yRepeat));
1734     return WTFMove(list);
1735 }
1736
1737 static Ref<CSSValue> fillSourceTypeToCSSValue(EMaskSourceType type)
1738 {
1739     switch (type) {
1740     case MaskAlpha:
1741         return CSSValuePool::singleton().createValue(CSSValueAlpha);
1742     default:
1743         ASSERT(type == MaskLuminance);
1744         return CSSValuePool::singleton().createValue(CSSValueLuminance);
1745     }
1746 }
1747
1748 static Ref<CSSValue> fillSizeToCSSValue(const FillSize& fillSize, const RenderStyle& style)
1749 {
1750     if (fillSize.type == Contain)
1751         return CSSValuePool::singleton().createIdentifierValue(CSSValueContain);
1752
1753     if (fillSize.type == Cover)
1754         return CSSValuePool::singleton().createIdentifierValue(CSSValueCover);
1755
1756     if (fillSize.size.height().isAuto())
1757         return zoomAdjustedPixelValueForLength(fillSize.size.width(), style);
1758
1759     auto list = CSSValueList::createSpaceSeparated();
1760     list.get().append(zoomAdjustedPixelValueForLength(fillSize.size.width(), style));
1761     list.get().append(zoomAdjustedPixelValueForLength(fillSize.size.height(), style));
1762     return WTFMove(list);
1763 }
1764
1765 static Ref<CSSValue> altTextToCSSValue(const RenderStyle* style)
1766 {
1767     return CSSValuePool::singleton().createValue(style->contentAltText(), CSSPrimitiveValue::CSS_STRING);
1768 }
1769     
1770 static Ref<CSSValueList> contentToCSSValue(const RenderStyle* style)
1771 {
1772     auto& cssValuePool = CSSValuePool::singleton();
1773     auto list = CSSValueList::createSpaceSeparated();
1774     for (const ContentData* contentData = style->contentData(); contentData; contentData = contentData->next()) {
1775         if (is<CounterContentData>(*contentData))
1776             list.get().append(cssValuePool.createValue(downcast<CounterContentData>(*contentData).counter().identifier(), CSSPrimitiveValue::CSS_COUNTER_NAME));
1777         else if (is<ImageContentData>(*contentData))
1778             list.get().append(*downcast<ImageContentData>(*contentData).image().cssValue());
1779         else if (is<TextContentData>(*contentData))
1780             list.get().append(cssValuePool.createValue(downcast<TextContentData>(*contentData).text(), CSSPrimitiveValue::CSS_STRING));
1781     }
1782     if (style->hasFlowFrom())
1783         list.get().append(cssValuePool.createValue(style->regionThread(), CSSPrimitiveValue::CSS_STRING));
1784     return list;
1785 }
1786
1787 static RefPtr<CSSValue> counterToCSSValue(const RenderStyle* style, CSSPropertyID propertyID)
1788 {
1789     const CounterDirectiveMap* map = style->counterDirectives();
1790     if (!map)
1791         return nullptr;
1792
1793     auto& cssValuePool = CSSValuePool::singleton();
1794     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
1795     for (CounterDirectiveMap::const_iterator it = map->begin(); it != map->end(); ++it) {
1796         list->append(cssValuePool.createValue(it->key, CSSPrimitiveValue::CSS_STRING));
1797         short number = propertyID == CSSPropertyCounterIncrement ? it->value.incrementValue() : it->value.resetValue();
1798         list->append(cssValuePool.createValue((double)number, CSSPrimitiveValue::CSS_NUMBER));
1799     }
1800     return list.release();
1801 }
1802
1803 static void logUnimplementedPropertyID(CSSPropertyID propertyID)
1804 {
1805     static NeverDestroyed<HashSet<CSSPropertyID>> propertyIDSet;
1806     if (!propertyIDSet.get().add(propertyID).isNewEntry)
1807         return;
1808
1809     LOG_ERROR("WebKit does not yet implement getComputedStyle for '%s'.", getPropertyName(propertyID));
1810 }
1811
1812 static Ref<CSSValueList> fontFamilyFromStyle(const RenderStyle* style)
1813 {
1814     auto list = CSSValueList::createCommaSeparated();
1815     for (unsigned i = 0; i < style->fontCascade().familyCount(); ++i)
1816         list.get().append(valueForFamily(style->fontCascade().familyAt(i)));
1817     return list;
1818 }
1819
1820 static Ref<CSSPrimitiveValue> lineHeightFromStyle(const RenderStyle& style)
1821 {
1822     Length length = style.lineHeight();
1823     if (length.isNegative()) // If true, line-height not set; use the font's line spacing.
1824         return zoomAdjustedPixelValue(style.fontMetrics().floatLineSpacing(), style);
1825     if (length.isPercent()) {
1826         // This is imperfect, because it doesn't include the zoom factor and the real computation
1827         // for how high to be in pixels does include things like minimum font size and the zoom factor.
1828         // On the other hand, since font-size doesn't include the zoom factor, we really can't do
1829         // that here either.
1830         return zoomAdjustedPixelValue(static_cast<int>(length.percent() * style.fontDescription().specifiedSize()) / 100, style);
1831     }
1832     return zoomAdjustedPixelValue(floatValueForLength(length, 0), style);
1833 }
1834
1835 static Ref<CSSPrimitiveValue> fontSizeFromStyle(const RenderStyle& style)
1836 {
1837     return zoomAdjustedPixelValue(style.fontDescription().computedSize(), style);
1838 }
1839
1840 static Ref<CSSPrimitiveValue> fontStyleFromStyle(const RenderStyle* style)
1841 {
1842     if (style->fontDescription().italic())
1843         return CSSValuePool::singleton().createIdentifierValue(CSSValueItalic);
1844     return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
1845 }
1846
1847 static Ref<CSSValue> fontVariantFromStyle(const RenderStyle* style)
1848 {
1849     if (style->fontDescription().variantSettings().isAllNormal())
1850         return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
1851
1852     auto list = CSSValueList::createSpaceSeparated();
1853
1854     switch (style->fontDescription().variantCommonLigatures()) {
1855     case FontVariantLigatures::Normal:
1856         break;
1857     case FontVariantLigatures::Yes:
1858         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueCommonLigatures));
1859         break;
1860     case FontVariantLigatures::No:
1861         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueNoCommonLigatures));
1862         break;
1863     }
1864
1865     switch (style->fontDescription().variantDiscretionaryLigatures()) {
1866     case FontVariantLigatures::Normal:
1867         break;
1868     case FontVariantLigatures::Yes:
1869         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueDiscretionaryLigatures));
1870         break;
1871     case FontVariantLigatures::No:
1872         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueNoDiscretionaryLigatures));
1873         break;
1874     }
1875
1876     switch (style->fontDescription().variantHistoricalLigatures()) {
1877     case FontVariantLigatures::Normal:
1878         break;
1879     case FontVariantLigatures::Yes:
1880         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueHistoricalLigatures));
1881         break;
1882     case FontVariantLigatures::No:
1883         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueNoHistoricalLigatures));
1884         break;
1885     }
1886
1887     switch (style->fontDescription().variantContextualAlternates()) {
1888     case FontVariantLigatures::Normal:
1889         break;
1890     case FontVariantLigatures::Yes:
1891         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueContextual));
1892         break;
1893     case FontVariantLigatures::No:
1894         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueNoContextual));
1895         break;
1896     }
1897
1898     switch (style->fontDescription().variantPosition()) {
1899     case FontVariantPosition::Normal:
1900         break;
1901     case FontVariantPosition::Subscript:
1902         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueSub));
1903         break;
1904     case FontVariantPosition::Superscript:
1905         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueSuper));
1906         break;
1907     }
1908
1909     switch (style->fontDescription().variantCaps()) {
1910     case FontVariantCaps::Normal:
1911         break;
1912     case FontVariantCaps::Small:
1913         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueSmallCaps));
1914         break;
1915     case FontVariantCaps::AllSmall:
1916         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueAllSmallCaps));
1917         break;
1918     case FontVariantCaps::Petite:
1919         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValuePetiteCaps));
1920         break;
1921     case FontVariantCaps::AllPetite:
1922         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueAllPetiteCaps));
1923         break;
1924     case FontVariantCaps::Unicase:
1925         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueUnicase));
1926         break;
1927     case FontVariantCaps::Titling:
1928         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueTitlingCaps));
1929         break;
1930     }
1931
1932     switch (style->fontDescription().variantNumericFigure()) {
1933     case FontVariantNumericFigure::Normal:
1934         break;
1935     case FontVariantNumericFigure::LiningNumbers:
1936         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueLiningNums));
1937         break;
1938     case FontVariantNumericFigure::OldStyleNumbers:
1939         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueOldstyleNums));
1940         break;
1941     }
1942
1943     switch (style->fontDescription().variantNumericSpacing()) {
1944     case FontVariantNumericSpacing::Normal:
1945         break;
1946     case FontVariantNumericSpacing::ProportionalNumbers:
1947         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueProportionalNums));
1948         break;
1949     case FontVariantNumericSpacing::TabularNumbers:
1950         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueTabularNums));
1951         break;
1952     }
1953
1954     switch (style->fontDescription().variantNumericFraction()) {
1955     case FontVariantNumericFraction::Normal:
1956         break;
1957     case FontVariantNumericFraction::DiagonalFractions:
1958         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueDiagonalFractions));
1959         break;
1960     case FontVariantNumericFraction::StackedFractions:
1961         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueStackedFractions));
1962         break;
1963     }
1964
1965     switch (style->fontDescription().variantNumericOrdinal()) {
1966     case FontVariantNumericOrdinal::Normal:
1967         break;
1968     case FontVariantNumericOrdinal::Yes:
1969         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueOrdinal));
1970         break;
1971     }
1972
1973     switch (style->fontDescription().variantNumericSlashedZero()) {
1974     case FontVariantNumericSlashedZero::Normal:
1975         break;
1976     case FontVariantNumericSlashedZero::Yes:
1977         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueSlashedZero));
1978         break;
1979     }
1980
1981     switch (style->fontDescription().variantAlternates()) {
1982     case FontVariantAlternates::Normal:
1983         break;
1984     case FontVariantAlternates::HistoricalForms:
1985         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueHistoricalForms));
1986         break;
1987     }
1988
1989     switch (style->fontDescription().variantEastAsianVariant()) {
1990     case FontVariantEastAsianVariant::Normal:
1991         break;
1992     case FontVariantEastAsianVariant::Jis78:
1993         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis78));
1994         break;
1995     case FontVariantEastAsianVariant::Jis83:
1996         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis83));
1997         break;
1998     case FontVariantEastAsianVariant::Jis90:
1999         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis90));
2000         break;
2001     case FontVariantEastAsianVariant::Jis04:
2002         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueJis04));
2003         break;
2004     case FontVariantEastAsianVariant::Simplified:
2005         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueSimplified));
2006         break;
2007     case FontVariantEastAsianVariant::Traditional:
2008         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueTraditional));
2009         break;
2010     }
2011
2012     switch (style->fontDescription().variantEastAsianWidth()) {
2013     case FontVariantEastAsianWidth::Normal:
2014         break;
2015     case FontVariantEastAsianWidth::Full:
2016         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueFullWidth));
2017         break;
2018     case FontVariantEastAsianWidth::Proportional:
2019         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueProportionalWidth));
2020         break;
2021     }
2022
2023     switch (style->fontDescription().variantEastAsianRuby()) {
2024     case FontVariantEastAsianRuby::Normal:
2025         break;
2026     case FontVariantEastAsianRuby::Yes:
2027         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueRuby));
2028         break;
2029     }
2030
2031     return WTFMove(list);
2032 }
2033
2034 static Ref<CSSPrimitiveValue> fontWeightFromStyle(const RenderStyle* style)
2035 {
2036     switch (style->fontDescription().weight()) {
2037     case FontWeight100:
2038         return CSSValuePool::singleton().createIdentifierValue(CSSValue100);
2039     case FontWeight200:
2040         return CSSValuePool::singleton().createIdentifierValue(CSSValue200);
2041     case FontWeight300:
2042         return CSSValuePool::singleton().createIdentifierValue(CSSValue300);
2043     case FontWeightNormal:
2044         return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
2045     case FontWeight500:
2046         return CSSValuePool::singleton().createIdentifierValue(CSSValue500);
2047     case FontWeight600:
2048         return CSSValuePool::singleton().createIdentifierValue(CSSValue600);
2049     case FontWeightBold:
2050         return CSSValuePool::singleton().createIdentifierValue(CSSValueBold);
2051     case FontWeight800:
2052         return CSSValuePool::singleton().createIdentifierValue(CSSValue800);
2053     case FontWeight900:
2054         return CSSValuePool::singleton().createIdentifierValue(CSSValue900);
2055     }
2056     ASSERT_NOT_REACHED();
2057     return CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
2058 }
2059
2060 static Ref<CSSValue> fontSynthesisFromStyle(const RenderStyle& style)
2061 {
2062     if (style.fontDescription().fontSynthesis() == FontSynthesisNone)
2063         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
2064
2065     auto list = CSSValueList::createSpaceSeparated();
2066     if (style.fontDescription().fontSynthesis() & FontSynthesisStyle)
2067         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueStyle));
2068     if (style.fontDescription().fontSynthesis() & FontSynthesisWeight)
2069         list.get().append(CSSValuePool::singleton().createIdentifierValue(CSSValueWeight));
2070     return Ref<CSSValue>(list.get());
2071 }
2072
2073 typedef const Length& (RenderStyle::*RenderStyleLengthGetter)() const;
2074 typedef LayoutUnit (RenderBoxModelObject::*RenderBoxComputedCSSValueGetter)() const;
2075
2076 template<RenderStyleLengthGetter lengthGetter, RenderBoxComputedCSSValueGetter computedCSSValueGetter>
2077 inline RefPtr<CSSValue> zoomAdjustedPaddingOrMarginPixelValue(const RenderStyle& style, RenderObject* renderer)
2078 {
2079     Length unzoomzedLength = (style.*lengthGetter)();
2080     if (!is<RenderBox>(renderer) || unzoomzedLength.isFixed())
2081         return zoomAdjustedPixelValueForLength(unzoomzedLength, style);
2082     return zoomAdjustedPixelValue((downcast<RenderBox>(*renderer).*computedCSSValueGetter)(), style);
2083 }
2084
2085 template<RenderStyleLengthGetter lengthGetter>
2086 inline bool paddingOrMarginIsRendererDependent(const RenderStyle* style, RenderObject* renderer)
2087 {
2088     if (!renderer || !renderer->isBox())
2089         return false;
2090     return !(style && (style->*lengthGetter)().isFixed());
2091 }
2092
2093 static CSSValueID convertToPageBreak(BreakBetween value)
2094 {
2095     if (value == PageBreakBetween || value == LeftPageBreakBetween || value == RightPageBreakBetween
2096         || value == RectoPageBreakBetween || value == VersoPageBreakBetween)
2097         return CSSValueAlways; // CSS 2.1 allows us to map these to always.
2098     if (value == AvoidBreakBetween || value == AvoidPageBreakBetween)
2099         return CSSValueAvoid;
2100     return CSSValueAuto;
2101 }
2102
2103 static CSSValueID convertToColumnBreak(BreakBetween value)
2104 {
2105     if (value == ColumnBreakBetween)
2106         return CSSValueAlways;
2107     if (value == AvoidBreakBetween || value == AvoidColumnBreakBetween)
2108         return CSSValueAvoid;
2109     return CSSValueAuto;
2110 }
2111
2112 static CSSValueID convertToPageBreak(BreakInside value)
2113 {
2114     if (value == AvoidBreakInside || value == AvoidPageBreakInside)
2115         return CSSValueAvoid;
2116     return CSSValueAuto;
2117 }
2118
2119 static CSSValueID convertToColumnBreak(BreakInside value)
2120 {
2121     if (value == AvoidBreakInside || value == AvoidColumnBreakInside)
2122         return CSSValueAvoid;
2123     return CSSValueAuto;
2124 }
2125
2126 #if ENABLE(CSS_REGIONS)
2127 static CSSValueID convertToRegionBreak(BreakBetween value)
2128 {
2129     if (value == RegionBreakBetween)
2130         return CSSValueAlways;
2131     if (value == AvoidBreakBetween || value == AvoidRegionBreakBetween)
2132         return CSSValueAvoid;
2133     return CSSValueAuto;
2134 }
2135     
2136 static CSSValueID convertToRegionBreak(BreakInside value)
2137 {
2138     if (value == AvoidBreakInside || value == AvoidRegionBreakInside)
2139         return CSSValueAvoid;
2140     return CSSValueAuto;
2141 }
2142 #endif
2143     
2144 static bool isLayoutDependent(CSSPropertyID propertyID, const RenderStyle* style, RenderObject* renderer)
2145 {
2146     switch (propertyID) {
2147     case CSSPropertyWidth:
2148     case CSSPropertyHeight:
2149     case CSSPropertyPerspectiveOrigin:
2150     case CSSPropertyTransformOrigin:
2151     case CSSPropertyTransform:
2152     case CSSPropertyFilter:
2153 #if ENABLE(FILTERS_LEVEL_2)
2154     case CSSPropertyWebkitBackdropFilter:
2155 #endif
2156         return true;
2157     case CSSPropertyMargin: {
2158         if (!renderer || !renderer->isBox())
2159             return false;
2160         return !(style && style->marginTop().isFixed() && style->marginRight().isFixed()
2161             && style->marginBottom().isFixed() && style->marginLeft().isFixed());
2162     }
2163     case CSSPropertyMarginTop:
2164         return paddingOrMarginIsRendererDependent<&RenderStyle::marginTop>(style, renderer);
2165     case CSSPropertyMarginRight:
2166         return paddingOrMarginIsRendererDependent<&RenderStyle::marginRight>(style, renderer);
2167     case CSSPropertyMarginBottom:
2168         return paddingOrMarginIsRendererDependent<&RenderStyle::marginBottom>(style, renderer);
2169     case CSSPropertyMarginLeft:
2170         return paddingOrMarginIsRendererDependent<&RenderStyle::marginLeft>(style, renderer);
2171     case CSSPropertyPadding: {
2172         if (!renderer || !renderer->isBox())
2173             return false;
2174         return !(style && style->paddingTop().isFixed() && style->paddingRight().isFixed()
2175             && style->paddingBottom().isFixed() && style->paddingLeft().isFixed());
2176     }
2177     case CSSPropertyPaddingTop:
2178         return paddingOrMarginIsRendererDependent<&RenderStyle::paddingTop>(style, renderer);
2179     case CSSPropertyPaddingRight:
2180         return paddingOrMarginIsRendererDependent<&RenderStyle::paddingRight>(style, renderer);
2181     case CSSPropertyPaddingBottom:
2182         return paddingOrMarginIsRendererDependent<&RenderStyle::paddingBottom>(style, renderer);
2183     case CSSPropertyPaddingLeft:
2184         return paddingOrMarginIsRendererDependent<&RenderStyle::paddingLeft>(style, renderer); 
2185 #if ENABLE(CSS_GRID_LAYOUT)
2186     case CSSPropertyWebkitGridTemplateColumns:
2187     case CSSPropertyWebkitGridTemplateRows:
2188     case CSSPropertyWebkitGridTemplate:
2189     case CSSPropertyWebkitGrid:
2190         return renderer && renderer->isRenderGrid();
2191 #endif
2192     default:
2193         return false;
2194     }
2195 }
2196
2197 Node* ComputedStyleExtractor::styledNode() const
2198 {
2199     if (!m_node)
2200         return nullptr;
2201     if (!is<Element>(*m_node))
2202         return m_node.get();
2203     Element& element = downcast<Element>(*m_node);
2204     PseudoElement* pseudoElement;
2205     if (m_pseudoElementSpecifier == BEFORE && (pseudoElement = element.beforePseudoElement()))
2206         return pseudoElement;
2207     if (m_pseudoElementSpecifier == AFTER && (pseudoElement = element.afterPseudoElement()))
2208         return pseudoElement;
2209     return &element;
2210 }
2211
2212 static ItemPosition resolveContainerAlignmentAuto(ItemPosition position, RenderObject* element)
2213 {
2214     if (position != ItemPositionAuto || !element)
2215         return position;
2216
2217     return element->style().isDisplayFlexibleOrGridBox() ? ItemPositionStretch : ItemPositionStart;
2218 }
2219
2220 static ItemPosition resolveSelfAlignmentAuto(ItemPosition position, OverflowAlignment& overflow, RenderObject* element)
2221 {
2222     if (position != ItemPositionAuto || !element || element->isOutOfFlowPositioned())
2223         return position;
2224
2225     RenderBlock* parent = element->containingBlock();
2226     if (!parent)
2227         return ItemPositionStart;
2228
2229     overflow = parent->style().alignItemsOverflowAlignment();
2230     return resolveContainerAlignmentAuto(parent->style().alignItemsPosition(), parent);
2231 }
2232
2233 RefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
2234 {
2235     return ComputedStyleExtractor(m_node, m_allowVisitedStyle, m_pseudoElementSpecifier).propertyValue(propertyID, updateLayout);
2236 }
2237
2238 Ref<MutableStyleProperties> CSSComputedStyleDeclaration::copyProperties() const
2239 {
2240     return ComputedStyleExtractor(m_node, m_allowVisitedStyle, m_pseudoElementSpecifier).copyProperties();
2241 }
2242
2243 static inline bool nodeOrItsAncestorNeedsStyleRecalc(const Node& node)
2244 {
2245     if (node.needsStyleRecalc())
2246         return true;
2247
2248     const Node* currentNode = &node;
2249     const Element* ancestor = currentNode->parentOrShadowHostElement();
2250     while (ancestor) {
2251         if (ancestor->needsStyleRecalc())
2252             return true;
2253
2254         if (ancestor->directChildNeedsStyleRecalc() && currentNode->styleIsAffectedByPreviousSibling())
2255             return true;
2256
2257         currentNode = ancestor;
2258         ancestor = currentNode->parentOrShadowHostElement();
2259     }
2260     return false;
2261 }
2262
2263 static inline bool updateStyleIfNeededForNode(const Node& node)
2264 {
2265     Document& document = node.document();
2266     if (!document.hasPendingForcedStyleRecalc() && !(document.childNeedsStyleRecalc() && nodeOrItsAncestorNeedsStyleRecalc(node)))
2267         return false;
2268     document.updateStyleIfNeeded();
2269     return true;
2270 }
2271
2272 static inline const RenderStyle* computeRenderStyleForProperty(Node* styledNode, PseudoId pseudoElementSpecifier, CSSPropertyID propertyID, std::unique_ptr<RenderStyle>& ownedStyle)
2273 {
2274     RenderObject* renderer = styledNode->renderer();
2275
2276     if (renderer && renderer->isComposited() && AnimationController::supportsAcceleratedAnimationOfProperty(propertyID)) {
2277         ownedStyle = renderer->animation().getAnimatedStyleForRenderer(downcast<RenderElement>(*renderer));
2278         if (pseudoElementSpecifier && !styledNode->isPseudoElement()) {
2279             // FIXME: This cached pseudo style will only exist if the animation has been run at least once.
2280             return ownedStyle->getCachedPseudoStyle(pseudoElementSpecifier);
2281         }
2282         return ownedStyle.get();
2283     }
2284
2285     return styledNode->computedStyle(styledNode->isPseudoElement() ? NOPSEUDO : pseudoElementSpecifier);
2286 }
2287
2288 #if ENABLE(CSS_SHAPES)
2289 static Ref<CSSValue> shapePropertyValue(const RenderStyle& style, const ShapeValue* shapeValue)
2290 {
2291     if (!shapeValue)
2292         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
2293
2294     if (shapeValue->type() == ShapeValue::Type::Box)
2295         return CSSValuePool::singleton().createValue(shapeValue->cssBox());
2296
2297     if (shapeValue->type() == ShapeValue::Type::Image) {
2298         if (shapeValue->image())
2299             return *shapeValue->image()->cssValue();
2300         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
2301     }
2302
2303     ASSERT(shapeValue->type() == ShapeValue::Type::Shape);
2304
2305     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2306     list->append(valueForBasicShape(style, *shapeValue->shape()));
2307     if (shapeValue->cssBox() != BoxMissing)
2308         list->append(CSSValuePool::singleton().createValue(shapeValue->cssBox()));
2309     return list.releaseNonNull();
2310 }
2311 #endif
2312
2313 static RefPtr<CSSValueList> valueForItemPositionWithOverflowAlignment(ItemPosition itemPosition, OverflowAlignment overflowAlignment, ItemPositionType positionType)
2314 {
2315     auto& cssValuePool = CSSValuePool::singleton();
2316     RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
2317     if (positionType == LegacyPosition)
2318         result->append(CSSPrimitiveValue::createIdentifier(CSSValueLegacy));
2319     result->append(cssValuePool.createValue(itemPosition));
2320     if (overflowAlignment != OverflowAlignmentDefault)
2321         result->append(cssValuePool.createValue(overflowAlignment));
2322     ASSERT(result->length() <= 2);
2323     return result;
2324 }
2325
2326 static RefPtr<CSSValueList> valueForContentPositionAndDistributionWithOverflowAlignment(const StyleContentAlignmentData& data)
2327 {
2328     RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
2329     if (data.distribution() != ContentDistributionDefault)
2330         result->append(CSSPrimitiveValue::create(data.distribution()));
2331     if (data.distribution() == ContentDistributionDefault || data.position() != ContentPositionNormal)
2332         result->append(CSSPrimitiveValue::create(data.position()));
2333     if ((data.position() >= ContentPositionCenter || data.distribution() != ContentDistributionDefault) && data.overflow() != OverflowAlignmentDefault)
2334         result->append(CSSPrimitiveValue::create(data.overflow()));
2335     ASSERT(result->length() > 0);
2336     ASSERT(result->length() <= 3);
2337     return result;
2338 }
2339
2340 inline static bool isFlexOrGrid(ContainerNode* element)
2341 {
2342     return element && element->computedStyle() && element->computedStyle()->isDisplayFlexibleOrGridBox();
2343 }
2344
2345 RefPtr<CSSValue> ComputedStyleExtractor::customPropertyValue(const String& propertyName) const
2346 {
2347     Node* styledNode = this->styledNode();
2348     if (!styledNode)
2349         return nullptr;
2350     
2351     if (updateStyleIfNeededForNode(*styledNode)) {
2352         // The style recalc could have caused the styled node to be discarded or replaced
2353         // if it was a PseudoElement so we need to update it.
2354         styledNode = this->styledNode();
2355     }
2356
2357     std::unique_ptr<RenderStyle> ownedStyle;
2358     auto* style = computeRenderStyleForProperty(styledNode, m_pseudoElementSpecifier, CSSPropertyCustom, ownedStyle);
2359     if (!style || !style->hasCustomProperty(propertyName))
2360         return nullptr;
2361
2362     return style->getCustomPropertyValue(propertyName);
2363 }
2364
2365 String ComputedStyleExtractor::customPropertyText(const String& propertyName) const
2366 {
2367     RefPtr<CSSValue> propertyValue = this->customPropertyValue(propertyName);
2368     return propertyValue ? propertyValue->cssText() : emptyString();
2369 }
2370
2371 RefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
2372 {
2373     Node* styledNode = this->styledNode();
2374     if (!styledNode)
2375         return nullptr;
2376
2377     std::unique_ptr<RenderStyle> ownedStyle;
2378     const RenderStyle* style = nullptr;
2379     RenderObject* renderer = nullptr;
2380     bool forceFullLayout = false;
2381     if (updateLayout) {
2382         Document& document = styledNode->document();
2383
2384         if (updateStyleIfNeededForNode(*styledNode)) {
2385             // The style recalc could have caused the styled node to be discarded or replaced
2386             // if it was a PseudoElement so we need to update it.
2387             styledNode = this->styledNode();
2388         }
2389
2390         renderer = styledNode->renderer();
2391
2392         if (propertyID == CSSPropertyDisplay && !renderer && is<SVGElement>(*styledNode) && !downcast<SVGElement>(*styledNode).isValid())
2393             return nullptr;
2394
2395         style = computeRenderStyleForProperty(styledNode, m_pseudoElementSpecifier, propertyID, ownedStyle);
2396
2397         // FIXME: Some of these cases could be narrowed down or optimized better.
2398         forceFullLayout = isLayoutDependent(propertyID, style, renderer)
2399             || styledNode->isInShadowTree()
2400             || (document.styleResolverIfExists() && document.styleResolverIfExists()->hasViewportDependentMediaQueries() && document.ownerElement());
2401
2402         if (forceFullLayout) {
2403             document.updateLayoutIgnorePendingStylesheets();
2404             styledNode = this->styledNode();
2405         }
2406     }
2407
2408     if (!updateLayout || forceFullLayout) {
2409         style = computeRenderStyleForProperty(styledNode, m_pseudoElementSpecifier, propertyID, ownedStyle);
2410         renderer = styledNode->renderer();
2411     }
2412
2413     if (!style)
2414         return nullptr;
2415
2416     auto& cssValuePool = CSSValuePool::singleton();
2417     propertyID = CSSProperty::resolveDirectionAwareProperty(propertyID, style->direction(), style->writingMode());
2418
2419     switch (propertyID) {
2420         case CSSPropertyInvalid:
2421             break;
2422
2423         case CSSPropertyBackgroundColor:
2424             return cssValuePool.createColorValue(m_allowVisitedStyle? style->visitedDependentColor(CSSPropertyBackgroundColor).rgb() : style->backgroundColor().rgb());
2425         case CSSPropertyBackgroundImage:
2426         case CSSPropertyWebkitMaskImage: {
2427             const FillLayer* layers = propertyID == CSSPropertyWebkitMaskImage ? style->maskLayers() : style->backgroundLayers();
2428             if (!layers)
2429                 return cssValuePool.createIdentifierValue(CSSValueNone);
2430
2431             if (!layers->next()) {
2432                 if (layers->image())
2433                     return layers->image()->cssValue();
2434
2435                 return cssValuePool.createIdentifierValue(CSSValueNone);
2436             }
2437
2438             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2439             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next()) {
2440                 if (currLayer->image())
2441                     list->append(*currLayer->image()->cssValue());
2442                 else
2443                     list->append(cssValuePool.createIdentifierValue(CSSValueNone));
2444             }
2445             return list;
2446         }
2447         case CSSPropertyBackgroundSize:
2448         case CSSPropertyWebkitBackgroundSize:
2449         case CSSPropertyWebkitMaskSize: {
2450             const FillLayer* layers = propertyID == CSSPropertyWebkitMaskSize ? style->maskLayers() : style->backgroundLayers();
2451             if (!layers->next())
2452                 return fillSizeToCSSValue(layers->size(), *style);
2453
2454             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2455             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
2456                 list->append(fillSizeToCSSValue(currLayer->size(), *style));
2457
2458             return list;
2459         }
2460         case CSSPropertyBackgroundRepeat:
2461         case CSSPropertyWebkitMaskRepeat: {
2462             const FillLayer* layers = propertyID == CSSPropertyWebkitMaskRepeat ? style->maskLayers() : style->backgroundLayers();
2463             if (!layers->next())
2464                 return fillRepeatToCSSValue(layers->repeatX(), layers->repeatY());
2465
2466             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2467             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
2468                 list->append(fillRepeatToCSSValue(currLayer->repeatX(), currLayer->repeatY()));
2469
2470             return list;
2471         }
2472         case CSSPropertyWebkitMaskSourceType: {
2473             const FillLayer* layers = style->maskLayers();
2474
2475             if (!layers)
2476                 return cssValuePool.createIdentifierValue(CSSValueNone);
2477
2478             if (!layers->next())
2479                 return fillSourceTypeToCSSValue(layers->maskSourceType());
2480
2481             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2482             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
2483                 list->append(fillSourceTypeToCSSValue(currLayer->maskSourceType()));
2484
2485             return list;
2486         }
2487         case CSSPropertyWebkitBackgroundComposite:
2488         case CSSPropertyWebkitMaskComposite: {
2489             const FillLayer* layers = propertyID == CSSPropertyWebkitMaskComposite ? style->maskLayers() : style->backgroundLayers();
2490             if (!layers->next())
2491                 return cssValuePool.createValue(layers->composite());
2492
2493             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2494             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
2495                 list->append(cssValuePool.createValue(currLayer->composite()));
2496
2497             return list;
2498         }
2499         case CSSPropertyBackgroundAttachment: {
2500             const FillLayer* layers = style->backgroundLayers();
2501             if (!layers->next())
2502                 return cssValuePool.createValue(layers->attachment());
2503
2504             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2505             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
2506                 list->append(cssValuePool.createValue(currLayer->attachment()));
2507
2508             return list;
2509         }
2510         case CSSPropertyBackgroundClip:
2511         case CSSPropertyBackgroundOrigin:
2512         case CSSPropertyWebkitBackgroundClip:
2513         case CSSPropertyWebkitBackgroundOrigin:
2514         case CSSPropertyWebkitMaskClip:
2515         case CSSPropertyWebkitMaskOrigin: {
2516             const FillLayer* layers = (propertyID == CSSPropertyWebkitMaskClip || propertyID == CSSPropertyWebkitMaskOrigin) ? style->maskLayers() : style->backgroundLayers();
2517             bool isClip = propertyID == CSSPropertyBackgroundClip || propertyID == CSSPropertyWebkitBackgroundClip || propertyID == CSSPropertyWebkitMaskClip;
2518             if (!layers->next()) {
2519                 EFillBox box = isClip ? layers->clip() : layers->origin();
2520                 return cssValuePool.createValue(box);
2521             }
2522
2523             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2524             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next()) {
2525                 EFillBox box = isClip ? currLayer->clip() : currLayer->origin();
2526                 list->append(cssValuePool.createValue(box));
2527             }
2528
2529             return list;
2530         }
2531         case CSSPropertyBackgroundPosition:
2532         case CSSPropertyWebkitMaskPosition: {
2533             const FillLayer* layers = propertyID == CSSPropertyWebkitMaskPosition ? style->maskLayers() : style->backgroundLayers();
2534             if (!layers->next())
2535                 return createPositionListForLayer(propertyID, layers, *style);
2536
2537             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2538             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
2539                 list->append(createPositionListForLayer(propertyID, currLayer, *style));
2540             return list;
2541         }
2542         case CSSPropertyBackgroundPositionX:
2543         case CSSPropertyWebkitMaskPositionX: {
2544             const FillLayer* layers = propertyID == CSSPropertyWebkitMaskPositionX ? style->maskLayers() : style->backgroundLayers();
2545             if (!layers->next())
2546                 return cssValuePool.createValue(layers->xPosition());
2547
2548             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2549             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
2550                 list->append(cssValuePool.createValue(currLayer->xPosition()));
2551
2552             return list;
2553         }
2554         case CSSPropertyBackgroundPositionY:
2555         case CSSPropertyWebkitMaskPositionY: {
2556             const FillLayer* layers = propertyID == CSSPropertyWebkitMaskPositionY ? style->maskLayers() : style->backgroundLayers();
2557             if (!layers->next())
2558                 return cssValuePool.createValue(layers->yPosition());
2559
2560             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2561             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
2562                 list->append(cssValuePool.createValue(currLayer->yPosition()));
2563
2564             return list;
2565         }
2566         case CSSPropertyBorderCollapse:
2567             if (style->borderCollapse())
2568                 return cssValuePool.createIdentifierValue(CSSValueCollapse);
2569             return cssValuePool.createIdentifierValue(CSSValueSeparate);
2570         case CSSPropertyBorderSpacing: {
2571             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2572             list->append(zoomAdjustedPixelValue(style->horizontalBorderSpacing(), *style));
2573             list->append(zoomAdjustedPixelValue(style->verticalBorderSpacing(), *style));
2574             return list;
2575         }
2576         case CSSPropertyWebkitBorderHorizontalSpacing:
2577             return zoomAdjustedPixelValue(style->horizontalBorderSpacing(), *style);
2578         case CSSPropertyWebkitBorderVerticalSpacing:
2579             return zoomAdjustedPixelValue(style->verticalBorderSpacing(), *style);
2580         case CSSPropertyBorderImageSource:
2581             if (style->borderImageSource())
2582                 return style->borderImageSource()->cssValue();
2583             return cssValuePool.createIdentifierValue(CSSValueNone);
2584         case CSSPropertyBorderTopColor:
2585             return m_allowVisitedStyle ? cssValuePool.createColorValue(style->visitedDependentColor(CSSPropertyBorderTopColor).rgb()) : currentColorOrValidColor(style, style->borderTopColor());
2586         case CSSPropertyBorderRightColor:
2587             return m_allowVisitedStyle ? cssValuePool.createColorValue(style->visitedDependentColor(CSSPropertyBorderRightColor).rgb()) : currentColorOrValidColor(style, style->borderRightColor());
2588         case CSSPropertyBorderBottomColor:
2589             return m_allowVisitedStyle ? cssValuePool.createColorValue(style->visitedDependentColor(CSSPropertyBorderBottomColor).rgb()) : currentColorOrValidColor(style, style->borderBottomColor());
2590         case CSSPropertyBorderLeftColor:
2591             return m_allowVisitedStyle ? cssValuePool.createColorValue(style->visitedDependentColor(CSSPropertyBorderLeftColor).rgb()) : currentColorOrValidColor(style, style->borderLeftColor());
2592         case CSSPropertyBorderTopStyle:
2593             return cssValuePool.createValue(style->borderTopStyle());
2594         case CSSPropertyBorderRightStyle:
2595             return cssValuePool.createValue(style->borderRightStyle());
2596         case CSSPropertyBorderBottomStyle:
2597             return cssValuePool.createValue(style->borderBottomStyle());
2598         case CSSPropertyBorderLeftStyle:
2599             return cssValuePool.createValue(style->borderLeftStyle());
2600         case CSSPropertyBorderTopWidth:
2601             return zoomAdjustedPixelValue(style->borderTopWidth(), *style);
2602         case CSSPropertyBorderRightWidth:
2603             return zoomAdjustedPixelValue(style->borderRightWidth(), *style);
2604         case CSSPropertyBorderBottomWidth:
2605             return zoomAdjustedPixelValue(style->borderBottomWidth(), *style);
2606         case CSSPropertyBorderLeftWidth:
2607             return zoomAdjustedPixelValue(style->borderLeftWidth(), *style);
2608         case CSSPropertyBottom:
2609             return positionOffsetValue(*style, CSSPropertyBottom);
2610         case CSSPropertyWebkitBoxAlign:
2611             return cssValuePool.createValue(style->boxAlign());
2612 #if ENABLE(CSS_BOX_DECORATION_BREAK)
2613         case CSSPropertyWebkitBoxDecorationBreak:
2614             if (style->boxDecorationBreak() == DSLICE)
2615                 return cssValuePool.createIdentifierValue(CSSValueSlice);
2616         return cssValuePool.createIdentifierValue(CSSValueClone);
2617 #endif
2618         case CSSPropertyWebkitBoxDirection:
2619             return cssValuePool.createValue(style->boxDirection());
2620         case CSSPropertyWebkitBoxFlex:
2621             return cssValuePool.createValue(style->boxFlex(), CSSPrimitiveValue::CSS_NUMBER);
2622         case CSSPropertyWebkitBoxFlexGroup:
2623             return cssValuePool.createValue(style->boxFlexGroup(), CSSPrimitiveValue::CSS_NUMBER);
2624         case CSSPropertyWebkitBoxLines:
2625             return cssValuePool.createValue(style->boxLines());
2626         case CSSPropertyWebkitBoxOrdinalGroup:
2627             return cssValuePool.createValue(style->boxOrdinalGroup(), CSSPrimitiveValue::CSS_NUMBER);
2628         case CSSPropertyWebkitBoxOrient:
2629             return cssValuePool.createValue(style->boxOrient());
2630         case CSSPropertyWebkitBoxPack:
2631             return cssValuePool.createValue(style->boxPack());
2632         case CSSPropertyWebkitBoxReflect:
2633             return valueForReflection(style->boxReflect(), *style);
2634         case CSSPropertyBoxShadow:
2635         case CSSPropertyWebkitBoxShadow:
2636             return valueForShadow(style->boxShadow(), propertyID, *style);
2637         case CSSPropertyCaptionSide:
2638             return cssValuePool.createValue(style->captionSide());
2639         case CSSPropertyClear:
2640             return cssValuePool.createValue(style->clear());
2641         case CSSPropertyColor:
2642             return cssValuePool.createColorValue(m_allowVisitedStyle ? style->visitedDependentColor(CSSPropertyColor).rgb() : style->color().rgb());
2643         case CSSPropertyWebkitPrintColorAdjust:
2644             return cssValuePool.createValue(style->printColorAdjust());
2645         case CSSPropertyWebkitColumnAxis:
2646             return cssValuePool.createValue(style->columnAxis());
2647         case CSSPropertyColumnCount:
2648             if (style->hasAutoColumnCount())
2649                 return cssValuePool.createIdentifierValue(CSSValueAuto);
2650             return cssValuePool.createValue(style->columnCount(), CSSPrimitiveValue::CSS_NUMBER);
2651         case CSSPropertyColumnFill:
2652             return cssValuePool.createValue(style->columnFill());
2653         case CSSPropertyColumnGap:
2654             if (style->hasNormalColumnGap())
2655                 return cssValuePool.createIdentifierValue(CSSValueNormal);
2656             return zoomAdjustedPixelValue(style->columnGap(), *style);
2657         case CSSPropertyColumnProgression:
2658             return cssValuePool.createValue(style->columnProgression());
2659         case CSSPropertyColumnRuleColor:
2660             return m_allowVisitedStyle ? cssValuePool.createColorValue(style->visitedDependentColor(CSSPropertyOutlineColor).rgb()) : currentColorOrValidColor(style, style->columnRuleColor());
2661         case CSSPropertyColumnRuleStyle:
2662             return cssValuePool.createValue(style->columnRuleStyle());
2663         case CSSPropertyColumnRuleWidth:
2664             return zoomAdjustedPixelValue(style->columnRuleWidth(), *style);
2665         case CSSPropertyColumnSpan:
2666             return cssValuePool.createIdentifierValue(style->columnSpan() ? CSSValueAll : CSSValueNone);
2667         case CSSPropertyWebkitColumnBreakAfter:
2668             return cssValuePool.createValue(convertToColumnBreak(style->breakAfter()));
2669         case CSSPropertyWebkitColumnBreakBefore:
2670             return cssValuePool.createValue(convertToColumnBreak(style->breakBefore()));
2671         case CSSPropertyWebkitColumnBreakInside:
2672             return cssValuePool.createValue(convertToColumnBreak(style->breakInside()));
2673         case CSSPropertyColumnWidth:
2674             if (style->hasAutoColumnWidth())
2675                 return cssValuePool.createIdentifierValue(CSSValueAuto);
2676             return zoomAdjustedPixelValue(style->columnWidth(), *style);
2677         case CSSPropertyTabSize:
2678             return cssValuePool.createValue(style->tabSize(), CSSPrimitiveValue::CSS_NUMBER);
2679 #if ENABLE(CSS_REGIONS)
2680         case CSSPropertyWebkitRegionBreakAfter:
2681             return cssValuePool.createValue(convertToRegionBreak(style->breakAfter()));
2682         case CSSPropertyWebkitRegionBreakBefore:
2683             return cssValuePool.createValue(convertToRegionBreak(style->breakBefore()));
2684         case CSSPropertyWebkitRegionBreakInside:
2685             return cssValuePool.createValue(convertToRegionBreak(style->breakInside()));
2686 #endif
2687         case CSSPropertyCursor: {
2688             RefPtr<CSSValueList> list;
2689             CursorList* cursors = style->cursors();
2690             if (cursors && cursors->size() > 0) {
2691                 list = CSSValueList::createCommaSeparated();
2692                 for (unsigned i = 0; i < cursors->size(); ++i)
2693                     if (StyleImage* image = cursors->at(i).image())
2694                         list->append(*image->cssValue());
2695             }
2696             auto value = cssValuePool.createValue(style->cursor());
2697             if (list) {
2698                 list->append(WTFMove(value));
2699                 return list;
2700             }
2701             return WTFMove(value);
2702         }
2703 #if ENABLE(CURSOR_VISIBILITY)
2704         case CSSPropertyWebkitCursorVisibility:
2705             return cssValuePool.createValue(style->cursorVisibility());
2706 #endif
2707         case CSSPropertyDirection:
2708             return cssValuePool.createValue(style->direction());
2709         case CSSPropertyDisplay:
2710             return cssValuePool.createValue(style->display());
2711         case CSSPropertyEmptyCells:
2712             return cssValuePool.createValue(style->emptyCells());
2713         case CSSPropertyAlignContent:
2714             return valueForContentPositionAndDistributionWithOverflowAlignment(style->alignContent());
2715         case CSSPropertyAlignItems:
2716             return valueForItemPositionWithOverflowAlignment(resolveContainerAlignmentAuto(style->alignItemsPosition(), renderer), style->alignItemsOverflowAlignment(), NonLegacyPosition);
2717         case CSSPropertyAlignSelf: {
2718             OverflowAlignment overflow = style->alignSelfOverflowAlignment();
2719             ItemPosition alignSelf = resolveSelfAlignmentAuto(style->alignSelfPosition(), overflow, renderer);
2720             return valueForItemPositionWithOverflowAlignment(alignSelf, overflow, NonLegacyPosition);
2721         }
2722         case CSSPropertyFlex:
2723             return getCSSPropertyValuesForShorthandProperties(flexShorthand());
2724         case CSSPropertyFlexBasis:
2725             return cssValuePool.createValue(style->flexBasis());
2726         case CSSPropertyFlexDirection:
2727             return cssValuePool.createValue(style->flexDirection());
2728         case CSSPropertyFlexFlow:
2729             return getCSSPropertyValuesForShorthandProperties(flexFlowShorthand());
2730         case CSSPropertyFlexGrow:
2731             return cssValuePool.createValue(style->flexGrow());
2732         case CSSPropertyFlexShrink:
2733             return cssValuePool.createValue(style->flexShrink());
2734         case CSSPropertyFlexWrap:
2735             return cssValuePool.createValue(style->flexWrap());
2736         case CSSPropertyJustifyContent:
2737             return valueForContentPositionAndDistributionWithOverflowAlignment(style->justifyContent());
2738         case CSSPropertyJustifyItems:
2739             return valueForItemPositionWithOverflowAlignment(resolveContainerAlignmentAuto(style->justifyItemsPosition(), renderer), style->justifyItemsOverflowAlignment(), style->justifyItemsPositionType());
2740         case CSSPropertyJustifySelf: {
2741             OverflowAlignment overflow = style->justifySelfOverflowAlignment();
2742             ItemPosition justifySelf = resolveSelfAlignmentAuto(style->justifySelfPosition(), overflow, renderer);
2743             return valueForItemPositionWithOverflowAlignment(justifySelf, overflow, NonLegacyPosition);
2744         }
2745         case CSSPropertyOrder:
2746             return cssValuePool.createValue(style->order(), CSSPrimitiveValue::CSS_NUMBER);
2747         case CSSPropertyFloat:
2748             if (style->display() != NONE && style->hasOutOfFlowPosition())
2749                 return cssValuePool.createIdentifierValue(CSSValueNone);
2750             return cssValuePool.createValue(style->floating());
2751         case CSSPropertyFont: {
2752             RefPtr<CSSFontValue> computedFont = CSSFontValue::create();
2753             computedFont->style = fontStyleFromStyle(style);
2754             if (style->fontDescription().variantCaps() == FontVariantCaps::Small)
2755                 computedFont->variant = CSSValuePool::singleton().createIdentifierValue(CSSValueSmallCaps);
2756             else
2757                 computedFont->variant = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
2758             computedFont->weight = fontWeightFromStyle(style);
2759             computedFont->size = fontSizeFromStyle(*style);
2760             computedFont->lineHeight = lineHeightFromStyle(*style);
2761             computedFont->family = fontFamilyFromStyle(style);
2762             return computedFont;
2763         }
2764         case CSSPropertyFontFamily: {
2765             RefPtr<CSSValueList> fontFamilyList = fontFamilyFromStyle(style);
2766             // If there's only a single family, return that as a CSSPrimitiveValue.
2767             // NOTE: Gecko always returns this as a comma-separated CSSPrimitiveValue string.
2768             if (fontFamilyList->length() == 1)
2769                 return fontFamilyList->item(0);
2770             return fontFamilyList;
2771         }
2772         case CSSPropertyFontSize:
2773             return fontSizeFromStyle(*style);
2774         case CSSPropertyFontStyle:
2775             return fontStyleFromStyle(style);
2776         case CSSPropertyFontVariant:
2777             return fontVariantFromStyle(style);
2778         case CSSPropertyFontWeight:
2779             return fontWeightFromStyle(style);
2780         case CSSPropertyFontSynthesis:
2781             return fontSynthesisFromStyle(*style);
2782         case CSSPropertyFontFeatureSettings: {
2783             const FontFeatureSettings& featureSettings = style->fontDescription().featureSettings();
2784             if (!featureSettings.size())
2785                 return cssValuePool.createIdentifierValue(CSSValueNormal);
2786             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
2787             for (auto& feature : featureSettings)
2788                 list->append(CSSFontFeatureValue::create(FontFeatureTag(feature.tag()), feature.value()));
2789             return list;
2790         }
2791 #if ENABLE(CSS_GRID_LAYOUT)
2792         case CSSPropertyWebkitGridAutoFlow: {
2793             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2794             ASSERT(style->isGridAutoFlowDirectionRow() || style->isGridAutoFlowDirectionColumn());
2795             if (style->isGridAutoFlowDirectionRow())
2796                 list->append(cssValuePool.createIdentifierValue(CSSValueRow));
2797             else
2798                 list->append(cssValuePool.createIdentifierValue(CSSValueColumn));
2799
2800             if (style->isGridAutoFlowAlgorithmDense())
2801                 list->append(cssValuePool.createIdentifierValue(CSSValueDense));
2802
2803             return list;
2804         }
2805
2806         // Specs mention that getComputedStyle() should return the used value of the property instead of the computed
2807         // one for grid-definition-{rows|columns} but not for the grid-auto-{rows|columns} as things like
2808         // grid-auto-columns: 2fr; cannot be resolved to a value in pixels as the '2fr' means very different things
2809         // depending on the size of the explicit grid or the number of implicit tracks added to the grid. See
2810         // http://lists.w3.org/Archives/Public/www-style/2013Nov/0014.html
2811         case CSSPropertyWebkitGridAutoColumns:
2812             return specifiedValueForGridTrackSize(style->gridAutoColumns(), *style);
2813         case CSSPropertyWebkitGridAutoRows:
2814             return specifiedValueForGridTrackSize(style->gridAutoRows(), *style);
2815
2816         case CSSPropertyWebkitGridTemplateColumns:
2817             return valueForGridTrackList(ForColumns, renderer, *style);
2818         case CSSPropertyWebkitGridTemplateRows:
2819             return valueForGridTrackList(ForRows, renderer, *style);
2820
2821         case CSSPropertyWebkitGridColumnStart:
2822             return valueForGridPosition(style->gridItemColumnStart());
2823         case CSSPropertyWebkitGridColumnEnd:
2824             return valueForGridPosition(style->gridItemColumnEnd());
2825         case CSSPropertyWebkitGridRowStart:
2826             return valueForGridPosition(style->gridItemRowStart());
2827         case CSSPropertyWebkitGridRowEnd:
2828             return valueForGridPosition(style->gridItemRowEnd());
2829         case CSSPropertyWebkitGridArea:
2830             return getCSSPropertyValuesForGridShorthand(webkitGridAreaShorthand());
2831         case CSSPropertyWebkitGridTemplate:
2832             return getCSSPropertyValuesForGridShorthand(webkitGridTemplateShorthand());
2833         case CSSPropertyWebkitGrid:
2834             return getCSSPropertyValuesForGridShorthand(webkitGridShorthand());
2835         case CSSPropertyWebkitGridColumn:
2836             return getCSSPropertyValuesForGridShorthand(webkitGridColumnShorthand());
2837         case CSSPropertyWebkitGridRow:
2838             return getCSSPropertyValuesForGridShorthand(webkitGridRowShorthand());
2839
2840         case CSSPropertyWebkitGridTemplateAreas:
2841             if (!style->namedGridAreaRowCount()) {
2842                 ASSERT(!style->namedGridAreaColumnCount());
2843                 return cssValuePool.createIdentifierValue(CSSValueNone);
2844             }
2845
2846             return CSSGridTemplateAreasValue::create(style->namedGridArea(), style->namedGridAreaRowCount(), style->namedGridAreaColumnCount());
2847         case CSSPropertyWebkitGridColumnGap:
2848             return zoomAdjustedPixelValueForLength(style->gridColumnGap(), *style);
2849         case CSSPropertyWebkitGridRowGap:
2850             return zoomAdjustedPixelValueForLength(style->gridRowGap(), *style);
2851         case CSSPropertyWebkitGridGap:
2852             return getCSSPropertyValuesForGridShorthand(webkitGridGapShorthand());
2853 #endif /* ENABLE(CSS_GRID_LAYOUT) */
2854         case CSSPropertyHeight:
2855             if (renderer && !renderer->isRenderSVGModelObject()) {
2856                 // According to http://www.w3.org/TR/CSS2/visudet.html#the-height-property,
2857                 // the "height" property does not apply for non-replaced inline elements.
2858                 if (!renderer->isReplaced() && renderer->isInline())
2859                     return cssValuePool.createIdentifierValue(CSSValueAuto);
2860                 return zoomAdjustedPixelValue(sizingBox(*renderer).height(), *style);
2861             }
2862             return zoomAdjustedPixelValueForLength(style->height(), *style);
2863         case CSSPropertyWebkitHyphens:
2864             return cssValuePool.createValue(style->hyphens());
2865         case CSSPropertyWebkitHyphenateCharacter:
2866             if (style->hyphenationString().isNull())
2867                 return cssValuePool.createIdentifierValue(CSSValueAuto);
2868             return cssValuePool.createValue(style->hyphenationString(), CSSPrimitiveValue::CSS_STRING);
2869         case CSSPropertyWebkitHyphenateLimitAfter:
2870             if (style->hyphenationLimitAfter() < 0)
2871                 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
2872             return CSSPrimitiveValue::create(style->hyphenationLimitAfter(), CSSPrimitiveValue::CSS_NUMBER);
2873         case CSSPropertyWebkitHyphenateLimitBefore:
2874             if (style->hyphenationLimitBefore() < 0)
2875                 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
2876             return CSSPrimitiveValue::create(style->hyphenationLimitBefore(), CSSPrimitiveValue::CSS_NUMBER);
2877         case CSSPropertyWebkitHyphenateLimitLines:
2878             if (style->hyphenationLimitLines() < 0)
2879                 return CSSPrimitiveValue::createIdentifier(CSSValueNoLimit);
2880             return CSSPrimitiveValue::create(style->hyphenationLimitLines(), CSSPrimitiveValue::CSS_NUMBER);
2881         case CSSPropertyWebkitBorderFit:
2882             if (style->borderFit() == BorderFitBorder)
2883                 return cssValuePool.createIdentifierValue(CSSValueBorder);
2884             return cssValuePool.createIdentifierValue(CSSValueLines);
2885 #if ENABLE(CSS_IMAGE_ORIENTATION)
2886         case CSSPropertyImageOrientation:
2887             return cssValuePool.createValue(style->imageOrientation());
2888 #endif
2889         case CSSPropertyImageRendering:
2890             return CSSPrimitiveValue::create(style->imageRendering());
2891 #if ENABLE(CSS_IMAGE_RESOLUTION)
2892         case CSSPropertyImageResolution:
2893             return cssValuePool.createValue(style->imageResolution(), CSSPrimitiveValue::CSS_DPPX);
2894 #endif
2895         case CSSPropertyLeft:
2896             return positionOffsetValue(*style, CSSPropertyLeft);
2897         case CSSPropertyLetterSpacing:
2898             if (!style->letterSpacing())
2899                 return cssValuePool.createIdentifierValue(CSSValueNormal);
2900             return zoomAdjustedPixelValue(style->letterSpacing(), *style);
2901         case CSSPropertyWebkitLineClamp:
2902             if (style->lineClamp().isNone())
2903                 return cssValuePool.createIdentifierValue(CSSValueNone);
2904             return cssValuePool.createValue(style->lineClamp().value(), style->lineClamp().isPercentage() ? CSSPrimitiveValue::CSS_PERCENTAGE : CSSPrimitiveValue::CSS_NUMBER);
2905         case CSSPropertyLineHeight:
2906             return lineHeightFromStyle(*style);
2907         case CSSPropertyListStyleImage:
2908             if (style->listStyleImage())
2909                 return style->listStyleImage()->cssValue();
2910             return cssValuePool.createIdentifierValue(CSSValueNone);
2911         case CSSPropertyListStylePosition:
2912             return cssValuePool.createValue(style->listStylePosition());
2913         case CSSPropertyListStyleType:
2914             return cssValuePool.createValue(style->listStyleType());
2915         case CSSPropertyWebkitLocale:
2916             if (style->locale().isNull())
2917                 return cssValuePool.createIdentifierValue(CSSValueAuto);
2918             return cssValuePool.createValue(style->locale(), CSSPrimitiveValue::CSS_STRING);
2919         case CSSPropertyMarginTop:
2920             return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::marginTop, &RenderBoxModelObject::marginTop>(*style, renderer);
2921         case CSSPropertyMarginRight: {
2922             Length marginRight = style->marginRight();
2923             if (marginRight.isFixed() || !is<RenderBox>(renderer))
2924                 return zoomAdjustedPixelValueForLength(marginRight, *style);
2925             float value;
2926             if (marginRight.isPercentOrCalculated()) {
2927                 // RenderBox gives a marginRight() that is the distance between the right-edge of the child box
2928                 // and the right-edge of the containing box, when display == BLOCK. Let's calculate the absolute
2929                 // value of the specified margin-right % instead of relying on RenderBox's marginRight() value.
2930                 value = minimumValueForLength(marginRight, downcast<RenderBox>(*renderer).containingBlockLogicalWidthForContent());
2931             } else
2932                 value = downcast<RenderBox>(*renderer).marginRight();
2933             return zoomAdjustedPixelValue(value, *style);
2934         }
2935         case CSSPropertyMarginBottom:
2936             return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::marginBottom, &RenderBoxModelObject::marginBottom>(*style, renderer);
2937         case CSSPropertyMarginLeft:
2938             return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::marginLeft, &RenderBoxModelObject::marginLeft>(*style, renderer);
2939         case CSSPropertyWebkitMarqueeDirection:
2940             return cssValuePool.createValue(style->marqueeDirection());
2941         case CSSPropertyWebkitMarqueeIncrement:
2942             return cssValuePool.createValue(style->marqueeIncrement());
2943         case CSSPropertyWebkitMarqueeRepetition:
2944             if (style->marqueeLoopCount() < 0)
2945                 return cssValuePool.createIdentifierValue(CSSValueInfinite);
2946             return cssValuePool.createValue(style->marqueeLoopCount(), CSSPrimitiveValue::CSS_NUMBER);
2947         case CSSPropertyWebkitMarqueeStyle:
2948             return cssValuePool.createValue(style->marqueeBehavior());
2949         case CSSPropertyWebkitUserModify:
2950             return cssValuePool.createValue(style->userModify());
2951         case CSSPropertyMaxHeight: {
2952             const Length& maxHeight = style->maxHeight();
2953             if (maxHeight.isUndefined())
2954                 return cssValuePool.createIdentifierValue(CSSValueNone);
2955             return zoomAdjustedPixelValueForLength(maxHeight, *style);
2956         }
2957         case CSSPropertyMaxWidth: {
2958             const Length& maxWidth = style->maxWidth();
2959             if (maxWidth.isUndefined())
2960                 return cssValuePool.createIdentifierValue(CSSValueNone);
2961             return zoomAdjustedPixelValueForLength(maxWidth, *style);
2962         }
2963         case CSSPropertyMinHeight:
2964             if (style->minHeight().isAuto()) {
2965                 if (isFlexOrGrid(styledNode->parentNode()))
2966                     return cssValuePool.createIdentifierValue(CSSValueAuto);
2967                 return zoomAdjustedPixelValue(0, *style);
2968             }
2969             return zoomAdjustedPixelValueForLength(style->minHeight(), *style);
2970         case CSSPropertyMinWidth:
2971             if (style->minWidth().isAuto()) {
2972                 if (isFlexOrGrid(styledNode->parentNode()))
2973                     return cssValuePool.createIdentifierValue(CSSValueAuto);
2974                 return zoomAdjustedPixelValue(0, *style);
2975             }
2976             return zoomAdjustedPixelValueForLength(style->minWidth(), *style);
2977         case CSSPropertyObjectFit:
2978             return cssValuePool.createValue(style->objectFit());
2979         case CSSPropertyObjectPosition: {
2980             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2981             list->append(zoomAdjustedPixelValueForLength(style->objectPosition().x(), *style));
2982             list->append(zoomAdjustedPixelValueForLength(style->objectPosition().y(), *style));
2983             return list;
2984         }
2985         case CSSPropertyOpacity:
2986             return cssValuePool.createValue(style->opacity(), CSSPrimitiveValue::CSS_NUMBER);
2987         case CSSPropertyOrphans:
2988             if (style->hasAutoOrphans())
2989                 return cssValuePool.createIdentifierValue(CSSValueAuto);
2990             return cssValuePool.createValue(style->orphans(), CSSPrimitiveValue::CSS_NUMBER);
2991         case CSSPropertyOutlineColor:
2992             return m_allowVisitedStyle ? cssValuePool.createColorValue(style->visitedDependentColor(CSSPropertyOutlineColor).rgb()) : currentColorOrValidColor(style, style->outlineColor());
2993         case CSSPropertyOutlineOffset:
2994             return zoomAdjustedPixelValue(style->outlineOffset(), *style);
2995         case CSSPropertyOutlineStyle:
2996             if (style->outlineStyleIsAuto())
2997                 return cssValuePool.createIdentifierValue(CSSValueAuto);
2998             return cssValuePool.createValue(style->outlineStyle());
2999         case CSSPropertyOutlineWidth:
3000             return zoomAdjustedPixelValue(style->outlineWidth(), *style);
3001         case CSSPropertyOverflow:
3002             return cssValuePool.createValue(std::max(style->overflowX(), style->overflowY()));
3003         case CSSPropertyOverflowWrap:
3004             return cssValuePool.createValue(style->overflowWrap());
3005         case CSSPropertyOverflowX:
3006             return cssValuePool.createValue(style->overflowX());
3007         case CSSPropertyOverflowY:
3008             return cssValuePool.createValue(style->overflowY());
3009         case CSSPropertyPaddingTop:
3010             return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::paddingTop, &RenderBoxModelObject::computedCSSPaddingTop>(*style, renderer);
3011         case CSSPropertyPaddingRight:
3012             return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::paddingRight, &RenderBoxModelObject::computedCSSPaddingRight>(*style, renderer);
3013         case CSSPropertyPaddingBottom:
3014             return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::paddingBottom, &RenderBoxModelObject::computedCSSPaddingBottom>(*style, renderer);
3015         case CSSPropertyPaddingLeft:
3016             return zoomAdjustedPaddingOrMarginPixelValue<&RenderStyle::paddingLeft, &RenderBoxModelObject::computedCSSPaddingLeft>(*style, renderer);
3017         case CSSPropertyPageBreakAfter:
3018             return cssValuePool.createValue(convertToPageBreak(style->breakAfter()));
3019         case CSSPropertyPageBreakBefore:
3020             return cssValuePool.createValue(convertToPageBreak(style->breakBefore()));
3021         case CSSPropertyPageBreakInside:
3022             return cssValuePool.createValue(convertToPageBreak(style->breakInside()));
3023         case CSSPropertyBreakAfter:
3024             return cssValuePool.createValue(style->breakAfter());
3025         case CSSPropertyBreakBefore:
3026             return cssValuePool.createValue(style->breakBefore());
3027         case CSSPropertyBreakInside:
3028             return cssValuePool.createValue(style->breakInside());
3029         case CSSPropertyHangingPunctuation:
3030             return hangingPunctuationToCSSValue(style->hangingPunctuation());
3031         case CSSPropertyPosition:
3032             return cssValuePool.createValue(style->position());
3033         case CSSPropertyRight:
3034             return positionOffsetValue(*style, CSSPropertyRight);
3035         case CSSPropertyWebkitRubyPosition:
3036             return cssValuePool.createValue(style->rubyPosition());
3037         case CSSPropertyTableLayout:
3038             return cssValuePool.createValue(style->tableLayout());
3039         case CSSPropertyTextAlign:
3040             return cssValuePool.createValue(style->textAlign());
3041         case CSSPropertyTextDecoration:
3042             return renderTextDecorationFlagsToCSSValue(style->textDecoration());
3043 #if ENABLE(CSS3_TEXT)
3044         case CSSPropertyWebkitTextAlignLast:
3045             return cssValuePool.createValue(style->textAlignLast());
3046         case CSSPropertyWebkitTextJustify:
3047             return cssValuePool.createValue(style->textJustify());
3048 #endif // CSS3_TEXT
3049         case CSSPropertyWebkitTextDecoration:
3050             return getCSSPropertyValuesForShorthandProperties(webkitTextDecorationShorthand());
3051         case CSSPropertyWebkitTextDecorationLine:
3052             return renderTextDecorationFlagsToCSSValue(style->textDecoration());
3053         case CSSPropertyWebkitTextDecorationStyle:
3054             return renderTextDecorationStyleFlagsToCSSValue(style->textDecorationStyle());
3055         case CSSPropertyWebkitTextDecorationColor:
3056             return currentColorOrValidColor(style, style->textDecorationColor());
3057         case CSSPropertyWebkitTextDecorationSkip:
3058             return renderTextDecorationSkipFlagsToCSSValue(style->textDecorationSkip());
3059         case CSSPropertyWebkitTextUnderlinePosition:
3060             return cssValuePool.createValue(style->textUnderlinePosition());
3061         case CSSPropertyWebkitTextDecorationsInEffect:
3062             return renderTextDecorationFlagsToCSSValue(style->textDecorationsInEffect());
3063         case CSSPropertyWebkitTextFillColor:
3064             return currentColorOrValidColor(style, style->textFillColor());
3065         case CSSPropertyWebkitTextEmphasisColor:
3066             return currentColorOrValidColor(style, style->textEmphasisColor());
3067         case CSSPropertyWebkitTextEmphasisPosition:
3068             return renderEmphasisPositionFlagsToCSSValue(style->textEmphasisPosition());
3069         case CSSPropertyWebkitTextEmphasisStyle:
3070             switch (style->textEmphasisMark()) {
3071             case TextEmphasisMarkNone:
3072                 return cssValuePool.createIdentifierValue(CSSValueNone);
3073             case TextEmphasisMarkCustom:
3074                 return cssValuePool.createValue(style->textEmphasisCustomMark(), CSSPrimitiveValue::CSS_STRING);
3075             case TextEmphasisMarkAuto:
3076                 ASSERT_NOT_REACHED();
3077 #if ASSERT_DISABLED
3078                 FALLTHROUGH;
3079 #endif
3080             case TextEmphasisMarkDot:
3081             case TextEmphasisMarkCircle:
3082             case TextEmphasisMarkDoubleCircle:
3083             case TextEmphasisMarkTriangle:
3084             case TextEmphasisMarkSesame: {
3085                 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3086                 list->append(cssValuePool.createValue(style->textEmphasisFill()));
3087                 list->append(cssValuePool.createValue(style->textEmphasisMark()));
3088                 return list;
3089             }
3090             }
3091         case CSSPropertyTextIndent: {
3092             // If CSS3_TEXT is disabled or text-indent has only one value(<length> | <percentage>),
3093             // getPropertyCSSValue() returns CSSValue.
3094             RefPtr<CSSValue> textIndent = zoomAdjustedPixelValueForLength(style->textIndent(), *style);
3095 #if ENABLE(CSS3_TEXT)
3096             // If CSS3_TEXT is enabled and text-indent has -webkit-each-line or -webkit-hanging,
3097             // getPropertyCSSValue() returns CSSValueList.
3098             if (style->textIndentLine() == TextIndentEachLine || style->textIndentType() == TextIndentHanging) {
3099                 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3100                 list->append(textIndent.releaseNonNull());
3101                 if (style->textIndentLine() == TextIndentEachLine)
3102                     list->append(cssValuePool.createIdentifierValue(CSSValueWebkitEachLine));
3103                 if (style->textIndentType() == TextIndentHanging)
3104                     list->append(cssValuePool.createIdentifierValue(CSSValueWebkitHanging));
3105                 return list;
3106             }
3107 #endif
3108             return textIndent;
3109         }
3110         case CSSPropertyTextShadow:
3111             return valueForShadow(style->textShadow(), propertyID, *style);
3112         case CSSPropertyTextRendering:
3113             return cssValuePool.createValue(style->fontDescription().textRenderingMode());
3114         case CSSPropertyTextOverflow:
3115             if (style->textOverflow())
3116                 return cssValuePool.createIdentifierValue(CSSValueEllipsis);
3117             return cssValuePool.createIdentifierValue(CSSValueClip);
3118         case CSSPropertyWebkitTextSecurity:
3119             return cssValuePool.createValue(style->textSecurity());
3120 #if ENABLE(IOS_TEXT_AUTOSIZING)
3121         case CSSPropertyWebkitTextSizeAdjust:
3122             if (style->textSizeAdjust().isAuto())
3123                 return cssValuePool.createIdentifierValue(CSSValueAuto);
3124             if (style->textSizeAdjust().isNone())
3125                 return cssValuePool.createIdentifierValue(CSSValueNone);
3126             return CSSPrimitiveValue::create(style->textSizeAdjust().percentage(), CSSPrimitiveValue::CSS_PERCENTAGE);
3127 #endif
3128         case CSSPropertyWebkitTextStrokeColor:
3129             return currentColorOrValidColor(style, style->textStrokeColor());
3130         case CSSPropertyWebkitTextStrokeWidth:
3131             return zoomAdjustedPixelValue(style->textStrokeWidth(), *style);
3132         case CSSPropertyTextTransform:
3133             return cssValuePool.createValue(style->textTransform());
3134         case CSSPropertyTop:
3135             return positionOffsetValue(*style, CSSPropertyTop);
3136         case CSSPropertyUnicodeBidi:
3137             return cssValuePool.createValue(style->unicodeBidi());
3138         case CSSPropertyVerticalAlign:
3139             switch (style->verticalAlign()) {
3140                 case BASELINE:
3141                     return cssValuePool.createIdentifierValue(CSSValueBaseline);
3142                 case MIDDLE:
3143                     return cssValuePool.createIdentifierValue(CSSValueMiddle);
3144                 case SUB:
3145                     return cssValuePool.createIdentifierValue(CSSValueSub);
3146                 case SUPER:
3147                     return cssValuePool.createIdentifierValue(CSSValueSuper);
3148                 case TEXT_TOP:
3149                     return cssValuePool.createIdentifierValue(CSSValueTextTop);
3150                 case TEXT_BOTTOM:
3151                     return cssValuePool.createIdentifierValue(CSSValueTextBottom);
3152                 case TOP:
3153                     return cssValuePool.createIdentifierValue(CSSValueTop);
3154                 case BOTTOM:
3155                     return cssValuePool.createIdentifierValue(CSSValueBottom);
3156                 case BASELINE_MIDDLE:
3157                     return cssValuePool.createIdentifierValue(CSSValueWebkitBaselineMiddle);
3158                 case LENGTH:
3159                     return cssValuePool.createValue(style->verticalAlignLength());
3160             }
3161             ASSERT_NOT_REACHED();
3162             return nullptr;
3163         case CSSPropertyVisibility:
3164             return cssValuePool.createValue(style->visibility());
3165         case CSSPropertyWhiteSpace:
3166             return cssValuePool.createValue(style->whiteSpace());
3167         case CSSPropertyWidows:
3168             if (style->hasAutoWidows())
3169                 return cssValuePool.createIdentifierValue(CSSValueAuto);
3170             return cssValuePool.createValue(style->widows(), CSSPrimitiveValue::CSS_NUMBER);
3171         case CSSPropertyWidth:
3172             if (renderer && !renderer->isRenderSVGModelObject()) {
3173                 // According to http://www.w3.org/TR/CSS2/visudet.html#the-width-property,
3174                 // the "width" property does not apply for non-replaced inline elements.
3175                 if (!renderer->isReplaced() && renderer->isInline())
3176                     return cssValuePool.createIdentifierValue(CSSValueAuto);
3177                 return zoomAdjustedPixelValue(sizingBox(*renderer).width(), *style);
3178             }
3179             return zoomAdjustedPixelValueForLength(style->width(), *style);
3180         case CSSPropertyWillChange:
3181             return getWillChangePropertyValue(style->willChange());
3182             break;
3183         case CSSPropertyWordBreak:
3184             return cssValuePool.createValue(style->wordBreak());
3185         case CSSPropertyWordSpacing:
3186             return zoomAdjustedPixelValue(style->fontCascade().wordSpacing(), *style);
3187         case CSSPropertyWordWrap:
3188             return cssValuePool.createValue(style->overflowWrap());
3189         case CSSPropertyWebkitLineBreak:
3190             return cssValuePool.createValue(style->lineBreak());
3191         case CSSPropertyWebkitNbspMode:
3192             return cssValuePool.createValue(style->nbspMode());
3193         case CSSPropertyResize:
3194             return cssValuePool.createValue(style->resize());
3195         case CSSPropertyWebkitFontKerning:
3196             return cssValuePool.createValue(style->fontDescription().kerning());
3197         case CSSPropertyWebkitFontSmoothing:
3198             return cssValuePool.createValue(style->fontDescription().fontSmoothing());
3199         case CSSPropertyFontVariantLigatures:
3200             return fontVariantLigaturesPropertyValue(style->fontDescription().variantCommonLigatures(), style->fontDescription().variantDiscretionaryLigatures(), style->fontDescription().variantHistoricalLigatures(), style->fontDescription().variantContextualAlternates());
3201         case CSSPropertyFontVariantPosition:
3202             return fontVariantPositionPropertyValue(style->fontDescription().variantPosition());
3203         case CSSPropertyFontVariantCaps:
3204             return fontVariantCapsPropertyValue(style->fontDescription().variantCaps());
3205         case CSSPropertyFontVariantNumeric:
3206             return fontVariantNumericPropertyValue(style->fontDescription().variantNumericFigure(), style->fontDescription().variantNumericSpacing(), style->fontDescription().variantNumericFraction(), style->fontDescription().variantNumericOrdinal(), style->fontDescription().variantNumericSlashedZero());
3207         case CSSPropertyFontVariantAlternates:
3208             return fontVariantAlternatesPropertyValue(style->fontDescription().variantAlternates());
3209         case CSSPropertyFontVariantEastAsian:
3210             return fontVariantEastAsianPropertyValue(style->fontDescription().variantEastAsianVariant(), style->fontDescription().variantEastAsianWidth(), style->fontDescription().variantEastAsianRuby());
3211         case CSSPropertyZIndex:
3212             if (style->hasAutoZIndex())
3213                 return cssValuePool.createIdentifierValue(CSSValueAuto);
3214             return cssValuePool.createValue(style->zIndex(), CSSPrimitiveValue::CSS_NUMBER);
3215         case CSSPropertyZoom:
3216             return cssValuePool.createValue(style->zoom(), CSSPrimitiveValue::CSS_NUMBER);
3217         case CSSPropertyBoxSizing:
3218             if (style->boxSizing() == CONTENT_BOX)
3219                 return cssValuePool.createIdentifierValue(CSSValueContentBox);
3220             return cssValuePool.createIdentifierValue(CSSValueBorderBox);
3221 #if ENABLE(DASHBOARD_SUPPORT)
3222         case CSSPropertyWebkitDashboardRegion:
3223         {
3224             const Vector<StyleDashboardRegion>& regions = style->dashboardRegions();
3225             unsigned count = regions.size();
3226             if (count == 1 && regions[0].type == StyleDashboardRegion::None)
3227                 return cssValuePool.createIdentifierValue(CSSValueNone);
3228
3229             RefPtr<DashboardRegion> firstRegion;
3230             DashboardRegion* previousRegion = nullptr;
3231             for (unsigned i = 0; i < count; i++) {
3232                 auto region = DashboardRegion::create();
3233                 StyleDashboardRegion styleRegion = regions[i];
3234
3235                 region->m_label = styleRegion.label;
3236                 LengthBox offset = styleRegion.offset;
3237                 region->setTop(zoomAdjustedPixelValue(offset.top().value(), *style));
3238                 region->setRight(zoomAdjustedPixelValue(offset.right().value(), *style));
3239                 region->setBottom(zoomAdjustedPixelValue(offset.bottom().value(), *style));
3240                 region->setLeft(zoomAdjustedPixelValue(offset.left().value(), *style));
3241                 region->m_isRectangle = (styleRegion.type == StyleDashboardRegion::Rectangle);
3242                 region->m_isCircle = (styleRegion.type == StyleDashboardRegion::Circle);
3243
3244                 if (previousRegion)
3245                     previousRegion->m_next = region.copyRef();
3246                 else
3247                     firstRegion = region.copyRef();
3248                 previousRegion = region.ptr();
3249             }
3250             return cssValuePool.createValue(WTFMove(firstRegion));
3251         }
3252 #endif
3253         case CSSPropertyAnimationDelay:
3254         case CSSPropertyWebkitAnimationDelay:
3255             return getDelayValue(style->animations());
3256         case CSSPropertyAnimationDirection:
3257         case CSSPropertyWebkitAnimationDirection: {
3258             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3259             const AnimationList* t = style->animations();
3260             if (t) {
3261                 for (size_t i = 0; i < t->size(); ++i) {
3262                     switch (t->animation(i).direction()) {
3263                     case Animation::AnimationDirectionNormal:
3264                         list->append(cssValuePool.createIdentifierValue(CSSValueNormal));
3265                         break;
3266                     case Animation::AnimationDirectionAlternate:
3267                         list->append(cssValuePool.createIdentifierValue(CSSValueAlternate));
3268                         break;
3269                     case Animation::AnimationDirectionReverse:
3270                         list->append(cssValuePool.createIdentifierValue(CSSValueReverse));
3271                         break;
3272                     case Animation::AnimationDirectionAlternateReverse:
3273                         list->append(cssValuePool.createIdentifierValue(CSSValueAlternateReverse));
3274                         break;
3275                     }
3276                 }
3277             } else
3278                 list->append(cssValuePool.createIdentifierValue(CSSValueNormal));
3279             return list;
3280         }
3281         case CSSPropertyAnimationDuration:
3282         case CSSPropertyWebkitAnimationDuration:
3283             return getDurationValue(style->animations());
3284         case CSSPropertyAnimationFillMode:
3285         case CSSPropertyWebkitAnimationFillMode: {
3286             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3287             const AnimationList* t = style->animations();
3288             if (t) {
3289                 for (size_t i = 0; i < t->size(); ++i) {
3290                     switch (t->animation(i).fillMode()) {
3291                     case AnimationFillModeNone:
3292                         list->append(cssValuePool.createIdentifierValue(CSSValueNone));
3293                         break;
3294                     case AnimationFillModeForwards:
3295                         list->append(cssValuePool.createIdentifierValue(CSSValueForwards));
3296                         break;
3297                     case AnimationFillModeBackwards:
3298                         list->append(cssValuePool.createIdentifierValue(CSSValueBackwards));
3299                         break;
3300                     case AnimationFillModeBoth:
3301                         list->append(cssValuePool.createIdentifierValue(CSSValueBoth));
3302                         break;
3303                     }
3304                 }
3305             } else
3306                 list->append(cssValuePool.createIdentifierValue(CSSValueNone));
3307             return list;
3308         }
3309         case CSSPropertyAnimationIterationCount:
3310         case CSSPropertyWebkitAnimationIterationCount: {
3311             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3312             const AnimationList* t = style->animations();
3313             if (t) {
3314                 for (size_t i = 0; i < t->size(); ++i) {
3315                     double iterationCount = t->animation(i).iterationCount();
3316                     if (iterationCount == Animation::IterationCountInfinite)
3317                         list->append(cssValuePool.createIdentifierValue(CSSValueInfinite));
3318                     else
3319                         list->append(cssValuePool.createValue(iterationCount, CSSPrimitiveValue::CSS_NUMBER));
3320                 }
3321             } else
3322                 list->append(cssValuePool.createValue(Animation::initialIterationCount(), CSSPrimitiveValue::CSS_NUMBER));
3323             return list;
3324         }
3325         case CSSPropertyAnimationName:
3326         case CSSPropertyWebkitAnimationName: {
3327             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3328             const AnimationList* t = style->animations();
3329             if (t) {
3330                 for (size_t i = 0; i < t->size(); ++i)
3331                     list->append(cssValuePool.createValue(t->animation(i).name(), CSSPrimitiveValue::CSS_STRING));
3332             } else
3333                 list->append(cssValuePool.createIdentifierValue(CSSValueNone));
3334             return list;
3335         }
3336         case CSSPropertyAnimationPlayState:
3337         case CSSPropertyWebkitAnimationPlayState: {
3338             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3339             const AnimationList* t = style->animations();
3340             if (t) {
3341                 for (size_t i = 0; i < t->size(); ++i) {
3342                     int prop = t->animation(i).playState();
3343                     if (prop == AnimPlayStatePlaying)
3344                         list->append(cssValuePool.createIdentifierValue(CSSValueRunning));
3345                     else
3346                         list->append(cssValuePool.createIdentifierValue(CSSValuePaused));
3347                 }
3348             } else
3349                 list->append(cssValuePool.createIdentifierValue(CSSValueRunning));
3350             return list;
3351         }
3352         case CSSPropertyAnimationTimingFunction:
3353         case CSSPropertyWebkitAnimationTimingFunction:
3354             return getTimingFunctionValue(style->animations());
3355 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
3356         case CSSPropertyWebkitAnimationTrigger:
3357             return getAnimationTriggerValue(style->animations(), *style);
3358 #endif
3359         case CSSPropertyWebkitAppearance:
3360             return cssValuePool.createValue(style->appearance());
3361         case CSSPropertyWebkitAspectRatio:
3362             if (style->aspectRatioType() == AspectRatioAuto)
3363                 return cssValuePool.createIdentifierValue(CSSValueAuto);
3364             if (style->aspectRatioType() == AspectRatioFromDimensions)
3365                 return cssValuePool.createIdentifierValue(CSSValueFromDimensions);
3366             if (style->aspectRatioType() == AspectRatioFromIntrinsic)
3367                 return cssValuePool.createIdentifierValue(CSSValueFromIntrinsic);
3368             return CSSAspectRatioValue::create(style->aspectRatioNumerator(), style->aspectRatioDenominator());
3369         case CSSPropertyWebkitBackfaceVisibility:
3370             return cssValuePool.createIdentifierValue((style->backfaceVisibility() == BackfaceVisibilityHidden) ? CSSValueHidden : CSSValueVisible);
3371         case CSSPropertyWebkitBorderImage:
3372             return valueForNinePieceImage(style->borderImage());
3373         case CSSPropertyBorderImageOutset:
3374             return valueForNinePieceImageQuad(style->borderImage().outset());
3375         case CSSPropertyBorderImageRepeat:
3376             return valueForNinePieceImageRepeat(style->borderImage());
3377         case CSSPropertyBorderImageSlice:
3378             return valueForNinePieceImageSlice(style->borderImage());
3379         case CSSPropertyBorderImageWidth:
3380             return valueForNinePieceImageQuad(style->borderImage().borderSlices());
3381         case CSSPropertyWebkitMaskBoxImage:
3382             return valueForNinePieceImage(style->maskBoxImage());
3383         case CSSPropertyWebkitMaskBoxImageOutset:
3384             return valueForNinePieceImageQuad(style->maskBoxImage().outset());
3385         case CSSPropertyWebkitMaskBoxImageRepeat:
3386             return valueForNinePieceImageRepeat(style->maskBoxImage());
3387         case CSSPropertyWebkitMaskBoxImageSlice:
3388             return valueForNinePieceImageSlice(style->maskBoxImage());
3389         case CSSPropertyWebkitMaskBoxImageWidth:
3390             return valueForNinePieceImageQuad(style->maskBoxImage().borderSlices());
3391         case CSSPropertyWebkitMaskBoxImageSource:
3392             if (style->maskBoxImageSource())
3393                 return style->maskBoxImageSource()->cssValue();
3394             return cssValuePool.createIdentifierValue(CSSValueNone);
3395         case CSSPropertyWebkitFontSizeDelta:
3396             // Not a real style property -- used by the editing engine -- so has no computed value.
3397             break;
3398         case CSSPropertyWebkitInitialLetter: {
3399             RefPtr<CSSPrimitiveValue> drop = !style->initialLetterDrop() ? cssValuePool.createIdentifierValue(CSSValueNormal) : cssValuePool.createValue(style->initialLetterDrop(), CSSPrimitiveValue::CSS_NUMBER);
3400             RefPtr<CSSPrimitiveValue> size = !style->initialLetterHeight() ? cssValuePool.createIdentifierValue(CSSValueNormal) : cssValuePool.createValue(style->initialLetterHeight(), CSSPrimitiveValue::CSS_NUMBER);
3401             return cssValuePool.createValue(Pair::create(drop.release(), size.release()));
3402         }
3403         case CSSPropertyWebkitMarginBottomCollapse:
3404         case CSSPropertyWebkitMarginAfterCollapse:
3405             return cssValuePool.createValue(style->marginAfterCollapse());
3406         case CSSPropertyWebkitMarginTopCollapse:
3407         case CSSPropertyWebkitMarginBeforeCollapse:
3408             return cssValuePool.createValue(style->marginBeforeCollapse());
3409 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
3410         case CSSPropertyWebkitOverflowScrolling:
3411             if (!style->useTouchOverflowScrolling())
3412                 return cssValuePool.createIdentifierValue(CSSValueAuto);
3413             return cssValuePool.createIdentifierValue(CSSValueTouch);
3414 #endif
3415         case CSSPropertyPerspective:
3416             if (!style->hasPerspective())
3417                 return cssValuePool.createIdentifierValue(CSSValueNone);
3418             return zoomAdjustedPixelValue(style->perspective(), *style);
3419         case CSSPropertyPerspectiveOrigin: {
3420             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3421             if (renderer) {
3422                 LayoutRect box;
3423                 if (is<RenderBox>(*renderer))
3424                     box = downcast<RenderBox>(*renderer).borderBoxRect();
3425
3426                 list->append(zoomAdjustedPixelValue(minimumValueForLength(style->perspectiveOriginX(), box.width()), *style));
3427                 list->append(zoomAdjustedPixelValue(minimumValueForLength(style->perspectiveOriginY(), box.height()), *style));
3428             }
3429             else {
3430                 list->append(zoomAdjustedPixelValueForLength(style->perspectiveOriginX(), *style));
3431                 list->append(zoomAdjustedPixelValueForLength(style->perspectiveOriginY(), *style));
3432
3433             }
3434             return list;
3435         }
3436         case CSSPropertyWebkitRtlOrdering:
3437             return cssValuePool.createIdentifierValue(style->rtlOrdering() ? CSSValueVisual : CSSValueLogical);
3438 #if ENABLE(TOUCH_EVENTS)
3439         case CSSPropertyWebkitTapHighlightColor:
3440             return currentColorOrValidColor(style, style->tapHighlightColor());
3441         case CSSPropertyTouchAction:
3442             return cssValuePool.createValue(style->touchAction());
3443 #endif
3444 #if PLATFORM(IOS)
3445         case CSSPropertyWebkitTouchCallout:
3446             return cssValuePool.createIdentifierValue(style->touchCalloutEnabled() ? CSSValueDefault : CSSValueNone);
3447 #endif
3448         case CSSPropertyWebkitUserDrag:
3449             return cssValuePool.createValue(style->userDrag());
3450         case CSSPropertyWebkitUserSelect:
3451             return cssValuePool.createValue(style->userSelect());
3452         case CSSPropertyBorderBottomLeftRadius:
3453             return getBorderRadiusCornerValue(style->borderBottomLeftRadius(), *style);
3454         case CSSPropertyBorderBottomRightRadius:
3455             return getBorderRadiusCornerValue(style->borderBottomRightRadius(), *style);
3456         case CSSPropertyBorderTopLeftRadius:
3457             return getBorderRadiusCornerValue(style->borderTopLeftRadius(), *style);
3458         case CSSPropertyBorderTopRightRadius:
3459             return getBorderRadiusCornerValue(style->borderTopRightRadius(), *style);
3460         case CSSPropertyClip: {
3461             if (!style->hasClip())
3462                 return cssValuePool.createIdentifierValue(CSSValueAuto);
3463             auto rect = Rect::create();
3464             rect->setTop(autoOrZoomAdjustedValue(style->clip().top(), *style));
3465             rect->setRight(autoOrZoomAdjustedValue(style->clip().right(), *style));
3466             rect->setBottom(autoOrZoomAdjustedValue(style->clip().bottom(), *style));
3467             rect->setLeft(autoOrZoomAdjustedValue(style->clip().left(), *style));
3468             return cssValuePool.createValue(WTFMove(rect));
3469         }
3470         case CSSPropertySpeak:
3471             return cssValuePool.createValue(style->speak());
3472         case CSSPropertyTransform:
3473             return computedTransform(renderer, *style);
3474         case CSSPropertyTransformOrigin: {
3475             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3476             if (renderer) {
3477                 LayoutRect box;
3478                 if (is<RenderBox>(*renderer))
3479                     box = downcast<RenderBox>(*renderer).borderBoxRect();
3480
3481                 list->append(zoomAdjustedPixelValue(minimumValueForLength(style->transformOriginX(), box.width()), *style));
3482                 list->append(zoomAdjustedPixelValue(minimumValueForLength(style->transformOriginY(), box.height()), *style));
3483                 if (style->transformOriginZ() != 0)
3484                     list->append(zoomAdjustedPixelValue(style->transformOriginZ(), *style));
3485             } else {
3486                 list->append(zoomAdjustedPixelValueForLength(style->transformOriginX(), *style));
3487                 list->append(zoomAdjustedPixelValueForLength(style->transformOriginY(), *style));
3488                 if (style->transformOriginZ() != 0)
3489                     list->append(zoomAdjustedPixelValue(style->transformOriginZ(), *style));
3490             }
3491             return list;
3492         }
3493         case CSSPropertyTransformStyle:
3494         case CSSPropertyWebkitTransformStyle:
3495             return cssValuePool.createIdentifierValue((style->transformStyle3D() == TransformStyle3DPreserve3D) ? CSSValuePreserve3d : CSSValueFlat);
3496         case CSSPropertyTransitionDelay:
3497         case CSSPropertyWebkitTransitionDelay:
3498             return getDelayValue(style->transitions());
3499         case CSSPropertyTransitionDuration:
3500         case CSSPropertyWebkitTransitionDuration:
3501             return getDurationValue(style->transitions());
3502         case CSSPropertyTransitionProperty:
3503         case CSSPropertyWebkitTransitionProperty:
3504             return getTransitionPropertyValue(style->transitions());
3505         case CSSPropertyTransitionTimingFunction:
3506         case CSSPropertyWebkitTransitionTimingFunction:
3507             return getTimingFunctionValue(style->transitions());
3508         case CSSPropertyTransition:
3509         case CSSPropertyWebkitTransition: {
3510             const AnimationList* animList = style->transitions();
3511             if (animList) {
3512                 RefPtr<CSSValueList> transitionsList = CSSValueList::createCommaSeparated();
3513                 for (size_t i = 0; i < animList->size(); ++i) {
3514                     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3515                     const Animation& animation = animList->animation(i);
3516                     list->append(createTransitionPropertyValue(animation));
3517                     list->append(cssValuePool.createValue(animation.duration(), CSSPrimitiveValue::CSS_S));
3518                     list->append(createTimingFunctionValue(animation.timingFunction().get()));
3519                     list->append(cssValuePool.createValue(animation.delay(), CSSPrimitiveValue::CSS_S));
3520                     transitionsList->append(list.releaseNonNull());
3521                 }
3522                 return transitionsList;
3523             }
3524
3525             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3526             // transition-property default value.
3527             list->append(cssValuePool.createIdentifierValue(CSSValueAll));
3528             list->append(cssValuePool.createValue(Animation::initialDuration(), CSSPrimitiveValue::CSS_S));
3529             list->append(createTimingFunctionValue(Animation::initialTimingFunction().get()));
3530             list->append(cssValuePool.createValue(Animation::initialDelay(), CSSPrimitiveValue::CSS_S));
3531             return list;
3532         }
3533         case CSSPropertyPointerEvents:
3534             return cssValuePool.createValue(style->pointerEvents());
3535         case CSSPropertyWebkitLineGrid:
3536             if (style->lineGrid().isNull())
3537                 return cssValuePool.createIdentifierValue(CSSValueNone);
3538             return cssValuePool.createValue(style->lineGrid(), CSSPrimitiveValue::CSS_STRING);
3539         case CSSPropertyWebkitLineSnap:
3540             return CSSPrimitiveValue::create(style->lineSnap());
3541         case CSSPropertyWebkitLineAlign:
3542             return CSSPrimitiveValue::create(style->lineAlign());
3543         case CSSPropertyWebkitWritingMode:
3544             return cssValuePool.createValue(style->writingMode());
3545         case CSSPropertyWebkitTextCombine:
3546             return cssValuePool.createValue(style->textCombine());
3547         case CSSPropertyWebkitTextOrientation:
3548             return CSSPrimitiveValue::create(style->textOrientation());
3549         case CSSPropertyWebkitLineBoxContain:
3550             return createLineBoxContainValue(style->lineBoxContain());
3551         case CSSPropertyAlt:
3552             return altTextToCSSValue(style);
3553         case CSSPropertyContent:
3554             return contentToCSSValue(style);
3555         case CSSPropertyCounterIncrement:
3556             return counterToCSSValue(style, propertyID);
3557         case CSSPropertyCounterReset:
3558             return counterToCSSValue(style, propertyID);
3559         case CSSPropertyWebkitClipPath: {
3560             ClipPathOperation* operation = style->clipPath();
3561             if (!operation)
3562                 return cssValuePool.createIdentifierValue(CSSValueNone);
3563             if (is<ReferenceClipPathOperation>(*operation)) {
3564                 const auto& referenceOperation = downcast<ReferenceClipPathOperation>(*operation);
3565                 return CSSPrimitiveValue::create(referenceOperation.url(), CSSPrimitiveValue::CSS_URI);
3566             }
3567             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
3568             if (is<ShapeClipPathOperation>(*operation)) {
3569                 const auto& shapeOperation = downcast<ShapeClipPathOperation>(*operation);
3570                 list->append(valueForBasicShape(*style, shapeOperation.basicShape()));
3571                 if (shapeOperation.referenceBox() != BoxMissing)
3572                     list->append(cssValuePool.createValue(shapeOperation.referenceBox()));
3573             }
3574             if (is<BoxClipPathOperation>(*operation)) {
3575                 const auto& boxOperation = downcast<BoxClipPathOperation>(*operation);
3576                 list->append(cssValuePool.createValue(boxOperation.referenceBox()));
3577             }
3578             return list;
3579         }
3580 #if ENABLE(CSS_REGIONS)
3581         case CSSPropertyWebkitFlowInto:
3582             if (!style->hasFlowInto())
3583                 return cssValuePool.createIdentifierValue(CSSValueNone);
3584             return cssValuePool.createValue(style->flowThread(), CSSPrimitiveValue::CSS_STRING);
3585         case CSSPropertyWebkitFlowFrom:
3586             if (!style->hasFlowFrom())
3587                 return cssValuePool.createIdentifierValue(CSSValueNone);
3588             return cssValuePool.createValue(style->regionThread(), CSSPrimitiveValue::CSS_STRING);
3589         case CSSPropertyWebkitRegionFragment:
3590             return cssValuePool.createValue(style->regionFragment());
3591 #endif
3592 #if ENABLE(CSS_SHAPES)
3593         case CSSPropertyWebkitShapeMargin:
3594             return cssValuePool.createValue(style->shapeMargin(), *style);
3595         case CSSPropertyWebkitShapeImageThreshold:
3596             return cssValuePool.createValue(style->shapeImageThreshold(), CSSPrimitiveValue::CSS_NUMBER);
3597         case CSSPropertyWebkitShapeOutside:
3598             return shapePropertyValue(*style, style->shapeOutside());
3599 #endif
3600         case CSSPropertyFilter:
3601             return valueForFilter(*style, style->filter());
3602 #if ENABLE(FILTERS_LEVEL_2)
3603         case CSSPropertyWebkitBackdropFilter:
3604             return valueForFilter(*style, style->backdropFilter());
3605 #endif
3606 #if ENABLE(CSS_COMPOSITING)
3607         case CSSPropertyMixBlendMode:
3608             return cssValuePool.createValue(style->blendMode());
3609         case CSSPropertyIsolation:
3610             return cssValuePool.createValue(style->isolation());
3611 #endif
3612         case CSSPropertyBackgroundBlendMode: {
3613             const FillLayer* layers = style->backgroundLayers();
3614             if (!layers->next())
3615                 return cssValuePool.createValue(layers->blendMode());
3616
3617             RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
3618             for (const FillLayer* currLayer = layers; currLayer; currLayer = currLayer->next())
3619                 list->append(cssValuePool.createValue(currLayer->blendMode()));
3620
3621             return list.release();
3622         }
3623         case CSSPropertyBackground:
3624             return getBackgroundShorthandValue();
3625         case CSSPropertyBorder: {
3626             RefPtr<CSSValue> value = propertyValue(CSSPropertyBorderTop, DoNotUpdateLayout);
3627             const CSSPropertyID properties[3] = { CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft };
3628             for (auto& property : properties) {
3629                 if (!compareCSSValuePtr<CSSValue>(value, propertyValue(property, DoNotUpdateLayout)))
3630                     return nullptr;
3631             }
3632             return value;
3633         }
3634         case CSSPropertyBorderBottom:
3635             return getCSSPropertyValuesForShorthandProperties(borderBottomShorthand());
3636         case CSSPropertyBorderColor:
3637             return getCSSPropertyValuesForSidesShorthand(borderColorShorthand());
3638         case CSSPropertyBorderLeft:
3639             return getCSSPropertyValuesForShorthandProperties(borderLeftShorthand());
3640         case CSSPropertyBorderImage:
3641             return valueForNinePieceImage(style->borderImage())