2007-02-06 Mark Rowe <mrowe@apple.com>
[WebKit-https.git] / WebCore / css / CSSComputedStyleDeclaration.cpp
1 /**
2  *
3  * Copyright (C) 2004 Zack Rusin <zack@kde.org>
4  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "CSSComputedStyleDeclaration.h"
24
25 #include "CSSMutableStyleDeclaration.h"
26 #include "CSSPrimitiveValue.h"
27 #include "CSSPropertyNames.h"
28 #include "CSSValueKeywords.h"
29 #include "CSSValueList.h"
30 #include "CachedImage.h"
31 #include "DashboardRegion.h"
32 #include "Document.h"
33 #include "ExceptionCode.h"
34 #include "Pair.h"
35 #include "RenderObject.h"
36 #include "ShadowValue.h"
37
38 namespace WebCore {
39
40 // List of all properties we know how to compute, omitting shorthands.
41 static const int computedProperties[] = {
42     CSS_PROP_BACKGROUND_ATTACHMENT,
43     CSS_PROP_BACKGROUND_COLOR,
44     CSS_PROP_BACKGROUND_IMAGE,
45     CSS_PROP_BACKGROUND_POSITION_X,
46     CSS_PROP_BACKGROUND_POSITION_Y,
47     CSS_PROP_BACKGROUND_REPEAT,
48     CSS_PROP_BORDER_BOTTOM_COLOR,
49     CSS_PROP_BORDER_BOTTOM_STYLE,
50     CSS_PROP_BORDER_BOTTOM_WIDTH,
51     CSS_PROP_BORDER_COLLAPSE,
52     CSS_PROP_BORDER_LEFT_COLOR,
53     CSS_PROP_BORDER_LEFT_STYLE,
54     CSS_PROP_BORDER_LEFT_WIDTH,
55     CSS_PROP_BORDER_RIGHT_COLOR,
56     CSS_PROP_BORDER_RIGHT_STYLE,
57     CSS_PROP_BORDER_RIGHT_WIDTH,
58     CSS_PROP_BORDER_TOP_COLOR,
59     CSS_PROP_BORDER_TOP_STYLE,
60     CSS_PROP_BORDER_TOP_WIDTH,
61     CSS_PROP_BOTTOM,
62     CSS_PROP_BOX_SIZING,
63     CSS_PROP_CAPTION_SIDE,
64     CSS_PROP_CLEAR,
65     CSS_PROP_COLOR,
66     CSS_PROP_CURSOR,
67     CSS_PROP_DIRECTION,
68     CSS_PROP_DISPLAY,
69     CSS_PROP_EMPTY_CELLS,
70     CSS_PROP_FLOAT,
71     CSS_PROP_FONT_FAMILY,
72     CSS_PROP_FONT_SIZE,
73     CSS_PROP_FONT_STYLE,
74     CSS_PROP_FONT_VARIANT,
75     CSS_PROP_FONT_WEIGHT,
76     CSS_PROP_HEIGHT,
77     CSS_PROP_LEFT,
78     CSS_PROP_LETTER_SPACING,
79     CSS_PROP_LINE_HEIGHT,
80     CSS_PROP_LIST_STYLE_IMAGE,
81     CSS_PROP_LIST_STYLE_POSITION,
82     CSS_PROP_LIST_STYLE_TYPE,
83     CSS_PROP_MARGIN_BOTTOM,
84     CSS_PROP_MARGIN_LEFT,
85     CSS_PROP_MARGIN_RIGHT,
86     CSS_PROP_MARGIN_TOP,
87     CSS_PROP_MAX_HEIGHT,
88     CSS_PROP_MAX_WIDTH,
89     CSS_PROP_MIN_HEIGHT,
90     CSS_PROP_MIN_WIDTH,
91     CSS_PROP_OPACITY,
92     CSS_PROP_ORPHANS,
93     CSS_PROP_OUTLINE_COLOR,
94     CSS_PROP_OUTLINE_STYLE,
95     CSS_PROP_OUTLINE_WIDTH,
96     CSS_PROP_OVERFLOW_X,
97     CSS_PROP_OVERFLOW_Y,
98     CSS_PROP_PADDING_BOTTOM,
99     CSS_PROP_PADDING_LEFT,
100     CSS_PROP_PADDING_RIGHT,
101     CSS_PROP_PADDING_TOP,
102     CSS_PROP_PAGE_BREAK_AFTER,
103     CSS_PROP_PAGE_BREAK_BEFORE,
104     CSS_PROP_PAGE_BREAK_INSIDE,
105     CSS_PROP_POSITION,
106     CSS_PROP_RESIZE,
107     CSS_PROP_RIGHT,
108     CSS_PROP_TABLE_LAYOUT,
109     CSS_PROP_TEXT_ALIGN,
110     CSS_PROP_TEXT_DECORATION,
111     CSS_PROP_TEXT_INDENT,
112     CSS_PROP_TEXT_SHADOW,
113     CSS_PROP_TEXT_TRANSFORM,
114     CSS_PROP_TOP,
115     CSS_PROP_UNICODE_BIDI,
116     CSS_PROP_VERTICAL_ALIGN,
117     CSS_PROP_VISIBILITY,
118     CSS_PROP_WHITE_SPACE,
119     CSS_PROP_WIDOWS,
120     CSS_PROP_WIDTH,
121     CSS_PROP_WORD_SPACING,
122     CSS_PROP_WORD_WRAP,
123     CSS_PROP_Z_INDEX,
124
125     CSS_PROP__WEBKIT_APPEARANCE,
126     CSS_PROP__WEBKIT_BACKGROUND_CLIP,
127     CSS_PROP__WEBKIT_BACKGROUND_COMPOSITE,
128     CSS_PROP__WEBKIT_BACKGROUND_ORIGIN,
129     CSS_PROP__WEBKIT_BACKGROUND_SIZE,
130     CSS_PROP__WEBKIT_BORDER_HORIZONTAL_SPACING,
131     CSS_PROP__WEBKIT_BORDER_VERTICAL_SPACING,
132     CSS_PROP__WEBKIT_BOX_ALIGN,
133     CSS_PROP__WEBKIT_BOX_DIRECTION,
134     CSS_PROP__WEBKIT_BOX_FLEX,
135     CSS_PROP__WEBKIT_BOX_FLEX_GROUP,
136     CSS_PROP__WEBKIT_BOX_LINES,
137     CSS_PROP__WEBKIT_BOX_ORDINAL_GROUP,
138     CSS_PROP__WEBKIT_BOX_ORIENT,
139     CSS_PROP__WEBKIT_BOX_PACK,
140     CSS_PROP__WEBKIT_BOX_SHADOW,
141     CSS_PROP__WEBKIT_COLUMN_BREAK_AFTER,
142     CSS_PROP__WEBKIT_COLUMN_BREAK_BEFORE,
143     CSS_PROP__WEBKIT_COLUMN_BREAK_INSIDE,
144     CSS_PROP__WEBKIT_COLUMN_COUNT,
145     CSS_PROP__WEBKIT_COLUMN_GAP,
146     CSS_PROP__WEBKIT_COLUMN_RULE_COLOR,
147     CSS_PROP__WEBKIT_COLUMN_RULE_STYLE,
148     CSS_PROP__WEBKIT_COLUMN_RULE_WIDTH,
149     CSS_PROP__WEBKIT_COLUMN_WIDTH,
150     CSS_PROP__WEBKIT_HIGHLIGHT,
151     CSS_PROP__WEBKIT_LINE_BREAK,
152     CSS_PROP__WEBKIT_LINE_CLAMP,
153     CSS_PROP__WEBKIT_MARGIN_BOTTOM_COLLAPSE,
154     CSS_PROP__WEBKIT_MARGIN_TOP_COLLAPSE,
155     CSS_PROP__WEBKIT_MARQUEE_DIRECTION,
156     CSS_PROP__WEBKIT_MARQUEE_INCREMENT,
157     CSS_PROP__WEBKIT_MARQUEE_REPETITION,
158     CSS_PROP__WEBKIT_MARQUEE_STYLE,
159     CSS_PROP__WEBKIT_NBSP_MODE,
160     CSS_PROP__WEBKIT_RTL_ORDERING,
161     CSS_PROP__WEBKIT_TEXT_DECORATIONS_IN_EFFECT,
162     CSS_PROP__WEBKIT_TEXT_FILL_COLOR,
163     CSS_PROP__WEBKIT_TEXT_SECURITY,
164     CSS_PROP__WEBKIT_TEXT_STROKE_COLOR,
165     CSS_PROP__WEBKIT_TEXT_STROKE_WIDTH,
166     CSS_PROP__WEBKIT_USER_DRAG,
167     CSS_PROP__WEBKIT_USER_MODIFY,
168     CSS_PROP__WEBKIT_USER_SELECT,
169
170 #if PLATFORM(MAC)
171     CSS_PROP__WEBKIT_DASHBOARD_REGION,
172 #endif
173 };
174
175 const unsigned numComputedProperties = sizeof(computedProperties) / sizeof(computedProperties[0]);
176
177 static PassRefPtr<CSSValue> valueForLength(const Length& length)
178 {
179     switch (length.type()) {
180         case Auto:
181             return new CSSPrimitiveValue(CSS_VAL_AUTO);
182         case WebCore::Fixed:
183             return new CSSPrimitiveValue(length.value(), CSSPrimitiveValue::CSS_PX);
184         case Intrinsic:
185             return new CSSPrimitiveValue(CSS_VAL_INTRINSIC);
186         case MinIntrinsic:
187             return new CSSPrimitiveValue(CSS_VAL_MIN_INTRINSIC);
188         case Percent:
189             return new CSSPrimitiveValue(length.percent(), CSSPrimitiveValue::CSS_PERCENTAGE);
190         case Relative:
191         case Static:
192             break;
193     }
194     ASSERT_NOT_REACHED();
195     return 0;
196 }
197
198 // Handles special value for "none".
199 static PassRefPtr<CSSValue> valueForMaxLength(const Length& length)
200 {
201     if (length.isFixed() && length.value() == undefinedLength)
202         return new CSSPrimitiveValue(CSS_VAL_NONE);
203     return valueForLength(length);
204 }
205
206 static PassRefPtr<CSSValue> valueForBorderStyle(EBorderStyle style)
207 {
208     switch (style) {
209         case BNONE:
210             return new CSSPrimitiveValue(CSS_VAL_NONE);
211         case BHIDDEN:
212             return new CSSPrimitiveValue(CSS_VAL_HIDDEN);
213         case INSET:
214             return new CSSPrimitiveValue(CSS_VAL_INSET);
215         case GROOVE:
216             return new CSSPrimitiveValue(CSS_VAL_GROOVE);
217         case RIDGE:
218             return new CSSPrimitiveValue(CSS_VAL_RIDGE);
219         case OUTSET:
220             return new CSSPrimitiveValue(CSS_VAL_OUTSET);
221         case DOTTED:
222             return new CSSPrimitiveValue(CSS_VAL_DOTTED);
223         case DASHED:
224             return new CSSPrimitiveValue(CSS_VAL_DASHED);
225         case SOLID:
226             return new CSSPrimitiveValue(CSS_VAL_SOLID);
227         case DOUBLE:
228             return new CSSPrimitiveValue(CSS_VAL_DOUBLE);
229     }
230     ASSERT_NOT_REACHED();
231     return 0;
232 }
233
234 static PassRefPtr<CSSValue> valueForTextAlign(ETextAlign align)
235 {
236     switch (align) {
237         case TAAUTO:
238             return new CSSPrimitiveValue(CSS_VAL_AUTO);
239         case LEFT:
240             return new CSSPrimitiveValue(CSS_VAL_LEFT);
241         case RIGHT:
242             return new CSSPrimitiveValue(CSS_VAL_RIGHT);
243         case CENTER:
244             return new CSSPrimitiveValue(CSS_VAL_CENTER);
245         case JUSTIFY:
246             return new CSSPrimitiveValue(CSS_VAL_JUSTIFY);
247         case KHTML_LEFT:
248             return new CSSPrimitiveValue(CSS_VAL__WEBKIT_LEFT);
249         case KHTML_RIGHT:
250             return new CSSPrimitiveValue(CSS_VAL__WEBKIT_RIGHT);
251         case KHTML_CENTER:
252             return new CSSPrimitiveValue(CSS_VAL__WEBKIT_CENTER);
253     }
254     ASSERT_NOT_REACHED();
255     return 0;
256 }
257
258 static PassRefPtr<CSSValue> valueForAppearance(EAppearance appearance)
259 {
260     switch (appearance) {
261         case NoAppearance:
262             return new CSSPrimitiveValue(CSS_VAL_NONE);
263         case CheckboxAppearance:
264             return new CSSPrimitiveValue(CSS_VAL_CHECKBOX);
265         case RadioAppearance:
266             return new CSSPrimitiveValue(CSS_VAL_RADIO);
267         case PushButtonAppearance:
268             return new CSSPrimitiveValue(CSS_VAL_PUSH_BUTTON);
269         case SquareButtonAppearance:
270             return new CSSPrimitiveValue(CSS_VAL_SQUARE_BUTTON);
271         case ButtonAppearance:
272             return new CSSPrimitiveValue(CSS_VAL_BUTTON);
273         case ButtonBevelAppearance:
274             return new CSSPrimitiveValue(CSS_VAL_BUTTON_BEVEL);
275         case ListboxAppearance:
276             return new CSSPrimitiveValue(CSS_VAL_LISTBOX);
277         case ListItemAppearance:
278             return new CSSPrimitiveValue(CSS_VAL_LISTITEM);
279         case MenulistAppearance:
280             return new CSSPrimitiveValue(CSS_VAL_MENULIST);
281         case MenulistButtonAppearance:
282             return new CSSPrimitiveValue(CSS_VAL_MENULIST_BUTTON);
283         case MenulistTextAppearance:
284             return new CSSPrimitiveValue(CSS_VAL_MENULIST_TEXT);
285         case MenulistTextFieldAppearance:
286             return new CSSPrimitiveValue(CSS_VAL_MENULIST_TEXTFIELD);
287         case ScrollbarButtonUpAppearance:
288             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARBUTTON_UP);
289         case ScrollbarButtonDownAppearance:
290             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARBUTTON_DOWN);
291         case ScrollbarButtonLeftAppearance:
292             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARBUTTON_LEFT);
293         case ScrollbarButtonRightAppearance:
294             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARBUTTON_RIGHT);
295         case ScrollbarTrackHorizontalAppearance:
296             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARTRACK_HORIZONTAL);
297         case ScrollbarTrackVerticalAppearance:
298             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARTRACK_VERTICAL);
299         case ScrollbarThumbHorizontalAppearance:
300             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARTHUMB_HORIZONTAL);
301         case ScrollbarThumbVerticalAppearance:
302             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARTHUMB_VERTICAL);
303         case ScrollbarGripperHorizontalAppearance:
304             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARGRIPPER_HORIZONTAL);
305         case ScrollbarGripperVerticalAppearance:
306             return new CSSPrimitiveValue(CSS_VAL_SCROLLBARGRIPPER_VERTICAL);
307         case SliderHorizontalAppearance:
308             return new CSSPrimitiveValue(CSS_VAL_SLIDER_HORIZONTAL);
309         case SliderVerticalAppearance:
310             return new CSSPrimitiveValue(CSS_VAL_SLIDER_VERTICAL);
311         case SliderThumbHorizontalAppearance:
312             return new CSSPrimitiveValue(CSS_VAL_SLIDERTHUMB_HORIZONTAL);
313         case SliderThumbVerticalAppearance:
314             return new CSSPrimitiveValue(CSS_VAL_SLIDERTHUMB_VERTICAL);
315         case CaretAppearance:
316             return new CSSPrimitiveValue(CSS_VAL_CARET);
317         case SearchFieldAppearance:
318             return new CSSPrimitiveValue(CSS_VAL_SEARCHFIELD);
319         case SearchFieldDecorationAppearance:
320             return new CSSPrimitiveValue(CSS_VAL_SEARCHFIELD_DECORATION);
321         case SearchFieldResultsDecorationAppearance:
322             return new CSSPrimitiveValue(CSS_VAL_SEARCHFIELD_RESULTS_DECORATION);
323         case SearchFieldResultsButtonAppearance:
324             return new CSSPrimitiveValue(CSS_VAL_SEARCHFIELD_RESULTS_BUTTON);
325         case SearchFieldCancelButtonAppearance:
326             return new CSSPrimitiveValue(CSS_VAL_SEARCHFIELD_CANCEL_BUTTON);
327         case TextFieldAppearance:
328             return new CSSPrimitiveValue(CSS_VAL_TEXTFIELD);
329         case TextAreaAppearance:
330             return new CSSPrimitiveValue(CSS_VAL_TEXTAREA);
331     }
332     ASSERT_NOT_REACHED();
333     return 0;
334 }
335
336 static PassRefPtr<CSSValue> valueForMarginCollapse(EMarginCollapse collapse)
337 {
338     switch (collapse) {
339         case MCOLLAPSE:
340             return new CSSPrimitiveValue(CSS_VAL_COLLAPSE);
341         case MSEPARATE:
342             return new CSSPrimitiveValue(CSS_VAL_SEPARATE);
343         case MDISCARD:
344             return new CSSPrimitiveValue(CSS_VAL_DISCARD);
345     }
346     ASSERT_NOT_REACHED();
347     return 0;
348 }
349
350 static PassRefPtr<CSSValue> valueForShadow(const ShadowData* shadow)
351 {
352     if (!shadow)
353         return new CSSPrimitiveValue(CSS_VAL_NONE);
354
355     CSSValueList* list = new CSSValueList;
356     for (const ShadowData* s = shadow; s; s = s->next) {
357         CSSPrimitiveValue* x = new CSSPrimitiveValue(s->x, CSSPrimitiveValue::CSS_PX);
358         CSSPrimitiveValue* y = new CSSPrimitiveValue(s->y, CSSPrimitiveValue::CSS_PX);
359         CSSPrimitiveValue* blur = new CSSPrimitiveValue(s->blur, CSSPrimitiveValue::CSS_PX);
360         CSSPrimitiveValue* color = new CSSPrimitiveValue(s->color.rgb());
361         list->append(new ShadowValue(x, y, blur, color));
362     }
363     return list;
364 }
365
366 static PassRefPtr<CSSValue> getPositionOffsetValue(RenderObject* renderer, int propertyID)
367 {
368     if (!renderer)
369         return 0;
370
371     RenderStyle* style = renderer->style();
372     if (!style)
373         return 0;
374
375     Length l;
376     switch (propertyID) {
377         case CSS_PROP_LEFT:
378             l = style->left();
379             break;
380         case CSS_PROP_RIGHT:
381             l = style->right();
382             break;
383         case CSS_PROP_TOP:
384             l = style->top();
385             break;
386         case CSS_PROP_BOTTOM:
387             l = style->bottom();
388             break;
389         default:
390             return 0;
391     }
392
393     if (renderer->isPositioned())
394         return valueForLength(l);
395
396     if (renderer->isRelPositioned())
397         // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined.
398         // In other words if left is auto and right is not auto, then left's computed value is negative right.
399         // So we should get the opposite length unit and see if it is auto.
400         return valueForLength(l);
401
402     return new CSSPrimitiveValue(CSS_VAL_AUTO);
403 }
404
405 static PassRefPtr<CSSPrimitiveValue> currentColorOrValidColor(RenderStyle* style, const Color& color)
406 {
407     if (!color.isValid())
408         return new CSSPrimitiveValue(style->color().rgb());
409     return new CSSPrimitiveValue(color.rgb());
410 }
411
412 CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(PassRefPtr<Node> n)
413     : m_node(n)
414 {
415 }
416
417 CSSComputedStyleDeclaration::~CSSComputedStyleDeclaration()
418 {
419 }
420
421 String CSSComputedStyleDeclaration::cssText() const
422 {
423     String result("");
424
425     for (unsigned i = 0; i < numComputedProperties; i++) {
426         if (i)
427             result += " ";
428         result += getPropertyName(static_cast<CSSPropertyID>(computedProperties[i]));
429         result += ": ";
430         result += getPropertyValue(computedProperties[i]);
431         result += ";";
432     }
433
434     return result;
435 }
436
437 void CSSComputedStyleDeclaration::setCssText(const String&, ExceptionCode& ec)
438 {
439     ec = NO_MODIFICATION_ALLOWED_ERR;
440 }
441
442 // Display integers in integer format instead of "1.0".
443 static String numberAsString(double n)
444 {
445     long i = static_cast<long>(n);
446     return i == n ? String::number(i) : String::number(n);
447 }
448
449 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(int propertyID) const
450 {
451     return getPropertyCSSValue(propertyID, UpdateLayout);
452 }
453
454 PassRefPtr<CSSPrimitiveValue> primitiveValueFromLength(Length length)
455 {
456     String string;
457     switch (length.type()) {
458         case Percent:
459             string = numberAsString(length.percent()) + "%";
460             break;
461         case Fixed:
462             string = numberAsString(length.calcMinValue(0));
463             break;
464         case Auto:
465             string = "auto";
466             break;
467         default:
468             break;
469     }
470     return new CSSPrimitiveValue(string, CSSPrimitiveValue::CSS_STRING);
471 }
472
473 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
474 {
475     Node* node = m_node.get();
476     if (!node)
477         return 0;
478
479     // Make sure our layout is up to date before we allow a query on these attributes.
480     if (updateLayout)
481         node->document()->updateLayout();
482
483     // FIXME: This should work even if we do not have a renderer.
484     RenderObject* renderer = node->renderer();
485     if (!renderer)
486         return 0;
487
488     RenderStyle* style = renderer->style();
489     if (!style)
490         return 0;
491
492     switch (static_cast<CSSPropertyID>(propertyID)) {
493         case CSS_PROP_INVALID:
494             break;
495
496         case CSS_PROP_BACKGROUND_COLOR:
497             return new CSSPrimitiveValue(style->backgroundColor().rgb());
498         case CSS_PROP_BACKGROUND_IMAGE:
499             if (style->backgroundImage())
500                 return new CSSPrimitiveValue(style->backgroundImage()->url(), CSSPrimitiveValue::CSS_URI);
501             return new CSSPrimitiveValue(CSS_VAL_NONE);
502         case CSS_PROP__WEBKIT_BACKGROUND_SIZE:
503             return new CSSPrimitiveValue(new Pair(primitiveValueFromLength(style->backgroundSize().width),
504                 primitiveValueFromLength(style->backgroundSize().height)));
505         case CSS_PROP_BACKGROUND_REPEAT:
506             switch (style->backgroundRepeat()) {
507                 case REPEAT:
508                     return new CSSPrimitiveValue(CSS_VAL_REPEAT);
509                 case REPEAT_X:
510                     return new CSSPrimitiveValue(CSS_VAL_REPEAT_X);
511                 case REPEAT_Y:
512                     return new CSSPrimitiveValue(CSS_VAL_REPEAT_Y);
513                 case NO_REPEAT:
514                     return new CSSPrimitiveValue(CSS_VAL_NO_REPEAT);
515             }
516             ASSERT_NOT_REACHED();
517             return 0;
518         case CSS_PROP__WEBKIT_BACKGROUND_COMPOSITE:
519             switch (style->backgroundComposite()) {
520                 case CompositeClear:
521                     return new CSSPrimitiveValue(CSS_VAL_CLEAR);
522                 case CompositeCopy:
523                     return new CSSPrimitiveValue(CSS_VAL_COPY);
524                 case CompositeSourceOver:
525                     return new CSSPrimitiveValue(CSS_VAL_SOURCE_OVER);
526                 case CompositeSourceIn:
527                     return new CSSPrimitiveValue(CSS_VAL_SOURCE_IN);
528                 case CompositeSourceOut:
529                     return new CSSPrimitiveValue(CSS_VAL_SOURCE_OUT);
530                 case CompositeSourceAtop:
531                     return new CSSPrimitiveValue(CSS_VAL_SOURCE_ATOP);
532                 case CompositeDestinationOver:
533                     return new CSSPrimitiveValue(CSS_VAL_DESTINATION_OVER);
534                 case CompositeDestinationIn:
535                     return new CSSPrimitiveValue(CSS_VAL_DESTINATION_IN);
536                 case CompositeDestinationOut:
537                     return new CSSPrimitiveValue(CSS_VAL_DESTINATION_OUT);
538                 case CompositeDestinationAtop:
539                     return new CSSPrimitiveValue(CSS_VAL_DESTINATION_ATOP);
540                 case CompositeXOR:
541                     return new CSSPrimitiveValue(CSS_VAL_XOR);
542                 case CompositePlusDarker:
543                     return new CSSPrimitiveValue(CSS_VAL_PLUS_DARKER);
544                 case CompositeHighlight:
545                     return new CSSPrimitiveValue(CSS_VAL_HIGHLIGHT);
546                 case CompositePlusLighter:
547                     return new CSSPrimitiveValue(CSS_VAL_PLUS_LIGHTER);
548             }
549             ASSERT_NOT_REACHED();
550             return 0;
551         case CSS_PROP_BACKGROUND_ATTACHMENT:
552             if (style->backgroundAttachment())
553                 return new CSSPrimitiveValue(CSS_VAL_SCROLL);
554             return new CSSPrimitiveValue(CSS_VAL_FIXED);
555         case CSS_PROP__WEBKIT_BACKGROUND_CLIP:
556         case CSS_PROP__WEBKIT_BACKGROUND_ORIGIN: {
557             EBackgroundBox box = (propertyID == CSS_PROP__WEBKIT_BACKGROUND_CLIP ? style->backgroundClip() : style->backgroundOrigin());
558             switch (box) {
559                 case BGBORDER:
560                     return new CSSPrimitiveValue(CSS_VAL_BORDER);
561                 case BGPADDING:
562                     return new CSSPrimitiveValue(CSS_VAL_PADDING);
563                 case BGCONTENT:
564                     return new CSSPrimitiveValue(CSS_VAL_CONTENT);
565             }
566             ASSERT_NOT_REACHED();
567             return 0;
568         }
569         case CSS_PROP_BACKGROUND_POSITION: {
570             String string;
571             Length length(style->backgroundXPosition());
572             if (length.isPercent())
573                 string = numberAsString(length.percent()) + "%";
574             else
575                 string = numberAsString(length.calcMinValue(renderer->contentWidth()));
576             string += " ";
577             length = style->backgroundYPosition();
578             if (length.isPercent())
579                 string += numberAsString(length.percent()) + "%";
580             else
581                 string += numberAsString(length.calcMinValue(renderer->contentWidth()));
582             return new CSSPrimitiveValue(string, CSSPrimitiveValue::CSS_STRING);
583         }
584         case CSS_PROP_BACKGROUND_POSITION_X:
585             return valueForLength(style->backgroundXPosition());
586         case CSS_PROP_BACKGROUND_POSITION_Y:
587             return valueForLength(style->backgroundYPosition());
588         case CSS_PROP_BORDER_COLLAPSE:
589             if (style->borderCollapse())
590                 return new CSSPrimitiveValue(CSS_VAL_COLLAPSE);
591             return new CSSPrimitiveValue(CSS_VAL_SEPARATE);
592         case CSS_PROP_BORDER_SPACING:
593             return new CSSPrimitiveValue(numberAsString(style->horizontalBorderSpacing()) + "px "
594                 + numberAsString(style->verticalBorderSpacing()) + "px", CSSPrimitiveValue::CSS_STRING);
595         case CSS_PROP__WEBKIT_BORDER_HORIZONTAL_SPACING:
596             return new CSSPrimitiveValue(style->horizontalBorderSpacing(), CSSPrimitiveValue::CSS_PX);
597         case CSS_PROP__WEBKIT_BORDER_VERTICAL_SPACING:
598             return new CSSPrimitiveValue(style->verticalBorderSpacing(), CSSPrimitiveValue::CSS_PX);
599         case CSS_PROP_BORDER_TOP_COLOR:
600             return currentColorOrValidColor(style, style->borderTopColor());
601         case CSS_PROP_BORDER_RIGHT_COLOR:
602             return currentColorOrValidColor(style, style->borderRightColor());
603         case CSS_PROP_BORDER_BOTTOM_COLOR:
604             return currentColorOrValidColor(style, style->borderBottomColor());
605         case CSS_PROP_BORDER_LEFT_COLOR:
606             return currentColorOrValidColor(style, style->borderLeftColor());
607         case CSS_PROP_BORDER_TOP_STYLE:
608             return valueForBorderStyle(style->borderTopStyle());
609         case CSS_PROP_BORDER_RIGHT_STYLE:
610             return valueForBorderStyle(style->borderRightStyle());
611         case CSS_PROP_BORDER_BOTTOM_STYLE:
612             return valueForBorderStyle(style->borderBottomStyle());
613         case CSS_PROP_BORDER_LEFT_STYLE:
614             return valueForBorderStyle(style->borderLeftStyle());
615         case CSS_PROP_BORDER_TOP_WIDTH:
616             return new CSSPrimitiveValue(style->borderTopWidth(), CSSPrimitiveValue::CSS_PX);
617         case CSS_PROP_BORDER_RIGHT_WIDTH:
618             return new CSSPrimitiveValue(style->borderRightWidth(), CSSPrimitiveValue::CSS_PX);
619         case CSS_PROP_BORDER_BOTTOM_WIDTH:
620             return new CSSPrimitiveValue(style->borderBottomWidth(), CSSPrimitiveValue::CSS_PX);
621         case CSS_PROP_BORDER_LEFT_WIDTH:
622             return new CSSPrimitiveValue(style->borderLeftWidth(), CSSPrimitiveValue::CSS_PX);
623         case CSS_PROP_BOTTOM:
624             return getPositionOffsetValue(renderer, CSS_PROP_BOTTOM);
625         case CSS_PROP__WEBKIT_BOX_ALIGN:
626             switch (style->boxAlign()) {
627                 case BSTRETCH:
628                     return new CSSPrimitiveValue(CSS_VAL_STRETCH);
629                 case BSTART:
630                     return new CSSPrimitiveValue(CSS_VAL_START);
631                 case BCENTER:
632                     return new CSSPrimitiveValue(CSS_VAL_CENTER);
633                 case BEND:
634                     return new CSSPrimitiveValue(CSS_VAL_END);
635                 case BBASELINE:
636                     return new CSSPrimitiveValue(CSS_VAL_BASELINE);
637                 case BJUSTIFY:
638                     break; // not allowed
639             }
640             ASSERT_NOT_REACHED();
641             return 0;
642         case CSS_PROP__WEBKIT_BOX_DIRECTION:
643             switch (style->boxDirection()) {
644                 case BNORMAL:
645                     return new CSSPrimitiveValue(CSS_VAL_NORMAL);
646                 case BREVERSE:
647                     return new CSSPrimitiveValue(CSS_VAL_REVERSE);
648             }
649             ASSERT_NOT_REACHED();
650             return 0;
651         case CSS_PROP__WEBKIT_BOX_FLEX:
652             return new CSSPrimitiveValue(style->boxFlex(), CSSPrimitiveValue::CSS_NUMBER);
653         case CSS_PROP__WEBKIT_BOX_FLEX_GROUP:
654             return new CSSPrimitiveValue(style->boxFlexGroup(), CSSPrimitiveValue::CSS_NUMBER);
655         case CSS_PROP__WEBKIT_BOX_LINES:
656             switch (style->boxLines()) {
657                 case SINGLE:
658                     return new CSSPrimitiveValue(CSS_VAL_SINGLE);
659                 case MULTIPLE:
660                     return new CSSPrimitiveValue(CSS_VAL_MULTIPLE);
661             }
662             ASSERT_NOT_REACHED();
663             return 0;
664         case CSS_PROP__WEBKIT_BOX_ORDINAL_GROUP:
665             return new CSSPrimitiveValue(style->boxOrdinalGroup(), CSSPrimitiveValue::CSS_NUMBER);
666         case CSS_PROP__WEBKIT_BOX_ORIENT:
667             switch (style->boxOrient()) {
668                 case HORIZONTAL:
669                     return new CSSPrimitiveValue(CSS_VAL_HORIZONTAL);
670                 case VERTICAL:
671                     return new CSSPrimitiveValue(CSS_VAL_VERTICAL);
672             }
673             ASSERT_NOT_REACHED();
674             return 0;
675         case CSS_PROP__WEBKIT_BOX_PACK:
676             switch (style->boxPack()) {
677                 case BSTART:
678                     return new CSSPrimitiveValue(CSS_VAL_START);
679                 case BEND:
680                     return new CSSPrimitiveValue(CSS_VAL_END);
681                 case BCENTER:
682                     return new CSSPrimitiveValue(CSS_VAL_CENTER);
683                 case BJUSTIFY:
684                     return new CSSPrimitiveValue(CSS_VAL_JUSTIFY);
685                 case BSTRETCH:
686                 case BBASELINE:
687                     break; // not allowed
688             }
689             ASSERT_NOT_REACHED();
690             return 0;
691         case CSS_PROP__WEBKIT_BOX_SHADOW:
692             return valueForShadow(style->boxShadow());
693         case CSS_PROP_CAPTION_SIDE:
694             switch (style->captionSide()) {
695                 case CAPLEFT:
696                     return new CSSPrimitiveValue(CSS_VAL_LEFT);
697                 case CAPRIGHT:
698                     return new CSSPrimitiveValue(CSS_VAL_RIGHT);
699                 case CAPTOP:
700                     return new CSSPrimitiveValue(CSS_VAL_TOP);
701                 case CAPBOTTOM:
702                     return new CSSPrimitiveValue(CSS_VAL_BOTTOM);
703             }
704             ASSERT_NOT_REACHED();
705             return 0;
706         case CSS_PROP_CLEAR:
707             switch (style->clear()) {
708                 case CNONE:
709                     return new CSSPrimitiveValue(CSS_VAL_NONE);
710                 case CLEFT:
711                     return new CSSPrimitiveValue(CSS_VAL_LEFT);
712                 case CRIGHT:
713                     return new CSSPrimitiveValue(CSS_VAL_RIGHT);
714                 case CBOTH:
715                     return new CSSPrimitiveValue(CSS_VAL_BOTH);
716             }
717             ASSERT_NOT_REACHED();
718             return 0;
719         case CSS_PROP_COLOR:
720             return new CSSPrimitiveValue(style->color().rgb());
721         case CSS_PROP__WEBKIT_COLUMN_COUNT:
722             if (style->hasAutoColumnCount())
723                 return new CSSPrimitiveValue(CSS_VAL_AUTO);
724             return new CSSPrimitiveValue(style->columnCount(), CSSPrimitiveValue::CSS_NUMBER);
725         case CSS_PROP__WEBKIT_COLUMN_GAP:
726             if (style->hasNormalColumnGap())
727                 return new CSSPrimitiveValue(CSS_VAL_NORMAL);
728             return new CSSPrimitiveValue(style->columnGap(), CSSPrimitiveValue::CSS_NUMBER);
729         case CSS_PROP__WEBKIT_COLUMN_RULE_COLOR:
730             return currentColorOrValidColor(style, style->columnRuleColor());
731         case CSS_PROP__WEBKIT_COLUMN_RULE_STYLE:
732             return valueForBorderStyle(style->columnRuleStyle());
733         case CSS_PROP__WEBKIT_COLUMN_RULE_WIDTH:
734             return new CSSPrimitiveValue(style->columnRuleWidth(), CSSPrimitiveValue::CSS_PX);
735         case CSS_PROP__WEBKIT_COLUMN_BREAK_AFTER:
736             switch (style->columnBreakAfter()) {
737                 case PBAUTO:
738                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
739                 case PBALWAYS:
740                     return new CSSPrimitiveValue(CSS_VAL_ALWAYS);
741                 case PBAVOID:
742                     return new CSSPrimitiveValue(CSS_VAL_AVOID);
743             }
744             ASSERT_NOT_REACHED();
745             return 0;
746         case CSS_PROP__WEBKIT_COLUMN_BREAK_BEFORE:
747             switch (style->columnBreakBefore()) {
748                 case PBAUTO:
749                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
750                 case PBALWAYS:
751                     return new CSSPrimitiveValue(CSS_VAL_ALWAYS);
752                 case PBAVOID:
753                     return new CSSPrimitiveValue(CSS_VAL_AVOID);
754             }
755             ASSERT_NOT_REACHED();
756             return 0;
757         case CSS_PROP__WEBKIT_COLUMN_BREAK_INSIDE:
758             switch (style->columnBreakInside()) {
759                 case PBAUTO:
760                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
761                 case PBAVOID:
762                     return new CSSPrimitiveValue(CSS_VAL_AVOID);
763                 case PBALWAYS:
764                     break; // not allowed
765             }
766             ASSERT_NOT_REACHED();
767             return 0;
768         case CSS_PROP__WEBKIT_COLUMN_WIDTH:
769             if (style->hasAutoColumnWidth())
770                 return new CSSPrimitiveValue(CSS_VAL_AUTO);
771             return new CSSPrimitiveValue(style->columnWidth(), CSSPrimitiveValue::CSS_NUMBER);
772         case CSS_PROP_CURSOR: {
773             CSSValueList* list = 0;
774             CursorList* cursors = style->cursors();
775             if (cursors && cursors->size() > 0) {
776                 list = new CSSValueList;
777                 for (unsigned i = 0; i < cursors->size(); ++i)
778                     list->append(new CSSPrimitiveValue((*cursors)[i].cursorImage->url(), CSSPrimitiveValue::CSS_URI));
779             }
780             CSSValue* value = 0;
781             switch (style->cursor()) {
782                 case CURSOR_AUTO:
783                     value = new CSSPrimitiveValue(CSS_VAL_AUTO);
784                     break;
785                 case CURSOR_CROSS:
786                     value = new CSSPrimitiveValue(CSS_VAL_CROSSHAIR);
787                     break;
788                 case CURSOR_DEFAULT:
789                     value = new CSSPrimitiveValue(CSS_VAL_DEFAULT);
790                     break;
791                 case CURSOR_POINTER:
792                     value = new CSSPrimitiveValue(CSS_VAL_POINTER);
793                     break;
794                 case CURSOR_MOVE:
795                     value = new CSSPrimitiveValue(CSS_VAL_MOVE);
796                     break;
797                 case CURSOR_CELL:
798                     value = new CSSPrimitiveValue(CSS_VAL_CELL);
799                     break;
800                 case CURSOR_VERTICAL_TEXT:
801                     value = new CSSPrimitiveValue(CSS_VAL_VERTICAL_TEXT);
802                     break;
803                 case CURSOR_CONTEXT_MENU:
804                     value = new CSSPrimitiveValue(CSS_VAL_CONTEXT_MENU);
805                     break;
806                 case CURSOR_ALIAS:
807                     value = new CSSPrimitiveValue(CSS_VAL_ALIAS);
808                     break;
809                 case CURSOR_COPY:
810                     value = new CSSPrimitiveValue(CSS_VAL_COPY);
811                     break;
812                 case CURSOR_NONE:
813                     value = new CSSPrimitiveValue(CSS_VAL_NONE);
814                     break;
815                 case CURSOR_PROGRESS:
816                     value = new CSSPrimitiveValue(CSS_VAL_PROGRESS);
817                     break;
818                 case CURSOR_NO_DROP:
819                     value = new CSSPrimitiveValue(CSS_VAL_NO_DROP);
820                     break;
821                 case CURSOR_NOT_ALLOWED:
822                     value = new CSSPrimitiveValue(CSS_VAL_NOT_ALLOWED);
823                     break;
824                 case CURSOR_E_RESIZE:
825                     value = new CSSPrimitiveValue(CSS_VAL_E_RESIZE);
826                     break;
827                 case CURSOR_NE_RESIZE:
828                     value = new CSSPrimitiveValue(CSS_VAL_NE_RESIZE);
829                     break;
830                 case CURSOR_NW_RESIZE:
831                     value = new CSSPrimitiveValue(CSS_VAL_NW_RESIZE);
832                     break;
833                 case CURSOR_N_RESIZE:
834                     value = new CSSPrimitiveValue(CSS_VAL_N_RESIZE);
835                     break;
836                 case CURSOR_SE_RESIZE:
837                     value = new CSSPrimitiveValue(CSS_VAL_SE_RESIZE);
838                     break;
839                 case CURSOR_SW_RESIZE:
840                     value = new CSSPrimitiveValue(CSS_VAL_SW_RESIZE);
841                     break;
842                 case CURSOR_S_RESIZE:
843                     value = new CSSPrimitiveValue(CSS_VAL_S_RESIZE);
844                     break;
845                 case CURSOR_W_RESIZE:
846                     value = new CSSPrimitiveValue(CSS_VAL_W_RESIZE);
847                     break;
848                 case CURSOR_EW_RESIZE:
849                     value = new CSSPrimitiveValue(CSS_VAL_EW_RESIZE);
850                     break;
851                 case CURSOR_NS_RESIZE:
852                     value = new CSSPrimitiveValue(CSS_VAL_NS_RESIZE);
853                     break;
854                 case CURSOR_NESW_RESIZE:
855                     value = new CSSPrimitiveValue(CSS_VAL_NESW_RESIZE);
856                     break;
857                 case CURSOR_NWSE_RESIZE:
858                     value = new CSSPrimitiveValue(CSS_VAL_NWSE_RESIZE);
859                     break;
860                 case CURSOR_COL_RESIZE:
861                     value = new CSSPrimitiveValue(CSS_VAL_COL_RESIZE);
862                     break;
863                 case CURSOR_ROW_RESIZE:
864                     value = new CSSPrimitiveValue(CSS_VAL_ROW_RESIZE);
865                     break;
866                 case CURSOR_TEXT:
867                     value = new CSSPrimitiveValue(CSS_VAL_TEXT);
868                     break;
869                 case CURSOR_WAIT:
870                     value = new CSSPrimitiveValue(CSS_VAL_WAIT);
871                     break;
872                 case CURSOR_HELP:
873                     value = new CSSPrimitiveValue(CSS_VAL_HELP);
874                     break;
875                 case CURSOR_ALL_SCROLL:
876                     value = new CSSPrimitiveValue(CSS_VAL_ALL_SCROLL);
877                     break;
878             }
879             ASSERT(value);
880             if (list) {
881                 list->append(value);
882                 return list;
883             }
884             return value;
885         }
886         case CSS_PROP_DIRECTION:
887             switch (style->direction()) {
888                 case LTR:
889                     return new CSSPrimitiveValue(CSS_VAL_LTR);
890                 case RTL:
891                     return new CSSPrimitiveValue(CSS_VAL_RTL);
892             }
893             ASSERT_NOT_REACHED();
894             return 0;
895         case CSS_PROP_DISPLAY:
896             switch (style->display()) {
897                 case INLINE:
898                     return new CSSPrimitiveValue(CSS_VAL_INLINE);
899                 case BLOCK:
900                     return new CSSPrimitiveValue(CSS_VAL_BLOCK);
901                 case LIST_ITEM:
902                     return new CSSPrimitiveValue(CSS_VAL_LIST_ITEM);
903                 case RUN_IN:
904                     return new CSSPrimitiveValue(CSS_VAL_RUN_IN);
905                 case COMPACT:
906                     return new CSSPrimitiveValue(CSS_VAL_COMPACT);
907                 case INLINE_BLOCK:
908                     return new CSSPrimitiveValue(CSS_VAL_INLINE_BLOCK);
909                 case TABLE:
910                     return new CSSPrimitiveValue(CSS_VAL_TABLE);
911                 case INLINE_TABLE:
912                     return new CSSPrimitiveValue(CSS_VAL_INLINE_TABLE);
913                 case TABLE_ROW_GROUP:
914                     return new CSSPrimitiveValue(CSS_VAL_TABLE_ROW_GROUP);
915                 case TABLE_HEADER_GROUP:
916                     return new CSSPrimitiveValue(CSS_VAL_TABLE_HEADER_GROUP);
917                 case TABLE_FOOTER_GROUP:
918                     return new CSSPrimitiveValue(CSS_VAL_TABLE_FOOTER_GROUP);
919                 case TABLE_ROW:
920                     return new CSSPrimitiveValue(CSS_VAL_TABLE_ROW);
921                 case TABLE_COLUMN_GROUP:
922                     return new CSSPrimitiveValue(CSS_VAL_TABLE_COLUMN_GROUP);
923                 case TABLE_COLUMN:
924                     return new CSSPrimitiveValue(CSS_VAL_TABLE_COLUMN);
925                 case TABLE_CELL:
926                     return new CSSPrimitiveValue(CSS_VAL_TABLE_CELL);
927                 case TABLE_CAPTION:
928                     return new CSSPrimitiveValue(CSS_VAL_TABLE_CAPTION);
929                 case BOX:
930                     return new CSSPrimitiveValue(CSS_VAL__WEBKIT_BOX);
931                 case INLINE_BOX:
932                     return new CSSPrimitiveValue(CSS_VAL__WEBKIT_INLINE_BOX);
933                 case NONE:
934                     return new CSSPrimitiveValue(CSS_VAL_NONE);
935             }
936             ASSERT_NOT_REACHED();
937             return 0;
938         case CSS_PROP_EMPTY_CELLS:
939             switch (style->emptyCells()) {
940                 case SHOW:
941                     return new CSSPrimitiveValue(CSS_VAL_SHOW);
942                 case HIDE:
943                     return new CSSPrimitiveValue(CSS_VAL_HIDE);
944             }
945             ASSERT_NOT_REACHED();
946             return 0;
947         case CSS_PROP_FLOAT:
948             switch (style->floating()) {
949                 case FNONE:
950                     return new CSSPrimitiveValue(CSS_VAL_NONE);
951                 case FLEFT:
952                     return new CSSPrimitiveValue(CSS_VAL_LEFT);
953                 case FRIGHT:
954                     return new CSSPrimitiveValue(CSS_VAL_RIGHT);
955             }
956             ASSERT_NOT_REACHED();
957             return 0;
958         case CSS_PROP_FONT_FAMILY:
959             // FIXME: This only returns the first family.
960             return new CSSPrimitiveValue(style->fontDescription().family().family().domString(), CSSPrimitiveValue::CSS_STRING);
961         case CSS_PROP_FONT_SIZE:
962             return new CSSPrimitiveValue(style->fontDescription().computedPixelSize(), CSSPrimitiveValue::CSS_PX);
963         case CSS_PROP__WEBKIT_BINDING:
964             break;
965         case CSS_PROP_FONT_STYLE:
966             if (style->fontDescription().italic())
967                 return new CSSPrimitiveValue(CSS_VAL_ITALIC);
968             return new CSSPrimitiveValue(CSS_VAL_NORMAL);
969         case CSS_PROP_FONT_VARIANT:
970             if (style->fontDescription().smallCaps())
971                 return new CSSPrimitiveValue(CSS_VAL_SMALL_CAPS);
972             return new CSSPrimitiveValue(CSS_VAL_NORMAL);
973         case CSS_PROP_FONT_WEIGHT:
974             // FIXME: this does not reflect the full range of weights
975             // that can be expressed with CSS
976             if (style->fontDescription().weight() == cBoldWeight)
977                 return new CSSPrimitiveValue(CSS_VAL_BOLD);
978             return new CSSPrimitiveValue(CSS_VAL_NORMAL);
979         case CSS_PROP_HEIGHT:
980             return new CSSPrimitiveValue(renderer->contentHeight(), CSSPrimitiveValue::CSS_PX);
981         case CSS_PROP__WEBKIT_HIGHLIGHT:
982             if (style->highlight() == nullAtom)
983                 return new CSSPrimitiveValue(CSS_VAL_NONE);
984             return new CSSPrimitiveValue(style->highlight(), CSSPrimitiveValue::CSS_STRING);
985         case CSS_PROP_LEFT:
986             return getPositionOffsetValue(renderer, CSS_PROP_LEFT);
987         case CSS_PROP_LETTER_SPACING:
988             if (!style->letterSpacing())
989                 return new CSSPrimitiveValue(CSS_VAL_NORMAL);
990             return new CSSPrimitiveValue(style->letterSpacing(), CSSPrimitiveValue::CSS_PX);
991         case CSS_PROP__WEBKIT_LINE_CLAMP:
992             if (style->lineClamp() == -1)
993                 return new CSSPrimitiveValue(CSS_VAL_NONE);
994             return new CSSPrimitiveValue(style->lineClamp(), CSSPrimitiveValue::CSS_PERCENTAGE);
995         case CSS_PROP_LINE_HEIGHT: {
996             Length length = style->lineHeight();
997             if (length.isNegative())
998                 return new CSSPrimitiveValue(CSS_VAL_NORMAL);
999             if (length.isPercent())
1000                 // This is imperfect, because it doesn't include the zoom factor and the real computation
1001                 // for how high to be in pixels does include things like minimum font size and the zoom factor.
1002                 // On the other hand, since font-size doesn't include the zoom factor, we really can't do
1003                 // that here either.
1004                 return new CSSPrimitiveValue(static_cast<int>(length.percent() * style->fontDescription().specifiedSize()) / 100, CSSPrimitiveValue::CSS_PX);
1005             return new CSSPrimitiveValue(length.value(), CSSPrimitiveValue::CSS_PX);
1006         }
1007         case CSS_PROP_LIST_STYLE_IMAGE:
1008             if (style->listStyleImage())
1009                 return new CSSPrimitiveValue(style->listStyleImage()->url(), CSSPrimitiveValue::CSS_URI);
1010             return new CSSPrimitiveValue(CSS_VAL_NONE);
1011         case CSS_PROP_LIST_STYLE_POSITION:
1012             switch (style->listStylePosition()) {
1013                 case OUTSIDE:
1014                     return new CSSPrimitiveValue(CSS_VAL_OUTSIDE);
1015                 case INSIDE:
1016                     return new CSSPrimitiveValue(CSS_VAL_INSIDE);
1017             }
1018             ASSERT_NOT_REACHED();
1019             return 0;
1020         case CSS_PROP_LIST_STYLE_TYPE:
1021             switch (style->listStyleType()) {
1022                 case LNONE:
1023                     return new CSSPrimitiveValue(CSS_VAL_NONE);
1024                 case DISC:
1025                     return new CSSPrimitiveValue(CSS_VAL_DISC);
1026                 case CIRCLE:
1027                     return new CSSPrimitiveValue(CSS_VAL_CIRCLE);
1028                 case SQUARE:
1029                     return new CSSPrimitiveValue(CSS_VAL_SQUARE);
1030                 case LDECIMAL:
1031                     return new CSSPrimitiveValue(CSS_VAL_DECIMAL);
1032                 case DECIMAL_LEADING_ZERO:
1033                     return new CSSPrimitiveValue(CSS_VAL_DECIMAL_LEADING_ZERO);
1034                 case LOWER_ROMAN:
1035                     return new CSSPrimitiveValue(CSS_VAL_LOWER_ROMAN);
1036                 case UPPER_ROMAN:
1037                     return new CSSPrimitiveValue(CSS_VAL_UPPER_ROMAN);
1038                 case LOWER_GREEK:
1039                     return new CSSPrimitiveValue(CSS_VAL_LOWER_GREEK);
1040                 case LOWER_ALPHA:
1041                     return new CSSPrimitiveValue(CSS_VAL_LOWER_ALPHA);
1042                 case LOWER_LATIN:
1043                     return new CSSPrimitiveValue(CSS_VAL_LOWER_LATIN);
1044                 case UPPER_ALPHA:
1045                     return new CSSPrimitiveValue(CSS_VAL_UPPER_ALPHA);
1046                 case UPPER_LATIN:
1047                     return new CSSPrimitiveValue(CSS_VAL_UPPER_LATIN);
1048                 case HEBREW:
1049                     return new CSSPrimitiveValue(CSS_VAL_HEBREW);
1050                 case ARMENIAN:
1051                     return new CSSPrimitiveValue(CSS_VAL_ARMENIAN);
1052                 case GEORGIAN:
1053                     return new CSSPrimitiveValue(CSS_VAL_GEORGIAN);
1054                 case CJK_IDEOGRAPHIC:
1055                     return new CSSPrimitiveValue(CSS_VAL_CJK_IDEOGRAPHIC);
1056                 case HIRAGANA:
1057                     return new CSSPrimitiveValue(CSS_VAL_HIRAGANA);
1058                 case KATAKANA:
1059                     return new CSSPrimitiveValue(CSS_VAL_KATAKANA);
1060                 case HIRAGANA_IROHA:
1061                     return new CSSPrimitiveValue(CSS_VAL_HIRAGANA_IROHA);
1062                 case KATAKANA_IROHA:
1063                     return new CSSPrimitiveValue(CSS_VAL_KATAKANA_IROHA);
1064             }
1065             ASSERT_NOT_REACHED();
1066             return 0;
1067         case CSS_PROP_MARGIN_TOP:
1068             // FIXME: Supposed to return the percentage if percentage was specified.
1069             return new CSSPrimitiveValue(renderer->marginTop(), CSSPrimitiveValue::CSS_PX);
1070         case CSS_PROP_MARGIN_RIGHT:
1071             // FIXME: Supposed to return the percentage if percentage was specified.
1072             return new CSSPrimitiveValue(renderer->marginRight(), CSSPrimitiveValue::CSS_PX);
1073         case CSS_PROP_MARGIN_BOTTOM:
1074             // FIXME: Supposed to return the percentage if percentage was specified.
1075             return new CSSPrimitiveValue(renderer->marginBottom(), CSSPrimitiveValue::CSS_PX);
1076         case CSS_PROP_MARGIN_LEFT:
1077             // FIXME: Supposed to return the percentage if percentage was specified.
1078             return new CSSPrimitiveValue(renderer->marginLeft(), CSSPrimitiveValue::CSS_PX);
1079         case CSS_PROP__WEBKIT_MARQUEE_DIRECTION:
1080             switch (style->marqueeDirection()) {
1081                 case MFORWARD:
1082                     return new CSSPrimitiveValue(CSS_VAL_FORWARDS);
1083                 case MBACKWARD:
1084                     return new CSSPrimitiveValue(CSS_VAL_BACKWARDS);
1085                 case MAUTO:
1086                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
1087                 case MUP:
1088                     return new CSSPrimitiveValue(CSS_VAL_UP);
1089                 case MDOWN:
1090                     return new CSSPrimitiveValue(CSS_VAL_DOWN);
1091                 case MLEFT:
1092                     return new CSSPrimitiveValue(CSS_VAL_LEFT);
1093                 case MRIGHT:
1094                     return new CSSPrimitiveValue(CSS_VAL_RIGHT);
1095             }
1096             ASSERT_NOT_REACHED();
1097             return 0;
1098         case CSS_PROP__WEBKIT_MARQUEE_INCREMENT:
1099             return valueForLength(style->marqueeIncrement());
1100         case CSS_PROP__WEBKIT_MARQUEE_REPETITION:
1101             if (style->marqueeLoopCount() < 0)
1102                 return new CSSPrimitiveValue(CSS_VAL_INFINITE);
1103             return new CSSPrimitiveValue(style->marqueeLoopCount(), CSSPrimitiveValue::CSS_NUMBER);
1104         case CSS_PROP__WEBKIT_MARQUEE_STYLE:
1105             switch (style->marqueeBehavior()) {
1106                 case MNONE:
1107                     return new CSSPrimitiveValue(CSS_VAL_NONE);
1108                 case MSCROLL:
1109                     return new CSSPrimitiveValue(CSS_VAL_SCROLL);
1110                 case MSLIDE:
1111                     return new CSSPrimitiveValue(CSS_VAL_SLIDE);
1112                 case MALTERNATE:
1113                     return new CSSPrimitiveValue(CSS_VAL_ALTERNATE);
1114             }
1115             ASSERT_NOT_REACHED();
1116             return 0;
1117         case CSS_PROP__WEBKIT_USER_MODIFY:
1118             switch (style->userModify()) {
1119                 case READ_ONLY:
1120                     return new CSSPrimitiveValue(CSS_VAL_READ_ONLY);
1121                 case READ_WRITE:
1122                     return new CSSPrimitiveValue(CSS_VAL_READ_WRITE);
1123                 case READ_WRITE_PLAINTEXT_ONLY:
1124                     return new CSSPrimitiveValue(CSS_VAL_READ_WRITE_PLAINTEXT_ONLY);
1125             }
1126             ASSERT_NOT_REACHED();
1127             return 0;
1128         case CSS_PROP_MAX_HEIGHT:
1129             return valueForMaxLength(style->maxHeight());
1130         case CSS_PROP_MAX_WIDTH:
1131             return valueForMaxLength(style->maxWidth());
1132         case CSS_PROP_MIN_HEIGHT:
1133             return valueForLength(style->minHeight());
1134         case CSS_PROP_MIN_WIDTH:
1135             return valueForLength(style->minWidth());
1136         case CSS_PROP_OPACITY:
1137             return new CSSPrimitiveValue(style->opacity(), CSSPrimitiveValue::CSS_NUMBER);
1138         case CSS_PROP_ORPHANS:
1139             return new CSSPrimitiveValue(style->orphans(), CSSPrimitiveValue::CSS_NUMBER);
1140         case CSS_PROP_OUTLINE_COLOR:
1141             return currentColorOrValidColor(style, style->outlineColor());
1142         case CSS_PROP_OUTLINE_STYLE:
1143             if (style->outlineStyleIsAuto())
1144                 return new CSSPrimitiveValue(CSS_VAL_AUTO);
1145             return valueForBorderStyle(style->outlineStyle());
1146         case CSS_PROP_OUTLINE_WIDTH:
1147             return new CSSPrimitiveValue(style->outlineWidth(), CSSPrimitiveValue::CSS_PX);
1148         case CSS_PROP_OVERFLOW:
1149         case CSS_PROP_OVERFLOW_X:
1150         case CSS_PROP_OVERFLOW_Y: {
1151             EOverflow overflow;
1152             switch (propertyID) {
1153                 case CSS_PROP_OVERFLOW_X:
1154                     overflow = style->overflowX();
1155                     break;
1156                 case CSS_PROP_OVERFLOW_Y:
1157                     overflow = style->overflowY();
1158                     break;
1159                 default:
1160                     overflow = max(style->overflowX(), style->overflowY());
1161             }
1162             switch (overflow) {
1163                 case OVISIBLE:
1164                     return new CSSPrimitiveValue(CSS_VAL_VISIBLE);
1165                 case OHIDDEN:
1166                     return new CSSPrimitiveValue(CSS_VAL_HIDDEN);
1167                 case OSCROLL:
1168                     return new CSSPrimitiveValue(CSS_VAL_SCROLL);
1169                 case OAUTO:
1170                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
1171                 case OMARQUEE:
1172                     return new CSSPrimitiveValue(CSS_VAL__WEBKIT_MARQUEE);
1173                 case OOVERLAY:
1174                     return new CSSPrimitiveValue(CSS_VAL_OVERLAY);
1175             }
1176             ASSERT_NOT_REACHED();
1177             return 0;
1178         }
1179         case CSS_PROP_PADDING_TOP:
1180             return new CSSPrimitiveValue(renderer->paddingTop(), CSSPrimitiveValue::CSS_PX);
1181         case CSS_PROP_PADDING_RIGHT:
1182             return new CSSPrimitiveValue(renderer->paddingRight(), CSSPrimitiveValue::CSS_PX);
1183         case CSS_PROP_PADDING_BOTTOM:
1184             return new CSSPrimitiveValue(renderer->paddingBottom(), CSSPrimitiveValue::CSS_PX);
1185         case CSS_PROP_PADDING_LEFT:
1186             return new CSSPrimitiveValue(renderer->paddingLeft(), CSSPrimitiveValue::CSS_PX);
1187         case CSS_PROP_PAGE_BREAK_AFTER:
1188             switch (style->pageBreakAfter()) {
1189                 case PBAUTO:
1190                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
1191                 case PBALWAYS:
1192                     return new CSSPrimitiveValue(CSS_VAL_ALWAYS);
1193                 case PBAVOID:
1194                     return new CSSPrimitiveValue(CSS_VAL_AVOID);
1195             }
1196             ASSERT_NOT_REACHED();
1197             return 0;
1198         case CSS_PROP_PAGE_BREAK_BEFORE:
1199             switch (style->pageBreakBefore()) {
1200                 case PBAUTO:
1201                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
1202                 case PBALWAYS:
1203                     return new CSSPrimitiveValue(CSS_VAL_ALWAYS);
1204                 case PBAVOID:
1205                     return new CSSPrimitiveValue(CSS_VAL_AVOID);
1206             }
1207             ASSERT_NOT_REACHED();
1208             return 0;
1209         case CSS_PROP_PAGE_BREAK_INSIDE:
1210             switch (style->pageBreakInside()) {
1211                 case PBAUTO:
1212                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
1213                 case PBAVOID:
1214                     return new CSSPrimitiveValue(CSS_VAL_AVOID);
1215                 case PBALWAYS:
1216                     break; // not allowed
1217             }
1218             ASSERT_NOT_REACHED();
1219             return 0;
1220         case CSS_PROP_POSITION:
1221             switch (style->position()) {
1222                 case StaticPosition:
1223                     return new CSSPrimitiveValue(CSS_VAL_STATIC);
1224                 case RelativePosition:
1225                     return new CSSPrimitiveValue(CSS_VAL_RELATIVE);
1226                 case AbsolutePosition:
1227                     return new CSSPrimitiveValue(CSS_VAL_ABSOLUTE);
1228                 case FixedPosition:
1229                     return new CSSPrimitiveValue(CSS_VAL_FIXED);
1230             }
1231             ASSERT_NOT_REACHED();
1232             return 0;
1233         case CSS_PROP_RIGHT:
1234             return getPositionOffsetValue(renderer, CSS_PROP_RIGHT);
1235         case CSS_PROP_TABLE_LAYOUT:
1236             switch (style->tableLayout()) {
1237                 case TAUTO:
1238                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
1239                 case TFIXED:
1240                     return new CSSPrimitiveValue(CSS_VAL_FIXED);
1241             }
1242             ASSERT_NOT_REACHED();
1243             return 0;
1244         case CSS_PROP_TEXT_ALIGN:
1245             return valueForTextAlign(style->textAlign());
1246         case CSS_PROP_TEXT_DECORATION: {
1247             String string;
1248             if (style->textDecoration() & UNDERLINE)
1249                 string += "underline";
1250             if (style->textDecoration() & OVERLINE) {
1251                 if (string.length())
1252                     string += " ";
1253                 string += "overline";
1254             }
1255             if (style->textDecoration() & LINE_THROUGH) {
1256                 if (string.length())
1257                     string += " ";
1258                 string += "line-through";
1259             }
1260             if (style->textDecoration() & BLINK) {
1261                 if (string.length())
1262                     string += " ";
1263                 string += "blink";
1264             }
1265             if (!string.length())
1266                 return new CSSPrimitiveValue(CSS_VAL_NONE);
1267             return new CSSPrimitiveValue(string, CSSPrimitiveValue::CSS_STRING);
1268         }
1269         case CSS_PROP__WEBKIT_TEXT_DECORATIONS_IN_EFFECT: {
1270             String string;
1271             if (style->textDecorationsInEffect() & UNDERLINE)
1272                 string += "underline";
1273             if (style->textDecorationsInEffect() & OVERLINE) {
1274                 if (string.length())
1275                     string += " ";
1276                 string += "overline";
1277             }
1278             if (style->textDecorationsInEffect() & LINE_THROUGH) {
1279                 if (string.length())
1280                     string += " ";
1281                 string += "line-through";
1282             }
1283             if (style->textDecorationsInEffect() & BLINK) {
1284                 if (string.length())
1285                     string += " ";
1286                 string += "blink";
1287             }
1288             if (!string.length())
1289                 return new CSSPrimitiveValue(CSS_VAL_NONE);
1290             return new CSSPrimitiveValue(string, CSSPrimitiveValue::CSS_STRING);
1291         }
1292         case CSS_PROP__WEBKIT_TEXT_FILL_COLOR:
1293             return currentColorOrValidColor(style, style->textFillColor());
1294         case CSS_PROP_TEXT_INDENT:
1295             return valueForLength(style->textIndent());
1296         case CSS_PROP_TEXT_SHADOW:
1297             return valueForShadow(style->textShadow());
1298         case CSS_PROP__WEBKIT_TEXT_SECURITY:
1299             switch (style->textSecurity()) {
1300                 case TSNONE:
1301                     return new CSSPrimitiveValue(CSS_VAL_NONE);
1302                 case TSDISC:
1303                     return new CSSPrimitiveValue(CSS_VAL_DISC);
1304                 case TSCIRCLE:
1305                     return new CSSPrimitiveValue(CSS_VAL_CIRCLE);
1306                 case TSSQUARE:
1307                     return new CSSPrimitiveValue(CSS_VAL_SQUARE);
1308             }
1309             ASSERT_NOT_REACHED();
1310             return 0;
1311         case CSS_PROP__WEBKIT_TEXT_SIZE_ADJUST:
1312             if (style->textSizeAdjust())
1313                 return new CSSPrimitiveValue(CSS_VAL_AUTO);
1314             return new CSSPrimitiveValue(CSS_VAL_NONE);
1315         case CSS_PROP__WEBKIT_TEXT_STROKE_COLOR:
1316             return currentColorOrValidColor(style, style->textStrokeColor());
1317         case CSS_PROP__WEBKIT_TEXT_STROKE_WIDTH:
1318             return new CSSPrimitiveValue(style->textStrokeWidth(), CSSPrimitiveValue::CSS_NUMBER);
1319         case CSS_PROP_TEXT_TRANSFORM:
1320             switch (style->textTransform()) {
1321                 case CAPITALIZE:
1322                     return new CSSPrimitiveValue(CSS_VAL_CAPITALIZE);
1323                 case UPPERCASE:
1324                     return new CSSPrimitiveValue(CSS_VAL_UPPERCASE);
1325                 case LOWERCASE:
1326                     return new CSSPrimitiveValue(CSS_VAL_LOWERCASE);
1327                 case TTNONE:
1328                     return new CSSPrimitiveValue(CSS_VAL_NONE);
1329             }
1330             ASSERT_NOT_REACHED();
1331             return 0;
1332         case CSS_PROP_TOP:
1333             return getPositionOffsetValue(renderer, CSS_PROP_TOP);
1334         case CSS_PROP_UNICODE_BIDI:
1335             switch (style->unicodeBidi()) {
1336                 case UBNormal:
1337                     return new CSSPrimitiveValue(CSS_VAL_NORMAL);
1338                 case Embed:
1339                     return new CSSPrimitiveValue(CSS_VAL_EMBED);
1340                 case Override:
1341                     return new CSSPrimitiveValue(CSS_VAL_BIDI_OVERRIDE);
1342             }
1343             ASSERT_NOT_REACHED();
1344             return 0;
1345         case CSS_PROP_VERTICAL_ALIGN:
1346             switch (style->verticalAlign()) {
1347                 case BASELINE:
1348                     return new CSSPrimitiveValue(CSS_VAL_BASELINE);
1349                 case MIDDLE:
1350                     return new CSSPrimitiveValue(CSS_VAL_MIDDLE);
1351                 case SUB:
1352                     return new CSSPrimitiveValue(CSS_VAL_SUB);
1353                 case SUPER:
1354                     return new CSSPrimitiveValue(CSS_VAL_SUPER);
1355                 case TEXT_TOP:
1356                     return new CSSPrimitiveValue(CSS_VAL_TEXT_TOP);
1357                 case TEXT_BOTTOM:
1358                     return new CSSPrimitiveValue(CSS_VAL_TEXT_BOTTOM);
1359                 case TOP:
1360                     return new CSSPrimitiveValue(CSS_VAL_TOP);
1361                 case BOTTOM:
1362                     return new CSSPrimitiveValue(CSS_VAL_BOTTOM);
1363                 case BASELINE_MIDDLE:
1364                     return new CSSPrimitiveValue(CSS_VAL__WEBKIT_BASELINE_MIDDLE);
1365                 case LENGTH:
1366                     return valueForLength(style->verticalAlignLength());
1367             }
1368             ASSERT_NOT_REACHED();
1369             return 0;
1370         case CSS_PROP_VISIBILITY:
1371             switch (style->visibility()) {
1372                 case VISIBLE:
1373                     return new CSSPrimitiveValue(CSS_VAL_VISIBLE);
1374                 case HIDDEN:
1375                     return new CSSPrimitiveValue(CSS_VAL_HIDDEN);
1376                 case COLLAPSE:
1377                     return new CSSPrimitiveValue(CSS_VAL_COLLAPSE);
1378             }
1379             ASSERT_NOT_REACHED();
1380             return 0;
1381         case CSS_PROP_WHITE_SPACE:
1382             switch (style->whiteSpace()) {
1383                 case NORMAL:
1384                     return new CSSPrimitiveValue(CSS_VAL_NORMAL);
1385                 case PRE:
1386                     return new CSSPrimitiveValue(CSS_VAL_PRE);
1387                 case PRE_WRAP:
1388                     return new CSSPrimitiveValue(CSS_VAL_PRE_WRAP);
1389                 case PRE_LINE:
1390                     return new CSSPrimitiveValue(CSS_VAL_PRE_LINE);
1391                 case NOWRAP:
1392                     return new CSSPrimitiveValue(CSS_VAL_NOWRAP);
1393                 case KHTML_NOWRAP:
1394                     return new CSSPrimitiveValue(CSS_VAL__WEBKIT_NOWRAP);
1395             }
1396             ASSERT_NOT_REACHED();
1397             return 0;
1398         case CSS_PROP_WIDOWS:
1399             return new CSSPrimitiveValue(style->widows(), CSSPrimitiveValue::CSS_NUMBER);
1400         case CSS_PROP_WIDTH:
1401             return new CSSPrimitiveValue(renderer->contentWidth(), CSSPrimitiveValue::CSS_PX);
1402         case CSS_PROP_WORD_SPACING:
1403             return new CSSPrimitiveValue(style->wordSpacing(), CSSPrimitiveValue::CSS_PX);
1404         case CSS_PROP_WORD_WRAP:
1405             switch (style->wordWrap()) {
1406                 case WBNORMAL:
1407                     return new CSSPrimitiveValue(CSS_VAL_NORMAL);
1408                 case BREAK_WORD:
1409                     return new CSSPrimitiveValue(CSS_VAL_BREAK_WORD);
1410             }
1411             ASSERT_NOT_REACHED();
1412             return 0;
1413         case CSS_PROP__WEBKIT_LINE_BREAK:
1414             switch (style->khtmlLineBreak()) {
1415                 case LBNORMAL:
1416                     return new CSSPrimitiveValue(CSS_VAL_NORMAL);
1417                 case AFTER_WHITE_SPACE:
1418                     return new CSSPrimitiveValue(CSS_VAL_AFTER_WHITE_SPACE);
1419             }
1420             ASSERT_NOT_REACHED();
1421             return 0;
1422         case CSS_PROP__WEBKIT_NBSP_MODE:
1423             switch (style->nbspMode()) {
1424                 case NBNORMAL:
1425                     return new CSSPrimitiveValue(CSS_VAL_NORMAL);
1426                 case SPACE:
1427                     return new CSSPrimitiveValue(CSS_VAL_SPACE);
1428             }
1429             ASSERT_NOT_REACHED();
1430             return 0;
1431         case CSS_PROP__WEBKIT_MATCH_NEAREST_MAIL_BLOCKQUOTE_COLOR:
1432             switch (style->matchNearestMailBlockquoteColor()) {
1433                 case BCNORMAL:
1434                     return new CSSPrimitiveValue(CSS_VAL_NORMAL);
1435                 case MATCH:
1436                     return new CSSPrimitiveValue(CSS_VAL_MATCH);
1437             }
1438             ASSERT_NOT_REACHED();
1439             return 0;
1440         case CSS_PROP_RESIZE:
1441             switch (style->resize()) {
1442                 case RESIZE_BOTH:
1443                     return new CSSPrimitiveValue(CSS_VAL_BOTH);
1444                 case RESIZE_HORIZONTAL:
1445                     return new CSSPrimitiveValue(CSS_VAL_HORIZONTAL);
1446                 case RESIZE_VERTICAL:
1447                     return new CSSPrimitiveValue(CSS_VAL_VERTICAL);
1448                 case RESIZE_NONE:
1449                     return new CSSPrimitiveValue(CSS_VAL_NONE);
1450             }
1451             ASSERT_NOT_REACHED();
1452             return 0;
1453         case CSS_PROP_Z_INDEX:
1454             if (style->hasAutoZIndex())
1455                 return new CSSPrimitiveValue(CSS_VAL_NORMAL);
1456             return new CSSPrimitiveValue(style->zIndex(), CSSPrimitiveValue::CSS_NUMBER);
1457         case CSS_PROP_BOX_SIZING:
1458             if (style->boxSizing() == CONTENT_BOX)
1459                 new CSSPrimitiveValue(CSS_VAL_CONTENT_BOX);
1460             return new CSSPrimitiveValue(CSS_VAL_BORDER_BOX);
1461         case CSS_PROP__WEBKIT_DASHBOARD_REGION:
1462 #if PLATFORM(MAC)
1463         {
1464             const Vector<StyleDashboardRegion>& regions = style->dashboardRegions();
1465             unsigned count = regions.size();
1466             if (count == 1 && regions[0].type == StyleDashboardRegion::None)
1467                 return new CSSPrimitiveValue(CSS_VAL_NONE);
1468
1469             RefPtr<DashboardRegion> firstRegion;
1470             DashboardRegion* previousRegion = 0;
1471             for (unsigned i = 0; i < count; i++) {
1472                 RefPtr<DashboardRegion> region = new DashboardRegion;
1473                 StyleDashboardRegion styleRegion = regions[i];
1474
1475                 region->m_label = styleRegion.label;
1476                 LengthBox offset = styleRegion.offset;
1477                 region->setTop(new CSSPrimitiveValue(offset.top.value(), CSSPrimitiveValue::CSS_PX));
1478                 region->setRight(new CSSPrimitiveValue(offset.right.value(), CSSPrimitiveValue::CSS_PX));
1479                 region->setBottom(new CSSPrimitiveValue(offset.bottom.value(), CSSPrimitiveValue::CSS_PX));
1480                 region->setLeft(new CSSPrimitiveValue(offset.left.value(), CSSPrimitiveValue::CSS_PX));
1481                 region->m_isRectangle = (styleRegion.type == StyleDashboardRegion::Rectangle);
1482                 region->m_isCircle = (styleRegion.type == StyleDashboardRegion::Circle);
1483
1484                 if (previousRegion)
1485                     previousRegion->m_next = region;
1486                 else
1487                     firstRegion = region;
1488                 previousRegion = region.get();
1489             }
1490             return new CSSPrimitiveValue(firstRegion.release());
1491         }
1492 #else
1493             break;
1494 #endif
1495         case CSS_PROP__WEBKIT_APPEARANCE:
1496             return valueForAppearance(style->appearance());
1497         case CSS_PROP__WEBKIT_FONT_SIZE_DELTA:
1498             // Not a real style property -- used by the editing engine -- so has no computed value.
1499             break;
1500         case CSS_PROP__WEBKIT_MARGIN_BOTTOM_COLLAPSE:
1501             return valueForMarginCollapse(style->marginBottomCollapse());
1502         case CSS_PROP__WEBKIT_MARGIN_TOP_COLLAPSE:
1503             return valueForMarginCollapse(style->marginTopCollapse());
1504         case CSS_PROP__WEBKIT_RTL_ORDERING:
1505             if (style->visuallyOrdered())
1506                 return new CSSPrimitiveValue(CSS_VAL_VISUAL);
1507             return new CSSPrimitiveValue(CSS_VAL_LOGICAL);
1508         case CSS_PROP__WEBKIT_USER_DRAG:
1509             switch (style->userDrag()) {
1510                 case DRAG_AUTO:
1511                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
1512                 case DRAG_NONE:
1513                     return new CSSPrimitiveValue(CSS_VAL_NONE);
1514                 case DRAG_ELEMENT:
1515                     return new CSSPrimitiveValue(CSS_VAL_ELEMENT);
1516             }
1517             break;
1518         case CSS_PROP__WEBKIT_USER_SELECT:
1519             switch (style->userSelect()) {
1520                 case SELECT_AUTO:
1521                     return new CSSPrimitiveValue(CSS_VAL_AUTO);
1522                 case SELECT_NONE:
1523                     return new CSSPrimitiveValue(CSS_VAL_NONE);
1524                 case SELECT_TEXT:
1525                     return new CSSPrimitiveValue(CSS_VAL_TEXT);
1526                 case SELECT_IGNORE:
1527                     return new CSSPrimitiveValue(CSS_VAL_IGNORE);
1528             }
1529             break;
1530         case CSS_PROP_BACKGROUND:
1531         case CSS_PROP_BORDER:
1532         case CSS_PROP_BORDER_BOTTOM:
1533         case CSS_PROP_BORDER_COLOR:
1534         case CSS_PROP_BORDER_LEFT:
1535         case CSS_PROP_BORDER_RIGHT:
1536         case CSS_PROP_BORDER_STYLE:
1537         case CSS_PROP_BORDER_TOP:
1538         case CSS_PROP_BORDER_WIDTH:
1539         case CSS_PROP_CLIP:
1540         case CSS_PROP_CONTENT:
1541         case CSS_PROP_COUNTER_INCREMENT:
1542         case CSS_PROP_COUNTER_RESET:
1543         case CSS_PROP_FONT:
1544         case CSS_PROP_FONT_STRETCH:
1545         case CSS_PROP_LIST_STYLE:
1546         case CSS_PROP_MARGIN:
1547         case CSS_PROP_OUTLINE:
1548         case CSS_PROP_OUTLINE_OFFSET:
1549         case CSS_PROP_PADDING:
1550         case CSS_PROP_PAGE:
1551         case CSS_PROP_QUOTES:
1552         case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR:
1553         case CSS_PROP_SCROLLBAR_ARROW_COLOR:
1554         case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR:
1555         case CSS_PROP_SCROLLBAR_FACE_COLOR:
1556         case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR:
1557         case CSS_PROP_SCROLLBAR_SHADOW_COLOR:
1558         case CSS_PROP_SCROLLBAR_TRACK_COLOR:
1559         case CSS_PROP_SIZE:
1560         case CSS_PROP_TEXT_LINE_THROUGH:
1561         case CSS_PROP_TEXT_LINE_THROUGH_COLOR:
1562         case CSS_PROP_TEXT_LINE_THROUGH_MODE:
1563         case CSS_PROP_TEXT_LINE_THROUGH_STYLE:
1564         case CSS_PROP_TEXT_LINE_THROUGH_WIDTH:
1565         case CSS_PROP_TEXT_OVERFLOW:
1566         case CSS_PROP_TEXT_OVERLINE:
1567         case CSS_PROP_TEXT_OVERLINE_COLOR:
1568         case CSS_PROP_TEXT_OVERLINE_MODE:
1569         case CSS_PROP_TEXT_OVERLINE_STYLE:
1570         case CSS_PROP_TEXT_OVERLINE_WIDTH:
1571         case CSS_PROP_TEXT_UNDERLINE:
1572         case CSS_PROP_TEXT_UNDERLINE_COLOR:
1573         case CSS_PROP_TEXT_UNDERLINE_MODE:
1574         case CSS_PROP_TEXT_UNDERLINE_STYLE:
1575         case CSS_PROP_TEXT_UNDERLINE_WIDTH:
1576         case CSS_PROP__WEBKIT_BORDER_BOTTOM_LEFT_RADIUS:
1577         case CSS_PROP__WEBKIT_BORDER_BOTTOM_RIGHT_RADIUS:
1578         case CSS_PROP__WEBKIT_BORDER_IMAGE:
1579         case CSS_PROP__WEBKIT_BORDER_RADIUS:
1580         case CSS_PROP__WEBKIT_BORDER_TOP_LEFT_RADIUS:
1581         case CSS_PROP__WEBKIT_BORDER_TOP_RIGHT_RADIUS:
1582         case CSS_PROP__WEBKIT_COLUMNS:
1583         case CSS_PROP__WEBKIT_COLUMN_RULE:
1584         case CSS_PROP__WEBKIT_MARGIN_COLLAPSE:
1585         case CSS_PROP__WEBKIT_MARGIN_START:
1586         case CSS_PROP__WEBKIT_MARQUEE:
1587         case CSS_PROP__WEBKIT_MARQUEE_SPEED:
1588         case CSS_PROP__WEBKIT_PADDING_START:
1589         case CSS_PROP__WEBKIT_TEXT_STROKE:
1590             // FIXME: The above are unimplemented.
1591             break;
1592     }
1593
1594     LOG_ERROR("unimplemented propertyID: %d", propertyID);
1595     return 0;
1596 }
1597
1598 String CSSComputedStyleDeclaration::getPropertyValue(int propertyID) const
1599 {
1600     RefPtr<CSSValue> value = getPropertyCSSValue(propertyID);
1601     if (value)
1602         return value->cssText();
1603     return "";
1604 }
1605
1606 bool CSSComputedStyleDeclaration::getPropertyPriority(int /*propertyID*/) const
1607 {
1608     // All computed styles have a priority of false (not "important").
1609     return false;
1610 }
1611
1612 String CSSComputedStyleDeclaration::removeProperty(int /*propertyID*/, ExceptionCode& ec)
1613 {
1614     ec = NO_MODIFICATION_ALLOWED_ERR;
1615     return String();
1616 }
1617
1618 void CSSComputedStyleDeclaration::setProperty(int /*propertyID*/, const String& /*value*/, bool /*important*/, ExceptionCode& ec)
1619 {
1620     ec = NO_MODIFICATION_ALLOWED_ERR;
1621 }
1622
1623 unsigned CSSComputedStyleDeclaration::length() const
1624 {
1625     Node* node = m_node.get();
1626     if (!node)
1627         return 0;
1628
1629     RenderObject* renderer = node->renderer();
1630     if (!renderer)
1631         return 0;
1632
1633     RenderStyle* style = renderer->style();
1634     if (!style)
1635         return 0;
1636
1637     return numComputedProperties;
1638 }
1639
1640 String CSSComputedStyleDeclaration::item(unsigned i) const
1641 {
1642     if (i >= length())
1643         return String();
1644
1645     return getPropertyName(static_cast<CSSPropertyID>(computedProperties[i]));
1646 }
1647
1648 // This is the list of properties we want to copy in the copyInheritableProperties() function.
1649 // It is the intersection of the list of inherited CSS properties and the
1650 // properties for which we have a computed implementation in this file.
1651 const int inheritableProperties[] = {
1652     CSS_PROP_BORDER_COLLAPSE,
1653     CSS_PROP_COLOR,
1654     CSS_PROP_FONT_FAMILY,
1655     CSS_PROP_FONT_SIZE,
1656     CSS_PROP_FONT_STYLE,
1657     CSS_PROP_FONT_VARIANT,
1658     CSS_PROP_FONT_WEIGHT,
1659     CSS_PROP_LETTER_SPACING,
1660     CSS_PROP_LINE_HEIGHT,
1661     CSS_PROP_ORPHANS,
1662     CSS_PROP_TEXT_ALIGN,
1663     CSS_PROP_TEXT_INDENT,
1664     CSS_PROP_TEXT_TRANSFORM,
1665     CSS_PROP_WHITE_SPACE,
1666     CSS_PROP_WIDOWS,
1667     CSS_PROP_WORD_SPACING,
1668     CSS_PROP__WEBKIT_BORDER_HORIZONTAL_SPACING,
1669     CSS_PROP__WEBKIT_BORDER_VERTICAL_SPACING,
1670     CSS_PROP__WEBKIT_TEXT_DECORATIONS_IN_EFFECT,
1671     CSS_PROP__WEBKIT_TEXT_FILL_COLOR,
1672     CSS_PROP__WEBKIT_TEXT_SIZE_ADJUST,
1673     CSS_PROP__WEBKIT_TEXT_STROKE_COLOR,
1674     CSS_PROP__WEBKIT_TEXT_STROKE_WIDTH,
1675 };
1676
1677 const unsigned numInheritableProperties = sizeof(inheritableProperties) / sizeof(inheritableProperties[0]);
1678
1679 void CSSComputedStyleDeclaration::removeComputedInheritablePropertiesFrom(CSSMutableStyleDeclaration* declaration)
1680 {
1681     declaration->removePropertiesInSet(inheritableProperties, numInheritableProperties);
1682 }
1683
1684 PassRefPtr<CSSMutableStyleDeclaration> CSSComputedStyleDeclaration::copyInheritableProperties() const
1685 {
1686     return copyPropertiesInSet(inheritableProperties, numInheritableProperties);
1687 }
1688
1689 PassRefPtr<CSSMutableStyleDeclaration> CSSComputedStyleDeclaration::copy() const
1690 {
1691     return copyPropertiesInSet(computedProperties, numComputedProperties);
1692 }
1693
1694 PassRefPtr<CSSMutableStyleDeclaration> CSSComputedStyleDeclaration::makeMutable()
1695 {
1696     return copy();
1697 }
1698
1699 } // namespace WebCore