khtml Library API Documentation

css_valueimpl.h

00001 /*
00002  * This file is part of the DOM implementation for KDE.
00003  *
00004  * (C) 1999 Lars Knoll (knoll@kde.org)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  *
00021  * $Id: css_valueimpl.h,v 1.41.2.2 2003/08/17 14:38:51 mueller Exp $
00022  */
00023 #ifndef _CSS_css_valueimpl_h_
00024 #define _CSS_css_valueimpl_h_
00025 
00026 #include "dom/css_value.h"
00027 #include "dom/dom_string.h"
00028 #include "css/cssparser.h"
00029 #include "misc/loader_client.h"
00030 #include "misc/shared.h"
00031 
00032 #include <qintdict.h>
00033 
00034 namespace khtml {
00035     class RenderStyle;
00036     class CachedImage;
00037 }
00038 
00039 namespace DOM {
00040 
00041 class CSSRuleImpl;
00042 class CSSValueImpl;
00043 class NodeImpl;
00044 class CounterImpl;
00045 
00046 
00047 class CSSStyleDeclarationImpl : public StyleBaseImpl
00048 {
00049 public:
00050     CSSStyleDeclarationImpl(CSSRuleImpl *parentRule);
00051     CSSStyleDeclarationImpl(CSSRuleImpl *parentRule, QPtrList<CSSProperty> *lstValues);
00052     virtual ~CSSStyleDeclarationImpl();
00053 
00054     CSSStyleDeclarationImpl& operator=( const CSSStyleDeclarationImpl&);
00055 
00056     unsigned long length() const;
00057     CSSRuleImpl *parentRule() const;
00058     DOM::DOMString removeProperty( int propertyID, bool NonCSSHints = false );
00059     void setProperty ( int propertyId, const DOM::DOMString &value, bool important = false, bool nonCSSHint = false);
00060     void setProperty ( int propertyId, int value, bool important = false, bool nonCSSHint = false);
00061     // this treats integers as pixels!
00062     // needed for conversion of html attributes
00063     void setLengthProperty(int id, const DOM::DOMString &value, bool important, bool nonCSSHint = true, bool multiLength = false);
00064 
00065     // add a whole, unparsed property
00066     void setProperty ( const DOMString &propertyString);
00067     DOM::DOMString item ( unsigned long index );
00068 
00069     DOM::DOMString cssText() const;
00070     void setCssText(DOM::DOMString str);
00071 
00072     virtual bool isStyleDeclaration() { return true; }
00073 
00074     virtual bool parseString( const DOMString &string, bool = false );
00075 
00076     CSSValueImpl *getPropertyCSSValue( int propertyID ) const;
00077     DOMString getPropertyValue( int propertyID ) const;
00078     bool getPropertyPriority( int propertyID ) const;
00079 
00080     QPtrList<CSSProperty> *values() { return m_lstValues; }
00081     void setNode(NodeImpl *_node) { m_node = _node; }
00082 
00083     void setChanged();
00084 
00085 protected:
00086     DOMString getShortHandValue( const int* properties, int number ) const;
00087     DOMString get4Values( const int* properties ) const;
00088 
00089     QPtrList<CSSProperty> *m_lstValues;
00090     NodeImpl *m_node;
00091 
00092 private:
00093     // currently not needed - make sure its not used
00094     CSSStyleDeclarationImpl(const CSSStyleDeclarationImpl& o);
00095 };
00096 
00097 class CSSValueImpl : public StyleBaseImpl
00098 {
00099 public:
00100     CSSValueImpl();
00101 
00102     virtual ~CSSValueImpl();
00103 
00104     virtual unsigned short cssValueType() const = 0;
00105 
00106     virtual DOM::DOMString cssText() const;
00107     void setCssText(DOM::DOMString str);
00108 
00109     virtual bool isValue() { return true; }
00110 };
00111 
00112 class CSSInheritedValueImpl : public CSSValueImpl
00113 {
00114 public:
00115     CSSInheritedValueImpl() : CSSValueImpl() {}
00116     virtual ~CSSInheritedValueImpl() {}
00117 
00118     virtual unsigned short cssValueType() const { return CSSValue::CSS_INHERIT; }
00119     virtual DOM::DOMString cssText() const;
00120 };
00121 
00122 
00123 class CSSValueListImpl : public CSSValueImpl
00124 {
00125 public:
00126     CSSValueListImpl();
00127 
00128     virtual ~CSSValueListImpl();
00129 
00130     unsigned long length() const { return m_values.count(); }
00131     CSSValueImpl *item ( unsigned long index ) { return m_values.at(index); }
00132 
00133     virtual bool isValueList() { return true; }
00134 
00135     virtual unsigned short cssValueType() const;
00136 
00137     void append(CSSValueImpl *val);
00138     virtual DOM::DOMString cssText() const;
00139 
00140 protected:
00141     QPtrList<CSSValueImpl> m_values;
00142 };
00143 
00144 
00145 class Counter;
00146 class RGBColor;
00147 class Rect;
00148 
00149 class CSSPrimitiveValueImpl : public CSSValueImpl
00150 {
00151 public:
00152     CSSPrimitiveValueImpl();
00153     CSSPrimitiveValueImpl(int ident);
00154     CSSPrimitiveValueImpl(float num, CSSPrimitiveValue::UnitTypes type);
00155     CSSPrimitiveValueImpl(const DOMString &str, CSSPrimitiveValue::UnitTypes type);
00156     CSSPrimitiveValueImpl(const Counter &c);
00157     CSSPrimitiveValueImpl( RectImpl *r);
00158     CSSPrimitiveValueImpl(QRgb color);
00159 
00160     virtual ~CSSPrimitiveValueImpl();
00161 
00162     void cleanup();
00163 
00164     unsigned short primitiveType() const {
00165             return m_type;
00166     }
00167 
00168     /*
00169      * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
00170      * the fontinfo in case val is defined in em or ex.
00171      *
00172      * The metrics have to be a bit different for screen and printer output.
00173      * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
00174      *
00175      * this is screen/printer dependent, so we probably need a config option for this,
00176      * and some tool to calibrate.
00177      */
00178     int computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
00179 
00180     float computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
00181 
00182 
00183     // use with care!!!
00184     void setPrimitiveType(unsigned short type) { m_type = type; }
00185     void setFloatValue ( unsigned short unitType, float floatValue, int &exceptioncode );
00186     float getFloatValue ( unsigned short/* unitType */) const {
00187         return m_value.num;
00188     }
00189 
00190     void setStringValue ( unsigned short stringType, const DOM::DOMString &stringValue, int &exceptioncode );
00191     DOM::DOMStringImpl *getStringValue () const {
00192         return ( ( m_type < CSSPrimitiveValue::CSS_STRING ||
00193                    m_type > CSSPrimitiveValue::CSS_ATTR ||
00194                    m_type == CSSPrimitiveValue::CSS_IDENT ) ? // fix IDENT
00195                  0 : m_value.string );
00196     }
00197     CounterImpl *getCounterValue () const {
00198         return ( m_type != CSSPrimitiveValue::CSS_COUNTER ? 0 : m_value.counter );
00199     }
00200 
00201     RectImpl *getRectValue () const {
00202         return ( m_type != CSSPrimitiveValue::CSS_RECT ? 0 : m_value.rect );
00203     }
00204 
00205     QRgb getRGBColorValue () const {
00206         return ( m_type != CSSPrimitiveValue::CSS_RGBCOLOR ? 0 : m_value.rgbcolor );
00207     }
00208 
00209     virtual bool isPrimitiveValue() const { return true; }
00210     virtual unsigned short cssValueType() const;
00211 
00212     int getIdent();
00213 
00214     virtual bool parseString( const DOMString &string, bool = false);
00215     virtual DOM::DOMString cssText() const;
00216 
00217 protected:
00218     int m_type;
00219     union {
00220         int ident;
00221         float num;
00222         DOM::DOMStringImpl *string;
00223         CounterImpl *counter;
00224         RectImpl *rect;
00225         QRgb rgbcolor;
00226     } m_value;
00227 };
00228 
00229 class CounterImpl : public khtml::Shared<CounterImpl> {
00230 public:
00231     CounterImpl() { }
00232     DOMString identifier() const { return m_identifier; }
00233     DOMString listStyle() const { return m_listStyle; }
00234     DOMString separator() const { return m_separator; }
00235 
00236     DOMString m_identifier;
00237     DOMString m_listStyle;
00238     DOMString m_separator;
00239 };
00240 
00241 class RectImpl : public khtml::Shared<RectImpl> {
00242 public:
00243     RectImpl();
00244     ~RectImpl();
00245 
00246     CSSPrimitiveValueImpl *top() { return m_top; }
00247     CSSPrimitiveValueImpl *right() { return m_right; }
00248     CSSPrimitiveValueImpl *bottom() { return m_bottom; }
00249     CSSPrimitiveValueImpl *left() { return m_left; }
00250 
00251     void setTop( CSSPrimitiveValueImpl *top );
00252     void setRight( CSSPrimitiveValueImpl *right );
00253     void setBottom( CSSPrimitiveValueImpl *bottom );
00254     void setLeft( CSSPrimitiveValueImpl *left );
00255 protected:
00256     CSSPrimitiveValueImpl *m_top;
00257     CSSPrimitiveValueImpl *m_right;
00258     CSSPrimitiveValueImpl *m_bottom;
00259     CSSPrimitiveValueImpl *m_left;
00260 };
00261 
00262 class CSSImageValueImpl : public CSSPrimitiveValueImpl, public khtml::CachedObjectClient
00263 {
00264 public:
00265     CSSImageValueImpl(const DOMString &url, StyleBaseImpl *style);
00266     CSSImageValueImpl();
00267     virtual ~CSSImageValueImpl();
00268 
00269     khtml::CachedImage *image() { return m_image; }
00270 protected:
00271     khtml::CachedImage *m_image;
00272 };
00273 
00274 class FontFamilyValueImpl : public CSSPrimitiveValueImpl
00275 {
00276 public:
00277     FontFamilyValueImpl( const QString &string);
00278     const QString &fontName() const { return parsedFontName; }
00279 protected:
00280     QString parsedFontName;
00281 };
00282 
00283 // ------------------------------------------------------------------------------
00284 
00285 // another helper class
00286 class CSSProperty
00287 {
00288 public:
00289     CSSProperty()
00290     {
00291         m_id = -1;
00292         m_bImportant = false;
00293         nonCSSHint = false;
00294         m_value = 0;
00295     }
00296     CSSProperty(const CSSProperty& o)
00297     {
00298         m_id = o.m_id;
00299         m_bImportant = o.m_bImportant;
00300         nonCSSHint = o.nonCSSHint;
00301         m_value = o.m_value;
00302         if (m_value) m_value->ref();
00303     }
00304     ~CSSProperty() {
00305         if(m_value) m_value->deref();
00306     }
00307 
00308     void setValue(CSSValueImpl *val) {
00309         if ( val != m_value ) {
00310             if(m_value) m_value->deref();
00311             m_value = val;
00312             if(m_value) m_value->ref();
00313         }
00314     }
00315 
00316     CSSValueImpl *value() { return m_value; }
00317 
00318     // make sure the following fits in 4 bytes.
00319     signed int  m_id    : 29;
00320     bool m_bImportant   : 1;
00321     bool nonCSSHint     : 1;
00322 protected:
00323     CSSValueImpl *m_value;
00324 };
00325 
00326 
00327 } // namespace
00328 
00329 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:33 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001