khtml Library API Documentation

css_valueimpl.h

00001 /*
00002  * This file is part of the DOM implementation for KDE.
00003  *
00004  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
00005  * Copyright (C) 2002 Apple Computer, Inc.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public License
00018  * along with this library; see the file COPYING.LIB.  If not, write to
00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  *
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/css_base.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     virtual DOM::DOMString removeProperty( int propertyID, bool NonCSSHints = false );
00059     virtual bool setProperty ( int propertyId, const DOM::DOMString &value, bool important = false, bool nonCSSHint = false);
00060     virtual 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     virtual void setLengthProperty(int id, const DOM::DOMString &value, bool important, bool nonCSSHint = true, bool multiLength = false);
00064 
00065     // add a whole, unparsed property
00066     virtual void setProperty ( const DOMString &propertyString);
00067     virtual DOM::DOMString item ( unsigned long index ) const;
00068 
00069     DOM::DOMString cssText() const;
00070     void setCssText(DOM::DOMString str);
00071 
00072     virtual bool isStyleDeclaration() const { return true; }
00073     virtual bool parseString( const DOMString &string, bool = false );
00074 
00075     virtual CSSValueImpl *getPropertyCSSValue( int propertyID ) const;
00076     virtual DOMString getPropertyValue( int propertyID ) const;
00077     virtual bool getPropertyPriority( int propertyID ) const;
00078 
00079     QPtrList<CSSProperty> *values() const { return m_lstValues; }
00080     void setNode(NodeImpl *_node) { m_node = _node; }
00081 
00082     void setChanged();
00083 
00084     void removeCSSHints();
00085 
00086 protected:
00087     DOMString getShortHandValue( const int* properties, int number ) const;
00088     DOMString get4Values( const int* properties ) const;
00089 
00090     QPtrList<CSSProperty> *m_lstValues;
00091     NodeImpl *m_node;
00092 
00093 private:
00094     // currently not needed - make sure its not used
00095     CSSStyleDeclarationImpl(const CSSStyleDeclarationImpl& o);
00096 };
00097 
00098 class CSSValueImpl : public StyleBaseImpl
00099 {
00100 public:
00101     CSSValueImpl() : StyleBaseImpl() {}
00102 
00103     virtual unsigned short cssValueType() const = 0;
00104 
00105     virtual DOM::DOMString cssText() const = 0;
00106 
00107     virtual bool isValue() const { return true; }
00108     virtual bool isFontValue() const { return false; }
00109 };
00110 
00111 class CSSInheritedValueImpl : public CSSValueImpl
00112 {
00113 public:
00114     CSSInheritedValueImpl() : CSSValueImpl() {}
00115     virtual ~CSSInheritedValueImpl() {}
00116 
00117     virtual unsigned short cssValueType() const;
00118     virtual DOM::DOMString cssText() const;
00119 };
00120 
00121 class CSSInitialValueImpl : public CSSValueImpl
00122 {
00123 public:
00124     virtual unsigned short cssValueType() const;
00125     virtual DOM::DOMString cssText() const;
00126 };
00127 
00128 class CSSValueListImpl : public CSSValueImpl
00129 {
00130 public:
00131     CSSValueListImpl() : CSSValueImpl() {}
00132 
00133     virtual ~CSSValueListImpl();
00134 
00135     unsigned long length() const { return m_values.count(); }
00136     CSSValueImpl *item ( unsigned long index ) { return m_values.at(index); }
00137 
00138     virtual bool isValueList() const { return true; }
00139 
00140     virtual unsigned short cssValueType() const;
00141 
00142     void append(CSSValueImpl *val);
00143     virtual DOM::DOMString cssText() const;
00144 
00145 protected:
00146     QPtrList<CSSValueImpl> m_values;
00147 };
00148 
00149 
00150 class Counter;
00151 class RGBColor;
00152 class Rect;
00153 
00154 class CSSPrimitiveValueImpl : public CSSValueImpl
00155 {
00156 public:
00157     CSSPrimitiveValueImpl();
00158     CSSPrimitiveValueImpl(int ident);
00159     CSSPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type);
00160     CSSPrimitiveValueImpl(const DOMString &str, CSSPrimitiveValue::UnitTypes type);
00161     CSSPrimitiveValueImpl(const Counter &c);
00162     CSSPrimitiveValueImpl( RectImpl *r);
00163     CSSPrimitiveValueImpl(QRgb color);
00164 
00165     virtual ~CSSPrimitiveValueImpl();
00166 
00167     void cleanup();
00168 
00169     unsigned short primitiveType() const { return m_type; }
00170 
00171     /*
00172      * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
00173      * the fontinfo in case val is defined in em or ex.
00174      *
00175      * The metrics have to be a bit different for screen and printer output.
00176      * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
00177      *
00178      * this is screen/printer dependent, so we probably need a config option for this,
00179      * and some tool to calibrate.
00180      */
00181     int computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
00182 
00183     double computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
00184 
00185     // use with care!!!
00186     void setPrimitiveType(unsigned short type) { m_type = type; }
00187     void setFloatValue ( unsigned short unitType, double floatValue, int &exceptioncode );
00188     double floatValue ( unsigned short/* unitType */) const { return m_value.num; }
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     virtual bool isQuirkValue() const { return false; }
00218 
00219 protected:
00220     int m_type;
00221     union {
00222     int ident;
00223     double num;
00224     DOM::DOMStringImpl *string;
00225     CounterImpl *counter;
00226     RectImpl *rect;
00227         QRgb rgbcolor;
00228     } m_value;
00229 };
00230 
00231 // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
00232 // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em
00233 // in a stylesheet.  When the quirky value is used, if you're in quirks mode, the margin will
00234 // collapse away inside a table cell.
00235 class CSSQuirkPrimitiveValueImpl : public CSSPrimitiveValueImpl
00236 {
00237 public:
00238     CSSQuirkPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type)
00239       :CSSPrimitiveValueImpl(num, type) {}
00240 
00241     virtual ~CSSQuirkPrimitiveValueImpl() {}
00242 
00243     virtual bool isQuirkValue() const { return true; }
00244 };
00245 
00246 class CounterImpl : public khtml::Shared<CounterImpl> {
00247 public:
00248     CounterImpl() { }
00249     DOMString identifier() const { return m_identifier; }
00250     DOMString listStyle() const { return m_listStyle; }
00251     DOMString separator() const { return m_separator; }
00252 
00253     DOMString m_identifier;
00254     DOMString m_listStyle;
00255     DOMString m_separator;
00256 };
00257 
00258 class RectImpl : public khtml::Shared<RectImpl> {
00259 public:
00260     RectImpl();
00261     ~RectImpl();
00262 
00263     CSSPrimitiveValueImpl *top() const { return m_top; }
00264     CSSPrimitiveValueImpl *right() const { return m_right; }
00265     CSSPrimitiveValueImpl *bottom() const { return m_bottom; }
00266     CSSPrimitiveValueImpl *left() const { return m_left; }
00267 
00268     void setTop( CSSPrimitiveValueImpl *top );
00269     void setRight( CSSPrimitiveValueImpl *right );
00270     void setBottom( CSSPrimitiveValueImpl *bottom );
00271     void setLeft( CSSPrimitiveValueImpl *left );
00272 protected:
00273     CSSPrimitiveValueImpl *m_top;
00274     CSSPrimitiveValueImpl *m_right;
00275     CSSPrimitiveValueImpl *m_bottom;
00276     CSSPrimitiveValueImpl *m_left;
00277 };
00278 
00279 class CSSImageValueImpl : public CSSPrimitiveValueImpl, public khtml::CachedObjectClient
00280 {
00281 public:
00282     CSSImageValueImpl(const DOMString &url, const StyleBaseImpl *style);
00283     CSSImageValueImpl();
00284     virtual ~CSSImageValueImpl();
00285 
00286     khtml::CachedImage *image() { return m_image; }
00287 protected:
00288     khtml::CachedImage *m_image;
00289 };
00290 
00291 class FontFamilyValueImpl : public CSSPrimitiveValueImpl
00292 {
00293 public:
00294     FontFamilyValueImpl( const QString &string);
00295     const QString &fontName() const { return parsedFontName; }
00296     int genericFamilyType() const { return _genericFamilyType; }
00297 protected:
00298     QString parsedFontName;
00299 private:
00300     int _genericFamilyType;
00301 };
00302 
00303 class FontValueImpl : public CSSValueImpl
00304 {
00305 public:
00306     FontValueImpl();
00307     virtual ~FontValueImpl();
00308 
00309     virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
00310 
00311     virtual DOM::DOMString cssText() const;
00312 
00313     virtual bool isFontValue() const { return true; }
00314 
00315     CSSPrimitiveValueImpl *style;
00316     CSSPrimitiveValueImpl *variant;
00317     CSSPrimitiveValueImpl *weight;
00318     CSSPrimitiveValueImpl *size;
00319     CSSPrimitiveValueImpl *lineHeight;
00320     CSSValueListImpl *family;
00321 };
00322 
00323 // ------------------------------------------------------------------------------
00324 
00325 // another helper class
00326 class CSSProperty
00327 {
00328 public:
00329     CSSProperty()
00330     {
00331     m_id = -1;
00332     m_bImportant = false;
00333     nonCSSHint = false;
00334         m_value = 0;
00335     }
00336     CSSProperty(const CSSProperty& o)
00337     {
00338         m_id = o.m_id;
00339         m_bImportant = o.m_bImportant;
00340         nonCSSHint = o.nonCSSHint;
00341         m_value = o.m_value;
00342         if (m_value) m_value->ref();
00343     }
00344     ~CSSProperty() {
00345     if(m_value) m_value->deref();
00346     }
00347 
00348     void setValue(CSSValueImpl *val) {
00349     if ( val != m_value ) {
00350         if(m_value) m_value->deref();
00351         m_value = val;
00352         if(m_value) m_value->ref();
00353     }
00354     }
00355 
00356     CSSValueImpl *value() const { return m_value; }
00357 
00358     DOM::DOMString cssText() const;
00359 
00360     // make sure the following fits in 4 bytes.
00361     signed int  m_id    : 29;
00362     bool m_bImportant   : 1;
00363     bool nonCSSHint     : 1;
00364 protected:
00365     CSSValueImpl *m_value;
00366 };
00367 
00368 
00369 } // namespace
00370 
00371 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 30 10:22:16 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003