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