# khtml Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# cssstyleselector.h

    00001 /*
    00002  * This file is part of the CSS implementation for KDE.
    00003  *
    00004  * Copyright (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: cssstyleselector.h,v 1.29.2.1 2003/05/18 12:34:36 mueller Exp $
    00022  */
    00023 #ifndef _CSS_cssstyleselector_h_
    00024 #define _CSS_cssstyleselector_h_
    00025
    00026 #include <qptrlist.h>
    00027
    00028 #include "rendering/render_style.h"
    00029 #include "dom/dom_string.h"
    00030
    00031 class KHTMLSettings;
    00032 class KHTMLView;
    00033 class KHTMLPart;
    00034 class KURL;
    00035
    00036 namespace DOM {
    00037     class DocumentImpl;
    00038     class NodeImpl;
    00039     class ElementImpl;
    00040     class StyleSheetImpl;
    00041     class CSSStyleRuleImpl;
    00042     class CSSStyleSheetImpl;
    00043     class CSSSelector;
    00044     class CSSStyleDeclarationImpl;
    00045     class CSSProperty;
    00046     class StyleSheetListImpl;
    00047 }
    00048
    00049 namespace khtml
    00050 {
    00051     class CSSStyleSelectorList;
    00052     class CSSOrderedRule;
    00053     class CSSOrderedProperty;
    00054     class CSSOrderedPropertyList;
    00055     class RenderStyle;
    00056
    00057     /*
    00058      * to remember the source where a rule came from. Differntiates between
    00059      * important and not important rules. This is ordered in the order they have to be applied
    00060      * to the RenderStyle.
    00061      */
    00062     enum Source {
    00063         Default = 0,
    00064         User = 1,
    00065         NonCSSHint = 2,
    00066         Author = 3,
    00067         Inline = 4,
    00068         AuthorImportant = 5,
    00069         InlineImportant = 6,
    00070         UserImportant =7
    00071     };
    00072
    00079     class StyleSelector
    00080     {
    00081     public:
    00082         StyleSelector() {};
    00083
    00084         /* as noone has implemented a second style selector up to now comment out
    00085            the virtual methods until then, so the class has no vptr.
    00086         */
    00087 //      virtual ~StyleSelector() {};
    00088 //      virtual RenderStyle *styleForElement(DOM::ElementImpl *e, int = None) = 0;
    00089
    00090         enum State {
    00091             None = 0x00,
    00092             Hover = 0x01,
    00093             Focus = 0x02,
    00094             Active = 0x04
    00095         };
    00096     };
    00097
    00098
    00102     class CSSStyleSelector : public StyleSelector
    00103     {
    00104     public:
    00113         CSSStyleSelector( DOM::DocumentImpl* doc, QString userStyleSheet, DOM::StyleSheetListImpl *styleSheets, const KURL &url,
    00114                           bool _strictParsing );
    00118         CSSStyleSelector( DOM::CSSStyleSheetImpl *sheet );
    00119
    00120         ~CSSStyleSelector();
    00121
    00122         void addSheet( DOM::CSSStyleSheetImpl *sheet );
    00123
    00124         static void loadDefaultStyle(const KHTMLSettings *s = 0);
    00125         static void clear();
    00126
    00127         RenderStyle *styleForElement(DOM::ElementImpl *e, int state = None );
    00128
    00129         QValueList<int> fontSizes() const { return m_fontSizes; }
    00130
    00131         bool strictParsing;
    00132         struct Encodedurl {
    00133             QString host; //also contains protocol
    00134             QString path;
    00135             QString file;
    00136         } encodedurl;
    00137
    00138         void computeFontSizes(QPaintDeviceMetrics* paintDeviceMetrics, int zoomFactor);
    00139     protected:
    00140
    00141         /* checks if the complete selector (which can be build up from a few CSSSelector's
    00142             with given relationships matches the given Element */
    00143         void checkSelector(int selector, DOM::ElementImpl *e);
    00144         /* checks if the selector matches the given Element */
    00145         bool checkOneSelector(DOM::CSSSelector *selector, DOM::ElementImpl *e);
    00146
    00147         /* builds up the selectors and properties lists from the CSSStyleSelectorList's */
    00148         void buildLists();
    00149         void clearLists();
    00150
    00151         unsigned int addInlineDeclarations(DOM::CSSStyleDeclarationImpl *decl,
    00152                                    unsigned int numProps );
    00153
    00154         static DOM::CSSStyleSheetImpl *defaultSheet;
    00155         static CSSStyleSelectorList *defaultStyle;
    00156         static CSSStyleSelectorList *defaultPrintStyle;
    00157         CSSStyleSelectorList *authorStyle;
    00158         CSSStyleSelectorList *userStyle;
    00159         DOM::CSSStyleSheetImpl *userSheet;
    00160
    00161     private:
    00162         void init();
    00163
    00164     public: // we need to make the enum public for SelectorCache
    00165         enum SelectorState {
    00166             Unknown = 0,
    00167             Applies,
    00168             AppliesPseudo,
    00169             Invalid
    00170         };
    00171
    00172         enum SelectorMedia {
    00173             MediaAural = 1,
    00174             MediaBraille,
    00175             MediaEmboss,
    00176             MediaHandheld,
    00177             MediaPrint,
    00178             MediaProjection,
    00179             MediaScreen,
    00180             MediaTTY,
    00181             MediaTV
    00182         };
    00183     protected:
    00184
    00185         struct SelectorCache {
    00186             SelectorState state;
    00187             unsigned int props_size;
    00188             int *props;
    00189         };
    00190
    00191         unsigned int selectors_size;
    00192         DOM::CSSSelector **selectors;
    00193         SelectorCache *selectorCache;
    00194         unsigned int properties_size;
    00195         CSSOrderedProperty **properties;
    00196         QMemArray<CSSOrderedProperty> inlineProps;
    00197         QString m_medium;
    00198         CSSOrderedProperty **propsToApply;
    00199         CSSOrderedProperty **pseudoProps;
    00200         unsigned int propsToApplySize;
    00201         unsigned int pseudoPropsSize;
    00202
    00203
    00204         int dynamicState;
    00205         RenderStyle::PseudoId dynamicPseudo;
    00206         int usedDynamicStates;
    00207         int selectorDynamicState;
    00208
    00209         RenderStyle *style;
    00210         RenderStyle *parentStyle;
    00211         DOM::ElementImpl *element;
    00212         DOM::NodeImpl *parentNode;
    00213         KHTMLView *view;
    00214         KHTMLPart *part;
    00215         const KHTMLSettings *settings;
    00216         QPaintDeviceMetrics *paintDeviceMetrics;
    00217         QValueList<int>     m_fontSizes;
    00218
    00219         bool fontDirty;
    00220
    00221         void applyRule(DOM::CSSProperty *prop);
    00222     };
    00223
    00224     /*
    00225      * List of properties that get applied to the Element. We need to collect them first
    00226      * and then apply them one by one, because we have to change the apply order.
    00227      * Some properties depend on other one already being applied (for example all properties spezifying
    00228      * some length need to have already the correct font size. Same applies to color
    00229      *
    00230      * While sorting them, we have to take care not to mix up the original order.
    00231      */
    00232     class CSSOrderedProperty
    00233     {
    00234     public:
    00235         CSSOrderedProperty(DOM::CSSProperty *_prop, uint _selector,
    00236                            bool first, Source source, unsigned int specificity,
    00237                            unsigned int _position )
    00238             : prop ( _prop ), pseudoId( RenderStyle::NOPSEUDO ), selector( _selector ),
    00239               position( _position )
    00240         {
    00241             priority = (!first << 30) | (source << 24) | specificity;
    00242         }
    00243
    00244         bool operator < ( const CSSOrderedProperty &other ) const {
    00245              if (priority < other.priority) return true;
    00246              if (priority > other.priority) return false;
    00247              if (position < other.position) return true;
    00248              return false;
    00249         }
    00250
    00251         DOM::CSSProperty *prop;
    00252         RenderStyle::PseudoId pseudoId;
    00253         unsigned int selector;
    00254         unsigned int position;
    00255
    00256         Q_UINT32 priority;
    00257     };
    00258
    00259     /*
    00260      * This is the list we will collect all properties we need to apply in.
    00261      * It will get sorted once before applying.
    00262      */
    00263     class CSSOrderedPropertyList : public QPtrList<CSSOrderedProperty>
    00264     {
    00265     public:
    00266         virtual int compareItems(QPtrCollection::Item i1, QPtrCollection::Item i2);
    00267         void append(DOM::CSSStyleDeclarationImpl *decl, uint selector, uint specificity,
    00268                     Source regular, Source important );
    00269     };
    00270
    00271     class CSSOrderedRule
    00272     {
    00273     public:
    00274         CSSOrderedRule(DOM::CSSStyleRuleImpl *r, DOM::CSSSelector *s, int _index);
    00275         ~CSSOrderedRule();
    00276
    00277         DOM::CSSSelector *selector;
    00278         DOM::CSSStyleRuleImpl *rule;
    00279         int index;
    00280     };
    00281
    00282     class CSSStyleSelectorList : public QPtrList<CSSOrderedRule>
    00283     {
    00284     public:
    00285         CSSStyleSelectorList();
    00286         virtual ~CSSStyleSelectorList();
    00287
    00288         void append( DOM::CSSStyleSheetImpl *sheet,
    00289                  const DOM::DOMString &medium = "screen" );
    00290
    00291         void collect( QPtrList<DOM::CSSSelector> *selectorList, CSSOrderedPropertyList *propList,
    00292                       Source regular, Source important );
    00293     };
    00294
    00295 }
    00296 #endif

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:35 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001