css_renderstyledeclarationimpl.cpp 46.6 KB
Newer Older
George Staikos's avatar
George Staikos committed
1 2 3
/**
 * css_renderstyledeclarationimpl.cpp
 *
4 5
 * Copyright 2004  Zack Rusin <zack@kde.org>
 * Copyright 2004,2005 Apple Computer, Inc.
George Staikos's avatar
George Staikos committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */
#include "css_renderstyledeclarationimpl.h"

#include "rendering/render_style.h"
#include "rendering/render_object.h"

#include "cssproperties.h"
Maks Orlovich's avatar
Maks Orlovich committed
28
#include "cssvalues.h"
George Staikos's avatar
George Staikos committed
29

30 31
#include <dom/dom_exception.h>

George Staikos's avatar
George Staikos committed
32 33 34
using namespace DOM;
using namespace khtml;

Maks Orlovich's avatar
Maks Orlovich committed
35 36 37
// List of all properties we know how to compute, omitting shorthands.
static const int computedProperties[] = {
    CSS_PROP_BACKGROUND_COLOR,
38
    CSS_PROP_BACKGROUND_CLIP,
Maks Orlovich's avatar
Maks Orlovich committed
39 40 41 42 43 44 45 46 47 48
    CSS_PROP_BACKGROUND_IMAGE,
    CSS_PROP_BACKGROUND_REPEAT,
    CSS_PROP_BACKGROUND_ATTACHMENT,
    CSS_PROP_BACKGROUND_POSITION,
    CSS_PROP_BACKGROUND_POSITION_X,
    CSS_PROP_BACKGROUND_POSITION_Y,
    CSS_PROP_BORDER_COLLAPSE,
    CSS_PROP_BORDER_SPACING,
    CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING,
    CSS_PROP__KHTML_BORDER_VERTICAL_SPACING,
49 50 51 52
    CSS_PROP__KHTML_BORDER_TOP_RIGHT_RADIUS,
    CSS_PROP__KHTML_BORDER_BOTTOM_RIGHT_RADIUS,
    CSS_PROP__KHTML_BORDER_BOTTOM_LEFT_RADIUS,
    CSS_PROP__KHTML_BORDER_TOP_LEFT_RADIUS,
53 54 55 56
    CSS_PROP_BORDER_TOP_RIGHT_RADIUS,
    CSS_PROP_BORDER_BOTTOM_RIGHT_RADIUS,
    CSS_PROP_BORDER_BOTTOM_LEFT_RADIUS,
    CSS_PROP_BORDER_TOP_LEFT_RADIUS,
Maks Orlovich's avatar
Maks Orlovich committed
57 58 59 60 61 62 63 64 65 66 67 68 69
    CSS_PROP_BORDER_TOP_COLOR,
    CSS_PROP_BORDER_RIGHT_COLOR,
    CSS_PROP_BORDER_BOTTOM_COLOR,
    CSS_PROP_BORDER_LEFT_COLOR,
    CSS_PROP_BORDER_TOP_STYLE,
    CSS_PROP_BORDER_RIGHT_STYLE,
    CSS_PROP_BORDER_BOTTOM_STYLE,
    CSS_PROP_BORDER_LEFT_STYLE,
    CSS_PROP_BORDER_TOP_WIDTH,
    CSS_PROP_BORDER_RIGHT_WIDTH,
    CSS_PROP_BORDER_BOTTOM_WIDTH,
    CSS_PROP_BORDER_LEFT_WIDTH,
    CSS_PROP_BOTTOM,
Maks Orlovich's avatar
Maks Orlovich committed
70
    CSS_PROP_BOX_SIZING,
Maks Orlovich's avatar
Maks Orlovich committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    CSS_PROP_CAPTION_SIDE,
    CSS_PROP_CLEAR,
    CSS_PROP_COLOR,
    CSS_PROP_CURSOR,
    CSS_PROP_DIRECTION,
    CSS_PROP_DISPLAY,
    CSS_PROP_EMPTY_CELLS,
    CSS_PROP_FLOAT,
    CSS_PROP_FONT_FAMILY,
    CSS_PROP_FONT_SIZE,
    CSS_PROP_FONT_STYLE,
    CSS_PROP_FONT_VARIANT,
    CSS_PROP_FONT_WEIGHT,
    CSS_PROP_HEIGHT,
    CSS_PROP_LEFT,
    CSS_PROP_LETTER_SPACING,
    CSS_PROP_LINE_HEIGHT,
    CSS_PROP_LIST_STYLE_IMAGE,
    CSS_PROP_LIST_STYLE_POSITION,
    CSS_PROP_LIST_STYLE_TYPE,
    CSS_PROP_MARGIN_TOP,
    CSS_PROP_MARGIN_RIGHT,
    CSS_PROP_MARGIN_BOTTOM,
    CSS_PROP_MARGIN_LEFT,
    CSS_PROP__KHTML_MARQUEE_DIRECTION,
    CSS_PROP__KHTML_MARQUEE_INCREMENT,
    CSS_PROP__KHTML_MARQUEE_REPETITION,
    CSS_PROP__KHTML_MARQUEE_STYLE,
    CSS_PROP_MAX_HEIGHT,
    CSS_PROP_MAX_WIDTH,
    CSS_PROP_MIN_HEIGHT,
    CSS_PROP_MIN_WIDTH,
    CSS_PROP_OPACITY,
    CSS_PROP_ORPHANS,
    CSS_PROP_OUTLINE_STYLE,
    CSS_PROP_OVERFLOW,
Germain Garand's avatar
Germain Garand committed
107 108
    CSS_PROP_OVERFLOW_X,
    CSS_PROP_OVERFLOW_Y,
Maks Orlovich's avatar
Maks Orlovich committed
109 110 111 112 113 114 115 116 117 118 119 120 121
    CSS_PROP_PADDING_TOP,
    CSS_PROP_PADDING_RIGHT,
    CSS_PROP_PADDING_BOTTOM,
    CSS_PROP_PADDING_LEFT,
    CSS_PROP_PAGE_BREAK_AFTER,
    CSS_PROP_PAGE_BREAK_BEFORE,
    CSS_PROP_PAGE_BREAK_INSIDE,
    CSS_PROP_POSITION,
    CSS_PROP_RIGHT,
    CSS_PROP_TABLE_LAYOUT,
    CSS_PROP_TEXT_ALIGN,
    CSS_PROP_TEXT_DECORATION,
    CSS_PROP_TEXT_INDENT,
Maks Orlovich's avatar
Maks Orlovich committed
122
    CSS_PROP_TEXT_OVERFLOW,    
Maks Orlovich's avatar
Maks Orlovich committed
123 124 125 126 127 128 129 130 131 132
    CSS_PROP_TEXT_SHADOW,
    CSS_PROP_TEXT_TRANSFORM,
    CSS_PROP_TOP,
    CSS_PROP_UNICODE_BIDI,
    CSS_PROP_VERTICAL_ALIGN,
    CSS_PROP_VISIBILITY,
    CSS_PROP_WHITE_SPACE,
    CSS_PROP_WIDOWS,
    CSS_PROP_WIDTH,
    CSS_PROP_WORD_SPACING,
Maks Orlovich's avatar
Maks Orlovich committed
133
    CSS_PROP_Z_INDEX
Maks Orlovich's avatar
Maks Orlovich committed
134 135 136 137
};

