cssstyleselector.h [plain text]
#ifndef _CSS_cssstyleselector_h_
#define _CSS_cssstyleselector_h_
#include <qptrlist.h>
#include "rendering/render_style.h"
#include "dom/dom_string.h"
class KHTMLSettings;
class KHTMLView;
class KHTMLPart;
class KURL;
namespace DOM {
class DocumentImpl;
class NodeImpl;
class ElementImpl;
class StyleSheetImpl;
class CSSStyleRuleImpl;
class CSSStyleSheetImpl;
class CSSSelector;
class CSSStyleDeclarationImpl;
class CSSProperty;
class StyleSheetListImpl;
class CSSValueImpl;
}
namespace khtml
{
class CSSStyleSelectorList;
class CSSOrderedRule;
class CSSOrderedProperty;
class CSSOrderedPropertyList;
class RenderStyle;
enum Source {
Default = 0,
NonCSSHint = 1,
User = 2,
Author = 3,
Inline = 4,
AuthorImportant = 5,
InlineImportant = 6,
UserImportant =7
};
class StyleSelector
{
public:
StyleSelector() {};
enum State {
None = 0x00,
Hover = 0x01,
Focus = 0x02,
Active = 0x04
};
};
class CSSStyleSelector : public StyleSelector
{
public:
CSSStyleSelector( DOM::DocumentImpl* doc, QString userStyleSheet, DOM::StyleSheetListImpl *styleSheets, const KURL &url,
bool _strictParsing );
CSSStyleSelector( DOM::CSSStyleSheetImpl *sheet );
~CSSStyleSelector();
void addSheet( DOM::CSSStyleSheetImpl *sheet );
static void loadDefaultStyle(const KHTMLSettings *s = 0);
static void clear();
RenderStyle *styleForElement(DOM::ElementImpl *e);
QValueList<int> fontSizes() const { return m_fontSizes; }
bool strictParsing;
struct Encodedurl {
QString host; QString path;
QString file;
} encodedurl;
void computeFontSizes(QPaintDeviceMetrics* paintDeviceMetrics);
void setFontSize(FontDef& fontDef, float size);
float getComputedSizeFromSpecifiedSize(bool isAbsoluteSize, float specifiedSize);
protected:
void checkSelector(int selector, DOM::ElementImpl *e);
bool checkOneSelector(DOM::CSSSelector *selector, DOM::ElementImpl *e);
void checkForGenericFamilyChange(RenderStyle* aStyle, RenderStyle* aParentStyle);
void buildLists();
void clearLists();
unsigned int addInlineDeclarations(DOM::ElementImpl* e, DOM::CSSStyleDeclarationImpl *decl,
unsigned int numProps);
void adjustRenderStyle(RenderStyle* style, DOM::ElementImpl *e);
static DOM::CSSStyleSheetImpl *defaultSheet;
static DOM::CSSStyleSheetImpl *quirksSheet;
static CSSStyleSelectorList *defaultStyle;
static CSSStyleSelectorList *defaultQuirksStyle;
static CSSStyleSelectorList *defaultPrintStyle;
CSSStyleSelectorList *authorStyle;
CSSStyleSelectorList *userStyle;
DOM::CSSStyleSheetImpl *userSheet;
public:
static RenderStyle* styleNotYetAvailable;
private:
void init();
public: enum SelectorState {
Unknown = 0,
Applies,
AppliesPseudo,
Invalid
};
enum SelectorMedia {
MediaAural = 1,
MediaBraille,
MediaEmboss,
MediaHandheld,
MediaPrint,
MediaProjection,
MediaScreen,
MediaTTY,
MediaTV
};
protected:
struct SelectorCache {
SelectorState state;
unsigned int props_size;
int *props;
};
unsigned int selectors_size;
DOM::CSSSelector **selectors;
SelectorCache *selectorCache;
unsigned int properties_size;
CSSOrderedProperty **properties;
QMemArray<CSSOrderedProperty> inlineProps;
QString m_medium;
CSSOrderedProperty **propsToApply;
CSSOrderedProperty **pseudoProps;
unsigned int propsToApplySize;
unsigned int pseudoPropsSize;
RenderStyle::PseudoId dynamicPseudo;
RenderStyle *style;
RenderStyle *parentStyle;
DOM::ElementImpl *element;
DOM::NodeImpl *parentNode;
KHTMLView *view;
KHTMLPart *part;
const KHTMLSettings *settings;
QPaintDeviceMetrics *paintDeviceMetrics;
QValueList<int> m_fontSizes;
float m_fixedScaleFactor; bool fontDirty;
bool isXMLDoc;
void applyRule(int id, DOM::CSSValueImpl *value);
};
class CSSOrderedProperty
{
public:
CSSOrderedProperty(DOM::CSSProperty *_prop, uint _selector,
bool first, Source source, unsigned int specificity,
unsigned int _position )
: prop ( _prop ), pseudoId( RenderStyle::NOPSEUDO ), selector( _selector ),
position( _position )
{
priority = (!first << 30) | (source << 24) | specificity;
}
bool operator < ( const CSSOrderedProperty &other ) const {
if (priority < other.priority) return true;
if (priority > other.priority) return false;
if (position < other.position) return true;
return false;
}
DOM::CSSProperty *prop;
RenderStyle::PseudoId pseudoId;
unsigned int selector;
unsigned int position;
Q_UINT32 priority;
};
class CSSOrderedPropertyList : public QPtrList<CSSOrderedProperty>
{
public:
virtual int compareItems(QPtrCollection::Item i1, QPtrCollection::Item i2);
void append(DOM::CSSStyleDeclarationImpl *decl, uint selector, uint specificity,
Source regular, Source important );
};
class CSSOrderedRule
{
public:
CSSOrderedRule(DOM::CSSStyleRuleImpl *r, DOM::CSSSelector *s, int _index);
~CSSOrderedRule();
DOM::CSSSelector *selector;
DOM::CSSStyleRuleImpl *rule;
int index;
};
class CSSStyleSelectorList : public QPtrList<CSSOrderedRule>
{
public:
CSSStyleSelectorList();
virtual ~CSSStyleSelectorList();
void append( DOM::CSSStyleSheetImpl *sheet,
const DOM::DOMString &medium = "screen" );
void collect( QPtrList<DOM::CSSSelector> *selectorList, CSSOrderedPropertyList *propList,
Source regular, Source important );
};
};
#endif