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