const unsigned numComputedProperties = sizeof(computedProperties) / sizeof(computedProperties[0]);

George Staikos's avatar
George Staikos committed
138 139 140 141

static CSSValueImpl *valueForLength(const Length &length, int max)
{
    if (length.isPercent()) {
142
        return new CSSPrimitiveValueImpl(length.percent(), CSSPrimitiveValue::CSS_PERCENTAGE);
George Staikos's avatar
George Staikos committed
143 144 145 146 147 148
    }
    else {
        return new CSSPrimitiveValueImpl(length.minWidth(max), CSSPrimitiveValue::CSS_PX);
    }
}

149 150 151
static CSSValueImpl *valueForLength2(const Length &length)
{
    if (length.isPercent()) {
152
        return new CSSPrimitiveValueImpl(length.percent(), CSSPrimitiveValue::CSS_PERCENTAGE);
153 154 155 156 157 158
    }
    else {
        return new CSSPrimitiveValueImpl(length.value(), CSSPrimitiveValue::CSS_PX);
    }
}

Maks Orlovich's avatar
Maks Orlovich committed
159
static CSSValueImpl *valueForBorderStyle(EBorderStyle style)
George Staikos's avatar
George Staikos committed
160 161 162
{
    switch (style) {
    case khtml::BNATIVE:
Maks Orlovich's avatar
Maks Orlovich committed
163
        return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_NATIVE);
George Staikos's avatar
George Staikos committed
164
    case khtml::BNONE:
Maks Orlovich's avatar
Maks Orlovich committed
165
        return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
George Staikos's avatar
George Staikos committed
166
    case khtml::BHIDDEN:
Maks Orlovich's avatar
Maks Orlovich committed
167
        return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
George Staikos's avatar
George Staikos committed
168
    case khtml::INSET:
Maks Orlovich's avatar
Maks Orlovich committed
169
        return new CSSPrimitiveValueImpl(CSS_VAL_INSET);
George Staikos's avatar
George Staikos committed
170
    case khtml::GROOVE:
Maks Orlovich's avatar
Maks Orlovich committed
171
        return new CSSPrimitiveValueImpl(CSS_VAL_GROOVE);
George Staikos's avatar
George Staikos committed
172
    case khtml::RIDGE:
Maks Orlovich's avatar
Maks Orlovich committed
173
         return new CSSPrimitiveValueImpl(CSS_VAL_RIDGE);
George Staikos's avatar
George Staikos committed
174
    case khtml::OUTSET:
Maks Orlovich's avatar
Maks Orlovich committed
175
        return new CSSPrimitiveValueImpl(CSS_VAL_OUTSET);
George Staikos's avatar
George Staikos committed
176
    case khtml::DOTTED:
Maks Orlovich's avatar
Maks Orlovich committed
177
        return new CSSPrimitiveValueImpl(CSS_VAL_DOTTED);
George Staikos's avatar
George Staikos committed
178
    case khtml::DASHED:
Maks Orlovich's avatar
Maks Orlovich committed
179
        return new CSSPrimitiveValueImpl(CSS_VAL_DASHED);
George Staikos's avatar
George Staikos committed
180
    case khtml::SOLID:
Maks Orlovich's avatar
Maks Orlovich committed
181
        return new CSSPrimitiveValueImpl(CSS_VAL_SOLID);
George Staikos's avatar
George Staikos committed
182
    case khtml::DOUBLE:
Maks Orlovich's avatar
Maks Orlovich committed
183
        return new CSSPrimitiveValueImpl(CSS_VAL_DOUBLE);
George Staikos's avatar
George Staikos committed
184 185
    }
    Q_ASSERT( 0 );
Maks Orlovich's avatar
Maks Orlovich committed
186
    return 0;
George Staikos's avatar
George Staikos committed
187 188
}

189 190 191 192 193 194 195
static CSSValueImpl *valueForBorderRadii(BorderRadii radii)
{
    CSSPrimitiveValueImpl* h = new CSSPrimitiveValueImpl(radii.horizontal, CSSPrimitiveValue::CSS_PX);
    CSSPrimitiveValueImpl* v = new CSSPrimitiveValueImpl(radii.vertical, CSSPrimitiveValue::CSS_PX);
    return new CSSPrimitiveValueImpl(new PairImpl(h, v));
}

Maks Orlovich's avatar
Maks Orlovich committed
196
static CSSValueImpl *valueForTextAlign(ETextAlign align)
George Staikos's avatar
George Staikos committed
197 198 199
{
    switch (align) {
    case khtml::TAAUTO:
Maks Orlovich's avatar
Maks Orlovich committed
200
        return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
George Staikos's avatar
George Staikos committed
201
    case khtml::LEFT:
Maks Orlovich's avatar
Maks Orlovich committed
202
        return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
George Staikos's avatar
George Staikos committed
203
    case khtml::RIGHT:
Maks Orlovich's avatar
Maks Orlovich committed
204
        return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
George Staikos's avatar
George Staikos committed
205
    case khtml::CENTER:
Maks Orlovich's avatar
Maks Orlovich committed
206
        return new CSSPrimitiveValueImpl(CSS_VAL_CENTER);
George Staikos's avatar
George Staikos committed
207
    case khtml::JUSTIFY:
Maks Orlovich's avatar
Maks Orlovich committed
208
        return new CSSPrimitiveValueImpl(CSS_VAL_JUSTIFY);
George Staikos's avatar
George Staikos committed
209
    case khtml::KHTML_LEFT:
Maks Orlovich's avatar
Maks Orlovich committed
210
        return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_LEFT);
George Staikos's avatar
George Staikos committed
211
    case khtml::KHTML_RIGHT:
Maks Orlovich's avatar
Maks Orlovich committed
212
        return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_RIGHT);
George Staikos's avatar
George Staikos committed
213
    case khtml::KHTML_CENTER:
Maks Orlovich's avatar
Maks Orlovich committed
214
        return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_CENTER);
George Staikos's avatar
George Staikos committed
215 216
    }
    Q_ASSERT( 0 );
Maks Orlovich's avatar
Maks Orlovich committed
217
    return 0;
George Staikos's avatar
George Staikos committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
}

