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