When no background-size is specified on the 2nd background layer, it takes the first...
[WebKit-https.git] / Source / WebCore / css / CSSToStyleMap.cpp
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4  * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5  * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
6  * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7  * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
9  * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Library General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public License
23  * along with this library; see the file COPYING.LIB.  If not, write to
24  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25  * Boston, MA 02110-1301, USA.
26  */
27
28 #include "config.h"
29 #include "CSSToStyleMap.h"
30
31 #include "Animation.h"
32 #include "CSSBorderImageSliceValue.h"
33 #include "CSSImageGeneratorValue.h"
34 #include "CSSImageSetValue.h"
35 #include "CSSImageValue.h"
36 #include "CSSPrimitiveValue.h"
37 #include "CSSPrimitiveValueMappings.h"
38 #include "CSSTimingFunctionValue.h"
39 #include "CSSValueKeywords.h"
40 #include "FillLayer.h"
41 #include "Pair.h"
42 #include "Rect.h"
43 #include "RenderView.h"
44 #include "StyleResolver.h"
45
46 namespace WebCore {
47
48 CSSToStyleMap::CSSToStyleMap(StyleResolver* resolver)
49     : m_resolver(resolver)
50 {
51 }
52
53 RenderStyle* CSSToStyleMap::style() const
54 {
55     return m_resolver->style();
56 }
57
58 RenderStyle* CSSToStyleMap::rootElementStyle() const
59 {
60     return m_resolver->rootElementStyle();
61 }
62
63 bool CSSToStyleMap::useSVGZoomRules() const
64 {
65     return m_resolver->useSVGZoomRules();
66 }
67
68 PassRefPtr<StyleImage> CSSToStyleMap::styleImage(CSSPropertyID propertyId, CSSValue& value)
69 {
70     return m_resolver->styleImage(propertyId, value);
71 }
72
73 void CSSToStyleMap::mapFillAttachment(CSSPropertyID, FillLayer& layer, CSSValue& value)
74 {
75     if (value.isInitialValue()) {
76         layer.setAttachment(FillLayer::initialFillAttachment(layer.type()));
77         return;
78     }
79
80     if (!is<CSSPrimitiveValue>(value))
81         return;
82
83     switch (downcast<CSSPrimitiveValue>(value).getValueID()) {
84     case CSSValueFixed:
85         layer.setAttachment(FixedBackgroundAttachment);
86         break;
87     case CSSValueScroll:
88         layer.setAttachment(ScrollBackgroundAttachment);
89         break;
90     case CSSValueLocal:
91         layer.setAttachment(LocalBackgroundAttachment);
92         break;
93     default:
94         return;
95     }
96 }
97
98 void CSSToStyleMap::mapFillClip(CSSPropertyID, FillLayer& layer, CSSValue& value)
99 {
100     if (value.isInitialValue()) {
101         layer.setClip(FillLayer::initialFillClip(layer.type()));
102         return;
103     }
104
105     if (!is<CSSPrimitiveValue>(value))
106         return;
107
108     layer.setClip(downcast<CSSPrimitiveValue>(value));
109 }
110
111 void CSSToStyleMap::mapFillComposite(CSSPropertyID, FillLayer& layer, CSSValue& value)
112 {
113     if (value.isInitialValue()) {
114         layer.setComposite(FillLayer::initialFillComposite(layer.type()));
115         return;
116     }
117
118     if (!is<CSSPrimitiveValue>(value))
119         return;
120
121     layer.setComposite(downcast<CSSPrimitiveValue>(value));
122 }
123
124 void CSSToStyleMap::mapFillBlendMode(CSSPropertyID, FillLayer& layer, CSSValue& value)
125 {
126     if (value.isInitialValue()) {
127         layer.setBlendMode(FillLayer::initialFillBlendMode(layer.type()));
128         return;
129     }
130
131     if (!is<CSSPrimitiveValue>(value))
132         return;
133
134     layer.setBlendMode(downcast<CSSPrimitiveValue>(value));
135 }
136
137 void CSSToStyleMap::mapFillOrigin(CSSPropertyID, FillLayer& layer, CSSValue& value)
138 {
139     if (value.isInitialValue()) {
140         layer.setOrigin(FillLayer::initialFillOrigin(layer.type()));
141         return;
142     }
143
144     if (!is<CSSPrimitiveValue>(value))
145         return;
146
147     layer.setOrigin(downcast<CSSPrimitiveValue>(value));
148 }
149
150
151 void CSSToStyleMap::mapFillImage(CSSPropertyID property, FillLayer& layer, CSSValue& value)
152 {
153     if (value.isInitialValue()) {
154         layer.setImage(FillLayer::initialFillImage(layer.type()));
155         return;
156     }
157
158     layer.setImage(styleImage(property, value));
159 }
160
161 void CSSToStyleMap::mapFillRepeatX(CSSPropertyID, FillLayer& layer, CSSValue& value)
162 {
163     if (value.isInitialValue()) {
164         layer.setRepeatX(FillLayer::initialFillRepeatX(layer.type()));
165         return;
166     }
167
168     if (!is<CSSPrimitiveValue>(value))
169         return;
170
171     layer.setRepeatX(downcast<CSSPrimitiveValue>(value));
172 }
173
174 void CSSToStyleMap::mapFillRepeatY(CSSPropertyID, FillLayer& layer, CSSValue& value)
175 {
176     if (value.isInitialValue()) {
177         layer.setRepeatY(FillLayer::initialFillRepeatY(layer.type()));
178         return;
179     }
180
181     if (!is<CSSPrimitiveValue>(value))
182         return;
183
184     layer.setRepeatY(downcast<CSSPrimitiveValue>(value));
185 }
186
187 static inline bool convertToLengthSize(const CSSPrimitiveValue& primitiveValue, CSSToLengthConversionData conversionData, LengthSize& size)
188 {
189     if (auto* pair = primitiveValue.getPairValue()) {
190         size.setWidth(pair->first()->convertToLength<AnyConversion>(conversionData));
191         size.setHeight(pair->second()->convertToLength<AnyConversion>(conversionData));
192     } else
193         size.setWidth(primitiveValue.convertToLength<AnyConversion>(conversionData));
194
195     return !size.width().isUndefined() && !size.height().isUndefined();
196 }
197
198 void CSSToStyleMap::mapFillSize(CSSPropertyID, FillLayer& layer, CSSValue& value)
199 {
200     if (value.isInitialValue()) {
201         layer.setSize(FillLayer::initialFillSize(layer.type()));
202         return;
203     }
204
205     if (!is<CSSPrimitiveValue>(value))
206         return;
207
208     auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
209     FillSize fillSize;
210     switch (primitiveValue.getValueID()) {
211     case CSSValueContain:
212         fillSize.type = Contain;
213         break;
214     case CSSValueCover:
215         fillSize.type = Cover;
216         break;
217     default:
218         ASSERT(fillSize.type == SizeLength);
219         if (!convertToLengthSize(primitiveValue, m_resolver->state().cssToLengthConversionData(), fillSize.size))
220             return;
221         break;
222     }
223     layer.setSize(fillSize);
224 }
225
226 void CSSToStyleMap::mapFillXPosition(CSSPropertyID propertyID, FillLayer& layer, CSSValue& value)
227 {
228     if (value.isInitialValue()) {
229         layer.setXPosition(FillLayer::initialFillXPosition(layer.type()));
230         return;
231     }
232
233     if (!is<CSSPrimitiveValue>(value))
234         return;
235
236     auto* primitiveValue = &downcast<CSSPrimitiveValue>(value);
237     Pair* pair = primitiveValue->getPairValue();
238     if (pair) {
239         ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionX || propertyID == CSSPropertyWebkitMaskPositionX);
240         primitiveValue = pair->second();
241     }
242
243     Length length;
244     if (primitiveValue->isLength())
245         length = primitiveValue->computeLength<Length>(m_resolver->state().cssToLengthConversionData());
246     else if (primitiveValue->isPercentage())
247         length = Length(primitiveValue->getDoubleValue(), Percent);
248     else if (primitiveValue->isCalculatedPercentageWithLength())
249         length = Length(primitiveValue->cssCalcValue()->createCalculationValue(m_resolver->state().cssToLengthConversionData()));
250     else
251         return;
252
253     layer.setXPosition(length);
254     if (pair)
255         layer.setBackgroundXOrigin(*pair->first());
256 }
257
258 void CSSToStyleMap::mapFillYPosition(CSSPropertyID propertyID, FillLayer& layer, CSSValue& value)
259 {
260     if (value.isInitialValue()) {
261         layer.setYPosition(FillLayer::initialFillYPosition(layer.type()));
262         return;
263     }
264
265     if (!is<CSSPrimitiveValue>(value))
266         return;
267
268     auto* primitiveValue = &downcast<CSSPrimitiveValue>(value);
269     Pair* pair = primitiveValue->getPairValue();
270     if (pair) {
271         ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionY || propertyID == CSSPropertyWebkitMaskPositionY);
272         primitiveValue = pair->second();
273     }
274
275     Length length;
276     if (primitiveValue->isLength())
277         length = primitiveValue->computeLength<Length>(m_resolver->state().cssToLengthConversionData());
278     else if (primitiveValue->isPercentage())
279         length = Length(primitiveValue->getDoubleValue(), Percent);
280     else if (primitiveValue->isCalculatedPercentageWithLength())
281         length = Length(primitiveValue->cssCalcValue()->createCalculationValue(m_resolver->state().cssToLengthConversionData()));
282     else
283         return;
284
285     layer.setYPosition(length);
286     if (pair)
287         layer.setBackgroundYOrigin(*pair->first());
288 }
289
290 void CSSToStyleMap::mapFillMaskSourceType(CSSPropertyID, FillLayer& layer, CSSValue& value)
291 {
292     EMaskSourceType type = FillLayer::initialFillMaskSourceType(layer.type());
293     if (value.isInitialValue()) {
294         layer.setMaskSourceType(type);
295         return;
296     }
297
298     if (!is<CSSPrimitiveValue>(value))
299         return;
300
301     switch (downcast<CSSPrimitiveValue>(value).getValueID()) {
302     case CSSValueAlpha:
303         type = EMaskSourceType::MaskAlpha;
304         break;
305     case CSSValueLuminance:
306         type = EMaskSourceType::MaskLuminance;
307         break;
308     case CSSValueAuto:
309         break;
310     default:
311         ASSERT_NOT_REACHED();
312     }
313
314     layer.setMaskSourceType(type);
315 }
316
317 void CSSToStyleMap::mapAnimationDelay(Animation& animation, CSSValue& value)
318 {
319     if (value.isInitialValue()) {
320         animation.setDelay(Animation::initialDelay());
321         return;
322     }
323
324     if (!is<CSSPrimitiveValue>(value))
325         return;
326
327     animation.setDelay(downcast<CSSPrimitiveValue>(value).computeTime<double, CSSPrimitiveValue::Seconds>());
328 }
329
330 void CSSToStyleMap::mapAnimationDirection(Animation& layer, CSSValue& value)
331 {
332     if (value.isInitialValue()) {
333         layer.setDirection(Animation::initialDirection());
334         return;
335     }
336
337     if (!is<CSSPrimitiveValue>(value))
338         return;
339
340     switch (downcast<CSSPrimitiveValue>(value).getValueID()) {
341     case CSSValueNormal:
342         layer.setDirection(Animation::AnimationDirectionNormal);
343         break;
344     case CSSValueAlternate:
345         layer.setDirection(Animation::AnimationDirectionAlternate);
346         break;
347     case CSSValueReverse:
348         layer.setDirection(Animation::AnimationDirectionReverse);
349         break;
350     case CSSValueAlternateReverse:
351         layer.setDirection(Animation::AnimationDirectionAlternateReverse);
352         break;
353     default:
354         break;
355     }
356 }
357
358 void CSSToStyleMap::mapAnimationDuration(Animation& animation, CSSValue& value)
359 {
360     if (value.isInitialValue()) {
361         animation.setDuration(Animation::initialDuration());
362         return;
363     }
364
365     if (!is<CSSPrimitiveValue>(value))
366         return;
367
368     animation.setDuration(downcast<CSSPrimitiveValue>(value).computeTime<double, CSSPrimitiveValue::Seconds>());
369 }
370
371 void CSSToStyleMap::mapAnimationFillMode(Animation& layer, CSSValue& value)
372 {
373     if (value.isInitialValue()) {
374         layer.setFillMode(Animation::initialFillMode());
375         return;
376     }
377
378     if (!is<CSSPrimitiveValue>(value))
379         return;
380
381     switch (downcast<CSSPrimitiveValue>(value).getValueID()) {
382     case CSSValueNone:
383         layer.setFillMode(AnimationFillModeNone);
384         break;
385     case CSSValueForwards:
386         layer.setFillMode(AnimationFillModeForwards);
387         break;
388     case CSSValueBackwards:
389         layer.setFillMode(AnimationFillModeBackwards);
390         break;
391     case CSSValueBoth:
392         layer.setFillMode(AnimationFillModeBoth);
393         break;
394     default:
395         break;
396     }
397 }
398
399 void CSSToStyleMap::mapAnimationIterationCount(Animation& animation, CSSValue& value)
400 {
401     if (value.isInitialValue()) {
402         animation.setIterationCount(Animation::initialIterationCount());
403         return;
404     }
405
406     if (!is<CSSPrimitiveValue>(value))
407         return;
408
409     auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
410     if (primitiveValue.getValueID() == CSSValueInfinite)
411         animation.setIterationCount(Animation::IterationCountInfinite);
412     else
413         animation.setIterationCount(primitiveValue.getFloatValue());
414 }
415
416 void CSSToStyleMap::mapAnimationName(Animation& layer, CSSValue& value)
417 {
418     if (value.isInitialValue()) {
419         layer.setName(Animation::initialName());
420         return;
421     }
422
423     if (!is<CSSPrimitiveValue>(value))
424         return;
425
426     auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
427     if (primitiveValue.getValueID() == CSSValueNone)
428         layer.setIsNoneAnimation(true);
429     else
430         layer.setName(primitiveValue.getStringValue());
431 }
432
433 void CSSToStyleMap::mapAnimationPlayState(Animation& layer, CSSValue& value)
434 {
435     if (value.isInitialValue()) {
436         layer.setPlayState(Animation::initialPlayState());
437         return;
438     }
439
440     if (!is<CSSPrimitiveValue>(value))
441         return;
442
443     EAnimPlayState playState = (downcast<CSSPrimitiveValue>(value).getValueID() == CSSValuePaused) ? AnimPlayStatePaused : AnimPlayStatePlaying;
444     layer.setPlayState(playState);
445 }
446
447 void CSSToStyleMap::mapAnimationProperty(Animation& animation, CSSValue& value)
448 {
449     if (value.isInitialValue()) {
450         animation.setAnimationMode(Animation::AnimateAll);
451         animation.setProperty(CSSPropertyInvalid);
452         return;
453     }
454
455     if (!is<CSSPrimitiveValue>(value))
456         return;
457
458     auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
459     if (primitiveValue.getValueID() == CSSValueAll) {
460         animation.setAnimationMode(Animation::AnimateAll);
461         animation.setProperty(CSSPropertyInvalid);
462     } else if (primitiveValue.getValueID() == CSSValueNone) {
463         animation.setAnimationMode(Animation::AnimateNone);
464         animation.setProperty(CSSPropertyInvalid);
465     } else {
466         animation.setAnimationMode(Animation::AnimateSingleProperty);
467         animation.setProperty(primitiveValue.getPropertyID());
468     }
469 }
470
471 void CSSToStyleMap::mapAnimationTimingFunction(Animation& animation, CSSValue& value)
472 {
473     if (value.isInitialValue()) {
474         animation.setTimingFunction(Animation::initialTimingFunction());
475         return;
476     }
477
478     if (is<CSSPrimitiveValue>(value)) {
479         switch (downcast<CSSPrimitiveValue>(value).getValueID()) {
480         case CSSValueLinear:
481             animation.setTimingFunction(LinearTimingFunction::create());
482             break;
483         case CSSValueEase:
484             animation.setTimingFunction(CubicBezierTimingFunction::create());
485             break;
486         case CSSValueEaseIn:
487             animation.setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseIn));
488             break;
489         case CSSValueEaseOut:
490             animation.setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseOut));
491             break;
492         case CSSValueEaseInOut:
493             animation.setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseInOut));
494             break;
495         case CSSValueStepStart:
496             animation.setTimingFunction(StepsTimingFunction::create(1, true));
497             break;
498         case CSSValueStepEnd:
499             animation.setTimingFunction(StepsTimingFunction::create(1, false));
500             break;
501         default:
502             break;
503         }
504         return;
505     }
506
507     if (is<CSSCubicBezierTimingFunctionValue>(value)) {
508         auto& cubicTimingFunction = downcast<CSSCubicBezierTimingFunctionValue>(value);
509         animation.setTimingFunction(CubicBezierTimingFunction::create(cubicTimingFunction.x1(), cubicTimingFunction.y1(), cubicTimingFunction.x2(), cubicTimingFunction.y2()));
510     } else if (is<CSSStepsTimingFunctionValue>(value)) {
511         auto& stepsTimingFunction = downcast<CSSStepsTimingFunctionValue>(value);
512         animation.setTimingFunction(StepsTimingFunction::create(stepsTimingFunction.numberOfSteps(), stepsTimingFunction.stepAtStart()));
513     }
514 }
515
516 void CSSToStyleMap::mapNinePieceImage(CSSPropertyID property, CSSValue* value, NinePieceImage& image)
517 {
518     // If we're not a value list, then we are "none" and don't need to alter the empty image at all.
519     if (!is<CSSValueList>(value))
520         return;
521
522     // Retrieve the border image value.
523     CSSValueList& borderImage = downcast<CSSValueList>(*value);
524
525     // Set the image (this kicks off the load).
526     CSSPropertyID imageProperty;
527     if (property == CSSPropertyWebkitBorderImage)
528         imageProperty = CSSPropertyBorderImageSource;
529     else if (property == CSSPropertyWebkitMaskBoxImage)
530         imageProperty = CSSPropertyWebkitMaskBoxImageSource;
531     else
532         imageProperty = property;
533
534     for (auto& current : borderImage) {
535         if (is<CSSImageValue>(current.get()) || is<CSSImageGeneratorValue>(current.get())
536 #if ENABLE(CSS_IMAGE_SET)
537             || is<CSSImageSetValue>(current.get())
538 #endif
539             )
540             image.setImage(styleImage(imageProperty, current.get()));
541         else if (is<CSSBorderImageSliceValue>(current.get()))
542             mapNinePieceImageSlice(current, image);
543         else if (is<CSSValueList>(current.get())) {
544             CSSValueList& slashList = downcast<CSSValueList>(current.get());
545             // Map in the image slices.
546             if (is<CSSBorderImageSliceValue>(slashList.item(0)))
547                 mapNinePieceImageSlice(*slashList.item(0), image);
548
549             // Map in the border slices.
550             if (slashList.item(1))
551                 image.setBorderSlices(mapNinePieceImageQuad(*slashList.item(1)));
552
553             // Map in the outset.
554             if (slashList.item(2))
555                 image.setOutset(mapNinePieceImageQuad(*slashList.item(2)));
556         } else if (is<CSSPrimitiveValue>(current.get())) {
557             // Set the appropriate rules for stretch/round/repeat of the slices.
558             mapNinePieceImageRepeat(current, image);
559         }
560     }
561
562     if (property == CSSPropertyWebkitBorderImage) {
563         // We have to preserve the legacy behavior of -webkit-border-image and make the border slices
564         // also set the border widths. We don't need to worry about percentages, since we don't even support
565         // those on real borders yet.
566         if (image.borderSlices().top().isFixed())
567             style()->setBorderTopWidth(image.borderSlices().top().value());
568         if (image.borderSlices().right().isFixed())
569             style()->setBorderRightWidth(image.borderSlices().right().value());
570         if (image.borderSlices().bottom().isFixed())
571             style()->setBorderBottomWidth(image.borderSlices().bottom().value());
572         if (image.borderSlices().left().isFixed())
573             style()->setBorderLeftWidth(image.borderSlices().left().value());
574     }
575 }
576
577 void CSSToStyleMap::mapNinePieceImageSlice(CSSValue& value, NinePieceImage& image)
578 {
579     if (!is<CSSBorderImageSliceValue>(value))
580         return;
581
582     // Retrieve the border image value.
583     auto& borderImageSlice = downcast<CSSBorderImageSliceValue>(value);
584
585     // Set up a length box to represent our image slices.
586     LengthBox box;
587     Quad* slices = borderImageSlice.slices();
588     if (slices->top()->isPercentage())
589         box.m_top = Length(slices->top()->getDoubleValue(), Percent);
590     else
591         box.m_top = Length(slices->top()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed);
592     if (slices->bottom()->isPercentage())
593         box.m_bottom = Length(slices->bottom()->getDoubleValue(), Percent);
594     else
595         box.m_bottom = Length((int)slices->bottom()->getFloatValue(CSSPrimitiveValue::CSS_NUMBER), Fixed);
596     if (slices->left()->isPercentage())
597         box.m_left = Length(slices->left()->getDoubleValue(), Percent);
598     else
599         box.m_left = Length(slices->left()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed);
600     if (slices->right()->isPercentage())
601         box.m_right = Length(slices->right()->getDoubleValue(), Percent);
602     else
603         box.m_right = Length(slices->right()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed);
604     image.setImageSlices(box);
605
606     // Set our fill mode.
607     image.setFill(borderImageSlice.m_fill);
608 }
609
610 LengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue& value)
611 {
612     if (!is<CSSPrimitiveValue>(value))
613         return LengthBox();
614
615     // Get our zoom value.
616     CSSToLengthConversionData conversionData = useSVGZoomRules() ? m_resolver->state().cssToLengthConversionData().copyWithAdjustedZoom(1.0f) : m_resolver->state().cssToLengthConversionData();
617
618     // Retrieve the primitive value.
619     auto& borderWidths = downcast<CSSPrimitiveValue>(value);
620
621     // Set up a length box to represent our image slices.
622     LengthBox box; // Defaults to 'auto' so we don't have to handle that explicitly below.
623     Quad* slices = borderWidths.getQuadValue();
624     if (slices->top()->isNumber())
625         box.m_top = Length(slices->top()->getIntValue(), Relative);
626     else if (slices->top()->isPercentage())
627         box.m_top = Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
628     else if (slices->top()->getValueID() != CSSValueAuto)
629         box.m_top = slices->top()->computeLength<Length>(conversionData);
630
631     if (slices->right()->isNumber())
632         box.m_right = Length(slices->right()->getIntValue(), Relative);
633     else if (slices->right()->isPercentage())
634         box.m_right = Length(slices->right()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
635     else if (slices->right()->getValueID() != CSSValueAuto)
636         box.m_right = slices->right()->computeLength<Length>(conversionData);
637
638     if (slices->bottom()->isNumber())
639         box.m_bottom = Length(slices->bottom()->getIntValue(), Relative);
640     else if (slices->bottom()->isPercentage())
641         box.m_bottom = Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
642     else if (slices->bottom()->getValueID() != CSSValueAuto)
643         box.m_bottom = slices->bottom()->computeLength<Length>(conversionData);
644
645     if (slices->left()->isNumber())
646         box.m_left = Length(slices->left()->getIntValue(), Relative);
647     else if (slices->left()->isPercentage())
648         box.m_left = Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
649     else if (slices->left()->getValueID() != CSSValueAuto)
650         box.m_left = slices->left()->computeLength<Length>(conversionData);
651
652     return box;
653 }
654
655 void CSSToStyleMap::mapNinePieceImageRepeat(CSSValue& value, NinePieceImage& image)
656 {
657     if (!is<CSSPrimitiveValue>(value))
658         return;
659
660     CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value);
661     Pair* pair = primitiveValue.getPairValue();
662     if (!pair || !pair->first() || !pair->second())
663         return;
664
665     CSSValueID firstIdentifier = pair->first()->getValueID();
666     CSSValueID secondIdentifier = pair->second()->getValueID();
667
668     ENinePieceImageRule horizontalRule;
669     switch (firstIdentifier) {
670     case CSSValueStretch:
671         horizontalRule = StretchImageRule;
672         break;
673     case CSSValueRound:
674         horizontalRule = RoundImageRule;
675         break;
676     case CSSValueSpace:
677         horizontalRule = SpaceImageRule;
678         break;
679     default: // CSSValueRepeat
680         horizontalRule = RepeatImageRule;
681         break;
682     }
683     image.setHorizontalRule(horizontalRule);
684
685     ENinePieceImageRule verticalRule;
686     switch (secondIdentifier) {
687     case CSSValueStretch:
688         verticalRule = StretchImageRule;
689         break;
690     case CSSValueRound:
691         verticalRule = RoundImageRule;
692         break;
693     case CSSValueSpace:
694         verticalRule = SpaceImageRule;
695         break;
696     default: // CSSValueRepeat
697         verticalRule = RepeatImageRule;
698         break;
699     }
700     image.setVerticalRule(verticalRule);
701 }
702
703 };