2 * This file is part of the DOM implementation for KDE.
4 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
5 * Copyright (C) 2002 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include "dom/css_value.h"
24 #include "dom/dom_exception.h"
25 #include "dom/dom_string.h"
27 #include "css/css_valueimpl.h"
28 #include "css/css_ruleimpl.h"
29 #include "css/css_stylesheetimpl.h"
30 #include "css/cssparser.h"
31 #include "css/cssproperties.h"
32 #include "css/cssvalues.h"
33 #include "css/cssstyleselector.h"
35 #include "xml/dom_stringimpl.h"
36 #include "xml/dom_docimpl.h"
38 #include "misc/loader.h"
40 #include "rendering/font.h"
41 #include "rendering/render_style.h"
45 #include <qpaintdevice.h>
46 #include <qpaintdevicemetrics.h>
48 // Hack for debugging purposes
49 extern DOM::DOMString getPropertyName(unsigned short id);
52 using khtml::CSSStyleSelector;
56 CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent)
57 : StyleBaseImpl(parent)
63 CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent, QPtrList<CSSProperty> *lstValues)
64 : StyleBaseImpl(parent)
66 m_lstValues = lstValues;
70 CSSStyleDeclarationImpl& CSSStyleDeclarationImpl::operator= (const CSSStyleDeclarationImpl& o)
72 // don't attach it to the same node, just leave the current m_node value
76 m_lstValues = new QPtrList<CSSProperty>;
77 m_lstValues->setAutoDelete( true );
79 QPtrListIterator<CSSProperty> lstValuesIt(*o.m_lstValues);
80 for (lstValuesIt.toFirst(); lstValuesIt.current(); ++lstValuesIt)
81 m_lstValues->append(new CSSProperty(*lstValuesIt.current()));
87 CSSStyleDeclarationImpl::~CSSStyleDeclarationImpl()
90 // we don't use refcounting for m_node, to avoid cyclic references (see ElementImpl)
93 DOMString CSSStyleDeclarationImpl::getPropertyValue( int propertyID ) const
95 if(!m_lstValues) return DOMString();
97 CSSValueImpl* value = getPropertyCSSValue( propertyID );
99 return value->cssText();
101 // Shorthand and 4-values properties
102 switch ( propertyID ) {
103 case CSS_PROP_BACKGROUND_POSITION:
105 // ## Is this correct? The code in cssparser.cpp is confusing
106 const int properties[2] = { CSS_PROP_BACKGROUND_POSITION_X,
107 CSS_PROP_BACKGROUND_POSITION_Y };
108 return getShortHandValue( properties, 2 );
110 case CSS_PROP_BACKGROUND:
112 const int properties[5] = { CSS_PROP_BACKGROUND_IMAGE, CSS_PROP_BACKGROUND_REPEAT,
113 CSS_PROP_BACKGROUND_ATTACHMENT, CSS_PROP_BACKGROUND_POSITION,
114 CSS_PROP_BACKGROUND_COLOR };
115 return getShortHandValue( properties, 5 );
117 case CSS_PROP_BORDER:
119 const int properties[3] = { CSS_PROP_BORDER_WIDTH, CSS_PROP_BORDER_STYLE,
120 CSS_PROP_BORDER_COLOR };
121 return getShortHandValue( properties, 3 );
123 case CSS_PROP_BORDER_TOP:
125 const int properties[3] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_TOP_STYLE,
126 CSS_PROP_BORDER_TOP_COLOR};
127 return getShortHandValue( properties, 3 );
129 case CSS_PROP_BORDER_RIGHT:
131 const int properties[3] = { CSS_PROP_BORDER_RIGHT_WIDTH, CSS_PROP_BORDER_RIGHT_STYLE,
132 CSS_PROP_BORDER_RIGHT_COLOR};
133 return getShortHandValue( properties, 3 );
135 case CSS_PROP_BORDER_BOTTOM:
137 const int properties[3] = { CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_BOTTOM_STYLE,
138 CSS_PROP_BORDER_BOTTOM_COLOR};
139 return getShortHandValue( properties, 3 );
141 case CSS_PROP_BORDER_LEFT:
143 const int properties[3] = { CSS_PROP_BORDER_LEFT_WIDTH, CSS_PROP_BORDER_LEFT_STYLE,
144 CSS_PROP_BORDER_LEFT_COLOR};
145 return getShortHandValue( properties, 3 );
147 case CSS_PROP_OUTLINE:
149 const int properties[3] = { CSS_PROP_OUTLINE_WIDTH, CSS_PROP_OUTLINE_STYLE,
150 CSS_PROP_OUTLINE_COLOR };
151 return getShortHandValue( properties, 3 );
153 case CSS_PROP_BORDER_COLOR:
155 const int properties[4] = { CSS_PROP_BORDER_TOP_COLOR, CSS_PROP_BORDER_RIGHT_COLOR,
156 CSS_PROP_BORDER_BOTTOM_COLOR, CSS_PROP_BORDER_LEFT_COLOR };
157 return get4Values( properties );
159 case CSS_PROP_BORDER_WIDTH:
161 const int properties[4] = { CSS_PROP_BORDER_TOP_WIDTH, CSS_PROP_BORDER_RIGHT_WIDTH,
162 CSS_PROP_BORDER_BOTTOM_WIDTH, CSS_PROP_BORDER_LEFT_WIDTH };
163 return get4Values( properties );
165 case CSS_PROP_BORDER_STYLE:
167 const int properties[4] = { CSS_PROP_BORDER_TOP_STYLE, CSS_PROP_BORDER_RIGHT_STYLE,
168 CSS_PROP_BORDER_BOTTOM_STYLE, CSS_PROP_BORDER_LEFT_STYLE };
169 return get4Values( properties );
171 case CSS_PROP_MARGIN:
173 const int properties[4] = { CSS_PROP_MARGIN_TOP, CSS_PROP_MARGIN_RIGHT,
174 CSS_PROP_MARGIN_BOTTOM, CSS_PROP_MARGIN_LEFT };
175 return get4Values( properties );
177 case CSS_PROP_PADDING:
179 const int properties[4] = { CSS_PROP_PADDING_TOP, CSS_PROP_PADDING_RIGHT,
180 CSS_PROP_PADDING_BOTTOM, CSS_PROP_PADDING_LEFT };
181 return get4Values( properties );
183 case CSS_PROP_LIST_STYLE:
185 const int properties[3] = { CSS_PROP_LIST_STYLE_TYPE, CSS_PROP_LIST_STYLE_POSITION,
186 CSS_PROP_LIST_STYLE_IMAGE };
187 return getShortHandValue( properties, 3 );
190 //kdDebug() << k_funcinfo << "property not found:" << propertyID << endl;
194 DOMString CSSStyleDeclarationImpl::get4Values( const int* properties ) const
197 for ( int i = 0 ; i < 4 ; ++i ) {
198 CSSValueImpl* value = getPropertyCSSValue( properties[i] );
199 if ( !value ) { // apparently all 4 properties must be specified.
204 res += value->cssText();
209 DOMString CSSStyleDeclarationImpl::getShortHandValue( const int* properties, int number ) const
212 for ( int i = 0 ; i < number ; ++i ) {
213 CSSValueImpl* value = getPropertyCSSValue( properties[i] );
214 if ( value ) { // TODO provide default value if !value
217 res += value->cssText();
223 CSSValueImpl *CSSStyleDeclarationImpl::getPropertyCSSValue( int propertyID ) const
225 if(!m_lstValues) return 0;
227 QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
228 CSSProperty *current;
229 for ( lstValuesIt.toLast(); (current = lstValuesIt.current()); --lstValuesIt )
230 if (current->m_id == propertyID)
231 return current->value();
235 DOMString CSSStyleDeclarationImpl::removeProperty(int propertyID, bool notifyChanged)
237 if(!m_lstValues) return DOMString();
240 QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
241 CSSProperty *current;
242 for ( lstValuesIt.toLast(); (current = lstValuesIt.current()); --lstValuesIt )
243 if (current->m_id == propertyID) {
244 value = current->value()->cssText();
245 m_lstValues->removeRef(current);
254 void CSSStyleDeclarationImpl::setChanged()
257 m_node->setChanged();
261 // ### quick&dirty hack for KDE 3.0... make this MUCH better! (Dirk)
262 for (StyleBaseImpl* stylesheet = this; stylesheet; stylesheet = stylesheet->parent())
263 if (stylesheet->isCSSStyleSheet()) {
264 static_cast<CSSStyleSheetImpl*>(stylesheet)->doc()->updateStyleSelector();
269 bool CSSStyleDeclarationImpl::getPropertyPriority( int propertyID ) const
272 QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
273 CSSProperty *current;
274 for ( lstValuesIt.toFirst(); (current = lstValuesIt.current()); ++lstValuesIt ) {
275 if( propertyID == current->m_id )
276 return current->m_bImportant;
282 bool CSSStyleDeclarationImpl::setProperty(int id, const DOMString &value, bool important, bool notifyChanged)
285 m_lstValues = new QPtrList<CSSProperty>;
286 m_lstValues->setAutoDelete(true);
290 CSSParser parser( strictParsing );
291 bool success = parser.parseValue(this, id, value, important);
293 kdDebug( 6080 ) << "CSSStyleDeclarationImpl::setProperty invalid property: [" << getPropertyName(id).string()
294 << "] value: [" << value.string() << "]"<< endl;
295 else if (notifyChanged)
300 void CSSStyleDeclarationImpl::setProperty(int id, int value, bool important, bool notifyChanged)
303 m_lstValues = new QPtrList<CSSProperty>;
304 m_lstValues->setAutoDelete(true);
308 CSSValueImpl * cssValue = new CSSPrimitiveValueImpl(value);
309 setParsedValue(id, cssValue, important, m_lstValues);
314 void CSSStyleDeclarationImpl::setStringProperty(int propertyId, const DOMString &value, CSSPrimitiveValue::UnitTypes type, bool important)
317 m_lstValues = new QPtrList<CSSProperty>;
318 m_lstValues->setAutoDelete(true);
320 removeProperty(propertyId);
321 setParsedValue(propertyId, new CSSPrimitiveValueImpl(value, type), important, m_lstValues);
325 void CSSStyleDeclarationImpl::setImageProperty(int propertyId, const DOMString &URL, bool important)
328 m_lstValues = new QPtrList<CSSProperty>;
329 m_lstValues->setAutoDelete(true);
331 removeProperty(propertyId);
332 setParsedValue(propertyId, new CSSImageValueImpl(URL, this), important, m_lstValues);
336 void CSSStyleDeclarationImpl::setProperty ( const DOMString &propertyString)
339 m_lstValues = new QPtrList<CSSProperty>;
340 m_lstValues->setAutoDelete( true );
343 CSSParser parser(strictParsing);
344 parser.parseDeclaration(this, propertyString);
348 void CSSStyleDeclarationImpl::setLengthProperty(int id, const DOM::DOMString &value, bool important, bool _multiLength )
350 bool parseMode = strictParsing;
351 strictParsing = false;
352 multiLength = _multiLength;
353 setProperty( id, value, important);
354 strictParsing = parseMode;
358 unsigned long CSSStyleDeclarationImpl::length() const
360 return m_lstValues ? m_lstValues->count() : 0;
363 DOMString CSSStyleDeclarationImpl::item( unsigned long /*index*/ )
366 //return m_lstValues->at(index);
370 CSSRuleImpl *CSSStyleDeclarationImpl::parentRule() const
372 return (m_parent && m_parent->isRule() ) ?
373 static_cast<CSSRuleImpl *>(m_parent) : 0;
376 DOM::DOMString CSSStyleDeclarationImpl::cssText() const
381 QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
382 CSSProperty *current;
383 for ( lstValuesIt.toFirst(); (current = lstValuesIt.current()); ++lstValuesIt )
384 result += current->cssText();
390 void CSSStyleDeclarationImpl::setCssText(const DOM::DOMString& text)
393 m_lstValues->clear();
395 m_lstValues = new QPtrList<CSSProperty>;
396 m_lstValues->setAutoDelete(true);
399 CSSParser parser(strictParsing);
400 parser.parseDeclaration(this, text);
404 bool CSSStyleDeclarationImpl::parseString( const DOMString &/*string*/, bool )
410 void CSSStyleDeclarationImpl::merge(CSSStyleDeclarationImpl *other, bool argOverridesOnConflict)
412 for (QPtrListIterator<CSSProperty> it(*(other->values())); it.current(); ++it) {
413 CSSProperty *property = it.current();
414 if (getPropertyCSSValue(property->id())) {
415 if (!argOverridesOnConflict)
417 removeProperty(property->id());
420 m_lstValues = new QPtrList<CSSProperty>;
421 m_lstValues->setAutoDelete(true);
423 m_lstValues->append(new CSSProperty(*property));
427 // --------------------------------------------------------------------------------------
429 CSSValueImpl::CSSValueImpl()
434 CSSValueImpl::~CSSValueImpl()
438 unsigned short CSSInheritedValueImpl::cssValueType() const
440 return CSSValue::CSS_INHERIT;
443 DOM::DOMString CSSInheritedValueImpl::cssText() const
445 return DOMString("inherit");
448 unsigned short CSSInitialValueImpl::cssValueType() const
450 return CSSValue::CSS_INITIAL;
453 DOM::DOMString CSSInitialValueImpl::cssText() const
455 return DOMString("initial");
458 // ----------------------------------------------------------------------------------------
460 CSSValueListImpl::CSSValueListImpl()
465 CSSValueListImpl::~CSSValueListImpl()
467 CSSValueImpl *val = m_values.first();
470 val = m_values.next();
474 unsigned short CSSValueListImpl::cssValueType() const
476 return CSSValue::CSS_VALUE_LIST;
479 void CSSValueListImpl::append(CSSValueImpl *val)
481 m_values.append(val);
485 DOM::DOMString CSSValueListImpl::cssText() const
487 DOMString result = "";
489 for (QPtrListIterator<CSSValueImpl> iterator(m_values); iterator.current(); ++iterator) {
490 if (result.length() != 0) {
493 result += iterator.current()->cssText();
499 // -------------------------------------------------------------------------------------
501 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl()
507 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(int ident)
510 m_value.ident = ident;
511 m_type = CSSPrimitiveValue::CSS_IDENT;
514 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type)
520 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(const DOMString &str, CSSPrimitiveValue::UnitTypes type)
522 m_value.string = str.implementation();
523 if(m_value.string) m_value.string->ref();
527 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(const Counter &c)
529 m_value.counter = c.handle();
531 m_value.counter->ref();
532 m_type = CSSPrimitiveValue::CSS_COUNTER;
535 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl( RectImpl *r)
540 m_type = CSSPrimitiveValue::CSS_RECT;
543 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl( DashboardRegionImpl *r)
547 m_value.region->ref();
548 m_type = CSSPrimitiveValue::CSS_DASHBOARD_REGION;
551 CSSPrimitiveValueImpl::CSSPrimitiveValueImpl(QRgb color)
553 m_value.rgbcolor = color;
554 m_type = CSSPrimitiveValue::CSS_RGBCOLOR;
557 CSSPrimitiveValueImpl::~CSSPrimitiveValueImpl()
562 void CSSPrimitiveValueImpl::cleanup()
565 case CSSPrimitiveValue::CSS_STRING:
566 case CSSPrimitiveValue::CSS_URI:
567 case CSSPrimitiveValue::CSS_ATTR:
568 if(m_value.string) m_value.string->deref();
570 case CSSPrimitiveValue::CSS_COUNTER:
571 m_value.counter->deref();
573 case CSSPrimitiveValue::CSS_RECT:
574 m_value.rect->deref();
582 int CSSPrimitiveValueImpl::computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics )
584 double result = computeLengthFloat( style, devMetrics );
586 // This conversion is imprecise, often resulting in values of, e.g., 44.99998. We
587 // need to go ahead and round if we're really close to the next integer value.
588 int intResult = (int)(result + (result < 0 ? -0.01 : +0.01));
590 int intResult = (int)result;
595 int CSSPrimitiveValueImpl::computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics,
598 double result = multiplier * computeLengthFloat( style, devMetrics );
600 // This conversion is imprecise, often resulting in values of, e.g., 44.99998. We
601 // need to go ahead and round if we're really close to the next integer value.
602 int intResult = (int)(result + (result < 0 ? -0.01 : +0.01));
604 int intResult = (int)result;
609 double CSSPrimitiveValueImpl::computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics,
610 bool applyZoomFactor )
612 unsigned short type = primitiveType();
614 double dpiY = 72.; // fallback
616 dpiY = devMetrics->logicalDpiY();
617 if ( !khtml::printpainter && dpiY < 96 )
623 case CSSPrimitiveValue::CSS_EMS:
624 factor = applyZoomFactor ?
625 style->htmlFont().getFontDef().computedSize :
626 style->htmlFont().getFontDef().specifiedSize;
628 case CSSPrimitiveValue::CSS_EXS:
629 // FIXME: We have a bug right now where the zoom will be applied multiple times to EX units.
630 // We really need to compute EX using fontMetrics for the original specifiedSize and not use
631 // our actual constructed rendering font.
633 QFontMetrics fm = style->fontMetrics();
635 factor = fm.xHeight();
637 QRect b = fm.boundingRect('x');
642 case CSSPrimitiveValue::CSS_PX:
644 case CSSPrimitiveValue::CSS_CM:
645 factor = dpiY/2.54; //72dpi/(2.54 cm/in)
647 case CSSPrimitiveValue::CSS_MM:
650 case CSSPrimitiveValue::CSS_IN:
653 case CSSPrimitiveValue::CSS_PT:
656 case CSSPrimitiveValue::CSS_PC:
658 factor = dpiY*12./72.;
664 return getFloatValue(type)*factor;
667 void CSSPrimitiveValueImpl::setFloatValue( unsigned short unitType, double floatValue, int &exceptioncode )
671 // ### check if property supports this type
672 if(m_type > CSSPrimitiveValue::CSS_DIMENSION) {
673 exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET;
676 //if(m_type > CSSPrimitiveValue::CSS_DIMENSION) throw DOMException(DOMException::INVALID_ACCESS_ERR);
677 m_value.num = floatValue;
681 void CSSPrimitiveValueImpl::setStringValue( unsigned short stringType, const DOMString &stringValue, int &exceptioncode )
685 //if(m_type < CSSPrimitiveValue::CSS_STRING) throw DOMException(DOMException::INVALID_ACCESS_ERR);
686 //if(m_type > CSSPrimitiveValue::CSS_ATTR) throw DOMException(DOMException::INVALID_ACCESS_ERR);
687 if(m_type < CSSPrimitiveValue::CSS_STRING || m_type >> CSSPrimitiveValue::CSS_ATTR) {
688 exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET;
691 if(stringType != CSSPrimitiveValue::CSS_IDENT)
693 m_value.string = stringValue.implementation();
694 m_value.string->ref();
700 DOMString CSSPrimitiveValueImpl::getStringValue() const
703 case CSSPrimitiveValue::CSS_STRING:
704 case CSSPrimitiveValue::CSS_ATTR:
705 case CSSPrimitiveValue::CSS_URI:
706 return m_value.string;
707 case CSSPrimitiveValue::CSS_IDENT:
708 return getValueName(m_value.ident);
710 // FIXME: The CSS 2.1 spec says you should throw an exception here.
717 unsigned short CSSPrimitiveValueImpl::cssValueType() const
719 return CSSValue::CSS_PRIMITIVE_VALUE;
722 bool CSSPrimitiveValueImpl::parseString( const DOMString &/*string*/, bool )
728 int CSSPrimitiveValueImpl::getIdent()
730 if(m_type != CSSPrimitiveValue::CSS_IDENT) return 0;
731 return m_value.ident;
734 DOM::DOMString CSSPrimitiveValueImpl::cssText() const
736 // ### return the original value instead of a generated one (e.g. color
737 // name if it was specified) - check what spec says about this
740 case CSSPrimitiveValue::CSS_UNKNOWN:
743 case CSSPrimitiveValue::CSS_NUMBER:
744 text = DOMString(QString::number( (int)m_value.num ));
746 case CSSPrimitiveValue::CSS_PERCENTAGE:
747 text = DOMString(QString::number( m_value.num ) + "%");
749 case CSSPrimitiveValue::CSS_EMS:
750 text = DOMString(QString::number( m_value.num ) + "em");
752 case CSSPrimitiveValue::CSS_EXS:
753 text = DOMString(QString::number( m_value.num ) + "ex");
755 case CSSPrimitiveValue::CSS_PX:
756 text = DOMString(QString::number( m_value.num ) + "px");
758 case CSSPrimitiveValue::CSS_CM:
759 text = DOMString(QString::number( m_value.num ) + "cm");
761 case CSSPrimitiveValue::CSS_MM:
762 text = DOMString(QString::number( m_value.num ) + "mm");
764 case CSSPrimitiveValue::CSS_IN:
765 text = DOMString(QString::number( m_value.num ) + "in");
767 case CSSPrimitiveValue::CSS_PT:
768 text = DOMString(QString::number( m_value.num ) + "pt");
770 case CSSPrimitiveValue::CSS_PC:
771 text = DOMString(QString::number( m_value.num ) + "pc");
773 case CSSPrimitiveValue::CSS_DEG:
774 text = DOMString(QString::number( m_value.num ) + "deg");
776 case CSSPrimitiveValue::CSS_RAD:
777 text = DOMString(QString::number( m_value.num ) + "rad");
779 case CSSPrimitiveValue::CSS_GRAD:
780 text = DOMString(QString::number( m_value.num ) + "grad");
782 case CSSPrimitiveValue::CSS_MS:
783 text = DOMString(QString::number( m_value.num ) + "ms");
785 case CSSPrimitiveValue::CSS_S:
786 text = DOMString(QString::number( m_value.num ) + "s");
788 case CSSPrimitiveValue::CSS_HZ:
789 text = DOMString(QString::number( m_value.num ) + "hz");
791 case CSSPrimitiveValue::CSS_KHZ:
792 text = DOMString(QString::number( m_value.num ) + "khz");
794 case CSSPrimitiveValue::CSS_DIMENSION:
797 case CSSPrimitiveValue::CSS_STRING:
798 text = DOMString(m_value.string);
800 case CSSPrimitiveValue::CSS_URI:
802 text += DOMString( m_value.string );
805 case CSSPrimitiveValue::CSS_IDENT:
806 text = getValueName(m_value.ident);
808 case CSSPrimitiveValue::CSS_ATTR:
811 case CSSPrimitiveValue::CSS_COUNTER:
814 case CSSPrimitiveValue::CSS_RECT: {
815 RectImpl* rectVal = getRectValue();
817 text += rectVal->top()->cssText() + " ";
818 text += rectVal->right()->cssText() + " ";
819 text += rectVal->bottom()->cssText() + " ";
820 text += rectVal->left()->cssText() + ")";
823 case CSSPrimitiveValue::CSS_RGBCOLOR: {
824 QColor color(m_value.rgbcolor);
825 if (qAlpha(m_value.rgbcolor) < 0xFF)
829 text += QString::number(color.red()) + ", ";
830 text += QString::number(color.green()) + ", ";
831 text += QString::number(color.blue());
832 if (qAlpha(m_value.rgbcolor) < 0xFF)
833 text += ", " + QString::number((float)qAlpha(m_value.rgbcolor) / 0xFF);
838 case CSSPrimitiveValue::CSS_DASHBOARD_REGION: {
839 DashboardRegionImpl *region = getDashboardRegionValue();
841 text = "dashboard-region(";
842 text += region->m_label;
843 if (region->m_isCircle){
846 else if (region->m_isRectangle){
847 text += " rectangle ";
851 text += region->top()->cssText() + " ";
852 text += region->right()->cssText() + " ";
853 text += region->bottom()->cssText() + " ";
854 text += region->left()->cssText();
856 region = region->m_next;
865 // -----------------------------------------------------------------
875 RectImpl::~RectImpl()
877 if (m_top) m_top->deref();
878 if (m_right) m_right->deref();
879 if (m_bottom) m_bottom->deref();
880 if (m_left) m_left->deref();
883 void RectImpl::setTop( CSSPrimitiveValueImpl *top )
885 if( top ) top->ref();
886 if ( m_top ) m_top->deref();
890 void RectImpl::setRight( CSSPrimitiveValueImpl *right )
892 if( right ) right->ref();
893 if ( m_right ) m_right->deref();
897 void RectImpl::setBottom( CSSPrimitiveValueImpl *bottom )
899 if( bottom ) bottom->ref();
900 if ( m_bottom ) m_bottom->deref();
904 void RectImpl::setLeft( CSSPrimitiveValueImpl *left )
906 if( left ) left->ref();
907 if ( m_left ) m_left->deref();
911 // -----------------------------------------------------------------
913 CSSImageValueImpl::CSSImageValueImpl(const DOMString &url, StyleBaseImpl *style)
914 : CSSPrimitiveValueImpl(url, CSSPrimitiveValue::CSS_URI), m_image(0), m_accessedImage(false)
918 CSSImageValueImpl::CSSImageValueImpl()
919 : CSSPrimitiveValueImpl(CSS_VAL_NONE), m_image(0), m_accessedImage(true)
923 CSSImageValueImpl::~CSSImageValueImpl()
925 if(m_image) m_image->deref(this);
928 khtml::CachedImage* CSSImageValueImpl::image(khtml::DocLoader* loader)
930 if (!m_accessedImage) {
931 m_accessedImage = true;
934 m_image = loader->requestImage(getStringValue());
936 m_image = khtml::Cache::requestImage(0, getStringValue());
938 if(m_image) m_image->ref(this);
944 // ------------------------------------------------------------------------
946 FontFamilyValueImpl::FontFamilyValueImpl( const QString &string)
947 : CSSPrimitiveValueImpl( DOMString(), CSSPrimitiveValue::CSS_STRING)
949 static const QRegExp parenReg(" \\(.*\\)$");
950 static const QRegExp braceReg(" \\[.*\\]$");
953 parsedFontName = string;
954 // a language tag is often added in braces at the end. Remove it.
955 parsedFontName.replace(parenReg, "");
956 // remove [Xft] qualifiers
957 parsedFontName.replace(braceReg, "");
959 const QString &available = KHTMLSettings::availableFamilies();
961 QString face = string.lower();
962 // a languge tag is often added in braces at the end. Remove it.
963 face = face.replace(parenReg, "");
964 // remove [Xft] qualifiers
965 face = face.replace(braceReg, "");
966 //kdDebug(0) << "searching for face '" << face << "'" << endl;
968 int pos = available.find( face, 0, false );
971 int p = face.find(' ');
972 // Arial Blk --> Arial
973 // MS Sans Serif --> Sans Serif
975 if(p > 0 && (int)str.length() - p > p + 1)
976 str = str.mid( p+1 );
979 pos = available.find( str, 0, false);
984 int pos1 = available.findRev( ',', pos ) + 1;
985 pos = available.find( ',', pos );
987 pos = available.length();
988 parsedFontName = available.mid( pos1, pos - pos1 );
990 #endif // !APPLE_CHANGES
993 DOM::DOMString FontFamilyValueImpl::cssText() const
995 return parsedFontName;
998 FontValueImpl::FontValueImpl()
999 : style(0), variant(0), weight(0), size(0), lineHeight(0), family(0)
1003 FontValueImpl::~FontValueImpl()
1013 DOMString FontValueImpl::cssText() const
1015 // font variant weight size / line-height family
1017 DOMString result("");
1020 result += style->cssText();
1023 if (result.length() > 0) {
1026 result += variant->cssText();
1029 if (result.length() > 0) {
1032 result += weight->cssText();
1035 if (result.length() > 0) {
1038 result += size->cssText();
1045 result += lineHeight->cssText();
1048 if (result.length() > 0) {
1051 result += family->cssText();
1058 // Used for text-shadow and box-shadow
1059 ShadowValueImpl::ShadowValueImpl(CSSPrimitiveValueImpl* _x, CSSPrimitiveValueImpl* _y,
1060 CSSPrimitiveValueImpl* _blur, CSSPrimitiveValueImpl* _color)
1061 :x(_x), y(_y), blur(_blur), color(_color)
1064 ShadowValueImpl::~ShadowValueImpl()
1072 DOMString ShadowValueImpl::cssText() const
1076 text += color->cssText();
1079 if (text.length() > 0) {
1082 text += x->cssText();
1085 if (text.length() > 0) {
1088 text += y->cssText();
1091 if (text.length() > 0) {
1094 text += blur->cssText();
1100 // Used for box-flex-transition-group
1101 FlexGroupTransitionValueImpl::FlexGroupTransitionValueImpl()
1102 :autoValue(true), group1(0), group2(0), length(0)
1105 FlexGroupTransitionValueImpl::FlexGroupTransitionValueImpl(unsigned int _group1,
1106 unsigned int _group2,
1107 CSSPrimitiveValueImpl* _length)
1108 :autoValue(false), group1(_group1), group2(_group2), length(_length)
1111 FlexGroupTransitionValueImpl::~FlexGroupTransitionValueImpl()
1116 DOMString FlexGroupTransitionValueImpl::cssText() const
1118 DOMString text(QString::number(group1));
1121 text += QString::number(group2);
1125 text += length->cssText();
1130 DOMString CSSProperty::cssText() const
1132 return getPropertyName(m_id) + DOMString(": ") + m_value->cssText() + (m_bImportant ? DOMString(" !important") : DOMString()) + DOMString("; ");