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 #include "xml/dom_restyler.h"
00032
00033 class KHTMLSettings;
00034 class KHTMLView;
00035 class KHTMLPart;
00036 class KHTMLFactory;
00037 class KURL;
00038
00039 namespace DOM {
00040 class DocumentImpl;
00041 class NodeImpl;
00042 class ElementImpl;
00043 class StyleSheetImpl;
00044 class CSSStyleRuleImpl;
00045 class CSSStyleSheetImpl;
00046 class CSSSelector;
00047 class CSSStyleDeclarationImpl;
00048 class CSSProperty;
00049 class StyleSheetListImpl;
00050 class CSSValueImpl;
00051 }
00052
00053 namespace khtml
00054 {
00055 class CSSStyleSelectorList;
00056 class CSSOrderedRule;
00057 class CSSOrderedProperty;
00058 class CSSOrderedPropertyList;
00059 class RenderStyle;
00060
00061
00062
00063
00064
00065
00066 enum Source {
00067 Default = 0,
00068 NonCSSHint = 1,
00069 User = 2,
00070 Author = 3,
00071 Inline = 4,
00072 AuthorImportant = 5,
00073 InlineImportant = 6,
00074 UserImportant =7
00075 };
00076
00083 class StyleSelector
00084 {
00085 public:
00086 StyleSelector() {}
00087
00088
00089
00090
00091
00092
00093
00094 enum State {
00095 None = 0x00,
00096 Hover = 0x01,
00097 Focus = 0x02,
00098 Active = 0x04
00099 };
00100 };
00101
00102
00106 class CSSStyleSelector : public StyleSelector
00107 {
00108 public:
00117 CSSStyleSelector( DOM::DocumentImpl* doc, QString userStyleSheet, DOM::StyleSheetListImpl *styleSheets, const KURL &url,
00118 bool _strictParsing );
00122 CSSStyleSelector( DOM::CSSStyleSheetImpl *sheet );
00123
00124 ~CSSStyleSelector();
00125
00126 void addSheet( DOM::CSSStyleSheetImpl *sheet );
00127 KDE_EXPORT static void clear();
00128 static void reparseConfiguration();
00129
00130 static void loadDefaultStyle(const KHTMLSettings *s, DOM::DocumentImpl *doc);
00131
00132 RenderStyle *styleForElement(DOM::ElementImpl *e);
00133
00134 QValueVector<int> fontSizes() const { return m_fontSizes; }
00135 QValueVector<int> fixedFontSizes() const { return m_fixedFontSizes; }
00136
00137 bool strictParsing;
00138 struct Encodedurl {
00139 QString host;
00140 QString path;
00141 QString file;
00142 } encodedurl;
00143
00144 void computeFontSizes(QPaintDeviceMetrics* paintDeviceMetrics, int zoomFactor);
00145 void computeFontSizesFor(QPaintDeviceMetrics* paintDeviceMetrics, int zoomFactor, QValueVector<int>& fontSizes, bool isFixed);
00146
00147 static void precomputeAttributeDependencies(DOM::DocumentImpl* doc, DOM::CSSSelector* sel);
00148 protected:
00149
00150
00151 void checkSelector(int selector, DOM::ElementImpl *e);
00152
00153 bool checkSimpleSelector(DOM::CSSSelector *selector, DOM::ElementImpl *e, bool isAncestor, bool isSubSelector = false);
00154
00155 DOM::ElementImpl* checkSelector(DOM::CSSSelector *sel, DOM::ElementImpl *e, bool isAncestor, bool isSubSelector = false);
00156
00157 void addDependency(StructuralDependencyType dependencyType, DOM::ElementImpl* dependency);
00158 #ifdef APPLE_CHANGES
00159
00160
00161 void checkForGenericFamilyChange(RenderStyle* aStyle, RenderStyle* aParentStyle);
00162 #endif
00163
00164
00165 void buildLists();
00166 void clearLists();
00167
00168 void adjustRenderStyle(RenderStyle* style, DOM::ElementImpl *e);
00169
00170 unsigned int addInlineDeclarations(DOM::ElementImpl* e, DOM::CSSStyleDeclarationImpl *decl,
00171 unsigned int numProps);
00172
00173 static DOM::CSSStyleSheetImpl *s_defaultSheet;
00174 static DOM::CSSStyleSheetImpl *s_quirksSheet;
00175 static CSSStyleSelectorList *s_defaultStyle;
00176 static CSSStyleSelectorList *s_defaultQuirksStyle;
00177 static CSSStyleSelectorList *s_defaultPrintStyle;
00178 static RenderStyle* styleNotYetAvailable;
00179
00180 CSSStyleSelectorList *defaultStyle;
00181 CSSStyleSelectorList *defaultQuirksStyle;
00182 CSSStyleSelectorList *defaultPrintStyle;
00183
00184 CSSStyleSelectorList *authorStyle;
00185 CSSStyleSelectorList *userStyle;
00186 DOM::CSSStyleSheetImpl *userSheet;
00187
00188 public:
00189
00190 private:
00191 void init(const KHTMLSettings* settings, DOM::DocumentImpl* doc);
00192
00193 void mapBackgroundAttachment(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00194 void mapBackgroundClip(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00195 void mapBackgroundOrigin(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00196 void mapBackgroundImage(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00197 void mapBackgroundRepeat(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00198 void mapBackgroundSize(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00199 void mapBackgroundXPosition(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00200 void mapBackgroundYPosition(BackgroundLayer* layer, DOM::CSSValueImpl* value);
00201
00202 public:
00203 enum SelectorState {
00204 Unknown = 0,
00205 Applies,
00206 AppliesPseudo,
00207 Invalid
00208 };
00209
00210 enum SelectorMedia {
00211 MediaAural = 1,
00212 MediaBraille,
00213 MediaEmboss,
00214 MediaHandheld,
00215 MediaPrint,
00216 MediaProjection,
00217 MediaScreen,
00218 MediaTTY,
00219 MediaTV
00220 };
00221 protected:
00222
00223 struct SelectorCache {
00224 SelectorState state;
00225 unsigned int props_size;
00226 int *props;
00227 };
00228
00229 unsigned int selectors_size;
00230 DOM::CSSSelector **selectors;
00231 SelectorCache *selectorCache;
00232 unsigned int properties_size;
00233 CSSOrderedProperty **properties;
00234 QMemArray<CSSOrderedProperty> inlineProps;
00235 QString m_medium;
00236 CSSOrderedProperty **propsToApply;
00237 CSSOrderedProperty **pseudoProps;
00238 unsigned int propsToApplySize;
00239 unsigned int pseudoPropsSize;
00240
00241
00242 RenderStyle::PseudoId dynamicPseudo;
00243
00244 RenderStyle *style;
00245 RenderStyle *parentStyle;
00246 DOM::ElementImpl *element;
00247 DOM::NodeImpl *parentNode;
00248 KHTMLView *view;
00249 KHTMLPart *part;
00250 const KHTMLSettings *settings;
00251 QPaintDeviceMetrics *paintDeviceMetrics;
00252 QValueVector<int> m_fontSizes;
00253 QValueVector<int> m_fixedFontSizes;
00254
00255 bool fontDirty;
00256
00257 void applyRule(int id, DOM::CSSValueImpl *value);
00258 };
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 class CSSOrderedProperty
00269 {
00270 public:
00271 CSSOrderedProperty(DOM::CSSProperty *_prop, uint _selector,
00272 bool first, Source source, unsigned int specificity,
00273 unsigned int _position )
00274 : prop ( _prop ), pseudoId( RenderStyle::NOPSEUDO ), selector( _selector ),
00275 position( _position )
00276 {
00277 priority = (!first << 30) | (source << 24) | specificity;
00278 }
00279
00280 bool operator < ( const CSSOrderedProperty &other ) const {
00281 if (priority < other.priority) return true;
00282 if (priority > other.priority) return false;
00283 if (position < other.position) return true;
00284 return false;
00285 }
00286
00287 DOM::CSSProperty *prop;
00288 RenderStyle::PseudoId pseudoId;
00289 unsigned int selector;
00290 unsigned int position;
00291
00292 Q_UINT32 priority;
00293 };
00294
00295
00296
00297
00298
00299 class CSSOrderedPropertyList : public QPtrList<CSSOrderedProperty>
00300 {
00301 public:
00302 virtual int compareItems(QPtrCollection::Item i1, QPtrCollection::Item i2);
00303 void append(DOM::CSSStyleDeclarationImpl *decl, uint selector, uint specificity,
00304 Source regular, Source important );
00305 };
00306
00307 class CSSOrderedRule
00308 {
00309 public:
00310 CSSOrderedRule(DOM::CSSStyleRuleImpl *r, DOM::CSSSelector *s, int _index);
00311 ~CSSOrderedRule();
00312
00313 DOM::CSSSelector *selector;
00314 DOM::CSSStyleRuleImpl *rule;
00315 int index;
00316 };
00317
00318 class CSSStyleSelectorList : public QPtrList<CSSOrderedRule>
00319 {
00320 public:
00321 CSSStyleSelectorList();
00322 virtual ~CSSStyleSelectorList();
00323
00324 void append( DOM::CSSStyleSheetImpl *sheet,
00325 const DOM::DOMString &medium = "screen" );
00326
00327 void collect( QPtrList<DOM::CSSSelector> *selectorList, CSSOrderedPropertyList *propList,
00328 Source regular, Source important );
00329 };
00330
00331 }
00332 #endif