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