DOMString khtml::stringForListStyleType(EListStyleType type)
{
    switch (type) {
        case khtml::LDISC:
            return "disc";
        case khtml::LCIRCLE:
            return "circle";
        case khtml::LSQUARE:
            return "square";
        case khtml::LBOX:
            return "box";
        case khtml::LDIAMOND:
            return "-khtml-diamond";
        case khtml::LDECIMAL:
            return "decimal";
        case khtml::DECIMAL_LEADING_ZERO:
            return "decimal-leading-zero";
        case khtml::ARABIC_INDIC:
            return "-khtml-arabic-indic";
        case khtml::LAO:
            return "-khtml-lao";
        case khtml::PERSIAN:
            return "-khtml-persian";
        case khtml::URDU:
            return "-khtml-urdu";
        case khtml::THAI:
            return "-khtml-thai";
        case khtml::TIBETAN:
            return "-khtml-tibetan";
        case khtml::LOWER_ROMAN:
            return "lower-roman";
        case khtml::UPPER_ROMAN:
            return "upper-roman";
        case khtml::HEBREW:
            return "hebrew";
        case khtml::ARMENIAN:
            return "armenian";
        case khtml::GEORGIAN:
            return "georgian";
        case khtml::CJK_IDEOGRAPHIC:
            return "cjk-ideographic";
        case khtml::JAPANESE_FORMAL:
            return "-khtml-japanese-formal";
        case khtml::JAPANESE_INFORMAL:
            return "-khtml-japanese-informal";
        case khtml::SIMP_CHINESE_FORMAL:
            return "-khtml-simp-chinese-formal";
        case khtml::SIMP_CHINESE_INFORMAL:
            return "-khtml-simp-chinese-informal";
        case khtml::TRAD_CHINESE_FORMAL:
            return "-khtml-trad-chinese-formal";
        case khtml::TRAD_CHINESE_INFORMAL:
            return "-khtml-trad-chinese-informal";
        case khtml::LOWER_GREEK:
            return "lower-greek";
        case khtml::UPPER_GREEK:
            return "-khtml-upper-greek";
        case khtml::LOWER_ALPHA:
            return "lower-alpha";
        case khtml::UPPER_ALPHA:
            return "upper-alpha";
        case khtml::LOWER_LATIN:
            return "lower-latin";
        case khtml::UPPER_LATIN:
            return "upper-latin";
        case khtml::HIRAGANA:
            return "hiragana";
        case khtml::KATAKANA:
            return "katakana";
        case khtml::HIRAGANA_IROHA:
            return "hiragana-iroha";
        case khtml::KATAKANA_IROHA:
            return "katakana_iroha";
        case khtml::LNONE:
            return "none";
    }
    Q_ASSERT( 0 );
    return "";
}

300 301 302
static CSSPrimitiveValueImpl* valueForColor(QColor color)
{
    if (color.isValid())
Germain Garand's avatar
Germain Garand committed
303
        return new CSSPrimitiveValueImpl(color.rgba());
304 305 306 307
    else
        return new CSSPrimitiveValueImpl(khtml::transparentColor);
}

Maks Orlovich's avatar
Maks Orlovich committed
308 309 310 311
static CSSValueImpl* valueForShadow(const ShadowData *shadow)
{
    if (!shadow)
        return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
312
    CSSValueListImpl *list = new CSSValueListImpl(CSSValueListImpl::Comma);
Maks Orlovich's avatar
Maks Orlovich committed
313 314 315 316
    for (const ShadowData *s = shadow; s; s = s->next) {
        CSSPrimitiveValueImpl *x = new CSSPrimitiveValueImpl(s->x, CSSPrimitiveValue::CSS_PX);
        CSSPrimitiveValueImpl *y = new CSSPrimitiveValueImpl(s->y, CSSPrimitiveValue::CSS_PX);
        CSSPrimitiveValueImpl *blur = new CSSPrimitiveValueImpl(s->blur, CSSPrimitiveValue::CSS_PX);
317
        CSSPrimitiveValueImpl *color = valueForColor(s->color);
Maks Orlovich's avatar
Maks Orlovich committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
        list->append(new ShadowValueImpl(x, y, blur, color));
    }
    return list;
}

static CSSValueImpl *getPositionOffsetValue(RenderObject *renderer, int propertyID)
{
    if (!renderer)
        return 0;

    RenderStyle *style = renderer->style();
    if (!style)
        return 0;

    Length l;
    switch (propertyID) {
    case CSS_PROP_LEFT:
        l = style->left();
        break;
    case CSS_PROP_RIGHT:
        l = style->right();
        break;
    case CSS_PROP_TOP:
        l = style->top();
        break;
    case CSS_PROP_BOTTOM:
        l = style->bottom();
        break;
    default:
        return 0;
    }

    if (renderer->isPositioned())
        return valueForLength(l, renderer->contentWidth());
352

Maks Orlovich's avatar
Maks Orlovich committed
353 354 355 356 357
    if (renderer->isRelPositioned())
        // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined.
        // In other words if left is auto and right is not auto, then left's computed value is negative right.
        // So we should get the opposite length unit and see if it is auto.
        return valueForLength(l, renderer->contentWidth());
358

Maks Orlovich's avatar
Maks Orlovich committed
359 360 361
    return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
 }

George Staikos's avatar
George Staikos committed
362 363 364
RenderStyleDeclarationImpl::RenderStyleDeclarationImpl( DOM::NodeImpl *node )
    : CSSStyleDeclarationImpl(0), m_node(node)
{
Laurent Montel's avatar
Laurent Montel committed
365
    //kDebug() << "Render Style Declaration created";
George Staikos's avatar
George Staikos committed
366 367 368 369
}

RenderStyleDeclarationImpl::~RenderStyleDeclarationImpl()
{
Laurent Montel's avatar
Laurent Montel committed
370
    //kDebug() << "Render Style Declaration destroyed";
George Staikos's avatar
George Staikos committed
371 372 373 374
}

DOM::DOMString RenderStyleDeclarationImpl::cssText() const
{
Maks Orlovich's avatar
Maks Orlovich committed
375 376 377 378
    DOMString result;

    for (unsigned i = 0; i < numComputedProperties; i++) {
        if (i != 0)
379
            result += " ";
Maks Orlovich's avatar
Maks Orlovich committed
380 381 382
        result += getPropertyName(computedProperties[i]);
        result += ": ";
        result += getPropertyValue(computedProperties[i]);
383
        result += ";";
Maks Orlovich's avatar
Maks Orlovich committed
384 385 386
    }

    return result;
George Staikos's avatar
George Staikos committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400
}

void RenderStyleDeclarationImpl::setCssText( DOM::DOMString )
{
    // ### report that this sucka is read only
}

CSSValueImpl *RenderStyleDeclarationImpl::getPropertyCSSValue( int propertyID ) const
{
    NodeImpl *node = m_node.get();
    if (!node)
        return 0;

    // Make sure our layout is up to date before we allow a query on these attributes.
401
    DocumentImpl* docimpl = node->document();
George Staikos's avatar
George Staikos committed
402 403 404 405
    if (docimpl) {
        docimpl->updateLayout();
    }

406
    RenderStyle *style = node->computedStyle();
George Staikos's avatar
George Staikos committed
407 408
    if (!style)
        return 0;
409 410 411 412 413
    RenderObject *renderer = node->renderer(); // can be NULL

    // temporary(?) measure to handle with missing render object
    // check how we can better deal with it on a case-by-case basis
#define RETURN_NULL_ON_NULL(ptr) if(ptr == 0) return 0;
George Staikos's avatar
George Staikos committed
414 415 416 417

    switch(propertyID)
    {
    case CSS_PROP_BACKGROUND_COLOR:
418
        return valueForColor(style->backgroundColor());
419 420 421 422 423 424 425 426 427 428 429
    case CSS_PROP_BACKGROUND_CLIP:
        switch (style->backgroundLayers()->backgroundClip()) {
            case BGBORDER:
                return new CSSPrimitiveValueImpl(CSS_VAL_BORDER_BOX);
            case BGPADDING:
                return new CSSPrimitiveValueImpl(CSS_VAL_PADDING_BOX);
            case BGCONTENT:
                return new CSSPrimitiveValueImpl(CSS_VAL_CONTENT_BOX);
        }
        Q_ASSERT(0);
        break;
George Staikos's avatar
George Staikos committed
430 431 432 433
    case CSS_PROP_BACKGROUND_IMAGE:
        if (style->backgroundImage())
            return new CSSPrimitiveValueImpl(style->backgroundImage()->url(),
                                             CSSPrimitiveValue::CSS_URI);
Maks Orlovich's avatar
Maks Orlovich committed
434
        return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
George Staikos's avatar
George Staikos committed
435 436 437
    case CSS_PROP_BACKGROUND_REPEAT:
        switch (style->backgroundRepeat()) {
        case khtml::REPEAT:
Maks Orlovich's avatar
Maks Orlovich committed
438
            return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT);
George Staikos's avatar
George Staikos committed
439
        case khtml::REPEAT_X:
Maks Orlovich's avatar
Maks Orlovich committed
440
            return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT_X);
George Staikos's avatar
George Staikos committed
441
        case khtml::REPEAT_Y:
Maks Orlovich's avatar
Maks Orlovich committed
442
            return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT_Y);
