khtml Library API Documentation

cssstyleselector.cpp

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) // this may be null, not everyone uses khtmlview (Niko) 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 // add stylesheets from document 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 //kdDebug( 6080 ) << "number of style sheets in document " << authorStyleSheets.count() << endl; 00161 //kdDebug( 6080 ) << "CSSStyleSelector: author style has " << authorStyle->count() << " elements"<< endl; 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 //kdDebug() << "CSSStyleSelector::CSSStyleSelector encoded url " << encodedurl.path << endl; 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 // Collect only strict-mode rules. 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 // Collect only quirks-mode rules. 00270 s_defaultQuirksStyle = new CSSStyleSelectorList(); 00271 s_defaultQuirksStyle->append( s_quirksSheet, "screen" ); 00272 } 00273 00274 //kdDebug() << "CSSStyleSelector: default style has " << defaultStyle->count() << " elements"<< endl; 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 // nice leak, but best we can do right now. hopefully its only rare. 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 // We don't want to scale the settings by the dpi. 00312 const float toPix = 1; 00313 #else 00314 Q_UNUSED( isFixed ); 00315 00316 // ### get rid of float / double 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 // ## depending on something / configurable ? 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 // set some variables we will need 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 // try to sort out most style rules as early as possible. 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 // qDebug("adding property" ); 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 // inline style declarations, after all others. non css hints 00444 // count as author rules, and come before all other style sheets, see hack in append() 00445 numPropsToApply = addInlineDeclarations( e, e->m_styleDecls, numPropsToApply ); 00446 00447 // qDebug( "styleForElement( %s )", e->tagName().string().latin1() ); 00448 // qDebug( "%d selectors, %d checked, %d match, %d properties ( of %d )", 00449 // selectors_size, schecked, smatch, numPropsToApply, properties_size ); 00450 00451 bubbleSort( propsToApply, propsToApply+numPropsToApply-1 ); 00452 bubbleSort( pseudoProps, pseudoProps+numPseudoProps-1 ); 00453 00454 // we can't apply style rules without a view() and a part. This 00455 // tends to happen on delayed destruction of widget Renderobjects 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 // we are past the font properties, time to update to the 00464 // correct font 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 // if (prop->m_id == CSS_PROP__KONQ_USER_INPUT) kdDebug(6080) << "El: "<<e->nodeName().string() << " user-input: "<<((CSSPrimitiveValueImpl *)prop->value())->getIdent() << endl; 00473 // if (prop->m_id == CSS_PROP_TEXT_TRANSFORM) kdDebug(6080) << "El: "<<e->nodeName().string() << endl; 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 // Clean up our style object's display and text decorations (among other fixups). 00485 adjustRenderStyle(style, e); 00486 00487 if ( numPseudoProps ) { 00488 fontDirty = false; 00489 //qDebug("%d applying %d pseudo props", e->cssTagId(), pseudoProps->count() ); 00490 for (unsigned int i = 0; i < numPseudoProps; ++i) { 00491 if ( fontDirty && pseudoProps[i]->priority >= (1 << 30) ) { 00492 // we are past the font properties, time to update to the 00493 // correct font 00494 //We have to do this for all pseudo styles 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 // Now adjust all our pseudo-styles. 00535 RenderStyle *pseudoStyle = style->pseudoStyle; 00536 while (pseudoStyle) { 00537 adjustRenderStyle(pseudoStyle, 0); 00538 pseudoStyle = pseudoStyle->pseudoStyle; 00539 } 00540 00541 // Now return the style. 00542 return style; 00543 } 00544 00545 void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, DOM::ElementImpl *e) 00546 { 00547 #ifdef APPLE_CHANGES 00548 // Cache our original display. 00549 style->setOriginalDisplay(style->display()); 00550 #endif 00551 00552 if (style->display() != NONE) { 00553 // If we have a <td> that specifies a float property, in quirks mode we just drop the float 00554 // property. 00555 // Sites also commonly use display:inline/block on <td>s and <table>s. In quirks mode we force 00556 // these tags to retain their display types. 00557 if (!strictParsing && e) { 00558 if (e->id() == ID_TD) { 00559 style->setDisplay(TABLE_CELL); 00560 style->setFloating(FNONE); 00561 } 00562 // else if (e->id() == ID_TABLE) 00563 // style->setDisplay(style->isDisplayInlineType() ? INLINE_TABLE : TABLE); 00564 } 00565 00566 // Mutate the display to BLOCK or TABLE for certain cases, e.g., if someone attempts to 00567 // position or float an inline, compact, or run-in. Cache the original display, since it 00568 // may be needed for positioned elements that have to compute their static normal flow 00569 // positions. We also force inline-level roots to be block-level. 00570 if (style->display() != BLOCK && style->display() != TABLE /*&& style->display() != BOX*/ && 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 // else if (style->display() == INLINE_BOX) 00576 // style->setDisplay(BOX); 00577 else if (style->display() == LIST_ITEM) { 00578 // It is a WinIE bug that floated list items lose their bullets, so we'll emulate the quirk, 00579 // but only in quirks mode. 00580 if (!strictParsing && style->floating() != FNONE) 00581 style->setDisplay(BLOCK); 00582 } 00583 else 00584 style->setDisplay(BLOCK); 00585 } 00586 00587 // After performing the display mutation, check table rows. We do not honor position:relative on 00588 // table rows. This has been established in CSS2.1 (and caused a crash in containingBlock() on 00589 // some sites). 00590 if (style->display() == TABLE_ROW && style->position() == RELATIVE) 00591 style->setPosition(STATIC); 00592 } 00593 00594 // Frames and framesets never honor position:relative or position:absolute. This is necessary to 00595 // fix a crash where a site tries to position these objects. 00596 if ( e ) { 00597 // ignore display: none for <frame> 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 // Finally update our text decorations in effect, but don't allow text-decoration to percolate through 00608 // tables, inline blocks, inline tables, or run-ins. 00609 if (style->display() == TABLE || style->display() == INLINE_TABLE || style->display() == RUN_IN 00610 || style->display() == INLINE_BLOCK /*|| style->display() == INLINE_BOX*/) 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) // For now only TableCellElement implements the 00623 addDecls = e->getAdditionalStyleDecls(); // virtual function for shared cell rules. 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 // give special priority to font-xxx, color properties 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 // these have to be applied first, because other properties use the computed 00673 // values of these properties. 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 // modified version of the one in kurl.cpp 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 // don't remove the host, i.e. http://foo.org/../foo.html 00702 if (prev < 0 || (prev > 3 && path.findRev("://", prev-1) == prev-2)) 00703 path.remove( pos, 3); 00704 else 00705 // matching directory found ? 00706 path.remove( prev, pos- prev + 3 ); 00707 } 00708 pos = 0; 00709 00710 // Don't remove "//" from an anchor identifier. -rjw 00711 // Set refPos to -2 to mean "I haven't looked for the anchor yet". 00712 // We don't want to waste a function call on the search for the anchor 00713 // in the vast majority of cases where there is no "//" in the path. 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 //kdDebug() << "checkPseudoState " << path << endl; 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 //completeURL( attr.string() ); 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 // we have the subject part of the selector 00767 subject = true; 00768 00769 // We track whether or not the rule contains only :hover and :active in a simple selector. If 00770 // so, we can't allow that to apply to every element on the page. We assume the author intended 00771 // to apply the rules only to links. 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 // first selector has to match 00780 if(!checkOneSelector(sel, e)) return; 00781 00782 // check the subselectors 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 //kdDebug() << "CSSOrderedRule::checkSelector" << endl; 00832 ElementImpl *elem = static_cast<ElementImpl *>(n); 00833 // a selector is invalid if something follows :first-xxx 00834 if ( dynamicPseudo != RenderStyle::NOPSEUDO ) { 00835 return; 00836 } 00837 if(!checkOneSelector(sel, elem)) return; 00838 //kdDebug() << "CSSOrderedRule::checkSelector: passed" << endl; 00839 break; 00840 } 00841 } 00842 relation = sel->relation; 00843 } 00844 00845 // disallow *:hover, *:active, and *:hover:active except for links 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 //qDebug( "selector %d applies", selIndex ); 00865 //selectors[ selIndex ]->print(); 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 // all namespaces would match 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 // specific namespace selected 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 // ### fixme: this should allow attributes from all 00895 // ### namespaces. I'm not 100% sure what the semantics 00896 // ### should be in this case. Do they all have to match? 00897 // ### Or should only one of them match. Anyways it might 00898 // ### be we have to iterate over all namespaces and check 00899 // ### all of them. For now we just set the namespace to 00900 // ### 0, so they at least match attributes in the default 00901 // ### namespace. 00902 attr_id &= NodeImpl_IdLocalMask; 00903 } 00904 DOMString value = e->getAttribute(attr_id); 00905 if(value.isNull()) return false; // attribute is not set 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 // There is no list, just a single item. We can avoid 00922 // allocing QStrings and just treat this as an exact 00923 // match check. 00924 if( (strictParsing && strcmp(sel->value, value) ) || 00925 (!strictParsing && strcasecmp(sel->value, value))) 00926 return false; 00927 break; 00928 } 00929 00930 // The selector's value can't contain a space, or it's totally bogus. 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; // We have a match. 00946 } 00947 ++pos; 00948 } 00949 break; 00950 } 00951 case CSSSelector::Contain: 00952 { 00953 //kdDebug( 6080 ) << "checking for contains match" << endl; 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 //kdDebug( 6080 ) << "checking for beginswith match" << endl; 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 //kdDebug( 6080 ) << "checking for endswith match" << endl; 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 //kdDebug( 6080 ) << "checking for hyphen match" << endl; 00985 QString str = value.string(); 00986 QString selStr = sel->value.string(); 00987 if(str.length() < selStr.length()) return false; 00988 // Check if str begins with selStr: 00989 if(str.find(selStr, 0, strictParsing) != 0) return false; 00990 // It does. Check for exact match or following '-': 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 // Pseudo elements. We need to check first child here. No dynamic pseudo 01003 // elements for the moment 01004 // kdDebug() << "CSSOrderedRule::pseudo " << value << endl; 01005 switch (sel->pseudoType()) { 01006 case CSSSelector::PseudoEmpty: 01007 if (!e->firstChild()) 01008 return true; 01009 break; 01010 case CSSSelector::PseudoFirstChild: { 01011 // first-child matches the first child that is an element! 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 // last-child matches the last child that is an element! 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 // If both first-child and last-child apply, then only-child applies. 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() && // :target matches the root when no CSS target exists 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 // If we're in quirks mode, then hover should never match anchors with no 01083 // href. This is important for sites like wsj.com. 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 // If we're in quirks mode, then :active should never match anchors with no 01103 // href. 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 // check the simple selector 01119 for (CSSSelector* subSel = sel->simpleSelector; subSel; 01120 subSel = subSel->tagHistory) { 01121 // :not cannot nest. I don't really know why this is a restriction in CSS3, 01122 // but it is, so let's honor it. 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 /* not supported for now */ 01145 case CSSSelector::PseudoOther: 01146 break; 01147 } 01148 return false; 01149 } 01150 // ### add the rest of the checks... 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 // collect all selectors and Properties in lists. Then transfer them to the array for faster lookup. 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 // presort properties. Should make the sort() calls in styleForElement faster. 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 // and now the same for the selector map 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 // offset = p-selectors; 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 // No media implies "all", but if a medialist exists it must 01318 // contain our current medium 01319 if( sheet->media() && !sheet->media()->contains( medium ) ) 01320 return; // style sheet not applicable for this medium 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 //kdDebug( 6080 ) << "appending StyleRule!" << endl; 01336 } 01337 } 01338 else if(item->isImportRule()) 01339 { 01340 CSSImportRuleImpl *import = static_cast<CSSImportRuleImpl *>(item); 01341 01342 //kdDebug( 6080 ) << "@import: Media: " 01343 // << import->media()->mediaText().string() << endl; 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 //DOMString mediaText = media->mediaText(); 01357 //kdDebug( 6080 ) << "@media: Media: " 01358 // << r->media()->mediaText().string() << endl; 01359 01360 if( ( !r->media() || r->media()->contains( medium ) ) && rules) 01361 { 01362 // Traverse child elements of the @import rule. Since 01363 // many elements are not allowed as child we do not use 01364 // a recursive call to append() here 01365 for( unsigned j = 0; j < rules->length(); j++ ) 01366 { 01367 //kdDebug( 6080 ) << "*** Rule #" << j << endl; 01368 01369 CSSRuleImpl *childItem = rules->item( j ); 01370 if( childItem->isStyleRule() ) 01371 { 01372 // It is a StyleRule, so append it to our list 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 //kdDebug( 6080 ) << "Ignoring child rule of " 01387 // "ImportRule: rule is not a StyleRule!" << endl; 01388 } 01389 } // for rules 01390 } // if rules 01391 else 01392 { 01393 //kdDebug( 6080 ) << "CSSMediaRule not rendered: " 01394 // << "rule empty or wrong medium!" << endl; 01395 } 01396 } 01397 // ### include other rules 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 // else 01418 // qDebug("merged one selector"); 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 // give special priority to font-xxx, color properties 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 // these have to be applied first, because other properties use the computed 01461 // values of these porperties. 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 // this is mostly boring stuff on how to apply a certain rule to the renderstyle... 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 // color mapping code 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_GREY, 0xff808080 }, 01528 { 0, 0 } 01529 }; 01530 01531 struct uiColors { 01532 int css_value; 01533 const char * configGroup; 01534 const char * configEntry; 01535 QPalette::ColorGroup group; 01536 QColorGroup::ColorRole role; 01537 }; 01538 01539 const char * const wmgroup = "WM"; 01540 const char * const generalgroup = "General"; 01541 01542 /* Mapping system settings to CSS 2 01543 * Tried hard to get an appropriate mapping - schlpbch 01544 */ 01545 static const uiColors uimap[] = { 01546 // Active window border. 01547 { CSS_VAL_ACTIVEBORDER, wmgroup, "background", QPalette::Active, QColorGroup::Light }, 01548 // Active window caption. 01549 { CSS_VAL_ACTIVECAPTION, wmgroup, "background", QPalette::Active, QColorGroup::Text }, 01550 // Text in caption, size box, and scrollbar arrow box. 01551 { CSS_VAL_CAPTIONTEXT, wmgroup, "activeForeground", QPalette::Active, QColorGroup::Text }, 01552 // Face color for three-dimensional display elements. 01553 { CSS_VAL_BUTTONFACE, wmgroup, 0, QPalette::Inactive, QColorGroup::Button }, 01554 // Dark shadow for three-dimensional display elements (for edges facing away from the light source). 01555 { CSS_VAL_BUTTONHIGHLIGHT, wmgroup, 0, QPalette::Inactive, QColorGroup::Light }, 01556 // Shadow color for three-dimensional display elements. 01557 { CSS_VAL_BUTTONSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Shadow }, 01558 // Text on push buttons. 01559 { CSS_VAL_BUTTONTEXT, wmgroup, "buttonForeground", QPalette::Inactive, QColorGroup::ButtonText }, 01560 // Dark shadow for three-dimensional display elements. 01561 { CSS_VAL_THREEDDARKSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Dark }, 01562 // Face color for three-dimensional display elements. 01563 { CSS_VAL_THREEDFACE, wmgroup, 0, QPalette::Inactive, QColorGroup::Button }, 01564 // Highlight color for three-dimensional display elements. 01565 { CSS_VAL_THREEDHIGHLIGHT, wmgroup, 0, QPalette::Inactive, QColorGroup::Light }, 01566 // Light color for three-dimensional display elements (for edges facing the light source). 01567 { CSS_VAL_THREEDLIGHTSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Midlight }, 01568 // Dark shadow for three-dimensional display elements. 01569 { CSS_VAL_THREEDSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Shadow }, 01570 01571 // Inactive window border. 01572 { CSS_VAL_INACTIVEBORDER, wmgroup, "background", QPalette::Disabled, QColorGroup::Background }, 01573 // Inactive window caption. 01574 { CSS_VAL_INACTIVECAPTION, wmgroup, "inactiveBackground", QPalette::Disabled, QColorGroup::Background }, 01575 // Color of text in an inactive caption. 01576 { CSS_VAL_INACTIVECAPTIONTEXT, wmgroup, "inactiveForeground", QPalette::Disabled, QColorGroup::Text }, 01577 { CSS_VAL_GRAYTEXT, wmgroup, 0, QPalette::Disabled, QColorGroup::Text }, 01578 01579 // Menu background 01580 { CSS_VAL_MENU, generalgroup, "background", QPalette::Inactive, QColorGroup::Background }, 01581 // Text in menus 01582 { CSS_VAL_MENUTEXT, generalgroup, "foreground", QPalette::Inactive, QColorGroup::Background }, 01583 01584 // Text of item(s) selected in a control. 01585 { CSS_VAL_HIGHLIGHT, generalgroup, "selectBackground", QPalette::Inactive, QColorGroup::Background }, 01586 01587 // Text of item(s) selected in a control. 01588 { CSS_VAL_HIGHLIGHTTEXT, generalgroup, "selectForeground", QPalette::Inactive, QColorGroup::Background }, 01589 01590 // Background color of multiple document interface. 01591 { CSS_VAL_APPWORKSPACE, generalgroup, "background", QPalette::Inactive, QColorGroup::Text }, 01592 01593 // Scroll bar gray area. 01594 { CSS_VAL_SCROLLBAR, generalgroup, "background", QPalette::Inactive, QColorGroup::Background }, 01595 01596 // Window background. 01597 { CSS_VAL_WINDOW, generalgroup, "windowBackground", QPalette::Inactive, QColorGroup::Background }, 01598 // Window frame. 01599 { CSS_VAL_WINDOWFRAME, generalgroup, "windowBackground", QPalette::Inactive, QColorGroup::Background }, 01600 // WindowText 01601 { CSS_VAL_WINDOWTEXT, generalgroup, "windowForeground", QPalette::Inactive, QColorGroup::Text }, 01602 { CSS_VAL_TEXT, generalgroup, 0, QPalette::Inactive, QColorGroup::Text }, 01603 { 0, 0, 0, QPalette::NColorGroups, QColorGroup::NColorRoles } 01604 }; 01605 01606 static QColor colorForCSSValue( int css_value ) 01607 { 01608 // try the regular ones first 01609 const colorMap *col = cmap; 01610 while ( col->css_value && col->css_value != css_value ) 01611 ++col; 01612 if ( col->css_value ) 01613 return col->color; 01614 01615 const uiColors *uicol = uimap; 01616 while ( uicol->css_value && uicol->css_value != css_value ) 01617 ++uicol; 01618 #ifndef APPLE_CHANGES 01619 if ( !uicol->css_value ) { 01620 if ( css_value == CSS_VAL_INFOBACKGROUND ) 01621 return QToolTip::palette().inactive().background(); 01622 else if ( css_value == CSS_VAL_INFOTEXT ) 01623 return QToolTip::palette().inactive().foreground(); 01624 else if ( css_value == CSS_VAL_BACKGROUND ) { 01625 KConfig bckgrConfig("kdesktoprc", true, false); // No multi-screen support 01626 bckgrConfig.setGroup("Desktop0"); 01627 // Desktop background. 01628 return bckgrConfig.readColorEntry("Color1", &qApp->palette().disabled().background()); 01629 } 01630 return QColor(); 01631 } 01632 #endif 01633 01634 const QPalette &pal = qApp->palette(); 01635 QColor c = pal.color( uicol->group, uicol->role ); 01636 #ifndef APPLE_CHANGES 01637 if ( uicol->configEntry ) { 01638 KConfig *globalConfig = KGlobal::config(); 01639 globalConfig->setGroup( uicol->configGroup ); 01640 c = globalConfig->readColorEntry( uicol->configEntry, &c ); 01641 } 01642 #endif 01643 01644 return c; 01645 } 01646 01647 01648 void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value ) 01649 { 01650 // kdDebug( 6080 ) << "applying property " << id << endl; 01651 01652 CSSPrimitiveValueImpl *primitiveValue = 0; 01653 if(value->isPrimitiveValue()) primitiveValue = static_cast<CSSPrimitiveValueImpl *>(value); 01654 01655 Length l; 01656 bool apply = false; 01657 01658 bool isInherit = (parentNode && value->cssValueType() == CSSValue::CSS_INHERIT); 01659 bool isInitial = (value->cssValueType() == CSSValue::CSS_INITIAL) || 01660 (!parentNode && value->cssValueType() == CSSValue::CSS_INHERIT); 01661 01662 // What follows is a list that maps the CSS properties into their corresponding front-end 01663 // RenderStyle values. Shorthands (e.g. border, background) occur in this list as well and 01664 // are only hit when mapping "inherit" or "initial" into front-end values. 01665 switch(id) 01666 { 01667 // ident only properties 01668 case CSS_PROP_BACKGROUND_ATTACHMENT: 01669 HANDLE_INHERIT_AND_INITIAL(backgroundAttachment, BackgroundAttachment) 01670 if(!primitiveValue) break; 01671 switch(primitiveValue->getIdent()) 01672 { 01673 case CSS_VAL_FIXED: 01674 { 01675 style->setBackgroundAttachment(false); 01676 // only use slow repaints if we actually have a background pixmap 01677 if( style->backgroundImage() ) 01678 view->useSlowRepaints(); 01679 break; 01680 } 01681 case CSS_VAL_SCROLL: 01682 style->setBackgroundAttachment(true); 01683 break; 01684 default: 01685 return; 01686 } 01687 case CSS_PROP_BACKGROUND_REPEAT: 01688 { 01689 HANDLE_INHERIT_AND_INITIAL(backgroundRepeat, BackgroundRepeat) 01690 if(!primitiveValue) return; 01691 switch(primitiveValue->getIdent()) 01692 { 01693 case CSS_VAL_REPEAT: 01694 style->setBackgroundRepeat( REPEAT ); 01695 break; 01696 case CSS_VAL_REPEAT_X: 01697 style->setBackgroundRepeat( REPEAT_X ); 01698 break; 01699 case CSS_VAL_REPEAT_Y: 01700 style->setBackgroundRepeat( REPEAT_Y ); 01701 break; 01702 case CSS_VAL_NO_REPEAT: 01703 style->setBackgroundRepeat( NO_REPEAT ); 01704 break; 01705 default: 01706 return; 01707 } 01708 } 01709 case CSS_PROP_BORDER_COLLAPSE: 01710 HANDLE_INHERIT_AND_INITIAL(borderCollapse, BorderCollapse) 01711 if(!primitiveValue) break; 01712 switch(primitiveValue->getIdent()) 01713 { 01714 case CSS_VAL_COLLAPSE: 01715 style->setBorderCollapse(true); 01716 break; 01717 case CSS_VAL_SEPARATE: 01718 style->setBorderCollapse(false); 01719 break; 01720 default: 01721 return; 01722 } 01723 break; 01724 01725 case CSS_PROP_BORDER_TOP_STYLE: 01726 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderTopStyle, BorderTopStyle, BorderStyle) 01727 if (!primitiveValue) return; 01728 style->setBorderTopStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE)); 01729 break; 01730 case CSS_PROP_BORDER_RIGHT_STYLE: 01731 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderRightStyle, BorderRightStyle, BorderStyle) 01732 if (!primitiveValue) return; 01733 style->setBorderRightStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE)); 01734 break; 01735 case CSS_PROP_BORDER_BOTTOM_STYLE: 01736 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderBottomStyle, BorderBottomStyle, BorderStyle) 01737 if (!primitiveValue) return; 01738 style->setBorderBottomStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE)); 01739 break; 01740 case CSS_PROP_BORDER_LEFT_STYLE: 01741 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(borderLeftStyle, BorderLeftStyle, BorderStyle) 01742 if (!primitiveValue) return; 01743 style->setBorderLeftStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE)); 01744 break; 01745 case CSS_PROP_OUTLINE_STYLE: 01746 HANDLE_INHERIT_AND_INITIAL_WITH_VALUE(outlineStyle, OutlineStyle, BorderStyle) 01747 if (!primitiveValue) return; 01748 style->setOutlineStyle((EBorderStyle)(primitiveValue->getIdent() - CSS_VAL_NONE)); 01749 break; 01750 case CSS_PROP_CAPTION_SIDE: 01751 { 01752 HANDLE_INHERIT_AND_INITIAL(captionSide, CaptionSide) 01753 if(!primitiveValue) break; 01754 ECaptionSide c = RenderStyle::initialCaptionSide(); 01755 switch(primitiveValue->getIdent()) 01756 { 01757 case CSS_VAL_TOP: 01758 c = CAPTOP; break; 01759 case CSS_VAL_BOTTOM: 01760 c = CAPBOTTOM; break; 01761 default: 01762 return; 01763 } 01764 style->setCaptionSide(c); 01765 return; 01766 } 01767 case CSS_PROP_CLEAR: 01768 { 01769 HANDLE_INHERIT_AND_INITIAL(clear, Clear) 01770 if(!primitiveValue) break; 01771 EClear c = CNONE; 01772 switch(primitiveValue->getIdent()) 01773 { 01774 case CSS_VAL_LEFT: 01775 c = CLEFT; break; 01776 case CSS_VAL_RIGHT: 01777 c = CRIGHT; break; 01778 case CSS_VAL_BOTH: 01779 c = CBOTH; break; 01780 case CSS_VAL_NONE: 01781 c = CNONE; break; 01782 default: 01783 return; 01784 } 01785 style->setClear(c); 01786 return; 01787 } 01788 case CSS_PROP_DIRECTION: 01789 { 01790 HANDLE_INHERIT_AND_INITIAL(direction, Direction) 01791 if(!primitiveValue) break; 01792 style->setDirection( (EDirection) (primitiveValue->getIdent() - CSS_VAL_LTR) ); 01793 return; 01794 } 01795 case CSS_PROP_DISPLAY: 01796 { 01797 HANDLE_INHERIT_AND_INITIAL(display, Display) 01798 if(!primitiveValue) break; 01799 int id = primitiveValue->getIdent(); 01800 style->setDisplay( id == CSS_VAL_NONE ? NONE : EDisplay(id - CSS_VAL_INLINE) ); 01801 break; 01802 } 01803 01804 case CSS_PROP_EMPTY_CELLS: 01805 { 01806 HANDLE_INHERIT(emptyCells, EmptyCells); 01807 if (!primitiveValue) break; 01808 int id = primitiveValue->getIdent(); 01809 if (id == CSS_VAL_SHOW) 01810 style->setEmptyCells(SHOW); 01811 else if (id == CSS_VAL_HIDE) 01812 style->setEmptyCells(HIDE); 01813 break; 01814 } 01815 case CSS_PROP_FLOAT: 01816 { 01817 HANDLE_INHERIT_AND_INITIAL(floating, Floating) 01818 if(!primitiveValue) return; 01819 EFloat f; 01820 switch(primitiveValue->getIdent()) 01821 { 01822 case CSS_VAL_LEFT: 01823 f = FLEFT; break; 01824 case CSS_VAL_RIGHT: 01825 f = FRIGHT; break; 01826 case CSS_VAL_NONE: 01827 case CSS_VAL_CENTER: //Non standart CSS-Value 01828 f = FNONE; break; 01829 default: 01830 return; 01831 } 01832 if (f!=FNONE && style->display()==LIST_ITEM) 01833 style->setDisplay(BLOCK); 01834 01835 style->setFloating(f); 01836 break; 01837 } 01838 01839 case CSS_PROP_FONT_STYLE: 01840 { 01841 FontDef fontDef = style->htmlFont().fontDef; 01842 if (isInherit) 01843 fontDef.italic = parentStyle->htmlFont().fontDef.italic; 01844 else if (isInitial) 01845 fontDef.italic = false; 01846 else { 01847 if(!primitiveValue) return; 01848 switch(primitiveValue->getIdent()) { 01849 case CSS_VAL_OBLIQUE: 01850 // ### oblique is the same as italic for the moment... 01851 case CSS_VAL_ITALIC: 01852 fontDef.italic = true; 01853 break; 01854 case CSS_VAL_NORMAL: 01855 fontDef.italic = false; 01856 break; 01857 default: 01858 return; 01859 } 01860 } 01861 fontDirty |= style->setFontDef( fontDef ); 01862 break; 01863 } 01864 01865 01866 case CSS_PROP_FONT_VARIANT: 01867 { 01868 FontDef fontDef = style->htmlFont().fontDef; 01869 if (isInherit) 01870 fontDef.smallCaps = parentStyle->htmlFont().fontDef.weight; 01871 else if (isInitial) 01872 fontDef.smallCaps = false; 01873 else { 01874 if(!primitiveValue) return; 01875 int id = primitiveValue->getIdent(); 01876 if ( id == CSS_VAL_NORMAL ) 01877 fontDef.smallCaps = false; 01878 else if ( id == CSS_VAL_SMALL_CAPS ) 01879 fontDef.smallCaps = true; 01880 else 01881 return; 01882 } 01883 fontDirty |= style->setFontDef( fontDef ); 01884 break; 01885 } 01886 01887 case CSS_PROP_FONT_WEIGHT: 01888 { 01889 FontDef fontDef = style->htmlFont().fontDef; 01890 if (isInherit) 01891 fontDef.weight = parentStyle->htmlFont().fontDef.weight; 01892 else if (isInitial) 01893 fontDef.weight = QFont::Normal; 01894 else { 01895 if(!primitiveValue) return; 01896 if(primitiveValue->getIdent()) 01897 { 01898 switch(primitiveValue->getIdent()) { 01899 // ### we just support normal and bold fonts at the moment... 01900 // setWeight can actually accept values between 0 and 99... 01901 case CSS_VAL_BOLD: 01902 case CSS_VAL_BOLDER: 01903 case CSS_VAL_600: 01904 case CSS_VAL_700: 01905 case CSS_VAL_800: 01906 case CSS_VAL_900: 01907 fontDef.weight = QFont::Bold; 01908 break; 01909 case CSS_VAL_NORMAL: 01910 case CSS_VAL_LIGHTER: 01911 case CSS_VAL_100: 01912 case CSS_VAL_200: 01913 case CSS_VAL_300: 01914 case CSS_VAL_400: 01915 case CSS_VAL_500: 01916 fontDef.weight = QFont::Normal; 01917 break; 01918 default: 01919 return; 01920 } 01921 } 01922 else 01923 { 01924 // ### fix parsing of 100-900 values in parser, apply them here 01925 } 01926 } 01927 fontDirty |= style->setFontDef( fontDef ); 01928 break; 01929 } 01930 01931 case CSS_PROP_LIST_STYLE_POSITION: 01932 { 01933 HANDLE_INHERIT_AND_INITIAL(listStylePosition, ListStylePosition) 01934 if (!primitiveValue) return; 01935 if (primitiveValue->getIdent()) 01936 style->setListStylePosition( (EListStylePosition) (primitiveValue->getIdent() - CSS_VAL_OUTSIDE) ); 01937 return; 01938 } 01939 01940 case CSS_PROP_LIST_STYLE_TYPE: 01941 { 01942 HANDLE_INHERIT_AND_INITIAL(listStyleType, ListStyleType) 01943 if (!primitiveValue) return; 01944 if (primitiveValue->getIdent()) 01945 { 01946 EListStyleType t; 01947 int id = primitiveValue->getIdent(); 01948 if ( id == CSS_VAL_NONE) { // important!! 01949 t = LNONE; 01950 } else { 01951 t = EListStyleType(id - CSS_VAL_DISC); 01952 } 01953 style->setListStyleType(t); 01954 } 01955 return; 01956 } 01957 01958 case CSS_PROP_OVERFLOW: 01959 { 01960 HANDLE_INHERIT_AND_INITIAL(overflow, Overflow) 01961 if (!primitiveValue) return; 01962 EOverflow o; 01963 switch(primitiveValue->getIdent()) 01964 { 01965 case CSS_VAL_VISIBLE: 01966 o = OVISIBLE; break; 01967 case CSS_VAL_HIDDEN: 01968 o = OHIDDEN; break; 01969 case CSS_VAL_SCROLL: 01970 o = OSCROLL; break; 01971 case CSS_VAL_AUTO: 01972 o = OAUTO; 01973 break; 01974 default: 01975 return; 01976 } 01977 style->setOverflow(o); 01978 return; 01979 } 01980 break; 01981 case CSS_PROP_PAGE_BREAK_AFTER: 01982 case CSS_PROP_PAGE_BREAK_BEFORE: 01983 case CSS_PROP_PAGE_BREAK_INSIDE: 01984 // case CSS_PROP_PAUSE_AFTER: 01985 // case CSS_PROP_PAUSE_BEFORE: 01986 break; 01987 01988 case CSS_PROP_POSITION: 01989 { 01990 HANDLE_INHERIT_AND_INITIAL(position, Position) 01991 if (!primitiveValue) return; 01992 EPosition p; 01993 switch(primitiveValue->getIdent()) 01994 { 01995 case CSS_VAL_STATIC: 01996 p = STATIC; break; 01997 case CSS_VAL_RELATIVE: 01998 p = RELATIVE; break; 01999 case CSS_VAL_ABSOLUTE: 02000 p = ABSOLUTE; break; 02001 case CSS_VAL_FIXED: 02002 { 02003 view->useSlowRepaints(); 02004 p = FIXED; 02005 break; 02006 } 02007 default: 02008 return; 02009 } 02010 style->setPosition(p); 02011 return; 02012 } 02013 02014 case CSS_PROP_TABLE_LAYOUT: { 02015 HANDLE_INHERIT_AND_INITIAL(tableLayout, TableLayout) 02016 02017 if ( !primitiveValue ) 02018 return; 02019 02020 ETableLayout l = RenderStyle::initialTableLayout(); 02021 switch( primitiveValue->getIdent() ) { 02022 case CSS_VAL_FIXED: 02023 l = TFIXED; 02024 // fall through 02025 case CSS_VAL_AUTO: 02026 style->setTableLayout( l ); 02027 default: 02028 break; 02029 } 02030 break; 02031 } 02032 02033 case CSS_PROP_UNICODE_BIDI: { 02034 HANDLE_INHERIT_AND_INITIAL(unicodeBidi, UnicodeBidi) 02035 switch (primitiveValue->getIdent()) { 02036 case CSS_VAL_NORMAL: 02037 style->setUnicodeBidi(UBNormal); 02038 break; 02039 case CSS_VAL_EMBED: 02040 style->setUnicodeBidi(Embed); 02041 break; 02042 case CSS_VAL_BIDI_OVERRIDE: 02043 style->setUnicodeBidi(Override); 02044 break; 02045 default: 02046 return; 02047 } 02048 break; 02049 } 02050 case CSS_PROP_TEXT_TRANSFORM: { 02051 HANDLE_INHERIT_AND_INITIAL(textTransform, TextTransform) 02052 02053 if(!primitiveValue->getIdent()) return; 02054 02055 ETextTransform tt; 02056 switch(primitiveValue->getIdent()) { 02057 case CSS_VAL_CAPITALIZE: tt = CAPITALIZE; break; 02058 case CSS_VAL_UPPERCASE: tt = UPPERCASE; break; 02059 case CSS_VAL_LOWERCASE: tt = LOWERCASE; break; 02060 case CSS_VAL_NONE: 02061 default: tt = TTNONE; break; 02062 } 02063 style->setTextTransform(tt); 02064 break; 02065 } 02066 02067 case CSS_PROP_VISIBILITY: 02068 { 02069 HANDLE_INHERIT_AND_INITIAL(visibility, Visibility) 02070 02071 switch( primitiveValue->getIdent() ) { 02072 case CSS_VAL_HIDDEN: 02073 style->setVisibility( HIDDEN ); 02074 break; 02075 case CSS_VAL_VISIBLE: 02076 style->setVisibility( VISIBLE ); 02077 break; 02078 case CSS_VAL_COLLAPSE: 02079 style->setVisibility( COLLAPSE ); 02080 default: 02081 break; 02082 } 02083 break; 02084 } 02085 case CSS_PROP_WHITE_SPACE: 02086 HANDLE_INHERIT_AND_INITIAL(whiteSpace, WhiteSpace) 02087 02088 if(!primitiveValue->getIdent()) return; 02089 02090 EWhiteSpace s; 02091 switch(primitiveValue->getIdent()) { 02092 case CSS_VAL__KHTML_NOWRAP: 02093 s = KHTML_NOWRAP; 02094 break; 02095 case CSS_VAL_NOWRAP: 02096 s = NOWRAP; 02097 break; 02098 case CSS_VAL_PRE: 02099 s = PRE; 02100 break; 02101 case CSS_VAL_NORMAL: 02102 default: 02103 s = NORMAL; 02104 break; 02105 } 02106 style->setWhiteSpace(s); 02107 break; 02108 02109 case CSS_PROP_BACKGROUND_POSITION: 02110 if (isInherit) { 02111 style->setBackgroundXPosition(parentStyle->backgroundXPosition()); 02112 style->setBackgroundYPosition(parentStyle->backgroundYPosition()); 02113 } 02114 else if (isInitial) { 02115 style->setBackgroundXPosition(RenderStyle::initialBackgroundXPosition()); 02116 style->setBackgroundYPosition(RenderStyle::initialBackgroundYPosition()); 02117 } 02118 break; 02119 case CSS_PROP_BACKGROUND_POSITION_X: { 02120 HANDLE_INHERIT_AND_INITIAL(backgroundXPosition, BackgroundXPosition) 02121 if(!primitiveValue) break; 02122 Length l; 02123 int type = primitiveValue->primitiveType(); 02124 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) 02125 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed); 02126 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) 02127 l = Length((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); 02128 else 02129 return; 02130 style->setBackgroundXPosition(l); 02131 break; 02132 } 02133 case CSS_PROP_BACKGROUND_POSITION_Y: { 02134 HANDLE_INHERIT_AND_INITIAL(backgroundYPosition, BackgroundYPosition) 02135 if(!primitiveValue) break; 02136 Length l; 02137 int type = primitiveValue->primitiveType(); 02138 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) 02139 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed); 02140 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) 02141 l = Length((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); 02142 else 02143 return; 02144 style->setBackgroundYPosition(l); 02145 break; 02146 } 02147 case CSS_PROP_BORDER_SPACING: 02148 assert( false ); 02149 02150 case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING: { 02151 HANDLE_INHERIT_AND_INITIAL(borderHorizontalSpacing, BorderHorizontalSpacing) 02152 if (!primitiveValue) break; 02153 short spacing = primitiveValue->computeLength(style, paintDeviceMetrics); 02154 style->setBorderHorizontalSpacing(spacing); 02155 break; 02156 } 02157 case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING: { 02158 HANDLE_INHERIT_AND_INITIAL(borderVerticalSpacing, BorderVerticalSpacing) 02159 if (!primitiveValue) break; 02160 short spacing = primitiveValue->computeLength(style, paintDeviceMetrics); 02161 style->setBorderVerticalSpacing(spacing); 02162 break; 02163 } 02164 02165 case CSS_PROP_CURSOR: 02166 HANDLE_INHERIT_AND_INITIAL(cursor, Cursor) 02167 if(primitiveValue) 02168 style->setCursor( (ECursor) (primitiveValue->getIdent() - CSS_VAL_AUTO) ); 02169 break; 02170 // colors || inherit 02171 case CSS_PROP_BACKGROUND_COLOR: 02172 case CSS_PROP_BORDER_TOP_COLOR: 02173 case CSS_PROP_BORDER_RIGHT_COLOR: 02174 case CSS_PROP_BORDER_BOTTOM_COLOR: 02175 case CSS_PROP_BORDER_LEFT_COLOR: 02176 case CSS_PROP_COLOR: 02177 case CSS_PROP_OUTLINE_COLOR: 02178 // this property is an extension used to get HTML4 <font> right. 02179 case CSS_PROP_SCROLLBAR_FACE_COLOR: 02180 case CSS_PROP_SCROLLBAR_SHADOW_COLOR: 02181 case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR: 02182 case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR: 02183 case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR: 02184 case CSS_PROP_SCROLLBAR_TRACK_COLOR: 02185 case CSS_PROP_SCROLLBAR_ARROW_COLOR: 02186 { 02187 QColor col; 02188 if (isInherit) { 02189 HANDLE_INHERIT_COND(CSS_PROP_BACKGROUND_COLOR, backgroundColor, BackgroundColor) 02190 HANDLE_INHERIT_COND(CSS_PROP_BORDER_TOP_COLOR, borderTopColor, BorderTopColor) 02191 HANDLE_INHERIT_COND(CSS_PROP_BORDER_BOTTOM_COLOR, borderBottomColor, BorderBottomColor) 02192 HANDLE_INHERIT_COND(CSS_PROP_BORDER_RIGHT_COLOR, borderRightColor, BorderRightColor) 02193 HANDLE_INHERIT_COND(CSS_PROP_BORDER_LEFT_COLOR, borderLeftColor, BorderLeftColor) 02194 HANDLE_INHERIT_COND(CSS_PROP_COLOR, color, Color) 02195 HANDLE_INHERIT_COND(CSS_PROP_OUTLINE_COLOR, outlineColor, OutlineColor) 02196 return; 02197 } else if (isInitial) { 02198 // The border/outline colors will just map to the invalid color |col| above. This will have the 02199 // effect of forcing the use of the currentColor when it comes time to draw the borders (and of 02200 // not painting the background since the color won't be valid). 02201 if (id == CSS_PROP_COLOR) 02202 col = RenderStyle::initialColor(); 02203 } else { 02204 if(!primitiveValue ) 02205 return; 02206 int ident = primitiveValue->getIdent(); 02207 if ( ident ) { 02208 if ( ident == CSS_VAL__KHTML_TEXT ) 02209 col = element->getDocument()->textColor(); 02210 else if ( ident == CSS_VAL_TRANSPARENT ) 02211 col = QColor(); 02212 else 02213 col = colorForCSSValue( ident ); 02214 } else if ( primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR ) { 02215 #ifndef APPLE_CHANGES 02216 if(qAlpha(primitiveValue->getRGBColorValue())) 02217 #endif 02218 col.setRgb(primitiveValue->getRGBColorValue()); 02219 } else { 02220 return; 02221 } 02222 } 02223 //kdDebug( 6080 ) << "applying color " << col.isValid() << endl; 02224 switch(id) 02225 { 02226 case CSS_PROP_BACKGROUND_COLOR: 02227 style->setBackgroundColor(col); break; 02228 case CSS_PROP_BORDER_TOP_COLOR: 02229 style->setBorderTopColor(col); break; 02230 case CSS_PROP_BORDER_RIGHT_COLOR: 02231 style->setBorderRightColor(col); break; 02232 case CSS_PROP_BORDER_BOTTOM_COLOR: 02233 style->setBorderBottomColor(col); break; 02234 case CSS_PROP_BORDER_LEFT_COLOR: 02235 style->setBorderLeftColor(col); break; 02236 case CSS_PROP_COLOR: 02237 style->setColor(col); break; 02238 case CSS_PROP__KHTML_TEXT_DECORATION_COLOR: 02239 style->setTextDecorationColor(col); break; 02240 case CSS_PROP_OUTLINE_COLOR: 02241 style->setOutlineColor(col); break; 02242 #ifndef APPLE_CHANGES 02243 case CSS_PROP_SCROLLBAR_FACE_COLOR: 02244 style->setPaletteColor(QPalette::Active, QColorGroup::Button, col); 02245 style->setPaletteColor(QPalette::Inactive, QColorGroup::Button, col); 02246 break; 02247 case CSS_PROP_SCROLLBAR_SHADOW_COLOR: 02248 style->setPaletteColor(QPalette::Active, QColorGroup::Shadow, col); 02249 style->setPaletteColor(QPalette::Inactive, QColorGroup::Shadow, col); 02250 break; 02251 case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR: 02252 style->setPaletteColor(QPalette::Active, QColorGroup::Light, col); 02253 style->setPaletteColor(QPalette::Inactive, QColorGroup::Light, col); 02254 break; 02255 case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR: 02256 break; 02257 case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR: 02258 style->setPaletteColor(QPalette::Active, QColorGroup::Dark, col); 02259 style->setPaletteColor(QPalette::Inactive, QColorGroup::Dark, col); 02260 break; 02261 case CSS_PROP_SCROLLBAR_TRACK_COLOR: 02262 style->setPaletteColor(QPalette::Active, QColorGroup::Mid, col); 02263 style->setPaletteColor(QPalette::Inactive, QColorGroup::Mid, col); 02264 style->setPaletteColor(QPalette::Active, QColorGroup::Background, col); 02265 style->setPaletteColor(QPalette::Inactive, QColorGroup::Background, col); 02266 // fall through 02267 case CSS_PROP_SCROLLBAR_BASE_COLOR: 02268 style->setPaletteColor(QPalette::Active, QColorGroup::Base, col); 02269 style->setPaletteColor(QPalette::Inactive, QColorGroup::Base, col); 02270 break; 02271 case CSS_PROP_SCROLLBAR_ARROW_COLOR: 02272 style->setPaletteColor(QPalette::Active, QColorGroup::ButtonText, col); 02273 style->setPaletteColor(QPalette::Inactive, QColorGroup::ButtonText, col); 02274 break; 02275 #endif 02276 default: 02277 return; 02278 } 02279 return; 02280 } 02281 break; 02282 // uri || inherit 02283 case CSS_PROP_BACKGROUND_IMAGE: 02284 { 02285 HANDLE_INHERIT_AND_INITIAL(backgroundImage, BackgroundImage) 02286 if (!primitiveValue) return; 02287 style->setBackgroundImage(static_cast<CSSImageValueImpl *>(primitiveValue)->image()); 02288 //kdDebug( 6080 ) << "setting image in style to " << image << endl; 02289 break; 02290 } 02291 case CSS_PROP_LIST_STYLE_IMAGE: 02292 { 02293 HANDLE_INHERIT_AND_INITIAL(listStyleImage, ListStyleImage) 02294 if (!primitiveValue) return; 02295 style->setListStyleImage(static_cast<CSSImageValueImpl *>(primitiveValue)->image()); 02296 //kdDebug( 6080 ) << "setting image in list to " << image->image() << endl; 02297 break; 02298 } 02299 02300 // length 02301 case CSS_PROP_BORDER_TOP_WIDTH: 02302 case CSS_PROP_BORDER_RIGHT_WIDTH: 02303 case CSS_PROP_BORDER_BOTTOM_WIDTH: 02304 case CSS_PROP_BORDER_LEFT_WIDTH: 02305 case CSS_PROP_OUTLINE_WIDTH: 02306 { 02307 if (isInherit) { 02308 HANDLE_INHERIT_COND(CSS_PROP_BORDER_TOP_WIDTH, borderTopWidth, BorderTopWidth) 02309 HANDLE_INHERIT_COND(CSS_PROP_BORDER_RIGHT_WIDTH, borderRightWidth, BorderRightWidth) 02310 HANDLE_INHERIT_COND(CSS_PROP_BORDER_BOTTOM_WIDTH, borderBottomWidth, BorderBottomWidth) 02311 HANDLE_INHERIT_COND(CSS_PROP_BORDER_LEFT_WIDTH, borderLeftWidth, BorderLeftWidth) 02312 HANDLE_INHERIT_COND(CSS_PROP_OUTLINE_WIDTH, outlineWidth, OutlineWidth) 02313 return; 02314 } 02315 else if (isInitial) { 02316 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BORDER_TOP_WIDTH, BorderTopWidth, BorderWidth) 02317 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BORDER_RIGHT_WIDTH, BorderRightWidth, BorderWidth) 02318 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BORDER_BOTTOM_WIDTH, BorderBottomWidth, BorderWidth) 02319 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BORDER_LEFT_WIDTH, BorderLeftWidth, BorderWidth) 02320 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_OUTLINE_WIDTH, OutlineWidth, BorderWidth) 02321 return; 02322 } 02323 02324 if(!primitiveValue) break; 02325 short width = 3; 02326 switch(primitiveValue->getIdent()) 02327 { 02328 case CSS_VAL_THIN: 02329 width = 1; 02330 break; 02331 case CSS_VAL_MEDIUM: 02332 width = 3; 02333 break; 02334 case CSS_VAL_THICK: 02335 width = 5; 02336 break; 02337 case CSS_VAL_INVALID: 02338 { 02339 double widthd = primitiveValue->computeLengthFloat(style, paintDeviceMetrics); 02340 width = (int)widthd; 02341 // somewhat resemble Mozilla's granularity 02342 // this makes border-width: 0.5pt borders visible 02343 if (width == 0 && widthd >= 0.025) width++; 02344 break; 02345 } 02346 default: 02347 return; 02348 } 02349 02350 if(width < 0) return; 02351 switch(id) 02352 { 02353 case CSS_PROP_BORDER_TOP_WIDTH: 02354 style->setBorderTopWidth(width); 02355 break; 02356 case CSS_PROP_BORDER_RIGHT_WIDTH: 02357 style->setBorderRightWidth(width); 02358 break; 02359 case CSS_PROP_BORDER_BOTTOM_WIDTH: 02360 style->setBorderBottomWidth(width); 02361 break; 02362 case CSS_PROP_BORDER_LEFT_WIDTH: 02363 style->setBorderLeftWidth(width); 02364 break; 02365 case CSS_PROP_OUTLINE_WIDTH: 02366 style->setOutlineWidth(width); 02367 break; 02368 default: 02369 return; 02370 } 02371 return; 02372 } 02373 02374 case CSS_PROP_LETTER_SPACING: 02375 case CSS_PROP_WORD_SPACING: 02376 { 02377 if (isInherit) { 02378 HANDLE_INHERIT_COND(CSS_PROP_LETTER_SPACING, letterSpacing, LetterSpacing) 02379 HANDLE_INHERIT_COND(CSS_PROP_WORD_SPACING, wordSpacing, WordSpacing) 02380 return; 02381 } else if (isInitial) { 02382 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_LETTER_SPACING, LetterSpacing, LetterWordSpacing) 02383 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_WORD_SPACING, WordSpacing, LetterWordSpacing) 02384 return; 02385 } 02386 if(!primitiveValue) return; 02387 02388 int width = 0; 02389 if (primitiveValue->getIdent() != CSS_VAL_NORMAL) 02390 width = primitiveValue->computeLength(style, paintDeviceMetrics); 02391 02392 switch(id) 02393 { 02394 case CSS_PROP_LETTER_SPACING: 02395 style->setLetterSpacing(width); 02396 break; 02397 case CSS_PROP_WORD_SPACING: 02398 style->setWordSpacing(width); 02399 break; 02400 // ### needs the definitions in renderstyle 02401 default: break; 02402 } 02403 return; 02404 } 02405 02406 // length, percent 02407 case CSS_PROP_MAX_WIDTH: 02408 // +none +inherit 02409 if(primitiveValue && primitiveValue->getIdent() == CSS_VAL_NONE) 02410 apply = true; 02411 case CSS_PROP_TOP: 02412 case CSS_PROP_LEFT: 02413 case CSS_PROP_RIGHT: 02414 case CSS_PROP_BOTTOM: 02415 case CSS_PROP_WIDTH: 02416 case CSS_PROP_MIN_WIDTH: 02417 case CSS_PROP_MARGIN_TOP: 02418 case CSS_PROP_MARGIN_RIGHT: 02419 case CSS_PROP_MARGIN_BOTTOM: 02420 case CSS_PROP_MARGIN_LEFT: 02421 // +inherit +auto 02422 if(id != CSS_PROP_MAX_WIDTH && primitiveValue && 02423 primitiveValue->getIdent() == CSS_VAL_AUTO) 02424 { 02425 //kdDebug( 6080 ) << "found value=auto" << endl; 02426 apply = true; 02427 } 02428 case CSS_PROP_PADDING_TOP: 02429 case CSS_PROP_PADDING_RIGHT: 02430 case CSS_PROP_PADDING_BOTTOM: 02431 case CSS_PROP_PADDING_LEFT: 02432 case CSS_PROP_TEXT_INDENT: 02433 // +inherit 02434 { 02435 if (isInherit) { 02436 HANDLE_INHERIT_COND(CSS_PROP_MAX_WIDTH, maxWidth, MaxWidth) 02437 HANDLE_INHERIT_COND(CSS_PROP_BOTTOM, bottom, Bottom) 02438 HANDLE_INHERIT_COND(CSS_PROP_TOP, top, Top) 02439 HANDLE_INHERIT_COND(CSS_PROP_LEFT, left, Left) 02440 HANDLE_INHERIT_COND(CSS_PROP_RIGHT, right, Right) 02441 HANDLE_INHERIT_COND(CSS_PROP_WIDTH, width, Width) 02442 HANDLE_INHERIT_COND(CSS_PROP_MIN_WIDTH, minWidth, MinWidth) 02443 HANDLE_INHERIT_COND(CSS_PROP_PADDING_TOP, paddingTop, PaddingTop) 02444 HANDLE_INHERIT_COND(CSS_PROP_PADDING_RIGHT, paddingRight, PaddingRight) 02445 HANDLE_INHERIT_COND(CSS_PROP_PADDING_BOTTOM, paddingBottom, PaddingBottom) 02446 HANDLE_INHERIT_COND(CSS_PROP_PADDING_LEFT, paddingLeft, PaddingLeft) 02447 HANDLE_INHERIT_COND(CSS_PROP_MARGIN_TOP, marginTop, MarginTop) 02448 HANDLE_INHERIT_COND(CSS_PROP_MARGIN_RIGHT, marginRight, MarginRight) 02449 HANDLE_INHERIT_COND(CSS_PROP_MARGIN_BOTTOM, marginBottom, MarginBottom) 02450 HANDLE_INHERIT_COND(CSS_PROP_MARGIN_LEFT, marginLeft, MarginLeft) 02451 HANDLE_INHERIT_COND(CSS_PROP_TEXT_INDENT, textIndent, TextIndent) 02452 return; 02453 } else if (isInitial) { 02454 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MAX_WIDTH, MaxWidth, MaxSize) 02455 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_BOTTOM, Bottom, Offset) 02456 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_TOP, Top, Offset) 02457 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_LEFT, Left, Offset) 02458 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_RIGHT, Right, Offset) 02459 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_WIDTH, Width, Size) 02460 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MIN_WIDTH, MinWidth, MinSize) 02461 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_PADDING_TOP, PaddingTop, Padding) 02462 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_PADDING_RIGHT, PaddingRight, Padding) 02463 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_PADDING_BOTTOM, PaddingBottom, Padding) 02464 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_PADDING_LEFT, PaddingLeft, Padding) 02465 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MARGIN_TOP, MarginTop, Margin) 02466 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MARGIN_RIGHT, MarginRight, Margin) 02467 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MARGIN_BOTTOM, MarginBottom, Margin) 02468 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MARGIN_LEFT, MarginLeft, Margin) 02469 HANDLE_INITIAL_COND(CSS_PROP_TEXT_INDENT, TextIndent) 02470 return; 02471 } 02472 02473 if (primitiveValue && !apply) { 02474 int type = primitiveValue->primitiveType(); 02475 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) 02476 // Handle our quirky margin units if we have them. 02477 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed, 02478 primitiveValue->isQuirkValue()); 02479 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) 02480 l = Length((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); 02481 else if (type == CSSPrimitiveValue::CSS_HTML_RELATIVE) 02482 l = Length(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_HTML_RELATIVE)), Relative); 02483 else 02484 return; 02485 apply = true; 02486 } 02487 if(!apply) return; 02488 switch(id) 02489 { 02490 case CSS_PROP_MAX_WIDTH: 02491 style->setMaxWidth(l); break; 02492 case CSS_PROP_BOTTOM: 02493 style->setBottom(l); break; 02494 case CSS_PROP_TOP: 02495 style->setTop(l); break; 02496 case CSS_PROP_LEFT: 02497 style->setLeft(l); break; 02498 case CSS_PROP_RIGHT: 02499 style->setRight(l); break; 02500 case CSS_PROP_WIDTH: 02501 style->setWidth(l); break; 02502 case CSS_PROP_MIN_WIDTH: 02503 style->setMinWidth(l); break; 02504 case CSS_PROP_PADDING_TOP: 02505 style->setPaddingTop(l); break; 02506 case CSS_PROP_PADDING_RIGHT: 02507 style->setPaddingRight(l); break; 02508 case CSS_PROP_PADDING_BOTTOM: 02509 style->setPaddingBottom(l); break; 02510 case CSS_PROP_PADDING_LEFT: 02511 style->setPaddingLeft(l); break; 02512 case CSS_PROP_MARGIN_TOP: 02513 style->setMarginTop(l); break; 02514 case CSS_PROP_MARGIN_RIGHT: 02515 style->setMarginRight(l); break; 02516 case CSS_PROP_MARGIN_BOTTOM: 02517 style->setMarginBottom(l); break; 02518 case CSS_PROP_MARGIN_LEFT: 02519 style->setMarginLeft(l); break; 02520 case CSS_PROP_TEXT_INDENT: 02521 style->setTextIndent(l); break; 02522 default: break; 02523 } 02524 return; 02525 } 02526 02527 case CSS_PROP_MAX_HEIGHT: 02528 if(primitiveValue && primitiveValue->getIdent() == CSS_VAL_NONE) 02529 apply = true; 02530 case CSS_PROP_HEIGHT: 02531 case CSS_PROP_MIN_HEIGHT: 02532 if(id != CSS_PROP_MAX_HEIGHT && primitiveValue && 02533 primitiveValue->getIdent() == CSS_VAL_AUTO) 02534 apply = true; 02535 if (isInherit) { 02536 HANDLE_INHERIT_COND(CSS_PROP_MAX_HEIGHT, maxHeight, MaxHeight) 02537 HANDLE_INHERIT_COND(CSS_PROP_HEIGHT, height, Height) 02538 HANDLE_INHERIT_COND(CSS_PROP_MIN_HEIGHT, minHeight, MinHeight) 02539 return; 02540 } 02541 else if (isInitial) { 02542 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MAX_HEIGHT, MaxHeight, MaxSize) 02543 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_HEIGHT, Height, Size) 02544 HANDLE_INITIAL_COND_WITH_VALUE(CSS_PROP_MIN_HEIGHT, MinHeight, MinSize) 02545 return; 02546 } 02547 02548 if (primitiveValue && !apply) 02549 { 02550 int type = primitiveValue->primitiveType(); 02551 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) 02552 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed); 02553 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) 02554 l = Length((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); 02555 else 02556 return; 02557 apply = true; 02558 } 02559 if(!apply) return; 02560 switch(id) 02561 { 02562 case CSS_PROP_MAX_HEIGHT: 02563 style->setMaxHeight(l); break; 02564 case CSS_PROP_HEIGHT: 02565 style->setHeight(l); break; 02566 case CSS_PROP_MIN_HEIGHT: 02567 style->setMinHeight(l); break; 02568 default: 02569 return; 02570 } 02571 return; 02572 02573 break; 02574 02575 case CSS_PROP_VERTICAL_ALIGN: 02576 HANDLE_INHERIT_AND_INITIAL(verticalAlign, VerticalAlign) 02577 if (!primitiveValue) return; 02578 if (primitiveValue->getIdent()) { 02579 khtml::EVerticalAlign align; 02580 02581 switch(primitiveValue->getIdent()) 02582 { 02583 case CSS_VAL_TOP: 02584 align = TOP; break; 02585 case CSS_VAL_BOTTOM: 02586 align = BOTTOM; break; 02587 case CSS_VAL_MIDDLE: 02588 align = MIDDLE; break; 02589 case CSS_VAL_BASELINE: 02590 align = BASELINE; break; 02591 case CSS_VAL_TEXT_BOTTOM: 02592 align = TEXT_BOTTOM; break; 02593 case CSS_VAL_TEXT_TOP: 02594 align = TEXT_TOP; break; 02595 case CSS_VAL_SUB: 02596 align = SUB; break; 02597 case CSS_VAL_SUPER: 02598 align = SUPER; break; 02599 case CSS_VAL__KHTML_BASELINE_MIDDLE: 02600 align = BASELINE_MIDDLE; break; 02601 default: 02602 return; 02603 } 02604 style->setVerticalAlign(align); 02605 return; 02606 } else { 02607 int type = primitiveValue->primitiveType(); 02608 Length l; 02609 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) 02610 l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed ); 02611 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) 02612 l = Length( int( primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE) ), Percent ); 02613 02614 style->setVerticalAlign( LENGTH ); 02615 style->setVerticalAlignLength( l ); 02616 } 02617 break; 02618 02619 case CSS_PROP_FONT_SIZE: 02620 { 02621 FontDef fontDef = style->htmlFont().fontDef; 02622 int oldSize; 02623 int size = 0; 02624 02625 float toPix = paintDeviceMetrics->logicalDpiY()/72.; 02626 if (toPix < 96./72.) toPix = 96./72.; 02627 02628 int minFontSize = int(settings->minFontSize() * toPix); 02629 02630 if(parentNode) { 02631 oldSize = parentStyle->font().pixelSize(); 02632 } else 02633 oldSize = m_fontSizes[3]; 02634 02635 if (isInherit ) 02636 size = oldSize; 02637 else if (isInitial) 02638 size = m_fontSizes[3]; 02639 else if(primitiveValue->getIdent()) { 02640 // keywords are being used. Pick the correct default 02641 // based off the font family. 02642 #ifdef APPLE_CHANGES 02643 QValueList<int>& fontSizes = (fontDef.genericFamily == FontDef::eMonospace) ? 02644 m_fixedFontSizes : m_fontSizes; 02645 #else 02646 QValueList<int>& fontSizes = m_fontSizes; 02647 #endif 02648 switch(primitiveValue->getIdent()) 02649 { 02650 case CSS_VAL_XX_SMALL: size = int( fontSizes[0] ); break; 02651 case CSS_VAL_X_SMALL: size = int( fontSizes[1] ); break; 02652 case CSS_VAL_SMALL: size = int( fontSizes[2] ); break; 02653 case CSS_VAL_MEDIUM: size = int( fontSizes[3] ); break; 02654 case CSS_VAL_LARGE: size = int( fontSizes[4] ); break; 02655 case CSS_VAL_X_LARGE: size = int( fontSizes[5] ); break; 02656 case CSS_VAL_XX_LARGE: size = int( fontSizes[6] ); break; 02657 case CSS_VAL__KHTML_XXX_LARGE: size = ( fontSizes[6]*5 )/3; break; 02658 case CSS_VAL_LARGER: 02659 // ### use the next bigger standardSize!!! 02660 size = ( oldSize * 5 ) / 4; 02661 break; 02662 case CSS_VAL_SMALLER: 02663 size = ( oldSize * 4 ) / 5; 02664 break; 02665 default: 02666 return; 02667 } 02668 02669 } else { 02670 int type = primitiveValue->primitiveType(); 02671 if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) { 02672 if (!khtml::printpainter && element && element->getDocument()->view()) 02673 size = int( primitiveValue->computeLengthFloat(parentStyle, paintDeviceMetrics) * 02674 element->getDocument()->view()->part()->zoomFactor() ) / 100; 02675 else 02676 size = int( primitiveValue->computeLengthFloat(parentStyle, paintDeviceMetrics) ); 02677 } 02678 else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) 02679 size = int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE) 02680 * parentStyle->font().pixelSize()) / 100; 02681 else 02682 return; 02683 } 02684 02685 if(size < 1) return; 02686 02687 // we never want to get smaller than the minimum font size to keep fonts readable 02688 if(size < minFontSize ) size = minFontSize; 02689 02690 //kdDebug( 6080 ) << "computed raw font size: " << size << endl; 02691 02692 fontDef.size = size; 02693 fontDirty |= style->setFontDef( fontDef ); 02694 return; 02695 } 02696 02697 case CSS_PROP_Z_INDEX: 02698 { 02699 HANDLE_INHERIT(zIndex, ZIndex) 02700 else if (isInitial) { 02701 style->setHasAutoZIndex(); 02702 return; 02703 } 02704 02705 if (!primitiveValue) 02706 return; 02707 02708 if (primitiveValue->getIdent() == CSS_VAL_AUTO) { 02709 style->setHasAutoZIndex(); 02710 return; 02711 } 02712 02713 if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER) 02714 return; // Error case. 02715 02716 style->setZIndex((int)primitiveValue->floatValue(CSSPrimitiveValue::CSS_NUMBER)); 02717 return; 02718 } 02719 02720 /* 02721 case CSS_PROP_WIDOWS: 02722 { 02723 HANDLE_INHERIT_AND_INITIAL(widows, Widows) 02724 if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER) 02725 return; 02726 style->setWidows((int)primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_NUMBER)); 02727 break; 02728 } 02729 02730 case CSS_PROP_ORPHANS: 02731 { 02732 HANDLE_INHERIT_AND_INITIAL(orphans, Orphans) 02733 if (!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER) 02734 return; 02735 style->setOrphans((int)primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_NUMBER)); 02736 break; 02737 } 02738 */ 02739 02740 // length, percent, number 02741 case CSS_PROP_LINE_HEIGHT: 02742 { 02743 HANDLE_INHERIT_AND_INITIAL(lineHeight, LineHeight) 02744 if(!primitiveValue) return; 02745 Length lineHeight; 02746 int type = primitiveValue->primitiveType(); 02747 if (primitiveValue->getIdent() == CSS_VAL_NORMAL) 02748 lineHeight = Length( -100, Percent ); 02749 else if (type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) { 02750 #ifdef APPLE_CHANGES 02751 double multiplier = 1.0; 02752 // Scale for the font zoom factor only for types other than "em" and "ex", since those are 02753 // already based on the font size. 02754 if (type != CSSPrimitiveValue::CSS_EMS && type != CSSPrimitiveValue::CSS_EXS && view && view->part()) { 02755 multiplier = view->part()->zoomFactor() / 100.0; 02756 } 02757 lineHeight = Length(primitiveValue->computeLength(style, paintDeviceMetrics, multiplier), Fixed); 02758 #else 02759 lineHeight = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed); 02760 #endif 02761 } else if (type == CSSPrimitiveValue::CSS_PERCENTAGE) 02762 lineHeight = Length( ( style->font().pixelSize() * int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE)) ) / 100, Fixed ); 02763 else if (type == CSSPrimitiveValue::CSS_NUMBER) 02764 lineHeight = Length(int(primitiveValue->floatValue(CSSPrimitiveValue::CSS_NUMBER)*100), Percent); 02765 else 02766 return; 02767 style->setLineHeight(lineHeight); 02768 return; 02769 } 02770 02771 // string 02772 case CSS_PROP_TEXT_ALIGN: 02773 { 02774 HANDLE_INHERIT_AND_INITIAL(textAlign, TextAlign) 02775 if (!primitiveValue) return; 02776 if (primitiveValue->getIdent()) 02777 style->setTextAlign( (ETextAlign) (primitiveValue->getIdent() - CSS_VAL__KHTML_AUTO) ); 02778 return; 02779 } 02780 02781 // rect 02782 case CSS_PROP_CLIP: 02783 { 02784 Length top; 02785 Length right; 02786 Length bottom; 02787 Length left; 02788 bool hasClip = true; 02789 if (isInherit) { 02790 if (parentStyle->hasClip()) { 02791 top = parentStyle->clipTop(); 02792 right = parentStyle->clipRight(); 02793 bottom = parentStyle->clipBottom(); 02794 left = parentStyle->clipLeft(); 02795 } 02796 else { 02797 hasClip = false; 02798 top = right = bottom = left = Length(); 02799 } 02800 } else if (isInitial) { 02801 hasClip = false; 02802 top = right = bottom = left = Length(); 02803 } else if ( !primitiveValue ) { 02804 break; 02805 } else if ( primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RECT ) { 02806 RectImpl *rect = primitiveValue->getRectValue(); 02807 if ( !rect ) 02808 break; 02809 top = convertToLength( rect->top(), style, paintDeviceMetrics ); 02810 right = convertToLength( rect->right(), style, paintDeviceMetrics ); 02811 bottom = convertToLength( rect->bottom(), style, paintDeviceMetrics ); 02812 left = convertToLength( rect->left(), style, paintDeviceMetrics ); 02813 02814 } else if ( primitiveValue->getIdent() != CSS_VAL_AUTO ) { 02815 break; 02816 } 02817 // qDebug("setting clip top to %d", top.value ); 02818 // qDebug("setting clip right to %d", right.value ); 02819 // qDebug("setting clip bottom to %d", bottom.value ); 02820 // qDebug("setting clip left to %d", left.value ); 02821 style->setClip(top, right, bottom, left ); 02822 style->setHasClip(hasClip); 02823 // rect, ident 02824 break; 02825 } 02826 02827 // lists 02828 case CSS_PROP_CONTENT: 02829 // list of string, uri, counter, attr, i 02830 { 02831 // FIXME: In CSS3, it will be possible to inherit content. In CSS2 it is not. This 02832 // note is a reminder that eventually "inherit" needs to be supported. 02833 if (!(style->styleType()==RenderStyle::BEFORE || 02834 style->styleType()==RenderStyle::AFTER)) 02835 break; 02836 02837 if (isInitial) { 02838 if (style->contentData()) 02839 style->contentData()->clearContent(); 02840 return; 02841 } 02842 02843 if(!value->isValueList()) return; 02844 CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value); 02845 int len = list->length(); 02846 02847 for(int i = 0; i < len; i++) { 02848 CSSValueImpl *item = list->item(i); 02849 if(!item->isPrimitiveValue()) continue; 02850 CSSPrimitiveValueImpl *val = static_cast<CSSPrimitiveValueImpl *>(item); 02851 if(val->primitiveType()==CSSPrimitiveValue::CSS_STRING) 02852 { 02853 style->setContent(val->getStringValue(), i != 0); 02854 } 02855 else if (val->primitiveType()==CSSPrimitiveValue::CSS_ATTR) 02856 { 02857 #ifdef APPLE_CHANGES 02858 int attrID = element->getDocument()->attrId(0, val->getStringValue(), false); 02859 if (attrID) 02860 style->setContent(element->getAttribute(attrID).implementation(), i != 0); 02861 #else 02862 int attrID = element->getDocument()->getId(NodeImpl::AttributeId, val->getStringValue(), false, true); 02863 if (attrID) 02864 style->setContent(element->getAttribute(attrID).implementation(), i != 0); 02865 #endif 02866 } 02867 else if (val->primitiveType()==CSSPrimitiveValue::CSS_URI) 02868 { 02869 CSSImageValueImpl *image = static_cast<CSSImageValueImpl *>(val); 02870 style->setContent(image->image(), i != 0); 02871 } 02872 02873 } 02874 break; 02875 } 02876 02877 case CSS_PROP_COUNTER_INCREMENT: 02878 // list of CSS2CounterIncrement 02879 case CSS_PROP_COUNTER_RESET: 02880 // list of CSS2CounterReset 02881 break; 02882 case CSS_PROP_FONT_FAMILY: 02883 // list of strings and ids 02884 { 02885 if (isInherit) { 02886 FontDef parentFontDef = parentStyle->htmlFont().fontDef; 02887 FontDef fontDef = style->htmlFont().fontDef; 02888 fontDef.family = parentFontDef.family; 02889 if (style->setFontDef(fontDef)) 02890 fontDirty = true; 02891 return; 02892 } 02893 else if (isInitial) { 02894 FontDef fontDef = style->htmlFont().fontDef; 02895 FontDef initialDef = FontDef(); 02896 #ifdef APPLE_CHANGES 02897 fontDef.family = initialDef.firstFamily(); 02898 #else 02899 fontDef.family = QString::null; 02900 #endif 02901 if (style->setFontDef(fontDef)) 02902 fontDirty = true; 02903 return; 02904 } 02905 if(!value->isValueList()) return; 02906 FontDef fontDef = style->htmlFont().fontDef; 02907 CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value); 02908 int len = list->length(); 02909 for(int i = 0; i < len; i++) { 02910 CSSValueImpl *item = list->item(i); 02911 if(!item->isPrimitiveValue()) continue; 02912 CSSPrimitiveValueImpl *val = static_cast<CSSPrimitiveValueImpl *>(item); 02913 QString face; 02914 if( val->primitiveType() == CSSPrimitiveValue::CSS_STRING ) 02915 face = static_cast<FontFamilyValueImpl *>(val)->fontName(); 02916 else if ( val->primitiveType() == CSSPrimitiveValue::CSS_IDENT ) { 02917 switch( val->getIdent() ) { 02918 case CSS_VAL_SERIF: 02919 face = settings->serifFontName(); 02920 break; 02921 case CSS_VAL_SANS_SERIF: 02922 face = settings->sansSerifFontName(); 02923 break; 02924 case CSS_VAL_CURSIVE: 02925 face = settings->cursiveFontName(); 02926 break; 02927 case CSS_VAL_FANTASY: 02928 face = settings->fantasyFontName(); 02929 break; 02930 case CSS_VAL_MONOSPACE: 02931 face = settings->fixedFontName(); 02932 break; 02933 default: 02934 return; 02935 } 02936 } else { 02937 return; 02938 } 02939 if ( !face.isEmpty() ) { 02940 fontDef.family = face; 02941 fontDirty |= style->setFontDef( fontDef ); 02942 return; 02943 } 02944 } 02945 break; 02946 } 02947 case CSS_PROP_QUOTES: 02948 // list of strings or i 02949 case CSS_PROP_SIZE: 02950 // ### look up 02951 break; 02952 case CSS_PROP_TEXT_DECORATION: { 02953 // list of ident 02954 HANDLE_INHERIT_AND_INITIAL(textDecoration, TextDecoration) 02955 int t = RenderStyle::initialTextDecoration(); 02956 if(primitiveValue && primitiveValue->getIdent() == CSS_VAL_NONE) { 02957 // do nothing 02958 } else { 02959 if(!value->isValueList()) return; 02960 CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value); 02961 int len = list->length(); 02962 for(int i = 0; i < len; i++) 02963 { 02964 CSSValueImpl *item = list->item(i); 02965 if(!item->isPrimitiveValue()) continue; 02966 primitiveValue = static_cast<CSSPrimitiveValueImpl *>(item); 02967 switch(primitiveValue->getIdent()) 02968 { 02969 case CSS_VAL_NONE: 02970 t = TDNONE; break; 02971 case CSS_VAL_UNDERLINE: 02972 t |= UNDERLINE; break; 02973 case CSS_VAL_OVERLINE: 02974 t |= OVERLINE; break; 02975 case CSS_VAL_LINE_THROUGH: 02976 t |= LINE_THROUGH; break; 02977 case CSS_VAL_BLINK: 02978 t |= BLINK; break; 02979 default: 02980 return; 02981 } 02982 } 02983 } 02984 style->setTextDecoration(t); 02985 break; 02986 } 02987 case CSS_PROP__KHTML_FLOW_MODE: 02988 HANDLE_INHERIT_AND_INITIAL(flowAroundFloats, FlowAroundFloats) 02989 if (!primitiveValue) return; 02990 if (primitiveValue->getIdent()) { 02991 style->setFlowAroundFloats( primitiveValue->getIdent() == CSS_VAL__KHTML_AROUND_FLOATS ); 02992 return; 02993 } 02994 break; 02995 case CSS_PROP__KHTML_USER_INPUT: { 02996 if(value->cssValueType() == CSSValue::CSS_INHERIT) 02997 { 02998 if(!parentNode) return; 02999 style->setUserInput(parentStyle->userInput()); 03000 // kdDebug() << "UI erm" << endl; 03001 return; 03002 } 03003 if(!primitiveValue) return; 03004 int id = primitiveValue->getIdent(); 03005 if (id == CSS_VAL_NONE) 03006 style->setUserInput(UI_NONE); 03007 else 03008 style->setUserInput(EUserInput(id - CSS_VAL_ENABLED)); 03009 // kdDebug(6080) << "userInput: " << style->userEdit() << endl; 03010 return; 03011 } 03012 03013 // shorthand properties 03014 case CSS_PROP_BACKGROUND: 03015 if (isInherit) { 03016 style->setBackgroundColor(parentStyle->backgroundColor()); 03017 style->setBackgroundImage(parentStyle->backgroundImage()); 03018 style->setBackgroundRepeat(parentStyle->backgroundRepeat()); 03019 style->setBackgroundAttachment(parentStyle->backgroundAttachment()); 03020 style->setBackgroundXPosition(parentStyle->backgroundXPosition()); 03021 style->setBackgroundYPosition(parentStyle->backgroundYPosition()); 03022 } 03023 else if (isInitial) { 03024 style->setBackgroundColor(QColor()); 03025 style->setBackgroundImage(RenderStyle::initialBackgroundImage()); 03026 style->setBackgroundRepeat(RenderStyle::initialBackgroundRepeat()); 03027 style->setBackgroundAttachment(RenderStyle::initialBackgroundAttachment()); 03028 style->setBackgroundXPosition(RenderStyle::initialBackgroundXPosition()); 03029 style->setBackgroundYPosition(RenderStyle::initialBackgroundYPosition()); 03030 } 03031 break; 03032 case CSS_PROP_BORDER_COLOR: 03033 if(primitiveValue && primitiveValue->getIdent() == CSS_VAL_TRANSPARENT) 03034 { 03035 style->setBorderTopColor(QColor()); 03036 style->setBorderBottomColor(QColor()); 03037 style->setBorderLeftColor(QColor()); 03038 style->setBorderRightColor(QColor()); 03039 return; 03040 } 03041 case CSS_PROP_BORDER: 03042 case CSS_PROP_BORDER_STYLE: 03043 case CSS_PROP_BORDER_WIDTH: 03044 if(id == CSS_PROP_BORDER || id == CSS_PROP_BORDER_COLOR) 03045 { 03046 if (isInherit) { 03047 style->setBorderTopColor(parentStyle->borderTopColor()); 03048 style->setBorderBottomColor(parentStyle->borderBottomColor()); 03049 style->setBorderLeftColor(parentStyle->borderLeftColor()); 03050 style->setBorderRightColor(parentStyle->borderRightColor()); 03051 } 03052 else if (isInitial) { 03053 style->setBorderTopColor(QColor()); // Reset to invalid color so currentColor is used instead. 03054 style->setBorderBottomColor(QColor()); 03055 style->setBorderLeftColor(QColor()); 03056 style->setBorderRightColor(QColor()); 03057 } 03058 } 03059 if (id == CSS_PROP_BORDER || id == CSS_PROP_BORDER_STYLE) 03060 { 03061 if (isInherit) { 03062 style->setBorderTopStyle(parentStyle->borderTopStyle()); 03063 style->setBorderBottomStyle(parentStyle->borderBottomStyle()); 03064 style->setBorderLeftStyle(parentStyle->borderLeftStyle()); 03065 style->setBorderRightStyle(parentStyle->borderRightStyle()); 03066 } 03067 else if (isInitial) { 03068 style->setBorderTopStyle(RenderStyle::initialBorderStyle()); 03069 style->setBorderBottomStyle(RenderStyle::initialBorderStyle()); 03070 style->setBorderLeftStyle(RenderStyle::initialBorderStyle()); 03071 style->setBorderRightStyle(RenderStyle::initialBorderStyle()); 03072 } 03073 } 03074 if (id == CSS_PROP_BORDER || id == CSS_PROP_BORDER_WIDTH) 03075 { 03076 if (isInherit) { 03077 style->setBorderTopWidth(parentStyle->borderTopWidth()); 03078 style->setBorderBottomWidth(parentStyle->borderBottomWidth()); 03079 style->setBorderLeftWidth(parentStyle->borderLeftWidth()); 03080 style->setBorderRightWidth(parentStyle->borderRightWidth()); 03081 } 03082 else if (isInitial) { 03083 style->setBorderTopWidth(RenderStyle::initialBorderWidth()); 03084 style->setBorderBottomWidth(RenderStyle::initialBorderWidth()); 03085 style->setBorderLeftWidth(RenderStyle::initialBorderWidth()); 03086 style->setBorderRightWidth(RenderStyle::initialBorderWidth()); 03087 } 03088 } 03089 return; 03090 case CSS_PROP_BORDER_TOP: 03091 if ( isInherit ) { 03092 style->setBorderTopColor(parentStyle->borderTopColor()); 03093 style->setBorderTopStyle(parentStyle->borderTopStyle()); 03094 style->setBorderTopWidth(parentStyle->borderTopWidth()); 03095 } else if (isInitial) 03096 style->resetBorderTop(); 03097 return; 03098 case CSS_PROP_BORDER_RIGHT: 03099 if (isInherit) { 03100 style->setBorderRightColor(parentStyle->borderRightColor()); 03101 style->setBorderRightStyle(parentStyle->borderRightStyle()); 03102 style->setBorderRightWidth(parentStyle->borderRightWidth()); 03103 } 03104 else if (isInitial) 03105 style->resetBorderRight(); 03106 return; 03107 case CSS_PROP_BORDER_BOTTOM: 03108 if (isInherit) { 03109 style->setBorderBottomColor(parentStyle->borderBottomColor()); 03110 style->setBorderBottomStyle(parentStyle->borderBottomStyle()); 03111 style->setBorderBottomWidth(parentStyle->borderBottomWidth()); 03112 } 03113 else if (isInitial) 03114 style->resetBorderBottom(); 03115 return; 03116 case CSS_PROP_BORDER_LEFT: 03117 if (isInherit) { 03118 style->setBorderLeftColor(parentStyle->borderLeftColor()); 03119 style->setBorderLeftStyle(parentStyle->borderLeftStyle()); 03120 style->setBorderLeftWidth(parentStyle->borderLeftWidth()); 03121 } 03122 else if (isInitial) 03123 style->resetBorderLeft(); 03124 return; 03125 case CSS_PROP_MARGIN: 03126 if (isInherit) { 03127 style->setMarginTop(parentStyle->marginTop()); 03128 style->setMarginBottom(parentStyle->marginBottom()); 03129 style->setMarginLeft(parentStyle->marginLeft()); 03130 style->setMarginRight(parentStyle->marginRight()); 03131 } 03132 else if (isInitial) 03133 style->resetMargin(); 03134 return; 03135 case CSS_PROP_PADDING: 03136 if (isInherit) { 03137 style->setPaddingTop(parentStyle->paddingTop()); 03138 style->setPaddingBottom(parentStyle->paddingBottom()); 03139 style->setPaddingLeft(parentStyle->paddingLeft()); 03140 style->setPaddingRight(parentStyle->paddingRight()); 03141 } 03142 else if (isInitial) 03143 style->resetPadding(); 03144 return; 03145 case CSS_PROP_FONT: 03146 if ( isInherit ) { 03147 FontDef fontDef = parentStyle->htmlFont().fontDef; 03148 style->setLineHeight( parentStyle->lineHeight() ); 03149 fontDirty |= style->setFontDef( fontDef ); 03150 } else if (isInitial) { 03151 FontDef fontDef; 03152 style->setLineHeight(RenderStyle::initialLineHeight()); 03153 if (style->setFontDef( fontDef )) 03154 fontDirty = true; 03155 } else if ( value->isFontValue() ) { 03156 FontValueImpl *font = static_cast<FontValueImpl *>(value); 03157 if ( !font->style || !font->variant || !font->weight || 03158 !font->size || !font->lineHeight || !font->family ) 03159 return; 03160 applyRule( CSS_PROP_FONT_STYLE, font->style ); 03161 applyRule( CSS_PROP_FONT_VARIANT, font->variant ); 03162 applyRule( CSS_PROP_FONT_WEIGHT, font->weight ); 03163 applyRule( CSS_PROP_FONT_SIZE, font->size ); 03164 03165 // Line-height can depend on font().pixelSize(), so we have to update the font 03166 // before we evaluate line-height, e.g., font: 1em/1em. FIXME: Still not 03167 // good enough: style="font:1em/1em; font-size:36px" should have a line-height of 36px. 03168 if (fontDirty) 03169 CSSStyleSelector::style->htmlFont().update( paintDeviceMetrics ); 03170 03171 applyRule( CSS_PROP_LINE_HEIGHT, font->lineHeight ); 03172 applyRule( CSS_PROP_FONT_FAMILY, font->family ); 03173 } 03174 return; 03175 03176 case CSS_PROP_LIST_STYLE: 03177 if (isInherit) { 03178 style->setListStyleType(parentStyle->listStyleType()); 03179 style->setListStyleImage(parentStyle->listStyleImage()); 03180 style->setListStylePosition(parentStyle->listStylePosition()); 03181 } 03182 else if (isInitial) { 03183 style->setListStyleType(RenderStyle::initialListStyleType()); 03184 style->setListStyleImage(RenderStyle::initialListStyleImage()); 03185 style->setListStylePosition(RenderStyle::initialListStylePosition()); 03186 } 03187 break; 03188 case CSS_PROP_OUTLINE: 03189 if (isInherit) { 03190 style->setOutlineWidth(parentStyle->outlineWidth()); 03191 style->setOutlineColor(parentStyle->outlineColor()); 03192 style->setOutlineStyle(parentStyle->outlineStyle()); 03193 } 03194 else if (isInitial) 03195 style->resetOutline(); 03196 break; 03197 default: 03198 return; 03199 } 03200 } 03201 03202 #ifdef APPLE_CHANGES 03203 void CSSStyleSelector::checkForGenericFamilyChange(RenderStyle* aStyle, RenderStyle* aParentStyle) 03204 { 03205 const FontDef& childFont = aStyle->htmlFont().fontDef; 03206 03207 if (childFont.sizeSpecified || !aParentStyle) 03208 return; 03209 03210 const FontDef& parentFont = aParentStyle->htmlFont().fontDef; 03211 03212 if (childFont.genericFamily == parentFont.genericFamily) 03213 return; 03214 03215 // For now, lump all families but monospace together. 03216 if (childFont.genericFamily != FontDef::eMonospace && 03217 parentFont.genericFamily != FontDef::eMonospace) 03218 return; 03219 03220 // We know the parent is monospace or the child is monospace, and that font 03221 // size was unspecified. We want to alter our font size to use the correct 03222 // "medium" font for our family. 03223 float size = 0; 03224 int minFontSize = settings->minFontSize(); 03225 size = (childFont.genericFamily == FontDef::eMonospace) ? m_fixedFontSizes[3] : m_fontSizes[3]; 03226 int isize = (int)size; 03227 if (isize < minFontSize) 03228 isize = minFontSize; 03229 03230 FontDef newFontDef(childFont); 03231 newFontDef.size = isize; 03232 aStyle->setFontDef(newFontDef); 03233 } 03234 #endif 03235 03236 } // namespace khtml
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Aug 30 22:56:24 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003