00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 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
00059
00060
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
00085
00086
00087
00088
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;
00134 QString path;
00135 QString file;
00136 } encodedurl;
00137
00138 void computeFontSizes(QPaintDeviceMetrics* paintDeviceMetrics, int zoomFactor);
00139 protected:
00140
00141
00142
00143 void checkSelector(int selector, DOM::ElementImpl *e);
00144
00145 bool checkOneSelector(DOM::CSSSelector *selector, DOM::ElementImpl *e);
00146
00147
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:
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
00226
00227
00228
00229
00230
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
00261
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