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 parseString( const DOMString
&string
, bool = false );
82 CSSValueImpl
*getPropertyCSSValue(const DOMString
&propertyName
) const;
83 DOMString
getPropertyValue(const DOMString
&propertyName
) const ;
84 DOMString
getPropertyPriority(const DOMString
&propertyName
) const;
86 virtual CSSValueImpl
*getPropertyCSSValue( int propertyID
) const;
87 virtual DOMString
getPropertyValue( int propertyID
) const;
88 virtual bool getPropertyPriority( int propertyID
) const;
90 QList
<CSSProperty
*> *values() const { return m_lstValues
; }
91 void setNode(NodeImpl
*_node
) { m_node
= _node
; }
95 void removeCSSHints();
98 DOMString
getShortHandValue( const int* properties
, int number
) const;
99 DOMString
getCommonValue(const int* properties
, int number
) const;
100 DOMString
getLayeredShortHandValue(const int* properties
, unsigned number
) const;
101 DOMString
get4Values( const int* properties
) const;
103 QList
<CSSProperty
*> *m_lstValues
;
107 // currently not needed - make sure its not used
108 CSSStyleDeclarationImpl(const CSSStyleDeclarationImpl
& o
);
111 class CSSValueImpl
: public StyleBaseImpl
114 CSSValueImpl() : StyleBaseImpl() {}
116 virtual unsigned short cssValueType() const = 0;
118 virtual DOM::DOMString
cssText() const = 0;
119 void setCssText(const DOM::DOMString
&) { } // FIXME: Not implemented.
121 virtual bool isValue() const { return true; }
122 virtual bool isFontValue() const { return false; }
123 virtual bool isImplicitInitialValue() const { return false; }
126 class CSSInheritedValueImpl
: public CSSValueImpl
129 CSSInheritedValueImpl() : CSSValueImpl() {}
130 virtual ~CSSInheritedValueImpl() {}
132 virtual unsigned short cssValueType() const;
133 virtual DOM::DOMString
cssText() const;
136 class CSSInitialValueImpl
: public CSSValueImpl
139 CSSInitialValueImpl(bool implicit
)
140 :m_implicit(implicit
)
142 virtual unsigned short cssValueType() const;
143 virtual DOM::DOMString
cssText() const;
145 virtual bool isImplicitInitialValue() const { return m_implicit
; }
150 class CSSValueListImpl
: public CSSValueImpl
153 CSSValueListImpl() : CSSValueImpl() {}
155 virtual ~CSSValueListImpl();
157 unsigned long length() const { return m_values
.count(); }
158 CSSValueImpl
*item ( unsigned long index
) { return m_values
.at(index
); }
160 virtual bool isValueList() const { return true; }
162 virtual unsigned short cssValueType() const;
164 void append(CSSValueImpl
*val
);
165 virtual DOM::DOMString
cssText() const;
168 QList
<CSSValueImpl
*> m_values
;
176 class CSSPrimitiveValueImpl
: public CSSValueImpl
179 CSSPrimitiveValueImpl();
180 CSSPrimitiveValueImpl(int ident
);
181 CSSPrimitiveValueImpl(double num
, CSSPrimitiveValue::UnitTypes type
);
182 CSSPrimitiveValueImpl(const DOMString
&str
, CSSPrimitiveValue::UnitTypes type
);
183 CSSPrimitiveValueImpl(CounterImpl
*c
);
184 CSSPrimitiveValueImpl( RectImpl
*r
);
185 CSSPrimitiveValueImpl(QRgb color
);
186 CSSPrimitiveValueImpl(PairImpl
*p
);
188 virtual ~CSSPrimitiveValueImpl();
192 unsigned short primitiveType() const { return m_type
; }
195 * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
196 * the fontinfo in case val is defined in em or ex.
198 * The metrics have to be a bit different for screen and printer output.
199 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
201 * this is screen/printer dependent, so we probably need a config option for this,
202 * and some tool to calibrate.
204 int computeLength( khtml::RenderStyle
*style
, int logicalDpiY
);
206 double computeLengthFloat( khtml::RenderStyle
*style
, int logicalDpiY
);
208 // Retrieves an explicit resolution from the CSSValue if it contains one.
209 // This is specific to the CSS3 Media Queries module's resolution feature.
210 int getDPIResolution() const;
213 void setPrimitiveType(unsigned short type
) { m_type
= type
; }
214 void setFloatValue ( unsigned short unitType
, double floatValue
, int &exceptioncode
);
215 double floatValue ( unsigned short unitType
= CSSPrimitiveValue::CSS_UNKNOWN
) const { (void)unitType
; return m_value
.num
; }
217 void setStringValue ( unsigned short stringType
, const DOM::DOMString
&stringValue
, int &exceptioncode
);
218 DOM::DOMStringImpl
*getStringValue () const {
219 return ( ( m_type
< CSSPrimitiveValue::CSS_STRING
||
220 m_type
> CSSPrimitiveValue::CSS_ATTR
||
221 m_type
== CSSPrimitiveValue::CSS_IDENT
) ? // fix IDENT
222 0 : m_value
.string
);
224 CounterImpl
*getCounterValue () const {
225 return ( m_type
!= CSSPrimitiveValue::CSS_COUNTER
? 0 : m_value
.counter
);
228 RectImpl
*getRectValue () const {
229 return ( m_type
!= CSSPrimitiveValue::CSS_RECT
? 0 : m_value
.rect
);
232 QRgb
getRGBColorValue () const {
233 return ( m_type
!= CSSPrimitiveValue::CSS_RGBCOLOR
? 0 : m_value
.rgbcolor
);
236 PairImpl
* getPairValue() const {
237 return (m_type
!= CSSPrimitiveValue::CSS_PAIR
? 0 : m_value
.pair
);
240 virtual bool isPrimitiveValue() const { return true; }
241 virtual unsigned short cssValueType() const;
245 virtual bool parseString( const DOMString
&string
, bool = false);
246 virtual DOM::DOMString
cssText() const;
248 virtual bool isQuirkValue() const { return false; }
255 DOM::DOMStringImpl
*string
;
256 CounterImpl
*counter
;
263 // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
264 // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em
265 // in a stylesheet. When the quirky value is used, if you're in quirks mode, the margin will
266 // collapse away inside a table cell.
267 class CSSQuirkPrimitiveValueImpl
: public CSSPrimitiveValueImpl
270 CSSQuirkPrimitiveValueImpl(double num
, CSSPrimitiveValue::UnitTypes type
)
271 :CSSPrimitiveValueImpl(num
, type
) {}
273 virtual ~CSSQuirkPrimitiveValueImpl() {}
275 virtual bool isQuirkValue() const { return true; }
278 class CounterImpl
: public khtml::Shared
<CounterImpl
> {
280 CounterImpl() : m_listStyle(0) { }
281 DOMString
identifier() const { return m_identifier
; }
282 unsigned int listStyle() const { return m_listStyle
; }
283 DOMString
separator() const { return m_separator
; }
285 DOMString m_identifier
;
286 unsigned int m_listStyle
;
287 DOMString m_separator
;
290 class RectImpl
: public khtml::Shared
<RectImpl
> {
295 CSSPrimitiveValueImpl
*top() const { return m_top
; }
296 CSSPrimitiveValueImpl
*right() const { return m_right
; }
297 CSSPrimitiveValueImpl
*bottom() const { return m_bottom
; }
298 CSSPrimitiveValueImpl
*left() const { return m_left
; }
300 void setTop( CSSPrimitiveValueImpl
*top
);
301 void setRight( CSSPrimitiveValueImpl
*right
);
302 void setBottom( CSSPrimitiveValueImpl
*bottom
);
303 void setLeft( CSSPrimitiveValueImpl
*left
);
305 CSSPrimitiveValueImpl
*m_top
;
306 CSSPrimitiveValueImpl
*m_right
;
307 CSSPrimitiveValueImpl
*m_bottom
;
308 CSSPrimitiveValueImpl
*m_left
;
311 // A primitive value representing a pair. This is useful for properties like border-radius, background-size/position,
312 // and border-spacing (all of which are space-separated sets of two values). At the moment we are only using it for
313 // border-radius and background-size, but (FIXME) border-spacing and background-position could be converted over to use
314 // it (eliminating some extra -webkit- internal properties).
315 class PairImpl
: public khtml::Shared
<PairImpl
> {
317 PairImpl() : m_first(0), m_second(0) { }
318 PairImpl(CSSPrimitiveValueImpl
* first
, CSSPrimitiveValueImpl
* second
)
319 : m_first(first
), m_second(second
) { if (first
) first
->ref(); if (second
) second
->ref(); }
322 CSSPrimitiveValueImpl
* first() const { return m_first
; }
323 CSSPrimitiveValueImpl
* second() const { return m_second
; }
325 void setFirst(CSSPrimitiveValueImpl
* first
);
326 void setSecond(CSSPrimitiveValueImpl
* second
);
329 CSSPrimitiveValueImpl
* m_first
;
330 CSSPrimitiveValueImpl
* m_second
;
334 class CSSImageValueImpl
: public CSSPrimitiveValueImpl
, public khtml::CachedObjectClient
337 CSSImageValueImpl(const DOMString
&url
, const StyleBaseImpl
*style
);
339 virtual ~CSSImageValueImpl();
341 khtml::CachedImage
*image() { return m_image
; }
343 khtml::CachedImage
*m_image
;
346 class FontFamilyValueImpl
: public CSSPrimitiveValueImpl
349 FontFamilyValueImpl( const QString
&string
);
350 const QString
&fontName() const { return parsedFontName
; }
351 int genericFamilyType() const { return _genericFamilyType
; }
353 QString parsedFontName
;
355 int _genericFamilyType
;
358 class FontValueImpl
: public CSSValueImpl
362 virtual ~FontValueImpl();
364 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM
; }
366 virtual DOM::DOMString
cssText() const;
368 virtual bool isFontValue() const { return true; }
370 CSSPrimitiveValueImpl
*style
;
371 CSSPrimitiveValueImpl
*variant
;
372 CSSPrimitiveValueImpl
*weight
;
373 CSSPrimitiveValueImpl
*size
;
374 CSSPrimitiveValueImpl
*lineHeight
;
375 CSSValueListImpl
*family
;
379 class QuotesValueImpl
: public CSSValueImpl
383 // virtual ~QuotesValueImpl();
385 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM
; }
386 virtual DOM::DOMString
cssText() const;
388 void addLevel(const QString
& open
, const QString
& close
);
389 QString
openQuote(int level
) const;
390 QString
closeQuote(int level
) const;
396 // Used for text-shadow and box-shadow
397 class ShadowValueImpl
: public CSSValueImpl
400 ShadowValueImpl(CSSPrimitiveValueImpl
* _x
, CSSPrimitiveValueImpl
* _y
,
401 CSSPrimitiveValueImpl
* _blur
, CSSPrimitiveValueImpl
* _color
);
402 virtual ~ShadowValueImpl();
404 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM
; }
406 virtual DOM::DOMString
cssText() const;
408 CSSPrimitiveValueImpl
* x
;
409 CSSPrimitiveValueImpl
* y
;
410 CSSPrimitiveValueImpl
* blur
;
411 CSSPrimitiveValueImpl
* color
;
414 // Used for counter-reset and counter-increment
415 class CounterActImpl
: public CSSValueImpl
{
417 CounterActImpl(const DOMString
&c
, short v
) : m_counter(c
), m_value(v
) { }
418 virtual ~CounterActImpl() {}
420 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM
; }
421 virtual DOM::DOMString
cssText() const;
423 const DOMString
& counter() const { return m_counter
; }
424 short value() const { return m_value
; }
425 void setValue( const short v
) { m_value
= v
; }
427 DOM::DOMString m_counter
;
432 // ------------------------------------------------------------------------------
434 // another helper class
444 CSSProperty(const CSSProperty
& o
)
447 m_important
= o
.m_important
;
449 if (m_value
) m_value
->ref();
452 if(m_value
) m_value
->deref();
455 void setValue(CSSValueImpl
*val
) {
456 if ( val
!= m_value
) {
457 if(m_value
) m_value
->deref();
459 if(m_value
) m_value
->ref();
463 int id() const { return m_id
; }
465 bool isImportant() const { return m_important
; }
467 CSSValueImpl
*value() const { return m_value
; }
469 DOM::DOMString
cssText() const;
471 // make sure the following fits in 4 bytes.
472 signed int m_id
: 29;
473 bool m_important
: 1;
475 CSSValueImpl
*m_value
;