Reviewed by Ken.
[WebKit-https.git] / WebCore / khtml / css / css_computedstyle.cpp
1 /**
2  * css_computedstyle.cpp
3  *
4  * Copyright (C)  2004  Zack Rusin <zack@kde.org>
5  * Copyright (C) 2004 Apple Computer, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307  USA
21  */
22
23 #include "css_computedstyle.h"
24
25 #include "cssproperties.h"
26 #include "cssvalues.h"
27 #include "dom_atomicstring.h"
28 #include "dom_exception.h"
29 #include "dom_string.h"
30 #include "font.h"
31 #include "khtmllayout.h"
32 #include "loader.h"
33 #include "rendering/render_style.h"
34 #include "rendering/render_object.h"
35
36 #if APPLE_CHANGES
37 #import "KWQAssertions.h"
38 #import "KWQFontFamily.h"
39 #import "KWQLogging.h"
40 #endif
41
42 using khtml::EBorderStyle;
43 using khtml::ETextAlign;
44 using khtml::Font;
45 using khtml::FontDef;
46 using khtml::Length;
47 using khtml::LengthBox;
48 using khtml::RenderObject;
49 using khtml::RenderStyle;
50 using khtml::ShadowData;
51 using khtml::StyleDashboardRegion;
52
53 namespace DOM {
54
55 // List of all properties we know how to compute, omitting shorthands.
56 static const int computedProperties[] = {
57     CSS_PROP_BACKGROUND_COLOR,
58     CSS_PROP_BACKGROUND_IMAGE,
59     CSS_PROP_BACKGROUND_REPEAT,
60     CSS_PROP_BACKGROUND_ATTACHMENT,
61     CSS_PROP_BACKGROUND_POSITION,
62     CSS_PROP_BACKGROUND_POSITION_X,
63     CSS_PROP_BACKGROUND_POSITION_Y,
64     CSS_PROP_BORDER_COLLAPSE,
65     CSS_PROP_BORDER_SPACING,
66     CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING,
67     CSS_PROP__KHTML_BORDER_VERTICAL_SPACING,
68     CSS_PROP_BORDER_TOP_COLOR,
69     CSS_PROP_BORDER_RIGHT_COLOR,
70     CSS_PROP_BORDER_BOTTOM_COLOR,
71     CSS_PROP_BORDER_LEFT_COLOR,
72     CSS_PROP_BORDER_TOP_STYLE,
73     CSS_PROP_BORDER_RIGHT_STYLE,
74     CSS_PROP_BORDER_BOTTOM_STYLE,
75     CSS_PROP_BORDER_LEFT_STYLE,
76     CSS_PROP_BORDER_TOP_WIDTH,
77     CSS_PROP_BORDER_RIGHT_WIDTH,
78     CSS_PROP_BORDER_BOTTOM_WIDTH,
79     CSS_PROP_BORDER_LEFT_WIDTH,
80     CSS_PROP_BOTTOM,
81     CSS_PROP__KHTML_BOX_ALIGN,
82     CSS_PROP__KHTML_BOX_DIRECTION,
83     CSS_PROP__KHTML_BOX_FLEX,
84     CSS_PROP__KHTML_BOX_FLEX_GROUP,
85     CSS_PROP__KHTML_BOX_LINES,
86     CSS_PROP__KHTML_BOX_ORDINAL_GROUP,
87     CSS_PROP__KHTML_BOX_ORIENT,
88     CSS_PROP__KHTML_BOX_PACK,
89     CSS_PROP_CAPTION_SIDE,
90     CSS_PROP_CLEAR,
91     CSS_PROP_COLOR,
92     CSS_PROP_CURSOR,
93     CSS_PROP__APPLE_DASHBOARD_REGION,
94     CSS_PROP_DIRECTION,
95     CSS_PROP_DISPLAY,
96     CSS_PROP_EMPTY_CELLS,
97     CSS_PROP_FLOAT,
98     CSS_PROP_FONT_FAMILY,
99     CSS_PROP_FONT_SIZE,
100     CSS_PROP_FONT_STYLE,
101     CSS_PROP_FONT_VARIANT,
102     CSS_PROP_FONT_WEIGHT,
103     CSS_PROP_HEIGHT,
104     CSS_PROP_LEFT,
105     CSS_PROP_LETTER_SPACING,
106     CSS_PROP__KHTML_LINE_BREAK,
107     CSS_PROP_LINE_HEIGHT,
108     CSS_PROP_LIST_STYLE_IMAGE,
109     CSS_PROP_LIST_STYLE_POSITION,
110     CSS_PROP_LIST_STYLE_TYPE,
111     CSS_PROP_MARGIN_TOP,
112     CSS_PROP_MARGIN_RIGHT,
113     CSS_PROP_MARGIN_BOTTOM,
114     CSS_PROP_MARGIN_LEFT,
115     CSS_PROP__KHTML_MARQUEE_DIRECTION,
116     CSS_PROP__KHTML_MARQUEE_INCREMENT,
117     CSS_PROP__KHTML_MARQUEE_REPETITION,
118     CSS_PROP__KHTML_MARQUEE_STYLE,
119     CSS_PROP_MAX_HEIGHT,
120     CSS_PROP_MAX_WIDTH,
121     CSS_PROP_MIN_HEIGHT,
122     CSS_PROP_MIN_WIDTH,
123     CSS_PROP__KHTML_NBSP_MODE,
124     CSS_PROP_OPACITY,
125     CSS_PROP_ORPHANS,
126     CSS_PROP_OUTLINE_STYLE,
127     CSS_PROP_OVERFLOW,
128     CSS_PROP_PADDING_TOP,
129     CSS_PROP_PADDING_RIGHT,
130     CSS_PROP_PADDING_BOTTOM,
131     CSS_PROP_PADDING_LEFT,
132     CSS_PROP_PAGE_BREAK_AFTER,
133     CSS_PROP_PAGE_BREAK_BEFORE,
134     CSS_PROP_PAGE_BREAK_INSIDE,
135     CSS_PROP_POSITION,
136     CSS_PROP_RIGHT,
137     CSS_PROP_TABLE_LAYOUT,
138     CSS_PROP_TEXT_ALIGN,
139     CSS_PROP_TEXT_DECORATION,
140     CSS_PROP_TEXT_INDENT,
141     CSS_PROP_TEXT_SHADOW,
142     CSS_PROP_TEXT_TRANSFORM,
143     CSS_PROP_TOP,
144     CSS_PROP_UNICODE_BIDI,
145     CSS_PROP__KHTML_USER_MODIFY,
146     CSS_PROP_VERTICAL_ALIGN,
147     CSS_PROP_VISIBILITY,
148     CSS_PROP_WHITE_SPACE,
149     CSS_PROP_WIDOWS,
150     CSS_PROP_WIDTH,
151     CSS_PROP_WORD_SPACING,
152     CSS_PROP_WORD_WRAP,
153     CSS_PROP_Z_INDEX,
154 };
155
156 const unsigned numComputedProperties = sizeof(computedProperties) / sizeof(computedProperties[0]);
157
158 // This is the list of properties we want to copy in the copyInheritableProperties() function.
159 // It is the intersection of the list of inherited CSS properties and the
160 // properties for which we have a computed implementation in this file.
161 static const int inheritableProperties[] = {
162     CSS_PROP_BORDER_COLLAPSE,
163     CSS_PROP_BORDER_SPACING,
164     CSS_PROP_COLOR,
165     CSS_PROP_FONT_FAMILY,
166     CSS_PROP_FONT_SIZE,
167     CSS_PROP_FONT_STYLE,
168     CSS_PROP_FONT_VARIANT,
169     CSS_PROP_FONT_WEIGHT,
170     CSS_PROP_LETTER_SPACING,
171     CSS_PROP_LINE_HEIGHT,
172     CSS_PROP_TEXT_ALIGN,
173     CSS_PROP_TEXT_DECORATION, // this is not inheritable, yet we do want to consider it for typing style (name change needed? redesign?)
174     CSS_PROP_TEXT_INDENT,
175     CSS_PROP_TEXT_TRANSFORM,
176     CSS_PROP_ORPHANS,
177     CSS_PROP_WHITE_SPACE,
178     CSS_PROP_WIDOWS,
179     CSS_PROP_WORD_SPACING,
180 };
181
182 const unsigned numInheritableProperties = sizeof(inheritableProperties) / sizeof(inheritableProperties[0]);
183
184 static CSSValueImpl* valueForLength(const Length &length)
185 {
186     switch (length.type) {
187         case khtml::Percent:
188             return new CSSPrimitiveValueImpl(length.length(), CSSPrimitiveValue::CSS_PERCENTAGE);
189         case khtml::Fixed:
190             return new CSSPrimitiveValueImpl(length.length(), CSSPrimitiveValue::CSS_PX);
191         default: // FIXME: Intrinsic and MinIntrinsic should probably return keywords.
192             return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
193     }
194 }
195
196 static CSSValueImpl *valueForBorderStyle(EBorderStyle style)
197 {
198     switch (style) {
199         case khtml::BNONE:
200             return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
201         case khtml::BHIDDEN:
202             return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
203         case khtml::INSET:
204             return new CSSPrimitiveValueImpl(CSS_VAL_INSET);
205         case khtml::GROOVE:
206             return new CSSPrimitiveValueImpl(CSS_VAL_GROOVE);
207         case khtml::RIDGE:
208             return new CSSPrimitiveValueImpl(CSS_VAL_RIDGE);
209         case khtml::OUTSET:
210             return new CSSPrimitiveValueImpl(CSS_VAL_OUTSET);
211         case khtml::DOTTED:
212             return new CSSPrimitiveValueImpl(CSS_VAL_DOTTED);
213         case khtml::DASHED:
214             return new CSSPrimitiveValueImpl(CSS_VAL_DASHED);
215         case khtml::SOLID:
216             return new CSSPrimitiveValueImpl(CSS_VAL_SOLID);
217         case khtml::DOUBLE:
218             return new CSSPrimitiveValueImpl(CSS_VAL_DOUBLE);
219     }
220     ASSERT_NOT_REACHED();
221     return 0;
222 }
223
224 static CSSValueImpl *valueForTextAlign(ETextAlign align)
225 {
226     switch (align) {
227         case khtml::TAAUTO:
228             return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
229         case khtml::LEFT:
230             return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
231         case khtml::RIGHT:
232             return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
233         case khtml::CENTER:
234             return new CSSPrimitiveValueImpl(CSS_VAL_CENTER);
235         case khtml::JUSTIFY:
236             return new CSSPrimitiveValueImpl(CSS_VAL_JUSTIFY);
237         case khtml::KHTML_LEFT:
238             return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_LEFT);
239         case khtml::KHTML_RIGHT:
240             return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_RIGHT);
241         case khtml::KHTML_CENTER:
242             return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_CENTER);
243     }
244     ASSERT_NOT_REACHED();
245     return 0;
246 }
247
248 static CSSValueImpl* valueForShadow(const ShadowData *shadow)
249 {
250     if (!shadow)
251         return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
252     CSSValueListImpl *list = new CSSValueListImpl;
253     for (const ShadowData *s = shadow; s; s = s->next) {
254         CSSPrimitiveValueImpl *x = new CSSPrimitiveValueImpl(s->x, CSSPrimitiveValue::CSS_PX);
255         CSSPrimitiveValueImpl *y = new CSSPrimitiveValueImpl(s->y, CSSPrimitiveValue::CSS_PX);
256         CSSPrimitiveValueImpl *blur = new CSSPrimitiveValueImpl(s->blur, CSSPrimitiveValue::CSS_PX);
257         CSSPrimitiveValueImpl *color = new CSSPrimitiveValueImpl(s->color.rgb());
258         list->append(new ShadowValueImpl(x, y, blur, color));
259     }
260     return list;
261 }
262
263 static CSSValueImpl *getPositionOffsetValue(RenderObject *renderer, int propertyID)
264 {
265     if (!renderer)
266         return 0;
267
268     RenderStyle *style = renderer->style();
269     if (!style)
270         return 0;
271
272     Length l;
273     switch (propertyID) {
274     case CSS_PROP_LEFT:
275         l = style->left();
276         break;
277     case CSS_PROP_RIGHT:
278         l = style->right();
279         break;
280     case CSS_PROP_TOP:
281         l = style->top();
282         break;
283     case CSS_PROP_BOTTOM:
284         l = style->bottom();
285         break;
286     default:
287         return 0;
288     }
289
290     if (renderer->isPositioned())
291         return valueForLength(l);
292     
293     if (renderer->isRelPositioned())
294         // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined.
295         // In other words if left is auto and right is not auto, then left's computed value is negative right.
296         // So we should get the opposite length unit and see if it is auto.
297         return valueForLength(l);
298     
299     return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
300 }
301
302 CSSComputedStyleDeclarationImpl::CSSComputedStyleDeclarationImpl(NodeImpl *n)
303     : m_node(n)
304 {
305 }
306
307 CSSComputedStyleDeclarationImpl::~CSSComputedStyleDeclarationImpl()
308 {
309 }
310
311 DOMString CSSComputedStyleDeclarationImpl::cssText() const
312 {
313     ERROR("unimplemented");
314     return DOMString();
315 }
316
317 void CSSComputedStyleDeclarationImpl::setCssText(const DOMString &, int &exceptionCode)
318 {
319     exceptionCode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
320 }
321
322 // Display integers in integer format instead of "1.0".
323 static QString numberAsString(double n)
324 {
325     long i = static_cast<long>(n);
326     return i == n ? QString::number(i) : QString::number(n);
327 }
328
329 CSSValueImpl *CSSComputedStyleDeclarationImpl::getPropertyCSSValue(int propertyID) const
330 {
331     return getPropertyCSSValue(propertyID, UpdateLayout);
332 }
333
334 CSSValueImpl *CSSComputedStyleDeclarationImpl::getPropertyCSSValue(int propertyID, EUpdateLayout updateLayout) const
335 {
336     NodeImpl *node = m_node.handle();
337     if (!node)
338         return 0;
339
340     // Make sure our layout is up to date before we allow a query on these attributes.
341     DocumentImpl* docimpl = node->getDocument();
342     if (docimpl && updateLayout)
343         docimpl->updateLayout();
344
345     RenderObject *renderer = node->renderer();
346     if (!renderer)
347         return 0;
348     RenderStyle *style = renderer->style();
349     if (!style)
350         return 0;
351
352     switch (propertyID)
353     {
354     case CSS_PROP_BACKGROUND_COLOR:
355         return new CSSPrimitiveValueImpl(style->backgroundColor().rgb());
356     case CSS_PROP_BACKGROUND_IMAGE:
357         if (style->backgroundImage())
358             return new CSSPrimitiveValueImpl(style->backgroundImage()->url(), CSSPrimitiveValue::CSS_URI);
359         return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
360     case CSS_PROP_BACKGROUND_REPEAT:
361         switch (style->backgroundRepeat()) {
362             case khtml::REPEAT:
363                 return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT);
364             case khtml::REPEAT_X:
365                 return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT_X);
366             case khtml::REPEAT_Y:
367                 return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT_Y);
368             case khtml::NO_REPEAT:
369                 return new CSSPrimitiveValueImpl(CSS_VAL_NO_REPEAT);
370         }
371         ASSERT_NOT_REACHED();
372         return 0;
373     case CSS_PROP_BACKGROUND_ATTACHMENT:
374         if (style->backgroundAttachment())
375             return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
376         else
377             return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
378     case CSS_PROP_BACKGROUND_POSITION:
379     {
380         DOMString string;
381         Length length(style->backgroundXPosition());
382         if (length.isPercent())
383             string = numberAsString(length.length()) + "%";
384         else
385             string = numberAsString(length.minWidth(renderer->contentWidth()));
386         string += " ";
387         length = style->backgroundYPosition();
388         if (length.isPercent())
389             string += numberAsString(length.length()) + "%";
390         else
391             string += numberAsString(length.minWidth(renderer->contentWidth()));
392         return new CSSPrimitiveValueImpl(string, CSSPrimitiveValue::CSS_STRING);
393     }
394     case CSS_PROP_BACKGROUND_POSITION_X:
395         return valueForLength(style->backgroundXPosition());
396     case CSS_PROP_BACKGROUND_POSITION_Y:
397         return valueForLength(style->backgroundYPosition());
398 #ifndef KHTML_NO_XBL
399     case CSS_PROP__KHTML_BINDING:
400         // FIXME: unimplemented
401         break;
402 #endif
403     case CSS_PROP_BORDER_COLLAPSE:
404         if (style->borderCollapse())
405             return new CSSPrimitiveValueImpl(CSS_VAL_COLLAPSE);
406         else
407             return new CSSPrimitiveValueImpl(CSS_VAL_SEPARATE);
408     case CSS_PROP_BORDER_SPACING:
409     {
410         QString string(numberAsString(style->horizontalBorderSpacing()) + 
411             "px " + 
412             numberAsString(style->verticalBorderSpacing()) +
413             "px");
414         return new CSSPrimitiveValueImpl(string, CSSPrimitiveValue::CSS_STRING);
415     }
416     case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING:
417         return new CSSPrimitiveValueImpl(style->horizontalBorderSpacing(), CSSPrimitiveValue::CSS_PX);
418     case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING:
419         return new CSSPrimitiveValueImpl(style->verticalBorderSpacing(), CSSPrimitiveValue::CSS_PX);
420     case CSS_PROP_BORDER_TOP_COLOR:
421         return new CSSPrimitiveValueImpl(style->borderLeftColor().rgb());
422     case CSS_PROP_BORDER_RIGHT_COLOR:
423         return new CSSPrimitiveValueImpl(style->borderRightColor().rgb());
424     case CSS_PROP_BORDER_BOTTOM_COLOR:
425         return new CSSPrimitiveValueImpl(style->borderBottomColor().rgb());
426     case CSS_PROP_BORDER_LEFT_COLOR:
427         return new CSSPrimitiveValueImpl(style->borderLeftColor().rgb());
428     case CSS_PROP_BORDER_TOP_STYLE:
429         return valueForBorderStyle(style->borderTopStyle());
430     case CSS_PROP_BORDER_RIGHT_STYLE:
431         return valueForBorderStyle(style->borderRightStyle());
432     case CSS_PROP_BORDER_BOTTOM_STYLE:
433         return valueForBorderStyle(style->borderBottomStyle());
434     case CSS_PROP_BORDER_LEFT_STYLE:
435         return valueForBorderStyle(style->borderLeftStyle());
436     case CSS_PROP_BORDER_TOP_WIDTH:
437         return new CSSPrimitiveValueImpl(style->borderTopWidth(), CSSPrimitiveValue::CSS_PX);
438     case CSS_PROP_BORDER_RIGHT_WIDTH:
439         return new CSSPrimitiveValueImpl(style->borderRightWidth(), CSSPrimitiveValue::CSS_PX);
440     case CSS_PROP_BORDER_BOTTOM_WIDTH:
441         return new CSSPrimitiveValueImpl(style->borderBottomWidth(), CSSPrimitiveValue::CSS_PX);
442     case CSS_PROP_BORDER_LEFT_WIDTH:
443         return new CSSPrimitiveValueImpl(style->borderLeftWidth(), CSSPrimitiveValue::CSS_PX);
444     case CSS_PROP_BOTTOM:
445         return getPositionOffsetValue(renderer, CSS_PROP_BOTTOM);
446     case CSS_PROP__KHTML_BOX_ALIGN:
447         switch (style->boxAlign()) {
448             case khtml::BSTRETCH:
449                 return new CSSPrimitiveValueImpl(CSS_VAL_STRETCH);
450             case khtml::BSTART:
451                 return new CSSPrimitiveValueImpl(CSS_VAL_START);
452             case khtml::BCENTER:
453                 return new CSSPrimitiveValueImpl(CSS_VAL_CENTER);
454             case khtml::BEND:
455                 return new CSSPrimitiveValueImpl(CSS_VAL_END);
456             case khtml::BBASELINE:
457                 return new CSSPrimitiveValueImpl(CSS_VAL_BASELINE);
458             case khtml::BJUSTIFY:
459                 break; // not allowed
460         }
461         ASSERT_NOT_REACHED();
462         return 0;
463     case CSS_PROP__KHTML_BOX_DIRECTION:
464         switch (style->boxDirection()) {
465             case khtml::BNORMAL:
466                 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
467             case khtml::BREVERSE:
468                 return new CSSPrimitiveValueImpl(CSS_VAL_REVERSE);
469         }
470         ASSERT_NOT_REACHED();
471         return 0;
472     case CSS_PROP__KHTML_BOX_FLEX:
473         return new CSSPrimitiveValueImpl(style->boxFlex(), CSSPrimitiveValue::CSS_NUMBER);
474     case CSS_PROP__KHTML_BOX_FLEX_GROUP:
475         return new CSSPrimitiveValueImpl(style->boxFlexGroup(), CSSPrimitiveValue::CSS_NUMBER);
476     case CSS_PROP__KHTML_BOX_LINES:
477         switch (style->boxLines()) {
478             case khtml::SINGLE:
479                 return new CSSPrimitiveValueImpl(CSS_VAL_SINGLE);
480             case khtml::MULTIPLE:
481                 return new CSSPrimitiveValueImpl(CSS_VAL_MULTIPLE);
482         }
483         ASSERT_NOT_REACHED();
484         return 0;
485     case CSS_PROP__KHTML_BOX_ORDINAL_GROUP:
486         return new CSSPrimitiveValueImpl(style->boxOrdinalGroup(), CSSPrimitiveValue::CSS_NUMBER);
487     case CSS_PROP__KHTML_BOX_ORIENT:
488         switch (style->boxOrient()) {
489             case khtml::HORIZONTAL:
490                 return new CSSPrimitiveValueImpl(CSS_VAL_HORIZONTAL);
491             case khtml::VERTICAL:
492                 return new CSSPrimitiveValueImpl(CSS_VAL_VERTICAL);
493         }
494         ASSERT_NOT_REACHED();
495         return 0;
496     case CSS_PROP__KHTML_BOX_PACK:
497         switch (style->boxPack()) {
498             case khtml::BSTART:
499                 return new CSSPrimitiveValueImpl(CSS_VAL_START);
500             case khtml::BEND:
501                 return new CSSPrimitiveValueImpl(CSS_VAL_END);
502             case khtml::BCENTER:
503                 return new CSSPrimitiveValueImpl(CSS_VAL_CENTER);
504             case khtml::BJUSTIFY:
505                 return new CSSPrimitiveValueImpl(CSS_VAL_JUSTIFY);
506             case khtml::BSTRETCH:
507             case khtml::BBASELINE:
508                 break; // not allowed
509         }
510         ASSERT_NOT_REACHED();
511         return 0;
512     case CSS_PROP_CAPTION_SIDE:
513         switch (style->captionSide()) {
514             case khtml::CAPLEFT:
515                 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
516             case khtml::CAPRIGHT:
517                 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
518             case khtml::CAPTOP:
519                 return new CSSPrimitiveValueImpl(CSS_VAL_TOP);
520             case khtml::CAPBOTTOM:
521                 return new CSSPrimitiveValueImpl(CSS_VAL_BOTTOM);
522         }
523         ASSERT_NOT_REACHED();
524         return 0;
525     case CSS_PROP_CLEAR:
526         switch (style->clear()) {
527             case khtml::CNONE:
528                 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
529             case khtml::CLEFT:
530                 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
531             case khtml::CRIGHT:
532                 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
533             case khtml::CBOTH:
534                 return new CSSPrimitiveValueImpl(CSS_VAL_BOTH);
535         }
536         ASSERT_NOT_REACHED();
537         return 0;
538     case CSS_PROP_CLIP:
539         // FIXME: unimplemented
540         break;
541     case CSS_PROP_COLOR:
542         return new CSSPrimitiveValueImpl(style->color().rgb());
543     case CSS_PROP_CONTENT:
544         // FIXME: unimplemented
545         break;
546     case CSS_PROP_COUNTER_INCREMENT:
547         // FIXME: unimplemented
548         break;
549     case CSS_PROP_COUNTER_RESET:
550         // FIXME: unimplemented
551         break;
552     case CSS_PROP_CURSOR:
553         switch (style->cursor()) {
554             case khtml::CURSOR_AUTO:
555                 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
556             case khtml::CURSOR_CROSS:
557                 return new CSSPrimitiveValueImpl(CSS_VAL_CROSSHAIR);
558             case khtml::CURSOR_DEFAULT:
559                 return new CSSPrimitiveValueImpl(CSS_VAL_DEFAULT);
560             case khtml::CURSOR_POINTER:
561                 return new CSSPrimitiveValueImpl(CSS_VAL_POINTER);
562             case khtml::CURSOR_MOVE:
563                 return new CSSPrimitiveValueImpl(CSS_VAL_MOVE);
564             case khtml::CURSOR_E_RESIZE:
565                 return new CSSPrimitiveValueImpl(CSS_VAL_E_RESIZE);
566             case khtml::CURSOR_NE_RESIZE:
567                 return new CSSPrimitiveValueImpl(CSS_VAL_NE_RESIZE);
568             case khtml::CURSOR_NW_RESIZE:
569                 return new CSSPrimitiveValueImpl(CSS_VAL_NW_RESIZE);
570             case khtml::CURSOR_N_RESIZE:
571                 return new CSSPrimitiveValueImpl(CSS_VAL_N_RESIZE);
572             case khtml::CURSOR_SE_RESIZE:
573                 return new CSSPrimitiveValueImpl(CSS_VAL_SE_RESIZE);
574             case khtml::CURSOR_SW_RESIZE:
575                 return new CSSPrimitiveValueImpl(CSS_VAL_SW_RESIZE);
576             case khtml::CURSOR_S_RESIZE:
577                 return new CSSPrimitiveValueImpl(CSS_VAL_S_RESIZE);
578             case khtml::CURSOR_W_RESIZE:
579                 return new CSSPrimitiveValueImpl(CSS_VAL_W_RESIZE);
580             case khtml::CURSOR_TEXT:
581                 return new CSSPrimitiveValueImpl(CSS_VAL_TEXT);
582             case khtml::CURSOR_WAIT:
583                 return new CSSPrimitiveValueImpl(CSS_VAL_WAIT);
584             case khtml::CURSOR_HELP:
585                 return new CSSPrimitiveValueImpl(CSS_VAL_HELP);
586         }
587         ASSERT_NOT_REACHED();
588         return 0;
589     case CSS_PROP_DIRECTION:
590         switch (style->direction()) {
591             case khtml::LTR:
592                 return new CSSPrimitiveValueImpl(CSS_VAL_LTR);
593             case khtml::RTL:
594                 return new CSSPrimitiveValueImpl(CSS_VAL_RTL);
595         }
596         ASSERT_NOT_REACHED();
597         return 0;
598     case CSS_PROP_DISPLAY:
599         switch (style->display()) {
600             case khtml::INLINE:
601                 return new CSSPrimitiveValueImpl(CSS_VAL_INLINE);
602             case khtml::BLOCK:
603                 return new CSSPrimitiveValueImpl(CSS_VAL_BLOCK);
604             case khtml::LIST_ITEM:
605                 return new CSSPrimitiveValueImpl(CSS_VAL_LIST_ITEM);
606             case khtml::RUN_IN:
607                 return new CSSPrimitiveValueImpl(CSS_VAL_RUN_IN);
608             case khtml::COMPACT:
609                 return new CSSPrimitiveValueImpl(CSS_VAL_COMPACT);
610             case khtml::INLINE_BLOCK:
611                 return new CSSPrimitiveValueImpl(CSS_VAL_INLINE_BLOCK);
612             case khtml::TABLE:
613                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE);
614             case khtml::INLINE_TABLE:
615                 return new CSSPrimitiveValueImpl(CSS_VAL_INLINE_TABLE);
616             case khtml::TABLE_ROW_GROUP:
617                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_ROW_GROUP);
618             case khtml::TABLE_HEADER_GROUP:
619                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_HEADER_GROUP);
620             case khtml::TABLE_FOOTER_GROUP:
621                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_FOOTER_GROUP);
622             case khtml::TABLE_ROW:
623                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_ROW);
624             case khtml::TABLE_COLUMN_GROUP:
625                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_COLUMN_GROUP);
626             case khtml::TABLE_COLUMN:
627                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_COLUMN);
628             case khtml::TABLE_CELL:
629                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_CELL);
630             case khtml::TABLE_CAPTION:
631                 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_CAPTION);
632             case khtml::BOX:
633                 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_BOX);
634             case khtml::INLINE_BOX:
635                 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_INLINE_BOX);
636             case khtml::NONE:
637                 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
638         }
639         ASSERT_NOT_REACHED();
640         return 0;
641     case CSS_PROP_EMPTY_CELLS:
642         switch (style->emptyCells()) {
643             case khtml::SHOW:
644                 return new CSSPrimitiveValueImpl(CSS_VAL_SHOW);
645             case khtml::HIDE:
646                 return new CSSPrimitiveValueImpl(CSS_VAL_HIDE);
647         }
648         ASSERT_NOT_REACHED();
649         return 0;
650     case CSS_PROP_FLOAT:
651         switch (style->floating()) {
652             case khtml::FNONE:
653                 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
654             case khtml::FLEFT:
655                 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
656             case khtml::FRIGHT:
657                 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
658         }
659         ASSERT_NOT_REACHED();
660         return 0;
661     case CSS_PROP_FONT_FAMILY:
662     {
663         FontDef def = style->htmlFont().getFontDef();
664         return new CSSPrimitiveValueImpl(def.firstFamily().family().domString(), CSSPrimitiveValue::CSS_STRING);
665     }
666     case CSS_PROP_FONT_SIZE:
667     {
668         FontDef def = style->htmlFont().getFontDef();
669         return new CSSPrimitiveValueImpl(def.specifiedSize, CSSPrimitiveValue::CSS_PX);
670     }
671     case CSS_PROP_FONT_STRETCH:
672         // FIXME: unimplemented
673         break;
674     case CSS_PROP_FONT_STYLE:
675     {
676         // FIXME: handle oblique?
677         FontDef def = style->htmlFont().getFontDef();
678         if (def.italic)
679             return new CSSPrimitiveValueImpl(CSS_VAL_ITALIC);
680         else
681             return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
682     }
683     case CSS_PROP_FONT_VARIANT:
684     {
685         FontDef def = style->htmlFont().getFontDef();
686         if (def.smallCaps)
687             return new CSSPrimitiveValueImpl(CSS_VAL_SMALL_CAPS);
688         else
689             return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
690     }
691     case CSS_PROP_FONT_WEIGHT:
692     {
693         // FIXME: this does not reflect the full range of weights
694         // that can be expressed with CSS
695         FontDef def = style->htmlFont().getFontDef();
696         if (def.weight == QFont::Bold)
697             return new CSSPrimitiveValueImpl(CSS_VAL_BOLD);
698         else
699             return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
700     }
701     case CSS_PROP_HEIGHT:
702         return new CSSPrimitiveValueImpl(renderer->contentHeight(), CSSPrimitiveValue::CSS_PX);
703     case CSS_PROP_LEFT:
704         return getPositionOffsetValue(renderer, CSS_PROP_LEFT);
705     case CSS_PROP_LETTER_SPACING:
706         if (style->letterSpacing() == 0)
707             return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
708         return new CSSPrimitiveValueImpl(style->letterSpacing(), CSSPrimitiveValue::CSS_PX);
709     case CSS_PROP_LINE_HEIGHT: {
710         Length length(style->lineHeight());
711         if (length.value < 0)
712             return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
713         if (length.isPercent()) {
714             float computedSize = style->htmlFont().getFontDef().computedSize;
715             return new CSSPrimitiveValueImpl((int)(length.length() * computedSize) / 100, CSSPrimitiveValue::CSS_PX);
716         }
717         else {
718             return new CSSPrimitiveValueImpl(length.length(), CSSPrimitiveValue::CSS_PX);
719         }
720     }
721     case CSS_PROP_LIST_STYLE_IMAGE:
722         if (style->listStyleImage())
723             return new CSSPrimitiveValueImpl(style->listStyleImage()->url(), CSSPrimitiveValue::CSS_URI);
724         return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
725     case CSS_PROP_LIST_STYLE_POSITION:
726         switch (style->listStylePosition()) {
727             case khtml::OUTSIDE:
728                 return new CSSPrimitiveValueImpl(CSS_VAL_OUTSIDE);
729             case khtml::INSIDE:
730                 return new CSSPrimitiveValueImpl(CSS_VAL_INSIDE);
731         }
732         ASSERT_NOT_REACHED();
733         return 0;
734     case CSS_PROP_LIST_STYLE_TYPE:
735         switch (style->listStyleType()) {
736             case khtml::LNONE:
737                 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
738             case khtml::DISC:
739                 return new CSSPrimitiveValueImpl(CSS_VAL_DISC);
740             case khtml::CIRCLE:
741                 return new CSSPrimitiveValueImpl(CSS_VAL_CIRCLE);
742             case khtml::SQUARE:
743                 return new CSSPrimitiveValueImpl(CSS_VAL_SQUARE);
744             case khtml::LDECIMAL:
745                 return new CSSPrimitiveValueImpl(CSS_VAL_DECIMAL);
746             case khtml::DECIMAL_LEADING_ZERO:
747                 return new CSSPrimitiveValueImpl(CSS_VAL_DECIMAL_LEADING_ZERO);
748             case khtml::LOWER_ROMAN:
749                 return new CSSPrimitiveValueImpl(CSS_VAL_LOWER_ROMAN);
750             case khtml::UPPER_ROMAN:
751                 return new CSSPrimitiveValueImpl(CSS_VAL_UPPER_ROMAN);
752             case khtml::LOWER_GREEK:
753                 return new CSSPrimitiveValueImpl(CSS_VAL_LOWER_GREEK);
754             case khtml::LOWER_ALPHA:
755                 return new CSSPrimitiveValueImpl(CSS_VAL_LOWER_ALPHA);
756             case khtml::LOWER_LATIN:
757                 return new CSSPrimitiveValueImpl(CSS_VAL_LOWER_LATIN);
758             case khtml::UPPER_ALPHA:
759                 return new CSSPrimitiveValueImpl(CSS_VAL_UPPER_ALPHA);
760             case khtml::UPPER_LATIN:
761                 return new CSSPrimitiveValueImpl(CSS_VAL_UPPER_LATIN);
762             case khtml::HEBREW:
763                 return new CSSPrimitiveValueImpl(CSS_VAL_HEBREW);
764             case khtml::ARMENIAN:
765                 return new CSSPrimitiveValueImpl(CSS_VAL_ARMENIAN);
766             case khtml::GEORGIAN:
767                 return new CSSPrimitiveValueImpl(CSS_VAL_GEORGIAN);
768             case khtml::CJK_IDEOGRAPHIC:
769                 return new CSSPrimitiveValueImpl(CSS_VAL_CJK_IDEOGRAPHIC);
770             case khtml::HIRAGANA:
771                 return new CSSPrimitiveValueImpl(CSS_VAL_HIRAGANA);
772             case khtml::KATAKANA:
773                 return new CSSPrimitiveValueImpl(CSS_VAL_KATAKANA);
774             case khtml::HIRAGANA_IROHA:
775                 return new CSSPrimitiveValueImpl(CSS_VAL_HIRAGANA_IROHA);
776             case khtml::KATAKANA_IROHA:
777                 return new CSSPrimitiveValueImpl(CSS_VAL_KATAKANA_IROHA);
778         }
779         ASSERT_NOT_REACHED();
780         return 0;
781     case CSS_PROP_MARGIN_TOP:
782         return valueForLength(style->marginTop());
783     case CSS_PROP_MARGIN_RIGHT:
784         return valueForLength(style->marginRight());
785     case CSS_PROP_MARGIN_BOTTOM:
786         return valueForLength(style->marginBottom());
787     case CSS_PROP_MARGIN_LEFT:
788         return valueForLength(style->marginLeft());
789     case CSS_PROP__KHTML_MARQUEE:
790         // FIXME: unimplemented
791         break;
792     case CSS_PROP__KHTML_MARQUEE_DIRECTION:
793         switch (style->marqueeDirection()) {
794             case khtml::MFORWARD:
795                 return new CSSPrimitiveValueImpl(CSS_VAL_FORWARDS);
796             case khtml::MBACKWARD:
797                 return new CSSPrimitiveValueImpl(CSS_VAL_BACKWARDS);
798             case khtml::MAUTO:
799                 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
800             case khtml::MUP:
801                 return new CSSPrimitiveValueImpl(CSS_VAL_UP);
802             case khtml::MDOWN:
803                 return new CSSPrimitiveValueImpl(CSS_VAL_DOWN);
804             case khtml::MLEFT:
805                 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
806             case khtml::MRIGHT:
807                 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
808         }
809         ASSERT_NOT_REACHED();
810         return 0;
811     case CSS_PROP__KHTML_MARQUEE_INCREMENT:
812         return valueForLength(style->marqueeIncrement());
813     case CSS_PROP__KHTML_MARQUEE_REPETITION:
814         if (style->marqueeLoopCount() < 0)
815             return new CSSPrimitiveValueImpl(CSS_VAL_INFINITE);
816         return new CSSPrimitiveValueImpl(style->marqueeLoopCount(), CSSPrimitiveValue::CSS_NUMBER);
817     case CSS_PROP__KHTML_MARQUEE_SPEED:
818         // FIXME: unimplemented
819         break;
820     case CSS_PROP__KHTML_MARQUEE_STYLE:
821         switch (style->marqueeBehavior()) {
822             case khtml::MNONE:
823                 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
824             case khtml::MSCROLL:
825                 return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
826             case khtml::MSLIDE:
827                 return new CSSPrimitiveValueImpl(CSS_VAL_SLIDE);
828             case khtml::MALTERNATE:
829                 return new CSSPrimitiveValueImpl(CSS_VAL_ALTERNATE);
830             case khtml::MUNFURL:
831                 return new CSSPrimitiveValueImpl(CSS_VAL_UNFURL);
832         }
833         ASSERT_NOT_REACHED();
834         return 0;
835     case CSS_PROP__KHTML_USER_MODIFY:
836         switch (style->userModify()) {
837             case khtml::READ_ONLY:
838                 return new CSSPrimitiveValueImpl(CSS_VAL_READ_ONLY);
839             case khtml::READ_WRITE:
840                 return new CSSPrimitiveValueImpl(CSS_VAL_READ_WRITE);
841         }
842         ASSERT_NOT_REACHED();
843         return 0;
844     case CSS_PROP_MAX_HEIGHT:
845         return valueForLength(style->maxHeight());
846     case CSS_PROP_MAX_WIDTH:
847         return valueForLength(style->maxWidth());
848     case CSS_PROP_MIN_HEIGHT:
849         return valueForLength(style->minHeight());
850     case CSS_PROP_MIN_WIDTH:
851         return valueForLength(style->minWidth());
852     case CSS_PROP_OPACITY:
853         return new CSSPrimitiveValueImpl(style->opacity(), CSSPrimitiveValue::CSS_NUMBER);
854     case CSS_PROP_ORPHANS:
855         return new CSSPrimitiveValueImpl(style->orphans(), CSSPrimitiveValue::CSS_NUMBER);
856     case CSS_PROP_OUTLINE_COLOR:
857         // FIXME: unimplemented
858         break;
859     case CSS_PROP_OUTLINE_OFFSET:
860         // FIXME: unimplemented
861         break;
862     case CSS_PROP_OUTLINE_STYLE:
863         if (style->outlineStyleIsAuto())
864             return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
865         return valueForBorderStyle(style->outlineStyle());
866     case CSS_PROP_OUTLINE_WIDTH:
867         // FIXME: unimplemented
868         break;
869     case CSS_PROP_OVERFLOW:
870         switch (style->overflow()) {
871             case khtml::OVISIBLE:
872                 return new CSSPrimitiveValueImpl(CSS_VAL_VISIBLE);
873             case khtml::OHIDDEN:
874                 return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
875             case khtml::OSCROLL:
876                 return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
877             case khtml::OAUTO:
878                 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
879             case khtml::OMARQUEE:
880                 return new CSSPrimitiveValueImpl(CSS_VAL_MARQUEE);
881             case khtml::OOVERLAY:
882                 return new CSSPrimitiveValueImpl(CSS_VAL_OVERLAY);
883         }
884         ASSERT_NOT_REACHED();
885         return 0;
886     case CSS_PROP_PADDING_TOP:
887         return valueForLength(style->paddingTop());
888     case CSS_PROP_PADDING_RIGHT:
889         return valueForLength(style->paddingRight());
890     case CSS_PROP_PADDING_BOTTOM:
891         return valueForLength(style->paddingBottom());
892     case CSS_PROP_PADDING_LEFT:
893         return valueForLength(style->paddingLeft());
894     case CSS_PROP_PAGE:
895         // FIXME: unimplemented
896         break;
897     case CSS_PROP_PAGE_BREAK_AFTER:
898         switch (style->pageBreakAfter()) {
899             case khtml::PBAUTO:
900                 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
901             case khtml::PBALWAYS:
902                 return new CSSPrimitiveValueImpl(CSS_VAL_ALWAYS);
903             case khtml::PBAVOID:
904                 return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
905         }
906         ASSERT_NOT_REACHED();
907         return 0;
908     case CSS_PROP_PAGE_BREAK_BEFORE:
909         switch (style->pageBreakBefore()) {
910             case khtml::PBAUTO:
911                 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
912             case khtml::PBALWAYS:
913                 return new CSSPrimitiveValueImpl(CSS_VAL_ALWAYS);
914             case khtml::PBAVOID:
915                 return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
916         }
917         ASSERT_NOT_REACHED();
918         return 0;
919     case CSS_PROP_PAGE_BREAK_INSIDE:
920         switch (style->pageBreakInside()) {
921             case khtml::PBAUTO:
922                 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
923             case khtml::PBAVOID:
924                 return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
925             case khtml::PBALWAYS:
926                 break; // not allowed
927         }
928         ASSERT_NOT_REACHED();
929         return 0;
930     case CSS_PROP_POSITION:
931         switch (style->position()) {
932             case khtml::STATIC:
933                 return new CSSPrimitiveValueImpl(CSS_VAL_STATIC);
934             case khtml::RELATIVE:
935                 return new CSSPrimitiveValueImpl(CSS_VAL_RELATIVE);
936             case khtml::ABSOLUTE:
937                 return new CSSPrimitiveValueImpl(CSS_VAL_ABSOLUTE);
938             case khtml::FIXED:
939                 return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
940         }
941         ASSERT_NOT_REACHED();
942         return 0;
943     case CSS_PROP_QUOTES:
944         // FIXME: unimplemented
945         break;
946     case CSS_PROP_RIGHT:
947         return getPositionOffsetValue(renderer, CSS_PROP_RIGHT);
948     case CSS_PROP_SIZE:
949         // FIXME: unimplemented
950         break;
951     case CSS_PROP_TABLE_LAYOUT:
952         switch (style->tableLayout()) {
953             case khtml::TAUTO:
954                 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
955             case khtml::TFIXED:
956                 return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
957         }
958         ASSERT_NOT_REACHED();
959         return 0;
960     case CSS_PROP_TEXT_ALIGN:
961         return valueForTextAlign(style->textAlign());
962     case CSS_PROP_TEXT_DECORATION:
963     {
964         QString string;
965         if (style->textDecoration() & khtml::UNDERLINE)
966             string += "underline";
967         if (style->textDecoration() & khtml::OVERLINE) {
968             if (string.length() > 0)
969                 string += " ";
970             string += "overline";
971         }
972         if (style->textDecoration() & khtml::LINE_THROUGH) {
973             if (string.length() > 0)
974                 string += " ";
975             string += "line-through";
976         }
977         if (style->textDecoration() & khtml::BLINK) {
978             if (string.length() > 0)
979                 string += " ";
980             string += "blink";
981         }
982         if (string.length() == 0)
983             return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
984         return new CSSPrimitiveValueImpl(string, CSSPrimitiveValue::CSS_STRING);
985     }
986     case CSS_PROP_TEXT_INDENT:
987         return valueForLength(style->textIndent());
988     case CSS_PROP_TEXT_SHADOW:
989         return valueForShadow(style->textShadow());
990     case CSS_PROP_TEXT_TRANSFORM:
991         switch (style->textTransform()) {
992             case khtml::CAPITALIZE:
993                 return new CSSPrimitiveValueImpl(CSS_VAL_CAPITALIZE);
994             case khtml::UPPERCASE:
995                 return new CSSPrimitiveValueImpl(CSS_VAL_UPPERCASE);
996             case khtml::LOWERCASE:
997                 return new CSSPrimitiveValueImpl(CSS_VAL_LOWERCASE);
998             case khtml::TTNONE:
999                 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
1000         }
1001         ASSERT_NOT_REACHED();
1002         return 0;
1003     case CSS_PROP_TOP:
1004         return getPositionOffsetValue(renderer, CSS_PROP_TOP);
1005     case CSS_PROP_UNICODE_BIDI:
1006         switch (style->unicodeBidi()) {
1007             case khtml::UBNormal:
1008                 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1009             case khtml::Embed:
1010                 return new CSSPrimitiveValueImpl(CSS_VAL_EMBED);
1011             case khtml::Override:
1012                 return new CSSPrimitiveValueImpl(CSS_VAL_BIDI_OVERRIDE);
1013         }
1014         ASSERT_NOT_REACHED();
1015         return 0;
1016     case CSS_PROP_VERTICAL_ALIGN:
1017         switch (style->verticalAlign()) {
1018             case khtml::BASELINE:
1019                 return new CSSPrimitiveValueImpl(CSS_VAL_BASELINE);
1020             case khtml::MIDDLE:
1021                 return new CSSPrimitiveValueImpl(CSS_VAL_MIDDLE);
1022             case khtml::SUB:
1023                 return new CSSPrimitiveValueImpl(CSS_VAL_SUB);
1024             case khtml::SUPER:
1025                 return new CSSPrimitiveValueImpl(CSS_VAL_SUPER);
1026             case khtml::TEXT_TOP:
1027                 return new CSSPrimitiveValueImpl(CSS_VAL_TEXT_TOP);
1028             case khtml::TEXT_BOTTOM:
1029                 return new CSSPrimitiveValueImpl(CSS_VAL_TEXT_BOTTOM);
1030             case khtml::TOP:
1031                 return new CSSPrimitiveValueImpl(CSS_VAL_TOP);
1032             case khtml::BOTTOM:
1033                 return new CSSPrimitiveValueImpl(CSS_VAL_BOTTOM);
1034             case khtml::BASELINE_MIDDLE:
1035                 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_BASELINE_MIDDLE);
1036             case khtml::LENGTH:
1037                 return valueForLength(style->verticalAlignLength());
1038         }
1039         ASSERT_NOT_REACHED();
1040         return 0;
1041     case CSS_PROP_VISIBILITY:
1042         switch (style->visibility()) {
1043             case khtml::VISIBLE:
1044                 return new CSSPrimitiveValueImpl(CSS_VAL_VISIBLE);
1045             case khtml::HIDDEN:
1046                 return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
1047             case khtml::COLLAPSE:
1048                 return new CSSPrimitiveValueImpl(CSS_VAL_COLLAPSE);
1049         }
1050         ASSERT_NOT_REACHED();
1051         return 0;
1052     case CSS_PROP_WHITE_SPACE:
1053         switch (style->whiteSpace()) {
1054             case khtml::NORMAL:
1055                 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1056             case khtml::PRE:
1057                 return new CSSPrimitiveValueImpl(CSS_VAL_PRE);
1058             case khtml::NOWRAP:
1059                 return new CSSPrimitiveValueImpl(CSS_VAL_NOWRAP);
1060             case khtml::KHTML_NOWRAP:
1061                 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_NOWRAP);
1062         }
1063         ASSERT_NOT_REACHED();
1064         return 0;
1065     case CSS_PROP_WIDOWS:
1066         return new CSSPrimitiveValueImpl(style->widows(), CSSPrimitiveValue::CSS_NUMBER);
1067     case CSS_PROP_WIDTH:
1068         return new CSSPrimitiveValueImpl(renderer->contentWidth(), CSSPrimitiveValue::CSS_PX);
1069     case CSS_PROP_WORD_SPACING:
1070         return new CSSPrimitiveValueImpl(style->wordSpacing(), CSSPrimitiveValue::CSS_PX);
1071     case CSS_PROP_WORD_WRAP:
1072         switch (style->wordWrap()) {
1073             case khtml::WBNORMAL:
1074                 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1075             case khtml::BREAK_WORD:
1076                 return new CSSPrimitiveValueImpl(CSS_VAL_BREAK_WORD);
1077         }
1078         ASSERT_NOT_REACHED();
1079         return 0;
1080     case CSS_PROP__KHTML_LINE_BREAK:
1081         switch (style->khtmlLineBreak()) {
1082             case khtml::LBNORMAL:
1083                 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1084             case khtml::AFTER_WHITE_SPACE:
1085                 return new CSSPrimitiveValueImpl(CSS_VAL_AFTER_WHITE_SPACE);
1086         }
1087         ASSERT_NOT_REACHED();
1088         return 0;
1089     case CSS_PROP__KHTML_NBSP_MODE:
1090         switch (style->nbspMode()) {
1091             case khtml::NBNORMAL:
1092                 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1093             case khtml::SPACE:
1094                 return new CSSPrimitiveValueImpl(CSS_VAL_SPACE);
1095         }
1096         ASSERT_NOT_REACHED();
1097         return 0;
1098     case CSS_PROP_Z_INDEX:
1099         if (style->hasAutoZIndex())
1100             return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1101         return new CSSPrimitiveValueImpl(style->zIndex(), CSSPrimitiveValue::CSS_NUMBER);
1102     case CSS_PROP_BACKGROUND:
1103         // FIXME: unimplemented
1104         break;
1105     case CSS_PROP_BORDER:
1106         // FIXME: unimplemented
1107         break;
1108     case CSS_PROP_BORDER_COLOR:
1109         // FIXME: unimplemented
1110         break;
1111     case CSS_PROP_BORDER_STYLE:
1112         // FIXME: unimplemented
1113         break;
1114     case CSS_PROP_BORDER_TOP:
1115         // FIXME: unimplemented
1116         break;
1117     case CSS_PROP_BORDER_RIGHT:
1118         // FIXME: unimplemented
1119         break;
1120     case CSS_PROP_BORDER_BOTTOM:
1121         // FIXME: unimplemented
1122         break;
1123     case CSS_PROP_BORDER_LEFT:
1124         // FIXME: unimplemented
1125         break;
1126     case CSS_PROP_BORDER_WIDTH:
1127         // FIXME: unimplemented
1128         break;
1129     case CSS_PROP_FONT:
1130         // FIXME: unimplemented
1131         break;
1132     case CSS_PROP_LIST_STYLE:
1133         // FIXME: unimplemented
1134         break;
1135     case CSS_PROP_MARGIN:
1136         // FIXME: unimplemented
1137         break;
1138     case CSS_PROP_OUTLINE:
1139         // FIXME: unimplemented
1140         break;
1141     case CSS_PROP_PADDING:
1142         // FIXME: unimplemented
1143         break;
1144 #if !APPLE_CHANGES
1145     case CSS_PROP_SCROLLBAR_FACE_COLOR:
1146         // FIXME: unimplemented
1147         break;
1148     case CSS_PROP_SCROLLBAR_SHADOW_COLOR:
1149         // FIXME: unimplemented
1150         break;
1151     case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR:
1152         // FIXME: unimplemented
1153         break;
1154     case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR:
1155         // FIXME: unimplemented
1156         break;
1157     case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR:
1158         // FIXME: unimplemented
1159         break;
1160     case CSS_PROP_SCROLLBAR_TRACK_COLOR:
1161         // FIXME: unimplemented
1162         break;
1163     case CSS_PROP_SCROLLBAR_ARROW_COLOR:
1164         // FIXME: unimplemented
1165         break;
1166 #endif
1167 #if APPLE_CHANGES
1168         case CSS_PROP__APPLE_DASHBOARD_REGION: {
1169             QValueList<StyleDashboardRegion> regions = style->dashboardRegions();
1170             uint i, count = regions.count();
1171             if (count == 1 && regions[0].type == StyleDashboardRegion::None)
1172                 return new CSSPrimitiveValueImpl (CSS_VAL_NONE);
1173                 
1174             DashboardRegionImpl *firstRegion = new DashboardRegionImpl(), *region;
1175             region = firstRegion;
1176             for (i = 0; i < count; i++) {
1177                 StyleDashboardRegion styleRegion = regions[i];
1178                 region->m_label = styleRegion.label;
1179                 LengthBox offset = styleRegion.offset;
1180                 region->setTop (new CSSPrimitiveValueImpl(offset.top.value, CSSPrimitiveValue::CSS_PX));
1181                 region->setRight (new CSSPrimitiveValueImpl(offset.right.value, CSSPrimitiveValue::CSS_PX));
1182                 region->setBottom (new CSSPrimitiveValueImpl(offset.bottom.value, CSSPrimitiveValue::CSS_PX));
1183                 region->setLeft (new CSSPrimitiveValueImpl(offset.left.value, CSSPrimitiveValue::CSS_PX));
1184                 region->m_isRectangle = (styleRegion.type == StyleDashboardRegion::Rectangle); 
1185                 region->m_isCircle = (styleRegion.type == StyleDashboardRegion::Circle);
1186                 if (i != count-1) {
1187                     DashboardRegionImpl *newRegion = new DashboardRegionImpl();
1188                     region->setNext (newRegion);
1189                     region = newRegion;
1190                 }
1191             }
1192             return new CSSPrimitiveValueImpl(firstRegion);
1193         }
1194 #endif
1195     }
1196
1197     ERROR("unimplemented propertyID: %d", propertyID);
1198     return 0;
1199 }
1200
1201 DOMString CSSComputedStyleDeclarationImpl::getPropertyValue(int propertyID) const
1202 {
1203     CSSValueImpl* value = getPropertyCSSValue(propertyID);
1204     if (value) {
1205         value->ref();
1206         DOMString result = value->cssText();
1207         value->deref();
1208         return result;
1209     }
1210     return "";
1211 }
1212
1213 bool CSSComputedStyleDeclarationImpl::getPropertyPriority(int) const
1214 {
1215     // All computed styles have a priority of false (not "important").
1216     return false;
1217 }
1218
1219 DOMString CSSComputedStyleDeclarationImpl::removeProperty(int, int &exceptionCode)
1220 {
1221     exceptionCode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
1222     return DOMString();
1223 }
1224
1225 void CSSComputedStyleDeclarationImpl::setProperty(int, const DOMString &, bool, int &exceptionCode)
1226 {
1227     exceptionCode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
1228 }
1229
1230 unsigned long CSSComputedStyleDeclarationImpl::length() const
1231 {
1232     return numComputedProperties;
1233 }
1234
1235 DOMString CSSComputedStyleDeclarationImpl::item(unsigned long i) const
1236 {
1237     if (i >= numComputedProperties)
1238         return DOMString();
1239     return getPropertyValue(computedProperties[i]);
1240 }
1241
1242 CSSMutableStyleDeclarationImpl *CSSComputedStyleDeclarationImpl::copyInheritableProperties() const
1243 {
1244     return copyPropertiesInSet(inheritableProperties, numInheritableProperties);
1245 }
1246
1247 CSSMutableStyleDeclarationImpl *CSSComputedStyleDeclarationImpl::copy() const
1248 {
1249     return copyPropertiesInSet(computedProperties, numComputedProperties);
1250 }
1251
1252 CSSMutableStyleDeclarationImpl *CSSComputedStyleDeclarationImpl::makeMutable()
1253 {
1254     return copy();
1255 }
1256
1257 } // namespace DOM