File indexing completed on 2024-04-28 15:22:54

0001 /*
0002  * This file is part of the DOM implementation for KDE.
0003  *
0004  * Copyright 1999 Lars Knoll (knoll@kde.org)
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  *
0021  */
0022 
0023 #include "dom/css_rule.h"
0024 #include "dom/dom_exception.h"
0025 
0026 #include "css/css_renderstyledeclarationimpl.h"
0027 #include "css/css_valueimpl.h"
0028 
0029 namespace DOM
0030 {
0031 
0032 CSSStyleDeclaration::CSSStyleDeclaration()
0033 {
0034     impl = nullptr;
0035 }
0036 
0037 CSSStyleDeclaration::CSSStyleDeclaration(const CSSStyleDeclaration &other)
0038 {
0039     impl = other.impl;
0040     if (impl) {
0041         impl->ref();
0042     }
0043 }
0044 
0045 CSSStyleDeclaration::CSSStyleDeclaration(CSSStyleDeclarationImpl *i)
0046 {
0047     impl = i;
0048     if (impl) {
0049         impl->ref();
0050     }
0051 }
0052 
0053 CSSStyleDeclaration &CSSStyleDeclaration::operator = (const CSSStyleDeclaration &other)
0054 {
0055     if (impl != other.impl) {
0056         if (impl) {
0057             impl->deref();
0058         }
0059         impl = other.impl;
0060         if (impl) {
0061             impl->ref();
0062         }
0063     }
0064     return *this;
0065 }
0066 
0067 CSSStyleDeclaration::~CSSStyleDeclaration()
0068 {
0069     if (impl) {
0070         impl->deref();
0071     }
0072 }
0073 
0074 DOMString CSSStyleDeclaration::cssText() const
0075 {
0076     if (!impl) {
0077         return DOMString();
0078     }
0079     return static_cast<CSSStyleDeclarationImpl *>(impl)->cssText();
0080 }
0081 
0082 void CSSStyleDeclaration::setCssText(const DOMString &value)
0083 {
0084     if (!impl) {
0085         return;
0086     }
0087     impl->setCssText(value);
0088 }
0089 
0090 DOMString CSSStyleDeclaration::getPropertyValue(const DOMString &propertyName) const
0091 {
0092     if (!impl) {
0093         return DOMString();
0094     }
0095     return static_cast<CSSStyleDeclarationImpl *>(impl)->getPropertyValue(propertyName);
0096 }
0097 
0098 CSSValue CSSStyleDeclaration::getPropertyCSSValue(const DOMString &propertyName) const
0099 {
0100     if (!impl) {
0101         return nullptr;
0102     }
0103     return static_cast<CSSStyleDeclarationImpl *>(impl)->getPropertyCSSValue(propertyName);
0104 }
0105 
0106 DOMString CSSStyleDeclaration::removeProperty(const DOMString &propertyName)
0107 {
0108     if (!impl) {
0109         return DOMString();
0110     }
0111     return static_cast<CSSStyleDeclarationImpl *>(impl)->removeProperty(propertyName);
0112 }
0113 
0114 DOMString CSSStyleDeclaration::getPropertyPriority(const DOMString &propertyName) const
0115 {
0116     if (!impl) {
0117         return DOMString();
0118     }
0119     return impl->getPropertyPriority(propertyName);
0120 }
0121 
0122 void CSSStyleDeclaration::setProperty(const DOMString &propName, const DOMString &value, const DOMString &priority)
0123 {
0124     if (!impl) {
0125         return;
0126     }
0127     if (value.isEmpty()) {
0128         static_cast<CSSStyleDeclarationImpl *>(impl)->removeProperty(propName);
0129         return;
0130     }
0131     static_cast<CSSStyleDeclarationImpl *>(impl)->setProperty(propName, value, priority);
0132 }
0133 
0134 unsigned long CSSStyleDeclaration::length() const
0135 {
0136     if (!impl) {
0137         return 0;
0138     }
0139     return static_cast<CSSStyleDeclarationImpl *>(impl)->length();
0140 }
0141 
0142 DOMString CSSStyleDeclaration::item(unsigned long index) const
0143 {
0144     if (!impl) {
0145         return DOMString();
0146     }
0147     return static_cast<CSSStyleDeclarationImpl *>(impl)->item(index);
0148 }
0149 CSSRule CSSStyleDeclaration::parentRule() const
0150 {
0151     if (!impl) {
0152         return nullptr;
0153     }
0154     return static_cast<CSSStyleDeclarationImpl *>(impl)->parentRule();
0155 }
0156 
0157 CSSStyleDeclarationImpl *CSSStyleDeclaration::handle() const
0158 {
0159     return impl;
0160 }
0161 
0162 bool CSSStyleDeclaration::isNull() const
0163 {
0164     return (impl == nullptr);
0165 }
0166 
0167 // ----------------------------------------------------------
0168 
0169 CSSValue::CSSValue()
0170 {
0171     impl = nullptr;
0172 }
0173 
0174 CSSValue::CSSValue(const CSSValue &other)
0175 {
0176     impl = other.impl;
0177     if (impl) {
0178         impl->ref();
0179     }
0180 }
0181 
0182 CSSValue::CSSValue(CSSValueImpl *i)
0183 {
0184     impl = i;
0185     if (impl) {
0186         impl->ref();
0187     }
0188 }
0189 
0190 CSSValue &CSSValue::operator = (const CSSValue &other)
0191 {
0192     if (impl != other.impl) {
0193         if (impl) {
0194             impl->deref();
0195         }
0196         impl = other.impl;
0197         if (impl) {
0198             impl->ref();
0199         }
0200     }
0201     return *this;
0202 }
0203 
0204 CSSValue::~CSSValue()
0205 {
0206     if (impl) {
0207         impl->deref();
0208     }
0209 }
0210 
0211 DOMString CSSValue::cssText() const
0212 {
0213     if (!impl) {
0214         return DOMString();
0215     }
0216     return ((CSSValueImpl *)impl)->cssText();
0217 }
0218 
0219 void CSSValue::setCssText(const DOMString &value)
0220 {
0221     if (!impl) {
0222         return;
0223     }
0224     ((CSSValueImpl *)impl)->setCssText(value);
0225 }
0226 
0227 unsigned short CSSValue::cssValueType() const
0228 {
0229     if (!impl) {
0230         return 0;
0231     }
0232     return ((CSSValueImpl *)impl)->cssValueType();
0233 }
0234 
0235 bool CSSValue::isCSSValueList() const
0236 {
0237     if (!impl) {
0238         return false;
0239     }
0240     return ((CSSValueImpl *)impl)->isValueList();
0241 }
0242 
0243 bool CSSValue::isCSSPrimitiveValue() const
0244 {
0245     if (!impl) {
0246         return false;
0247     }
0248     return ((CSSValueImpl *)impl)->isPrimitiveValue();
0249 }
0250 
0251 CSSValueImpl *CSSValue::handle() const
0252 {
0253     return impl;
0254 }
0255 
0256 bool CSSValue::isNull() const
0257 {
0258     return (impl == nullptr);
0259 }
0260 
0261 // ----------------------------------------------------------
0262 
0263 CSSValueList::CSSValueList() : CSSValue()
0264 {
0265 }
0266 
0267 CSSValueList::CSSValueList(const CSSValueList &other) : CSSValue(other)
0268 {
0269 }
0270 
0271 CSSValueList::CSSValueList(const CSSValue &other)
0272 {
0273     impl = nullptr;
0274     operator=(other);
0275 }
0276 
0277 CSSValueList::CSSValueList(CSSValueListImpl *impl) : CSSValue(impl)
0278 {
0279 }
0280 
0281 CSSValueList &CSSValueList::operator = (const CSSValueList &other)
0282 {
0283     if (impl != other.impl) {
0284         if (impl) {
0285             impl->deref();
0286         }
0287         impl = other.handle();
0288         if (impl) {
0289             impl->ref();
0290         }
0291     }
0292     return *this;
0293 }
0294 
0295 CSSValueList &CSSValueList::operator = (const CSSValue &other)
0296 {
0297     CSSValueImpl *ohandle = other.handle();
0298     if (impl != ohandle) {
0299         if (impl) {
0300             impl->deref();
0301         }
0302         if (!other.isNull() && !other.isCSSValueList()) {
0303             impl = nullptr;
0304         } else {
0305             impl = ohandle;
0306             if (impl) {
0307                 impl->ref();
0308             }
0309         }
0310     }
0311     return *this;
0312 }
0313 
0314 CSSValueList::~CSSValueList()
0315 {
0316 }
0317 
0318 unsigned long CSSValueList::length() const
0319 {
0320     if (!impl) {
0321         return 0;
0322     }
0323     return ((CSSValueListImpl *)impl)->length();
0324 }
0325 
0326 CSSValue CSSValueList::item(unsigned long index)
0327 {
0328     if (!impl) {
0329         return nullptr;
0330     }
0331     return ((CSSValueListImpl *)impl)->item(index);
0332 }
0333 
0334 // ----------------------------------------------------------
0335 
0336 CSSPrimitiveValue::CSSPrimitiveValue() : CSSValue()
0337 {
0338 }
0339 
0340 CSSPrimitiveValue::CSSPrimitiveValue(const CSSPrimitiveValue &other) : CSSValue(other)
0341 {
0342 }
0343 
0344 CSSPrimitiveValue::CSSPrimitiveValue(const CSSValue &other) : CSSValue(other)
0345 {
0346     impl = nullptr;
0347     operator=(other);
0348 }
0349 
0350 CSSPrimitiveValue::CSSPrimitiveValue(CSSPrimitiveValueImpl *impl) : CSSValue(impl)
0351 {
0352 }
0353 
0354 CSSPrimitiveValue &CSSPrimitiveValue::operator = (const CSSPrimitiveValue &other)
0355 {
0356     if (impl != other.impl) {
0357         if (impl) {
0358             impl->deref();
0359         }
0360         impl = other.handle();
0361         if (impl) {
0362             impl->ref();
0363         }
0364     }
0365     return *this;
0366 }
0367 
0368 CSSPrimitiveValue &CSSPrimitiveValue::operator = (const CSSValue &other)
0369 {
0370     CSSValueImpl *ohandle = other.handle();
0371     if (impl != ohandle) {
0372         if (impl) {
0373             impl->deref();
0374         }
0375         if (!other.isNull() && !other.isCSSPrimitiveValue()) {
0376             impl = nullptr;
0377         } else {
0378             impl = ohandle;
0379             if (impl) {
0380                 impl->ref();
0381             }
0382         }
0383     }
0384     return *this;
0385 }
0386 
0387 CSSPrimitiveValue::~CSSPrimitiveValue()
0388 {
0389 }
0390 
0391 unsigned short CSSPrimitiveValue::primitiveType() const
0392 {
0393     if (!impl) {
0394         return 0;
0395     }
0396     return ((CSSPrimitiveValueImpl *)impl)->primitiveType();
0397 }
0398 
0399 void CSSPrimitiveValue::setFloatValue(unsigned short unitType, float floatValue)
0400 {
0401     if (!impl) {
0402         return;
0403     }
0404     int exceptioncode = 0;
0405     ((CSSPrimitiveValueImpl *)impl)->setFloatValue(unitType, floatValue, exceptioncode);
0406     if (exceptioncode >= CSSException::_EXCEPTION_OFFSET) {
0407         throw CSSException(exceptioncode - CSSException::_EXCEPTION_OFFSET);
0408     }
0409     if (exceptioncode) {
0410         throw DOMException(exceptioncode);
0411     }
0412 }
0413 
0414 float CSSPrimitiveValue::getFloatValue(unsigned short unitType) const
0415 {
0416     if (!impl) {
0417         return 0;
0418     }
0419     // ### add unit conversion
0420     if (primitiveType() != unitType) {
0421         throw CSSException(CSSException::SYNTAX_ERR);
0422     }
0423     return ((CSSPrimitiveValueImpl *)impl)->floatValue(unitType);
0424 }
0425 
0426 void CSSPrimitiveValue::setStringValue(unsigned short stringType, const DOMString &stringValue)
0427 {
0428     int exceptioncode = 0;
0429     if (impl) {
0430         ((CSSPrimitiveValueImpl *)impl)->setStringValue(stringType, stringValue, exceptioncode);
0431     }
0432     if (exceptioncode >= CSSException::_EXCEPTION_OFFSET) {
0433         throw CSSException(exceptioncode - CSSException::_EXCEPTION_OFFSET);
0434     }
0435     if (exceptioncode) {
0436         throw DOMException(exceptioncode);
0437     }
0438 
0439 }
0440 
0441 DOMString CSSPrimitiveValue::getStringValue() const
0442 {
0443     if (!impl) {
0444         return DOMString();
0445     }
0446     return ((CSSPrimitiveValueImpl *)impl)->getStringValue();
0447 }
0448 
0449 Counter CSSPrimitiveValue::getCounterValue() const
0450 {
0451     if (!impl) {
0452         return Counter();
0453     }
0454     return ((CSSPrimitiveValueImpl *)impl)->getCounterValue();
0455 }
0456 
0457 Rect CSSPrimitiveValue::getRectValue() const
0458 {
0459     if (!impl) {
0460         return Rect();
0461     }
0462     return ((CSSPrimitiveValueImpl *)impl)->getRectValue();
0463 }
0464 
0465 RGBColor CSSPrimitiveValue::getRGBColorValue() const
0466 {
0467     // ###
0468     return RGBColor();
0469     //if(!impl) return RGBColor();
0470     //return ((CSSPrimitiveValueImpl *)impl)->getRGBColorValue(  );
0471 }
0472 
0473 // -------------------------------------------------------------------
0474 
0475 Counter::Counter()
0476 {
0477 }
0478 
0479 Counter::Counter(const Counter &/*other*/)
0480 {
0481     impl = nullptr;
0482 }
0483 
0484 Counter &Counter::operator = (const Counter &other)
0485 {
0486     if (impl != other.impl) {
0487         if (impl) {
0488             impl->deref();
0489         }
0490         impl = other.impl;
0491         if (impl) {
0492             impl->ref();
0493         }
0494     }
0495     return *this;
0496 }
0497 
0498 Counter::Counter(CounterImpl *i)
0499 {
0500     impl = i;
0501     if (impl) {
0502         impl->ref();
0503     }
0504 }
0505 
0506 Counter::~Counter()
0507 {
0508     if (impl) {
0509         impl->deref();
0510     }
0511 }
0512 
0513 DOMString Counter::identifier() const
0514 {
0515     if (!impl) {
0516         return DOMString();
0517     }
0518     return impl->identifier();
0519 }
0520 
0521 DOMString Counter::listStyle() const
0522 {
0523     if (!impl) {
0524         return DOMString();
0525     }
0526     return khtml::stringForListStyleType((khtml::EListStyleType)impl->listStyle());
0527 }
0528 
0529 DOMString Counter::separator() const
0530 {
0531     if (!impl) {
0532         return DOMString();
0533     }
0534     return impl->separator();
0535 }
0536 
0537 CounterImpl *Counter::handle() const
0538 {
0539     return impl;
0540 }
0541 
0542 bool Counter::isNull() const
0543 {
0544     return (impl == nullptr);
0545 }
0546 
0547 // --------------------------------------------------------------------
0548 
0549 RGBColor::RGBColor()
0550 {
0551 }
0552 
0553 RGBColor::RGBColor(const RGBColor &other)
0554 {
0555     m_color = other.m_color;
0556 }
0557 
0558 RGBColor::RGBColor(QRgb color)
0559 {
0560     m_color = color;
0561 }
0562 
0563 RGBColor &RGBColor::operator = (const RGBColor &other)
0564 {
0565     m_color = other.m_color;
0566     return *this;
0567 }
0568 
0569 RGBColor::~RGBColor()
0570 {
0571 }
0572 
0573 CSSPrimitiveValue RGBColor::red() const
0574 {
0575     return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qRed(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
0576 }
0577 
0578 CSSPrimitiveValue RGBColor::green() const
0579 {
0580     return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qGreen(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
0581 }
0582 
0583 CSSPrimitiveValue RGBColor::blue() const
0584 {
0585     return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qBlue(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
0586 }
0587 
0588 // ---------------------------------------------------------------------
0589 
0590 Rect::Rect()
0591 {
0592     impl = nullptr;
0593 }
0594 
0595 Rect::Rect(const Rect &other)
0596 {
0597     impl = other.impl;
0598     if (impl) {
0599         impl->ref();
0600     }
0601 }
0602 
0603 Rect::Rect(RectImpl *i)
0604 {
0605     impl = i;
0606     if (impl) {
0607         impl->ref();
0608     }
0609 }
0610 
0611 Rect &Rect::operator = (const Rect &other)
0612 {
0613     if (impl != other.impl) {
0614         if (impl) {
0615             impl->deref();
0616         }
0617         impl = other.impl;
0618         if (impl) {
0619             impl->ref();
0620         }
0621     }
0622     return *this;
0623 }
0624 
0625 Rect::~Rect()
0626 {
0627     if (impl) {
0628         impl->deref();
0629     }
0630 }
0631 
0632 CSSPrimitiveValue Rect::top() const
0633 {
0634     if (!impl) {
0635         return nullptr;
0636     }
0637     return impl->top();
0638 }
0639 
0640 CSSPrimitiveValue Rect::right() const
0641 {
0642     if (!impl) {
0643         return nullptr;
0644     }
0645     return impl->right();
0646 }
0647 
0648 CSSPrimitiveValue Rect::bottom() const
0649 {
0650     if (!impl) {
0651         return nullptr;
0652     }
0653     return impl->bottom();
0654 }
0655 
0656 CSSPrimitiveValue Rect::left() const
0657 {
0658     if (!impl) {
0659         return nullptr;
0660     }
0661     return impl->left();
0662 }
0663 
0664 RectImpl *Rect::handle() const
0665 {
0666     return impl;
0667 }
0668 
0669 bool Rect::isNull() const
0670 {
0671     return (impl == nullptr);
0672 }
0673 
0674 } // namespace
0675