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