khtml Library API Documentation

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