2 * This file is part of the DOM implementation for KDE.
4 * Copyright 1999 Lars Knoll (knoll@kde.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include "dom/css_rule.h"
24 #include "dom/dom_exception.h"
26 #include "css/css_renderstyledeclarationimpl.h"
27 #include "css/css_valueimpl.h"
31 CSSStyleDeclaration::CSSStyleDeclaration()
36 CSSStyleDeclaration::CSSStyleDeclaration(const CSSStyleDeclaration
&other
)
42 CSSStyleDeclaration::CSSStyleDeclaration(CSSStyleDeclarationImpl
*i
)
48 CSSStyleDeclaration
&CSSStyleDeclaration::operator = (const CSSStyleDeclaration
&other
)
50 if ( impl
!= other
.impl
) {
51 if(impl
) impl
->deref();
58 CSSStyleDeclaration::~CSSStyleDeclaration()
60 if(impl
) impl
->deref();
63 DOMString
CSSStyleDeclaration::cssText() const
65 if(!impl
) return DOMString();
66 return static_cast<CSSStyleDeclarationImpl
*>(impl
)->cssText();
69 void CSSStyleDeclaration::setCssText( const DOMString
&value
)
72 impl
->setCssText(value
);
75 DOMString
CSSStyleDeclaration::getPropertyValue( const DOMString
&propertyName
) const
77 if(!impl
) return DOMString();
78 return static_cast<CSSStyleDeclarationImpl
*>(impl
)->getPropertyValue(propertyName
);
81 CSSValue
CSSStyleDeclaration::getPropertyCSSValue( const DOMString
&propertyName
) const
84 return static_cast<CSSStyleDeclarationImpl
*>(impl
)->getPropertyCSSValue(propertyName
);
87 DOMString
CSSStyleDeclaration::removeProperty( const DOMString
&propertyName
)
89 if(!impl
) return DOMString();
90 return static_cast<CSSStyleDeclarationImpl
*>(impl
)->removeProperty(propertyName
);
93 DOMString
CSSStyleDeclaration::getPropertyPriority( const DOMString
&propertyName
) const
95 if(!impl
) return DOMString();
96 return impl
->getPropertyPriority(propertyName
);
99 void CSSStyleDeclaration::setProperty( const DOMString
&propName
, const DOMString
&value
, const DOMString
&priority
)
102 static_cast<CSSStyleDeclarationImpl
*>(impl
)->setProperty( propName
, value
, priority
);
105 unsigned long CSSStyleDeclaration::length() const
108 return static_cast<CSSStyleDeclarationImpl
*>(impl
)->length();
111 DOMString
CSSStyleDeclaration::item( unsigned long index
)
113 return const_cast<const CSSStyleDeclaration
*>( this )->item( index
);
116 DOMString
CSSStyleDeclaration::item( unsigned long index
) const
118 if(!impl
) return DOMString();
119 return static_cast<CSSStyleDeclarationImpl
*>(impl
)->item( index
);
121 CSSRule
CSSStyleDeclaration::parentRule() const
124 return static_cast<CSSStyleDeclarationImpl
*>(impl
)->parentRule();
127 CSSStyleDeclarationImpl
*CSSStyleDeclaration::handle() const
132 bool CSSStyleDeclaration::isNull() const
137 // ----------------------------------------------------------
144 CSSValue::CSSValue(const CSSValue
&other
)
147 if(impl
) impl
->ref();
150 CSSValue::CSSValue(CSSValueImpl
*i
)
153 if(impl
) impl
->ref();
156 CSSValue
&CSSValue::operator = (const CSSValue
&other
)
158 if ( impl
!= other
.impl
) {
159 if(impl
) impl
->deref();
161 if(impl
) impl
->ref();
166 CSSValue::~CSSValue()
168 if(impl
) impl
->deref();
171 DOMString
CSSValue::cssText() const
173 if(!impl
) return DOMString();
174 return ((CSSValueImpl
*)impl
)->cssText();
177 void CSSValue::setCssText(const DOMString
&value
)
180 ((CSSValueImpl
*)impl
)->setCssText(value
);
183 unsigned short CSSValue::cssValueType() const
186 return ((CSSValueImpl
*)impl
)->cssValueType();
189 bool CSSValue::isCSSValueList() const
191 if(!impl
) return false;
192 return ((CSSValueImpl
*)impl
)->isValueList();
195 bool CSSValue::isCSSPrimitiveValue() const
197 if(!impl
) return false;
198 return ((CSSValueImpl
*)impl
)->isPrimitiveValue();
201 CSSValueImpl
*CSSValue::handle() const
206 bool CSSValue::isNull() const
211 // ----------------------------------------------------------
213 CSSValueList::CSSValueList() : CSSValue()
217 CSSValueList::CSSValueList(const CSSValueList
&other
) : CSSValue(other
)
221 CSSValueList::CSSValueList(const CSSValue
&other
)
227 CSSValueList::CSSValueList(CSSValueListImpl
*impl
) : CSSValue(impl
)
231 CSSValueList
&CSSValueList::operator = (const CSSValueList
&other
)
233 if ( impl
!= other
.impl
) {
234 if (impl
) impl
->deref();
235 impl
= other
.handle();
236 if (impl
) impl
->ref();
241 CSSValueList
&CSSValueList::operator = (const CSSValue
&other
)
243 CSSValueImpl
*ohandle
= other
.handle() ;
244 if ( impl
!= ohandle
) {
245 if (impl
) impl
->deref();
246 if (!other
.isNull() && !other
.isCSSValueList()) {
250 if (impl
) impl
->ref();
256 CSSValueList::~CSSValueList()
260 unsigned long CSSValueList::length() const
263 return ((CSSValueListImpl
*)impl
)->length();
266 CSSValue
CSSValueList::item( unsigned long index
)
269 return ((CSSValueListImpl
*)impl
)->item( index
);
272 // ----------------------------------------------------------
274 CSSPrimitiveValue::CSSPrimitiveValue() : CSSValue()
278 CSSPrimitiveValue::CSSPrimitiveValue(const CSSPrimitiveValue
&other
) : CSSValue(other
)
282 CSSPrimitiveValue::CSSPrimitiveValue(const CSSValue
&other
) : CSSValue(other
)
288 CSSPrimitiveValue::CSSPrimitiveValue(CSSPrimitiveValueImpl
*impl
) : CSSValue(impl
)
292 CSSPrimitiveValue
&CSSPrimitiveValue::operator = (const CSSPrimitiveValue
&other
)
294 if ( impl
!= other
.impl
) {
295 if (impl
) impl
->deref();
296 impl
= other
.handle();
297 if (impl
) impl
->ref();
302 CSSPrimitiveValue
&CSSPrimitiveValue::operator = (const CSSValue
&other
)
304 CSSValueImpl
*ohandle
= other
.handle();
305 if ( impl
!= ohandle
) {
306 if (impl
) impl
->deref();
307 if (!other
.isNull() && !other
.isCSSPrimitiveValue()) {
311 if (impl
) impl
->ref();
317 CSSPrimitiveValue::~CSSPrimitiveValue()
321 unsigned short CSSPrimitiveValue::primitiveType() const
324 return ((CSSPrimitiveValueImpl
*)impl
)->primitiveType();
327 void CSSPrimitiveValue::setFloatValue( unsigned short unitType
, float floatValue
)
330 int exceptioncode
= 0;
331 ((CSSPrimitiveValueImpl
*)impl
)->setFloatValue( unitType
, floatValue
, exceptioncode
);
332 if ( exceptioncode
>= CSSException::_EXCEPTION_OFFSET
)
333 throw CSSException( exceptioncode
- CSSException::_EXCEPTION_OFFSET
);
335 throw DOMException( exceptioncode
);
338 float CSSPrimitiveValue::getFloatValue( unsigned short unitType
) const
341 // ### add unit conversion
342 if(primitiveType() != unitType
)
343 throw CSSException(CSSException::SYNTAX_ERR
);
344 return ((CSSPrimitiveValueImpl
*)impl
)->floatValue( unitType
);
347 void CSSPrimitiveValue::setStringValue( unsigned short stringType
, const DOMString
&stringValue
)
349 int exceptioncode
= 0;
351 ((CSSPrimitiveValueImpl
*)impl
)->setStringValue( stringType
, stringValue
, exceptioncode
);
352 if ( exceptioncode
>= CSSException::_EXCEPTION_OFFSET
)
353 throw CSSException( exceptioncode
- CSSException::_EXCEPTION_OFFSET
);
355 throw DOMException( exceptioncode
);
359 DOMString
CSSPrimitiveValue::getStringValue( ) const
361 if(!impl
) return DOMString();
362 return ((CSSPrimitiveValueImpl
*)impl
)->getStringValue( );
365 Counter
CSSPrimitiveValue::getCounterValue( ) const
367 if(!impl
) return Counter();
368 return ((CSSPrimitiveValueImpl
*)impl
)->getCounterValue( );
371 Rect
CSSPrimitiveValue::getRectValue( ) const
373 if(!impl
) return Rect();
374 return ((CSSPrimitiveValueImpl
*)impl
)->getRectValue( );
377 RGBColor
CSSPrimitiveValue::getRGBColorValue( ) const
381 //if(!impl) return RGBColor();
382 //return ((CSSPrimitiveValueImpl *)impl)->getRGBColorValue( );
385 // -------------------------------------------------------------------
391 Counter::Counter(const Counter
&/*other*/)
396 Counter
&Counter::operator = (const Counter
&other
)
398 if ( impl
!= other
.impl
) {
399 if (impl
) impl
->deref();
401 if (impl
) impl
->ref();
406 Counter::Counter(CounterImpl
*i
)
409 if (impl
) impl
->ref();
414 if (impl
) impl
->deref();
417 DOMString
Counter::identifier() const
419 if (!impl
) return DOMString();
420 return impl
->identifier();
423 DOMString
Counter::listStyle() const
425 if (!impl
) return DOMString();
426 return khtml::stringForListStyleType((khtml::EListStyleType
)impl
->listStyle());
429 DOMString
Counter::separator() const
431 if (!impl
) return DOMString();
432 return impl
->separator();
435 CounterImpl
*Counter::handle() const
440 bool Counter::isNull() const
445 // --------------------------------------------------------------------
451 RGBColor::RGBColor(const RGBColor
&other
)
453 m_color
= other
.m_color
;
456 RGBColor::RGBColor(QRgb color
)
461 RGBColor
&RGBColor::operator = (const RGBColor
&other
)
463 m_color
= other
.m_color
;
467 RGBColor::~RGBColor()
471 CSSPrimitiveValue
RGBColor::red() const
473 return new CSSPrimitiveValueImpl(float(qAlpha(m_color
) ? qRed(m_color
) : 0), CSSPrimitiveValue::CSS_DIMENSION
);
476 CSSPrimitiveValue
RGBColor::green() const
478 return new CSSPrimitiveValueImpl(float(qAlpha(m_color
) ? qGreen(m_color
) : 0), CSSPrimitiveValue::CSS_DIMENSION
);
481 CSSPrimitiveValue
RGBColor::blue() const
483 return new CSSPrimitiveValueImpl(float(qAlpha(m_color
) ? qBlue(m_color
) : 0), CSSPrimitiveValue::CSS_DIMENSION
);
487 // ---------------------------------------------------------------------
494 Rect::Rect(const Rect
&other
)
497 if (impl
) impl
->ref();
500 Rect::Rect(RectImpl
*i
)
503 if (impl
) impl
->ref();
506 Rect
&Rect::operator = (const Rect
&other
)
508 if ( impl
!= other
.impl
) {
509 if (impl
) impl
->deref();
511 if (impl
) impl
->ref();
518 if (impl
) impl
->deref();
521 CSSPrimitiveValue
Rect::top() const
527 CSSPrimitiveValue
Rect::right() const
530 return impl
->right();
533 CSSPrimitiveValue
Rect::bottom() const
536 return impl
->bottom();
539 CSSPrimitiveValue
Rect::left() const
545 RectImpl
*Rect::handle() const
550 bool Rect::isNull() const