2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
5 * (C) 2004, 2005, 2006 Apple Computer, Inc.
6 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #ifndef _CSS_css_valueimpl_h_
25 #define _CSS_css_valueimpl_h_
27 #include "dom/css_value.h"
28 #include "dom/dom_string.h"
29 #include "css/css_base.h"
30 #include "misc/loader_client.h"
31 #include "misc/shared.h"
48 class CSSStyleDeclarationImpl
: public StyleBaseImpl
51 CSSStyleDeclarationImpl(CSSRuleImpl
*parentRule
);
52 CSSStyleDeclarationImpl(CSSRuleImpl
*parentRule
, QList
<CSSProperty
*> *lstValues
);
53 virtual ~CSSStyleDeclarationImpl();
55 CSSStyleDeclarationImpl
& operator=( const CSSStyleDeclarationImpl
&);
57 virtual unsigned long length() const;
58 CSSRuleImpl
*parentRule() const;
59 virtual void removeProperty(int propertyID
, DOM::DOMString
* old
= 0);
60 virtual void removePropertiesInSet(const int* set
, unsigned length
);
61 virtual bool setProperty ( int propertyId
, const DOM::DOMString
&value
, bool important
, int &ec
);
62 virtual bool setProperty ( int propertyId
, const DOM::DOMString
&value
, bool important
= false);
63 virtual void setProperty ( int propertyId
, int value
, bool important
= false);
65 // this treats integers as pixels!
66 // needed for conversion of html attributes
67 virtual void setLengthProperty(int id
, const DOM::DOMString
&value
, bool important
, bool multiLength
= false);
69 void setProperty(const DOMString
&propertyName
, const DOMString
&value
, const DOMString
&priority
);
70 DOMString
removeProperty(const DOMString
&propertyName
);
72 // add a whole, unparsed property
73 virtual void setProperty ( const DOMString
&propertyString
);
74 virtual DOM::DOMString
item ( unsigned long index
) const;
76 DOM::DOMString
cssText() const;
77 void setCssText(const DOM::DOMString
& str
);
79 virtual bool isStyleDeclaration() const { return true; }
80 virtual bool isPropertyImplicit(int propertyID
) const;
81 virtual bool parseString( const DOMString
&string
, bool = false );
83 CSSValueImpl
*getPropertyCSSValue(const DOMString
&propertyName
) const;
84 DOMString
getPropertyValue(const DOMString
&propertyName
) const ;
85 DOMString
getPropertyPriority(const DOMString
&propertyName
) const;
87 virtual CSSValueImpl
*getPropertyCSSValue( int propertyID
) const;
88 virtual DOMString
getPropertyValue( int propertyID
) const;
89 virtual bool getPropertyPriority( int propertyID
) const;
91 QList
<CSSProperty
*> *values() const { return m_lstValues
; }
92 void setNode(NodeImpl
*_node
) { m_node
= _node
; }
96 void removeCSSHints();
99 DOMString
getShortHandValue( const int* properties
, int number
) const;
100 DOMString
getCommonValue(const int* properties
, int number
) const;
101 DOMString
getLayeredShortHandValue(const int* properties
, unsigned number
) const;
102 DOMString
get4Values( const int* properties
) const;
104 QList
<CSSProperty
*> *m_lstValues
;
108 // currently not needed - make sure its not used
109 CSSStyleDeclarationImpl(const CSSStyleDeclarationImpl
& o
);
112 class CSSValueImpl
: public StyleBaseImpl
115 CSSValueImpl() : StyleBaseImpl() {}
117 virtual unsigned short cssValueType() const = 0;
119 virtual DOM::DOMString
cssText() const = 0;
120 void setCssText(const DOM::DOMString
&) { } // FIXME: Not implemented.
122 virtual bool isValue() const { return true; }
123 virtual bool isFontValue() const { return false; }
124 virtual bool isImplicitInitialValue() const { return false; }
127 class CSSInheritedValueImpl
: public CSSValueImpl
130 CSSInheritedValueImpl() : CSSValueImpl() {}
131 virtual ~CSSInheritedValueImpl() {}
133 virtual unsigned short cssValueType() const;
134 virtual DOM::DOMString
cssText() const;
137 class CSSInitialValueImpl
: public CSSValueImpl
140 CSSInitialValueImpl(bool implicit
)
141 :m_implicit(implicit
)
143 virtual unsigned short cssValueType() const;
144 virtual DOM::DOMString
cssText() const;
146 virtual bool isImplicitInitialValue() const { return m_implicit
; }
148 bool m_implicit
; // whether this property has been created implicitly to fill undeclared properties
149 // of a shorthand (e.g. 'border-top-width: medium' set from the 'border: solid red' declaration)
152 class CSSValueListImpl
: public CSSValueImpl
155 CSSValueListImpl() : CSSValueImpl() {}
157 virtual ~CSSValueListImpl();
159 unsigned long length() const { return m_values
.count(); }
160 CSSValueImpl
*item ( unsigned long index
) { return m_values
.at(index
); }
162 virtual bool isValueList() const { return true; }
164 virtual unsigned short cssValueType() const;
166 void append(CSSValueImpl
*val
);
167 virtual DOM::DOMString
cssText() const;
170 QList
<CSSValueImpl
*> m_values
;
178 class CSSPrimitiveValueImpl
: public CSSValueImpl
181 CSSPrimitiveValueImpl();
182 CSSPrimitiveValueImpl(int ident
);
183 CSSPrimitiveValueImpl(double num
, CSSPrimitiveValue::UnitTypes type
);
184 CSSPrimitiveValueImpl(const DOMString
&str
, CSSPrimitiveValue::UnitTypes type
);
185 CSSPrimitiveValueImpl(CounterImpl
*c
);
186 CSSPrimitiveValueImpl( RectImpl
*r
);
187 CSSPrimitiveValueImpl(QRgb color
);
188 CSSPrimitiveValueImpl(PairImpl
*p
);
190 virtual ~CSSPrimitiveValueImpl();
194 unsigned short primitiveType() const { return m_type
; }
197 * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
198 * the fontinfo in case val is defined in em or ex.
200 * The metrics have to be a bit different for screen and printer output.
201 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
203 * this is screen/printer dependent, so we probably need a config option for this,
204 * and some tool to calibrate.
206 int computeLength( khtml::RenderStyle
*style
, int logicalDpiY
);
208 double computeLengthFloat( khtml::RenderStyle
*style
, int logicalDpiY
);
210 // Retrieves an explicit resolution from the CSSValue if it contains one.
211 // This is specific to the CSS3 Media Queries module's resolution feature.
212 int getDPIResolution() const;
215 void setPrimitiveType(unsigned short type
) { m_type
= type
; }
216 void setFloatValue ( unsigned short unitType
, double floatValue
, int &exceptioncode
);
217 double floatValue ( unsigned short unitType
= CSSPrimitiveValue::CSS_UNKNOWN
) const { (void)unitType
; return m_value
.num
; }
219 void setStringValue ( unsigned short stringType
, const DOM::DOMString
&stringValue
, int &exceptioncode
);
220 DOM::DOMStringImpl
*getStringValue () const {
221 return ( ( m_type
< CSSPrimitiveValue::CSS_STRING
||
222 m_type
> CSSPrimitiveValue::CSS_ATTR
||
223 m_type
== CSSPrimitiveValue::CSS_IDENT
) ? // fix IDENT
224 0 : m_value
.string
);
226 CounterImpl
*getCounterValue () const {
227 return ( m_type
!= CSSPrimitiveValue::CSS_COUNTER
? 0 : m_value
.counter
);
230 RectImpl
*getRectValue () const {
231 return ( m_type
!= CSSPrimitiveValue::CSS_RECT
? 0 : m_value
.rect
);
234 QRgb
getRGBColorValue () const {
235 return ( m_type
!= CSSPrimitiveValue::CSS_RGBCOLOR
? 0 : m_value
.rgbcolor
);
238 PairImpl
* getPairValue() const {
239 return (m_type
!= CSSPrimitiveValue::CSS_PAIR
? 0 : m_value
.pair
);
242 virtual bool isPrimitiveValue() const { return true; }
243 virtual unsigned short cssValueType() const;
247 virtual bool parseString( const DOMString
&string
, bool = false);
248 virtual DOM::DOMString
cssText() const;
250 virtual bool isQuirkValue() const { return false; }
257 DOM::DOMStringImpl
*string
;
258 CounterImpl
*counter
;
265 // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
266 // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em
267 // in a stylesheet. When the quirky value is used, if you're in quirks mode, the margin will
268 // collapse away inside a table cell.
269 class CSSQuirkPrimitiveValueImpl
: public CSSPrimitiveValueImpl
272 CSSQuirkPrimitiveValueImpl(double num
, CSSPrimitiveValue::UnitTypes type
)
273 :CSSPrimitiveValueImpl(num
, type
) {}
275 virtual ~CSSQuirkPrimitiveValueImpl() {}
277 virtual bool isQuirkValue() const { return true; }
280 class CounterImpl
: public khtml::Shared
<CounterImpl
> {
282 CounterImpl() : m_listStyle(0) { }
283 DOMString
identifier() const { return m_identifier
; }
284 unsigned int listStyle() const { return m_listStyle
; }
285 DOMString
separator() const { return m_separator
; }
287 DOMString m_identifier
;
288 unsigned int m_listStyle
;
289 DOMString m_separator
;
292 class RectImpl
: public khtml::Shared
<RectImpl
> {
297 CSSPrimitiveValueImpl
*top() const { return m_top
; }
298 CSSPrimitiveValueImpl
*right() const { return m_right
; }
299 CSSPrimitiveValueImpl
*bottom() const { return m_bottom
; }
300 CSSPrimitiveValueImpl
*left() const { return m_left
; }
302 void setTop( CSSPrimitiveValueImpl
*top
);
303 void setRight( CSSPrimitiveValueImpl
*right
);
304 void setBottom( CSSPrimitiveValueImpl
*bottom
);
305 void setLeft( CSSPrimitiveValueImpl
*left
);
307 CSSPrimitiveValueImpl
*m_top
;
308 CSSPrimitiveValueImpl
*m_right
;
309 CSSPrimitiveValueImpl
*m_bottom
;
310 CSSPrimitiveValueImpl
*m_left
;
313 // A primitive value representing a pair. This is useful for properties like border-radius, background-size/position,
314 // and border-spacing (all of which are space-separated sets of two values). At the moment we are only using it for
315 // border-radius and background-size, but (FIXME) border-spacing and background-position could be converted over to use
316 // it (eliminating some extra -webkit- internal properties).
317 class PairImpl
: public khtml::Shared
<PairImpl
> {
319 PairImpl() : m_first(0), m_second(0) { }
320 PairImpl(CSSPrimitiveValueImpl
* first
, CSSPrimitiveValueImpl
* second
)
321 : m_first(first
), m_second(second
) { if (first
) first
->ref(); if (second
) second
->ref(); }
324 CSSPrimitiveValueImpl
* first() const { return m_first
; }
325 CSSPrimitiveValueImpl
* second() const { return m_second
; }
327 void setFirst(CSSPrimitiveValueImpl
* first
);
328 void setSecond(CSSPrimitiveValueImpl
* second
);
331 CSSPrimitiveValueImpl
* m_first
;
332 CSSPrimitiveValueImpl
* m_second
;
336 class CSSImageValueImpl
: public CSSPrimitiveValueImpl
, public khtml::CachedObjectClient
339 CSSImageValueImpl(const DOMString
&url
, const StyleBaseImpl
*style
);
341 virtual ~CSSImageValueImpl();
343 khtml::CachedImage
*image() { return m_image
; }
345 khtml::CachedImage
*m_image
;
348 class FontFamilyValueImpl
: public CSSPrimitiveValueImpl
351 FontFamilyValueImpl( const QString
&string
);
352 const QString
&fontName() const { return parsedFontName
; }
353 int genericFamilyType() const { return _genericFamilyType
; }
355 QString parsedFontName
;
357 int _genericFamilyType
;
360 class FontValueImpl
: public CSSValueImpl
364 virtual ~FontValueImpl();
366 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM
; }
368 virtual DOM::DOMString
cssText() const;
370 virtual bool isFontValue() const { return true; }
372 CSSPrimitiveValueImpl
*style
;
373 CSSPrimitiveValueImpl
*variant
;
374 CSSPrimitiveValueImpl
*weight
;
375 CSSPrimitiveValueImpl
*size
;
376 CSSPrimitiveValueImpl
*lineHeight
;
377 CSSValueListImpl
*family
;
381 class QuotesValueImpl
: public CSSValueImpl
385 // virtual ~QuotesValueImpl();
387 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM
; }
388 virtual DOM::DOMString
cssText() const;
390 void addLevel(const QString
& open
, const QString
& close
);
391 QString
openQuote(int level
) const;
392 QString
closeQuote(int level
) const;
398 // Used for text-shadow and box-shadow
399 class ShadowValueImpl
: public CSSValueImpl
402 ShadowValueImpl(CSSPrimitiveValueImpl
* _x
, CSSPrimitiveValueImpl
* _y
,
403 CSSPrimitiveValueImpl
* _blur
, CSSPrimitiveValueImpl
* _color
);
404 virtual ~ShadowValueImpl();
406 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM
; }
408 virtual DOM::DOMString
cssText() const;
410 CSSPrimitiveValueImpl
* x
;
411 CSSPrimitiveValueImpl
* y
;
412 CSSPrimitiveValueImpl
* blur
;
413 CSSPrimitiveValueImpl
* color
;
416 // Used for counter-reset and counter-increment
417 class CounterActImpl
: public CSSValueImpl
{
419 CounterActImpl(const DOMString
&c
, short v
) : m_counter(c
), m_value(v
) { }
420 virtual ~CounterActImpl() {}
422 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM
; }
423 virtual DOM::DOMString
cssText() const;
425 const DOMString
& counter() const { return m_counter
; }
426 short value() const { return m_value
; }
427 void setValue( const short v
) { m_value
= v
; }
429 DOM::DOMString m_counter
;
434 // ------------------------------------------------------------------------------
436 // another helper class
446 CSSProperty(const CSSProperty
& o
)
449 m_important
= o
.m_important
;
451 if (m_value
) m_value
->ref();
454 if(m_value
) m_value
->deref();
457 void setValue(CSSValueImpl
*val
) {
458 if ( val
!= m_value
) {
459 if(m_value
) m_value
->deref();
461 if(m_value
) m_value
->ref();
465 int id() const { return m_id
; }
467 bool isImportant() const { return m_important
; }
468 bool isImplicit() const { return m_implicit
; }
470 CSSValueImpl
*value() const { return m_value
; }
472 DOM::DOMString
cssText() const;
474 // make sure the following fits in 4 bytes.
475 signed int m_id
: 28;
476 bool m_important
: 1;
477 bool m_implicit
: 1; // whether this property has been set implicitly as part of a shorthand
478 // (e.g. 'margin-left: 10px' set from the 'margin: 10px' declaration)
480 CSSValueImpl
*m_value
;