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  * $Id: css_valueimpl.h,v 1.53 2003/11/18 09:06:07 faure Exp $
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     DOM::DOMString removeProperty( int propertyID, bool NonCSSHints = false );
00060     bool setProperty ( int propertyId, const DOM::DOMString &value, bool important = false, bool nonCSSHint = false);
00061     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     void setLengthProperty(int id, const DOM::DOMString &value, bool important, bool nonCSSHint = true, bool multiLength = false);
00065 
00066     // add a whole, unparsed property
00067     void setProperty ( const DOMString &propertyString);
00068     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     CSSValueImpl *getPropertyCSSValue( int propertyID ) const;
00077     DOMString getPropertyValue( int propertyID ) const;
00078     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 { return CSSValue::CSS_INHERIT; }
00119     virtual DOM::DOMString cssText() const;
00120 };
00121 
00122 
00123 class CSSValueListImpl : public CSSValueImpl
00124 {
00125 public:
00126     CSSValueListImpl() : CSSValueImpl() {}
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() const { 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(double 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 { return m_type; }
00165 
00166     /*
00167      * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get
00168      * the fontinfo in case val is defined in em or ex.
00169      *
00170      * The metrics have to be a bit different for screen and printer output.
00171      * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
00172      *
00173      * this is screen/printer dependent, so we probably need a config option for this,
00174      * and some tool to calibrate.
00175      */
00176     int computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
00177 
00178     double computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics );
00179 
00180     // use with care!!!
00181     void setPrimitiveType(unsigned short type) { m_type = type; }
00182     void setFloatValue ( unsigned short unitType, double floatValue, int &exceptioncode );
00183     double floatValue ( unsigned short/* unitType */) const { return m_value.num; }
00184 
00185     void setStringValue ( unsigned short stringType, const DOM::DOMString &stringValue, int &exceptioncode );
00186     DOM::DOMStringImpl *getStringValue () const {
00187     return ( ( m_type < CSSPrimitiveValue::CSS_STRING ||
00188            m_type > CSSPrimitiveValue::CSS_ATTR ||
00189            m_type == CSSPrimitiveValue::CSS_IDENT ) ? // fix IDENT
00190          0 : m_value.string );
00191     }
00192     CounterImpl *getCounterValue () const {
00193         return ( m_type != CSSPrimitiveValue::CSS_COUNTER ? 0 : m_value.counter );
00194     }
00195 
00196     RectImpl *getRectValue () const {
00197     return ( m_type != CSSPrimitiveValue::CSS_RECT ? 0 : m_value.rect );
00198     }
00199 
00200     QRgb getRGBColorValue () const {
00201     return ( m_type != CSSPrimitiveValue::CSS_RGBCOLOR ? 0 : m_value.rgbcolor );
00202     }
00203 
00204     virtual bool isPrimitiveValue() const { return true; }
00205     virtual unsigned short cssValueType() const;
00206 
00207     int getIdent();
00208 
00209     virtual bool parseString( const DOMString &string, bool = false);
00210     virtual DOM::DOMString cssText() const;
00211 
00212     virtual bool isQuirkValue() const { return false; }
00213 
00214 protected:
00215     int m_type;
00216     union {
00217     int ident;
00218     double num;
00219     DOM::DOMStringImpl *string;
00220     CounterImpl *counter;
00221     RectImpl *rect;
00222         QRgb rgbcolor;
00223     } m_value;
00224 };
00225 
00226 // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
00227 // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em
00228 // in a stylesheet.  When the quirky value is used, if you're in quirks mode, the margin will
00229 // collapse away inside a table cell.
00230 class CSSQuirkPrimitiveValueImpl : public CSSPrimitiveValueImpl
00231 {
00232 public:
00233     CSSQuirkPrimitiveValueImpl(double num, CSSPrimitiveValue::UnitTypes type)
00234       :CSSPrimitiveValueImpl(num, type) {}
00235 
00236     virtual ~CSSQuirkPrimitiveValueImpl() {}
00237 
00238     virtual bool isQuirkValue() const { return true; }
00239 };
00240 
00241 class CounterImpl : public khtml::Shared<CounterImpl> {
00242 public:
00243     CounterImpl() { }
00244     DOMString identifier() const { return m_identifier; }
00245     DOMString listStyle() const { return m_listStyle; }
00246     DOMString separator() const { return m_separator; }
00247 
00248     DOMString m_identifier;
00249     DOMString m_listStyle;
00250     DOMString m_separator;
00251 };
00252 
00253 class RectImpl : public khtml::Shared<RectImpl> {
00254 public:
00255     RectImpl();
00256     ~RectImpl();
00257 
00258     CSSPrimitiveValueImpl *top() const { return m_top; }
00259     CSSPrimitiveValueImpl *right() const { return m_right; }
00260     CSSPrimitiveValueImpl *bottom() const { return m_bottom; }
00261     CSSPrimitiveValueImpl *left() const { return m_left; }
00262 
00263     void setTop( CSSPrimitiveValueImpl *top );
00264     void setRight( CSSPrimitiveValueImpl *right );
00265     void setBottom( CSSPrimitiveValueImpl *bottom );
00266     void setLeft( CSSPrimitiveValueImpl *left );
00267 protected:
00268     CSSPrimitiveValueImpl *m_top;
00269     CSSPrimitiveValueImpl *m_right;
00270     CSSPrimitiveValueImpl *m_bottom;
00271     CSSPrimitiveValueImpl *m_left;
00272 };
00273 
00274 class CSSImageValueImpl : public CSSPrimitiveValueImpl, public khtml::CachedObjectClient
00275 {
00276 public:
00277     CSSImageValueImpl(const DOMString &url, const StyleBaseImpl *style);
00278     CSSImageValueImpl();
00279     virtual ~CSSImageValueImpl();
00280 
00281     khtml::CachedImage *image() { return m_image; }
00282 protected:
00283     khtml::CachedImage *m_image;
00284 };
00285 
00286 class FontFamilyValueImpl : public CSSPrimitiveValueImpl
00287 {
00288 public:
00289     FontFamilyValueImpl( const QString &string);
00290     const QString &fontName() const { return parsedFontName; }
00291     int genericFamilyType() const { return _genericFamilyType; }
00292 protected:
00293     QString parsedFontName;
00294 private:
00295     int _genericFamilyType;
00296 };
00297 
00298 class FontValueImpl : public CSSValueImpl
00299 {
00300 public:
00301     FontValueImpl();
00302     virtual ~FontValueImpl();
00303 
00304     virtual unsigned short cssValueType() const { return CSSValue::CSS_CUSTOM; }
00305 
00306     virtual DOM::DOMString cssText() const;
00307 
00308     virtual bool isFontValue() const { return true; }
00309 
00310     CSSPrimitiveValueImpl *style;
00311     CSSPrimitiveValueImpl *variant;
00312     CSSPrimitiveValueImpl *weight;
00313     CSSPrimitiveValueImpl *size;
00314     CSSPrimitiveValueImpl *lineHeight;
00315     CSSValueListImpl *family;
00316 };
00317 
00318 // ------------------------------------------------------------------------------
00319 
00320 // another helper class
00321 class CSSProperty
00322 {
00323 public:
00324     CSSProperty()
00325     {
00326     m_id = -1;
00327     m_bImportant = false;
00328     nonCSSHint = false;
00329         m_value = 0;
00330     }
00331     CSSProperty(const CSSProperty& o)
00332     {
00333         m_id = o.m_id;
00334         m_bImportant = o.m_bImportant;
00335         nonCSSHint = o.nonCSSHint;
00336         m_value = o.m_value;
00337         if (m_value) m_value->ref();
00338     }
00339     ~CSSProperty() {
00340     if(m_value) m_value->deref();
00341     }
00342 
00343     void setValue(CSSValueImpl *val) {
00344     if ( val != m_value ) {
00345         if(m_value) m_value->deref();
00346         m_value = val;
00347         if(m_value) m_value->ref();
00348     }
00349     }
00350 
00351     CSSValueImpl *value() const { return m_value; }
00352 
00353     DOM::DOMString cssText() const;
00354 
00355     // make sure the following fits in 4 bytes.
00356     signed int  m_id    : 29;
00357     bool m_bImportant   : 1;
00358     bool nonCSSHint     : 1;
00359 protected:
00360     CSSValueImpl *m_value;
00361 };
00362 
00363 
00364 } // namespace
00365 
00366 #endif
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:37:15 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003