George Staikos's avatar
George Staikos committed
443
        case khtml::NO_REPEAT:
Maks Orlovich's avatar
Maks Orlovich committed
444
            return new CSSPrimitiveValueImpl(CSS_VAL_NO_REPEAT);
George Staikos's avatar
George Staikos committed
445 446 447
        default:
            Q_ASSERT( 0 );
        }
448
        break;
George Staikos's avatar
George Staikos committed
449
    case CSS_PROP_BACKGROUND_ATTACHMENT:
450 451
        switch (style->backgroundAttachment()) {
        case khtml::BGASCROLL:
Maks Orlovich's avatar
Maks Orlovich committed
452
            return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
453
        case khtml::BGAFIXED:
Maks Orlovich's avatar
Maks Orlovich committed
454
            return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
455 456 457 458
        case khtml::BGALOCAL:
            return new CSSPrimitiveValueImpl(CSS_VAL_LOCAL);
        default:
            Q_ASSERT( 0 );
459 460
        }
        break;
George Staikos's avatar
George Staikos committed
461 462
    case CSS_PROP_BACKGROUND_POSITION:
    {
463
        RETURN_NULL_ON_NULL(renderer);
Andrea Iacovitti's avatar
Andrea Iacovitti committed
464
        QString string;
George Staikos's avatar
George Staikos committed
465 466
        Length length(style->backgroundXPosition());
        if (length.isPercent())
467
            string = QString(QString::number(length.percent()) + "%");
George Staikos's avatar
George Staikos committed
468
        else
469
            string = QString(QString::number(length.minWidth(renderer->contentWidth())) + "px");
470
        string += " ";
George Staikos's avatar
George Staikos committed
471 472
        length = style->backgroundYPosition();
        if (length.isPercent())
473
            string += QString(QString::number(length.percent()) + "%");
George Staikos's avatar
George Staikos committed
474
        else
475
            string += QString(QString::number(length.minWidth(renderer->contentWidth())) + "px");
Andrea Iacovitti's avatar
Andrea Iacovitti committed
476
        return new CSSPrimitiveValueImpl(DOMString(string), CSSPrimitiveValue::CSS_STRING);
George Staikos's avatar
George Staikos committed
477 478
    }
    case CSS_PROP_BACKGROUND_POSITION_X:
479
        RETURN_NULL_ON_NULL(renderer);
George Staikos's avatar
George Staikos committed
480 481
        return valueForLength(style->backgroundXPosition(), renderer->contentWidth());
    case CSS_PROP_BACKGROUND_POSITION_Y:
482
        RETURN_NULL_ON_NULL(renderer);
George Staikos's avatar
George Staikos committed
483 484 485
        return valueForLength(style->backgroundYPosition(), renderer->contentHeight());
    case CSS_PROP_BORDER_COLLAPSE:
        if (style->borderCollapse())
Maks Orlovich's avatar
Maks Orlovich committed
486
            return new CSSPrimitiveValueImpl(CSS_VAL_COLLAPSE);
George Staikos's avatar
George Staikos committed
487
        else
Maks Orlovich's avatar
Maks Orlovich committed
488
            return new CSSPrimitiveValueImpl(CSS_VAL_SEPARATE);
George Staikos's avatar
George Staikos committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502
    case CSS_PROP_BORDER_SPACING:
    {
        QString string(QString::number(style->borderHorizontalSpacing()) +
                       "px " +
                       QString::number(style->borderVerticalSpacing()) +
                       "px");
        return new CSSPrimitiveValueImpl(DOMString(string), CSSPrimitiveValue::CSS_STRING);
    }
    case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING:
        return new CSSPrimitiveValueImpl(style->borderHorizontalSpacing(),
                                         CSSPrimitiveValue::CSS_PX);
    case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING:
        return new CSSPrimitiveValueImpl(style->borderVerticalSpacing(),
                                         CSSPrimitiveValue::CSS_PX);
503
    case CSS_PROP__KHTML_BORDER_TOP_RIGHT_RADIUS:
504
    case CSS_PROP_BORDER_TOP_RIGHT_RADIUS:
505 506
	return valueForBorderRadii(style->borderTopRightRadius());
    case CSS_PROP__KHTML_BORDER_BOTTOM_RIGHT_RADIUS:
507
    case CSS_PROP_BORDER_BOTTOM_RIGHT_RADIUS:
508 509
	return valueForBorderRadii(style->borderBottomRightRadius());
    case CSS_PROP__KHTML_BORDER_BOTTOM_LEFT_RADIUS:
510
    case CSS_PROP_BORDER_BOTTOM_LEFT_RADIUS:
511 512
	return valueForBorderRadii(style->borderBottomLeftRadius());
    case CSS_PROP__KHTML_BORDER_TOP_LEFT_RADIUS:
513
    case CSS_PROP_BORDER_TOP_LEFT_RADIUS:
514
	return valueForBorderRadii(style->borderTopLeftRadius());
George Staikos's avatar
George Staikos committed
515
    case CSS_PROP_BORDER_TOP_COLOR:
516
        return valueForColor(style->borderTopColor());
George Staikos's avatar
George Staikos committed
517
    case CSS_PROP_BORDER_RIGHT_COLOR:
518
        return valueForColor(style->borderRightColor());
George Staikos's avatar
George Staikos committed
519
    case CSS_PROP_BORDER_BOTTOM_COLOR:
520
        return valueForColor(style->borderBottomColor());
George Staikos's avatar
George Staikos committed
521
    case CSS_PROP_BORDER_LEFT_COLOR:
522
        return valueForColor(style->borderLeftColor());
George Staikos's avatar
George Staikos committed
523
    case CSS_PROP_BORDER_TOP_STYLE:
Maks Orlovich's avatar
Maks Orlovich committed
524
        return valueForBorderStyle(style->borderTopStyle());
George Staikos's avatar
George Staikos committed
525
    case CSS_PROP_BORDER_RIGHT_STYLE:
