| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# cssstyleselector.h

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

This file is part of the documentation for khtml Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:33:09 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003