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.
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, QPtrList<CSSProperty> *lstValues);
53 virtual ~CSSStyleDeclarationImpl();
55 CSSStyleDeclarationImpl& operator=( const CSSStyleDeclarationImpl&);
57 unsigned long length() const;
58 CSSRuleImpl *parentRule() const;
59 virtual DOM::DOMString removeProperty(int propertyID, bool notifyChanged = true);
60 virtual bool setProperty(int propertyId, const DOM::DOMString &value, bool important = false, bool notifyChanged = true);
61 virtual void setProperty(int propertyId, int value, bool important = false, bool notifyChanged = true);
62 // this treats integers as pixels!
63 // needed for conversion of html attributes
64 virtual void setLengthProperty(int id, const DOM::DOMString &value, bool important,bool multiLength = false);
65 virtual void setStringProperty(int propertyId, const DOM::DOMString &value, DOM::CSSPrimitiveValue::UnitTypes, bool important = false); // parsed string value
66 virtual void setImageProperty(int propertyId, const DOM::DOMString &URL, bool important = false);
68 // add a whole, unparsed property
69 virtual void setProperty ( const DOMString &propertyString);
70 virtual DOM::DOMString item ( unsigned long index );
72 virtual DOM::DOMString cssText() const;
73 virtual void setCssText(const DOM::DOMString& str);
75 virtual bool isStyleDeclaration() { return true; }
77 virtual bool parseString( const DOMString &string, bool = false );
79 virtual CSSValueImpl *getPropertyCSSValue( int propertyID ) const;
80 virtual DOMString getPropertyValue( int propertyID ) const;
81 virtual bool getPropertyPriority( int propertyID ) const;
83 QPtrList<CSSProperty> *values() { return m_lstValues; }
84 const QPtrList<CSSProperty> *values() const { return m_lstValues; }
85 void setNode(NodeImpl *_node) { m_node = _node; }
86 NodeImpl* node() const { return m_node; }
88 void merge(CSSStyleDeclarationImpl *, bool argOverridesOnConflict=true);
93 DOMString getShortHandValue( const int* properties, int number ) const;
94 DOMString get4Values( const int* properties ) const;
96 QPtrList<CSSProperty> *m_lstValues;
100 // currently not needed - make sure its not used
101 CSSStyleDeclarationImpl(const CSSStyleDeclarationImpl& o);
104 class CSSValueImpl : public StyleBaseImpl
109 virtual ~CSSValueImpl();
111 virtual unsigned short cssValueType() const = 0;
113 virtual DOM::DOMString cssText() const = 0;
115 virtual bool isValue() { return true; }
116 virtual bool isFontValue() { return false; }
119 class CSSInheritedValueImpl : public CSSValueImpl
122 CSSInheritedValueImpl() : CSSValueImpl() {}
123 virtual ~CSSInheritedValueImpl() {}
125 virtual unsigned short cssValueType() const;
126 virtual DOM::DOMString cssText() const;
129 class CSSInitialValueImpl : public CSSValueImpl
132 virtual unsigned short cssValueType() const;
133 virtual DOM::DOMString cssText() const;
136 class CSSValueListImpl : public CSSValueImpl
141 virtual ~CSSValueListImpl();
143 unsigned long length() const { return m_values.count(); }
144 CSSValueImpl *item ( unsigned long index ) { return m_values.at(index); }
146 virtual bool isValueList() { return true; }
148 virtual unsigned short cssValueType() const;
150 void append(CSSValueImpl *val);
151 virtual DOM::DOMString cssText() const;
154 QPtrList<CSSValueImpl> m_values;
161 class DashboardRegionImpl;
163 class CSSPrimitiveValueImpl : public CSSValueImpl
166 CSSPrimitiveValueImpl();
167 CSSPrimitiveValueImpl(int ident);
168 CSSPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type);
169 CSSPrimitiveValueImpl(const DOMString &str, CSSPrimitiveValue::UnitTypes type);
170 CSSPrimitiveValueImpl(const Counter &c);
171 CSSPrimitiveValueImpl( RectImpl *r);
172 CSSPrimitiveValueImpl( DashboardRegionImpl *r);
173 CSSPrimitiveValueImpl(QRgb color);
175 virtual ~CSSPrimitiveValueImpl();
179 unsigned short primitiveType() const {
184 * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
185 * the fontinfo in case val is defined in em or ex.
187 * The metrics have to be a bit different for screen and printer output.
188 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
190 * this is screen/printer dependent, so we probably need a config option for this,
191 * and some tool to calibrate.
193 int computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
194 int computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics, double multiplier );
195 double computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics,
196 bool applyZoomFactor = true );
199 void setPrimitiveType(unsigned short type) { m_type = type; }
200 void setFloatValue ( unsigned short unitType, double floatValue, int &exceptioncode );
201 double getFloatValue ( unsigned short/* unitType */) const {
205 void setStringValue ( unsigned short stringType, const DOM::DOMString &stringValue, int &exceptioncode );
206 DOM::DOMString getStringValue() const;
208 CounterImpl *getCounterValue () const {
209 return ( m_type != CSSPrimitiveValue::CSS_COUNTER ? 0 : m_value.counter );
212 RectImpl *getRectValue () const {
213 return ( m_type != CSSPrimitiveValue::CSS_RECT ? 0 : m_value.rect );
216 QRgb getRGBColorValue () const {
217 return ( m_type != CSSPrimitiveValue::CSS_RGBCOLOR ? 0 : m_value.rgbcolor );
221 DashboardRegionImpl *getDashboardRegionValue () const {
222 return ( m_type != CSSPrimitiveValue::CSS_DASHBOARD_REGION ? 0 : m_value.region );
226 virtual bool isPrimitiveValue() const { return true; }
227 virtual unsigned short cssValueType() const;
231 virtual bool parseString( const DOMString &string, bool = false);
232 virtual DOM::DOMString cssText() const;
234 virtual bool isQuirkValue() { return false; }
241 DOM::DOMStringImpl *string;
242 CounterImpl *counter;
245 DashboardRegionImpl *region;
249 // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
250 // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em
251 // in a stylesheet. When the quirky value is used, if you're in quirks mode, the margin will
252 // collapse away inside a table cell.
253 class CSSQuirkPrimitiveValueImpl : public CSSPrimitiveValueImpl
256 CSSQuirkPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type)
257 :CSSPrimitiveValueImpl(num, type) {}
259 virtual ~CSSQuirkPrimitiveValueImpl() {}
261 virtual bool isQuirkValue() { return true; }
264 class CounterImpl : public khtml::Shared<CounterImpl> {
267 DOMString identifier() const { return m_identifier; }
268 DOMString listStyle() const { return m_listStyle; }
269 DOMString separator() const { return m_separator; }
271 DOMString m_identifier;
272 DOMString m_listStyle;
273 DOMString m_separator;
276 class RectImpl : public khtml::Shared<RectImpl> {
281 CSSPrimitiveValueImpl *top() { return m_top; }
282 CSSPrimitiveValueImpl *right() { return m_right; }
283 CSSPrimitiveValueImpl *bottom() { return m_bottom; }
284 CSSPrimitiveValueImpl *left() { return m_left; }
286 void setTop( CSSPrimitiveValueImpl *top );
287 void setRight( CSSPrimitiveValueImpl *right );
288 void setBottom( CSSPrimitiveValueImpl *bottom );
289 void setLeft( CSSPrimitiveValueImpl *left );
291 CSSPrimitiveValueImpl *m_top;
292 CSSPrimitiveValueImpl *m_right;
293 CSSPrimitiveValueImpl *m_bottom;
294 CSSPrimitiveValueImpl *m_left;
298 class DashboardRegionImpl : public RectImpl {
300 DashboardRegionImpl() : RectImpl(), m_next(0), m_isCircle(0), m_isRectangle(0) { };
301 ~DashboardRegionImpl() {
306 void setNext (DashboardRegionImpl *next) {
307 if (m_next) m_next->deref();
308 if (next) next->ref();
313 DashboardRegionImpl *m_next;
315 QString m_geometryType;
316 unsigned int m_isCircle:1;
317 unsigned int m_isRectangle:1;
321 class CSSImageValueImpl : public CSSPrimitiveValueImpl, public khtml::CachedObjectClient
324 CSSImageValueImpl(const DOMString &url, StyleBaseImpl *style);
326 virtual ~CSSImageValueImpl();
328 khtml::CachedImage *image(khtml::DocLoader* loader);
331 khtml::CachedImage* m_image;
332 bool m_accessedImage;
335 class FontFamilyValueImpl : public CSSPrimitiveValueImpl
338 FontFamilyValueImpl( const QString &string);
339 const QString &fontName() const { return parsedFontName; }
340 int genericFamilyType() const { return _genericFamilyType; }
342 virtual DOM::DOMString cssText() const;
344 QString parsedFontName;
346 int _genericFamilyType;
349 class FontValueImpl : public CSSValueImpl
353 virtual ~FontValueImpl();
355 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
357 virtual DOM::DOMString cssText() const;
359 virtual bool isFontValue() { return true; }
361 CSSPrimitiveValueImpl *style;
362 CSSPrimitiveValueImpl *variant;
363 CSSPrimitiveValueImpl *weight;
364 CSSPrimitiveValueImpl *size;
365 CSSPrimitiveValueImpl *lineHeight;
366 CSSValueListImpl *family;
369 // Used for text-shadow and box-shadow
370 class ShadowValueImpl : public CSSValueImpl
373 ShadowValueImpl(CSSPrimitiveValueImpl* _x, CSSPrimitiveValueImpl* _y,
374 CSSPrimitiveValueImpl* _blur, CSSPrimitiveValueImpl* _color);
375 virtual ~ShadowValueImpl();
377 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
379 virtual DOM::DOMString cssText() const;
381 CSSPrimitiveValueImpl* x;
382 CSSPrimitiveValueImpl* y;
383 CSSPrimitiveValueImpl* blur;
384 CSSPrimitiveValueImpl* color;
387 // Used by box-flex-group-transition
388 class FlexGroupTransitionValueImpl : public CSSValueImpl
391 FlexGroupTransitionValueImpl();
392 FlexGroupTransitionValueImpl(unsigned int _group1,
393 unsigned int _group2,
394 CSSPrimitiveValueImpl* _length);
395 virtual ~FlexGroupTransitionValueImpl();
397 virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
399 virtual DOM::DOMString cssText() const;
401 bool isAuto() const { return autoValue; }
406 CSSPrimitiveValueImpl* length;
409 // ------------------------------------------------------------------------------
411 // another helper class
418 m_bImportant = false;
421 CSSProperty(const CSSProperty& o)
424 m_bImportant = o.m_bImportant;
426 if (m_value) m_value->ref();
429 if(m_value) m_value->deref();
432 void setValue(CSSValueImpl *val) {
433 if ( val != m_value ) {
434 if(m_value) m_value->deref();
436 if(m_value) m_value->ref();
440 int id() const { return m_id; }
441 bool isImportant() const { return m_bImportant; }
443 CSSValueImpl *value() const { return m_value; }
445 DOM::DOMString cssText() const;
447 // make sure the following fits in 4 bytes.
451 CSSValueImpl *m_value;
454 CSSProperty &operator=(const CSSProperty&);