ElementRuleCollector.h [plain text]
#ifndef ElementRuleCollector_h
#define ElementRuleCollector_h
#include "MediaQueryEvaluator.h"
#include "SelectorChecker.h"
#include "StyleResolver.h"
#include <memory>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class DocumentRuleSets;
class MatchRequest;
class RenderRegion;
class RuleData;
class RuleSet;
class SelectorFilter;
struct MatchedRule {
const RuleData* ruleData;
unsigned specificity;
unsigned treeContextOrdinal;
};
class ElementRuleCollector {
public:
ElementRuleCollector(const Element&, const DocumentRuleSets&, const SelectorFilter*);
ElementRuleCollector(const Element&, const RuleSet& authorStyle, const SelectorFilter*);
void matchAllRules(bool matchAuthorAndUserStyles, bool includeSMILProperties);
void matchUARules();
void matchAuthorRules(bool includeEmptyRules);
void matchUserRules(bool includeEmptyRules);
void setMode(SelectorChecker::Mode mode) { m_mode = mode; }
void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyleRequest = request; }
void setSameOriginOnly(bool f) { m_sameOriginOnly = f; }
void setRegionForStyling(const RenderRegion* regionForStyling) { m_regionForStyling = regionForStyling; }
void setMedium(const MediaQueryEvaluator* medium) { m_isPrintStyle = medium->mediaTypeMatchSpecific("print"); }
bool hasAnyMatchingRules(const RuleSet*);
StyleResolver::MatchResult& matchedResult();
const Vector<RefPtr<StyleRule>>& matchedRuleList() const;
bool hasMatchedRules() const { return !m_matchedRules.isEmpty(); }
void clearMatchedRules();
const PseudoIdSet& matchedPseudoElementIds() const { return m_matchedPseudoElementIds; }
const Style::Relations& styleRelations() const { return m_styleRelations; }
bool didMatchUncommonAttributeSelector() const { return m_didMatchUncommonAttributeSelector; }
private:
void addElementStyleProperties(const StyleProperties*, bool isCacheable = true);
void matchUARules(RuleSet*);
void matchHostPseudoClassRules(MatchRequest&, StyleResolver::RuleRange&);
void matchSlottedPseudoElementRules(MatchRequest&, StyleResolver::RuleRange&);
std::unique_ptr<RuleSet::RuleDataVector> collectSlottedPseudoElementRulesForSlot(bool includeEmptyRules);
void collectMatchingRules(const MatchRequest&, StyleResolver::RuleRange&);
void collectMatchingRulesForRegion(const MatchRequest&, StyleResolver::RuleRange&);
void collectMatchingRulesForList(const RuleSet::RuleDataVector*, const MatchRequest&, StyleResolver::RuleRange&);
bool ruleMatches(const RuleData&, unsigned &specificity);
void sortMatchedRules();
void sortAndTransferMatchedRules();
void addMatchedRule(const RuleData&, unsigned specificity, unsigned treeContextOrdinal, StyleResolver::RuleRange&);
const Element& m_element;
const RuleSet& m_authorStyle;
const RuleSet* m_userStyle { nullptr };
const SelectorFilter* m_selectorFilter { nullptr };
bool m_isPrintStyle { false };
const RenderRegion* m_regionForStyling { nullptr };
PseudoStyleRequest m_pseudoStyleRequest { NOPSEUDO };
bool m_sameOriginOnly { false };
SelectorChecker::Mode m_mode { SelectorChecker::Mode::ResolvingStyle };
bool m_isMatchingSlottedPseudoElements { false };
Vector<std::unique_ptr<RuleSet::RuleDataVector>> m_keepAliveSlottedPseudoElementRules;
Vector<MatchedRule, 64> m_matchedRules;
Vector<RefPtr<StyleRule>> m_matchedRuleList;
bool m_didMatchUncommonAttributeSelector { false };
StyleResolver::MatchResult m_result;
Style::Relations m_styleRelations;
PseudoIdSet m_matchedPseudoElementIds;
};
}
#endif // ElementRuleCollector_h