00001
00023 #include "css/cssstyleselector.h"
00024 #include "rendering/render_style.h"
00025 #include "css/css_stylesheetimpl.h"
00026 #include "css/css_ruleimpl.h"
00027 #include "css/css_valueimpl.h"
00028 #include "css/csshelper.h"
00029 #include "rendering/render_object.h"
00030 #include "html/html_documentimpl.h"
00031 #include "html/html_elementimpl.h"
00032 #include "xml/dom_elementimpl.h"
00033 #include "dom/css_rule.h"
00034 #include "dom/css_value.h"
00035 #include "khtml_factory.h"
00036 #include "khtmlpart_p.h"
00037 using namespace khtml;
00038 using namespace DOM;
00039
00040 #include "css/cssproperties.h"
00041 #include "css/cssvalues.h"
00042
00043 #include "misc/khtmllayout.h"
00044 #include "khtml_settings.h"
00045 #include "misc/htmlhashes.h"
00046 #include "misc/helper.h"
00047 #include "misc/loader.h"
00048
00049 #include "rendering/font.h"
00050
00051 #include "khtmlview.h"
00052 #include "khtml_part.h"
00053
00054 #include <kstandarddirs.h>
00055 #include <kcharsets.h>
00056 #include <kglobal.h>
00057 #include <kconfig.h>
00058 #include <qfile.h>
00059 #include <qvaluelist.h>
00060 #include <qstring.h>
00061 #include <qtooltip.h>
00062 #include <kdebug.h>
00063 #include <kurl.h>
00064 #include <assert.h>
00065 #include <qpaintdevicemetrics.h>
00066 #include <stdlib.h>
00067
00068 #define HANDLE_INHERIT(prop, Prop) \
00069 if (isInherit) \
00070 {\
00071 style->set##Prop(parentStyle->prop());\
00072 return;\
00073 }
00074
00075 #define HANDLE_INHERIT_AND_INITIAL(prop, Prop) \
00076 HANDLE_INHERIT(prop, Prop) \
00077 else if (isInitial) \
00078 style->set##Prop(RenderStyle::initial##Prop());
00079
00080 #define HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(prop, Prop, Value) \
00081 HANDLE_INHERIT(prop, Prop) \
00082 else if (isInitial) \
00083 style->set##Prop(RenderStyle::initial##Value());
00084
00085 #define HANDLE_INHERIT_COND(propID, prop, Prop) \
00086 if (id == propID) \
00087 {\
00088 style->set##Prop(parentStyle->prop());\
00089 return;\
00090 }
00091
00092 #define HANDLE_INITIAL_COND(propID, Prop) \
00093 if (id == propID) \
00094 {\
00095 style->set##Prop(RenderStyle::initial##Prop());\
00096 return;\
00097 }
00098
00099 #define HANDLE_INITIAL_COND_WITH_VALUE(propID, Prop, Value) \
00100 if (id == propID) \
00101 {\
00102 style->set##Prop(RenderStyle::initial##Value());\
00103 return;\
00104 }
00105
00106 namespace khtml {
00107
00108 CSSStyleSelectorList *CSSStyleSelector::s_defaultStyle;
00109 CSSStyleSelectorList *CSSStyleSelector::s_defaultQuirksStyle;
00110 CSSStyleSelectorList *CSSStyleSelector::s_defaultPrintStyle;
00111 CSSStyleSheetImpl *CSSStyleSelector::s_defaultSheet;
00112 RenderStyle* CSSStyleSelector::styleNotYetAvailable;
00113 CSSStyleSheetImpl *CSSStyleSelector::s_quirksSheet;
00114
00115 enum PseudoState { PseudoUnknown, PseudoNone, PseudoLink, PseudoVisited};
00116 static PseudoState pseudoState;
00117
00118
00119 CSSStyleSelector::CSSStyleSelector( DocumentImpl* doc, QString userStyleSheet, StyleSheetListImpl *styleSheets,
00120 const KURL &url, bool _strictParsing )
00121 {
00122 KHTMLView* view = doc->view();
00123
00124 init(view ? view->part()->settings() : 0);
00125
00126 strictParsing = _strictParsing;
00127 m_medium = view ? view->mediaType() : QString("all");
00128
00129 selectors = 0;
00130 selectorCache = 0;
00131 properties = 0;
00132 userStyle = 0;
00133 userSheet = 0;
00134 paintDeviceMetrics = doc->paintDeviceMetrics();
00135
00136 if(paintDeviceMetrics)
00137 computeFontSizes(paintDeviceMetrics, view ? view->part()->zoomFactor() : 100);
00138
00139 if ( !userStyleSheet.isEmpty() ) {
00140 userSheet = new DOM::CSSStyleSheetImpl(doc);
00141 userSheet->parseString( DOMString( userStyleSheet ) );
00142
00143 userStyle = new CSSStyleSelectorList();
00144 userStyle->append( userSheet, m_medium );
00145 }
00146
00147
00148 authorStyle = new CSSStyleSelectorList();
00149
00150
00151 QPtrListIterator<StyleSheetImpl> it( styleSheets->styleSheets );
00152 for ( ; it.current(); ++it ) {
00153 if ( it.current()->isCSSStyleSheet() ) {
00154 authorStyle->append( static_cast<CSSStyleSheetImpl*>( it.current() ), m_medium );
00155 }
00156 }
00157
00158 buildLists();
00159
00160
00161
00162
00163 KURL u = url;
00164
00165 u.setQuery( QString::null );
00166 u.setRef( QString::null );
00167 encodedurl.file = u.url();
00168 int pos = encodedurl.file.findRev('/');
00169 encodedurl.path = encodedurl.file;
00170 if ( pos > 0 ) {
00171 encodedurl.path.truncate( pos );
00172 encodedurl.path += '/';
00173 }
00174 u.setPath( QString::null );
00175 encodedurl.host = u.url();
00176
00177
00178 }
00179
00180 CSSStyleSelector::CSSStyleSelector( CSSStyleSheetImpl *sheet )
00181 {
00182 init(0L);
00183
00184 KHTMLView *view = sheet->doc()->view();
00185 m_medium = view ? view->mediaType() : "screen";
00186
00187 authorStyle = new CSSStyleSelectorList();
00188 authorStyle->append( sheet, m_medium );
00189 }
00190
00191 void CSSStyleSelector::init(const KHTMLSettings* _settings)
00192 {
00193 element = 0;
00194 settings = _settings;
00195 paintDeviceMetrics = 0;
00196 propsToApply = (CSSOrderedProperty **)malloc(128*sizeof(CSSOrderedProperty *));
00197 pseudoProps = (CSSOrderedProperty **)malloc(128*sizeof(CSSOrderedProperty *));
00198 propsToApplySize = 128;
00199 pseudoPropsSize = 128;
00200 if(!s_defaultStyle) loadDefaultStyle(settings);
00201
00202 defaultStyle = s_defaultStyle;
00203 defaultPrintStyle = s_defaultPrintStyle;
00204 defaultQuirksStyle = s_defaultQuirksStyle;
00205 }
00206
00207 CSSStyleSelector::~CSSStyleSelector()
00208 {
00209 clearLists();
00210 delete authorStyle;
00211 delete userStyle;
00212 delete userSheet;
00213 free(propsToApply);
00214 free(pseudoProps);
00215 }
00216
00217 void CSSStyleSelector::addSheet( CSSStyleSheetImpl *sheet )
00218 {
00219 KHTMLView *view = sheet->doc()->view();
00220 m_medium = view ? view->mediaType() : "screen";
00221 authorStyle->append( sheet, m_medium );
00222 }
00223
00224 void CSSStyleSelector::loadDefaultStyle(const KHTMLSettings *s)
00225 {
00226 if(s_defaultStyle) return;
00227
00228 {
00229 QFile f(locate( "data", "khtml/css/html4.css" ) );
00230 f.open(IO_ReadOnly);
00231
00232 QCString file( f.size()+1 );
00233 int readbytes = f.readBlock( file.data(), f.size() );
00234 f.close();
00235 if ( readbytes >= 0 )
00236 file[readbytes] = '\0';
00237
00238 QString style = QString::fromLatin1( file.data() );
00239 if(s)
00240 style += s->settingsToCSS();
00241 DOMString str(style);
00242
00243 s_defaultSheet = new DOM::CSSStyleSheetImpl((DOM::CSSStyleSheetImpl * ) 0);
00244 s_defaultSheet->parseString( str );
00245
00246
00247 s_defaultStyle = new CSSStyleSelectorList();
00248 s_defaultStyle->append( s_defaultSheet, "screen" );
00249
00250 s_defaultPrintStyle = new CSSStyleSelectorList();
00251 s_defaultPrintStyle->append( s_defaultSheet, "print" );
00252 }
00253 {
00254 QFile f(locate( "data", "khtml/css/quirks.css" ) );
00255 f.open(IO_ReadOnly);
00256
00257 QCString file( f.size()+1 );
00258 int readbytes = f.readBlock( file.data(), f.size() );
00259 f.close();
00260 if ( readbytes >= 0 )
00261 file[readbytes] = '\0';
00262
00263 QString style = QString::fromLatin1( file.data() );
00264 DOMString str(style);
00265
00266 s_quirksSheet = new DOM::CSSStyleSheetImpl((DOM::CSSStyleSheetImpl * ) 0);
00267 s_quirksSheet->parseString( str );
00268
00269
00270 s_defaultQuirksStyle = new CSSStyleSelectorList();
00271 s_defaultQuirksStyle->append( s_quirksSheet, "screen" );
00272 }
00273
00274
00275 }
00276
00277 void CSSStyleSelector::clear()
00278 {
00279 delete s_defaultStyle;
00280 delete s_defaultQuirksStyle;
00281 delete s_defaultPrintStyle;
00282 delete s_defaultSheet;
00283 delete styleNotYetAvailable;
00284 s_defaultStyle = 0;
00285 s_defaultQuirksStyle = 0;
00286 s_defaultPrintStyle = 0;
00287 s_defaultSheet = 0;
00288 styleNotYetAvailable = 0;
00289 }
00290
00291 void CSSStyleSelector::reparseConfiguration()
00292 {
00293
00294 s_defaultStyle = 0;
00295 s_defaultQuirksStyle = 0;
00296 s_defaultPrintStyle = 0;
00297 s_defaultSheet = 0;
00298 }
00299
00300 #define MAXFONTSIZES 15
00301
00302 void CSSStyleSelector::computeFontSizes(QPaintDeviceMetrics* paintDeviceMetrics, int zoomFactor)
00303 {
00304 computeFontSizesFor(paintDeviceMetrics, zoomFactor, m_fontSizes, false);
00305 computeFontSizesFor(paintDeviceMetrics, zoomFactor, m_fixedFontSizes, true);
00306 }
00307
00308 void CSSStyleSelector::computeFontSizesFor(QPaintDeviceMetrics* paintDeviceMetrics, int zoomFactor, QValueList<int>& fontSizes, bool isFixed)
00309 {
00310 #ifdef APPLE_CHANGES
00311
00312 const float toPix = 1;
00313 #else
00314 Q_UNUSED( isFixed );
00315
00316
00317 float toPix = paintDeviceMetrics->logicalDpiY()/72.;
00318 if (toPix < 96./72.) toPix = 96./72.;
00319 #endif // ######### fix isFixed code again.
00320
00321 fontSizes.clear();
00322 const float factor = 1.2;
00323 float scale = 1.0 / (factor*factor*factor);
00324 float mediumFontSize;
00325 float minFontSize;
00326 if (!khtml::printpainter) {
00327 scale *= zoomFactor / 100.0;
00328 #ifdef APPLE_CHANGES
00329 if (isFixed)
00330 mediumFontSize = settings->mediumFixedFontSize() * toPix;
00331 else
00332 #endif
00333 mediumFontSize = settings->mediumFontSize() * toPix;
00334 minFontSize = settings->minFontSize() * toPix;
00335 }
00336 else {
00337
00338 mediumFontSize = 12;
00339 minFontSize = 6;
00340 }
00341
00342 for ( int i = 0; i < MAXFONTSIZES; i++ ) {
00343 fontSizes << int(KMAX( mediumFontSize * scale + 0.5f, minFontSize));
00344 scale *= factor;
00345 }
00346 }
00347
00348 #undef MAXFONTSIZES
00349
00350 static inline void bubbleSort( CSSOrderedProperty **b, CSSOrderedProperty **e )
00351 {
00352 while( b < e ) {
00353 bool swapped = false;
00354 CSSOrderedProperty **y = e+1;
00355 CSSOrderedProperty **x = e;
00356 CSSOrderedProperty **swappedPos = 0;
00357 do {
00358 if ( !((**(--x)) < (**(--y))) ) {
00359 swapped = true;
00360 swappedPos = x;
00361 CSSOrderedProperty *tmp = *y;
00362 *y = *x;
00363 *x = tmp;
00364 }
00365 } while( x != b );
00366 if ( !swapped ) break;
00367 b = swappedPos + 1;
00368 }
00369 }
00370
00371 RenderStyle *CSSStyleSelector::styleForElement(ElementImpl *e)
00372 {
00373 if (!e->getDocument()->haveStylesheetsLoaded() || !e->getDocument()->view()) {
00374 if (!styleNotYetAvailable) {
00375 styleNotYetAvailable = new RenderStyle();
00376 styleNotYetAvailable->setDisplay(NONE);
00377 styleNotYetAvailable->ref();
00378 }
00379 return styleNotYetAvailable;
00380 }
00381
00382
00383 pseudoState = PseudoUnknown;
00384
00385 element = e;
00386 parentNode = e->parentNode();
00387 parentStyle = ( parentNode && parentNode->renderer()) ? parentNode->renderer()->style() : 0;
00388 view = element->getDocument()->view();
00389 part = view->part();
00390 settings = part->settings();
00391 paintDeviceMetrics = element->getDocument()->paintDeviceMetrics();
00392
00393 style = new RenderStyle();
00394 if( parentStyle )
00395 style->inheritFrom( parentStyle );
00396 else
00397 parentStyle = style;
00398
00399 unsigned int numPropsToApply = 0;
00400 unsigned int numPseudoProps = 0;
00401
00402
00403 int cssTagId = (e->id() & NodeImpl_IdLocalMask);
00404 int smatch = 0;
00405 int schecked = 0;
00406
00407 for ( unsigned int i = 0; i < selectors_size; i++ ) {
00408 int tag = selectors[i]->tag & NodeImpl_IdLocalMask;
00409 if ( cssTagId == tag || tag == 0xffff ) {
00410 ++schecked;
00411
00412 checkSelector( i, e );
00413
00414 if ( selectorCache[i].state == Applies ) {
00415 ++smatch;
00416
00417
00418 for ( unsigned int p = 0; p < selectorCache[i].props_size; p += 2 )
00419 for ( unsigned int j = 0; j < (unsigned int )selectorCache[i].props[p+1]; ++j ) {
00420 if (numPropsToApply >= propsToApplySize ) {
00421 propsToApplySize *= 2;
00422 propsToApply = (CSSOrderedProperty **)realloc( propsToApply, propsToApplySize*sizeof( CSSOrderedProperty * ) );
00423 }
00424 propsToApply[numPropsToApply++] = properties[selectorCache[i].props[p]+j];
00425 }
00426 } else if ( selectorCache[i].state == AppliesPseudo ) {
00427 for ( unsigned int p = 0; p < selectorCache[i].props_size; p += 2 )
00428 for ( unsigned int j = 0; j < (unsigned int) selectorCache[i].props[p+1]; ++j ) {
00429 if (numPseudoProps >= pseudoPropsSize ) {
00430 pseudoPropsSize *= 2;
00431 pseudoProps = (CSSOrderedProperty **)realloc( pseudoProps, pseudoPropsSize*sizeof( CSSOrderedProperty * ) );
00432 }
00433 pseudoProps[numPseudoProps++] = properties[selectorCache[i].props[p]+j];
00434 properties[selectorCache[i].props[p]+j]->pseudoId = (RenderStyle::PseudoId) selectors[i]->pseudoId;
00435 }
00436 }
00437 }
00438 else
00439 selectorCache[i].state = Invalid;
00440
00441 }
00442
00443
00444
00445 numPropsToApply = addInlineDeclarations( e, e->m_styleDecls, numPropsToApply );
00446
00447
00448
00449
00450
00451 bubbleSort( propsToApply, propsToApply+numPropsToApply-1 );
00452 bubbleSort( pseudoProps, pseudoProps+numPseudoProps-1 );
00453
00454
00455
00456 if ( part ) {
00457 fontDirty = false;
00458
00459 if (numPropsToApply ) {
00460 CSSStyleSelector::style = style;
00461 for (unsigned int i = 0; i < numPropsToApply; ++i) {
00462 if ( fontDirty && propsToApply[i]->priority >= (1 << 30) ) {
00463
00464
00465 #ifdef APPLE_CHANGES
00466 checkForGenericFamilyChange(style, parentStyle);
00467 #endif
00468 CSSStyleSelector::style->htmlFont().update( paintDeviceMetrics );
00469 fontDirty = false;
00470 }
00471 DOM::CSSProperty *prop = propsToApply[i]->prop;
00472
00473
00474 applyRule( prop->m_id, prop->value() );
00475 }
00476 if ( fontDirty ) {
00477 #ifdef APPLE_CHANGES
00478 checkForGenericFamilyChange(style, parentStyle);
00479 #endif
00480 CSSStyleSelector::style->htmlFont().update( paintDeviceMetrics );
00481 }
00482 }
00483
00484
00485 adjustRenderStyle(style, e);
00486
00487 if ( numPseudoProps ) {
00488 fontDirty = false;
00489
00490 for (unsigned int i = 0; i < numPseudoProps; ++i) {
00491 if ( fontDirty && pseudoProps[i]->priority >= (1 << 30) ) {
00492
00493
00494
00495 RenderStyle *pseudoStyle = style->pseudoStyle;
00496 while ( pseudoStyle ) {
00497 pseudoStyle->htmlFont().update( paintDeviceMetrics );
00498 pseudoStyle = pseudoStyle->pseudoStyle;
00499 }
00500 fontDirty = false;
00501 }
00502
00503 RenderStyle *pseudoStyle;
00504 pseudoStyle = style->getPseudoStyle(pseudoProps[i]->pseudoId);
00505 if (!pseudoStyle)
00506 {
00507 pseudoStyle = style->addPseudoStyle(pseudoProps[i]->pseudoId);
00508 if (pseudoStyle)
00509 pseudoStyle->inheritFrom( style );
00510 }
00511
00512 RenderStyle* oldStyle = style;
00513 RenderStyle* oldParentStyle = parentStyle;
00514 parentStyle = style;
00515 style = pseudoStyle;
00516 if ( pseudoStyle ) {
00517 DOM::CSSProperty *prop = pseudoProps[i]->prop;
00518 applyRule( prop->m_id, prop->value() );
00519 }
00520 style = oldStyle;
00521 parentStyle = oldParentStyle;
00522 }
00523
00524 if ( fontDirty ) {
00525 RenderStyle *pseudoStyle = style->pseudoStyle;
00526 while ( pseudoStyle ) {
00527 pseudoStyle->htmlFont().update( paintDeviceMetrics );
00528 pseudoStyle = pseudoStyle->pseudoStyle;
00529 }
00530 }
00531 }
00532 }
00533
00534
00535 RenderStyle *pseudoStyle = style->pseudoStyle;
00536 while (pseudoStyle) {
00537 adjustRenderStyle(pseudoStyle, 0);
00538 pseudoStyle = pseudoStyle->pseudoStyle;
00539 }
00540
00541
00542 return style;
00543 }
00544
00545 void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, DOM::ElementImpl *e)
00546 {
00547 #ifdef APPLE_CHANGES
00548
00549 style->setOriginalDisplay(style->display());
00550 #endif
00551
00552 if (style->display() != NONE) {
00553
00554
00555
00556
00557 if (!strictParsing && e) {
00558 if (e->id() == ID_TD) {
00559 style->setDisplay(TABLE_CELL);
00560 style->setFloating(FNONE);
00561 }
00562
00563
00564 }
00565
00566
00567
00568
00569
00570 if (style->display() != BLOCK && style->display() != TABLE &&
00571 (style->position() == ABSOLUTE || style->position() == FIXED || style->floating() != FNONE ||
00572 (e && e->getDocument()->documentElement() == e))) {
00573 if (style->display() == INLINE_TABLE)
00574 style->setDisplay(TABLE);
00575
00576
00577 else if (style->display() == LIST_ITEM) {
00578
00579
00580 if (!strictParsing && style->floating() != FNONE)
00581 style->setDisplay(BLOCK);
00582 }
00583 else
00584 style->setDisplay(BLOCK);
00585 }
00586
00587
00588
00589
00590 if (style->display() == TABLE_ROW && style->position() == RELATIVE)
00591 style->setPosition(STATIC);
00592 }
00593
00594
00595
00596 if ( e ) {
00597
00598 if ( e->id() == ID_FRAME ) {
00599 style->setPosition( STATIC );
00600 style->setDisplay( BLOCK );
00601 }
00602 else if ( e->id() == ID_FRAMESET ) {
00603 style->setPosition( STATIC );
00604 }
00605 }
00606
00607
00608
00609 if (style->display() == TABLE || style->display() == INLINE_TABLE || style->display() == RUN_IN
00610 || style->display() == INLINE_BLOCK )
00611 style->setTextDecorationsInEffect(style->textDecoration());
00612 else
00613 style->addToTextDecorationsInEffect(style->textDecoration());
00614 }
00615
00616 unsigned int CSSStyleSelector::addInlineDeclarations(DOM::ElementImpl* e,
00617 DOM::CSSStyleDeclarationImpl *decl,
00618 unsigned int numProps)
00619 {
00620 CSSStyleDeclarationImpl* addDecls = 0;
00621 #ifdef APPLE_CHANGES
00622 if (e->id() == ID_TD || e->id() == ID_TH)
00623 addDecls = e->getAdditionalStyleDecls();
00624 #else
00625 Q_UNUSED( e );
00626 #endif
00627
00628 if (!decl && !addDecls)
00629 return numProps;
00630
00631 QPtrList<CSSProperty>* values = decl ? decl->values() : 0;
00632 QPtrList<CSSProperty>* addValues = addDecls ? addDecls->values() : 0;
00633 if (!values && !addValues)
00634 return numProps;
00635
00636 int firstLen = values ? values->count() : 0;
00637 int secondLen = addValues ? addValues->count() : 0;
00638 int totalLen = firstLen + secondLen;
00639
00640 if (inlineProps.size() < (uint)totalLen)
00641 inlineProps.resize(totalLen + 1);
00642
00643 if (numProps + totalLen >= propsToApplySize ) {
00644 propsToApplySize += propsToApplySize;
00645 propsToApply = (CSSOrderedProperty **)realloc( propsToApply, propsToApplySize*sizeof( CSSOrderedProperty * ) );
00646 }
00647
00648 CSSOrderedProperty *array = (CSSOrderedProperty *)inlineProps.data();
00649 for(int i = 0; i < totalLen; i++)
00650 {
00651 if (i == firstLen)
00652 values = addValues;
00653
00654 CSSProperty *prop = values->at(i >= firstLen ? i - firstLen : i);
00655 Source source = Inline;
00656
00657 if( prop->m_bImportant ) source = InlineImportant;
00658 if( prop->nonCSSHint ) source = NonCSSHint;
00659
00660 bool first;
00661
00662 switch(prop->m_id)
00663 {
00664 case CSS_PROP_FONT_STYLE:
00665 case CSS_PROP_FONT_SIZE:
00666 case CSS_PROP_FONT_WEIGHT:
00667 case CSS_PROP_FONT_FAMILY:
00668 case CSS_PROP_FONT:
00669 case CSS_PROP_COLOR:
00670 case CSS_PROP_BACKGROUND_IMAGE:
00671 case CSS_PROP_DISPLAY:
00672
00673
00674 first = true;
00675 break;
00676 default:
00677 first = false;
00678 break;
00679 }
00680
00681 array->prop = prop;
00682 array->pseudoId = RenderStyle::NOPSEUDO;
00683 array->selector = 0;
00684 array->position = i;
00685 array->priority = (!first << 30) | (source << 24);
00686 propsToApply[numProps++] = array++;
00687 }
00688 return numProps;
00689 }
00690
00691 static bool subject;
00692
00693
00694 static void cleanpath(QString &path)
00695 {
00696 int pos;
00697 while ( (pos = path.find( "/../" )) != -1 ) {
00698 int prev = 0;
00699 if ( pos > 0 )
00700 prev = path.findRev( "/", pos -1 );
00701
00702 if (prev < 0 || (prev > 3 && path.findRev("://", prev-1) == prev-2))
00703 path.remove( pos, 3);
00704 else
00705
00706 path.remove( prev, pos- prev + 3 );
00707 }
00708 pos = 0;
00709
00710
00711
00712
00713
00714 int refPos = -2;
00715 while ( (pos = path.find( "//", pos )) != -1) {
00716 if (refPos == -2)
00717 refPos = path.find("#", 0);
00718 if (refPos > 0 && pos >= refPos)
00719 break;
00720
00721 if ( pos == 0 || path[pos-1] != ':' )
00722 path.remove( pos, 1 );
00723 else
00724 pos += 2;
00725 }
00726 while ( (pos = path.find( "/./" )) != -1)
00727 path.remove( pos, 2 );
00728
00729 }
00730
00731 static void checkPseudoState( const CSSStyleSelector::Encodedurl& encodedurl, DOM::ElementImpl *e )
00732 {
00733 if( e->id() != ID_A ) {
00734 pseudoState = PseudoNone;
00735 return;
00736 }
00737 DOMString attr = e->getAttribute(ATTR_HREF);
00738 if( attr.isNull() ) {
00739 pseudoState = PseudoNone;
00740 return;
00741 }
00742 QConstString cu(attr.unicode(), attr.length());
00743 QString u = cu.string();
00744 if ( !u.contains("://") ) {
00745 if ( u[0] == '/' )
00746 u = encodedurl.host + u;
00747 else if ( u[0] == '#' )
00748 u = encodedurl.file + u;
00749 else
00750 u = encodedurl.path + u;
00751 cleanpath( u );
00752 }
00753
00754 pseudoState = KHTMLFactory::vLinks()->contains( u ) ? PseudoVisited : PseudoLink;
00755 }
00756
00757 void CSSStyleSelector::checkSelector(int selIndex, DOM::ElementImpl *e)
00758 {
00759 dynamicPseudo = RenderStyle::NOPSEUDO;
00760
00761 NodeImpl *n = e;
00762
00763 selectorCache[ selIndex ].state = Invalid;
00764 CSSSelector *sel = selectors[ selIndex ];
00765
00766
00767 subject = true;
00768
00769
00770
00771
00772 bool onlyHoverActive = (((sel->tag & NodeImpl_IdLocalMask) == NodeImpl_IdLocalMask) &&
00773 (sel->match == CSSSelector::Pseudo &&
00774 (sel->pseudoType() == CSSSelector::PseudoHover ||
00775 sel->pseudoType() == CSSSelector::PseudoActive)));
00776 bool affectedByHover = style->affectedByHoverRules();
00777 bool affectedByActive = style->affectedByActiveRules();
00778
00779
00780 if(!checkOneSelector(sel, e)) return;
00781
00782
00783 CSSSelector::Relation relation = sel->relation;
00784 while((sel = sel->tagHistory))
00785 {
00786 if(!n->isElementNode()) return;
00787 switch(relation)
00788 {
00789 case CSSSelector::Descendant:
00790 {
00791 bool found = false;
00792 while(!found)
00793 {
00794 subject = false;
00795 n = n->parentNode();
00796 if(!n || !n->isElementNode()) return;
00797 ElementImpl *elem = static_cast<ElementImpl *>(n);
00798 if(checkOneSelector(sel, elem)) found = true;
00799 }
00800 break;
00801 }
00802 case CSSSelector::Child:
00803 {
00804 subject = false;
00805 n = n->parentNode();
00806 if (!strictParsing)
00807 while (n && n->implicitNode()) n = n->parentNode();
00808 if(!n || !n->isElementNode()) return;
00809 ElementImpl *elem = static_cast<ElementImpl *>(n);
00810 if(!checkOneSelector(sel, elem)) return;
00811 break;
00812 }
00813 case CSSSelector::Sibling:
00814 {
00815 subject = false;
00816 n = n->previousSibling();
00817 while( n && !n->isElementNode() )
00818 n = n->previousSibling();
00819 if( !n ) return;
00820 ElementImpl *elem = static_cast<ElementImpl *>(n);
00821 if(!checkOneSelector(sel, elem)) return;
00822 break;
00823 }
00824 case CSSSelector::SubSelector:
00825 {
00826 if (onlyHoverActive)
00827 onlyHoverActive = (sel->match == CSSSelector::Pseudo &&
00828 (sel->pseudoType() == CSSSelector::PseudoHover ||
00829 sel->pseudoType() == CSSSelector::PseudoActive));
00830
00831
00832 ElementImpl *elem = static_cast<ElementImpl *>(n);
00833
00834 if ( dynamicPseudo != RenderStyle::NOPSEUDO ) {
00835 return;
00836 }
00837 if(!checkOneSelector(sel, elem)) return;
00838
00839 break;
00840 }
00841 }
00842 relation = sel->relation;
00843 }
00844
00845
00846 if (onlyHoverActive && subject) {
00847 if (pseudoState == PseudoUnknown)
00848 checkPseudoState( encodedurl, e );
00849
00850 if (pseudoState == PseudoNone) {
00851 if (!affectedByHover && style->affectedByHoverRules())
00852 style->setAffectedByHoverRules(false);
00853 if (!affectedByActive && style->affectedByActiveRules())
00854 style->setAffectedByActiveRules(false);
00855 return;
00856 }
00857 }
00858
00859 if ( dynamicPseudo != RenderStyle::NOPSEUDO ) {
00860 selectorCache[selIndex].state = AppliesPseudo;
00861 selectors[ selIndex ]->pseudoId = dynamicPseudo;
00862 } else
00863 selectorCache[ selIndex ].state = Applies;
00864
00865
00866 return;
00867 }
00868
00869 bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl *e)
00870 {
00871 if(!e)
00872 return false;
00873
00874 unsigned int element_id = e->id();
00875 if ( (sel->tag & NodeImpl_IdNSMask) == NodeImpl_IdNSMask ) {
00876
00877 unsigned int sel_id = sel->tag & NodeImpl_IdLocalMask;
00878 if ( (element_id & NodeImpl_IdLocalMask) != sel_id &&
00879 sel_id != NodeImpl_IdLocalMask )
00880 return false;
00881 } else {
00882
00883 if( (element_id & NodeImpl_IdNSMask) != (sel->tag & NodeImpl_IdNSMask) )
00884 return false;
00885 if ( element_id != sel->tag &&
00886 (sel->tag & NodeImpl_IdLocalMask) != NodeImpl_IdLocalMask )
00887 return false;
00888 }
00889
00890 if(sel->attr)
00891 {
00892 unsigned int attr_id = sel->attr;
00893 if ( (attr_id & NodeImpl_IdNSMask ) == NodeImpl_IdNSMask ) {
00894
00895
00896
00897
00898
00899
00900
00901
00902 attr_id &= NodeImpl_IdLocalMask;
00903 }
00904 DOMString value = e->getAttribute(attr_id);
00905 if(value.isNull()) return false;
00906
00907 switch(sel->match)
00908 {
00909 case CSSSelector::Exact:
00910 case CSSSelector::Id:
00911 if( (strictParsing && strcmp(sel->value, value) ) ||
00912 (!strictParsing && strcasecmp(sel->value, value)))
00913 return false;
00914 break;
00915 case CSSSelector::Set:
00916 break;
00917 case CSSSelector::List:
00918 {
00919 int spacePos = value.find(' ', 0);
00920 if (spacePos == -1) {
00921
00922
00923
00924 if( (strictParsing && strcmp(sel->value, value) ) ||
00925 (!strictParsing && strcasecmp(sel->value, value)))
00926 return false;
00927 break;
00928 }
00929
00930
00931 spacePos = sel->value.find(' ');
00932 if (spacePos != -1)
00933 return false;
00934
00935 QString str = value.string();
00936 QString selStr = sel->value.string();
00937 const int selStrlen = selStr.length();
00938 int pos = 0;
00939 for ( ;; ) {
00940 pos = str.find(selStr, pos, strictParsing);
00941 if ( pos == -1 ) return false;
00942 if ( pos == 0 || str[pos-1] == ' ' ) {
00943 uint endpos = pos + selStrlen;
00944 if ( endpos >= str.length() || str[endpos] == ' ' )
00945 break;
00946 }
00947 ++pos;
00948 }
00949 break;
00950 }
00951 case CSSSelector::Contain:
00952 {
00953
00954 QString str = value.string();
00955 QString selStr = sel->value.string();
00956 int pos = str.find(selStr, 0, strictParsing);
00957 if(pos == -1) return false;
00958 break;
00959 }
00960 case CSSSelector::Begin:
00961 {
00962
00963 QString str = value.string();
00964 QString selStr = sel->value.string();
00965 int pos = str.find(selStr, 0, strictParsing);
00966 if(pos != 0) return false;
00967 break;
00968 }
00969 case CSSSelector::End:
00970 {
00971
00972 QString str = value.string();
00973 QString selStr = sel->value.string();
00974 if (strictParsing && !str.endsWith(selStr)) return false;
00975 if (!strictParsing) {
00976 int pos = str.length() - selStr.length();
00977 if (pos < 0 || pos != str.find(selStr, pos, false) )
00978 return false;
00979 }
00980 break;
00981 }
00982 case CSSSelector::Hyphen:
00983 {
00984
00985 QString str = value.string();
00986 QString selStr = sel->value.string();
00987 if(str.length() < selStr.length()) return false;
00988
00989 if(str.find(selStr, 0, strictParsing) != 0) return false;
00990
00991 if(str.length() != selStr.length()
00992 && str[selStr.length()] != '-') return false;
00993 break;
00994 }
00995 case CSSSelector::Pseudo:
00996 case CSSSelector::None:
00997 break;
00998 }
00999 }
01000 if(sel->match == CSSSelector::Pseudo)
01001 {
01002
01003
01004
01005 switch (sel->pseudoType()) {
01006 case CSSSelector::PseudoEmpty:
01007 if (!e->firstChild())
01008 return true;
01009 break;
01010 case CSSSelector::PseudoFirstChild: {
01011
01012 if (e->parentNode() && e->parentNode()->isElementNode()) {
01013 DOM::NodeImpl* n = e->previousSibling();
01014 while ( n && !n->isElementNode() )
01015 n = n->previousSibling();
01016 if ( !n )
01017 return true;
01018 }
01019 break;
01020 }
01021 case CSSSelector::PseudoLastChild: {
01022
01023 if (e->parentNode() && e->parentNode()->isElementNode()) {
01024 DOM::NodeImpl* n = e->nextSibling();
01025 while ( n && !n->isElementNode() )
01026 n = n->nextSibling();
01027 if ( !n )
01028 return true;
01029 }
01030 break;
01031 }
01032 case CSSSelector::PseudoOnlyChild: {
01033
01034 if (e->parentNode() && e->parentNode()->isElementNode()) {
01035 DOM::NodeImpl* n = e->previousSibling();
01036 while ( n && !n->isElementNode() )
01037 n = n->previousSibling();
01038 if ( !n ) {
01039 n = e->nextSibling();
01040 while ( n && !n->isElementNode() )
01041 n = n->nextSibling();
01042 if ( !n )
01043 return true;
01044 }
01045 }
01046 break;
01047 }
01048 case CSSSelector::PseudoFirstLine:
01049 if ( subject ) {
01050 dynamicPseudo=RenderStyle::FIRST_LINE;
01051 return true;
01052 }
01053 break;
01054 case CSSSelector::PseudoFirstLetter:
01055 if ( subject ) {
01056 dynamicPseudo=RenderStyle::FIRST_LETTER;
01057 return true;
01058 }
01059 break;
01060 case CSSSelector::PseudoTarget:
01061 #ifdef APPLE_CHANGES
01062 if (!e->getDocument()->getCSSTarget() &&
01063 e == e->getDocument()->documentElement())
01064 return true;
01065 if (e == e->getDocument()->getCSSTarget())
01066 return true;
01067 #endif
01068 break;
01069 case CSSSelector::PseudoLink:
01070 if ( pseudoState == PseudoUnknown )
01071 checkPseudoState( encodedurl, e );
01072 if ( pseudoState == PseudoLink )
01073 return true;
01074 break;
01075 case CSSSelector::PseudoVisited:
01076 if ( pseudoState == PseudoUnknown )
01077 checkPseudoState( encodedurl, e );
01078 if ( pseudoState == PseudoVisited )
01079 return true;
01080 break;
01081 case CSSSelector::PseudoHover: {
01082
01083
01084 if (strictParsing || e->id() != ID_A || e->hasAnchor()) {
01085 if (element == e)
01086 style->setAffectedByHoverRules(true);
01087 if (e->renderer()) {
01088 if (element != e)
01089 e->renderer()->style()->setAffectedByHoverRules(true);
01090 if (e->renderer()->mouseInside())
01091 return true;
01092 }
01093 }
01094 break;
01095 }
01096 case CSSSelector::PseudoFocus:
01097 if (e && e->focused()) {
01098 return true;
01099 }
01100 break;
01101 case CSSSelector::PseudoActive:
01102
01103
01104 if (strictParsing || e->id() != ID_A || e->hasAnchor()) {
01105 if (element == e)
01106 style->setAffectedByActiveRules(true);
01107 else if (e->renderer())
01108 e->renderer()->style()->setAffectedByActiveRules(true);
01109 if (e->active())
01110 return true;
01111 }
01112 break;
01113 case CSSSelector::PseudoRoot:
01114 if (e == e->getDocument()->documentElement())
01115 return true;
01116 break;
01117 case CSSSelector::PseudoNot: {
01118
01119 for (CSSSelector* subSel = sel->simpleSelector; subSel;
01120 subSel = subSel->tagHistory) {
01121
01122
01123 if (subSel->simpleSelector)
01124 break;
01125 if (!checkOneSelector(subSel, e))
01126 return true;
01127 }
01128 break;
01129 }
01130 case CSSSelector::PseudoSelection:
01131 dynamicPseudo = RenderStyle::SELECTION;
01132 return true;
01133 case CSSSelector::PseudoBefore:
01134 dynamicPseudo = RenderStyle::BEFORE;
01135 return true;
01136 case CSSSelector::PseudoAfter:
01137 dynamicPseudo = RenderStyle::AFTER;
01138 return true;
01139
01140 case CSSSelector::PseudoNotParsed:
01141 assert(false);
01142 break;
01143 case CSSSelector::PseudoLang:
01144
01145 case CSSSelector::PseudoOther:
01146 break;
01147 }
01148 return false;
01149 }
01150
01151 return true;
01152 }
01153
01154 void CSSStyleSelector::clearLists()
01155 {
01156 delete [] selectors;
01157 if ( selectorCache ) {
01158 for ( unsigned int i = 0; i < selectors_size; i++ )
01159 delete [] selectorCache[i].props;
01160
01161 delete [] selectorCache;
01162 }
01163 if ( properties ) {
01164 CSSOrderedProperty **prop = properties;
01165 while ( *prop ) {
01166 delete (*prop);
01167 prop++;
01168 }
01169 delete [] properties;
01170 }
01171 selectors = 0;
01172 properties = 0;
01173 selectorCache = 0;
01174 }
01175
01176
01177 void CSSStyleSelector::buildLists()
01178 {
01179 clearLists();
01180
01181
01182 QPtrList<CSSSelector> selectorList;
01183 CSSOrderedPropertyList propertyList;
01184
01185 if(m_medium == "print" && defaultPrintStyle)
01186 defaultPrintStyle->collect( &selectorList, &propertyList, Default,
01187 Default );
01188 else if(defaultStyle) defaultStyle->collect( &selectorList, &propertyList,
01189 Default, Default );
01190
01191 if (!strictParsing && defaultQuirksStyle)
01192 defaultQuirksStyle->collect( &selectorList, &propertyList, Default, Default );
01193
01194 if(userStyle) userStyle->collect(&selectorList, &propertyList, User, UserImportant );
01195 if(authorStyle) authorStyle->collect(&selectorList, &propertyList, Author, AuthorImportant );
01196
01197 selectors_size = selectorList.count();
01198 selectors = new CSSSelector *[selectors_size];
01199 CSSSelector *s = selectorList.first();
01200 CSSSelector **sel = selectors;
01201 while ( s ) {
01202 *sel = s;
01203 s = selectorList.next();
01204 ++sel;
01205 }
01206
01207 selectorCache = new SelectorCache[selectors_size];
01208 for ( unsigned int i = 0; i < selectors_size; i++ ) {
01209 selectorCache[i].state = Unknown;
01210 selectorCache[i].props_size = 0;
01211 selectorCache[i].props = 0;
01212 }
01213
01214
01215 propertyList.sort();
01216 properties_size = propertyList.count() + 1;
01217 properties = new CSSOrderedProperty *[ properties_size ];
01218 CSSOrderedProperty *p = propertyList.first();
01219 CSSOrderedProperty **prop = properties;
01220 while ( p ) {
01221 *prop = p;
01222 p = propertyList.next();
01223 ++prop;
01224 }
01225 *prop = 0;
01226
01227 unsigned int* offsets = new unsigned int[selectors_size];
01228 if(properties[0])
01229 offsets[properties[0]->selector] = 0;
01230 for(unsigned int p = 1; p < properties_size; ++p) {
01231
01232 if(!properties[p] || (properties[p]->selector != properties[p - 1]->selector)) {
01233 unsigned int sel = properties[p - 1]->selector;
01234 int* newprops = new int[selectorCache[sel].props_size+2];
01235 for ( unsigned int i=0; i < selectorCache[sel].props_size; i++ )
01236 newprops[i] = selectorCache[sel].props[i];
01237
01238 newprops[selectorCache[sel].props_size] = offsets[sel];
01239 newprops[selectorCache[sel].props_size+1] = p - offsets[sel];
01240 delete [] selectorCache[sel].props;
01241 selectorCache[sel].props = newprops;
01242 selectorCache[sel].props_size += 2;
01243
01244 if(properties[p]) {
01245 sel = properties[p]->selector;
01246 offsets[sel] = p;
01247 }
01248 }
01249 }
01250 delete [] offsets;
01251
01252
01253 #if 0
01254
01255 for ( unsigned int sel = 0; sel < selectors_size; ++sel ) {
01256 kdDebug( 6080 ) << "trying for sel: " << sel << endl;
01257 int len = 0;
01258 int offset = 0;
01259 bool matches = false;
01260 for ( unsigned int i = 0; i < selectors_size; i++ ) {
01261 int tag = selectors[i]->tag;
01262 if ( sel != tag && tag != -1 )
01263 selectorCache[i].state = Invalid;
01264 else
01265 selectorCache[i].state = Unknown;
01266
01267 if ( matches != ( selectorCache[i].state == Unknown ) ) {
01268 if ( matches ) {
01269 kdDebug( 6080 ) << "new: offs: " << offset << " len: " << len << endl;
01270 matches = false;
01271 }
01272 else {
01273 matches = true;
01274
01275 len = 0;
01276 }
01277 }
01278 ++len;
01279 }
01280 }
01281 #endif
01282 }
01283
01284
01285
01286
01287
01288 CSSOrderedRule::CSSOrderedRule(DOM::CSSStyleRuleImpl *r, DOM::CSSSelector *s, int _index)
01289 {
01290 rule = r;
01291 if(rule) r->ref();
01292 index = _index;
01293 selector = s;
01294 }
01295
01296 CSSOrderedRule::~CSSOrderedRule()
01297 {
01298 if(rule) rule->deref();
01299 }
01300
01301
01302
01303 CSSStyleSelectorList::CSSStyleSelectorList()
01304 : QPtrList<CSSOrderedRule>()
01305 {
01306 setAutoDelete(true);
01307 }
01308 CSSStyleSelectorList::~CSSStyleSelectorList()
01309 {
01310 }
01311
01312 void CSSStyleSelectorList::append( CSSStyleSheetImpl *sheet,
01313 const DOMString &medium )
01314 {
01315 if(!sheet || !sheet->isCSSStyleSheet()) return;
01316
01317
01318
01319 if( sheet->media() && !sheet->media()->contains( medium ) )
01320 return;
01321
01322 int len = sheet->length();
01323
01324 for(int i = 0; i< len; i++)
01325 {
01326 StyleBaseImpl *item = sheet->item(i);
01327 if(item->isStyleRule())
01328 {
01329 CSSStyleRuleImpl *r = static_cast<CSSStyleRuleImpl *>(item);
01330 QPtrList<CSSSelector> *s = r->selector();
01331 for(int j = 0; j < (int)s->count(); j++)
01332 {
01333 CSSOrderedRule *rule = new CSSOrderedRule(r, s->at(j), count());
01334 QPtrList<CSSOrderedRule>::append(rule);
01335
01336 }
01337 }
01338 else if(item->isImportRule())
01339 {
01340 CSSImportRuleImpl *import = static_cast<CSSImportRuleImpl *>(item);
01341
01342
01343
01344
01345 if( !import->media() || import->media()->contains( medium ) )
01346 {
01347 CSSStyleSheetImpl *importedSheet = import->styleSheet();
01348 append( importedSheet, medium );
01349 }
01350 }
01351 else if( item->isMediaRule() )
01352 {
01353 CSSMediaRuleImpl *r = static_cast<CSSMediaRuleImpl *>( item );
01354 CSSRuleListImpl *rules = r->cssRules();
01355
01356
01357
01358
01359
01360 if( ( !r->media() || r->media()->contains( medium ) ) && rules)
01361 {
01362
01363
01364
01365 for( unsigned j = 0; j < rules->length(); j++ )
01366 {
01367
01368
01369 CSSRuleImpl *childItem = rules->item( j );
01370 if( childItem->isStyleRule() )
01371 {
01372
01373 CSSStyleRuleImpl *styleRule =
01374 static_cast<CSSStyleRuleImpl *>( childItem );
01375
01376 QPtrList<CSSSelector> *s = styleRule->selector();
01377 for( int j = 0; j < ( int ) s->count(); j++ )
01378 {
01379 CSSOrderedRule *orderedRule = new CSSOrderedRule(
01380 styleRule, s->at( j ), count() );
01381 QPtrList<CSSOrderedRule>::append( orderedRule );
01382 }
01383 }
01384 else
01385 {
01386
01387
01388 }
01389 }
01390 }
01391 else
01392 {
01393
01394
01395 }
01396 }
01397
01398 }
01399 }
01400
01401
01402 void CSSStyleSelectorList::collect( QPtrList<CSSSelector> *selectorList, CSSOrderedPropertyList *propList,
01403 Source regular, Source important )
01404 {
01405 CSSOrderedRule *r = first();
01406 while( r ) {
01407 CSSSelector *sel = selectorList->first();
01408 int selectorNum = 0;
01409 while( sel ) {
01410 if ( *sel == *(r->selector) )
01411 break;
01412 sel = selectorList->next();
01413 selectorNum++;
01414 }
01415 if ( !sel )
01416 selectorList->append( r->selector );
01417
01418
01419 propList->append(r->rule->declaration(), selectorNum, r->selector->specificity(), regular, important );
01420 r = next();
01421 }
01422 }
01423
01424
01425
01426 int CSSOrderedPropertyList::compareItems(QPtrCollection::Item i1, QPtrCollection::Item i2)
01427 {
01428 int diff = static_cast<CSSOrderedProperty *>(i1)->priority
01429 - static_cast<CSSOrderedProperty *>(i2)->priority;
01430 return diff ? diff : static_cast<CSSOrderedProperty *>(i1)->position
01431 - static_cast<CSSOrderedProperty *>(i2)->position;
01432 }
01433
01434 void CSSOrderedPropertyList::append(DOM::CSSStyleDeclarationImpl *decl, uint selector, uint specificity,
01435 Source regular, Source important )
01436 {
01437 QPtrList<CSSProperty> *values = decl->values();
01438 if(!values) return;
01439 int len = values->count();
01440 for(int i = 0; i < len; i++)
01441 {
01442 CSSProperty *prop = values->at(i);
01443 Source source = regular;
01444
01445 if( prop->m_bImportant ) source = important;
01446 if( prop->nonCSSHint ) source = NonCSSHint;
01447
01448 bool first = false;
01449
01450 switch(prop->m_id)
01451 {
01452 case CSS_PROP_FONT_STYLE:
01453 case CSS_PROP_FONT_SIZE:
01454 case CSS_PROP_FONT_WEIGHT:
01455 case CSS_PROP_FONT_FAMILY:
01456 case CSS_PROP_FONT:
01457 case CSS_PROP_COLOR:
01458 case CSS_PROP_BACKGROUND_IMAGE:
01459 case CSS_PROP_DISPLAY:
01460
01461
01462 first = true;
01463 break;
01464 default:
01465 break;
01466 }
01467
01468 QPtrList<CSSOrderedProperty>::append(new CSSOrderedProperty(prop, selector,
01469 first, source, specificity,
01470 count() ));
01471 }
01472 }
01473
01474
01475
01476
01477 static Length convertToLength( CSSPrimitiveValueImpl *primitiveValue, RenderStyle *style, QPaintDeviceMetrics *paintDeviceMetrics, bool *ok = 0 )
01478 {
01479 Length l;
01480 if ( !primitiveValue ) {
01481 if ( ok )
01482 *ok = false;
01483 } else {
01484 int type = primitiveValue->primitiveType();
01485 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
01486 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed);
01487 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
01488 l = Length(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE)), Percent);
01489 else if(type == CSSPrimitiveValue::CSS_NUMBER)
01490 l = Length(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_NUMBER)*100), Percent);
01491 else if (type == CSSPrimitiveValue::CSS_HTML_RELATIVE)
01492 l = Length(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_HTML_RELATIVE)), Relative);
01493 else if ( ok )
01494 *ok = false;
01495 }
01496 return l;
01497 }
01498
01499
01500
01501 struct colorMap {
01502 int css_value;
01503 QRgb color;
01504 };
01505
01506 static const colorMap cmap[] = {
01507 { CSS_VAL_AQUA, 0xFF00FFFF },
01508 { CSS_VAL_BLACK, 0xFF000000 },
01509 { CSS_VAL_BLUE, 0xFF0000FF },
01510 { CSS_VAL_CRIMSON, 0xFFDC143C },
01511 { CSS_VAL_FUCHSIA, 0xFFFF00FF },
01512 { CSS_VAL_GRAY, 0xFF808080 },
01513 { CSS_VAL_GREEN, 0xFF008000 },
01514 { CSS_VAL_INDIGO, 0xFF4B0082 },
01515 { CSS_VAL_LIME, 0xFF00FF00 },
01516 { CSS_VAL_MAROON, 0xFF800000 },
01517 { CSS_VAL_NAVY, 0xFF000080 },
01518 { CSS_VAL_OLIVE, 0xFF808000 },
01519 { CSS_VAL_ORANGE, 0xFFFFA500 },
01520 { CSS_VAL_PURPLE, 0xFF800080 },
01521 { CSS_VAL_RED, 0xFFFF0000 },
01522 { CSS_VAL_SILVER, 0xFFC0C0C0 },
01523 { CSS_VAL_TEAL, 0xFF008080 },
01524 { CSS_VAL_WHITE, 0xFFFFFFFF },
01525 { CSS_VAL_YELLOW, 0xFFFFFF00 },
01526 { CSS_VAL_INVERT, invertedColor },
01527 { CSS_VAL_TRANSPARENT, transparentColor },
01528 { CSS_VAL_GREY, 0xff808080 },
01529 { 0, 0 }
01530 };
01531
01532 struct uiColors {
01533 int css_value;
01534 const char * configGroup;
01535 const char * configEntry;
01536 QPalette::ColorGroup group;
01537 QColorGroup::ColorRole role;
01538 };
01539
01540 const char * const wmgroup = "WM";
01541 const char * const generalgroup = "General";
01542
01543
01544
01545
01546 static const uiColors uimap[] = {
01547
01548 { CSS_VAL_ACTIVEBORDER, wmgroup, "background", QPalette::Active, QColorGroup::Light },
01549
01550 { CSS_VAL_ACTIVECAPTION, wmgroup, "background", QPalette::Active, QColorGroup::Text },
01551
01552 { CSS_VAL_CAPTIONTEXT, wmgroup, "activeForeground", QPalette::Active, QColorGroup::Text },
01553
01554 { CSS_VAL_BUTTONFACE, wmgroup, 0, QPalette::Inactive, QColorGroup::Button },
01555
01556 { CSS_VAL_BUTTONHIGHLIGHT, wmgroup, 0, QPalette::Inactive, QColorGroup::Light },
01557
01558 { CSS_VAL_BUTTONSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Shadow },
01559
01560 { CSS_VAL_BUTTONTEXT, wmgroup, "buttonForeground", QPalette::Inactive, QColorGroup::ButtonText },
01561
01562 { CSS_VAL_THREEDDARKSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Dark },
01563
01564 { CSS_VAL_THREEDFACE, wmgroup, 0, QPalette::Inactive, QColorGroup::Button },
01565
01566 { CSS_VAL_THREEDHIGHLIGHT, wmgroup, 0, QPalette::Inactive, QColorGroup::Light },
01567
01568 { CSS_VAL_THREEDLIGHTSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Midlight },
01569
01570 { CSS_VAL_THREEDSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Shadow },
01571
01572
01573 { CSS_VAL_INACTIVEBORDER, wmgroup, "background", QPalette::Disabled, QColorGroup::Background },
01574
01575 { CSS_VAL_INACTIVECAPTION, wmgroup, "inactiveBackground", QPalette::Disabled, QColorGroup::Background },
01576
01577 { CSS_VAL_INACTIVECAPTIONTEXT, wmgroup, "inactiveForeground", QPalette::Disabled, QColorGroup::Text },
01578 { CSS_VAL_GRAYTEXT, wmgroup, 0, QPalette::Disabled, QColorGroup::Text },
01579
01580
01581 { CSS_VAL_MENU, generalgroup, "background", QPalette::Inactive, QColorGroup::Background },
01582
01583 { CSS_VAL_MENUTEXT, generalgroup, "foreground", QPalette::Inactive, QColorGroup::Background },
01584
01585
01586 { CSS_VAL_HIGHLIGHT, generalgroup, "selectBackground", QPalette::Inactive, QColorGroup::Background },
01587
01588
01589 { CSS_VAL_HIGHLIGHTTEXT, generalgroup, "selectForeground", QPalette::Inactive, QColorGroup::Background },
01590
01591
01592 { CSS_VAL_APPWORKSPACE, generalgroup, "background", QPalette::Inactive, QColorGroup::Text },
01593
01594
01595 { CSS_VAL_SCROLLBAR, generalgroup, "background", QPalette::Inactive, QColorGroup::Background },
01596
01597
01598 { CSS_VAL_WINDOW, generalgroup, "windowBackground", QPalette::Inactive, QColorGroup::Background },
01599
01600 { CSS_VAL_WINDOWFRAME, generalgroup, "windowBackground", QPalette::Inactive, QColorGroup::Background },
01601
01602 { CSS_VAL_WINDOWTEXT, generalgroup, "windowForeground", QPalette::Inactive, QColorGroup::Text },
01603 { CSS_VAL_TEXT, generalgroup, 0, QPalette::Inactive, QColorGroup::Text },
01604 { 0, 0, 0, QPalette::NColorGroups, QColorGroup::NColorRoles }
01605 };
01606
01607 static QColor colorForCSSValue( int css_value )
01608 {
01609
01610 const colorMap *col = cmap;
01611 while ( col->css_value && col->css_value != css_value )
01612 ++col;
01613 if ( col->css_value )
01614 return col->color;
01615
01616 const uiColors *uicol = uimap;
01617 while ( uicol->css_value && uicol->css_value != css_value )
01618 ++uicol;
01619 #ifndef APPLE_CHANGES
01620 if ( !uicol->css_value ) {
01621 if ( css_value == CSS_VAL_INFOBACKGROUND )
01622 return QToolTip::palette().inactive().background();
01623 else if ( css_value == CSS_VAL_INFOTEXT )
01624 return QToolTip::palette().inactive().foreground();
01625 else if ( css_value == CSS_VAL_BACKGROUND ) {
01626 KConfig bckgrConfig("kdesktoprc", true, false);
01627 bckgrConfig.setGroup("Desktop0");
01628
01629 return bckgrConfig.readColorEntry("Color1", &qApp->palette().disabled().background());
01630 }
01631 return QColor();
01632 }
01633 #endif
01634
01635 const QPalette &pal = qApp->palette();
01636 QColor c = pal.color( uicol->group, uicol->role );
01637 #ifndef APPLE_CHANGES
01638 if ( uicol->configEntry ) {
01639 KConfig *globalConfig = KGlobal::config();
01640 globalConfig->setGroup( uicol->configGroup );
01641 c = globalConfig->readColorEntry( uicol->configEntry, &c );
01642 }
01643 #endif
01644
01645 return c;
01646 }
01647
01648
01649 void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
01650 {
01651
01652
01653 CSSPrimitiveValueImpl *primitiveValue = 0;
01654 if(value->isPrimitiveValue()) primitiveValue = static_cast<CSSPrimitiveValueImpl *>(value);
01655
01656 Length l;
01657 bool apply = false;
01658
01659 bool isInherit = (parentNode && value->cssValueType() == CSSValue::CSS_INHERIT);
01660 bool isInitial = (value->cssValueType() == CSSValue::CSS_INITIAL) ||
01661 (!parentNode && value->cssValueType() == CSSValue::CSS_INHERIT);
01662
01663
01664
01665
01666 switch(id)
01667 {
01668
01669 case CSS_PROP_BACKGROUND_ATTACHMENT:
01670 HANDLE_INHERIT_AND_INITIAL(backgroundAttachment, BackgroundAttachment)
01671 if(!primitiveValue) break;
01672 switch(primitiveValue->getIdent())
01673 {
01674 case CSS_VAL_FIXED:
01675 {
01676 style->setBackgroundAttachment(false);
01677
01678 if( style->backgroundImage() )
01679 view->useSlowRepaints();
01680 break;
01681 }
01682 case CSS_VAL_SCROLL:
01683 style->setBackgroundAttachment(true);
01684 break;
01685 default:
01686 return;
01687 }
01688 case CSS_PROP_BACKGROUND_REPEAT:
01689 {
01690 HANDLE_INHERIT_AND_INITIAL(backgroundRepeat, BackgroundRepeat)
01691 if(!primitiveValue) return;
01692 switch(primitiveValue->getIdent())
01693 {
01694 case CSS_VAL_REPEAT:
01695 style->setBackgroundRepeat( REPEAT );
01696 break;
01697 case CSS_VAL_REPEAT_X:
01698 style->setBackgroundRepeat( REPEAT_X );
01699 break;
01700 case CSS_VAL_REPEAT_Y:
01701 style->setBackgroundRepeat( REPEAT_Y );
01702 break;
01703 case CSS_VAL_NO_REPEAT:
01704 style->setBackgroundRepeat( NO_REPEAT );
01705 break;
01706 default:
01707 return;
01708 }
01709 }
01710 case CSS_PROP_BORDER_COLLAPSE:
01711 HANDLE_INHERIT_AND_INITIAL(borderCollapse, BorderCollapse)
01712 if(!primitiveValue) break;
01713 switch(primitiveValue->getIdent())
01714 {
01715 case CSS_VAL_COLLAPSE:
01716 style->setBorderCollapse(true);
01717 break;
01718 case CSS_VAL_SEPARATE:
01719 style->setBorderCollapse(false);
01720 break;
01721 default:
01722 return;
01723 }
01724 break;
01725
01726 case CSS_PROP_BORDER_TOP_STYLE:
01727 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderTopStyle, BorderTopStyle, BorderStyle)
01728 if (!primitiveValue) return;
01729 style->setBorderTopStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE));
01730 break;
01731 case CSS_PROP_BORDER_RIGHT_STYLE:
01732 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderRightStyle, BorderRightStyle, BorderStyle)
01733 if (!primitiveValue) return;
01734 style->setBorderRightStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE));
01735 break;
01736 case CSS_PROP_BORDER_BOTTOM_STYLE:
01737 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderBottomStyle, BorderBottomStyle, BorderStyle)
01738 if (!primitiveValue) return;
01739 style->setBorderBottomStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE));
01740 break;
01741 case CSS_PROP_BORDER_LEFT_STYLE:
01742 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderLeftStyle, BorderLeftStyle, BorderStyle)
01743 if (!primitiveValue) return;
01744 style->setBorderLeftStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE));
01745 break;
01746 case CSS_PROP_OUTLINE_STYLE:
01747 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(outlineStyle, OutlineStyle, BorderStyle)
01748 if (!primitiveValue) return;
01749 style->setOutlineStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE));
01750 break;
01751 case CSS_PROP_CAPTION_SIDE:
01752 {
01753 HANDLE_INHERIT_AND_INITIAL(captionSide, CaptionSide)
01754 if(!primitiveValue) break;
01755 ECaptionSide c = RenderStyle::initialCaptionSide();
01756 switch(primitiveValue->getIdent())
01757 {
01758 case CSS_VAL_TOP:
01759 c = CAPTOP; break;
01760 case CSS_VAL_BOTTOM:
01761 c = CAPBOTTOM; break;
01762 default:
01763 return;
01764 }
01765 style->setCaptionSide(c);
01766 return;
01767 }
01768 case CSS_PROP_CLEAR:
01769 {
01770 HANDLE_INHERIT_AND_INITIAL(clear, Clear)
01771 if(!primitiveValue) break;
01772 EClear c = CNONE;
01773 switch(primitiveValue->getIdent())
01774 {
01775 case CSS_VAL_LEFT:
01776 c = CLEFT; break;
01777 case CSS_VAL_RIGHT:
01778 c = CRIGHT; break;
01779 case CSS_VAL_BOTH:
01780 c = CBOTH; break;
01781 case CSS_VAL_NONE:
01782 c = CNONE; break;
01783 default:
01784 return;
01785 }
01786 style->setClear(c);
01787 return;
01788 }
01789 case CSS_PROP_DIRECTION:
01790 {
01791 HANDLE_INHERIT_AND_INITIAL(direction, Direction)
01792 if(!primitiveValue) break;
01793 style->setDirection( (EDirection) (primitiveValue->getIdent() - CSS_VAL_LTR) );
01794 return;
01795 }
01796 case CSS_PROP_DISPLAY:
01797 {
01798 HANDLE_INHERIT_AND_INITIAL(display, Display)
01799 if(!primitiveValue) break;
01800 int id = primitiveValue->getIdent();
01801 style->setDisplay( id == CSS_VAL_NONE ? NONE : EDisplay(id - CSS_VAL_INLINE) );
01802 break;
01803 }
01804
01805 case CSS_PROP_EMPTY_CELLS:
01806 {
01807 HANDLE_INHERIT(emptyCells, EmptyCells);
01808 if (!primitiveValue) break;
01809 int id = primitiveValue->getIdent();
01810 if (id == CSS_VAL_SHOW)
01811 style->setEmptyCells(SHOW);
01812 else if (id == CSS_VAL_HIDE)
01813 style->setEmptyCells(HIDE);
01814 break;
01815 }
01816 case CSS_PROP_FLOAT:
01817 {
01818 HANDLE_INHERIT_AND_INITIAL(floating, Floating)
01819 if(!primitiveValue) return;
01820 EFloat f;
01821 switch(primitiveValue->getIdent())
01822 {
01823 case CSS_VAL_LEFT:
01824 f = FLEFT; break;
01825 case CSS_VAL_RIGHT:
01826 f = FRIGHT; break;
01827 case CSS_VAL_NONE:
01828 case CSS_VAL_CENTER:
01829 f = FNONE; break;
01830 default:
01831 return;
01832 }
01833 if (f!=FNONE && style->display()==LIST_ITEM)
01834 style->setDisplay(BLOCK);
01835
01836 style->setFloating(f);
01837 break;
01838 }
01839
01840 case CSS_PROP_FONT_STYLE:
01841 {
01842 FontDef fontDef = style->htmlFont().fontDef;
01843 if (isInherit)
01844 fontDef.italic = parentStyle->htmlFont().fontDef.italic;
01845 else if (isInitial)
01846 fontDef.italic = false;
01847 else {
01848 if(!primitiveValue) return;
01849 switch(primitiveValue->getIdent()) {
01850 case CSS_VAL_OBLIQUE:
01851
01852 case CSS_VAL_ITALIC:
01853 fontDef.italic = true;
01854 break;
01855 case CSS_VAL_NORMAL:
01856 fontDef.italic = false;
01857 break;
01858 default:
01859 return;
01860 }
01861 }
01862 fontDirty |= style->setFontDef( fontDef );
01863 break;
01864 }
01865
01866
01867 case CSS_PROP_FONT_VARIANT:
01868 {
01869 FontDef fontDef = style->htmlFont().fontDef;
01870 if (isInherit)
01871 fontDef.smallCaps = parentStyle->htmlFont().fontDef.weight;
01872 else if (isInitial)
01873 fontDef.smallCaps = false;
01874 else {
01875 if(!primitiveValue) return;
01876 int id = primitiveValue->getIdent();
01877 if ( id == CSS_VAL_NORMAL )
01878 fontDef.smallCaps = false;
01879 else if ( id == CSS_VAL_SMALL_CAPS )
01880 fontDef.smallCaps = true;
01881 else
01882 return;
01883 }
01884 fontDirty |= style->setFontDef( fontDef );
01885 break;
01886 }
01887
01888 case CSS_PROP_FONT_WEIGHT:
01889 {
01890 FontDef fontDef = style->htmlFont().fontDef;
01891 if (isInherit)
01892 fontDef.weight = parentStyle->htmlFont().fontDef.weight;
01893 else if (isInitial)
01894 fontDef.weight = QFont::Normal;
01895 else {
01896 if(!primitiveValue) return;
01897 if(primitiveValue->getIdent())
01898 {
01899 switch(primitiveValue->getIdent()) {
01900
01901
01902 case CSS_VAL_BOLD:
01903 case CSS_VAL_BOLDER:
01904 case CSS_VAL_600:
01905 case CSS_VAL_700:
01906 case CSS_VAL_800:
01907 case CSS_VAL_900:
01908 fontDef.weight = QFont::Bold;
01909 break;
01910 case CSS_VAL_NORMAL:
01911 case CSS_VAL_LIGHTER:
01912 case CSS_VAL_100:
01913 case CSS_VAL_200:
01914 case CSS_VAL_300:
01915 case CSS_VAL_400:
01916 case CSS_VAL_500:
01917 fontDef.weight = QFont::Normal;
01918 break;
01919 default:
01920 return;
01921 }
01922 }
01923 else
01924 {
01925
01926 }
01927 }
01928 fontDirty |= style->setFontDef( fontDef );
01929 break;
01930 }
01931
01932 case CSS_PROP_LIST_STYLE_POSITION:
01933 {
01934 HANDLE_INHERIT_AND_INITIAL(listStylePosition, ListStylePosition)
01935 if (!primitiveValue) return;
01936 if (primitiveValue->getIdent())
01937 style->setListStylePosition( (EListStylePosition) (primitiveValue->getIdent() - CSS_VAL_OUTSIDE) );
01938 return;
01939 }
01940
01941 case CSS_PROP_LIST_STYLE_TYPE:
01942 {
01943 HANDLE_INHERIT_AND_INITIAL(listStyleType, ListStyleType)
01944 if (!primitiveValue) return;
01945 if (primitiveValue->getIdent())
01946 {
01947 EListStyleType t;
01948 int id = primitiveValue->getIdent();
01949 if ( id == CSS_VAL_NONE) {
01950 t = LNONE;
01951 } else {
01952 t = EListStyleType(id - CSS_VAL_DISC);
01953 }
01954 style->setListStyleType(t);
01955 }
01956 return;
01957 }
01958
01959 case CSS_PROP_OVERFLOW:
01960 {
01961 HANDLE_INHERIT_AND_INITIAL(overflow, Overflow)
01962 if (!primitiveValue) return;
01963 EOverflow o;
01964 switch(primitiveValue->getIdent())
01965 {
01966 case CSS_VAL_VISIBLE:
01967 o = OVISIBLE; break;
01968 case CSS_VAL_HIDDEN:
01969 o = OHIDDEN; break;
01970 case CSS_VAL_SCROLL:
01971 o = OSCROLL; break;
01972 case CSS_VAL_AUTO:
01973 o = OAUTO; break;
01974 case CSS_VAL_MARQUEE:
01975 o = OMARQUEE; break;
01976 default:
01977 return;
01978 }
01979 style->setOverflow(o);
01980 return;
01981 }
01982 break;
01983 case CSS_PROP_PAGE_BREAK_AFTER:
01984 case CSS_PROP_PAGE_BREAK_BEFORE:
01985 case CSS_PROP_PAGE_BREAK_INSIDE:
01986
01987
01988 break;
01989
01990 case CSS_PROP_POSITION:
01991 {
01992 HANDLE_INHERIT_AND_INITIAL(position, Position)
01993 if (!primitiveValue) return;
01994 EPosition p;
01995 switch(primitiveValue->getIdent())
01996 {
01997 case CSS_VAL_STATIC:
01998 p = STATIC; break;
01999 case CSS_VAL_RELATIVE:
02000 p = RELATIVE; break;
02001 case CSS_VAL_ABSOLUTE:
02002 p = ABSOLUTE; break;
02003 case CSS_VAL_FIXED:
02004 {
02005 view->useSlowRepaints();
02006 p = FIXED;
02007 break;
02008 }
02009 default:
02010 return;
02011 }
02012 style->setPosition(p);
02013 return;
02014 }
02015
02016 case CSS_PROP_TABLE_LAYOUT: {
02017 HANDLE_INHERIT_AND_INITIAL(tableLayout, TableLayout)
02018
02019 if ( !primitiveValue )
02020 return;
02021
02022 ETableLayout l = RenderStyle::initialTableLayout();
02023 switch( primitiveValue->getIdent() ) {
02024 case CSS_VAL_FIXED:
02025 l = TFIXED;
02026
02027 case CSS_VAL_AUTO:
02028 style->setTableLayout( l );
02029 default:
02030 break;
02031 }
02032 break;
02033 }
02034
02035 case CSS_PROP_UNICODE_BIDI: {
02036 HANDLE_INHERIT_AND_INITIAL(unicodeBidi, UnicodeBidi)
02037 switch (primitiveValue->getIdent()) {
02038 case CSS_VAL_NORMAL:
02039 style->setUnicodeBidi(UBNormal);
02040 break;
02041 case CSS_VAL_EMBED:
02042 style->setUnicodeBidi(Embed);
02043 break;
02044 case CSS_VAL_BIDI_OVERRIDE:
02045 style->setUnicodeBidi(Override);
02046 break;
02047 default:
02048 return;
02049 }
02050 break;
02051 }
02052 case CSS_PROP_TEXT_TRANSFORM: {
02053 HANDLE_INHERIT_AND_INITIAL(textTransform, TextTransform)
02054
02055 if(!primitiveValue->getIdent()) return;
02056
02057 ETextTransform tt;
02058 switch(primitiveValue->getIdent()) {
02059 case CSS_VAL_CAPITALIZE: tt = CAPITALIZE; break;
02060 case CSS_VAL_UPPERCASE: tt = UPPERCASE; break;
02061 case CSS_VAL_LOWERCASE: tt = LOWERCASE; break;
02062 case CSS_VAL_NONE:
02063 default: tt = TTNONE; break;
02064 }
02065 style->setTextTransform(tt);
02066 break;
02067 }
02068
02069 case CSS_PROP_VISIBILITY:
02070 {
02071 HANDLE_INHERIT_AND_INITIAL(visibility, Visibility)
02072
02073 switch( primitiveValue->getIdent() ) {
02074 case CSS_VAL_HIDDEN:
02075 style->setVisibility( HIDDEN );
02076 break;
02077 case CSS_VAL_VISIBLE:
02078 style->setVisibility( VISIBLE );
02079 break;
02080 case CSS_VAL_COLLAPSE:
02081 style->setVisibility( COLLAPSE );
02082 default:
02083 break;
02084 }
02085 break;
02086 }
02087 case CSS_PROP_WHITE_SPACE:
02088 HANDLE_INHERIT_AND_INITIAL(whiteSpace, WhiteSpace)
02089
02090 if(!primitiveValue->getIdent()) return;
02091
02092 EWhiteSpace s;
02093 switch(primitiveValue->getIdent()) {
02094 case CSS_VAL__KHTML_NOWRAP:
02095 s = KHTML_NOWRAP;
02096 break;
02097 case CSS_VAL_NOWRAP:
02098 s = NOWRAP;
02099 break;
02100 case CSS_VAL_PRE:
02101 s = PRE;
02102 break;
02103 case CSS_VAL_NORMAL:
02104 default:
02105 s = NORMAL;
02106 break;
02107 }
02108 style->setWhiteSpace(s);
02109 break;
02110
02111 case CSS_PROP_BACKGROUND_POSITION:
02112 if (isInherit) {
02113 style->setBackgroundXPosition(parentStyle->backgroundXPosition());
02114 style->setBackgroundYPosition(parentStyle->backgroundYPosition());
02115 }
02116 else if (isInitial) {
02117 style->setBackgroundXPosition(RenderStyle::initialBackgroundXPosition());
02118 style->setBackgroundYPosition(RenderStyle::initialBackgroundYPosition());
02119 }
02120 break;
02121 case CSS_PROP_BACKGROUND_POSITION_X: {
02122 HANDLE_INHERIT_AND_INITIAL(backgroundXPosition, BackgroundXPosition)
02123 if(!primitiveValue) break;
02124 Length l;
02125 int type = primitiveValue->primitiveType();
02126 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
02127 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed);
02128 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
02129 l = Length((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
02130 else
02131 return;
02132 style->setBackgroundXPosition(l);
02133 break;
02134 }
02135 case CSS_PROP_BACKGROUND_POSITION_Y: {
02136 HANDLE_INHERIT_AND_INITIAL(backgroundYPosition, BackgroundYPosition)
02137 if(!primitiveValue) break;
02138 Length l;
02139 int type = primitiveValue->primitiveType();
02140 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
02141 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed);
02142 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
02143 l = Length((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
02144 else
02145 return;
02146 style->setBackgroundYPosition(l);
02147 break;
02148 }
02149 case CSS_PROP_BORDER_SPACING:
02150 assert( false );
02151
02152 case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING: {
02153 HANDLE_INHERIT_AND_INITIAL(borderHorizontalSpacing, BorderHorizontalSpacing)
02154 if (!primitiveValue) break;
02155 short spacing = primitiveValue->computeLength(style, paintDeviceMetrics);
02156 style->setBorderHorizontalSpacing(spacing);
02157 break;
02158 }
02159 case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING: {
02160 HANDLE_INHERIT_AND_INITIAL(borderVerticalSpacing, BorderVerticalSpacing)
02161 if (!primitiveValue) break;
02162 short spacing = primitiveValue->computeLength(style, paintDeviceMetrics);
02163 style->setBorderVerticalSpacing(spacing);
02164 break;
02165 }
02166
02167 case CSS_PROP_CURSOR:
02168 HANDLE_INHERIT_AND_INITIAL(cursor, Cursor)
02169 if(primitiveValue)
02170 style->setCursor( (ECursor) (primitiveValue->getIdent() - CSS_VAL_AUTO) );
02171 break;
02172
02173 case CSS_PROP_BACKGROUND_COLOR:
02174 case CSS_PROP_BORDER_TOP_COLOR:
02175 case CSS_PROP_BORDER_RIGHT_COLOR:
02176 case CSS_PROP_BORDER_BOTTOM_COLOR:
02177 case CSS_PROP_BORDER_LEFT_COLOR:
02178 case CSS_PROP_COLOR:
02179 case CSS_PROP_OUTLINE_COLOR:
02180
02181 case CSS_PROP_SCROLLBAR_FACE_COLOR:
02182 case CSS_PROP_SCROLLBAR_SHADOW_COLOR:
02183 case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR:
02184 case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR:
02185 case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR:
02186 case CSS_PROP_SCROLLBAR_TRACK_COLOR:
02187 case CSS_PROP_SCROLLBAR_ARROW_COLOR:
02188 {
02189 QColor col;
02190 if (isInherit) {
02191 HANDLE_INHERIT_COND(CSS_PROP_BACKGROUND_COLOR, backgroundColor, BackgroundColor)
02192 HANDLE_INHERIT_COND(CSS_PROP_BORDER_TOP_COLOR, borderTopColor, BorderTopColor)
02193 HANDLE_INHERIT_COND(CSS_PROP_BORDER_BOTTOM_COLOR, borderBottomColor, BorderBottomColor)
02194 HANDLE_INHERIT_COND(CSS_PROP_BORDER_RIGHT_COLOR, borderRightColor, BorderRightColor)
02195 HANDLE_INHERIT_COND(CSS_PROP_BORDER_LEFT_COLOR, borderLeftColor, BorderLeftColor)
02196 HANDLE_INHERIT_COND(CSS_PROP_COLOR, color, Color)
02197 HANDLE_INHERIT_COND(CSS_PROP_OUTLINE_COLOR, outlineColor, OutlineColor)
02198 return;
02199 } else if (isInitial) {
02200
02201
02202
02203 if (id == CSS_PROP_COLOR)
02204 col = RenderStyle::initialColor();
02205 } else {
02206 if(!primitiveValue )
02207 return;
02208 int ident = primitiveValue->getIdent();
02209 if ( ident ) {
02210 if ( ident == CSS_VAL__KHTML_TEXT )
02211 col = element->getDocument()->textColor();
02212
02213 else if ( ident == CSS_VAL_TRANSPARENT
02214 && id != CSS_PROP_BORDER_TOP_COLOR
02215 && id != CSS_PROP_BORDER_RIGHT_COLOR
02216 && id != CSS_PROP_BORDER_BOTTOM_COLOR
02217 && id != CSS_PROP_BORDER_LEFT_COLOR )
02218 col = QColor();
02219 else
02220 col = colorForCSSValue( ident );
02221 } else if ( primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR ) {
02222 #ifndef APPLE_CHANGES
02223 if(qAlpha(primitiveValue->getRGBColorValue()))
02224 #endif
02225 col.setRgb(primitiveValue->getRGBColorValue());
02226 } else {
02227 return;
02228 }
02229 }
02230
02231 switch(id)
02232 {
02233 case CSS_PROP_BACKGROUND_COLOR:
02234 style->setBackgroundColor(col); break;
02235 case CSS_PROP_BORDER_TOP_COLOR:
02236 style->setBorderTopColor(col); break;
02237 case CSS_PROP_BORDER_RIGHT_COLOR:
02238 style->setBorderRightColor(col); break;
02239 case CSS_PROP_BORDER_BOTTOM_COLOR:
02240 style->setBorderBottomColor(col); break;
02241 case CSS_PROP_BORDER_LEFT_COLOR:
02242 style->setBorderLeftColor(col); break;
02243 case CSS_PROP_COLOR:
02244 style->setColor(col); break;
02245 case CSS_PROP__KHTML_TEXT_DECORATION_COLOR:
02246 style->setTextDecorationColor(col); break;
02247 case CSS_PROP_OUTLINE_COLOR:
02248 style->setOutlineColor(col); break;
02249 #ifndef APPLE_CHANGES
02250 case CSS_PROP_SCROLLBAR_FACE_COLOR:
02251 style->setPaletteColor(QPalette::Active, QColorGroup::Button, col);
02252 style->setPaletteColor(QPalette::Inactive, QColorGroup::Button, col);
02253 break;
02254 case CSS_PROP_SCROLLBAR_SHADOW_COLOR:
02255 style->setPaletteColor(QPalette::Active, QColorGroup::Shadow, col);
02256 style->setPaletteColor(QPalette::Inactive, QColorGroup::Shadow, col);
02257 break;
02258 case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR:
02259 style->setPaletteColor(QPalette::Active, QColorGroup::Light, col);
02260 style->setPaletteColor(QPalette::Inactive, QColorGroup::Light, col);
02261 break;
02262 case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR:
02263 break;
02264 case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR:
02265 style->setPaletteColor(QPalette::Active, QColorGroup::Dark, col);
02266 style->setPaletteColor(QPalette::Inactive, QColorGroup::Dark, col);
02267 break;
02268 case CSS_PROP_SCROLLBAR_TRACK_COLOR:
02269 style->setPaletteColor(QPalette::Active, QColorGroup::Mid, col);
02270 style->setPaletteColor(QPalette::Inactive, QColorGroup::Mid, col);
02271 style->setPaletteColor(QPalette::Active, QColorGroup::Background, col);
02272 style->setPaletteColor(QPalette::Inactive, QColorGroup::Background, col);
02273
02274 case CSS_PROP_SCROLLBAR_BASE_COLOR:
02275 style->setPaletteColor(QPalette::Active, QColorGroup::Base, col);
02276 style->setPaletteColor(QPalette::Inactive, QColorGroup::Base, col);
02277 break;
02278 case CSS_PROP_SCROLLBAR_ARROW_COLOR:
02279 style->setPaletteColor(QPalette::Active, QColorGroup::ButtonText, col);
02280 style->setPaletteColor(QPalette::Inactive, QColorGroup::ButtonText, col);
02281 break;
02282 #endif
02283 default:
02284 return;
02285 }
02286 return;
02287 }
02288 break;
02289
02290 case CSS_PROP_BACKGROUND_IMAGE:
02291 {
02292 HANDLE_INHERIT_AND_INITIAL(backgroundImage, BackgroundImage)
02293 if (!primitiveValue) return;
02294 style->setBackgroundImage(static_cast<CSSImageValueImpl *>(primitiveValue)->image());
02295
02296 break;
02297 }
02298 case CSS_PROP_LIST_STYLE_IMAGE:
02299 {
02300 HANDLE_INHERIT_AND_INITIAL(listStyleImage, ListStyleImage)
02301 if (!primitiveValue) return;
02302 style->setListStyleImage(static_cast<CSSImageValueImpl *>(primitiveValue)->image());
02303
02304 break;
02305 }
02306
02307
02308 case CSS_PROP_BORDER_TOP_WIDTH:
02309 case CSS_PROP_BORDER_RIGHT_WIDTH:
02310 case CSS_PROP_BORDER_BOTTOM_WIDTH:
02311 case CSS_PROP_BORDER_LEFT_WIDTH:
02312 case CSS_PROP_OUTLINE_WIDTH:
02313 {
02314 if (isInherit) {
02315 HANDLE_INHERIT_COND(CSS_PROP_BORDER_TOP_WIDTH, borderTopWidth, BorderTopWidth)
02316 HANDLE_INHERIT_COND(CSS_PROP_BORDER_RIGHT_WIDTH, borderRightWidth, BorderRightWidth)
02317 HANDLE_INHERIT_COND(CSS_PROP_BORDER_BOTTOM_WIDTH, borderBottomWidth, BorderBottomWidth)
02318 HANDLE_INHERIT_COND(CSS_PROP_BORDER_LEFT_WIDTH, borderLeftWidth, BorderLeftWidth)
02319 HANDLE_INHERIT_COND(CSS_PROP_OUTLINE_WIDTH, outlineWidth, OutlineWidth)
02320 return;
02321 }
02322 else if (isInitial) {
02323 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BORDER_TOP_WIDTH, BorderTopWidth, BorderWidth)
02324 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BORDER_RIGHT_WIDTH, BorderRightWidth, BorderWidth)
02325 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BORDER_BOTTOM_WIDTH, BorderBottomWidth, BorderWidth)
02326 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BORDER_LEFT_WIDTH, BorderLeftWidth, BorderWidth)
02327 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_OUTLINE_WIDTH, OutlineWidth, BorderWidth)
02328 return;
02329 }
02330
02331 if(!primitiveValue) break;
02332 short width = 3;
02333 switch(primitiveValue->getIdent())
02334 {
02335 case CSS_VAL_THIN:
02336 width = 1;
02337 break;
02338 case CSS_VAL_MEDIUM:
02339 width = 3;
02340 break;
02341 case CSS_VAL_THICK:
02342 width = 5;
02343 break;
02344 case CSS_VAL_INVALID:
02345 {
02346 double widthd = primitiveValue->computeLengthFloat(style, paintDeviceMetrics);
02347 width = (int)widthd;
02348
02349
02350 if (width == 0 && widthd >= 0.025) width++;
02351 break;
02352 }
02353 default:
02354 return;
02355 }
02356
02357 if(width < 0) return;
02358 switch(id)
02359 {
02360 case CSS_PROP_BORDER_TOP_WIDTH:
02361 style->setBorderTopWidth(width);
02362 break;
02363 case CSS_PROP_BORDER_RIGHT_WIDTH:
02364 style->setBorderRightWidth(width);
02365 break;
02366 case CSS_PROP_BORDER_BOTTOM_WIDTH:
02367 style->setBorderBottomWidth(width);
02368 break;
02369 case CSS_PROP_BORDER_LEFT_WIDTH:
02370 style->setBorderLeftWidth(width);
02371 break;
02372 case CSS_PROP_OUTLINE_WIDTH:
02373 style->setOutlineWidth(width);
02374 break;
02375 default:
02376 return;
02377 }
02378 return;
02379 }
02380
02381 case CSS_PROP_LETTER_SPACING:
02382 case CSS_PROP_WORD_SPACING:
02383 {
02384 if (isInherit) {
02385 HANDLE_INHERIT_COND(CSS_PROP_LETTER_SPACING, letterSpacing, LetterSpacing)
02386 HANDLE_INHERIT_COND(CSS_PROP_WORD_SPACING, wordSpacing, WordSpacing)
02387 return;
02388 } else if (isInitial) {
02389 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_LETTER_SPACING, LetterSpacing, LetterWordSpacing)
02390 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_WORD_SPACING, WordSpacing, LetterWordSpacing)
02391 return;
02392 }
02393 if(!primitiveValue) return;
02394
02395 int width = 0;
02396 if (primitiveValue->getIdent() != CSS_VAL_NORMAL)
02397 width = primitiveValue->computeLength(style, paintDeviceMetrics);
02398
02399 switch(id)
02400 {
02401 case CSS_PROP_LETTER_SPACING:
02402 style->setLetterSpacing(width);
02403 break;
02404 case CSS_PROP_WORD_SPACING:
02405 style->setWordSpacing(width);
02406 break;
02407
02408 default: break;
02409 }
02410 return;
02411 }
02412
02413
02414 case CSS_PROP_MAX_WIDTH:
02415
02416 if(primitiveValue && primitiveValue->getIdent() == CSS_VAL_NONE)
02417 apply = true;
02418 case CSS_PROP_TOP:
02419 case CSS_PROP_LEFT:
02420 case CSS_PROP_RIGHT:
02421 case CSS_PROP_BOTTOM:
02422 case CSS_PROP_WIDTH:
02423 case CSS_PROP_MIN_WIDTH:
02424 case CSS_PROP_MARGIN_TOP:
02425 case CSS_PROP_MARGIN_RIGHT:
02426 case CSS_PROP_MARGIN_BOTTOM:
02427 case CSS_PROP_MARGIN_LEFT:
02428
02429 if(id != CSS_PROP_MAX_WIDTH && primitiveValue &&
02430 primitiveValue->getIdent() == CSS_VAL_AUTO)
02431 {
02432
02433 apply = true;
02434 }
02435 case CSS_PROP_PADDING_TOP:
02436 case CSS_PROP_PADDING_RIGHT:
02437 case CSS_PROP_PADDING_BOTTOM:
02438 case CSS_PROP_PADDING_LEFT:
02439 case CSS_PROP_TEXT_INDENT:
02440
02441 {
02442 if (isInherit) {
02443 HANDLE_INHERIT_COND(CSS_PROP_MAX_WIDTH, maxWidth, MaxWidth)
02444 HANDLE_INHERIT_COND(CSS_PROP_BOTTOM, bottom, Bottom)
02445 HANDLE_INHERIT_COND(CSS_PROP_TOP, top, Top)
02446 HANDLE_INHERIT_COND(CSS_PROP_LEFT, left, Left)
02447 HANDLE_INHERIT_COND(CSS_PROP_RIGHT, right, Right)
02448 HANDLE_INHERIT_COND(CSS_PROP_WIDTH, width, Width)
02449 HANDLE_INHERIT_COND(CSS_PROP_MIN_WIDTH, minWidth, MinWidth)
02450 HANDLE_INHERIT_COND(CSS_PROP_PADDING_TOP, paddingTop, PaddingTop)
02451 HANDLE_INHERIT_COND(CSS_PROP_PADDING_RIGHT, paddingRight, PaddingRight)
02452 HANDLE_INHERIT_COND(CSS_PROP_PADDING_BOTTOM, paddingBottom, PaddingBottom)
02453 HANDLE_INHERIT_COND(CSS_PROP_PADDING_LEFT, paddingLeft, PaddingLeft)
02454 HANDLE_INHERIT_COND(CSS_PROP_MARGIN_TOP, marginTop, MarginTop)
02455 HANDLE_INHERIT_COND(CSS_PROP_MARGIN_RIGHT, marginRight, MarginRight)
02456 HANDLE_INHERIT_COND(CSS_PROP_MARGIN_BOTTOM, marginBottom, MarginBottom)
02457 HANDLE_INHERIT_COND(CSS_PROP_MARGIN_LEFT, marginLeft, MarginLeft)
02458 HANDLE_INHERIT_COND(CSS_PROP_TEXT_INDENT, textIndent, TextIndent)
02459 return;
02460 } else if (isInitial) {
02461 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MAX_WIDTH, MaxWidth, MaxSize)
02462 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BOTTOM, Bottom, Offset)
02463 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_TOP, Top, Offset)
02464 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_LEFT, Left, Offset)
02465 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_RIGHT, Right, Offset)
02466 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_WIDTH, Width, Size)
02467 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MIN_WIDTH, MinWidth, MinSize)
02468 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_PADDING_TOP, PaddingTop, Padding)
02469 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_PADDING_RIGHT, PaddingRight, Padding)
02470 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_PADDING_BOTTOM, PaddingBottom, Padding)
02471 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_PADDING_LEFT, PaddingLeft, Padding)
02472 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MARGIN_TOP, MarginTop, Margin)
02473 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MARGIN_RIGHT, MarginRight, Margin)
02474 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MARGIN_BOTTOM, MarginBottom, Margin)
02475 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MARGIN_LEFT, MarginLeft, Margin)
02476 HANDLE_INITIAL_COND(CSS_PROP_TEXT_INDENT, TextIndent)
02477 return;
02478 }
02479
02480 if (primitiveValue && !apply) {
02481 int type = primitiveValue->primitiveType();
02482 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
02483
02484 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed,
02485 primitiveValue->isQuirkValue());
02486 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
02487 l = Length((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
02488 else if (type == CSSPrimitiveValue::CSS_HTML_RELATIVE)
02489 l = Length(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_HTML_RELATIVE)), Relative);
02490 else
02491 return;
02492 apply = true;
02493 }
02494 if(!apply) return;
02495 switch(id)
02496 {
02497 case CSS_PROP_MAX_WIDTH:
02498 style->setMaxWidth(l); break;
02499 case CSS_PROP_BOTTOM:
02500 style->setBottom(l); break;
02501 case CSS_PROP_TOP:
02502 style->setTop(l); break;
02503 case CSS_PROP_LEFT:
02504 style->setLeft(l); break;
02505 case CSS_PROP_RIGHT:
02506 style->setRight(l); break;
02507 case CSS_PROP_WIDTH:
02508 style->setWidth(l); break;
02509 case CSS_PROP_MIN_WIDTH:
02510 style->setMinWidth(l); break;
02511 case CSS_PROP_PADDING_TOP:
02512 style->setPaddingTop(l); break;
02513 case CSS_PROP_PADDING_RIGHT:
02514 style->setPaddingRight(l); break;
02515 case CSS_PROP_PADDING_BOTTOM:
02516 style->setPaddingBottom(l); break;
02517 case CSS_PROP_PADDING_LEFT:
02518 style->setPaddingLeft(l); break;
02519 case CSS_PROP_MARGIN_TOP:
02520 style->setMarginTop(l); break;
02521 case CSS_PROP_MARGIN_RIGHT:
02522 style->setMarginRight(l); break;
02523 case CSS_PROP_MARGIN_BOTTOM:
02524 style->setMarginBottom(l); break;
02525 case CSS_PROP_MARGIN_LEFT:
02526 style->setMarginLeft(l); break;
02527 case CSS_PROP_TEXT_INDENT:
02528 style->setTextIndent(l); break;
02529 default: break;
02530 }
02531 return;
02532 }
02533
02534 case CSS_PROP_MAX_HEIGHT:
02535 if(primitiveValue && primitiveValue->getIdent() == CSS_VAL_NONE)
02536 apply = true;
02537 case CSS_PROP_HEIGHT:
02538 case CSS_PROP_MIN_HEIGHT:
02539 if(id != CSS_PROP_MAX_HEIGHT && primitiveValue &&
02540 primitiveValue->getIdent() == CSS_VAL_AUTO)
02541 apply = true;
02542 if (isInherit) {
02543 HANDLE_INHERIT_COND(CSS_PROP_MAX_HEIGHT, maxHeight, MaxHeight)
02544 HANDLE_INHERIT_COND(CSS_PROP_HEIGHT, height, Height)
02545 HANDLE_INHERIT_COND(CSS_PROP_MIN_HEIGHT, minHeight, MinHeight)
02546 return;
02547 }
02548 else if (isInitial) {
02549 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MAX_HEIGHT, MaxHeight, MaxSize)
02550 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_HEIGHT, Height, Size)
02551 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MIN_HEIGHT, MinHeight, MinSize)
02552 return;
02553 }
02554
02555 if (primitiveValue && !apply)
02556 {
02557 int type = primitiveValue->primitiveType();
02558 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
02559 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed);
02560 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
02561 l = Length((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
02562 else
02563 return;
02564 apply = true;
02565 }
02566 if(!apply) return;
02567 switch(id)
02568 {
02569 case CSS_PROP_MAX_HEIGHT:
02570 style->setMaxHeight(l); break;
02571 case CSS_PROP_HEIGHT:
02572 style->setHeight(l); break;
02573 case CSS_PROP_MIN_HEIGHT:
02574 style->setMinHeight(l); break;
02575 default:
02576 return;
02577 }
02578 return;
02579
02580 break;
02581
02582 case CSS_PROP_VERTICAL_ALIGN:
02583 HANDLE_INHERIT_AND_INITIAL(verticalAlign, VerticalAlign)
02584 if (!primitiveValue) return;
02585 if (primitiveValue->getIdent()) {
02586 khtml::EVerticalAlign align;
02587
02588 switch(primitiveValue->getIdent())
02589 {
02590 case CSS_VAL_TOP:
02591 align = TOP; break;
02592 case CSS_VAL_BOTTOM:
02593 align = BOTTOM; break;
02594 case CSS_VAL_MIDDLE:
02595 align = MIDDLE; break;
02596 case CSS_VAL_BASELINE:
02597 align = BASELINE; break;
02598 case CSS_VAL_TEXT_BOTTOM:
02599 align = TEXT_BOTTOM; break;
02600 case CSS_VAL_TEXT_TOP:
02601 align = TEXT_TOP; break;
02602 case CSS_VAL_SUB:
02603 align = SUB; break;
02604 case CSS_VAL_SUPER:
02605 align = SUPER; break;
02606 case CSS_VAL__KHTML_BASELINE_MIDDLE:
02607 align = BASELINE_MIDDLE; break;
02608 default:
02609 return;
02610 }
02611 style->setVerticalAlign(align);
02612 return;
02613 } else {
02614 int type = primitiveValue->primitiveType();
02615 Length l;
02616 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)
02617 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed );
02618 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
02619 l = Length( int( primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE) ), Percent );
02620
02621 style->setVerticalAlign( LENGTH );
02622 style->setVerticalAlignLength( l );
02623 }
02624 break;
02625
02626 case CSS_PROP_FONT_SIZE:
02627 {
02628 FontDef fontDef = style->htmlFont().fontDef;
02629 int oldSize;
02630 int size = 0;
02631
02632 float toPix = paintDeviceMetrics->logicalDpiY()/72.;
02633 if (toPix < 96./72.) toPix = 96./72.;
02634
02635 int minFontSize = int(settings->minFontSize() * toPix);
02636
02637 if(parentNode) {
02638 oldSize = parentStyle->font().pixelSize();
02639 } else
02640 oldSize = m_fontSizes[3];
02641
02642 if (isInherit )
02643 size = oldSize;
02644 else if (isInitial)
02645 size = m_fontSizes[3];
02646 else if(primitiveValue->getIdent()) {
02647
02648
02649 #ifdef APPLE_CHANGES
02650 QValueList<int>& fontSizes = (fontDef.genericFamily == FontDef::eMonospace) ?
02651 m_fixedFontSizes : m_fontSizes;
02652 #else
02653 QValueList<int>& fontSizes = m_fontSizes;
02654 #endif
02655 switch(primitiveValue->getIdent())
02656 {
02657 case CSS_VAL_XX_SMALL: size = int( fontSizes[0] ); break;
02658 case CSS_VAL_X_SMALL: size = int( fontSizes[1] ); break;
02659 case CSS_VAL_SMALL: size = int( fontSizes[2] ); break;
02660 case CSS_VAL_MEDIUM: size = int( fontSizes[3] ); break;
02661 case CSS_VAL_LARGE: size = int( fontSizes[4] ); break;
02662 case CSS_VAL_X_LARGE: size = int( fontSizes[5] ); break;
02663 case CSS_VAL_XX_LARGE: size = int( fontSizes[6] ); break;
02664 case CSS_VAL__KHTML_XXX_LARGE: size = ( fontSizes[6]*5 )/3; break;
02665 case CSS_VAL_LARGER:
02666
02667 size = ( oldSize * 5 ) / 4;
02668 break;
02669 case CSS_VAL_SMALLER:
02670 size = ( oldSize * 4 ) / 5;
02671 break;
02672 default:
02673 return;
02674 }
02675
02676 } else {
02677 int type = primitiveValue->primitiveType();
02678 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) {
02679 if (!khtml::printpainter && element && element->getDocument()->view())
02680 size = int( primitiveValue->computeLengthFloat(parentStyle, paintDeviceMetrics) *
02681 element->getDocument()->view()->part()->zoomFactor() ) / 100;
02682 else
02683 size = int( primitiveValue->computeLengthFloat(parentStyle, paintDeviceMetrics) );
02684 }
02685 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)
02686 size = int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE)
02687 * parentStyle->font().pixelSize()) / 100;
02688 else
02689 return;
02690 }
02691
02692 if(size < 1) return;
02693
02694
02695 if(size < minFontSize ) size = minFontSize;
02696
02697
02698
02699 fontDef.size = size;
02700 fontDirty |= style->setFontDef( fontDef );
02701 return;
02702 }
02703
02704 case CSS_PROP_Z_INDEX:
02705 {
02706 HANDLE_INHERIT(zIndex, ZIndex)
02707 else if (isInitial) {
02708 style->setHasAutoZIndex();
02709 return;
02710 }
02711
02712 if (!primitiveValue)
02713 return;
02714
02715 if (primitiveValue->getIdent() == CSS_VAL_AUTO) {
02716 style->setHasAutoZIndex();
02717 return;
02718 }
02719
02720 if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER)
02721 return;
02722
02723 style->setZIndex((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_NUMBER));
02724 return;
02725 }
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748 case CSS_PROP_LINE_HEIGHT:
02749 {
02750 HANDLE_INHERIT_AND_INITIAL(lineHeight, LineHeight)
02751 if(!primitiveValue) return;
02752 Length lineHeight;
02753 int type = primitiveValue->primitiveType();
02754 if (primitiveValue->getIdent() == CSS_VAL_NORMAL)
02755 lineHeight = Length( -100, Percent );
02756 else if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) {
02757 #ifdef APPLE_CHANGES
02758 double multiplier = 1.0;
02759
02760
02761 if (type != CSSPrimitiveValue::CSS_EMS && type != CSSPrimitiveValue::CSS_EXS && view && view->part()) {
02762 multiplier = view->part()->zoomFactor() / 100.0;
02763 }
02764 lineHeight = Length(primitiveValue->computeLength(style, paintDeviceMetrics, multiplier), Fixed);
02765 #else
02766 lineHeight = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed);
02767 #endif
02768 } else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
02769 lineHeight = Length( ( style->font().pixelSize() * int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE)) ) / 100, Fixed );
02770 else if (type == CSSPrimitiveValue::CSS_NUMBER)
02771 lineHeight = Length(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_NUMBER)*100), Percent);
02772 else
02773 return;
02774 style->setLineHeight(lineHeight);
02775 return;
02776 }
02777
02778
02779 case CSS_PROP_TEXT_ALIGN:
02780 {
02781 HANDLE_INHERIT_AND_INITIAL(textAlign, TextAlign)
02782 if (!primitiveValue) return;
02783 if (primitiveValue->getIdent())
02784 style->setTextAlign( (ETextAlign) (primitiveValue->getIdent() - CSS_VAL__KHTML_AUTO) );
02785 return;
02786 }
02787
02788
02789 case CSS_PROP_CLIP:
02790 {
02791 Length top;
02792 Length right;
02793 Length bottom;
02794 Length left;
02795 bool hasClip = true;
02796 if (isInherit) {
02797 if (parentStyle->hasClip()) {
02798 top = parentStyle->clipTop();
02799 right = parentStyle->clipRight();
02800 bottom = parentStyle->clipBottom();
02801 left = parentStyle->clipLeft();
02802 }
02803 else {
02804 hasClip = false;
02805 top = right = bottom = left = Length();
02806 }
02807 } else if (isInitial) {
02808 hasClip = false;
02809 top = right = bottom = left = Length();
02810 } else if ( !primitiveValue ) {
02811 break;
02812 } else if ( primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RECT ) {
02813 RectImpl *rect = primitiveValue->getRectValue();
02814 if ( !rect )
02815 break;
02816 top = convertToLength( rect->top(), style, paintDeviceMetrics );
02817 right = convertToLength( rect->right(), style, paintDeviceMetrics );
02818 bottom = convertToLength( rect->bottom(), style, paintDeviceMetrics );
02819 left = convertToLength( rect->left(), style, paintDeviceMetrics );
02820
02821 } else if ( primitiveValue->getIdent() != CSS_VAL_AUTO ) {
02822 break;
02823 }
02824
02825
02826
02827
02828 style->setClip(top, right, bottom, left );
02829 style->setHasClip(hasClip);
02830
02831 break;
02832 }
02833
02834
02835 case CSS_PROP_CONTENT:
02836
02837 {
02838
02839
02840 if (!(style->styleType()==RenderStyle::BEFORE ||
02841 style->styleType()==RenderStyle::AFTER))
02842 break;
02843
02844 if (isInitial) {
02845 if (style->contentData())
02846 style->contentData()->clearContent();
02847 return;
02848 }
02849
02850 if(!value->isValueList()) return;
02851 CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value);
02852 int len = list->length();
02853
02854 for(int i = 0; i < len; i++) {
02855 CSSValueImpl *item = list->item(i);
02856 if(!item->isPrimitiveValue()) continue;
02857 CSSPrimitiveValueImpl *val = static_cast<CSSPrimitiveValueImpl *>(item);
02858 if(val->primitiveType()==CSSPrimitiveValue::CSS_STRING)
02859 {
02860 style->setContent(val->getStringValue(), i != 0);
02861 }
02862 else if (val->primitiveType()==CSSPrimitiveValue::CSS_ATTR)
02863 {
02864 #ifdef APPLE_CHANGES
02865 int attrID = element->getDocument()->attrId(0, val->getStringValue(), false);
02866 if (attrID)
02867 style->setContent(element->getAttribute(attrID).implementation(), i != 0);
02868 #else
02869 int attrID = element->getDocument()->getId(NodeImpl::AttributeId, val->getStringValue(), false, true);
02870 if (attrID)
02871 style->setContent(element->getAttribute(attrID).implementation(), i != 0);
02872 #endif
02873 }
02874 else if (val->primitiveType()==CSSPrimitiveValue::CSS_URI)
02875 {
02876 CSSImageValueImpl *image = static_cast<CSSImageValueImpl *>(val);
02877 style->setContent(image->image(), i != 0);
02878 }
02879
02880 }
02881 break;
02882 }
02883
02884 case CSS_PROP_COUNTER_INCREMENT:
02885
02886 case CSS_PROP_COUNTER_RESET:
02887
02888 break;
02889 case CSS_PROP_FONT_FAMILY:
02890
02891 {
02892 if (isInherit) {
02893 FontDef parentFontDef = parentStyle->htmlFont().fontDef;
02894 FontDef fontDef = style->htmlFont().fontDef;
02895 fontDef.family = parentFontDef.family;
02896 if (style->setFontDef(fontDef))
02897 fontDirty = true;
02898 return;
02899 }
02900 else if (isInitial) {
02901 FontDef fontDef = style->htmlFont().fontDef;
02902 FontDef initialDef = FontDef();
02903 #ifdef APPLE_CHANGES
02904 fontDef.family = initialDef.firstFamily();
02905 #else
02906 fontDef.family = QString::null;
02907 #endif
02908 if (style->setFontDef(fontDef))
02909 fontDirty = true;
02910 return;
02911 }
02912 if(!value->isValueList()) return;
02913 FontDef fontDef = style->htmlFont().fontDef;
02914 CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value);
02915 int len = list->length();
02916 for(int i = 0; i < len; i++) {
02917 CSSValueImpl *item = list->item(i);
02918 if(!item->isPrimitiveValue()) continue;
02919 CSSPrimitiveValueImpl *val = static_cast<CSSPrimitiveValueImpl *>(item);
02920 QString face;
02921 if( val->primitiveType() == CSSPrimitiveValue::CSS_STRING )
02922 face = static_cast<FontFamilyValueImpl *>(val)->fontName();
02923 else if ( val->primitiveType() == CSSPrimitiveValue::CSS_IDENT ) {
02924 switch( val->getIdent() ) {
02925 case CSS_VAL_SERIF:
02926 face = settings->serifFontName();
02927 break;
02928 case CSS_VAL_SANS_SERIF:
02929 face = settings->sansSerifFontName();
02930 break;
02931 case CSS_VAL_CURSIVE:
02932 face = settings->cursiveFontName();
02933 break;
02934 case CSS_VAL_FANTASY:
02935 face = settings->fantasyFontName();
02936 break;
02937 case CSS_VAL_MONOSPACE:
02938 face = settings->fixedFontName();
02939 break;
02940 default:
02941 return;
02942 }
02943 } else {
02944 return;
02945 }
02946 if ( !face.isEmpty() ) {
02947 fontDef.family = face;
02948 fontDirty |= style->setFontDef( fontDef );
02949 return;
02950 }
02951 }
02952 break;
02953 }
02954 case CSS_PROP_QUOTES:
02955
02956 case CSS_PROP_SIZE:
02957
02958 break;
02959 case CSS_PROP_TEXT_DECORATION: {
02960
02961 HANDLE_INHERIT_AND_INITIAL(textDecoration, TextDecoration)
02962 int t = RenderStyle::initialTextDecoration();
02963 if(primitiveValue && primitiveValue->getIdent() == CSS_VAL_NONE) {
02964
02965 } else {
02966 if(!value->isValueList()) return;
02967 CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value);
02968 int len = list->length();
02969 for(int i = 0; i < len; i++)
02970 {
02971 CSSValueImpl *item = list->item(i);
02972 if(!item->isPrimitiveValue()) continue;
02973 primitiveValue = static_cast<CSSPrimitiveValueImpl *>(item);
02974 switch(primitiveValue->getIdent())
02975 {
02976 case CSS_VAL_NONE:
02977 t = TDNONE; break;
02978 case CSS_VAL_UNDERLINE:
02979 t |= UNDERLINE; break;
02980 case CSS_VAL_OVERLINE:
02981 t |= OVERLINE; break;
02982 case CSS_VAL_LINE_THROUGH:
02983 t |= LINE_THROUGH; break;
02984 case CSS_VAL_BLINK:
02985 t |= BLINK; break;
02986 default:
02987 return;
02988 }
02989 }
02990 }
02991 style->setTextDecoration(t);
02992 break;
02993 }
02994 case CSS_PROP__KHTML_FLOW_MODE:
02995 HANDLE_INHERIT_AND_INITIAL(flowAroundFloats, FlowAroundFloats)
02996 if (!primitiveValue) return;
02997 if (primitiveValue->getIdent()) {
02998 style->setFlowAroundFloats( primitiveValue->getIdent() == CSS_VAL__KHTML_AROUND_FLOATS );
02999 return;
03000 }
03001 break;
03002 case CSS_PROP__KHTML_USER_INPUT: {
03003 if(value->cssValueType() == CSSValue::CSS_INHERIT)
03004 {
03005 if(!parentNode) return;
03006 style->setUserInput(parentStyle->userInput());
03007
03008 return;
03009 }
03010 if(!primitiveValue) return;
03011 int id = primitiveValue->getIdent();
03012 if (id == CSS_VAL_NONE)
03013 style->setUserInput(UI_NONE);
03014 else
03015 style->setUserInput(EUserInput(id - CSS_VAL_ENABLED));
03016
03017 return;
03018 }
03019
03020
03021 case CSS_PROP_BACKGROUND:
03022 if (isInherit) {
03023 style->setBackgroundColor(parentStyle->backgroundColor());
03024 style->setBackgroundImage(parentStyle->backgroundImage());
03025 style->setBackgroundRepeat(parentStyle->backgroundRepeat());
03026 style->setBackgroundAttachment(parentStyle->backgroundAttachment());
03027 style->setBackgroundXPosition(parentStyle->backgroundXPosition());
03028 style->setBackgroundYPosition(parentStyle->backgroundYPosition());
03029 }
03030 else if (isInitial) {
03031 style->setBackgroundColor(QColor());
03032 style->setBackgroundImage(RenderStyle::initialBackgroundImage());
03033 style->setBackgroundRepeat(RenderStyle::initialBackgroundRepeat());
03034 style->setBackgroundAttachment(RenderStyle::initialBackgroundAttachment());
03035 style->setBackgroundXPosition(RenderStyle::initialBackgroundXPosition());
03036 style->setBackgroundYPosition(RenderStyle::initialBackgroundYPosition());
03037 }
03038 break;
03039 case CSS_PROP_BORDER:
03040 case CSS_PROP_BORDER_STYLE:
03041 case CSS_PROP_BORDER_WIDTH:
03042 case CSS_PROP_BORDER_COLOR:
03043 if(id == CSS_PROP_BORDER || id == CSS_PROP_BORDER_COLOR)
03044 {
03045 if (isInherit) {
03046 style->setBorderTopColor(parentStyle->borderTopColor());
03047 style->setBorderBottomColor(parentStyle->borderBottomColor());
03048 style->setBorderLeftColor(parentStyle->borderLeftColor());
03049 style->setBorderRightColor(parentStyle->borderRightColor());
03050 }
03051 else if (isInitial) {
03052 style->setBorderTopColor(QColor());
03053 style->setBorderBottomColor(QColor());
03054 style->setBorderLeftColor(QColor());
03055 style->setBorderRightColor(QColor());
03056 }
03057 }
03058 if (id == CSS_PROP_BORDER || id == CSS_PROP_BORDER_STYLE)
03059 {
03060 if (isInherit) {
03061 style->setBorderTopStyle(parentStyle->borderTopStyle());
03062 style->setBorderBottomStyle(parentStyle->borderBottomStyle());
03063 style->setBorderLeftStyle(parentStyle->borderLeftStyle());
03064 style->setBorderRightStyle(parentStyle->borderRightStyle());
03065 }
03066 else if (isInitial) {
03067 style->setBorderTopStyle(RenderStyle::initialBorderStyle());
03068 style->setBorderBottomStyle(RenderStyle::initialBorderStyle());
03069 style->setBorderLeftStyle(RenderStyle::initialBorderStyle());
03070 style->setBorderRightStyle(RenderStyle::initialBorderStyle());
03071 }
03072 }
03073 if (id == CSS_PROP_BORDER || id == CSS_PROP_BORDER_WIDTH)
03074 {
03075 if (isInherit) {
03076 style->setBorderTopWidth(parentStyle->borderTopWidth());
03077 style->setBorderBottomWidth(parentStyle->borderBottomWidth());
03078 style->setBorderLeftWidth(parentStyle->borderLeftWidth());
03079 style->setBorderRightWidth(parentStyle->borderRightWidth());
03080 }
03081 else if (isInitial) {
03082 style->setBorderTopWidth(RenderStyle::initialBorderWidth());
03083 style->setBorderBottomWidth(RenderStyle::initialBorderWidth());
03084 style->setBorderLeftWidth(RenderStyle::initialBorderWidth());
03085 style->setBorderRightWidth(RenderStyle::initialBorderWidth());
03086 }
03087 }
03088 return;
03089 case CSS_PROP_BORDER_TOP:
03090 if ( isInherit ) {
03091 style->setBorderTopColor(parentStyle->borderTopColor());
03092 style->setBorderTopStyle(parentStyle->borderTopStyle());
03093 style->setBorderTopWidth(parentStyle->borderTopWidth());
03094 } else if (isInitial)
03095 style->resetBorderTop();
03096 return;
03097 case CSS_PROP_BORDER_RIGHT:
03098 if (isInherit) {
03099 style->setBorderRightColor(parentStyle->borderRightColor());
03100 style->setBorderRightStyle(parentStyle->borderRightStyle());
03101 style->setBorderRightWidth(parentStyle->borderRightWidth());
03102 }
03103 else if (isInitial)
03104 style->resetBorderRight();
03105 return;
03106 case CSS_PROP_BORDER_BOTTOM:
03107 if (isInherit) {
03108 style->setBorderBottomColor(parentStyle->borderBottomColor());
03109 style->setBorderBottomStyle(parentStyle->borderBottomStyle());
03110 style->setBorderBottomWidth(parentStyle->borderBottomWidth());
03111 }
03112 else if (isInitial)
03113 style->resetBorderBottom();
03114 return;
03115 case CSS_PROP_BORDER_LEFT:
03116 if (isInherit) {
03117 style->setBorderLeftColor(parentStyle->borderLeftColor());
03118 style->setBorderLeftStyle(parentStyle->borderLeftStyle());
03119 style->setBorderLeftWidth(parentStyle->borderLeftWidth());
03120 }
03121 else if (isInitial)
03122 style->resetBorderLeft();
03123 return;
03124 case CSS_PROP_MARGIN:
03125 if (isInherit) {
03126 style->setMarginTop(parentStyle->marginTop());
03127 style->setMarginBottom(parentStyle->marginBottom());
03128 style->setMarginLeft(parentStyle->marginLeft());
03129 style->setMarginRight(parentStyle->marginRight());
03130 }
03131 else if (isInitial)
03132 style->resetMargin();
03133 return;
03134 case CSS_PROP_PADDING:
03135 if (isInherit) {
03136 style->setPaddingTop(parentStyle->paddingTop());
03137 style->setPaddingBottom(parentStyle->paddingBottom());
03138 style->setPaddingLeft(parentStyle->paddingLeft());
03139 style->setPaddingRight(parentStyle->paddingRight());
03140 }
03141 else if (isInitial)
03142 style->resetPadding();
03143 return;
03144 case CSS_PROP_FONT:
03145 if ( isInherit ) {
03146 FontDef fontDef = parentStyle->htmlFont().fontDef;
03147 style->setLineHeight( parentStyle->lineHeight() );
03148 fontDirty |= style->setFontDef( fontDef );
03149 } else if (isInitial) {
03150 FontDef fontDef;
03151 style->setLineHeight(RenderStyle::initialLineHeight());
03152 if (style->setFontDef( fontDef ))
03153 fontDirty = true;
03154 } else if ( value->isFontValue() ) {
03155 FontValueImpl *font = static_cast<FontValueImpl *>(value);
03156 if ( !font->style || !font->variant || !font->weight ||
03157 !font->size || !font->lineHeight || !font->family )
03158 return;
03159 applyRule( CSS_PROP_FONT_STYLE, font->style );
03160 applyRule( CSS_PROP_FONT_VARIANT, font->variant );
03161 applyRule( CSS_PROP_FONT_WEIGHT, font->weight );
03162 applyRule( CSS_PROP_FONT_SIZE, font->size );
03163
03164
03165
03166
03167 if (fontDirty)
03168 CSSStyleSelector::style->htmlFont().update( paintDeviceMetrics );
03169
03170 applyRule( CSS_PROP_LINE_HEIGHT, font->lineHeight );
03171 applyRule( CSS_PROP_FONT_FAMILY, font->family );
03172 }
03173 return;
03174
03175 case CSS_PROP_LIST_STYLE:
03176 if (isInherit) {
03177 style->setListStyleType(parentStyle->listStyleType());
03178 style->setListStyleImage(parentStyle->listStyleImage());
03179 style->setListStylePosition(parentStyle->listStylePosition());
03180 }
03181 else if (isInitial) {
03182 style->setListStyleType(RenderStyle::initialListStyleType());
03183 style->setListStyleImage(RenderStyle::initialListStyleImage());
03184 style->setListStylePosition(RenderStyle::initialListStylePosition());
03185 }
03186 break;
03187 case CSS_PROP_OUTLINE:
03188 if (isInherit) {
03189 style->setOutlineWidth(parentStyle->outlineWidth());
03190 style->setOutlineColor(parentStyle->outlineColor());
03191 style->setOutlineStyle(parentStyle->outlineStyle());
03192 }
03193 else if (isInitial)
03194 style->resetOutline();
03195 break;
03196 case CSS_PROP__KHTML_MARQUEE:
03197 if (value->cssValueType() != CSSValue::CSS_INHERIT || !parentNode) return;
03198 style->setMarqueeDirection(parentStyle->marqueeDirection());
03199 style->setMarqueeIncrement(parentStyle->marqueeIncrement());
03200 style->setMarqueeSpeed(parentStyle->marqueeSpeed());
03201 style->setMarqueeLoopCount(parentStyle->marqueeLoopCount());
03202 style->setMarqueeBehavior(parentStyle->marqueeBehavior());
03203 break;
03204 case CSS_PROP__KHTML_MARQUEE_REPETITION: {
03205 HANDLE_INHERIT_AND_INITIAL(marqueeLoopCount, MarqueeLoopCount)
03206 if (!primitiveValue) return;
03207 if (primitiveValue->getIdent() == CSS_VAL_INFINITE)
03208 style->setMarqueeLoopCount(-1);
03209 else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_NUMBER)
03210 style->setMarqueeLoopCount((int)(primitiveValue->floatValue(CSSPrimitiveValue::CSS_NUMBER)));
03211 break;
03212 }
03213 case CSS_PROP__KHTML_MARQUEE_SPEED: {
03214 HANDLE_INHERIT_AND_INITIAL(marqueeSpeed, MarqueeSpeed)
03215 if (!primitiveValue) return;
03216 if (primitiveValue->getIdent()) {
03217 switch (primitiveValue->getIdent())
03218 {
03219 case CSS_VAL_SLOW:
03220 style->setMarqueeSpeed(500);
03221 break;
03222 case CSS_VAL_NORMAL:
03223 style->setMarqueeSpeed(85);
03224 break;
03225 case CSS_VAL_FAST:
03226 style->setMarqueeSpeed(10);
03227 break;
03228 }
03229 }
03230 else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_S)
03231 style->setMarqueeSpeed(int(1000*primitiveValue->floatValue(CSSPrimitiveValue::CSS_S)));
03232 else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_MS)
03233 style->setMarqueeSpeed(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_MS)));
03234 else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_NUMBER)
03235 style->setMarqueeSpeed(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_NUMBER)));
03236 break;
03237 }
03238 case CSS_PROP__KHTML_MARQUEE_INCREMENT: {
03239 HANDLE_INHERIT_AND_INITIAL(marqueeIncrement, MarqueeIncrement)
03240 if (!primitiveValue) return;
03241 if (primitiveValue->getIdent()) {
03242 switch (primitiveValue->getIdent())
03243 {
03244 case CSS_VAL_SMALL:
03245 style->setMarqueeIncrement(Length(1, Fixed));
03246 break;
03247 case CSS_VAL_NORMAL:
03248 style->setMarqueeIncrement(Length(6, Fixed));
03249 break;
03250 case CSS_VAL_LARGE:
03251 style->setMarqueeIncrement(Length(36, Fixed));
03252 break;
03253 }
03254 }
03255 else {
03256 bool ok = true;
03257 Length l = convertToLength(primitiveValue, style, paintDeviceMetrics, &ok);
03258 if (ok)
03259 style->setMarqueeIncrement(l);
03260 }
03261 break;
03262 }
03263 case CSS_PROP__KHTML_MARQUEE_STYLE: {
03264 HANDLE_INHERIT_AND_INITIAL(marqueeBehavior, MarqueeBehavior)
03265 if (!primitiveValue || !primitiveValue->getIdent()) return;
03266 switch (primitiveValue->getIdent())
03267 {
03268 case CSS_VAL_NONE:
03269 style->setMarqueeBehavior(MNONE);
03270 break;
03271 case CSS_VAL_SCROLL:
03272 style->setMarqueeBehavior(MSCROLL);
03273 break;
03274 case CSS_VAL_SLIDE:
03275 style->setMarqueeBehavior(MSLIDE);
03276 break;
03277 case CSS_VAL_ALTERNATE:
03278 style->setMarqueeBehavior(MALTERNATE);
03279 break;
03280 case CSS_VAL_UNFURL:
03281 style->setMarqueeBehavior(MUNFURL);
03282 break;
03283 }
03284 break;
03285 }
03286 case CSS_PROP__KHTML_MARQUEE_DIRECTION: {
03287 HANDLE_INHERIT_AND_INITIAL(marqueeDirection, MarqueeDirection)
03288 if (!primitiveValue || !primitiveValue->getIdent()) return;
03289 switch (primitiveValue->getIdent())
03290 {
03291 case CSS_VAL_FORWARDS:
03292 style->setMarqueeDirection(MFORWARD);
03293 break;
03294 case CSS_VAL_BACKWARDS:
03295 style->setMarqueeDirection(MBACKWARD);
03296 break;
03297 case CSS_VAL_AUTO:
03298 style->setMarqueeDirection(MAUTO);
03299 break;
03300 case CSS_VAL_AHEAD:
03301 case CSS_VAL_UP:
03302 style->setMarqueeDirection(MUP);
03303 break;
03304 case CSS_VAL_REVERSE:
03305 case CSS_VAL_DOWN:
03306 style->setMarqueeDirection(MDOWN);
03307 break;
03308 case CSS_VAL_LEFT:
03309 style->setMarqueeDirection(MLEFT);
03310 break;
03311 case CSS_VAL_RIGHT:
03312 style->setMarqueeDirection(MRIGHT);
03313 break;
03314 }
03315 break;
03316 }
03317 default:
03318 return;
03319 }
03320 }
03321
03322 #ifdef APPLE_CHANGES
03323 void CSSStyleSelector::checkForGenericFamilyChange(RenderStyle* aStyle, RenderStyle* aParentStyle)
03324 {
03325 const FontDef& childFont = aStyle->htmlFont().fontDef;
03326
03327 if (childFont.sizeSpecified || !aParentStyle)
03328 return;
03329
03330 const FontDef& parentFont = aParentStyle->htmlFont().fontDef;
03331
03332 if (childFont.genericFamily == parentFont.genericFamily)
03333 return;
03334
03335
03336 if (childFont.genericFamily != FontDef::eMonospace &&
03337 parentFont.genericFamily != FontDef::eMonospace)
03338 return;
03339
03340
03341
03342
03343 float size = 0;
03344 int minFontSize = settings->minFontSize();
03345 size = (childFont.genericFamily == FontDef::eMonospace) ? m_fixedFontSizes[3] : m_fontSizes[3];
03346 int isize = (int)size;
03347 if (isize < minFontSize)
03348 isize = minFontSize;
03349
03350 FontDef newFontDef(childFont);
03351 newFontDef.size = isize;
03352 aStyle->setFontDef(newFontDef);
03353 }
03354 #endif
03355
03356 }