cssstyleselector.h [plain text]
#ifndef CSS_cssstyleselector_h_
#define CSS_cssstyleselector_h_
#include "DeprecatedString.h"
#include "RenderStyle.h"
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
namespace WebCore {
class CSSMutableStyleDeclaration;
class CSSPrimitiveValue;
class CSSProperty;
class CSSRuleData;
class CSSRuleDataList;
class CSSRuleList;
class CSSRuleSet;
class CSSSelector;
class CSSStyleRule;
class CSSStyleSheet;
class CSSValue;
class Document;
class Element;
class Frame;
class FrameView;
class KURL;
class MediaQueryEvaluator;
class Node;
class Settings;
class StyleSheet;
class StyleSheetList;
class StyledElement;
class StyleSelector
{
public:
enum State {
None = 0x00,
Hover = 0x01,
Focus = 0x02,
Active = 0x04,
Drag = 0x08
};
};
class CSSStyleSelector : public StyleSelector
{
public:
CSSStyleSelector(Document*, const String& userStyleSheet, StyleSheetList *styleSheets, bool strictParsing);
CSSStyleSelector(CSSStyleSheet *sheet);
~CSSStyleSelector();
static void loadDefaultStyle();
void initElementAndPseudoState(Element* e);
void initForStyleResolve(Element* e, RenderStyle* parentStyle);
RenderStyle *styleForElement(Element*, RenderStyle* parentStyle=0, bool allowSharing=true, bool resolveForRootDefault=false);
RenderStyle* pseudoStyleForElement(RenderStyle::PseudoId, Element*, RenderStyle* parentStyle=0);
RenderStyle* locateSharedStyle();
Node* locateCousinList(Element* parent);
bool canShareStyleWithElement(Node* n);
RefPtr<CSSRuleList> styleRulesForElement(Element* e, bool authorOnly);
RefPtr<CSSRuleList> pseudoStyleRulesForElement(Element* e, StringImpl* pseudoStyle, bool authorOnly);
bool strictParsing;
struct Encodedurl {
DeprecatedString host; DeprecatedString path;
DeprecatedString file;
} encodedurl;
void setEncodedURL(const KURL& url);
float fontSizeForKeyword(int keyword, bool quirksMode) const;
float largerFontSize(float size, bool quirksMode) const;
float smallerFontSize(float size, bool quirksMode) const;
void setFontSize(FontDescription& FontDescription, float size);
float getComputedSizeFromSpecifiedSize(bool isAbsoluteSize, float specifiedSize);
Color getColorFromPrimitiveValue(CSSPrimitiveValue* primitiveValue);
bool hasSelectorForAttribute(const AtomicString &attrname);
protected:
bool checkSelector(CSSSelector* selector, Element *e);
bool checkOneSelector(CSSSelector*, Element*, bool isSubSelector = false);
void checkForGenericFamilyChange(RenderStyle* aStyle, RenderStyle* aParentStyle);
void checkForTextSizeAdjust();
void adjustRenderStyle(RenderStyle* style, Element *e);
void addMatchedRule(CSSRuleData* rule) { m_matchedRules.append(rule); }
void addMatchedDeclaration(CSSMutableStyleDeclaration* decl) { m_matchedDecls.append(decl); }
void matchRules(CSSRuleSet* rules, int& firstRuleIndex, int& lastRuleIndex);
void matchRulesForList(CSSRuleDataList* rules, int& firstRuleIndex, int& lastRuleIndex);
void sortMatchedRules(unsigned start, unsigned end);
void applyDeclarations(bool firstPass, bool important, int startIndex, int endIndex);
static CSSStyleSheet* defaultSheet;
static CSSStyleSheet* quirksSheet;
static CSSStyleSheet* viewSourceSheet;
#if SVG_SUPPORT
static CSSStyleSheet* svgSheet;
#endif
static CSSRuleSet* defaultStyle;
static CSSRuleSet* defaultQuirksStyle;
static CSSRuleSet* defaultPrintStyle;
static CSSRuleSet* defaultViewSourceStyle;
CSSRuleSet* m_authorStyle;
CSSRuleSet* m_userStyle;
CSSStyleSheet* m_userSheet;
bool m_hasUAAppearance;
BorderData m_borderData;
BackgroundLayer m_backgroundData;
Color m_backgroundColor;
public:
static RenderStyle* styleNotYetAvailable;
private:
void init();
void matchUARules(int& firstUARule, int& lastUARule);
void updateFont();
void cacheBorderAndBackground();
void mapBackgroundAttachment(BackgroundLayer* layer, CSSValue* value);
void mapBackgroundClip(BackgroundLayer* layer, CSSValue* value);
void mapBackgroundComposite(BackgroundLayer* layer, CSSValue* value);
void mapBackgroundOrigin(BackgroundLayer* layer, CSSValue* value);
void mapBackgroundImage(BackgroundLayer* layer, CSSValue* value);
void mapBackgroundRepeat(BackgroundLayer* layer, CSSValue* value);
void mapBackgroundSize(BackgroundLayer* layer, CSSValue* value);
void mapBackgroundXPosition(BackgroundLayer* layer, CSSValue* value);
void mapBackgroundYPosition(BackgroundLayer* layer, CSSValue* value);
Vector<CSSMutableStyleDeclaration*> m_matchedDecls;
Vector<CSSRuleData*> m_matchedRules;
CSSRuleList* m_ruleList;
bool m_collectRulesOnly;
MediaQueryEvaluator* m_medium;
RenderStyle* m_rootDefaultStyle;
RenderStyle::PseudoId dynamicPseudo;
RenderStyle *style;
RenderStyle *parentStyle;
Element *element;
StyledElement *styledElement;
Node *parentNode;
RenderStyle::PseudoId pseudoStyle;
FrameView *view;
Frame *frame;
const Settings *settings;
bool fontDirty;
bool isXMLDoc;
HashSet<AtomicStringImpl *> m_selectorAttrs;
void applyProperty(int id, CSSValue *value);
#if SVG_SUPPORT
void applySVGProperty(int id, CSSValue *value);
#endif
};
class CSSRuleData {
public:
CSSRuleData(unsigned pos, CSSStyleRule* r, CSSSelector* sel, CSSRuleData* prev = 0)
:m_position(pos), m_rule(r), m_selector(sel), m_next(0) { if (prev) prev->m_next = this; }
~CSSRuleData() { delete m_next; }
unsigned position() { return m_position; }
CSSStyleRule* rule() { return m_rule; }
CSSSelector* selector() { return m_selector; }
CSSRuleData* next() { return m_next; }
private:
unsigned m_position;
CSSStyleRule* m_rule;
CSSSelector* m_selector;
CSSRuleData* m_next;
};
class CSSRuleDataList {
public:
CSSRuleDataList(unsigned pos, CSSStyleRule* rule, CSSSelector* sel)
{ m_first = m_last = new CSSRuleData(pos, rule, sel); }
~CSSRuleDataList() { delete m_first; }
CSSRuleData* first() { return m_first; }
CSSRuleData* last() { return m_last; }
void append(unsigned pos, CSSStyleRule* rule, CSSSelector* sel) {
m_last = new CSSRuleData(pos, rule, sel, m_last);
}
private:
CSSRuleData* m_first;
CSSRuleData* m_last;
};
}
#endif