khtml Library API Documentation

css_value.cpp

00001 
00024 #include "dom/css_rule.h"
00025 #include "dom/dom_exception.h"
00026 
00027 #include "css/css_valueimpl.h"
00028 
00029 using namespace DOM;
00030 
00031 CSSStyleDeclaration::CSSStyleDeclaration()
00032 {
00033     impl = 0;
00034 }
00035 
00036 CSSStyleDeclaration::CSSStyleDeclaration(const CSSStyleDeclaration &other)
00037 {
00038     impl = other.impl;
00039     if(impl) impl->ref();
00040 }
00041 
00042 CSSStyleDeclaration::CSSStyleDeclaration(CSSStyleDeclarationImpl *i)
00043 {
00044     impl = i;
00045     if(impl) impl->ref();
00046 }
00047 
00048 CSSStyleDeclaration &CSSStyleDeclaration::operator = (const CSSStyleDeclaration &other)
00049 {
00050     if ( impl != other.impl ) {
00051         if(impl) impl->deref();
00052         impl = other.impl;
00053         if(impl) impl->ref();
00054     }
00055     return *this;
00056 }
00057 
00058 CSSStyleDeclaration::~CSSStyleDeclaration()
00059 {
00060     if(impl) impl->deref();
00061 }
00062 
00063 DOMString CSSStyleDeclaration::cssText() const
00064 {
00065     if(!impl) return DOMString();
00066     return static_cast<CSSStyleDeclarationImpl *>(impl)->cssText();
00067 }
00068 
00069 void CSSStyleDeclaration::setCssText( const DOMString &value )
00070 {
00071     if(!impl) return;
00072     impl->setCssText(value);
00073 }
00074 
00075 DOMString CSSStyleDeclaration::getPropertyValue( const DOMString &propertyName )
00076 {
00077     if(!impl) return DOMString();
00078     int id = getPropertyID(propertyName.string().ascii(), propertyName.length());
00079     if (!id) return DOMString();
00080     return static_cast<CSSStyleDeclarationImpl *>(impl)->getPropertyValue(id);
00081 }
00082 
00083 CSSValue CSSStyleDeclaration::getPropertyCSSValue( const DOMString &propertyName )
00084 {
00085     if(!impl) return 0;
00086     int id = getPropertyID(propertyName.string().ascii(), propertyName.length());
00087     if (!id) return 0;
00088     return static_cast<CSSStyleDeclarationImpl *>(impl)->getPropertyCSSValue(id);
00089 }
00090 
00091 DOMString CSSStyleDeclaration::removeProperty( const DOMString &property )
00092 {
00093     int id = getPropertyID(property.string().ascii(), property.length());
00094     if(!impl || !id) return DOMString();
00095     return static_cast<CSSStyleDeclarationImpl *>(impl)->removeProperty( id );
00096 }
00097 
00098 DOMString CSSStyleDeclaration::getPropertyPriority( const DOMString &propertyName )
00099 {
00100     int id = getPropertyID(propertyName.string().ascii(), propertyName.length());
00101     if(!impl || !id) return DOMString();
00102     if (impl->getPropertyPriority(id))
00103         return DOMString("important");
00104     return DOMString();
00105 }
00106 
00107 void CSSStyleDeclaration::setProperty( const DOMString &propName, const DOMString &value, const DOMString &priority )
00108 {
00109     if(!impl) return;
00110     int id = getPropertyID(propName.string().lower().ascii(), propName.length());
00111     if (!id) return;
00112     bool important = false;
00113     QString str = priority.string();
00114     if (str.find("important", 0, false) != -1)
00115         important = true;
00116 
00117     static_cast<CSSStyleDeclarationImpl *>(impl)->setProperty( id, value, important );
00118 }
00119 
00120 unsigned long CSSStyleDeclaration::length() const
00121 {
00122     if(!impl) return 0;
00123     return static_cast<CSSStyleDeclarationImpl *>(impl)->length();
00124 }
00125 
00126 DOMString CSSStyleDeclaration::item( unsigned long index )
00127 {
00128     if(!impl) return DOMString();
00129     return static_cast<CSSStyleDeclarationImpl *>(impl)->item( index );
00130 }
00131 
00132 CSSRule CSSStyleDeclaration::parentRule() const
00133 {
00134     if(!impl) return 0;
00135     return static_cast<CSSStyleDeclarationImpl *>(impl)->parentRule();
00136 }
00137 
00138 CSSStyleDeclarationImpl *CSSStyleDeclaration::handle() const
00139 {
00140     return impl;
00141 }
00142 
00143 bool CSSStyleDeclaration::isNull() const
00144 {
00145     return (impl == 0);
00146 }
00147 
00148 // ----------------------------------------------------------
00149 
00150 CSSValue::CSSValue()
00151 {
00152     impl = 0;
00153 }
00154 
00155 CSSValue::CSSValue(const CSSValue &other)
00156 {
00157     impl = other.impl;
00158     if(impl) impl->ref();
00159 }
00160 
00161 CSSValue::CSSValue(CSSValueImpl *i)
00162 {
00163     impl = i;
00164     if(impl) impl->ref();
00165 }
00166 
00167 CSSValue &CSSValue::operator = (const CSSValue &other)
00168 {
00169     if ( impl != other.impl ) {
00170         if(impl) impl->deref();
00171         impl = other.impl;
00172         if(impl) impl->ref();
00173     }
00174     return *this;
00175 }
00176 
00177 CSSValue::~CSSValue()
00178 {
00179     if(impl) impl->deref();
00180 }
00181 
00182 DOMString CSSValue::cssText() const
00183 {
00184     if(!impl) return DOMString();
00185     return ((CSSValueImpl *)impl)->cssText();
00186 }
00187 
00188 void CSSValue::setCssText( const DOMString &/*value*/ )
00189 {
00190     if(!impl) return;
00191     ((CSSValueImpl *)impl)->cssText();
00192 }
00193 
00194 unsigned short CSSValue::cssValueType() const
00195 {
00196     if(!impl) return 0;
00197     return ((CSSValueImpl *)impl)->cssValueType();
00198 }
00199 
00200 bool CSSValue::isCSSValueList() const
00201 {
00202     if(!impl) return false;
00203     return ((CSSValueImpl *)impl)->isValueList();
00204 }
00205 
00206 bool CSSValue::isCSSPrimitiveValue() const
00207 {
00208     if(!impl) return false;
00209     return ((CSSValueImpl *)impl)->isPrimitiveValue();
00210 }
00211 
00212 CSSValueImpl *CSSValue::handle() const
00213 {
00214     return impl;
00215 }
00216 
00217 bool CSSValue::isNull() const
00218 {
00219     return (impl == 0);
00220 }
00221 
00222 // ----------------------------------------------------------
00223 
00224 CSSValueList::CSSValueList() : CSSValue()
00225 {
00226 }
00227 
00228 CSSValueList::CSSValueList(const CSSValueList &other) : CSSValue(other)
00229 {
00230 }
00231 
00232 CSSValueList::CSSValueList(const CSSValue &other)
00233 {
00234    impl = 0;
00235    operator=(other);
00236 }
00237 
00238 CSSValueList::CSSValueList(CSSValueListImpl *impl) : CSSValue(impl)
00239 {
00240 }
00241 
00242 CSSValueList &CSSValueList::operator = (const CSSValueList &other)
00243 {
00244     if ( impl != other.impl ) {
00245         if (impl) impl->deref();
00246         impl = other.handle();
00247         if (impl) impl->ref();
00248     }
00249     return *this;
00250 }
00251 
00252 CSSValueList &CSSValueList::operator = (const CSSValue &other)
00253 {
00254     CSSValueImpl *ohandle = other.handle() ;
00255     if ( impl != ohandle ) {
00256         if (impl) impl->deref();
00257         if (!other.isNull() && !other.isCSSValueList()) {
00258             impl = 0;
00259     } else {
00260         impl = ohandle;
00261             if (impl) impl->ref();
00262     }
00263     }
00264     return *this;
00265 }
00266 
00267 CSSValueList::~CSSValueList()
00268 {
00269 }
00270 
00271 unsigned long CSSValueList::length() const
00272 {
00273     if(!impl) return 0;
00274     return ((CSSValueListImpl *)impl)->length();
00275 }
00276 
00277 CSSValue CSSValueList::item( unsigned long index )
00278 {
00279     if(!impl) return 0;
00280     return ((CSSValueListImpl *)impl)->item( index );
00281 }
00282 
00283 // ----------------------------------------------------------
00284 
00285 CSSPrimitiveValue::CSSPrimitiveValue() : CSSValue()
00286 {
00287 }
00288 
00289 CSSPrimitiveValue::CSSPrimitiveValue(const CSSPrimitiveValue &other) : CSSValue(other)
00290 {
00291 }
00292 
00293 CSSPrimitiveValue::CSSPrimitiveValue(const CSSValue &other) : CSSValue(other)
00294 {
00295     impl = 0;
00296     operator=(other);
00297 }
00298 
00299 CSSPrimitiveValue::CSSPrimitiveValue(CSSPrimitiveValueImpl *impl) : CSSValue(impl)
00300 {
00301 }
00302 
00303 CSSPrimitiveValue &CSSPrimitiveValue::operator = (const CSSPrimitiveValue &other)
00304 {
00305     if ( impl != other.impl ) {
00306         if (impl) impl->deref();
00307         impl = other.handle();
00308         if (impl) impl->ref();
00309     }
00310     return *this;
00311 }
00312 
00313 CSSPrimitiveValue &CSSPrimitiveValue::operator = (const CSSValue &other)
00314 {
00315     CSSValueImpl *ohandle = other.handle();
00316     if ( impl != ohandle ) {
00317         if (impl) impl->deref();
00318         if (!other.isNull() && !other.isCSSPrimitiveValue()) {
00319             impl = 0;
00320     } else {
00321         impl = ohandle;
00322             if (impl) impl->ref();
00323     }
00324     }
00325     return *this;
00326 }
00327 
00328 CSSPrimitiveValue::~CSSPrimitiveValue()
00329 {
00330 }
00331 
00332 unsigned short CSSPrimitiveValue::primitiveType() const
00333 {
00334     if(!impl) return 0;
00335     return ((CSSPrimitiveValueImpl *)impl)->primitiveType();
00336 }
00337 
00338 void CSSPrimitiveValue::setFloatValue( unsigned short unitType, float floatValue )
00339 {
00340     if(!impl) return;
00341     int exceptioncode = 0;
00342     ((CSSPrimitiveValueImpl *)impl)->setFloatValue( unitType, floatValue, exceptioncode );
00343     if ( exceptioncode >= CSSException::_EXCEPTION_OFFSET )
00344     throw CSSException( exceptioncode - CSSException::_EXCEPTION_OFFSET );
00345     if ( exceptioncode )
00346     throw DOMException( exceptioncode );
00347 }
00348 
00349 float CSSPrimitiveValue::getFloatValue( unsigned short unitType )
00350 {
00351     if(!impl) return 0;
00352     // ### add unit conversion
00353     if(primitiveType() != unitType)
00354     throw CSSException(CSSException::SYNTAX_ERR);
00355     return ((CSSPrimitiveValueImpl *)impl)->getFloatValue( unitType );
00356 }
00357 
00358 void CSSPrimitiveValue::setStringValue( unsigned short stringType, const DOMString &stringValue )
00359 {
00360     int exceptioncode = 0;
00361     if(impl)
00362         ((CSSPrimitiveValueImpl *)impl)->setStringValue( stringType, stringValue, exceptioncode );
00363     if ( exceptioncode >= CSSException::_EXCEPTION_OFFSET )
00364     throw CSSException( exceptioncode - CSSException::_EXCEPTION_OFFSET );
00365     if ( exceptioncode )
00366     throw DOMException( exceptioncode );
00367 
00368 }
00369 
00370 DOMString CSSPrimitiveValue::getStringValue(  )
00371 {
00372     if(!impl) return DOMString();
00373     return ((CSSPrimitiveValueImpl *)impl)->getStringValue(  );
00374 }
00375 
00376 Counter CSSPrimitiveValue::getCounterValue(  )
00377 {
00378     if(!impl) return Counter();
00379     return ((CSSPrimitiveValueImpl *)impl)->getCounterValue(  );
00380 }
00381 
00382 Rect CSSPrimitiveValue::getRectValue(  )
00383 {
00384     if(!impl) return Rect();
00385     return ((CSSPrimitiveValueImpl *)impl)->getRectValue(  );
00386 }
00387 
00388 RGBColor CSSPrimitiveValue::getRGBColorValue(  )
00389 {
00390     // ###
00391     return RGBColor();
00392     //if(!impl) return RGBColor();
00393     //return ((CSSPrimitiveValueImpl *)impl)->getRGBColorValue(  );
00394 }
00395 
00396 // -------------------------------------------------------------------
00397 
00398 Counter::Counter()
00399 {
00400 }
00401 
00402 Counter::Counter(const Counter &/*other*/)
00403 {
00404     impl = 0;
00405 }
00406 
00407 Counter &Counter::operator = (const Counter &other)
00408 {
00409     if ( impl != other.impl ) {
00410         if (impl) impl->deref();
00411         impl = other.impl;
00412         if (impl) impl->ref();
00413     }
00414     return *this;
00415 }
00416 
00417 Counter::Counter(CounterImpl *i)
00418 {
00419     impl = i;
00420     if (impl) impl->ref();
00421 }
00422 
00423 Counter::~Counter()
00424 {
00425     if (impl) impl->deref();
00426 }
00427 
00428 DOMString Counter::identifier() const
00429 {
00430   if (!impl) return DOMString();
00431   return impl->identifier();
00432 }
00433 
00434 DOMString Counter::listStyle() const
00435 {
00436   if (!impl) return DOMString();
00437   return impl->listStyle();
00438 }
00439 
00440 DOMString Counter::separator() const
00441 {
00442   if (!impl) return DOMString();
00443   return impl->separator();
00444 }
00445 
00446 CounterImpl *Counter::handle() const
00447 {
00448     return impl;
00449 }
00450 
00451 bool Counter::isNull() const
00452 {
00453     return (impl == 0);
00454 }
00455 
00456 // --------------------------------------------------------------------
00457 
00458 RGBColor::RGBColor()
00459 {
00460 }
00461 
00462 RGBColor::RGBColor(const RGBColor &other)
00463 {
00464     m_color = other.m_color;
00465 }
00466 
00467 RGBColor::RGBColor(QRgb color)
00468 {
00469     m_color = color;
00470 }
00471 
00472 RGBColor &RGBColor::operator = (const RGBColor &other)
00473 {
00474     m_color = other.m_color;
00475     return *this;
00476 }
00477 
00478 RGBColor::~RGBColor()
00479 {
00480 }
00481 
00482 CSSPrimitiveValue RGBColor::red() const
00483 {
00484     return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qRed(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
00485 }
00486 
00487 CSSPrimitiveValue RGBColor::green() const
00488 {
00489     return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qGreen(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
00490 }
00491 
00492 CSSPrimitiveValue RGBColor::blue() const
00493 {
00494     return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qBlue(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
00495 }
00496 
00497 
00498 // ---------------------------------------------------------------------
00499 
00500 Rect::Rect()
00501 {
00502     impl = 0;
00503 }
00504 
00505 Rect::Rect(const Rect &other)
00506 {
00507     impl = other.impl;
00508     if (impl) impl->ref();
00509 }
00510 
00511 Rect::Rect(RectImpl *i)
00512 {
00513     impl = i;
00514     if (impl) impl->ref();
00515 }
00516 
00517 Rect &Rect::operator = (const Rect &other)
00518 {
00519     if ( impl != other.impl ) {
00520         if (impl) impl->deref();
00521         impl = other.impl;
00522         if (impl) impl->ref();
00523     }
00524     return *this;
00525 }
00526 
00527 Rect::~Rect()
00528 {
00529     if (impl) impl->deref();
00530 }
00531 
00532 CSSPrimitiveValue Rect::top() const
00533 {
00534     if (!impl) return 0;
00535     return impl->top();
00536 }
00537 
00538 CSSPrimitiveValue Rect::right() const
00539 {
00540     if (!impl) return 0;
00541     return impl->right();
00542 }
00543 
00544 CSSPrimitiveValue Rect::bottom() const
00545 {
00546     if (!impl) return 0;
00547     return impl->bottom();
00548 }
00549 
00550 CSSPrimitiveValue Rect::left() const
00551 {
00552     if (!impl) return 0;
00553     return impl->left();
00554 }
00555 
00556 RectImpl *Rect::handle() const
00557 {
00558     return impl;
00559 }
00560 
00561 bool Rect::isNull() const
00562 {
00563     return (impl == 0);
00564 }
00565 
00566 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:34 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001