Maks Orlovich's avatar
Maks Orlovich committed
526
        return valueForBorderStyle(style->borderRightStyle());
George Staikos's avatar
George Staikos committed
527
    case CSS_PROP_BORDER_BOTTOM_STYLE:
Maks Orlovich's avatar
Maks Orlovich committed
528
        return valueForBorderStyle(style->borderBottomStyle());
George Staikos's avatar
George Staikos committed
529
    case CSS_PROP_BORDER_LEFT_STYLE:
Maks Orlovich's avatar
Maks Orlovich committed
530
        return valueForBorderStyle(style->borderLeftStyle());
George Staikos's avatar
George Staikos committed
531 532 533 534 535 536 537 538 539
    case CSS_PROP_BORDER_TOP_WIDTH:
        return new CSSPrimitiveValueImpl( style->borderTopWidth(), CSSPrimitiveValue::CSS_PX );
    case CSS_PROP_BORDER_RIGHT_WIDTH:
        return new CSSPrimitiveValueImpl( style->borderRightWidth(), CSSPrimitiveValue::CSS_PX );
    case CSS_PROP_BORDER_BOTTOM_WIDTH:
        return new CSSPrimitiveValueImpl( style->borderBottomWidth(), CSSPrimitiveValue::CSS_PX );
    case CSS_PROP_BORDER_LEFT_WIDTH:
        return new CSSPrimitiveValueImpl( style->borderLeftWidth(), CSSPrimitiveValue::CSS_PX );
    case CSS_PROP_BOTTOM:
540
        RETURN_NULL_ON_NULL(renderer);
Maks Orlovich's avatar
Maks Orlovich committed
541
        return getPositionOffsetValue(renderer, CSS_PROP_BOTTOM);
Maks Orlovich's avatar
Maks Orlovich committed
542 543 544 545 546
    case CSS_PROP_BOX_SIZING:
        if (style->boxSizing() == BORDER_BOX)
            return new CSSPrimitiveValueImpl(CSS_VAL_BORDER_BOX);
        else
            return new CSSPrimitiveValueImpl(CSS_VAL_CONTENT_BOX);
George Staikos's avatar
George Staikos committed
547
    case CSS_PROP_CAPTION_SIDE:
Maks Orlovich's avatar
Maks Orlovich committed
548 549 550 551 552 553 554 555 556 557 558
        switch (style->captionSide()) {
        case CAPLEFT:
            return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
        case CAPRIGHT:
            return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
        case CAPTOP:
            return new CSSPrimitiveValueImpl(CSS_VAL_TOP);
        case CAPBOTTOM:
            return new CSSPrimitiveValueImpl(CSS_VAL_BOTTOM);
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
559 560
        break;
    case CSS_PROP_CLEAR:
Maks Orlovich's avatar
Maks Orlovich committed
561 562 563 564 565 566 567 568 569 570 571
        switch (style->clear()) {
        case CNONE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
        case CLEFT:
            return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
        case CRIGHT:
            return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
        case CBOTH:
            return new CSSPrimitiveValueImpl(CSS_VAL_BOTH);
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
572 573 574 575
        break;
    case CSS_PROP_CLIP:
        break;
    case CSS_PROP_COLOR:
576
        return valueForColor(style->color());
George Staikos's avatar
George Staikos committed
577 578 579 580 581 582 583
    case CSS_PROP_CONTENT:
        break;
    case CSS_PROP_COUNTER_INCREMENT:
        break;
    case CSS_PROP_COUNTER_RESET:
        break;
    case CSS_PROP_CURSOR:
Maks Orlovich's avatar
Maks Orlovich committed
584 585 586 587 588
        switch (style->cursor()) {
        case CURSOR_AUTO:
            return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
        case CURSOR_DEFAULT:
            return new CSSPrimitiveValueImpl(CSS_VAL_DEFAULT);
589 590 591 592 593 594
        case CURSOR_NONE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
        case CURSOR_CONTEXT_MENU:
            return new CSSPrimitiveValueImpl(CSS_VAL_CONTEXT_MENU);
        case CURSOR_HELP:
            return new CSSPrimitiveValueImpl(CSS_VAL_HELP);
Maks Orlovich's avatar
Maks Orlovich committed
595 596 597 598
        case CURSOR_POINTER:
            return new CSSPrimitiveValueImpl(CSS_VAL_POINTER);
        case CURSOR_PROGRESS:
            return new CSSPrimitiveValueImpl(CSS_VAL_PROGRESS);
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
        case CURSOR_WAIT:
            return new CSSPrimitiveValueImpl(CSS_VAL_WAIT);
        case CURSOR_CELL:
            return new CSSPrimitiveValueImpl(CSS_VAL_CELL);
        case CURSOR_CROSS:
            return new CSSPrimitiveValueImpl(CSS_VAL_CROSSHAIR);
        case CURSOR_TEXT:
            return new CSSPrimitiveValueImpl(CSS_VAL_TEXT);
        case CURSOR_VERTICAL_TEXT:
            return new CSSPrimitiveValueImpl(CSS_VAL_VERTICAL_TEXT);
        case CURSOR_ALIAS:
            return new CSSPrimitiveValueImpl(CSS_VAL_ALIAS);
        case CURSOR_COPY:
            return new CSSPrimitiveValueImpl(CSS_VAL_COPY);
        case CURSOR_MOVE:
            return new CSSPrimitiveValueImpl(CSS_VAL_MOVE);
        case CURSOR_NO_DROP:
            return new CSSPrimitiveValueImpl(CSS_VAL_NO_DROP);
        case CURSOR_NOT_ALLOWED:
            return new CSSPrimitiveValueImpl(CSS_VAL_NOT_ALLOWED);
Maks Orlovich's avatar
Maks Orlovich committed
619 620
        case CURSOR_E_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_E_RESIZE);
621 622
        case CURSOR_N_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_N_RESIZE);
Maks Orlovich's avatar
Maks Orlovich committed
623 624 625 626
        case CURSOR_NE_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NE_RESIZE);
        case CURSOR_NW_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NW_RESIZE);
627 628
        case CURSOR_S_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_S_RESIZE);
Maks Orlovich's avatar
Maks Orlovich committed
629 630 631 632 633 634
        case CURSOR_SE_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_SE_RESIZE);
        case CURSOR_SW_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_SW_RESIZE);
        case CURSOR_W_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_W_RESIZE);
635 636 637 638 639 640 641 642 643 644 645 646 647 648
        case CURSOR_EW_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_EW_RESIZE);
        case CURSOR_NS_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NS_RESIZE);
        case CURSOR_NESW_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NESW_RESIZE);
        case CURSOR_NWSE_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NWSE_RESIZE);
        case CURSOR_COL_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_COL_RESIZE);
        case CURSOR_ROW_RESIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_ROW_RESIZE);
        case CURSOR_ALL_SCROLL:
            return new CSSPrimitiveValueImpl(CSS_VAL_ALL_SCROLL);
Maks Orlovich's avatar
Maks Orlovich committed
649 650
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
651 652
        break;
    case CSS_PROP_DIRECTION:
