khtml Library API Documentation

css_valueimpl.h

00001 /*
00002  * This file is part of the DOM implementation for KDE.
00003  *
00004  * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
00005  *           (C) 2002 Apple Computer, Inc.
00006  *           (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Library General Public License
00019  * along with this library; see the file COPYING.LIB.  If not, write to
00020  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021  * Boston, MA 02111-1307, USA.
00022  *
00023  */
00024 #ifndef _CSS_css_valueimpl_h_
00025 #define _CSS_css_valueimpl_h_
00026 
00027 #include "dom/css_value.h"
00028 #include "dom/dom_string.h"
00029 #include "css/css_base.h"
00030 #include "misc/loader_client.h"
00031 #include "misc/shared.h"
00032 
00033 #include <qintdict.h>
00034 
00035 namespace khtml {
00036     class RenderStyle;
00037     class CachedImage;
00038 }
00039 
00040 namespace DOM {
00041 
00042 class CSSRuleImpl;
00043 class CSSValueImpl;
00044 class NodeImpl;
00045 class CounterImpl;
00046 
00047 
00048 class CSSStyleDeclarationImpl : public StyleBaseImpl
00049 {
00050 public:
00051     CSSStyleDeclarationImpl(CSSRuleImpl *parentRule);
00052     CSSStyleDeclarationImpl(CSSRuleImpl *parentRule, QPtrList<CSSProperty> *lstValues);
00053     virtual ~CSSStyleDeclarationImpl();
00054 
00055     CSSStyleDeclarationImpl& operator=( const CSSStyleDeclarationImpl&);
00056 
00057     unsigned long length() const;
00058     CSSRuleImpl *parentRule() const;
00059     virtual DOM::DOMString removeProperty( int propertyID, bool NonCSSHints = false );
00060     virtual bool setProperty ( int propertyId, const DOM::DOMString &value, bool important = false, bool nonCSSHint = false);
00061     virtual void setProperty ( int propertyId, int value, bool important = false, bool nonCSSHint = false);
00062     // this treats integers as pixels!
00063     // needed for conversion of html attributes
00064     virtual void setLengthProperty(int id, const DOM::DOMString &value, bool important, bool nonCSSHint = true, bool multiLength = false);
00065 
00066     // add a whole, unparsed property
00067     virtual void setProperty ( const DOMString &propertyString);
00068     virtual DOM::DOMString item ( unsigned long index ) const;
00069 
00070     DOM::DOMString cssText() const;
00071     void setCssText(DOM::DOMString str);
00072 
00073     virtual bool isStyleDeclaration() const { return true; }
00074     virtual bool parseString( const DOMString &string, bool = false );
00075 
00076     virtual CSSValueImpl *getPropertyCSSValue( int propertyID ) const;
00077     virtual DOMString getPropertyValue( int propertyID ) const;
00078     virtual bool getPropertyPriority( int propertyID ) const;
00079 
00080     QPtrList<CSSProperty> *values() const { return m_lstValues; }
00081     void setNode(NodeImpl *_node) { m_node = _node; }
00082 
00083     void setChanged();
00084 
00085     void removeCSSHints();
00086 
00087 protected:
00088     DOMString getShortHandValue( const int* properties, int number ) const;
00089     DOMString get4Values( const int* properties ) const;
00090 
00091     QPtrList<CSSProperty> *m_lstValues;
00092     NodeImpl *m_node;
00093 
00094 private:
00095     // currently not needed - make sure its not used
00096     CSSStyleDeclarationImpl(const CSSStyleDeclarationImpl& o);
00097 };
00098 
00099 class CSSValueImpl : public StyleBaseImpl
00100 {
00101 public:
00102     CSSValueImpl() : StyleBaseImpl() {}
00103 
00104     virtual unsigned short cssValueType() const = 0;
00105 
00106     virtual DOM::DOMString cssText() const = 0;
00107 
00108     virtual bool isValue() const { return true; }
00109     virtual bool isFontValue() const { return false; }
00110 };
00111 
00112 class CSSInheritedValueImpl : public CSSValueImpl
00113 {
00114 public:
00115     CSSInheritedValueImpl() : CSSValueImpl() {}
00116     virtual ~CSSInheritedValueImpl() {}
00117 
00118     virtual unsigned short cssValueType() const;
00119     virtual DOM::DOMString cssText() const;
00120 };
00121 
00122 class CSSInitialValueImpl : public CSSValueImpl
00123 {
00124 public:
00125     virtual unsigned short cssValueType() const;
00126     virtual DOM::DOMString cssText() const;
00127 };
00128 
00129 class CSSValueListImpl : public CSSValueImpl
00130 {
00131 public:
00132     CSSValueListImpl() : CSSValueImpl() {}
00133 
00134     virtual ~CSSValueListImpl();
00135 
00136     unsigned long length() const { return m_values.count(); }
00137     CSSValueImpl *item ( unsigned long index ) { return m_values.at(index); }
00138 
00139     virtual bool isValueList() const { return true; }
00140 
00141     virtual unsigned short cssValueType() const;
00142 
00143     void append(CSSValueImpl *val);
00144     virtual DOM::DOMString cssText() const;
00145 
00146 protected:
00147     QPtrList<CSSValueImpl> m_values;
00148 };
00149 
00150 
00151 class Counter;
00152 class RGBColor;
00153 class Rect;
00154 
00155 class CSSPrimitiveValueImpl : public CSSValueImpl
00156 {
00157 public:
00158     CSSPrimitiveValueImpl();
00159     CSSPrimitiveValueImpl(int ident);
00160     CSSPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type);
00161     CSSPrimitiveValueImpl(const DOMString &str, CSSPrimitiveValue::UnitTypes type);
00162     CSSPrimitiveValueImpl(CounterImpl *c);
00163     CSSPrimitiveValueImpl( RectImpl *r);
00164     CSSPrimitiveValueImpl(QRgb color);
00165 
00166     virtual ~CSSPrimitiveValueImpl();
00167 
00168     void cleanup();
00169 
00170     unsigned short primitiveType() const { return m_type; }
00171 
00172     /*
00173      * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
00174      * the fontinfo in case val is defined in em or ex.
00175      *
00176      * The metrics have to be a bit different for screen and printer output.
00177      * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
00178      *
00179      * this is screen/printer dependent, so we probably need a config option for this,
00180      * and some tool to calibrate.
00181      */
00182     int computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
00183 
00184     double computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
00185 
00186     // use with care!!!
00187     void setPrimitiveType(unsigned short type) { m_type = type; }
00188     void setFloatValue ( unsigned short unitType, double floatValue, int &exceptioncode );
00189     double floatValue ( unsigned short/* unitType */) const { return m_value.num; }
00190 
00191     void setStringValue ( unsigned short stringType, const DOM::DOMString &stringValue, int &exceptioncode );
00192     DOM::DOMStringImpl *getStringValue () const {
00193     return ( ( m_type < CSSPrimitiveValue::CSS_STRING ||
00194            m_type > CSSPrimitiveValue::CSS_ATTR ||
00195            m_type == CSSPrimitiveValue::CSS_IDENT ) ? // fix IDENT
00196          0 : m_value.string );
00197     }
00198     CounterImpl *getCounterValue () const {
00199         return ( m_type != CSSPrimitiveValue::CSS_COUNTER ? 0 : m_value.counter );
00200     }
00201 
00202     RectImpl *getRectValue () const {
00203     return ( m_type != CSSPrimitiveValue::CSS_RECT ? 0 : m_value.rect );
00204     }
00205 
00206     QRgb getRGBColorValue () const {
00207     return ( m_type != CSSPrimitiveValue::CSS_RGBCOLOR ? 0 : m_value.rgbcolor );
00208     }
00209 
00210     virtual bool isPrimitiveValue() const { return true; }
00211     virtual unsigned short cssValueType() const;
00212 
00213     int getIdent();
00214 
00215     virtual bool parseString( const DOMString &string, bool = false);
00216     virtual DOM::DOMString cssText() const;
00217 
00218     virtual bool isQuirkValue() const { return false; }
00219 
00220 protected:
00221     int m_type;
00222     union {
00223     int ident;
00224     double num;
00225     DOM::DOMStringImpl *string;
00226     CounterImpl *counter;
00227     RectImpl *rect;
00228         QRgb rgbcolor;
00229     } m_value;
00230 };
00231 
00232 // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
00233 // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em
00234 // in a stylesheet.  When the quirky value is used, if you're in quirks mode, the margin will
00235 // collapse away inside a table cell.
00236 class CSSQuirkPrimitiveValueImpl : public CSSPrimitiveValueImpl
00237 {
00238 public:
00239     CSSQuirkPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type)
00240       :CSSPrimitiveValueImpl(num, type) {}
00241 
00242     virtual ~CSSQuirkPrimitiveValueImpl() {}
00243 
00244     virtual bool isQuirkValue() const { return true; }
00245 };
00246 
00247 class CounterImpl : public khtml::Shared<CounterImpl> {
00248 public:
00249     CounterImpl() : m_listStyle(0) { }
00250     DOMString identifier() const { return m_identifier; }
00251     unsigned int listStyle() const { return m_listStyle; }
00252     DOMString separator() const { return m_separator; }
00253 
00254     DOMString m_identifier;
00255     unsigned int m_listStyle;
00256     DOMString m_separator;
00257 };
00258 
00259 class RectImpl : public khtml::Shared<RectImpl> {
00260 public:
00261     RectImpl();
00262     ~RectImpl();
00263 
00264     CSSPrimitiveValueImpl *top() const { return m_top; }
00265     CSSPrimitiveValueImpl *right() const { return m_right; }
00266     CSSPrimitiveValueImpl *bottom() const { return m_bottom; }
00267     CSSPrimitiveValueImpl *left() const { return m_left; }
00268 
00269     void setTop( CSSPrimitiveValueImpl *top );
00270     void setRight( CSSPrimitiveValueImpl *right );
00271     void setBottom( CSSPrimitiveValueImpl *bottom );
00272     void setLeft( CSSPrimitiveValueImpl *left );
00273 protected:
00274     CSSPrimitiveValueImpl *m_top;
00275     CSSPrimitiveValueImpl *m_right;
00276     CSSPrimitiveValueImpl *m_bottom;
00277     CSSPrimitiveValueImpl *m_left;
00278 };
00279 
00280 class CSSImageValueImpl : public CSSPrimitiveValueImpl, public khtml::CachedObjectClient
00281 {
00282 public:
00283     CSSImageValueImpl(const DOMString &url, const StyleBaseImpl *style);
00284     CSSImageValueImpl();
00285     virtual ~CSSImageValueImpl();
00286 
00287     khtml::CachedImage *image() { return m_image; }
00288 protected:
00289     khtml::CachedImage *m_image;
00290 };
00291 
00292 class FontFamilyValueImpl : public CSSPrimitiveValueImpl
00293 {
00294 public:
00295     FontFamilyValueImpl( const QString &string);
00296     const QString &fontName() const { return parsedFontName; }
00297     int genericFamilyType() const { return _genericFamilyType; }
00298 protected:
00299     QString parsedFontName;
00300 private:
00301     int _genericFamilyType;
00302 };
00303 
00304 class FontValueImpl : public CSSValueImpl
00305 {
00306 public:
00307     FontValueImpl();
00308     virtual ~FontValueImpl();
00309 
00310     virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
00311 
00312     virtual DOM::DOMString cssText() const;
00313 
00314     virtual bool isFontValue() const { return true; }
00315 
00316     CSSPrimitiveValueImpl *style;
00317     CSSPrimitiveValueImpl *variant;
00318     CSSPrimitiveValueImpl *weight;
00319     CSSPrimitiveValueImpl *size;
00320     CSSPrimitiveValueImpl *lineHeight;
00321     CSSValueListImpl *family;
00322 };
00323 
00324 // Used for quotes
00325 class QuotesValueImpl : public CSSValueImpl
00326 {
00327 public:
00328     QuotesValueImpl();
00329 //    virtual ~QuotesValueImpl();
00330 
00331     virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
00332     virtual DOM::DOMString cssText() const;
00333 
00334     void addLevel(const QString& open, const QString& close);
00335     QString openQuote(int level) const;
00336     QString closeQuote(int level) const;
00337 
00338     unsigned int levels;
00339     QStringList data;
00340 };
00341 
00342 // Used for text-shadow and box-shadow
00343 class ShadowValueImpl : public CSSValueImpl
00344 {
00345 public:
00346     ShadowValueImpl(CSSPrimitiveValueImpl* _x, CSSPrimitiveValueImpl* _y,
00347                     CSSPrimitiveValueImpl* _blur, CSSPrimitiveValueImpl* _color);
00348     virtual ~ShadowValueImpl();
00349 
00350     virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
00351 
00352     virtual DOM::DOMString cssText() const;
00353 
00354     CSSPrimitiveValueImpl* x;
00355     CSSPrimitiveValueImpl* y;
00356     CSSPrimitiveValueImpl* blur;
00357     CSSPrimitiveValueImpl* color;
00358 };
00359 
00360 // Used for counter-reset and counter-increment
00361 class CounterActImpl : public CSSValueImpl {
00362     public:
00363         CounterActImpl(DOM::DOMString &c, short v) : m_counter(c), m_value(v) { }
00364         virtual ~CounterActImpl() {};
00365 
00366         virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
00367         virtual DOM::DOMString cssText() const;
00368 
00369         DOMString counter() const { return m_counter; }
00370         short value() const { return m_value; }
00371         void setValue( const short v ) { m_value = v; }
00372 
00373         DOM::DOMString m_counter;
00374         short m_value;
00375 };
00376 
00377 
00378 // ------------------------------------------------------------------------------
00379 
00380 // another helper class
00381 class CSSProperty
00382 {
00383 public:
00384     CSSProperty()
00385     {
00386     m_id = -1;
00387     m_bImportant = false;
00388     nonCSSHint = false;
00389         m_value = 0;
00390     }
00391     CSSProperty(const CSSProperty& o)
00392     {
00393         m_id = o.m_id;
00394         m_bImportant = o.m_bImportant;
00395         nonCSSHint = o.nonCSSHint;
00396         m_value = o.m_value;
00397         if (m_value) m_value->ref();
00398     }
00399     ~CSSProperty() {
00400     if(m_value) m_value->deref();
00401     }
00402 
00403     void setValue(CSSValueImpl *val) {
00404     if ( val != m_value ) {
00405         if(m_value) m_value->deref();
00406         m_value = val;
00407         if(m_value) m_value->ref();
00408     }
00409     }
00410 
00411     CSSValueImpl *value() const { return m_value; }
00412 
00413     DOM::DOMString cssText() const;
00414 
00415     // make sure the following fits in 4 bytes.
00416     signed int  m_id    : 29;
00417     bool m_bImportant   : 1;
00418     bool nonCSSHint     : 1;
00419 protected:
00420     CSSValueImpl *m_value;
00421 };
00422 
00423 
00424 } // namespace
00425 
00426 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Aug 2 12:26:51 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003