css_valueimpl.cpp Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# css_valueimpl.cpp

    00001
    00022 #include "dom/css_value.h"
    00023 #include "dom/dom_exception.h"
    00024 #include "dom/dom_string.h"
    00025
    00026 #include "css/css_valueimpl.h"
    00027 #include "css/css_ruleimpl.h"
    00028 #include "css/css_stylesheetimpl.h"
    00029 #include "css/cssparser.h"
    00030 #include "css/cssproperties.h"
    00031 #include "css/cssvalues.h"
    00032
    00033 #include "xml/dom_stringimpl.h"
    00034 #include "xml/dom_docimpl.h"
    00035
    00036 #include "misc/loader.h"
    00037
    00038 #include "rendering/render_style.h"
    00039
    00040 #include <kdebug.h>
    00041 #include <qregexp.h>
    00042 #include <qpaintdevice.h>
    00043 #include <qpaintdevicemetrics.h>
    00044
    00045 // Hack for debugging purposes
    00046 extern DOM::DOMString getPropertyName(unsigned short id);
    00047
    00048 using namespace DOM;
    00049
    00050 CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent)
    00051     : StyleBaseImpl(parent)
    00052 {
    00053     m_lstValues = 0;
    00054     m_node = 0;
    00055 }
    00056
    00057 CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent, QPtrList<CSSProperty> *lstValues)
    00058     : StyleBaseImpl(parent)
    00059 {
    00060     m_lstValues = lstValues;
    00061     m_node = 0;
    00062 }
    00063
    00064 CSSStyleDeclarationImpl&  CSSStyleDeclarationImpl::operator= (const CSSStyleDeclarationImpl& o)
    00065 {
    00066     // don't attach it to the same node, just leave the current m_node value
    00067     delete m_lstValues;
    00068     m_lstValues = 0;
    00069     if (o.m_lstValues) {
    00070         m_lstValues = new QPtrList<CSSProperty>;
    00071         m_lstValues->setAutoDelete( true );
    00072
    00073         QPtrListIterator<CSSProperty> lstValuesIt(*o.m_lstValues);
    00074         for (lstValuesIt.toFirst(); lstValuesIt.current(); ++lstValuesIt)
    00075             m_lstValues->append(new CSSProperty(*lstValuesIt.current()));
    00076     }
    00077
    00078     return *this;
    00079 }
    00080
    00081 CSSStyleDeclarationImpl::~CSSStyleDeclarationImpl()
    00082 {
    00083     delete m_lstValues;
    00084     // we don't use refcounting for m_node, to avoid cyclic references (see ElementImpl)
    00085 }
    00086
    00087 DOMString CSSStyleDeclarationImpl::getPropertyValue( int propertyID ) const
    00088 {
    00089     if(!m_lstValues) return DOMString();
    00090
    00091     CSSValueImpl* value = getPropertyCSSValue( propertyID );
    00092     if ( value )
    00093         return value->cssText();
    00094
    00095     // Shorthand and 4-values properties
    00096     switch ( propertyID ) {
    00097     case CSS_PROP_BACKGROUND_POSITION:
    00098     {
    00099         // ## Is this correct? The code in cssparser.cpp is confusing
    00100         const int properties[2] = { CSS_PROP_BACKGROUND_POSITION_X,
    00101                                     CSS_PROP_BACKGROUND_POSITION_Y };
    00102         return getShortHandValue( properties, 2 );
    00103     }
    00104     case CSS_PROP_BACKGROUND:
    00105     {
    00106         const int properties[5] = { CSS_PROP_BACKGROUND_IMAGE, CSS_PROP_BACKGROUND_REPEAT,
    00107                                     CSS_PROP_BACKGROUND_ATTACHMENT, CSS_PROP_BACKGROUND_POSITION,
    00108                                     CSS_PROP_BACKGROUND_COLOR };
    00109         return getShortHandValue( properties, 5 );
    00110     }
    00111     case CSS_PROP_BORDER:
    00112     {
    00113         const int properties[3] = { CSS_PROP_BORDER_WIDTH, CSS_PROP_BORDER_STYLE,
    00114                                     CSS_PROP_BORDER_COLOR };
    00115         return getShortHandValue( properties, 3 );
    00116     }
    00117     case CSS_PROP_BORDER_TOP:
    00118     {
    00119         const int properties[3] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_TOP_STYLE,
    00120                                     CSS_PROP_BORDER_TOP_COLOR};
    00121         return getShortHandValue( properties, 3 );
    00122     }
    00123     case CSS_PROP_BORDER_RIGHT:
    00124     {
    00125         const int properties[3] = { CSS_PROP_BORDER_RIGHT_WIDTH, CSS_PROP_BORDER_RIGHT_STYLE,
    00126                                     CSS_PROP_BORDER_RIGHT_COLOR};
    00127         return getShortHandValue( properties, 3 );
    00128     }
    00129     case CSS_PROP_BORDER_BOTTOM:
    00130     {
    00131         const int properties[3] = { CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_BOTTOM_STYLE,
    00132                                     CSS_PROP_BORDER_BOTTOM_COLOR};
    00133         return getShortHandValue( properties, 3 );
    00134     }
    00135     case CSS_PROP_BORDER_LEFT:
    00136     {
    00137         const int properties[3] = { CSS_PROP_BORDER_LEFT_WIDTH, CSS_PROP_BORDER_LEFT_STYLE,
    00138                                     CSS_PROP_BORDER_LEFT_COLOR};
    00139         return getShortHandValue( properties, 3 );
    00140     }
    00141     case CSS_PROP_OUTLINE:
    00142     {
    00143         const int properties[3] = { CSS_PROP_OUTLINE_WIDTH, CSS_PROP_OUTLINE_STYLE,
    00144                                     CSS_PROP_OUTLINE_COLOR };
    00145         return getShortHandValue( properties, 3 );
    00146     }
    00147     case CSS_PROP_BORDER_COLOR:
    00148     {
    00149         const int properties[4] = { CSS_PROP_BORDER_TOP_COLOR, CSS_PROP_BORDER_RIGHT_COLOR,
    00150                                     CSS_PROP_BORDER_BOTTOM_COLOR, CSS_PROP_BORDER_LEFT_COLOR };
    00151         return get4Values( properties );
    00152     }
    00153     case CSS_PROP_BORDER_WIDTH:
    00154     {
    00155         const int properties[4] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_RIGHT_WIDTH,
    00156                                     CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_LEFT_WIDTH };
    00157         return get4Values( properties );
    00158     }
    00159     case CSS_PROP_BORDER_STYLE:
    00160     {
    00161         const int properties[4] = { CSS_PROP_BORDER_TOP_STYLE, CSS_PROP_BORDER_RIGHT_STYLE,
    00162                                     CSS_PROP_BORDER_BOTTOM_STYLE, CSS_PROP_BORDER_LEFT_STYLE };
    00163         return get4Values( properties );
    00164     }
    00165     case CSS_PROP_MARGIN:
    00166     {
    00167         const int properties[4] = { CSS_PROP_MARGIN_TOP, CSS_PROP_MARGIN_RIGHT,
    00168                                     CSS_PROP_MARGIN_BOTTOM, CSS_PROP_MARGIN_LEFT };
    00169         return get4Values( properties );
    00170     }
    00171     case CSS_PROP_PADDING:
    00172     {
    00173         const int properties[4] = { CSS_PROP_PADDING_TOP, CSS_PROP_PADDING_RIGHT,
    00174                                     CSS_PROP_PADDING_BOTTOM, CSS_PROP_PADDING_LEFT };
    00175         return get4Values( properties );
    00176     }
    00177     case CSS_PROP_LIST_STYLE:
    00178     {
    00179         const int properties[3] = { CSS_PROP_LIST_STYLE_TYPE, CSS_PROP_LIST_STYLE_POSITION,
    00180                                     CSS_PROP_LIST_STYLE_IMAGE };
    00181         return getShortHandValue( properties, 3 );
    00182     }
    00183     }
    00184     //kdDebug() << k_funcinfo << "property not found:" << propertyID << endl;
    00185     return DOMString();
    00186 }
    00187
    00188 DOMString CSSStyleDeclarationImpl::get4Values( const int* properties ) const
    00189 {
    00190     DOMString res;
    00191     for ( int i = 0 ; i < 4 ; ++i ) {
    00192         CSSValueImpl* value = getPropertyCSSValue( properties[i] );
    00193         if ( !value ) { // apparently all 4 properties must be specified.
    00194             return DOMString();
    00195         }
    00196         if ( i > 0 )
    00197             res += " ";
    00198         res += value->cssText();
    00199     }
    00200     return res;
    00201 }
    00202
    00203 DOMString CSSStyleDeclarationImpl::getShortHandValue( const int* properties, int number ) const
    00204 {
    00205     DOMString res;
    00206     for ( int i = 0 ; i < number ; ++i ) {
    00207         CSSValueImpl* value = getPropertyCSSValue( properties[i] );
    00208         if ( value ) { // TODO provide default value if !value
    00209             if ( !res.isNull() )
    00210                 res += " ";
    00211             res += value->cssText();
    00212         }
    00213     }
    00214     return res;
    00215 }
    00216
    00217 CSSValueImpl *CSSStyleDeclarationImpl::getPropertyCSSValue( int propertyID ) const
    00218 {
    00219     if(!m_lstValues) return 0;
    00220
    00221     QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
    00222     CSSProperty *current;
    00223     for ( lstValuesIt.toLast(); (current = lstValuesIt.current()); --lstValuesIt )
    00224         if (current->m_id == propertyID && !current->nonCSSHint)
    00225             return current->value();
    00226     return 0;
    00227 }
    00228
    00229 DOMString CSSStyleDeclarationImpl::removeProperty( int propertyID, bool NonCSSHint )
    00230 {
    00231     if(!m_lstValues) return DOMString();
    00232     DOMString value;
    00233
    00234     QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
    00235      CSSProperty *current;
    00236      for ( lstValuesIt.toLast(); (current = lstValuesIt.current()); --lstValuesIt )
    00237          if (current->m_id == propertyID && NonCSSHint == current->nonCSSHint) {
    00238              value = current->value()->cssText();
    00239              m_lstValues->removeRef(current);
    00240             setChanged();
    00241              break;
    00242         }
    00243
    00244     return value;
    00245 }
    00246
    00247 void CSSStyleDeclarationImpl::setChanged()
    00248 {
    00249     if (m_node) {
    00250         m_node->setChanged();
    00251         return;
    00252     }
    00253
    00254     // ### quick&dirty hack for KDE 3.0... make this MUCH better! (Dirk)
    00255     for (StyleBaseImpl* stylesheet = this; stylesheet; stylesheet = stylesheet->parent())
    00256         if (stylesheet->isCSSStyleSheet()) {
    00257             static_cast<CSSStyleSheetImpl*>(stylesheet)->doc()->updateStyleSelector();
    00258             break;
    00259         }
    00260 }
    00261
    00262 bool CSSStyleDeclarationImpl::getPropertyPriority( int propertyID ) const
    00263 {
    00264     if ( m_lstValues) {
    00265         QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
    00266         CSSProperty *current;
    00267         for ( lstValuesIt.toFirst(); (current = lstValuesIt.current()); ++lstValuesIt ) {
    00268             if( propertyID == current->m_id )
    00269                 return current->m_bImportant;
    00270         }
    00271     }
    00272     return false;
    00273 }
    00274
    00275 void CSSStyleDeclarationImpl::setProperty(int id, const DOMString &value, bool important, bool nonCSSHint)
    00276 {
    00277     if(!m_lstValues) {
    00278         m_lstValues = new QPtrList<CSSProperty>;
    00279         m_lstValues->setAutoDelete(true);
    00280     }
    00281     removeProperty(id, nonCSSHint );
    00282
    00283     DOMString ppValue = preprocess(value.string(),true);
    00284     bool success = parseValue(ppValue.unicode(), ppValue.unicode()+ppValue.length(), id, important, nonCSSHint, m_lstValues);
    00285
    00286     if(!success)
    00287         kdDebug( 6080 ) << "CSSStyleDeclarationImpl::setProperty invalid property: [" << getPropertyName(id).string()
    00288                                         << "] value: [" << value.string() << "]"<< endl;
    00289     else
    00290         setChanged();
    00291 }
    00292
    00293 void CSSStyleDeclarationImpl::setProperty(int id, int value, bool important, bool nonCSSHint)
    00294 {
    00295     if(!m_lstValues) {
    00296         m_lstValues = new QPtrList<CSSProperty>;
    00297         m_lstValues->setAutoDelete(true);
    00298     }
    00299     removeProperty(id, nonCSSHint );
    00300
    00301     CSSValueImpl * cssValue = new CSSPrimitiveValueImpl(value);
    00302     setParsedValue(id, cssValue, important, nonCSSHint, m_lstValues);
    00303     setChanged();
    00304 }
    00305
    00306 void CSSStyleDeclarationImpl::setProperty ( const DOMString &propertyString)
    00307 {
    00308     DOMString ppPropertyString = preprocess(propertyString.string(),true);
    00309     QPtrList<CSSProperty> *props = parseProperties(ppPropertyString.unicode(),
    00310                                                 ppPropertyString.unicode()+ppPropertyString.length());
    00311     if(!props || !props->count())
    00312         return;
    00313
    00314     props->setAutoDelete(false);
    00315
    00316     if(!m_lstValues) {
    00317         m_lstValues = new QPtrList<CSSProperty>;
    00318         m_lstValues->setAutoDelete( true );
    00319     }
    00320
    00321     CSSProperty *prop = props->first();
    00322     while( prop ) {
    00323         removeProperty(prop->m_id, false);
    00324         m_lstValues->append(prop);
    00325         prop = props->next();
    00326     }
    00327
    00328     delete props;
    00329     setChanged();
    00330 }
    00331
    00332 void CSSStyleDeclarationImpl::setLengthProperty(int id, const DOM::DOMString &value, bool important, bool nonCSSHint, bool _multiLength )
    00333 {
    00334     bool parseMode = strictParsing;
    00335     strictParsing = false;
    00336     multiLength = _multiLength;
    00337     setProperty( id, value, important, nonCSSHint);
    00338     strictParsing = parseMode;
    00339     multiLength = false;
    00340 }
    00341
    00342 unsigned long CSSStyleDeclarationImpl::length() const
    00343 {
    00344     return m_lstValues ? m_lstValues->count() : 0;
    00345 }
    00346
    00347 DOMString CSSStyleDeclarationImpl::item( unsigned long /*index*/ )
    00348 {
    00349     // ###
    00350     //return m_lstValues->at(index);
    00351     return DOMString();
    00352 }
    00353
    00354 CSSRuleImpl *CSSStyleDeclarationImpl::parentRule() const
    00355 {
    00356     return (m_parent && m_parent->isRule() ) ?
    00357         static_cast<CSSRuleImpl *>(m_parent) : 0;
    00358 }
    00359
    00360 DOM::DOMString CSSStyleDeclarationImpl::cssText() const
    00361 {
    00362     return DOM::DOMString();
    00363     // ###
    00364 }
    00365
    00366 void CSSStyleDeclarationImpl::setCssText(DOM::DOMString /*str*/)
    00367 {
    00368     // ###
    00369 }
    00370
    00371 bool CSSStyleDeclarationImpl::parseString( const DOMString &/*string*/, bool )
    00372 {
    00373     return false;
    00374     // ###
    00375 }
    00376
    00377
    00378 // --------------------------------------------------------------------------------------
    00379
    00380 CSSValueImpl::CSSValueImpl()
    00381     : StyleBaseImpl()
    00382 {
    00383 }
    00384
    00385 CSSValueImpl::~CSSValueImpl()
    00386 {
    00387 }
    00388
    00389 DOM::DOMString CSSValueImpl::cssText() const
    00390 {
    00391     return DOM::DOMString();
    00392 }
    00393
    00394 void CSSValueImpl::setCssText(DOM::DOMString /*str*/)
    00395 {
    00396     // ###
    00397 }
    00398
    00399 DOM::DOMString CSSInheritedValueImpl::cssText() const
    00400 {
    00401     return DOMString("inherited");
    00402 }
    00403 // ----------------------------------------------------------------------------------------
    00404
    00405 CSSValueListImpl::CSSValueListImpl()
    00406     : CSSValueImpl()
    00407 {
    00408 }
    00409
    00410 CSSValueListImpl::~CSSValueListImpl()
    00411 {
    00412     CSSValueImpl *val = m_values.first();
    00413     while( val ) {
    00414         val->deref();
    00415         val = m_values.next();
    00416     }
    00417 }
    00418
    00419 unsigned short CSSValueListImpl::cssValueType() const
    00420 {
    00421     return CSSValue::CSS_VALUE_LIST;
    00422 }
    00423
    00424 void CSSValueListImpl::append(CSSValueImpl *val)
    00425 {
    00426     m_values.append(val);
    00427     val->ref();
    00428 }
    00429
    00430 DOM::DOMString CSSValueListImpl::cssText() const
    00431 {
    00432     // ###
    00433     return DOM::DOMString();
    00434 }
    00435
    00436 // -------------------------------------------------------------------------------------
    00437
    00438 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl()
    00439     : CSSValueImpl()
    00440 {
    00441     m_type = 0;
    00442 }
    00443
    00444 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(int ident)
    00445     : CSSValueImpl()
    00446 {
    00447     m_value.ident = ident;
    00448     m_type = CSSPrimitiveValue::CSS_IDENT;
    00449 }
    00450
    00451 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(float num, CSSPrimitiveValue::UnitTypes type)
    00452 {
    00453     m_value.num = num;
    00454     m_type = type;
    00455 }
    00456
    00457 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(const DOMString &str, CSSPrimitiveValue::UnitTypes type)
    00458 {
    00459     m_value.string = str.implementation();
    00460     if(m_value.string) m_value.string->ref();
    00461     m_type = type;
    00462 }
    00463
    00464 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(const Counter &c)
    00465 {
    00466     m_value.counter = c.handle();
    00467     if (m_value.counter)
    00468         m_value.counter->ref();
    00469     m_type = CSSPrimitiveValue::CSS_COUNTER;
    00470 }
    00471
    00472 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl( RectImpl *r)
    00473 {
    00474     m_value.rect = r;
    00475     if (m_value.rect)
    00476         m_value.rect->ref();
    00477     m_type = CSSPrimitiveValue::CSS_RECT;
    00478 }
    00479
    00480 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(QRgb color)
    00481 {
    00482     m_value.rgbcolor = color;
    00483     m_type = CSSPrimitiveValue::CSS_RGBCOLOR;
    00484 }
    00485
    00486 CSSPrimitiveValueImpl::~CSSPrimitiveValueImpl()
    00487 {
    00488     cleanup();
    00489 }
    00490
    00491 void CSSPrimitiveValueImpl::cleanup()
    00492 {
    00493     switch(m_type) {
    00494     case CSSPrimitiveValue::CSS_STRING:
    00495     case CSSPrimitiveValue::CSS_URI:
    00496     case CSSPrimitiveValue::CSS_ATTR:
    00497         if(m_value.string) m_value.string->deref();
    00498         break;
    00499     case CSSPrimitiveValue::CSS_COUNTER:
    00500         m_value.counter->deref();
    00501         break;
    00502     case CSSPrimitiveValue::CSS_RECT:
    00503         m_value.rect->deref();
    00504     default:
    00505         break;
    00506     }
    00507
    00508     m_type = 0;
    00509 }
    00510
    00511 int CSSPrimitiveValueImpl::computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics )
    00512 {
    00513     return ( int ) computeLengthFloat( style, devMetrics );
    00514 }
    00515
    00516 float CSSPrimitiveValueImpl::computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics )
    00517 {
    00518     unsigned short type = primitiveType();
    00519
    00520     float dpiY = 72.; // fallback
    00521     if ( devMetrics )
    00522         dpiY = devMetrics->logicalDpiY();
    00523     if ( !khtml::printpainter && dpiY < 96 )
    00524         dpiY = 96.;
    00525
    00526     float factor = 1.;
    00527     switch(type)
    00528     {
    00529     case CSSPrimitiveValue::CSS_EMS:
    00530         factor = style->font().pixelSize();
    00531                 break;
    00532     case CSSPrimitiveValue::CSS_EXS:
    00533         {
    00534         QFontMetrics fm = style->fontMetrics();
    00535         QRect b = fm.boundingRect('x');
    00536         factor = b.height();
    00537         break;
    00538         }
    00539     case CSSPrimitiveValue::CSS_PX:
    00540         break;
    00541     case CSSPrimitiveValue::CSS_CM:
    00542         factor = dpiY/2.54; //72dpi/(2.54 cm/in)
    00543         break;
    00544     case CSSPrimitiveValue::CSS_MM:
    00545         factor = dpiY/25.4;
    00546         break;
    00547     case CSSPrimitiveValue::CSS_IN:
    00548             factor = dpiY;
    00549         break;
    00550     case CSSPrimitiveValue::CSS_PT:
    00551             factor = dpiY/72.;
    00552         break;
    00553     case CSSPrimitiveValue::CSS_PC:
    00554         // 1 pc == 12 pt
    00555             factor = dpiY*12./72.;
    00556         break;
    00557     default:
    00558         return -1;
    00559     }
    00560     return getFloatValue(type)*factor;
    00561 }
    00562
    00563 void CSSPrimitiveValueImpl::setFloatValue( unsigned short unitType, float floatValue, int &exceptioncode )
    00564 {
    00565     exceptioncode = 0;
    00566     cleanup();
    00567     // ### check if property supports this type
    00568     if(m_type > CSSPrimitiveValue::CSS_DIMENSION) {
    00569         exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET;
    00570         return;
    00571     }
    00572     //if(m_type > CSSPrimitiveValue::CSS_DIMENSION) throw DOMException(DOMException::INVALID_ACCESS_ERR);
    00573     m_value.num = floatValue;
    00574     m_type = unitType;
    00575 }
    00576
    00577 void CSSPrimitiveValueImpl::setStringValue( unsigned short stringType, const DOMString &stringValue, int &exceptioncode )
    00578 {
    00579     exceptioncode = 0;
    00580     cleanup();
    00581     //if(m_type < CSSPrimitiveValue::CSS_STRING) throw DOMException(DOMException::INVALID_ACCESS_ERR);
    00582     //if(m_type > CSSPrimitiveValue::CSS_ATTR) throw DOMException(DOMException::INVALID_ACCESS_ERR);
    00583     if(m_type < CSSPrimitiveValue::CSS_STRING || m_type >> CSSPrimitiveValue::CSS_ATTR) {
    00584         exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET;
    00585         return;
    00586     }
    00587     if(stringType != CSSPrimitiveValue::CSS_IDENT)
    00588     {
    00589         m_value.string = stringValue.implementation();
    00590         m_value.string->ref();
    00591         m_type = stringType;
    00592     }
    00593     // ### parse ident
    00594 }
    00595
    00596 unsigned short CSSPrimitiveValueImpl::cssValueType() const
    00597 {
    00598     return CSSValue::CSS_PRIMITIVE_VALUE;
    00599 }
    00600
    00601 bool CSSPrimitiveValueImpl::parseString( const DOMString &/*string*/, bool )
    00602 {
    00603     // ###
    00604     return false;
    00605 }
    00606
    00607 int CSSPrimitiveValueImpl::getIdent()
    00608 {
    00609     if(m_type != CSSPrimitiveValue::CSS_IDENT) return 0;
    00610     return m_value.ident;
    00611 }
    00612
    00613 DOM::DOMString CSSPrimitiveValueImpl::cssText() const
    00614 {
    00615     // ### return the original value instead of a generated one (e.g. color
    00616     // name if it was specified) - check what spec says about this
    00617     DOMString text;
    00618     switch ( m_type ) {
    00619         case CSSPrimitiveValue::CSS_UNKNOWN:
    00620             // ###
    00621             break;
    00622         case CSSPrimitiveValue::CSS_NUMBER:
    00623             text = DOMString(QString::number( (int)m_value.num ));
    00624             break;
    00625         case CSSPrimitiveValue::CSS_PERCENTAGE:
    00626             text = DOMString(QString::number( m_value.num ) + "%");
    00627             break;
    00628         case CSSPrimitiveValue::CSS_EMS:
    00629             text = DOMString(QString::number( m_value.num ) + "em");
    00630             break;
    00631         case CSSPrimitiveValue::CSS_EXS:
    00632             text = DOMString(QString::number( m_value.num ) + "ex");
    00633             break;
    00634         case CSSPrimitiveValue::CSS_PX:
    00635             text = DOMString(QString::number( m_value.num ) + "px");
    00636             break;
    00637         case CSSPrimitiveValue::CSS_CM:
    00638             text = DOMString(QString::number( m_value.num ) + "cm");
    00639             break;
    00640         case CSSPrimitiveValue::CSS_MM:
    00641             text = DOMString(QString::number( m_value.num ) + "mm");
    00642             break;
    00643         case CSSPrimitiveValue::CSS_IN:
    00644             text = DOMString(QString::number( m_value.num ) + "in");
    00645             break;
    00646         case CSSPrimitiveValue::CSS_PT:
    00647             text = DOMString(QString::number( m_value.num ) + "pt");
    00648             break;
    00649         case CSSPrimitiveValue::CSS_PC:
    00650             text = DOMString(QString::number( m_value.num ) + "pc");
    00651             break;
    00652         case CSSPrimitiveValue::CSS_DEG:
    00653             text = DOMString(QString::number( m_value.num ) + "deg");
    00654             break;
    00655         case CSSPrimitiveValue::CSS_RAD:
    00656             text = DOMString(QString::number( m_value.num ) + "rad");
    00657             break;
    00658         case CSSPrimitiveValue::CSS_GRAD:
    00659             text = DOMString(QString::number( m_value.num ) + "grad");
    00660             break;
    00661         case CSSPrimitiveValue::CSS_MS:
    00662             text = DOMString(QString::number( m_value.num ) + "ms");
    00663             break;
    00664         case CSSPrimitiveValue::CSS_S:
    00665             text = DOMString(QString::number( m_value.num ) + "s");
    00666             break;
    00667         case CSSPrimitiveValue::CSS_HZ:
    00668             text = DOMString(QString::number( m_value.num ) + "hz");
    00669             break;
    00670         case CSSPrimitiveValue::CSS_KHZ:
    00671             text = DOMString(QString::number( m_value.num ) + "khz");
    00672             break;
    00673         case CSSPrimitiveValue::CSS_DIMENSION:
    00674             // ###
    00675             break;
    00676         case CSSPrimitiveValue::CSS_STRING:
    00677             // ###
    00678             break;
    00679         case CSSPrimitiveValue::CSS_URI:
    00680             text = DOMString( m_value.string );
    00681             break;
    00682         case CSSPrimitiveValue::CSS_IDENT:
    00683             text = getValueName(m_value.ident);
    00684             break;
    00685         case CSSPrimitiveValue::CSS_ATTR:
    00686             // ###
    00687             break;
    00688         case CSSPrimitiveValue::CSS_COUNTER:
    00689             // ###
    00690             break;
    00691         case CSSPrimitiveValue::CSS_RECT:
    00692             // ###
    00693             break;
    00694         case CSSPrimitiveValue::CSS_RGBCOLOR:
    00695             text = QColor(m_value.rgbcolor).name();
    00696             break;
    00697         default:
    00698             break;
    00699     }
    00700     return text;
    00701 }
    00702
    00703 // -----------------------------------------------------------------
    00704
    00705 RectImpl::RectImpl()
    00706 {
    00707     m_top = 0;
    00708     m_right = 0;
    00709     m_bottom = 0;
    00710     m_left = 0;
    00711 }
    00712
    00713 RectImpl::~RectImpl()
    00714 {
    00715     if (m_top) m_top->deref();
    00716     if (m_right) m_right->deref();
    00717     if (m_bottom) m_bottom->deref();
    00718     if (m_left) m_left->deref();
    00719 }
    00720
    00721 void RectImpl::setTop( CSSPrimitiveValueImpl *top )
    00722 {
    00723     if( top ) top->ref();
    00724     if ( m_top ) m_top->deref();
    00725     m_top = top;
    00726 }
    00727
    00728 void RectImpl::setRight( CSSPrimitiveValueImpl *right )
    00729 {
    00730     if( right ) right->ref();
    00731     if ( m_right ) m_right->deref();
    00732     m_right = right;
    00733 }
    00734
    00735 void RectImpl::setBottom( CSSPrimitiveValueImpl *bottom )
    00736 {
    00737     if( bottom ) bottom->ref();
    00738     if ( m_bottom ) m_bottom->deref();
    00739     m_bottom = bottom;
    00740 }
    00741
    00742 void RectImpl::setLeft( CSSPrimitiveValueImpl *left )
    00743 {
    00744     if( left ) left->ref();
    00745     if ( m_left ) m_left->deref();
    00746     m_left = left;
    00747 }
    00748
    00749 // -----------------------------------------------------------------
    00750
    00751 CSSImageValueImpl::CSSImageValueImpl(const DOMString &url, StyleBaseImpl *style)
    00752     : CSSPrimitiveValueImpl(url, CSSPrimitiveValue::CSS_URI)
    00753 {
    00754     khtml::DocLoader *docLoader = 0;
    00755     StyleBaseImpl *root = style;
    00756     while (root->parent())
    00757         root = root->parent();
    00758     if (root->isCSSStyleSheet())
    00759         docLoader = static_cast<CSSStyleSheetImpl*>(root)->docLoader();
    00760
    00761     if (docLoader)
    00762         m_image = docLoader->requestImage(url);
    00763     else
    00764         m_image = khtml::Cache::requestImage(0, url);
    00765
    00766     if(m_image) m_image->ref(this);
    00767 }
    00768
    00769 CSSImageValueImpl::CSSImageValueImpl()
    00770     : CSSPrimitiveValueImpl(CSS_VAL_NONE)
    00771 {
    00772     m_image = 0;
    00773 }
    00774
    00775 CSSImageValueImpl::~CSSImageValueImpl()
    00776 {
    00777     if(m_image) m_image->deref(this);
    00778 }
    00779
    00780 // ------------------------------------------------------------------------
    00781
    00782 FontFamilyValueImpl::FontFamilyValueImpl( const QString &string)
    00783     : CSSPrimitiveValueImpl( DOMString(string), CSSPrimitiveValue::CSS_STRING)
    00784 {
    00785     const QString &available = KHTMLSettings::availableFamilies();
    00786
    00787     QString face = string.lower();
    00788     // a languge tag is often added in braces at the end. Remove it.
    00789     face = face.replace(QRegExp(" \\(.*\\)$"), "");
    00790     // remove [Xft] qualifiers
    00791     face = face.replace(QRegExp(" \\[.*\\]$"), "");
    00792     //kdDebug(0) << "searching for face '" << face << "'" << endl;
    00793     if(face == "serif" ||
    00794        face == "sans-serif" ||
    00795        face == "cursive" ||
    00796        face == "fantasy" ||
    00797        face == "monospace" ||
    00798        face == "konq_default") {
    00799         parsedFontName = face;
    00800     } else {
    00801         int pos = available.find( face, 0, false );
    00802         if( pos == -1 ) {
    00803             QString str = face;
    00804             int p = face.find(' ');
    00805             // Arial Blk --> Arial
    00806             // MS Sans Serif --> Sans Serif
    00807             if ( p != -1 ) {
    00808                 if(p > 0 && (int)str.length() - p > p + 1)
    00809                     str = str.mid( p+1 );
    00810                 else
    00811                     str.truncate( p );
    00812                 pos = available.find( str, 0, false);
    00813             }
    00814         }
    00815
    00816         if ( pos != -1 ) {
    00817             int pos1 = available.findRev( ',', pos ) + 1;
    00818             pos = available.find( ',', pos );
    00819             if ( pos == -1 )
    00820                 pos = available.length();
    00821             parsedFontName = available.mid( pos1, pos - pos1 );
    00822         }
    00823     }
    00824 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:33 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001