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 #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
00062
00063
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
00088
00089
00090
00091
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 KDE_EXPORT static void clear();
00127 static void reparseConfiguration();
00128
00129 static void loadDefaultStyle(const KHTMLSettings *s, DOM::DocumentImpl *doc);
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;
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 static void precomputeAttributeDependencies(DOM::DocumentImpl* doc, DOM::CSSSelector* sel);
00147 protected:
00148
00149 DOM::NodeImpl* checkSubSelectors(DOM::CSSSelector *sel, DOM::NodeImpl *n, bool isAncestor);
00150
00151
00152
00153 void checkSelector(int selector, DOM::ElementImpl *e);
00154
00155 bool checkOneSelector(DOM::CSSSelector *selector, DOM::ElementImpl *e, bool isAncestor);
00156
00157 #ifdef APPLE_CHANGES
00158
00159
00160 void checkForGenericFamilyChange(RenderStyle* aStyle, RenderStyle* aParentStyle);
00161 #endif
00162
00163
00164 void buildLists();
00165 void clearLists();
00166
00167 void adjustRenderStyle(RenderStyle* style, DOM::ElementImpl *e);
00168
00169 unsigned int addInlineDeclarations(DOM::ElementImpl* e, DOM::CSSStyleDeclarationImpl *decl,
00170 unsigned int numProps);
00171
00172 static DOM::CSSStyleSheetImpl *s_defaultSheet;
00173 static DOM::CSSStyleSheetImpl *s_quirksSheet;
00174 static CSSStyleSelectorList *s_defaultStyle;
00175 static CSSStyleSelectorList *s_defaultQuirksStyle;
00176 static CSSStyleSelectorList *s_defaultPrintStyle;
00177 static RenderStyle* styleNotYetAvailable;
00178
00179 CSSStyleSelectorList *defaultStyle;
00180 CSSStyleSelectorList *defaultQuirksStyle;
00181 CSSStyleSelectorList *defaultPrintStyle;
00182
00183 CSSStyleSelectorList *authorStyle;
00184 CSSStyleSelectorList *userStyle;
00185 DOM::CSSStyleSheetImpl *userSheet;
00186
00187 public:
00188
00189 private:
00190 void init(const KHTMLSettings* settings, DOM::DocumentImpl* doc);
00191
00192 void mapBackgroundAttachment(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00193 void mapBackgroundImage(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00194 void mapBackgroundRepeat(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00195 void mapBackgroundXPosition(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00196 void mapBackgroundYPosition(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00197
00198 public:
00199 enum SelectorState {
00200 Unknown = 0,
00201 Applies,
00202 AppliesPseudo,
00203 Invalid
00204 };
00205
00206 enum SelectorMedia {
00207 MediaAural = 1,
00208 MediaBraille,
00209 MediaEmboss,
00210 MediaHandheld,
00211 MediaPrint,
00212 MediaProjection,
00213 MediaScreen,
00214 MediaTTY,
00215 MediaTV
00216 };
00217 protected:
00218
00219 struct SelectorCache {
00220 SelectorState state;
00221 unsigned int props_size;
00222 int *props;
00223 };
00224
00225 unsigned int selectors_size;
00226 DOM::CSSSelector **selectors;
00227 SelectorCache *selectorCache;
00228 unsigned int properties_size;
00229 CSSOrderedProperty **properties;
00230 QMemArray<CSSOrderedProperty> inlineProps;
00231 QString m_medium;
00232 CSSOrderedProperty **propsToApply;
00233 CSSOrderedProperty **pseudoProps;
00234 unsigned int propsToApplySize;
00235 unsigned int pseudoPropsSize;
00236
00237
00238 RenderStyle::PseudoId dynamicPseudo;
00239
00240 RenderStyle *style;
00241 RenderStyle *parentStyle;
00242 DOM::ElementImpl *element;
00243 DOM::NodeImpl *parentNode;
00244 KHTMLView *view;
00245 KHTMLPart *part;
00246 const KHTMLSettings *settings;
00247 QPaintDeviceMetrics *paintDeviceMetrics;
00248 QValueVector<int> m_fontSizes;
00249 QValueVector<int> m_fixedFontSizes;
00250
00251 bool fontDirty;
00252
00253 void applyRule(int id, DOM::CSSValueImpl *value);
00254 };
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 class CSSOrderedProperty
00265 {
00266 public:
00267 CSSOrderedProperty(DOM::CSSProperty *_prop, uint _selector,
00268 bool first, Source source, unsigned int specificity,
00269 unsigned int _position )
00270 : prop ( _prop ), pseudoId( RenderStyle::NOPSEUDO ), selector( _selector ),
00271 position( _position )
00272 {
00273 priority = (!first << 30) | (source << 24) | specificity;
00274 }
00275
00276 bool operator < ( const CSSOrderedProperty &other ) const {
00277 if (priority < other.priority) return true;
00278 if (priority > other.priority) return false;
00279 if (position < other.position) return true;
00280 return false;
00281 }
00282
00283 DOM::CSSProperty *prop;
00284 RenderStyle::PseudoId pseudoId;
00285 unsigned int selector;
00286 unsigned int position;
00287
00288 Q_UINT32 priority;
00289 };
00290
00291
00292
00293
00294
00295 class CSSOrderedPropertyList : public QPtrList<CSSOrderedProperty>
00296 {
00297 public:
00298 virtual int compareItems(QPtrCollection::Item i1, QPtrCollection::Item i2);
00299 void append(DOM::CSSStyleDeclarationImpl *decl, uint selector, uint specificity,
00300 Source regular, Source important );
00301 };
00302
00303 class CSSOrderedRule
00304 {
00305 public:
00306 CSSOrderedRule(DOM::CSSStyleRuleImpl *r, DOM::CSSSelector *s, int _index);
00307 ~CSSOrderedRule();
00308
00309 DOM::CSSSelector *selector;
00310 DOM::CSSStyleRuleImpl *rule;
00311 int index;
00312 };
00313
00314 class CSSStyleSelectorList : public QPtrList<CSSOrderedRule>
00315 {
00316 public:
00317 CSSStyleSelectorList();
00318 virtual ~CSSStyleSelectorList();
00319
00320 void append( DOM::CSSStyleSheetImpl *sheet,
00321 const DOM::DOMString &medium = "screen" );
00322
00323 void collect( QPtrList<DOM::CSSSelector> *selectorList, CSSOrderedPropertyList *propList,
00324 Source regular, Source important );
00325 };
00326
00327 }
00328 #endif