Maks Orlovich's avatar
Maks Orlovich committed
653 654 655 656 657 658 659
        switch (style->direction()) {
        case LTR:
            return new CSSPrimitiveValueImpl(CSS_VAL_LTR);
        case RTL:
            return new CSSPrimitiveValueImpl(CSS_VAL_RTL);
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
660 661 662
        break;
    case CSS_PROP_DISPLAY:
        switch (style->display()) {
Maks Orlovich's avatar
Maks Orlovich committed
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
        case INLINE:
            return new CSSPrimitiveValueImpl(CSS_VAL_INLINE);
        case BLOCK:
            return new CSSPrimitiveValueImpl(CSS_VAL_BLOCK);
        case LIST_ITEM:
            return new CSSPrimitiveValueImpl(CSS_VAL_LIST_ITEM);
        case RUN_IN:
            return new CSSPrimitiveValueImpl(CSS_VAL_RUN_IN);
        case COMPACT:
            return new CSSPrimitiveValueImpl(CSS_VAL_COMPACT);
        case INLINE_BLOCK:
            return new CSSPrimitiveValueImpl(CSS_VAL_INLINE_BLOCK);
        case TABLE:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE);
        case INLINE_TABLE:
            return new CSSPrimitiveValueImpl(CSS_VAL_INLINE_TABLE);
        case TABLE_ROW_GROUP:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_ROW_GROUP);
        case TABLE_HEADER_GROUP:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_HEADER_GROUP);
        case TABLE_FOOTER_GROUP:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_FOOTER_GROUP);
        case TABLE_ROW:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_ROW);
        case TABLE_COLUMN_GROUP:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_COLUMN_GROUP);
        case TABLE_COLUMN:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_COLUMN);
        case TABLE_CELL:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_CELL);
        case TABLE_CAPTION:
            return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_CAPTION);
        case NONE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
George Staikos's avatar
George Staikos committed
697
        }
Maks Orlovich's avatar
Maks Orlovich committed
698 699
        Q_ASSERT( 0 );
        break;
George Staikos's avatar
George Staikos committed
700 701
    case CSS_PROP_EMPTY_CELLS:
        switch (style->emptyCells()) {
Maks Orlovich's avatar
Maks Orlovich committed
702 703 704 705
        case SHOW:
            return new CSSPrimitiveValueImpl(CSS_VAL_SHOW);
        case HIDE:
            return new CSSPrimitiveValueImpl(CSS_VAL_HIDE);
George Staikos's avatar
George Staikos committed
706
        }
Maks Orlovich's avatar
Maks Orlovich committed
707
        Q_ASSERT( 0 );
George Staikos's avatar
George Staikos committed
708 709 710 711
        break;
    case CSS_PROP_FLOAT:
    {
        switch (style->floating()) {
Maks Orlovich's avatar
Maks Orlovich committed
712 713 714 715 716 717 718 719 720 721
        case FNONE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
        case FLEFT:
            return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
        case FRIGHT:
            return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
        case FLEFT_ALIGN:
            return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_LEFT);
        case FRIGHT_ALIGN:
            return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_RIGHT);
George Staikos's avatar
George Staikos committed
722
        }
723 724
        Q_ASSERT( 0 );
        break;
George Staikos's avatar
George Staikos committed
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
    }
    case CSS_PROP_FONT_FAMILY:
    {
        FontDef def = style->htmlFont().getFontDef();
        return new CSSPrimitiveValueImpl(DOMString(def.family), CSSPrimitiveValue::CSS_STRING);
    }
    case CSS_PROP_FONT_SIZE:
    {
        FontDef def = style->htmlFont().getFontDef();
        return new CSSPrimitiveValueImpl(def.size, CSSPrimitiveValue::CSS_PX);
    }
    case CSS_PROP_FONT_STYLE:
    {
        // FIXME: handle oblique
        FontDef def = style->htmlFont().getFontDef();
        if (def.italic)
Maks Orlovich's avatar
Maks Orlovich committed
741
            return new CSSPrimitiveValueImpl(CSS_VAL_ITALIC);
George Staikos's avatar
George Staikos committed
742
        else
Maks Orlovich's avatar
Maks Orlovich committed
743
            return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
George Staikos's avatar
George Staikos committed
744 745 746 747 748
    }
    case CSS_PROP_FONT_VARIANT:
    {
        FontDef def = style->htmlFont().getFontDef();
        if (def.smallCaps)
Maks Orlovich's avatar
Maks Orlovich committed
749
            return new CSSPrimitiveValueImpl(CSS_VAL_SMALL_CAPS);
George Staikos's avatar
George Staikos committed
750
        else
Maks Orlovich's avatar
Maks Orlovich committed
751
            return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
George Staikos's avatar
George Staikos committed
752 753 754 755 756 757
    }
    case CSS_PROP_FONT_WEIGHT:
    {
        // FIXME: this does not reflect the full range of weights
        // that can be expressed with CSS
        FontDef def = style->htmlFont().getFontDef();
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
        switch (def.weight) {
            case QFont::Light:
                return new CSSPrimitiveValueImpl(CSS_VAL_300);
            case QFont::Normal:
                //return new CSSPrimitiveValueImpl(CSS_VAL_400);
                return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
            case QFont::DemiBold:
                return new CSSPrimitiveValueImpl(CSS_VAL_600);
            case QFont::Bold:
                //return new CSSPrimitiveValueImpl(CSS_VAL_700);
                return new CSSPrimitiveValueImpl(CSS_VAL_BOLD);
            case QFont::Black:
                return new CSSPrimitiveValueImpl(CSS_VAL_900);
            default:
                // Should not happen
                return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
        }
George Staikos's avatar
George Staikos committed
775 776
    }
    case CSS_PROP_HEIGHT:
777 778 779
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->contentHeight(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->height());
George Staikos's avatar
George Staikos committed
780
    case CSS_PROP_LEFT:
781
        RETURN_NULL_ON_NULL(renderer);
Maks Orlovich's avatar
Maks Orlovich committed
782
        return getPositionOffsetValue(renderer, CSS_PROP_LEFT);
George Staikos's avatar
George Staikos committed
783 784
    case CSS_PROP_LETTER_SPACING:
        if (style->letterSpacing() == 0)
Maks Orlovich's avatar
Maks Orlovich committed
785
            return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
George Staikos's avatar
George Staikos committed
786 787 788
        return new CSSPrimitiveValueImpl(style->letterSpacing(), CSSPrimitiveValue::CSS_PX);
    case CSS_PROP_LINE_HEIGHT:
    {
Germain Garand's avatar
Germain Garand committed
789
        // Note: internally a specified <number> value gets encoded as a percentage,
790
        // so the isPercent() case corresponds to the <number> case;
Germain Garand's avatar
Germain Garand committed
791
        // values < 0  are used to mark "normal"; and specified %%
792
        // get computed down to px by the time they get to RenderStyle
Germain Garand's avatar
Germain Garand committed
793
        // already
George Staikos's avatar
George Staikos committed
794
        Length length(style->lineHeight());
795
        if (length.isNegative())
Maks Orlovich's avatar
Maks Orlovich committed
796
            return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
George Staikos's avatar
George Staikos committed
797 798 799
        if (length.isPercent()) {
            //XXX: merge from webcore the computedStyle/specifiedStyle distinction in rendering/font.h
            float computedSize = style->htmlFont().getFontDef().size;
800
            return new CSSPrimitiveValueImpl((int)(length.percent() * computedSize) / 100, CSSPrimitiveValue::CSS_PX);
George Staikos's avatar
George Staikos committed
801 802
        }
        else {
Germain Garand's avatar
Germain Garand committed
803
            return new CSSPrimitiveValueImpl(length.value(), CSSPrimitiveValue::CSS_PX);
George Staikos's avatar
George Staikos committed
804 805 806
        }
    }
    case CSS_PROP_LIST_STYLE_IMAGE:
