fix logic
[personal-kdelibs.git] / khtml / css / css_renderstyledeclarationimpl.cpp
blob6e95c52f649bbb8ebe71616495b8ad4170b2b45e
1 /**
2 * css_renderstyledeclarationimpl.cpp
4 * Copyright 2004 Zack Rusin <zack@kde.org>
5 * Copyright 2004,2005 Apple Computer, Inc.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA
22 #include "css_renderstyledeclarationimpl.h"
24 #include "rendering/render_style.h"
25 #include "rendering/render_object.h"
27 #include "cssproperties.h"
28 #include "cssvalues.h"
30 #include <dom/dom_exception.h>
32 using namespace DOM;
33 using namespace khtml;
35 // List of all properties we know how to compute, omitting shorthands.
36 static const int computedProperties[] = {
37 CSS_PROP_BACKGROUND_COLOR,
38 CSS_PROP_BACKGROUND_IMAGE,
39 CSS_PROP_BACKGROUND_REPEAT,
40 CSS_PROP_BACKGROUND_ATTACHMENT,
41 CSS_PROP_BACKGROUND_POSITION,
42 CSS_PROP_BACKGROUND_POSITION_X,
43 CSS_PROP_BACKGROUND_POSITION_Y,
44 CSS_PROP_BORDER_COLLAPSE,
45 CSS_PROP_BORDER_SPACING,
46 CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING,
47 CSS_PROP__KHTML_BORDER_VERTICAL_SPACING,
48 CSS_PROP__KHTML_BORDER_TOP_RIGHT_RADIUS,
49 CSS_PROP__KHTML_BORDER_BOTTOM_RIGHT_RADIUS,
50 CSS_PROP__KHTML_BORDER_BOTTOM_LEFT_RADIUS,
51 CSS_PROP__KHTML_BORDER_TOP_LEFT_RADIUS,
52 CSS_PROP_BORDER_TOP_COLOR,
53 CSS_PROP_BORDER_RIGHT_COLOR,
54 CSS_PROP_BORDER_BOTTOM_COLOR,
55 CSS_PROP_BORDER_LEFT_COLOR,
56 CSS_PROP_BORDER_TOP_STYLE,
57 CSS_PROP_BORDER_RIGHT_STYLE,
58 CSS_PROP_BORDER_BOTTOM_STYLE,
59 CSS_PROP_BORDER_LEFT_STYLE,
60 CSS_PROP_BORDER_TOP_WIDTH,
61 CSS_PROP_BORDER_RIGHT_WIDTH,
62 CSS_PROP_BORDER_BOTTOM_WIDTH,
63 CSS_PROP_BORDER_LEFT_WIDTH,
64 CSS_PROP_BOTTOM,
65 CSS_PROP_BOX_SIZING,
66 CSS_PROP_CAPTION_SIDE,
67 CSS_PROP_CLEAR,
68 CSS_PROP_COLOR,
69 CSS_PROP_CURSOR,
70 CSS_PROP_DIRECTION,
71 CSS_PROP_DISPLAY,
72 CSS_PROP_EMPTY_CELLS,
73 CSS_PROP_FLOAT,
74 CSS_PROP_FONT_FAMILY,
75 CSS_PROP_FONT_SIZE,
76 CSS_PROP_FONT_STYLE,
77 CSS_PROP_FONT_VARIANT,
78 CSS_PROP_FONT_WEIGHT,
79 CSS_PROP_HEIGHT,
80 CSS_PROP_LEFT,
81 CSS_PROP_LETTER_SPACING,
82 CSS_PROP_LINE_HEIGHT,
83 CSS_PROP_LIST_STYLE_IMAGE,
84 CSS_PROP_LIST_STYLE_POSITION,
85 CSS_PROP_LIST_STYLE_TYPE,
86 CSS_PROP_MARGIN_TOP,
87 CSS_PROP_MARGIN_RIGHT,
88 CSS_PROP_MARGIN_BOTTOM,
89 CSS_PROP_MARGIN_LEFT,
90 CSS_PROP__KHTML_MARQUEE_DIRECTION,
91 CSS_PROP__KHTML_MARQUEE_INCREMENT,
92 CSS_PROP__KHTML_MARQUEE_REPETITION,
93 CSS_PROP__KHTML_MARQUEE_STYLE,
94 CSS_PROP_MAX_HEIGHT,
95 CSS_PROP_MAX_WIDTH,
96 CSS_PROP_MIN_HEIGHT,
97 CSS_PROP_MIN_WIDTH,
98 CSS_PROP_OPACITY,
99 CSS_PROP_ORPHANS,
100 CSS_PROP_OUTLINE_STYLE,
101 CSS_PROP_OVERFLOW,
102 CSS_PROP_OVERFLOW_X,
103 CSS_PROP_OVERFLOW_Y,
104 CSS_PROP_PADDING_TOP,
105 CSS_PROP_PADDING_RIGHT,
106 CSS_PROP_PADDING_BOTTOM,
107 CSS_PROP_PADDING_LEFT,
108 CSS_PROP_PAGE_BREAK_AFTER,
109 CSS_PROP_PAGE_BREAK_BEFORE,
110 CSS_PROP_PAGE_BREAK_INSIDE,
111 CSS_PROP_POSITION,
112 CSS_PROP_RIGHT,
113 CSS_PROP_TABLE_LAYOUT,
114 CSS_PROP_TEXT_ALIGN,
115 CSS_PROP_TEXT_DECORATION,
116 CSS_PROP_TEXT_INDENT,
117 CSS_PROP_TEXT_OVERFLOW,
118 CSS_PROP_TEXT_SHADOW,
119 CSS_PROP_TEXT_TRANSFORM,
120 CSS_PROP_TOP,
121 CSS_PROP_UNICODE_BIDI,
122 CSS_PROP_VERTICAL_ALIGN,
123 CSS_PROP_VISIBILITY,
124 CSS_PROP_WHITE_SPACE,
125 CSS_PROP_WIDOWS,
126 CSS_PROP_WIDTH,
127 CSS_PROP_WORD_SPACING,
128 CSS_PROP_Z_INDEX
131 const unsigned numComputedProperties = sizeof(computedProperties) / sizeof(computedProperties[0]);
134 static CSSValueImpl *valueForLength(const Length &length, int max)
136 if (length.isPercent()) {
137 return new CSSPrimitiveValueImpl(length.value(), CSSPrimitiveValue::CSS_PERCENTAGE);
139 else {
140 return new CSSPrimitiveValueImpl(length.minWidth(max), CSSPrimitiveValue::CSS_PX);
144 static CSSValueImpl *valueForLength2(const Length &length)
146 if (length.isPercent()) {
147 return new CSSPrimitiveValueImpl(length.value(), CSSPrimitiveValue::CSS_PERCENTAGE);
149 else {
150 return new CSSPrimitiveValueImpl(length.value(), CSSPrimitiveValue::CSS_PX);
154 static CSSValueImpl *valueForBorderStyle(EBorderStyle style)
156 switch (style) {
157 case khtml::BNATIVE:
158 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_NATIVE);
159 case khtml::BNONE:
160 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
161 case khtml::BHIDDEN:
162 return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
163 case khtml::INSET:
164 return new CSSPrimitiveValueImpl(CSS_VAL_INSET);
165 case khtml::GROOVE:
166 return new CSSPrimitiveValueImpl(CSS_VAL_GROOVE);
167 case khtml::RIDGE:
168 return new CSSPrimitiveValueImpl(CSS_VAL_RIDGE);
169 case khtml::OUTSET:
170 return new CSSPrimitiveValueImpl(CSS_VAL_OUTSET);
171 case khtml::DOTTED:
172 return new CSSPrimitiveValueImpl(CSS_VAL_DOTTED);
173 case khtml::DASHED:
174 return new CSSPrimitiveValueImpl(CSS_VAL_DASHED);
175 case khtml::SOLID:
176 return new CSSPrimitiveValueImpl(CSS_VAL_SOLID);
177 case khtml::DOUBLE:
178 return new CSSPrimitiveValueImpl(CSS_VAL_DOUBLE);
180 Q_ASSERT( 0 );
181 return 0;
184 static CSSValueImpl *valueForBorderRadii(BorderRadii radii)
186 CSSPrimitiveValueImpl* h = new CSSPrimitiveValueImpl(radii.horizontal, CSSPrimitiveValue::CSS_PX);
187 CSSPrimitiveValueImpl* v = new CSSPrimitiveValueImpl(radii.vertical, CSSPrimitiveValue::CSS_PX);
188 return new CSSPrimitiveValueImpl(new PairImpl(h, v));
191 static CSSValueImpl *valueForTextAlign(ETextAlign align)
193 switch (align) {
194 case khtml::TAAUTO:
195 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
196 case khtml::LEFT:
197 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
198 case khtml::RIGHT:
199 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
200 case khtml::CENTER:
201 return new CSSPrimitiveValueImpl(CSS_VAL_CENTER);
202 case khtml::JUSTIFY:
203 return new CSSPrimitiveValueImpl(CSS_VAL_JUSTIFY);
204 case khtml::KHTML_LEFT:
205 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_LEFT);
206 case khtml::KHTML_RIGHT:
207 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_RIGHT);
208 case khtml::KHTML_CENTER:
209 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_CENTER);
211 Q_ASSERT( 0 );
212 return 0;
215 DOMString khtml::stringForListStyleType(EListStyleType type)
217 switch (type) {
218 case khtml::LDISC:
219 return "disc";
220 case khtml::LCIRCLE:
221 return "circle";
222 case khtml::LSQUARE:
223 return "square";
224 case khtml::LBOX:
225 return "box";
226 case khtml::LDIAMOND:
227 return "-khtml-diamond";
228 case khtml::LDECIMAL:
229 return "decimal";
230 case khtml::DECIMAL_LEADING_ZERO:
231 return "decimal-leading-zero";
232 case khtml::ARABIC_INDIC:
233 return "-khtml-arabic-indic";
234 case khtml::LAO:
235 return "-khtml-lao";
236 case khtml::PERSIAN:
237 return "-khtml-persian";
238 case khtml::URDU:
239 return "-khtml-urdu";
240 case khtml::THAI:
241 return "-khtml-thai";
242 case khtml::TIBETAN:
243 return "-khtml-tibetan";
244 case khtml::LOWER_ROMAN:
245 return "lower-roman";
246 case khtml::UPPER_ROMAN:
247 return "upper-roman";
248 case khtml::HEBREW:
249 return "hebrew";
250 case khtml::ARMENIAN:
251 return "armenian";
252 case khtml::GEORGIAN:
253 return "georgian";
254 case khtml::CJK_IDEOGRAPHIC:
255 return "cjk-ideographic";
256 case khtml::JAPANESE_FORMAL:
257 return "-khtml-japanese-formal";
258 case khtml::JAPANESE_INFORMAL:
259 return "-khtml-japanese-informal";
260 case khtml::SIMP_CHINESE_FORMAL:
261 return "-khtml-simp-chinese-formal";
262 case khtml::SIMP_CHINESE_INFORMAL:
263 return "-khtml-simp-chinese-informal";
264 case khtml::TRAD_CHINESE_FORMAL:
265 return "-khtml-trad-chinese-formal";
266 case khtml::TRAD_CHINESE_INFORMAL:
267 return "-khtml-trad-chinese-informal";
268 case khtml::LOWER_GREEK:
269 return "lower-greek";
270 case khtml::UPPER_GREEK:
271 return "-khtml-upper-greek";
272 case khtml::LOWER_ALPHA:
273 return "lower-alpha";
274 case khtml::UPPER_ALPHA:
275 return "upper-alpha";
276 case khtml::LOWER_LATIN:
277 return "lower-latin";
278 case khtml::UPPER_LATIN:
279 return "upper-latin";
280 case khtml::HIRAGANA:
281 return "hiragana";
282 case khtml::KATAKANA:
283 return "katakana";
284 case khtml::HIRAGANA_IROHA:
285 return "hiragana-iroha";
286 case khtml::KATAKANA_IROHA:
287 return "katakana_iroha";
288 case khtml::LNONE:
289 return "none";
291 Q_ASSERT( 0 );
292 return "";
295 static CSSPrimitiveValueImpl* valueForColor(QColor color)
297 if (color.isValid())
298 return new CSSPrimitiveValueImpl(color.rgba());
299 else
300 return new CSSPrimitiveValueImpl(khtml::transparentColor);
303 static CSSValueImpl* valueForShadow(const ShadowData *shadow)
305 if (!shadow)
306 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
307 CSSValueListImpl *list = new CSSValueListImpl;
308 for (const ShadowData *s = shadow; s; s = s->next) {
309 CSSPrimitiveValueImpl *x = new CSSPrimitiveValueImpl(s->x, CSSPrimitiveValue::CSS_PX);
310 CSSPrimitiveValueImpl *y = new CSSPrimitiveValueImpl(s->y, CSSPrimitiveValue::CSS_PX);
311 CSSPrimitiveValueImpl *blur = new CSSPrimitiveValueImpl(s->blur, CSSPrimitiveValue::CSS_PX);
312 CSSPrimitiveValueImpl *color = valueForColor(s->color);
313 list->append(new ShadowValueImpl(x, y, blur, color));
315 return list;
318 static CSSValueImpl *getPositionOffsetValue(RenderObject *renderer, int propertyID)
320 if (!renderer)
321 return 0;
323 RenderStyle *style = renderer->style();
324 if (!style)
325 return 0;
327 Length l;
328 switch (propertyID) {
329 case CSS_PROP_LEFT:
330 l = style->left();
331 break;
332 case CSS_PROP_RIGHT:
333 l = style->right();
334 break;
335 case CSS_PROP_TOP:
336 l = style->top();
337 break;
338 case CSS_PROP_BOTTOM:
339 l = style->bottom();
340 break;
341 default:
342 return 0;
345 if (renderer->isPositioned())
346 return valueForLength(l, renderer->contentWidth());
348 if (renderer->isRelPositioned())
349 // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined.
350 // In other words if left is auto and right is not auto, then left's computed value is negative right.
351 // So we should get the opposite length unit and see if it is auto.
352 return valueForLength(l, renderer->contentWidth());
354 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
357 RenderStyleDeclarationImpl::RenderStyleDeclarationImpl( DOM::NodeImpl *node )
358 : CSSStyleDeclarationImpl(0), m_node(node)
360 //kDebug() << "Render Style Declaration created";
363 RenderStyleDeclarationImpl::~RenderStyleDeclarationImpl()
365 //kDebug() << "Render Style Declaration destroyed";
368 DOM::DOMString RenderStyleDeclarationImpl::cssText() const
370 DOMString result;
372 for (unsigned i = 0; i < numComputedProperties; i++) {
373 if (i != 0)
374 result += " ";
375 result += getPropertyName(computedProperties[i]);
376 result += ": ";
377 result += getPropertyValue(computedProperties[i]);
378 result += ";";
381 return result;
384 void RenderStyleDeclarationImpl::setCssText( DOM::DOMString )
386 // ### report that this sucka is read only
389 CSSValueImpl *RenderStyleDeclarationImpl::getPropertyCSSValue( int propertyID ) const
391 NodeImpl *node = m_node.get();
392 if (!node)
393 return 0;
395 // Make sure our layout is up to date before we allow a query on these attributes.
396 DocumentImpl* docimpl = node->document();
397 if (docimpl) {
398 docimpl->updateLayout();
401 RenderStyle *style = node->computedStyle();
402 if (!style)
403 return 0;
404 RenderObject *renderer = node->renderer(); // can be NULL
406 // temporary(?) measure to handle with missing render object
407 // check how we can better deal with it on a case-by-case basis
408 #define RETURN_NULL_ON_NULL(ptr) if(ptr == 0) return 0;
410 switch(propertyID)
412 case CSS_PROP_BACKGROUND_COLOR:
413 return valueForColor(style->backgroundColor());
414 case CSS_PROP_BACKGROUND_IMAGE:
415 if (style->backgroundImage())
416 return new CSSPrimitiveValueImpl(style->backgroundImage()->url(),
417 CSSPrimitiveValue::CSS_URI);
418 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
419 case CSS_PROP_BACKGROUND_REPEAT:
420 switch (style->backgroundRepeat()) {
421 case khtml::REPEAT:
422 return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT);
423 case khtml::REPEAT_X:
424 return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT_X);
425 case khtml::REPEAT_Y:
426 return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT_Y);
427 case khtml::NO_REPEAT:
428 return new CSSPrimitiveValueImpl(CSS_VAL_NO_REPEAT);
429 default:
430 Q_ASSERT( 0 );
432 case CSS_PROP_BACKGROUND_ATTACHMENT:
433 if (style->backgroundAttachment())
434 return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
435 else
436 return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
437 case CSS_PROP_BACKGROUND_POSITION:
439 RETURN_NULL_ON_NULL(renderer);
440 DOMString string;
441 Length length(style->backgroundXPosition());
442 if (length.isPercent())
443 string = QString::number(length.value()) + "%";
444 else
445 string = QString::number(length.minWidth(renderer->contentWidth())) + "px";
446 string += " ";
447 length = style->backgroundYPosition();
448 if (length.isPercent())
449 string += QString::number(length.value()) + "%";
450 else
451 string += QString::number(length.minWidth(renderer->contentWidth())) + "px";
452 return new CSSPrimitiveValueImpl(string, CSSPrimitiveValue::CSS_STRING);
454 case CSS_PROP_BACKGROUND_POSITION_X:
455 RETURN_NULL_ON_NULL(renderer);
456 return valueForLength(style->backgroundXPosition(), renderer->contentWidth());
457 case CSS_PROP_BACKGROUND_POSITION_Y:
458 RETURN_NULL_ON_NULL(renderer);
459 return valueForLength(style->backgroundYPosition(), renderer->contentHeight());
460 case CSS_PROP_BORDER_COLLAPSE:
461 if (style->borderCollapse())
462 return new CSSPrimitiveValueImpl(CSS_VAL_COLLAPSE);
463 else
464 return new CSSPrimitiveValueImpl(CSS_VAL_SEPARATE);
465 case CSS_PROP_BORDER_SPACING:
467 QString string(QString::number(style->borderHorizontalSpacing()) +
468 "px " +
469 QString::number(style->borderVerticalSpacing()) +
470 "px");
471 return new CSSPrimitiveValueImpl(DOMString(string), CSSPrimitiveValue::CSS_STRING);
473 case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING:
474 return new CSSPrimitiveValueImpl(style->borderHorizontalSpacing(),
475 CSSPrimitiveValue::CSS_PX);
476 case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING:
477 return new CSSPrimitiveValueImpl(style->borderVerticalSpacing(),
478 CSSPrimitiveValue::CSS_PX);
479 case CSS_PROP__KHTML_BORDER_TOP_RIGHT_RADIUS:
480 return valueForBorderRadii(style->borderTopRightRadius());
481 case CSS_PROP__KHTML_BORDER_BOTTOM_RIGHT_RADIUS:
482 return valueForBorderRadii(style->borderBottomRightRadius());
483 case CSS_PROP__KHTML_BORDER_BOTTOM_LEFT_RADIUS:
484 return valueForBorderRadii(style->borderBottomLeftRadius());
485 case CSS_PROP__KHTML_BORDER_TOP_LEFT_RADIUS:
486 return valueForBorderRadii(style->borderTopLeftRadius());
487 case CSS_PROP_BORDER_TOP_COLOR:
488 return valueForColor(style->borderTopColor());
489 case CSS_PROP_BORDER_RIGHT_COLOR:
490 return valueForColor(style->borderRightColor());
491 case CSS_PROP_BORDER_BOTTOM_COLOR:
492 return valueForColor(style->borderBottomColor());
493 case CSS_PROP_BORDER_LEFT_COLOR:
494 return valueForColor(style->borderLeftColor());
495 case CSS_PROP_BORDER_TOP_STYLE:
496 return valueForBorderStyle(style->borderTopStyle());
497 case CSS_PROP_BORDER_RIGHT_STYLE:
498 return valueForBorderStyle(style->borderRightStyle());
499 case CSS_PROP_BORDER_BOTTOM_STYLE:
500 return valueForBorderStyle(style->borderBottomStyle());
501 case CSS_PROP_BORDER_LEFT_STYLE:
502 return valueForBorderStyle(style->borderLeftStyle());
503 case CSS_PROP_BORDER_TOP_WIDTH:
504 return new CSSPrimitiveValueImpl( style->borderTopWidth(), CSSPrimitiveValue::CSS_PX );
505 case CSS_PROP_BORDER_RIGHT_WIDTH:
506 return new CSSPrimitiveValueImpl( style->borderRightWidth(), CSSPrimitiveValue::CSS_PX );
507 case CSS_PROP_BORDER_BOTTOM_WIDTH:
508 return new CSSPrimitiveValueImpl( style->borderBottomWidth(), CSSPrimitiveValue::CSS_PX );
509 case CSS_PROP_BORDER_LEFT_WIDTH:
510 return new CSSPrimitiveValueImpl( style->borderLeftWidth(), CSSPrimitiveValue::CSS_PX );
511 case CSS_PROP_BOTTOM:
512 RETURN_NULL_ON_NULL(renderer);
513 return getPositionOffsetValue(renderer, CSS_PROP_BOTTOM);
514 case CSS_PROP_BOX_SIZING:
515 if (style->boxSizing() == BORDER_BOX)
516 return new CSSPrimitiveValueImpl(CSS_VAL_BORDER_BOX);
517 else
518 return new CSSPrimitiveValueImpl(CSS_VAL_CONTENT_BOX);
519 case CSS_PROP_CAPTION_SIDE:
520 switch (style->captionSide()) {
521 case CAPLEFT:
522 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
523 case CAPRIGHT:
524 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
525 case CAPTOP:
526 return new CSSPrimitiveValueImpl(CSS_VAL_TOP);
527 case CAPBOTTOM:
528 return new CSSPrimitiveValueImpl(CSS_VAL_BOTTOM);
530 Q_ASSERT(0);
531 break;
532 case CSS_PROP_CLEAR:
533 switch (style->clear()) {
534 case CNONE:
535 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
536 case CLEFT:
537 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
538 case CRIGHT:
539 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
540 case CBOTH:
541 return new CSSPrimitiveValueImpl(CSS_VAL_BOTH);
543 Q_ASSERT(0);
544 break;
545 case CSS_PROP_CLIP:
546 break;
547 case CSS_PROP_COLOR:
548 return valueForColor(style->color());
549 case CSS_PROP_CONTENT:
550 break;
551 case CSS_PROP_COUNTER_INCREMENT:
552 break;
553 case CSS_PROP_COUNTER_RESET:
554 break;
555 case CSS_PROP_CURSOR:
556 switch (style->cursor()) {
557 case CURSOR_AUTO:
558 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
559 case CURSOR_DEFAULT:
560 return new CSSPrimitiveValueImpl(CSS_VAL_DEFAULT);
561 case CURSOR_NONE:
562 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
563 case CURSOR_CONTEXT_MENU:
564 return new CSSPrimitiveValueImpl(CSS_VAL_CONTEXT_MENU);
565 case CURSOR_HELP:
566 return new CSSPrimitiveValueImpl(CSS_VAL_HELP);
567 case CURSOR_POINTER:
568 return new CSSPrimitiveValueImpl(CSS_VAL_POINTER);
569 case CURSOR_PROGRESS:
570 return new CSSPrimitiveValueImpl(CSS_VAL_PROGRESS);
571 case CURSOR_WAIT:
572 return new CSSPrimitiveValueImpl(CSS_VAL_WAIT);
573 case CURSOR_CELL:
574 return new CSSPrimitiveValueImpl(CSS_VAL_CELL);
575 case CURSOR_CROSS:
576 return new CSSPrimitiveValueImpl(CSS_VAL_CROSSHAIR);
577 case CURSOR_TEXT:
578 return new CSSPrimitiveValueImpl(CSS_VAL_TEXT);
579 case CURSOR_VERTICAL_TEXT:
580 return new CSSPrimitiveValueImpl(CSS_VAL_VERTICAL_TEXT);
581 case CURSOR_ALIAS:
582 return new CSSPrimitiveValueImpl(CSS_VAL_ALIAS);
583 case CURSOR_COPY:
584 return new CSSPrimitiveValueImpl(CSS_VAL_COPY);
585 case CURSOR_MOVE:
586 return new CSSPrimitiveValueImpl(CSS_VAL_MOVE);
587 case CURSOR_NO_DROP:
588 return new CSSPrimitiveValueImpl(CSS_VAL_NO_DROP);
589 case CURSOR_NOT_ALLOWED:
590 return new CSSPrimitiveValueImpl(CSS_VAL_NOT_ALLOWED);
591 case CURSOR_E_RESIZE:
592 return new CSSPrimitiveValueImpl(CSS_VAL_E_RESIZE);
593 case CURSOR_N_RESIZE:
594 return new CSSPrimitiveValueImpl(CSS_VAL_N_RESIZE);
595 case CURSOR_NE_RESIZE:
596 return new CSSPrimitiveValueImpl(CSS_VAL_NE_RESIZE);
597 case CURSOR_NW_RESIZE:
598 return new CSSPrimitiveValueImpl(CSS_VAL_NW_RESIZE);
599 case CURSOR_S_RESIZE:
600 return new CSSPrimitiveValueImpl(CSS_VAL_S_RESIZE);
601 case CURSOR_SE_RESIZE:
602 return new CSSPrimitiveValueImpl(CSS_VAL_SE_RESIZE);
603 case CURSOR_SW_RESIZE:
604 return new CSSPrimitiveValueImpl(CSS_VAL_SW_RESIZE);
605 case CURSOR_W_RESIZE:
606 return new CSSPrimitiveValueImpl(CSS_VAL_W_RESIZE);
607 case CURSOR_EW_RESIZE:
608 return new CSSPrimitiveValueImpl(CSS_VAL_EW_RESIZE);
609 case CURSOR_NS_RESIZE:
610 return new CSSPrimitiveValueImpl(CSS_VAL_NS_RESIZE);
611 case CURSOR_NESW_RESIZE:
612 return new CSSPrimitiveValueImpl(CSS_VAL_NESW_RESIZE);
613 case CURSOR_NWSE_RESIZE:
614 return new CSSPrimitiveValueImpl(CSS_VAL_NWSE_RESIZE);
615 case CURSOR_COL_RESIZE:
616 return new CSSPrimitiveValueImpl(CSS_VAL_COL_RESIZE);
617 case CURSOR_ROW_RESIZE:
618 return new CSSPrimitiveValueImpl(CSS_VAL_ROW_RESIZE);
619 case CURSOR_ALL_SCROLL:
620 return new CSSPrimitiveValueImpl(CSS_VAL_ALL_SCROLL);
622 Q_ASSERT(0);
623 break;
624 case CSS_PROP_DIRECTION:
625 switch (style->direction()) {
626 case LTR:
627 return new CSSPrimitiveValueImpl(CSS_VAL_LTR);
628 case RTL:
629 return new CSSPrimitiveValueImpl(CSS_VAL_RTL);
631 Q_ASSERT(0);
632 break;
633 case CSS_PROP_DISPLAY:
634 switch (style->display()) {
635 case INLINE:
636 return new CSSPrimitiveValueImpl(CSS_VAL_INLINE);
637 case BLOCK:
638 return new CSSPrimitiveValueImpl(CSS_VAL_BLOCK);
639 case LIST_ITEM:
640 return new CSSPrimitiveValueImpl(CSS_VAL_LIST_ITEM);
641 case RUN_IN:
642 return new CSSPrimitiveValueImpl(CSS_VAL_RUN_IN);
643 case COMPACT:
644 return new CSSPrimitiveValueImpl(CSS_VAL_COMPACT);
645 case INLINE_BLOCK:
646 return new CSSPrimitiveValueImpl(CSS_VAL_INLINE_BLOCK);
647 case TABLE:
648 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE);
649 case INLINE_TABLE:
650 return new CSSPrimitiveValueImpl(CSS_VAL_INLINE_TABLE);
651 case TABLE_ROW_GROUP:
652 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_ROW_GROUP);
653 case TABLE_HEADER_GROUP:
654 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_HEADER_GROUP);
655 case TABLE_FOOTER_GROUP:
656 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_FOOTER_GROUP);
657 case TABLE_ROW:
658 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_ROW);
659 case TABLE_COLUMN_GROUP:
660 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_COLUMN_GROUP);
661 case TABLE_COLUMN:
662 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_COLUMN);
663 case TABLE_CELL:
664 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_CELL);
665 case TABLE_CAPTION:
666 return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_CAPTION);
667 case NONE:
668 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
670 Q_ASSERT( 0 );
671 break;
672 case CSS_PROP_EMPTY_CELLS:
673 switch (style->emptyCells()) {
674 case SHOW:
675 return new CSSPrimitiveValueImpl(CSS_VAL_SHOW);
676 case HIDE:
677 return new CSSPrimitiveValueImpl(CSS_VAL_HIDE);
679 Q_ASSERT( 0 );
680 break;
681 case CSS_PROP_FLOAT:
683 switch (style->floating()) {
684 case FNONE:
685 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
686 case FLEFT:
687 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
688 case FRIGHT:
689 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
690 case FLEFT_ALIGN:
691 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_LEFT);
692 case FRIGHT_ALIGN:
693 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_RIGHT);
696 case CSS_PROP_FONT_FAMILY:
698 FontDef def = style->htmlFont().getFontDef();
699 return new CSSPrimitiveValueImpl(DOMString(def.family), CSSPrimitiveValue::CSS_STRING);
701 case CSS_PROP_FONT_SIZE:
703 FontDef def = style->htmlFont().getFontDef();
704 return new CSSPrimitiveValueImpl(def.size, CSSPrimitiveValue::CSS_PX);
706 case CSS_PROP_FONT_STYLE:
708 // FIXME: handle oblique
709 FontDef def = style->htmlFont().getFontDef();
710 if (def.italic)
711 return new CSSPrimitiveValueImpl(CSS_VAL_ITALIC);
712 else
713 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
715 case CSS_PROP_FONT_VARIANT:
717 FontDef def = style->htmlFont().getFontDef();
718 if (def.smallCaps)
719 return new CSSPrimitiveValueImpl(CSS_VAL_SMALL_CAPS);
720 else
721 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
723 case CSS_PROP_FONT_WEIGHT:
725 // FIXME: this does not reflect the full range of weights
726 // that can be expressed with CSS
727 FontDef def = style->htmlFont().getFontDef();
728 if (def.weight == QFont::Bold)
729 return new CSSPrimitiveValueImpl(CSS_VAL_BOLD);
730 else
731 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
733 case CSS_PROP_HEIGHT:
734 if (renderer)
735 return new CSSPrimitiveValueImpl(renderer->contentHeight(), CSSPrimitiveValue::CSS_PX);
736 return valueForLength2(style->height());
737 case CSS_PROP_LEFT:
738 RETURN_NULL_ON_NULL(renderer);
739 return getPositionOffsetValue(renderer, CSS_PROP_LEFT);
740 case CSS_PROP_LETTER_SPACING:
741 if (style->letterSpacing() == 0)
742 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
743 return new CSSPrimitiveValueImpl(style->letterSpacing(), CSSPrimitiveValue::CSS_PX);
744 case CSS_PROP_LINE_HEIGHT:
746 // Note: internally a specified <number> value gets encoded as a percentage,
747 // so the isPercent() case corresponds to the <number> case;
748 // values < 0 are used to mark "normal"; and specified %%
749 // get computed down to px by the time they get to RenderStyle
750 // already
751 Length length(style->lineHeight());
752 if (length.value() < 0)
753 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
754 if (length.isPercent()) {
755 //XXX: merge from webcore the computedStyle/specifiedStyle distinction in rendering/font.h
756 float computedSize = style->htmlFont().getFontDef().size;
757 return new CSSPrimitiveValueImpl((int)(length.value() * computedSize) / 100, CSSPrimitiveValue::CSS_PX);
759 else {
760 return new CSSPrimitiveValueImpl(length.value(), CSSPrimitiveValue::CSS_PX);
763 case CSS_PROP_LIST_STYLE_IMAGE:
764 if (style->listStyleImage())
765 return new CSSPrimitiveValueImpl(style->listStyleImage()->url(), CSSPrimitiveValue::CSS_URI);
766 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
767 case CSS_PROP_LIST_STYLE_POSITION:
768 switch (style->listStylePosition()) {
769 case OUTSIDE:
770 return new CSSPrimitiveValueImpl(CSS_VAL_OUTSIDE);
771 case INSIDE:
772 return new CSSPrimitiveValueImpl(CSS_VAL_INSIDE);
774 Q_ASSERT( 0 );
775 break;
776 case CSS_PROP_LIST_STYLE_TYPE:
777 return new CSSPrimitiveValueImpl(stringForListStyleType(style->listStyleType()), CSSPrimitiveValue::CSS_STRING);
778 case CSS_PROP_MARGIN_TOP:
779 if (renderer)
780 return new CSSPrimitiveValueImpl(renderer->marginTop(), CSSPrimitiveValue::CSS_PX);
781 return valueForLength2(style->marginTop());
782 case CSS_PROP_MARGIN_RIGHT:
783 if (renderer)
784 return new CSSPrimitiveValueImpl(renderer->marginRight(), CSSPrimitiveValue::CSS_PX);
785 return valueForLength2(style->marginRight());
786 case CSS_PROP_MARGIN_BOTTOM:
787 if (renderer)
788 return new CSSPrimitiveValueImpl(renderer->marginBottom(), CSSPrimitiveValue::CSS_PX);
789 return valueForLength2(style->marginBottom());
790 case CSS_PROP_MARGIN_LEFT:
791 if (renderer)
792 return new CSSPrimitiveValueImpl(renderer->marginLeft(), CSSPrimitiveValue::CSS_PX);
793 return valueForLength2(style->marginLeft());
794 case CSS_PROP__KHTML_MARQUEE:
795 // FIXME: unimplemented
796 break;
797 case CSS_PROP__KHTML_MARQUEE_DIRECTION:
798 switch (style->marqueeDirection()) {
799 case MFORWARD:
800 return new CSSPrimitiveValueImpl(CSS_VAL_FORWARDS);
801 case MBACKWARD:
802 return new CSSPrimitiveValueImpl(CSS_VAL_BACKWARDS);
803 case MAUTO:
804 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
805 case MUP:
806 return new CSSPrimitiveValueImpl(CSS_VAL_UP);
807 case MDOWN:
808 return new CSSPrimitiveValueImpl(CSS_VAL_DOWN);
809 case MLEFT:
810 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
811 case MRIGHT:
812 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
814 Q_ASSERT(0);
815 return 0;
816 case CSS_PROP__KHTML_MARQUEE_INCREMENT:
817 RETURN_NULL_ON_NULL(renderer);
818 return valueForLength(style->marqueeIncrement(), renderer->contentWidth());
819 case CSS_PROP__KHTML_MARQUEE_REPETITION:
820 if (style->marqueeLoopCount() < 0)
821 return new CSSPrimitiveValueImpl(CSS_VAL_INFINITE);
822 return new CSSPrimitiveValueImpl(style->marqueeLoopCount(), CSSPrimitiveValue::CSS_NUMBER);
823 case CSS_PROP__KHTML_MARQUEE_SPEED:
824 // FIXME: unimplemented
825 break;
826 case CSS_PROP__KHTML_MARQUEE_STYLE:
827 switch (style->marqueeBehavior()) {
828 case MNONE:
829 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
830 case MSCROLL:
831 return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
832 case MSLIDE:
833 return new CSSPrimitiveValueImpl(CSS_VAL_SLIDE);
834 case MALTERNATE:
835 return new CSSPrimitiveValueImpl(CSS_VAL_ALTERNATE);
836 case MUNFURL:
837 return new CSSPrimitiveValueImpl(CSS_VAL_UNFURL);
839 Q_ASSERT(0);
840 return 0;
841 case CSS_PROP_MAX_HEIGHT:
842 RETURN_NULL_ON_NULL(renderer);
843 return new CSSPrimitiveValueImpl( renderer->availableHeight(),
844 CSSPrimitiveValue::CSS_PX );
845 break;
846 case CSS_PROP_MAX_WIDTH:
847 RETURN_NULL_ON_NULL(renderer);
848 return new CSSPrimitiveValueImpl( renderer->maxWidth(),
849 CSSPrimitiveValue::CSS_PX );
850 break;
851 case CSS_PROP_MIN_HEIGHT:
852 RETURN_NULL_ON_NULL(renderer);
853 return new CSSPrimitiveValueImpl( renderer->contentHeight(),
854 CSSPrimitiveValue::CSS_PX );
855 break;
856 case CSS_PROP_MIN_WIDTH:
857 RETURN_NULL_ON_NULL(renderer);
858 return new CSSPrimitiveValueImpl( renderer->minWidth(),
859 CSSPrimitiveValue::CSS_PX );
860 break;
861 case CSS_PROP_OPACITY:
862 return new CSSPrimitiveValueImpl(style->opacity(), CSSPrimitiveValue::CSS_NUMBER);
863 case CSS_PROP_ORPHANS:
864 return new CSSPrimitiveValueImpl(style->orphans(), CSSPrimitiveValue::CSS_NUMBER);
865 case CSS_PROP_OUTLINE_COLOR:
866 break;
867 case CSS_PROP_OUTLINE_OFFSET:
868 break;
869 case CSS_PROP_OUTLINE_STYLE:
870 if (style->outlineStyleIsAuto())
871 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
872 return valueForBorderStyle(style->outlineStyle());
873 case CSS_PROP_OUTLINE_WIDTH:
874 break;
875 case CSS_PROP_OVERFLOW:
876 case CSS_PROP_OVERFLOW_X:
877 case CSS_PROP_OVERFLOW_Y: {
878 EOverflow overflow;
879 switch (propertyID) {
880 case CSS_PROP_OVERFLOW_X:
881 overflow = style->overflowX();
882 break;
883 case CSS_PROP_OVERFLOW_Y:
884 overflow = style->overflowY();
885 break;
886 default:
887 overflow = qMax(style->overflowX(), style->overflowY());
889 switch (overflow) {
890 case OVISIBLE:
891 return new CSSPrimitiveValueImpl(CSS_VAL_VISIBLE);
892 case OHIDDEN:
893 return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
894 case OSCROLL:
895 return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
896 case OAUTO:
897 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
898 case OMARQUEE:
899 return new CSSPrimitiveValueImpl(CSS_VAL_MARQUEE);
901 Q_ASSERT(0);
902 return 0;
904 case CSS_PROP_PADDING_TOP:
905 if (renderer)
906 return new CSSPrimitiveValueImpl(renderer->paddingTop(), CSSPrimitiveValue::CSS_PX);
907 return valueForLength2(style->paddingTop());
908 case CSS_PROP_PADDING_RIGHT:
909 if (renderer)
910 return new CSSPrimitiveValueImpl(renderer->paddingRight(), CSSPrimitiveValue::CSS_PX);
911 return valueForLength2(style->paddingRight());
912 case CSS_PROP_PADDING_BOTTOM:
913 if (renderer)
914 return new CSSPrimitiveValueImpl(renderer->paddingBottom(), CSSPrimitiveValue::CSS_PX);
915 return valueForLength2(style->paddingBottom());
916 case CSS_PROP_PADDING_LEFT:
917 if (renderer)
918 return new CSSPrimitiveValueImpl(renderer->paddingLeft(), CSSPrimitiveValue::CSS_PX);
919 return valueForLength2(style->paddingLeft());
920 case CSS_PROP_PAGE_BREAK_AFTER:
921 switch (style->pageBreakAfter()) {
922 case PBAUTO:
923 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
924 case PBALWAYS:
925 return new CSSPrimitiveValueImpl(CSS_VAL_ALWAYS);
926 case PBAVOID:
927 return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
928 case PBLEFT:
929 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
930 case PBRIGHT:
931 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
933 Q_ASSERT(0);
934 break;
935 case CSS_PROP_PAGE_BREAK_BEFORE:
936 switch (style->pageBreakBefore()) {
937 case PBAUTO:
938 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
939 case PBALWAYS:
940 return new CSSPrimitiveValueImpl(CSS_VAL_ALWAYS);
941 case PBAVOID:
942 return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
943 case PBLEFT:
944 return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
945 case PBRIGHT:
946 return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
948 Q_ASSERT(0);
949 break;
950 case CSS_PROP_PAGE_BREAK_INSIDE:
951 if (style->pageBreakInside())
952 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
953 else
954 return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
955 Q_ASSERT(0);
956 break;
957 case CSS_PROP_POSITION:
958 switch (style->position()) {
959 case PSTATIC:
960 return new CSSPrimitiveValueImpl(CSS_VAL_STATIC);
961 case PRELATIVE:
962 return new CSSPrimitiveValueImpl(CSS_VAL_RELATIVE);
963 case PABSOLUTE:
964 return new CSSPrimitiveValueImpl(CSS_VAL_ABSOLUTE);
965 case PFIXED:
966 return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
968 Q_ASSERT(0);
969 break;
970 case CSS_PROP_QUOTES:
971 break;
972 case CSS_PROP_RIGHT:
973 RETURN_NULL_ON_NULL(renderer);
974 return getPositionOffsetValue(renderer, CSS_PROP_RIGHT);
975 case CSS_PROP_SIZE:
976 break;
977 case CSS_PROP_TABLE_LAYOUT:
978 switch (style->tableLayout()) {
979 case TAUTO:
980 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
981 case TFIXED:
982 return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
984 Q_ASSERT(0);
985 break;
986 case CSS_PROP_TEXT_ALIGN:
987 return valueForTextAlign(style->textAlign());
988 case CSS_PROP_TEXT_DECORATION:
990 QString string;
991 if (style->textDecoration() & khtml::UNDERLINE)
992 string += "underline";
993 if (style->textDecoration() & khtml::OVERLINE) {
994 if (string.length() > 0)
995 string += " ";
996 string += "overline";
998 if (style->textDecoration() & khtml::LINE_THROUGH) {
999 if (string.length() > 0)
1000 string += " ";
1001 string += "line-through";
1003 if (style->textDecoration() & khtml::BLINK) {
1004 if (string.length() > 0)
1005 string += " ";
1006 string += "blink";
1008 if (string.length() == 0)
1009 string = "none";
1010 return new CSSPrimitiveValueImpl(DOMString(string), CSSPrimitiveValue::CSS_STRING);
1012 case CSS_PROP_TEXT_INDENT:
1013 RETURN_NULL_ON_NULL(renderer);
1014 return valueForLength(style->textIndent(), renderer->contentWidth());
1015 case CSS_PROP_TEXT_SHADOW:
1016 return valueForShadow(style->textShadow());
1017 case CSS_PROP_TEXT_TRANSFORM:
1018 switch (style->textTransform()) {
1019 case CAPITALIZE:
1020 return new CSSPrimitiveValueImpl(CSS_VAL_CAPITALIZE);
1021 case UPPERCASE:
1022 return new CSSPrimitiveValueImpl(CSS_VAL_UPPERCASE);
1023 case LOWERCASE:
1024 return new CSSPrimitiveValueImpl(CSS_VAL_LOWERCASE);
1025 case TTNONE:
1026 return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
1028 Q_ASSERT(0);
1029 break;
1030 case CSS_PROP_TOP:
1031 RETURN_NULL_ON_NULL(renderer);
1032 return getPositionOffsetValue(renderer, CSS_PROP_TOP);
1033 case CSS_PROP_UNICODE_BIDI:
1034 switch (style->unicodeBidi()) {
1035 case UBNormal:
1036 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1037 case Embed:
1038 return new CSSPrimitiveValueImpl(CSS_VAL_EMBED);
1039 case Override:
1040 return new CSSPrimitiveValueImpl(CSS_VAL_BIDI_OVERRIDE);
1042 Q_ASSERT(0);
1043 break;
1044 case CSS_PROP_VERTICAL_ALIGN:
1046 switch (style->verticalAlign()) {
1047 case BASELINE:
1048 return new CSSPrimitiveValueImpl(CSS_VAL_BASELINE);
1049 case MIDDLE:
1050 return new CSSPrimitiveValueImpl(CSS_VAL_MIDDLE);
1051 case SUB:
1052 return new CSSPrimitiveValueImpl(CSS_VAL_SUB);
1053 case SUPER:
1054 return new CSSPrimitiveValueImpl(CSS_VAL_SUPER);
1055 case TEXT_TOP:
1056 return new CSSPrimitiveValueImpl(CSS_VAL_TEXT_TOP);
1057 case TEXT_BOTTOM:
1058 return new CSSPrimitiveValueImpl(CSS_VAL_TEXT_BOTTOM);
1059 case TOP:
1060 return new CSSPrimitiveValueImpl(CSS_VAL_TOP);
1061 case BOTTOM:
1062 return new CSSPrimitiveValueImpl(CSS_VAL_BOTTOM);
1063 case BASELINE_MIDDLE:
1064 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_BASELINE_MIDDLE);
1065 case LENGTH:
1066 RETURN_NULL_ON_NULL(renderer);
1067 return valueForLength(style->verticalAlignLength(), renderer->contentWidth());
1069 Q_ASSERT(0);
1070 break;
1072 case CSS_PROP_VISIBILITY:
1073 switch (style->visibility()) {
1074 case khtml::VISIBLE:
1075 return new CSSPrimitiveValueImpl(CSS_VAL_VISIBLE);
1076 case khtml::HIDDEN:
1077 return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
1078 case khtml::COLLAPSE:
1079 return new CSSPrimitiveValueImpl(CSS_VAL_COLLAPSE);
1081 Q_ASSERT(0);
1082 break;
1083 case CSS_PROP_WHITE_SPACE:
1085 switch (style->whiteSpace()) {
1086 case NORMAL:
1087 return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1088 case PRE:
1089 return new CSSPrimitiveValueImpl(CSS_VAL_PRE);
1090 case PRE_WRAP:
1091 return new CSSPrimitiveValueImpl(CSS_VAL_PRE_WRAP);
1092 case PRE_LINE:
1093 return new CSSPrimitiveValueImpl(CSS_VAL_PRE_LINE);
1094 case NOWRAP:
1095 return new CSSPrimitiveValueImpl(CSS_VAL_NOWRAP);
1096 case KHTML_NOWRAP:
1097 return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_NOWRAP);
1099 Q_ASSERT(0);
1100 break;
1102 case CSS_PROP_WIDOWS:
1103 return new CSSPrimitiveValueImpl(style->widows(), CSSPrimitiveValue::CSS_NUMBER);
1104 case CSS_PROP_WIDTH:
1105 if (renderer)
1106 return new CSSPrimitiveValueImpl(renderer->contentWidth(),
1107 CSSPrimitiveValue::CSS_PX);
1108 return valueForLength2(style->width());
1109 case CSS_PROP_WORD_SPACING:
1110 return new CSSPrimitiveValueImpl(style->wordSpacing(), CSSPrimitiveValue::CSS_PX);
1111 case CSS_PROP_Z_INDEX:
1112 if (style->hasAutoZIndex())
1113 return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
1114 return new CSSPrimitiveValueImpl(style->zIndex(), CSSPrimitiveValue::CSS_NUMBER);
1115 case CSS_PROP_BACKGROUND:
1116 break;
1117 case CSS_PROP_BORDER:
1118 break;
1119 case CSS_PROP_BORDER_COLOR:
1120 break;
1121 case CSS_PROP_BORDER_STYLE:
1122 break;
1123 case CSS_PROP_BORDER_TOP:
1124 RETURN_NULL_ON_NULL(renderer);
1125 return new CSSPrimitiveValueImpl( renderer->borderTop(),
1126 CSSPrimitiveValue::CSS_PX );
1127 break;
1128 case CSS_PROP_BORDER_RIGHT:
1129 RETURN_NULL_ON_NULL(renderer);
1130 return new CSSPrimitiveValueImpl( renderer->borderRight(),
1131 CSSPrimitiveValue::CSS_PX );
1132 break;
1133 case CSS_PROP_BORDER_BOTTOM:
1134 RETURN_NULL_ON_NULL(renderer);
1135 return new CSSPrimitiveValueImpl( renderer->borderBottom(),
1136 CSSPrimitiveValue::CSS_PX );
1137 break;
1138 case CSS_PROP_BORDER_LEFT:
1139 RETURN_NULL_ON_NULL(renderer);
1140 return new CSSPrimitiveValueImpl( renderer->borderLeft(),
1141 CSSPrimitiveValue::CSS_PX );
1142 break;
1143 case CSS_PROP_BORDER_WIDTH:
1144 break;
1145 case CSS_PROP_FONT:
1146 break;
1147 case CSS_PROP_LIST_STYLE:
1148 break;
1149 case CSS_PROP_MARGIN:
1150 break;
1151 case CSS_PROP_OUTLINE:
1152 break;
1153 case CSS_PROP_PADDING:
1154 break;
1155 case CSS_PROP_SCROLLBAR_BASE_COLOR:
1156 break;
1157 case CSS_PROP_SCROLLBAR_FACE_COLOR:
1158 break;
1159 case CSS_PROP_SCROLLBAR_SHADOW_COLOR:
1160 break;
1161 case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR:
1162 break;
1163 case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR:
1164 break;
1165 case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR:
1166 break;
1167 case CSS_PROP_SCROLLBAR_TRACK_COLOR:
1168 break;
1169 case CSS_PROP_SCROLLBAR_ARROW_COLOR:
1170 break;
1171 case CSS_PROP__KHTML_FLOW_MODE:
1172 break;
1173 case CSS_PROP__KHTML_USER_INPUT:
1174 break;
1175 case CSS_PROP_TEXT_OVERFLOW:
1176 if (style->textOverflow())
1177 return new CSSPrimitiveValueImpl(CSS_VAL_ELLIPSIS);
1178 else
1179 return new CSSPrimitiveValueImpl(CSS_VAL_CLIP);
1180 break;
1181 default:
1182 kWarning() << "Unhandled property:" << getPropertyName(propertyID);
1183 Q_ASSERT( 0 );
1184 break;
1186 return 0;
1189 #undef RETURN_NULL_ON_NULL
1191 DOMString RenderStyleDeclarationImpl::getPropertyValue( int propertyID ) const
1193 CSSValueImpl* value = getPropertyCSSValue(propertyID);
1194 if (value) {
1195 DOMString val = value->cssText();
1196 delete value;
1197 return val;
1199 return "";
1202 bool RenderStyleDeclarationImpl::getPropertyPriority( int ) const
1204 // All computed styles have a priority of false (not "important").
1205 return false;
1208 void RenderStyleDeclarationImpl::removeProperty(int, DOM::DOMString*)
1210 // ### emit error since we're read-only
1213 void RenderStyleDeclarationImpl::removePropertiesInSet(const int* set, unsigned length)
1215 // ### emit error since we're read-only
1218 bool RenderStyleDeclarationImpl::setProperty ( int, const DOM::DOMString &, bool, int &ec)
1220 ec = DOMException::NO_MODIFICATION_ALLOWED_ERR;
1221 return false;
1224 bool RenderStyleDeclarationImpl::setProperty ( int, const DOM::DOMString&, bool )
1226 // ### emit error since we're read-only
1227 return false;
1230 void RenderStyleDeclarationImpl::setProperty ( int, int, bool )
1232 // ### emit error since we're read-only
1235 void RenderStyleDeclarationImpl::setLengthProperty( int, const DOM::DOMString&, bool,
1236 bool )
1238 // ### emit error since we're read-only
1241 void RenderStyleDeclarationImpl::setProperty( const DOMString& )
1243 // ### emit error since we're read-only
1246 unsigned long RenderStyleDeclarationImpl::length() const
1248 return numComputedProperties;
1251 DOM::DOMString RenderStyleDeclarationImpl::item( unsigned long i ) const
1253 if (i >= numComputedProperties)
1254 return DOMString();
1256 return getPropertyName(computedProperties[i]);
1259 CSSProperty RenderStyleDeclarationImpl::property( int id ) const
1261 CSSProperty prop;
1262 prop.m_id = id;
1263 prop.m_important = false;
1265 CSSValueImpl* v = getPropertyCSSValue( id );
1266 if ( !v )
1267 v = new CSSPrimitiveValueImpl;
1268 prop.setValue( v );
1269 return prop;