00001
00024 #include "dom/css_value.h"
00025 #include "dom/dom_exception.h"
00026 #include "dom/dom_string.h"
00027
00028 #include "css/css_valueimpl.h"
00029 #include "css/css_ruleimpl.h"
00030 #include "css/css_stylesheetimpl.h"
00031 #include "css/cssparser.h"
00032 #include "css/cssproperties.h"
00033 #include "css/cssvalues.h"
00034
00035 #include "xml/dom_stringimpl.h"
00036 #include "xml/dom_docimpl.h"
00037
00038 #include "misc/loader.h"
00039
00040 #include "rendering/font.h"
00041 #include "rendering/render_style.h"
00042
00043 #include <kdebug.h>
00044 #include <qregexp.h>
00045 #include <qpaintdevice.h>
00046 #include <qpaintdevicemetrics.h>
00047
00048
00049 extern DOM::DOMString getPropertyName(unsigned short id);
00050
00051 using khtml::FontDef;
00052
00053 using namespace DOM;
00054
00055 CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent)
00056 : StyleBaseImpl(parent)
00057 {
00058 m_lstValues = 0;
00059 m_node = 0;
00060 }
00061
00062 CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent, QPtrList<CSSProperty> *lstValues)
00063 : StyleBaseImpl(parent)
00064 {
00065 m_lstValues = lstValues;
00066 m_node = 0;
00067 }
00068
00069 CSSStyleDeclarationImpl& CSSStyleDeclarationImpl::operator= (const CSSStyleDeclarationImpl& o)
00070 {
00071
00072 delete m_lstValues;
00073 m_lstValues = 0;
00074 if (o.m_lstValues) {
00075 m_lstValues = new QPtrList<CSSProperty>;
00076 m_lstValues->setAutoDelete( true );
00077
00078 QPtrListIterator<CSSProperty> lstValuesIt(*o.m_lstValues);
00079 for (lstValuesIt.toFirst(); lstValuesIt.current(); ++lstValuesIt)
00080 m_lstValues->append(new CSSProperty(*lstValuesIt.current()));
00081 }
00082
00083 return *this;
00084 }
00085
00086 CSSStyleDeclarationImpl::~CSSStyleDeclarationImpl()
00087 {
00088 delete m_lstValues;
00089
00090 }
00091
00092 DOMString CSSStyleDeclarationImpl::getPropertyValue( int propertyID ) const
00093 {
00094 if(!m_lstValues) return DOMString();
00095 CSSValueImpl* value = getPropertyCSSValue( propertyID );
00096 if ( value )
00097 return value->cssText();
00098
00099
00100 switch ( propertyID ) {
00101 case CSS_PROP_BACKGROUND_POSITION:
00102 {
00103
00104 const int properties[2] = { CSS_PROP_BACKGROUND_POSITION_X,
00105 CSS_PROP_BACKGROUND_POSITION_Y };
00106 return getShortHandValue( properties, 2 );
00107 }
00108 case CSS_PROP_BACKGROUND:
00109 {
00110 const int properties[5] = { CSS_PROP_BACKGROUND_IMAGE, CSS_PROP_BACKGROUND_REPEAT,
00111 CSS_PROP_BACKGROUND_ATTACHMENT, CSS_PROP_BACKGROUND_POSITION,
00112 CSS_PROP_BACKGROUND_COLOR };
00113 return getShortHandValue( properties, 5 );
00114 }
00115 case CSS_PROP_BORDER:
00116 {
00117 const int properties[3] = { CSS_PROP_BORDER_WIDTH, CSS_PROP_BORDER_STYLE,
00118 CSS_PROP_BORDER_COLOR };
00119 return getShortHandValue( properties, 3 );
00120 }
00121 case CSS_PROP_BORDER_TOP:
00122 {
00123 const int properties[3] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_TOP_STYLE,
00124 CSS_PROP_BORDER_TOP_COLOR};
00125 return getShortHandValue( properties, 3 );
00126 }
00127 case CSS_PROP_BORDER_RIGHT:
00128 {
00129 const int properties[3] = { CSS_PROP_BORDER_RIGHT_WIDTH, CSS_PROP_BORDER_RIGHT_STYLE,
00130 CSS_PROP_BORDER_RIGHT_COLOR};
00131 return getShortHandValue( properties, 3 );
00132 }
00133 case CSS_PROP_BORDER_BOTTOM:
00134 {
00135 const int properties[3] = { CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_BOTTOM_STYLE,
00136 CSS_PROP_BORDER_BOTTOM_COLOR};
00137 return getShortHandValue( properties, 3 );
00138 }
00139 case CSS_PROP_BORDER_LEFT:
00140 {
00141 const int properties[3] = { CSS_PROP_BORDER_LEFT_WIDTH, CSS_PROP_BORDER_LEFT_STYLE,
00142 CSS_PROP_BORDER_LEFT_COLOR};
00143 return getShortHandValue( properties, 3 );
00144 }
00145 case CSS_PROP_OUTLINE:
00146 {
00147 const int properties[3] = { CSS_PROP_OUTLINE_WIDTH, CSS_PROP_OUTLINE_STYLE,
00148 CSS_PROP_OUTLINE_COLOR };
00149 return getShortHandValue( properties, 3 );
00150 }
00151 case CSS_PROP_BORDER_COLOR:
00152 {
00153 const int properties[4] = { CSS_PROP_BORDER_TOP_COLOR, CSS_PROP_BORDER_RIGHT_COLOR,
00154 CSS_PROP_BORDER_BOTTOM_COLOR, CSS_PROP_BORDER_LEFT_COLOR };
00155 return get4Values( properties );
00156 }
00157 case CSS_PROP_BORDER_WIDTH:
00158 {
00159 const int properties[4] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_RIGHT_WIDTH,
00160 CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_LEFT_WIDTH };
00161 return get4Values( properties );
00162 }
00163 case CSS_PROP_BORDER_STYLE:
00164 {
00165 const int properties[4] = { CSS_PROP_BORDER_TOP_STYLE, CSS_PROP_BORDER_RIGHT_STYLE,
00166 CSS_PROP_BORDER_BOTTOM_STYLE, CSS_PROP_BORDER_LEFT_STYLE };
00167 return get4Values( properties );
00168 }
00169 case CSS_PROP_MARGIN:
00170 {
00171 const int properties[4] = { CSS_PROP_MARGIN_TOP, CSS_PROP_MARGIN_RIGHT,
00172 CSS_PROP_MARGIN_BOTTOM, CSS_PROP_MARGIN_LEFT };
00173 return get4Values( properties );
00174 }
00175 case CSS_PROP_PADDING:
00176 {
00177 const int properties[4] = { CSS_PROP_PADDING_TOP, CSS_PROP_PADDING_RIGHT,
00178 CSS_PROP_PADDING_BOTTOM, CSS_PROP_PADDING_LEFT };
00179 return get4Values( properties );
00180 }
00181 case CSS_PROP_LIST_STYLE:
00182 {
00183 const int properties[3] = { CSS_PROP_LIST_STYLE_TYPE, CSS_PROP_LIST_STYLE_POSITION,
00184 CSS_PROP_LIST_STYLE_IMAGE };
00185 return getShortHandValue( properties, 3 );
00186 }
00187 }
00188
00189 return DOMString();
00190 }
00191
00192 DOMString CSSStyleDeclarationImpl::get4Values( const int* properties ) const
00193 {
00194 DOMString res;
00195 for ( int i = 0 ; i < 4 ; ++i ) {
00196 CSSValueImpl* value = getPropertyCSSValue( properties[i] );
00197 if ( !value ) {
00198 return DOMString();
00199 }
00200 if ( i > 0 )
00201 res += " ";
00202 res += value->cssText();
00203 }
00204 return res;
00205 }
00206
00207 DOMString CSSStyleDeclarationImpl::getShortHandValue( const int* properties, int number ) const
00208 {
00209 DOMString res;
00210 for ( int i = 0 ; i < number ; ++i ) {
00211 CSSValueImpl* value = getPropertyCSSValue( properties[i] );
00212 if ( value ) {
00213 if ( !res.isNull() )
00214 res += " ";
00215 res += value->cssText();
00216 }
00217 }
00218 return res;
00219 }
00220
00221 CSSValueImpl *CSSStyleDeclarationImpl::getPropertyCSSValue( int propertyID ) const
00222 {
00223 if(!m_lstValues) return 0;
00224
00225 QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
00226 CSSProperty *current;
00227 for ( lstValuesIt.toLast(); (current = lstValuesIt.current()); --lstValuesIt )
00228 if (current->m_id == propertyID && !current->nonCSSHint)
00229 return current->value();
00230 return 0;
00231 }
00232
00233 DOMString CSSStyleDeclarationImpl::removeProperty( int propertyID, bool NonCSSHint )
00234 {
00235 if(!m_lstValues) return DOMString();
00236 DOMString value;
00237
00238 QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
00239 CSSProperty *current;
00240 for ( lstValuesIt.toLast(); (current = lstValuesIt.current()); --lstValuesIt ) {
00241 if (current->m_id == propertyID && NonCSSHint == current->nonCSSHint) {
00242 value = current->value()->cssText();
00243 m_lstValues->removeRef(current);
00244 setChanged();
00245 break;
00246 }
00247 }
00248
00249 return value;
00250 }
00251
00252 void CSSStyleDeclarationImpl::setChanged()
00253 {
00254 if (m_node) {
00255 m_node->setChanged();
00256 return;
00257 }
00258
00259
00260 for (StyleBaseImpl* stylesheet = this; stylesheet; stylesheet = stylesheet->parent())
00261 if (stylesheet->isCSSStyleSheet()) {
00262 static_cast<CSSStyleSheetImpl*>(stylesheet)->doc()->updateStyleSelector();
00263 break;
00264 }
00265 }
00266
00267 void CSSStyleDeclarationImpl::removeCSSHints()
00268 {
00269 if (!m_lstValues)
00270 return;
00271
00272 for (int i = (int)m_lstValues->count()-1; i >= 0; i--) {
00273 if (!m_lstValues->at(i)->nonCSSHint)
00274 m_lstValues->remove(i);
00275 }
00276 }
00277
00278 bool CSSStyleDeclarationImpl::getPropertyPriority( int propertyID ) const
00279 {
00280 if ( m_lstValues) {
00281 QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
00282 CSSProperty *current;
00283 for ( lstValuesIt.toFirst(); (current = lstValuesIt.current()); ++lstValuesIt ) {
00284 if( propertyID == current->m_id )
00285 return current->m_bImportant;
00286 }
00287 }
00288 return false;
00289 }
00290
00291 bool CSSStyleDeclarationImpl::setProperty(int id, const DOMString &value, bool important, bool nonCSSHint)
00292 {
00293 if(!m_lstValues) {
00294 m_lstValues = new QPtrList<CSSProperty>;
00295 m_lstValues->setAutoDelete(true);
00296 }
00297
00298 CSSParser parser( strictParsing );
00299 bool success = parser.parseValue( this, id, value, important, nonCSSHint );
00300 if(!success)
00301 kdDebug( 6080 ) << "CSSStyleDeclarationImpl::setProperty invalid property: [" << getPropertyName(id).string()
00302 << "] value: [" << value.string() << "]"<< endl;
00303 else
00304 setChanged();
00305 return success;
00306 }
00307
00308 void CSSStyleDeclarationImpl::setProperty(int id, int value, bool important, bool nonCSSHint)
00309 {
00310 if(!m_lstValues) {
00311 m_lstValues = new QPtrList<CSSProperty>;
00312 m_lstValues->setAutoDelete(true);
00313 }
00314 removeProperty(id, nonCSSHint );
00315
00316 CSSValueImpl * cssValue = new CSSPrimitiveValueImpl(value);
00317 setParsedValue(id, cssValue, important, nonCSSHint, m_lstValues);
00318 setChanged();
00319 }
00320
00321 void CSSStyleDeclarationImpl::setLengthProperty(int id, const DOM::DOMString &value, bool important, bool nonCSSHint, bool _multiLength )
00322 {
00323 bool parseMode = strictParsing;
00324 strictParsing = false;
00325 multiLength = _multiLength;
00326 setProperty( id, value, important, nonCSSHint);
00327 strictParsing = parseMode;
00328 multiLength = false;
00329 }
00330
00331 void CSSStyleDeclarationImpl::setProperty ( const DOMString &propertyString)
00332 {
00333 if(!m_lstValues) {
00334 m_lstValues = new QPtrList<CSSProperty>;
00335 m_lstValues->setAutoDelete( true );
00336 }
00337
00338 CSSParser parser( strictParsing );
00339 parser.parseDeclaration( this, propertyString, false );
00340 setChanged();
00341 }
00342
00343 unsigned long CSSStyleDeclarationImpl::length() const
00344 {
00345 return m_lstValues ? m_lstValues->count() : 0;
00346 }
00347
00348 DOMString CSSStyleDeclarationImpl::item( unsigned long index ) const
00349 {
00350 if(m_lstValues && index < m_lstValues->count() && m_lstValues->at(index))
00351 return getPropertyName(m_lstValues->at(index)->m_id);
00352 return DOMString();
00353 }
00354
00355 CSSRuleImpl *CSSStyleDeclarationImpl::parentRule() const
00356 {
00357 return (m_parent && m_parent->isRule() ) ?
00358 static_cast<CSSRuleImpl *>(m_parent) : 0;
00359 }
00360
00361 DOM::DOMString CSSStyleDeclarationImpl::cssText() const
00362 {
00363 DOMString result;
00364
00365 if ( m_lstValues) {
00366 QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
00367 CSSProperty *current;
00368 for ( lstValuesIt.toFirst(); (current = lstValuesIt.current()); ++lstValuesIt ) {
00369 result += current->cssText();
00370 }
00371 }
00372
00373 return result;
00374 }
00375
00376 void CSSStyleDeclarationImpl::setCssText(DOM::DOMString text)
00377 {
00378 if (m_lstValues) {
00379 m_lstValues->clear();
00380 } else {
00381 m_lstValues = new QPtrList<CSSProperty>;
00382 m_lstValues->setAutoDelete( true );
00383 }
00384
00385 CSSParser parser( strictParsing );
00386 parser.parseDeclaration( this, text, false );
00387 setChanged();
00388 }
00389
00390 bool CSSStyleDeclarationImpl::parseString( const DOMString &, bool )
00391 {
00392 kdDebug() << "WARNING: CSSStyleDeclarationImpl::parseString, unimplemented, was called" << endl;
00393 return false;
00394
00395 }
00396
00397
00398
00399
00400 unsigned short CSSInheritedValueImpl::cssValueType() const
00401 {
00402 return CSSValue::CSS_INHERIT;
00403 }
00404
00405 DOM::DOMString CSSInheritedValueImpl::cssText() const
00406 {
00407 return DOMString("inherit");
00408 }
00409
00410 unsigned short CSSInitialValueImpl::cssValueType() const
00411 {
00412 return CSSValue::CSS_INITIAL;
00413 }
00414
00415 DOM::DOMString CSSInitialValueImpl::cssText() const
00416 {
00417 return DOMString("initial");
00418 }
00419
00420
00421
00422 CSSValueListImpl::~CSSValueListImpl()
00423 {
00424 CSSValueImpl *val = m_values.first();
00425 while( val ) {
00426 val->deref();
00427 val = m_values.next();
00428 }
00429 }
00430
00431 unsigned short CSSValueListImpl::cssValueType() const
00432 {
00433 return CSSValue::CSS_VALUE_LIST;
00434 }
00435
00436 void CSSValueListImpl::append(CSSValueImpl *val)
00437 {
00438 m_values.append(val);
00439 val->ref();
00440 }
00441
00442 DOM::DOMString CSSValueListImpl::cssText() const
00443 {
00444 DOMString result = "";
00445
00446 for (QPtrListIterator<CSSValueImpl> iterator(m_values); iterator.current(); ++iterator) {
00447 result += iterator.current()->cssText();
00448 }
00449
00450 return result;
00451 }
00452
00453
00454
00455 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl()
00456 : CSSValueImpl()
00457 {
00458 m_type = 0;
00459 }
00460
00461 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(int ident)
00462 : CSSValueImpl()
00463 {
00464 m_value.ident = ident;
00465 m_type = CSSPrimitiveValue::CSS_IDENT;
00466 }
00467
00468 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type)
00469 {
00470 m_value.num = num;
00471 m_type = type;
00472 }
00473
00474 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(const DOMString &str, CSSPrimitiveValue::UnitTypes type)
00475 {
00476 m_value.string = str.implementation();
00477 if(m_value.string) m_value.string->ref();
00478 m_type = type;
00479 }
00480
00481 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(CounterImpl *c)
00482 {
00483 m_value.counter = c;
00484 if (m_value.counter)
00485 m_value.counter->ref();
00486 m_type = CSSPrimitiveValue::CSS_COUNTER;
00487 }
00488
00489 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl( RectImpl *r)
00490 {
00491 m_value.rect = r;
00492 if (m_value.rect)
00493 m_value.rect->ref();
00494 m_type = CSSPrimitiveValue::CSS_RECT;
00495 }
00496
00497 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(QRgb color)
00498 {
00499 m_value.rgbcolor = color;
00500 m_type = CSSPrimitiveValue::CSS_RGBCOLOR;
00501 }
00502
00503 CSSPrimitiveValueImpl::~CSSPrimitiveValueImpl()
00504 {
00505 cleanup();
00506 }
00507
00508 void CSSPrimitiveValueImpl::cleanup()
00509 {
00510 switch(m_type) {
00511 case CSSPrimitiveValue::CSS_STRING:
00512 case CSSPrimitiveValue::CSS_URI:
00513 case CSSPrimitiveValue::CSS_ATTR:
00514 if(m_value.string) m_value.string->deref();
00515 break;
00516 case CSSPrimitiveValue::CSS_COUNTER:
00517 m_value.counter->deref();
00518 break;
00519 case CSSPrimitiveValue::CSS_RECT:
00520 m_value.rect->deref();
00521 default:
00522 break;
00523 }
00524
00525 m_type = 0;
00526 }
00527
00528 int CSSPrimitiveValueImpl::computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics )
00529 {
00530 double result = computeLengthFloat( style, devMetrics );
00531
00532
00533 int intResult = (int)(result + (result < 0 ? -0.01 : +0.01));
00534 return intResult;
00535 }
00536
00537 double CSSPrimitiveValueImpl::computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics )
00538 {
00539 unsigned short type = primitiveType();
00540
00541 double dpiY = 72.;
00542 if ( devMetrics )
00543 dpiY = devMetrics->logicalDpiY();
00544 if ( !khtml::printpainter && dpiY < 96 )
00545 dpiY = 96.;
00546
00547 double factor = 1.;
00548 switch(type)
00549 {
00550 case CSSPrimitiveValue::CSS_EMS:
00551 factor = style->font().pixelSize();
00552 break;
00553 case CSSPrimitiveValue::CSS_EXS:
00554 {
00555 QFontMetrics fm = style->fontMetrics();
00556 #ifdef APPLE_CHANGES
00557 factor = fm.xHeight();
00558 #else
00559 QRect b = fm.boundingRect('x');
00560 factor = b.height();
00561 #endif
00562 break;
00563 }
00564 case CSSPrimitiveValue::CSS_PX:
00565 break;
00566 case CSSPrimitiveValue::CSS_CM:
00567 factor = dpiY/2.54;
00568 break;
00569 case CSSPrimitiveValue::CSS_MM:
00570 factor = dpiY/25.4;
00571 break;
00572 case CSSPrimitiveValue::CSS_IN:
00573 factor = dpiY;
00574 break;
00575 case CSSPrimitiveValue::CSS_PT:
00576 factor = dpiY/72.;
00577 break;
00578 case CSSPrimitiveValue::CSS_PC:
00579
00580 factor = dpiY*12./72.;
00581 break;
00582 default:
00583 return -1;
00584 }
00585
00586 return floatValue(type)*factor;
00587 }
00588
00589 void CSSPrimitiveValueImpl::setFloatValue( unsigned short unitType, double floatValue, int &exceptioncode )
00590 {
00591 exceptioncode = 0;
00592 cleanup();
00593
00594 if(m_type > CSSPrimitiveValue::CSS_DIMENSION) {
00595 exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET;
00596 return;
00597 }
00598
00599 m_value.num = floatValue;
00600 m_type = unitType;
00601 }
00602
00603 void CSSPrimitiveValueImpl::setStringValue( unsigned short stringType, const DOMString &stringValue, int &exceptioncode )
00604 {
00605 exceptioncode = 0;
00606 cleanup();
00607
00608
00609 if(m_type < CSSPrimitiveValue::CSS_STRING || m_type > CSSPrimitiveValue::CSS_ATTR) {
00610 exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET;
00611 return;
00612 }
00613 if(stringType != CSSPrimitiveValue::CSS_IDENT)
00614 {
00615 m_value.string = stringValue.implementation();
00616 m_value.string->ref();
00617 m_type = stringType;
00618 }
00619
00620 }
00621
00622 unsigned short CSSPrimitiveValueImpl::cssValueType() const
00623 {
00624 return CSSValue::CSS_PRIMITIVE_VALUE;
00625 }
00626
00627 bool CSSPrimitiveValueImpl::parseString( const DOMString &, bool )
00628 {
00629
00630 kdDebug() << "WARNING: CSSPrimitiveValueImpl::parseString, unimplemented, was called" << endl;
00631 return false;
00632 }
00633
00634 int CSSPrimitiveValueImpl::getIdent()
00635 {
00636 if(m_type != CSSPrimitiveValue::CSS_IDENT) return 0;
00637 return m_value.ident;
00638 }
00639
00640 DOM::DOMString CSSPrimitiveValueImpl::cssText() const
00641 {
00642
00643
00644 DOMString text;
00645 switch ( m_type ) {
00646 case CSSPrimitiveValue::CSS_UNKNOWN:
00647
00648 break;
00649 case CSSPrimitiveValue::CSS_NUMBER:
00650 text = DOMString(QString::number( (int)m_value.num ));
00651 break;
00652 case CSSPrimitiveValue::CSS_PERCENTAGE:
00653 text = DOMString(QString::number( m_value.num ) + "%");
00654 break;
00655 case CSSPrimitiveValue::CSS_EMS:
00656 text = DOMString(QString::number( m_value.num ) + "em");
00657 break;
00658 case CSSPrimitiveValue::CSS_EXS:
00659 text = DOMString(QString::number( m_value.num ) + "ex");
00660 break;
00661 case CSSPrimitiveValue::CSS_PX:
00662 text = DOMString(QString::number( m_value.num ) + "px");
00663 break;
00664 case CSSPrimitiveValue::CSS_CM:
00665 text = DOMString(QString::number( m_value.num ) + "cm");
00666 break;
00667 case CSSPrimitiveValue::CSS_MM:
00668 text = DOMString(QString::number( m_value.num ) + "mm");
00669 break;
00670 case CSSPrimitiveValue::CSS_IN:
00671 text = DOMString(QString::number( m_value.num ) + "in");
00672 break;
00673 case CSSPrimitiveValue::CSS_PT:
00674 text = DOMString(QString::number( m_value.num ) + "pt");
00675 break;
00676 case CSSPrimitiveValue::CSS_PC:
00677 text = DOMString(QString::number( m_value.num ) + "pc");
00678 break;
00679 case CSSPrimitiveValue::CSS_DEG:
00680 text = DOMString(QString::number( m_value.num ) + "deg");
00681 break;
00682 case CSSPrimitiveValue::CSS_RAD:
00683 text = DOMString(QString::number( m_value.num ) + "rad");
00684 break;
00685 case CSSPrimitiveValue::CSS_GRAD:
00686 text = DOMString(QString::number( m_value.num ) + "grad");
00687 break;
00688 case CSSPrimitiveValue::CSS_MS:
00689 text = DOMString(QString::number( m_value.num ) + "ms");
00690 break;
00691 case CSSPrimitiveValue::CSS_S:
00692 text = DOMString(QString::number( m_value.num ) + "s");
00693 break;
00694 case CSSPrimitiveValue::CSS_HZ:
00695 text = DOMString(QString::number( m_value.num ) + "hz");
00696 break;
00697 case CSSPrimitiveValue::CSS_KHZ:
00698 text = DOMString(QString::number( m_value.num ) + "khz");
00699 break;
00700 case CSSPrimitiveValue::CSS_DIMENSION:
00701
00702 break;
00703 case CSSPrimitiveValue::CSS_STRING:
00704
00705 break;
00706 case CSSPrimitiveValue::CSS_URI:
00707 text = "url(";
00708 text += DOMString( m_value.string );
00709 text += ")";
00710 break;
00711 case CSSPrimitiveValue::CSS_IDENT:
00712 text = getValueName(m_value.ident);
00713 break;
00714 case CSSPrimitiveValue::CSS_ATTR:
00715
00716 break;
00717 case CSSPrimitiveValue::CSS_COUNTER:
00718 text = "counter(";
00719 text += m_value.counter->m_identifier;
00720 text += ")";
00721
00722 break;
00723 case CSSPrimitiveValue::CSS_RECT:
00724 {
00725 RectImpl* rectVal = getRectValue();
00726 text = "rect(";
00727 text += rectVal->top()->cssText() + " ";
00728 text += rectVal->right()->cssText() + " ";
00729 text += rectVal->bottom()->cssText() + " ";
00730 text += rectVal->left()->cssText() + ")";
00731 }
00732 break;
00733 case CSSPrimitiveValue::CSS_RGBCOLOR:
00734 text = QColor(m_value.rgbcolor).name();
00735 break;
00736 default:
00737 break;
00738 }
00739 return text;
00740 }
00741
00742
00743
00744 RectImpl::RectImpl()
00745 {
00746 m_top = 0;
00747 m_right = 0;
00748 m_bottom = 0;
00749 m_left = 0;
00750 }
00751
00752 RectImpl::~RectImpl()
00753 {
00754 if (m_top) m_top->deref();
00755 if (m_right) m_right->deref();
00756 if (m_bottom) m_bottom->deref();
00757 if (m_left) m_left->deref();
00758 }
00759
00760 void RectImpl::setTop( CSSPrimitiveValueImpl *top )
00761 {
00762 if( top ) top->ref();
00763 if ( m_top ) m_top->deref();
00764 m_top = top;
00765 }
00766
00767 void RectImpl::setRight( CSSPrimitiveValueImpl *right )
00768 {
00769 if( right ) right->ref();
00770 if ( m_right ) m_right->deref();
00771 m_right = right;
00772 }
00773
00774 void RectImpl::setBottom( CSSPrimitiveValueImpl *bottom )
00775 {
00776 if( bottom ) bottom->ref();
00777 if ( m_bottom ) m_bottom->deref();
00778 m_bottom = bottom;
00779 }
00780
00781 void RectImpl::setLeft( CSSPrimitiveValueImpl *left )
00782 {
00783 if( left ) left->ref();
00784 if ( m_left ) m_left->deref();
00785 m_left = left;
00786 }
00787
00788
00789
00790 CSSImageValueImpl::CSSImageValueImpl(const DOMString &url, const StyleBaseImpl* style)
00791 : CSSPrimitiveValueImpl(url, CSSPrimitiveValue::CSS_URI)
00792 {
00793 khtml::DocLoader *docLoader = 0;
00794 const StyleBaseImpl *root = style;
00795 while (root->parent())
00796 root = root->parent();
00797 if (root->isCSSStyleSheet())
00798 docLoader = static_cast<const CSSStyleSheetImpl*>(root)->docLoader();
00799
00800 m_image = docLoader->requestImage(url);
00801 if(m_image) m_image->ref(this);
00802 }
00803
00804 CSSImageValueImpl::CSSImageValueImpl()
00805 : CSSPrimitiveValueImpl(CSS_VAL_NONE)
00806 {
00807 m_image = 0;
00808 }
00809
00810 CSSImageValueImpl::~CSSImageValueImpl()
00811 {
00812 if(m_image) m_image->deref(this);
00813 }
00814
00815
00816
00817 FontFamilyValueImpl::FontFamilyValueImpl( const QString &string)
00818 : CSSPrimitiveValueImpl( DOMString(string), CSSPrimitiveValue::CSS_STRING)
00819 {
00820 static const QRegExp parenReg(" \\(.*\\)$");
00821 static const QRegExp braceReg(" \\[.*\\]$");
00822
00823 parsedFontName = string;
00824
00825 parsedFontName.replace(parenReg, QString::null);
00826
00827 parsedFontName.replace(braceReg, QString::null);
00828
00829 #ifndef APPLE_CHANGES
00830 const QString &available = KHTMLSettings::availableFamilies();
00831
00832 parsedFontName = parsedFontName.lower();
00833
00834
00835 int pos = available.find( ',' + parsedFontName + ',', 0, false );
00836 if ( pos == -1 ) {
00837
00838 if ( parsedFontName.startsWith( "ms " ) )
00839 parsedFontName = parsedFontName.mid( 3 );
00840 if ( parsedFontName.endsWith( " ms" ) )
00841 parsedFontName.truncate( parsedFontName.length() - 3 );
00842 pos = available.find( ",ms " + parsedFontName + ',', 0, false );
00843 if ( pos == -1 )
00844 pos = available.find( ',' + parsedFontName + " ms,", 0, false );
00845 }
00846
00847 if ( pos != -1 ) {
00848 ++pos;
00849 int p = available.find(',', pos);
00850 assert( p != -1 );
00851 parsedFontName = available.mid( pos, p - pos);
00852
00853 } else
00854 parsedFontName = QString::null;
00855
00856 #endif // !APPLE_CHANGES
00857 }
00858
00859 FontValueImpl::FontValueImpl()
00860 : style(0), variant(0), weight(0), size(0), lineHeight(0), family(0)
00861 {
00862 }
00863
00864 FontValueImpl::~FontValueImpl()
00865 {
00866 delete style;
00867 delete variant;
00868 delete weight;
00869 delete size;
00870 delete lineHeight;
00871 delete family;
00872 }
00873
00874 DOMString FontValueImpl::cssText() const
00875 {
00876
00877
00878 DOMString result("");
00879
00880 if (style) {
00881 result += style->cssText();
00882 }
00883 if (variant) {
00884 if (result.length() > 0) {
00885 result += " ";
00886 }
00887 result += variant->cssText();
00888 }
00889 if (weight) {
00890 if (result.length() > 0) {
00891 result += " ";
00892 }
00893 result += weight->cssText();
00894 }
00895 if (size) {
00896 if (result.length() > 0) {
00897 result += " ";
00898 }
00899 result += size->cssText();
00900 }
00901 if (lineHeight) {
00902 if (!size) {
00903 result += " ";
00904 }
00905 result += "/";
00906 result += lineHeight->cssText();
00907 }
00908 if (family) {
00909 if (result.length() > 0) {
00910 result += " ";
00911 }
00912 result += family->cssText();
00913 }
00914
00915 return result;
00916 }
00917
00918 QuotesValueImpl::QuotesValueImpl()
00919 : levels(0)
00920 {
00921 }
00922
00923 DOMString QuotesValueImpl::cssText() const
00924 {
00925 return "\"" + data.join("\" \"") + "\"";
00926 }
00927
00928 void QuotesValueImpl::addLevel(const QString& open, const QString& close)
00929 {
00930 data.append(open);
00931 data.append(close);
00932 levels++;
00933 }
00934
00935 QString QuotesValueImpl::openQuote(int level) const
00936 {
00937 if (levels == 0) return "";
00938 level--;
00939
00940 if (level < 0) level = 0;
00941 else
00942 if (level >= (int) levels) level = (int) (levels-1);
00943 return data[level*2];
00944 }
00945
00946 QString QuotesValueImpl::closeQuote(int level) const
00947 {
00948 if (levels == 0) return "";
00949
00950 if (level < 0) level = 0;
00951 else
00952 if (level >= (int) levels) level = (int) (levels-1);
00953 return data[level*2+1];
00954 }
00955
00956
00957 ShadowValueImpl::ShadowValueImpl(CSSPrimitiveValueImpl* _x, CSSPrimitiveValueImpl* _y,
00958 CSSPrimitiveValueImpl* _blur, CSSPrimitiveValueImpl* _color)
00959 :x(_x), y(_y), blur(_blur), color(_color)
00960 {}
00961
00962 ShadowValueImpl::~ShadowValueImpl()
00963 {
00964 delete x;
00965 delete y;
00966 delete blur;
00967 delete color;
00968 }
00969
00970 DOMString ShadowValueImpl::cssText() const
00971 {
00972 DOMString text("");
00973 if (color) {
00974 text += color->cssText();
00975 }
00976 if (x) {
00977 if (text.length() > 0) {
00978 text += " ";
00979 }
00980 text += x->cssText();
00981 }
00982 if (y) {
00983 if (text.length() > 0) {
00984 text += " ";
00985 }
00986 text += y->cssText();
00987 }
00988 if (blur) {
00989 if (text.length() > 0) {
00990 text += " ";
00991 }
00992 text += blur->cssText();
00993 }
00994
00995 return text;
00996 }
00997
00998 DOMString CounterActImpl::cssText() const
00999 {
01000 DOMString text(m_counter);
01001 text += DOMString(QString::number(m_value));
01002
01003 return text;
01004 }
01005
01006 DOMString CSSProperty::cssText() const
01007 {
01008 return getPropertyName(m_id) + DOMString(": ") + m_value->cssText() + (m_bImportant ? DOMString(" !important") : DOMString()) + DOMString("; ");
01009 }