Maks Orlovich's avatar
Maks Orlovich committed
807 808 809
        if (style->listStyleImage())
            return new CSSPrimitiveValueImpl(style->listStyleImage()->url(), CSSPrimitiveValue::CSS_URI);
        return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
George Staikos's avatar
George Staikos committed
810 811 812
    case CSS_PROP_LIST_STYLE_POSITION:
        switch (style->listStylePosition()) {
        case OUTSIDE:
Maks Orlovich's avatar
Maks Orlovich committed
813
            return new CSSPrimitiveValueImpl(CSS_VAL_OUTSIDE);
George Staikos's avatar
George Staikos committed
814
        case INSIDE:
Maks Orlovich's avatar
Maks Orlovich committed
815
            return new CSSPrimitiveValueImpl(CSS_VAL_INSIDE);
George Staikos's avatar
George Staikos committed
816 817 818 819 820 821
        }
        Q_ASSERT( 0 );
        break;
    case CSS_PROP_LIST_STYLE_TYPE:
        return new CSSPrimitiveValueImpl(stringForListStyleType(style->listStyleType()), CSSPrimitiveValue::CSS_STRING);
    case CSS_PROP_MARGIN_TOP:
822 823 824
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->marginTop(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->marginTop());
George Staikos's avatar
George Staikos committed
825
    case CSS_PROP_MARGIN_RIGHT:
826 827 828
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->marginRight(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->marginRight());
George Staikos's avatar
George Staikos committed
829
    case CSS_PROP_MARGIN_BOTTOM:
830 831 832
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->marginBottom(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->marginBottom());
George Staikos's avatar
George Staikos committed
833
    case CSS_PROP_MARGIN_LEFT:
834 835 836
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->marginLeft(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->marginLeft());
Maks Orlovich's avatar
Maks Orlovich committed
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
    case CSS_PROP__KHTML_MARQUEE:
        // FIXME: unimplemented
        break;
    case CSS_PROP__KHTML_MARQUEE_DIRECTION:
        switch (style->marqueeDirection()) {
        case MFORWARD:
            return new CSSPrimitiveValueImpl(CSS_VAL_FORWARDS);
        case MBACKWARD:
            return new CSSPrimitiveValueImpl(CSS_VAL_BACKWARDS);
        case MAUTO:
            return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
        case MUP:
            return new CSSPrimitiveValueImpl(CSS_VAL_UP);
        case MDOWN:
            return new CSSPrimitiveValueImpl(CSS_VAL_DOWN);
        case MLEFT:
            return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
        case MRIGHT:
            return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
        }
        Q_ASSERT(0);
        return 0;
    case CSS_PROP__KHTML_MARQUEE_INCREMENT:
860
        RETURN_NULL_ON_NULL(renderer);
Maks Orlovich's avatar
Maks Orlovich committed
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
        return valueForLength(style->marqueeIncrement(), renderer->contentWidth());
    case CSS_PROP__KHTML_MARQUEE_REPETITION:
        if (style->marqueeLoopCount() < 0)
            return new CSSPrimitiveValueImpl(CSS_VAL_INFINITE);
        return new CSSPrimitiveValueImpl(style->marqueeLoopCount(), CSSPrimitiveValue::CSS_NUMBER);
    case CSS_PROP__KHTML_MARQUEE_SPEED:
        // FIXME: unimplemented
        break;
    case CSS_PROP__KHTML_MARQUEE_STYLE:
        switch (style->marqueeBehavior()) {
        case MNONE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
        case MSCROLL:
            return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
        case MSLIDE:
            return new CSSPrimitiveValueImpl(CSS_VAL_SLIDE);
        case MALTERNATE:
            return new CSSPrimitiveValueImpl(CSS_VAL_ALTERNATE);
        case MUNFURL:
            return new CSSPrimitiveValueImpl(CSS_VAL_UNFURL);
        }
        Q_ASSERT(0);
        return 0;
George Staikos's avatar
George Staikos committed
884
    case CSS_PROP_MAX_HEIGHT:
885
        RETURN_NULL_ON_NULL(renderer);
George Staikos's avatar
George Staikos committed
886 887 888 889
        return new CSSPrimitiveValueImpl( renderer->availableHeight(),
                                          CSSPrimitiveValue::CSS_PX );
        break;
    case CSS_PROP_MAX_WIDTH:
890
        RETURN_NULL_ON_NULL(renderer);
George Staikos's avatar
George Staikos committed
891 892 893 894
        return new CSSPrimitiveValueImpl( renderer->maxWidth(),
                                          CSSPrimitiveValue::CSS_PX );
        break;
    case CSS_PROP_MIN_HEIGHT:
895
        RETURN_NULL_ON_NULL(renderer);
George Staikos's avatar
George Staikos committed
896 897 898 899
        return new CSSPrimitiveValueImpl( renderer->contentHeight(),
                                          CSSPrimitiveValue::CSS_PX );
        break;
    case CSS_PROP_MIN_WIDTH:
900
        RETURN_NULL_ON_NULL(renderer);
George Staikos's avatar
George Staikos committed
901 902 903 904
        return new CSSPrimitiveValueImpl( renderer->minWidth(),
                                          CSSPrimitiveValue::CSS_PX );
        break;
    case CSS_PROP_OPACITY:
Maks Orlovich's avatar
Maks Orlovich committed
905
        return new CSSPrimitiveValueImpl(style->opacity(), CSSPrimitiveValue::CSS_NUMBER);
George Staikos's avatar
George Staikos committed
906
    case CSS_PROP_ORPHANS:
Maks Orlovich's avatar
Maks Orlovich committed
907
        return new CSSPrimitiveValueImpl(style->orphans(), CSSPrimitiveValue::CSS_NUMBER);
George Staikos's avatar
George Staikos committed
908 909 910 911 912
    case CSS_PROP_OUTLINE_COLOR:
        break;
    case CSS_PROP_OUTLINE_OFFSET:
        break;
    case CSS_PROP_OUTLINE_STYLE:
Maks Orlovich's avatar
Maks Orlovich committed
913 914 915
        if (style->outlineStyleIsAuto())
            return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
        return valueForBorderStyle(style->outlineStyle());
George Staikos's avatar
George Staikos committed
916 917 918
    case CSS_PROP_OUTLINE_WIDTH:
        break;
    case CSS_PROP_OVERFLOW:
