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 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
00061
00062
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
00087
00088
00089
00090
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;
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
00148
00149
void checkSelector(
int selector, DOM::ElementImpl *e);
00150
00151
bool checkOneSelector(DOM::CSSSelector *selector, DOM::ElementImpl *e);
00152
00153
#ifdef APPLE_CHANGES
00154
00155
00156
void checkForGenericFamilyChange(RenderStyle* aStyle, RenderStyle* aParentStyle);
00157
#endif
00158
00159
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:
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
00248
00249
00250
00251
00252
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
00283
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