#ifndef StyleResolver_h
#define StyleResolver_h
#include "core/animation/KeyframeEffectModel.h"
#include "core/css/CSSFontSelectorClient.h"
#include "core/css/PseudoStyleRequest.h"
#include "core/css/RuleFeature.h"
#include "core/css/RuleSet.h"
#include "core/css/SelectorChecker.h"
#include "core/css/SelectorFilter.h"
#include "core/css/SiblingTraversalStrategies.h"
#include "core/css/TreeBoundaryCrossingRules.h"
#include "core/css/resolver/MatchedPropertiesCache.h"
#include "core/css/resolver/ScopedStyleResolver.h"
#include "core/css/resolver/ScopedStyleTree.h"
#include "core/css/resolver/StyleBuilder.h"
#include "core/css/resolver/StyleResolverState.h"
#include "core/css/resolver/StyleResourceLoader.h"
#include "heap/Handle.h"
#include "wtf/Deque.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include "wtf/ListHashSet.h"
#include "wtf/RefPtr.h"
#include "wtf/Vector.h"
namespace WebCore {
class CSSAnimationUpdate;
class CSSFontSelector;
class CSSRuleList;
class CSSSelector;
class CSSStyleSheet;
class CSSValue;
class ContainerNode;
class Document;
class DocumentTimeline;
class Element;
class ElementRuleCollector;
class KeyframeList;
class KeyframeValue;
class MediaQueryEvaluator;
class MediaQueryResult;
class RuleData;
class Settings;
class StyleKeyframe;
class StylePropertySet;
class StyleResolverStats;
class StyleRule;
class StyleRuleKeyframes;
class StyleRulePage;
class ViewportStyleResolver;
class MatchResult;
enum StyleSharingBehavior {
AllowStyleSharing,
DisallowStyleSharing,
};
enum RuleMatchingBehavior {
MatchAllRules,
MatchAllRulesExcludingSMIL,
MatchOnlyUserAgentRules,
};
const unsigned styleSharingListSize = 40;
typedef WTF::Deque<Element*, styleSharingListSize> StyleSharingList;
struct CSSPropertyValue {
STACK_ALLOCATED();
public:
CSSPropertyValue(CSSPropertyID property, CSSValue* value)
: property(property), value(value) { }
CSSPropertyValue(CSSPropertyID, const StylePropertySet&);
CSSPropertyID property;
RawPtrWillBeMember<CSSValue> value;
};
class StyleResolver FINAL : public CSSFontSelectorClient {
WTF_MAKE_NONCOPYABLE(StyleResolver); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
explicit StyleResolver(Document&);
virtual ~StyleResolver();
void pushParentElement(Element&);
void popParentElement(Element&);
void pushParentShadowRoot(const ShadowRoot&);
void popParentShadowRoot(const ShadowRoot&);
PassRefPtr<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle = 0, StyleSharingBehavior = AllowStyleSharing,
RuleMatchingBehavior = MatchAllRules);
PassRefPtr<RenderStyle> styleForKeyframe(Element*, const RenderStyle&, RenderStyle* parentStyle, const StyleKeyframe*, const AtomicString& animationName);
static PassRefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> createKeyframeEffectModel(Element&, const WillBeHeapVector<RefPtrWillBeMember<MutableStylePropertySet> >&, AnimatableValueKeyframeVector&);
PassRefPtr<RenderStyle> pseudoStyleForElement(Element*, const PseudoStyleRequest&, RenderStyle* parentStyle);
PassRefPtr<RenderStyle> styleForPage(int pageIndex);
PassRefPtr<RenderStyle> defaultStyleForElement();
PassRefPtr<RenderStyle> styleForText(Text*);
static PassRefPtr<RenderStyle> styleForDocument(Document&, CSSFontSelector* = 0);
Document& document() { return m_document; }
void appendAuthorStyleSheets(unsigned firstNew, const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >&);
void resetAuthorStyle(const ContainerNode*);
void finishAppendAuthorStyleSheets();
TreeBoundaryCrossingRules& treeBoundaryCrossingRules() { return m_treeBoundaryCrossingRules; }
void processScopedRules(const RuleSet& authorRules, const KURL&, ContainerNode* scope = 0);
void lazyAppendAuthorStyleSheets(unsigned firstNew, const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >&);
void removePendingAuthorStyleSheets(const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >&);
void appendPendingAuthorStyleSheets();
bool hasPendingAuthorStyleSheets() const { return m_pendingStyleSheets.size() > 0 || m_needCollectFeatures; }
SelectorFilter& selectorFilter() { return m_selectorFilter; }
void setBuildScopedStyleTreeInDocumentOrder(bool enabled) { m_styleTree.setBuildInDocumentOrder(enabled); }
bool buildScopedStyleTreeInDocumentOrder() const { return m_styleTree.buildInDocumentOrder(); }
bool styleTreeHasOnlyScopedResolverForDocument() const { return m_styleTree.hasOnlyScopedResolverForDocument(); }
ScopedStyleResolver* styleTreeScopedStyleResolverForDocument() const { return m_styleTree.scopedStyleResolverForDocument(); }
ScopedStyleResolver* ensureScopedStyleResolver(ContainerNode* scope)
{
ASSERT(scope);
return m_styleTree.ensureScopedStyleResolver(*scope);
}
void styleTreeResolveScopedKeyframesRules(const Element* element, Vector<ScopedStyleResolver*, 8>& resolvers)
{
m_styleTree.resolveScopedKeyframesRules(element, resolvers);
}
enum CSSRuleFilter {
UAAndUserCSSRules = 1 << 1,
AuthorCSSRules = 1 << 2,
EmptyCSSRules = 1 << 3,
CrossOriginCSSRules = 1 << 4,
AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCSSRules,
AllCSSRules = AllButEmptyCSSRules | EmptyCSSRules,
};
PassRefPtrWillBeRawPtr<CSSRuleList> cssRulesForElement(Element*, unsigned rulesToInclude = AllButEmptyCSSRules);
PassRefPtrWillBeRawPtr<CSSRuleList> pseudoCSSRulesForElement(Element*, PseudoId, unsigned rulesToInclude = AllButEmptyCSSRules);
PassRefPtrWillBeRawPtr<StyleRuleList> styleRulesForElement(Element*, unsigned rulesToInclude);
void applyPropertiesToStyle(const CSSPropertyValue* properties, size_t count, RenderStyle*);
ViewportStyleResolver* viewportStyleResolver() { return m_viewportStyleResolver.get(); }
void addMediaQueryResults(const MediaQueryResultList&);
MediaQueryResultList* viewportDependentMediaQueryResults() { return &m_viewportDependentMediaQueryResults; }
bool hasViewportDependentMediaQueries() const { return !m_viewportDependentMediaQueryResults.isEmpty(); }
bool mediaQueryAffectedByViewportChange() const;
void invalidateMatchedPropertiesCache();
void notifyResizeForViewportUnits();
static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; }
RuleFeatureSet& ensureUpdatedRuleFeatureSet()
{
if (hasPendingAuthorStyleSheets())
appendPendingAuthorStyleSheets();
return m_features;
}
RuleFeatureSet& ruleFeatureSet()
{
return m_features;
}
StyleSharingList& styleSharingList() { return m_styleSharingList; }
bool hasRulesForId(const AtomicString&) const;
void addToStyleSharingList(Element&);
void clearStyleSharingList();
StyleResolverStats* stats() { return m_styleResolverStats.get(); }
StyleResolverStats* statsTotals() { return m_styleResolverStatsTotals.get(); }
enum StatsReportType { ReportDefaultStats, ReportSlowStats };
void enableStats(StatsReportType = ReportDefaultStats);
void disableStats();
void printStats();
unsigned accessCount() const { return m_accessCount; }
void didAccess() { ++m_accessCount; }
PassRefPtr<PseudoElement> createPseudoElementIfNeeded(Element& parent, PseudoId);
virtual void trace(Visitor*) OVERRIDE;
private:
virtual void fontsNeedUpdate(CSSFontSelector*) OVERRIDE;
private:
void initWatchedSelectorRules(const WillBeHeapVector<RefPtrWillBeMember<StyleRule> >& watchedSelectors);
void addTreeBoundaryCrossingRules(const WillBeHeapVector<MinimalRuleData>&, ContainerNode* scope);
void updateFont(StyleResolverState&);
void loadPendingResources(StyleResolverState&);
void appendCSSStyleSheet(CSSStyleSheet*);
void collectPseudoRulesForElement(Element*, ElementRuleCollector&, PseudoId, unsigned rulesToInclude);
void matchUARules(ElementRuleCollector&, RuleSet*);
void matchAuthorRules(Element*, ElementRuleCollector&, bool includeEmptyRules);
void matchAuthorRulesForShadowHost(Element*, ElementRuleCollector&, bool includeEmptyRules, Vector<ScopedStyleResolver*, 8>& resolvers, Vector<ScopedStyleResolver*, 8>& resolversInShadowTree);
void matchAllRules(StyleResolverState&, ElementRuleCollector&, bool includeSMILProperties);
void matchUARules(ElementRuleCollector&);
void matchWatchSelectorRules(ElementRuleCollector&);
void collectFeatures();
void collectTreeBoundaryCrossingRules(Element*, ElementRuleCollector&, bool includeEmptyRules);
void resetRuleFeatures();
bool fastRejectSelector(const RuleData&) const;
void applyMatchedProperties(StyleResolverState&, const MatchResult&);
void applyAnimatedProperties(StyleResolverState&, Element* animatingElement);
enum StyleApplicationPass {
AnimationProperties,
HighPriorityProperties,
LowPriorityProperties
};
template <StyleResolver::StyleApplicationPass pass>
static inline bool isPropertyForPass(CSSPropertyID);
template <StyleApplicationPass pass>
void applyMatchedProperties(StyleResolverState&, const MatchResult&, bool important, const RuleRange&, bool inheritedOnly);
template <StyleApplicationPass pass>
void applyProperties(StyleResolverState&, const StylePropertySet* properties, StyleRule*, bool isImportant, bool inheritedOnly, PropertyWhitelistType = PropertyWhitelistNone);
template <StyleApplicationPass pass>
void applyAnimatedProperties(StyleResolverState&, const WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation> >&);
void matchPageRules(MatchResult&, RuleSet*, bool isLeftPage, bool isFirstPage, const String& pageName);
void matchPageRulesForList(WillBeHeapVector<RawPtrWillBeMember<StyleRulePage> >& matchedRules, const WillBeHeapVector<RawPtrWillBeMember<StyleRulePage> >&, bool isLeftPage, bool isFirstPage, const String& pageName);
void collectViewportRules();
Settings* documentSettings() { return m_document.settings(); }
bool isLeftPage(int pageIndex) const;
bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); }
bool isFirstPage(int pageIndex) const;
String pageName(int pageIndex) const;
bool pseudoStyleForElementInternal(Element&, const PseudoStyleRequest&, RenderStyle* parentStyle, StyleResolverState&);
typedef WillBeHeapHashMap<StringImpl*, RefPtrWillBeMember<StyleRuleKeyframes> > KeyframesRuleMap;
KeyframesRuleMap m_keyframesRuleMap;
static RenderStyle* s_styleNotYetAvailable;
void cacheBorderAndBackground();
MatchedPropertiesCache m_matchedPropertiesCache;
OwnPtr<MediaQueryEvaluator> m_medium;
MediaQueryResultList m_viewportDependentMediaQueryResults;
RefPtr<RenderStyle> m_rootDefaultStyle;
Document& m_document;
SelectorFilter m_selectorFilter;
OwnPtrWillBeMember<ViewportStyleResolver> m_viewportStyleResolver;
ListHashSet<CSSStyleSheet*, 16> m_pendingStyleSheets;
ScopedStyleTree m_styleTree;
RuleFeatureSet m_features;
OwnPtrWillBeMember<RuleSet> m_siblingRuleSet;
OwnPtrWillBeMember<RuleSet> m_uncommonAttributeRuleSet;
OwnPtrWillBeMember<RuleSet> m_watchedSelectorsRules;
TreeBoundaryCrossingRules m_treeBoundaryCrossingRules;
bool m_needCollectFeatures;
StyleResourceLoader m_styleResourceLoader;
StyleSharingList m_styleSharingList;
OwnPtr<StyleResolverStats> m_styleResolverStats;
OwnPtr<StyleResolverStats> m_styleResolverStatsTotals;
unsigned m_styleResolverStatsSequence;
unsigned m_accessCount;
};
}
#endif