Germain Garand's avatar
Germain Garand committed
919 920 921 922 923 924 925 926 927 928 929 930 931 932
    case CSS_PROP_OVERFLOW_X:
    case CSS_PROP_OVERFLOW_Y: {
        EOverflow overflow;
        switch (propertyID) {
        case CSS_PROP_OVERFLOW_X:
            overflow = style->overflowX();
            break;
        case CSS_PROP_OVERFLOW_Y:
            overflow = style->overflowY();
            break;
        default:
            overflow = qMax(style->overflowX(), style->overflowY());
        }
        switch (overflow) {
Maks Orlovich's avatar
Maks Orlovich committed
933 934 935 936 937 938 939 940 941 942
        case OVISIBLE:
            return new CSSPrimitiveValueImpl(CSS_VAL_VISIBLE);
        case OHIDDEN:
            return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
        case OSCROLL:
            return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
        case OAUTO:
            return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
        case OMARQUEE:
            return new CSSPrimitiveValueImpl(CSS_VAL_MARQUEE);
George Staikos's avatar
George Staikos committed
943
        }
Maks Orlovich's avatar
Maks Orlovich committed
944 945
        Q_ASSERT(0);
        return 0;
George Staikos's avatar
George Staikos committed
946 947
    }
    case CSS_PROP_PADDING_TOP:
948 949 950
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->paddingTop(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->paddingTop());
George Staikos's avatar
George Staikos committed
951
    case CSS_PROP_PADDING_RIGHT:
952 953 954
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->paddingRight(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->paddingRight());
George Staikos's avatar
George Staikos committed
955
    case CSS_PROP_PADDING_BOTTOM:
956 957 958
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->paddingBottom(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->paddingBottom());
George Staikos's avatar
George Staikos committed
959
    case CSS_PROP_PADDING_LEFT:
960 961 962
        if (renderer)
            return new CSSPrimitiveValueImpl(renderer->paddingLeft(), CSSPrimitiveValue::CSS_PX);
        return valueForLength2(style->paddingLeft());
George Staikos's avatar
George Staikos committed
963
    case CSS_PROP_PAGE_BREAK_AFTER:
Maks Orlovich's avatar
Maks Orlovich committed
964 965 966 967 968 969 970 971 972 973 974 975 976
        switch (style->pageBreakAfter()) {
        case PBAUTO:
            return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
        case PBALWAYS:
            return new CSSPrimitiveValueImpl(CSS_VAL_ALWAYS);
        case PBAVOID:
            return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
        case PBLEFT:
            return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
        case PBRIGHT:
            return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
977 978
        break;
    case CSS_PROP_PAGE_BREAK_BEFORE:
Maks Orlovich's avatar
Maks Orlovich committed
979 980 981 982 983 984 985 986 987 988 989 990 991
        switch (style->pageBreakBefore()) {
        case PBAUTO:
            return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
        case PBALWAYS:
            return new CSSPrimitiveValueImpl(CSS_VAL_ALWAYS);
        case PBAVOID:
            return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
        case PBLEFT:
            return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
        case PBRIGHT:
            return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
992 993
        break;
    case CSS_PROP_PAGE_BREAK_INSIDE:
Germain Garand's avatar
Germain Garand committed
994
        if (style->pageBreakInside())
Maks Orlovich's avatar
Maks Orlovich committed
995
            return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
Germain Garand's avatar
Germain Garand committed
996
        else
Maks Orlovich's avatar
Maks Orlovich committed
997
            return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
Germain Garand's avatar
Germain Garand committed
998
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
999 1000
        break;
    case CSS_PROP_POSITION:
Maks Orlovich's avatar
Maks Orlovich committed
1001
        switch (style->position()) {
1002
        case PSTATIC:
Maks Orlovich's avatar
Maks Orlovich committed
1003
            return new CSSPrimitiveValueImpl(CSS_VAL_STATIC);
1004
        case PRELATIVE:
Maks Orlovich's avatar
Maks Orlovich committed
1005
            return new CSSPrimitiveValueImpl(CSS_VAL_RELATIVE);
1006
        case PABSOLUTE:
Maks Orlovich's avatar
Maks Orlovich committed
1007
            return new CSSPrimitiveValueImpl(CSS_VAL_ABSOLUTE);
1008
        case PFIXED:
Maks Orlovich's avatar
Maks Orlovich committed
1009 1010 1011
            return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
1012 1013 1014 1015
        break;
    case CSS_PROP_QUOTES:
        break;
    case CSS_PROP_RIGHT:
1016
        RETURN_NULL_ON_NULL(renderer);
Maks Orlovich's avatar
Maks Orlovich committed
1017
        return getPositionOffsetValue(renderer, CSS_PROP_RIGHT);
George Staikos's avatar
George Staikos committed
1018 1019 1020
    case CSS_PROP_SIZE:
        break;
    case CSS_PROP_TABLE_LAYOUT:
Maks Orlovich's avatar
Maks Orlovich committed
1021 1022 1023 1024 1025 1026 1027
        switch (style->tableLayout()) {
        case TAUTO:
            return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
        case TFIXED:
            return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
1028 1029
        break;
    case CSS_PROP_TEXT_ALIGN:
Maks Orlovich's avatar
Maks Orlovich committed
1030
        return valueForTextAlign(style->textAlign());
George Staikos's avatar
George Staikos committed
1031 1032 1033 1034 1035 1036 1037
    case CSS_PROP_TEXT_DECORATION:
    {
        QString string;
        if (style->textDecoration() & khtml::UNDERLINE)
            string += "underline";
        if (style->textDecoration() & khtml::OVERLINE) {
            if (string.length() > 0)
1038
                string += " ";
George Staikos's avatar
George Staikos committed
1039 1040 1041 1042
            string += "overline";
        }
        if (style->textDecoration() & khtml::LINE_THROUGH) {
            if (string.length() > 0)
1043
                string += " ";
George Staikos's avatar
George Staikos committed
1044 1045 1046 1047
            string += "line-through";
        }
        if (style->textDecoration() & khtml::BLINK) {
            if (string.length() > 0)
1048
                string += " ";
George Staikos's avatar
George Staikos committed
1049 1050 1051 1052 1053 1054 1055
            string += "blink";
        }
        if (string.length() == 0)
            string = "none";
        return new CSSPrimitiveValueImpl(DOMString(string), CSSPrimitiveValue::CSS_STRING);
    }
    case CSS_PROP_TEXT_INDENT:
1056
        RETURN_NULL_ON_NULL(renderer);
George Staikos's avatar
George Staikos committed
1057
        return valueForLength(style->textIndent(), renderer->contentWidth());
Maks Orlovich's avatar
Maks Orlovich committed
1058 1059
    case CSS_PROP_TEXT_SHADOW:
        return valueForShadow(style->textShadow());
George Staikos's avatar
George Staikos committed
1060
    case CSS_PROP_TEXT_TRANSFORM:
Maks Orlovich's avatar
Maks Orlovich committed
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
        switch (style->textTransform()) {
        case CAPITALIZE:
            return new CSSPrimitiveValueImpl(CSS_VAL_CAPITALIZE);
        case UPPERCASE:
            return new CSSPrimitiveValueImpl(CSS_VAL_UPPERCASE);
        case LOWERCASE:
            return new CSSPrimitiveValueImpl(CSS_VAL_LOWERCASE);
        case TTNONE:
            return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
        }
        Q_ASSERT(0);
George Staikos's avatar
George Staikos committed
1072 1073
        break;
    case CSS_PROP_TOP: