Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: Source/core/css/resolver/ScopedStyleResolver.h

Issue 23567016: Have ScopedStyleResolver deal with ContainerNode references, not pointers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/css/resolver/ScopedStyleResolver.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
4 * Copyright (C) 2012 Google Inc. All rights reserved. 4 * Copyright (C) 2012 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 class ElementRuleCollector; 43 class ElementRuleCollector;
44 class MediaQueryEvaluator; 44 class MediaQueryEvaluator;
45 class PageRuleCollector; 45 class PageRuleCollector;
46 class ShadowRoot; 46 class ShadowRoot;
47 class StyleSheetContents; 47 class StyleSheetContents;
48 48
49 // This class selects a RenderStyle for a given element based on a collection of stylesheets. 49 // This class selects a RenderStyle for a given element based on a collection of stylesheets.
50 class ScopedStyleResolver { 50 class ScopedStyleResolver {
51 WTF_MAKE_NONCOPYABLE(ScopedStyleResolver); WTF_MAKE_FAST_ALLOCATED; 51 WTF_MAKE_NONCOPYABLE(ScopedStyleResolver); WTF_MAKE_FAST_ALLOCATED;
52 public: 52 public:
53 static PassOwnPtr<ScopedStyleResolver> create(const ContainerNode* scopingNo de) { return adoptPtr(new ScopedStyleResolver(scopingNode)); } 53 static PassOwnPtr<ScopedStyleResolver> create(const ContainerNode& scopingNo de) { return adoptPtr(new ScopedStyleResolver(scopingNode)); }
54 54
55 static const ContainerNode* scopingNodeFor(const CSSStyleSheet*); 55 static const ContainerNode* scopingNodeFor(const CSSStyleSheet*);
56 56
57 const ContainerNode* scopingNode() const { return m_scopingNode; } 57 const ContainerNode& scopingNode() const { return m_scopingNode; }
58 const TreeScope* treeScope() const { return m_scopingNode->treeScope(); } 58 const TreeScope* treeScope() const { return m_scopingNode.treeScope(); }
59 void prepareEmptyRuleSet() { m_authorStyle = RuleSet::create(); } 59 void prepareEmptyRuleSet() { m_authorStyle = RuleSet::create(); }
60 void setParent(ScopedStyleResolver* newParent) { m_parent = newParent; } 60 void setParent(ScopedStyleResolver* newParent) { m_parent = newParent; }
61 ScopedStyleResolver* parent() { return m_parent; } 61 ScopedStyleResolver* parent() { return m_parent; }
62 62
63 bool hasOnlyEmptyRuleSets() const { return !m_authorStyle->ruleCount() && m_ atHostRules.isEmpty(); } 63 bool hasOnlyEmptyRuleSets() const { return !m_authorStyle->ruleCount() && m_ atHostRules.isEmpty(); }
64 64
65 public: 65 public:
66 bool checkRegionStyle(Element*); 66 bool checkRegionStyle(Element*);
67 const StyleRuleKeyframes* keyframeStylesForAnimation(const StringImpl* anima tionName); 67 const StyleRuleKeyframes* keyframeStylesForAnimation(const StringImpl* anima tionName);
68 void addKeyframeStyle(PassRefPtr<StyleRuleKeyframes>); 68 void addKeyframeStyle(PassRefPtr<StyleRuleKeyframes>);
69 69
70 void matchHostRules(ElementRuleCollector&, bool includeEmptyRules); 70 void matchHostRules(ElementRuleCollector&, bool includeEmptyRules);
71 void matchAuthorRules(ElementRuleCollector&, bool includeEmptyRules, bool ap plyAuthorStyles); 71 void matchAuthorRules(ElementRuleCollector&, bool includeEmptyRules, bool ap plyAuthorStyles);
72 void collectMatchingAuthorRules(ElementRuleCollector&, bool includeEmptyRule s, bool applyAuthorStyles, CascadeScope, CascadeOrder = ignoreCascadeOrder); 72 void collectMatchingAuthorRules(ElementRuleCollector&, bool includeEmptyRule s, bool applyAuthorStyles, CascadeScope, CascadeOrder = ignoreCascadeOrder);
73 void matchPageRules(PageRuleCollector&); 73 void matchPageRules(PageRuleCollector&);
74 void addRulesFromSheet(StyleSheetContents*, const MediaQueryEvaluator&, Styl eResolver*); 74 void addRulesFromSheet(StyleSheetContents*, const MediaQueryEvaluator&, Styl eResolver*);
75 void addHostRule(StyleRuleHost*, bool hasDocumentSecurityOrigin, const Conta inerNode* scopingNode); 75 void addHostRule(StyleRuleHost*, bool hasDocumentSecurityOrigin, const Conta inerNode* scopingNode);
76 void collectFeaturesTo(RuleFeatureSet&); 76 void collectFeaturesTo(RuleFeatureSet&);
77 void resetAuthorStyle(); 77 void resetAuthorStyle();
78 void resetAtHostRules(const ShadowRoot*); 78 void resetAtHostRules(const ShadowRoot*);
79 void collectViewportRulesTo(StyleResolver*) const; 79 void collectViewportRulesTo(StyleResolver*) const;
80 80
81 private: 81 private:
82 ScopedStyleResolver() : m_scopingNode(0), m_parent(0) { } 82 explicit ScopedStyleResolver(const ContainerNode& scopingNode) : m_scopingNo de(scopingNode), m_parent(0) { }
83 ScopedStyleResolver(const ContainerNode* scopingNode) : m_scopingNode(scopin gNode), m_parent(0) { }
84 83
85 RuleSet* ensureAtHostRuleSetFor(const ShadowRoot*); 84 RuleSet* ensureAtHostRuleSetFor(const ShadowRoot*);
86 RuleSet* atHostRuleSetFor(const ShadowRoot*) const; 85 RuleSet* atHostRuleSetFor(const ShadowRoot*) const;
87 86
88 const ContainerNode* m_scopingNode; 87 const ContainerNode& m_scopingNode;
89 ScopedStyleResolver* m_parent; 88 ScopedStyleResolver* m_parent;
90 89
91 OwnPtr<RuleSet> m_authorStyle; 90 OwnPtr<RuleSet> m_authorStyle;
92 HashMap<const ShadowRoot*, OwnPtr<RuleSet> > m_atHostRules; 91 HashMap<const ShadowRoot*, OwnPtr<RuleSet> > m_atHostRules;
93 92
94 typedef HashMap<const StringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRul eMap; 93 typedef HashMap<const StringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRul eMap;
95 KeyframesRuleMap m_keyframesRuleMap; 94 KeyframesRuleMap m_keyframesRuleMap;
96 }; 95 };
97 96
98 class ScopedStyleTree { 97 class ScopedStyleTree {
99 WTF_MAKE_NONCOPYABLE(ScopedStyleTree); WTF_MAKE_FAST_ALLOCATED; 98 WTF_MAKE_NONCOPYABLE(ScopedStyleTree); WTF_MAKE_FAST_ALLOCATED;
100 public: 99 public:
101 ScopedStyleTree() : m_scopedResolverForDocument(0), m_buildInDocumentOrder(t rue) { } 100 ScopedStyleTree() : m_scopedResolverForDocument(0), m_buildInDocumentOrder(t rue) { }
102 101
103 ScopedStyleResolver* ensureScopedStyleResolver(const ContainerNode* scopingN ode); 102 ScopedStyleResolver* ensureScopedStyleResolver(const ContainerNode& scopingN ode);
104 ScopedStyleResolver* scopedStyleResolverFor(const ContainerNode* scopingNode ); 103 ScopedStyleResolver* scopedStyleResolverFor(const ContainerNode& scopingNode );
105 ScopedStyleResolver* addScopedStyleResolver(const ContainerNode* scopingNode , bool& isNewEntry); 104 ScopedStyleResolver* addScopedStyleResolver(const ContainerNode& scopingNode , bool& isNewEntry);
106 void clear(); 105 void clear();
107 106
108 // for fast-path. 107 // for fast-path.
109 bool hasOnlyScopedResolverForDocument() const { return m_scopedResolverForDo cument && m_authorStyles.size() == 1; } 108 bool hasOnlyScopedResolverForDocument() const { return m_scopedResolverForDo cument && m_authorStyles.size() == 1; }
110 ScopedStyleResolver* scopedStyleResolverForDocument() { return m_scopedResol verForDocument; } 109 ScopedStyleResolver* scopedStyleResolverForDocument() { return m_scopedResol verForDocument; }
111 110
112 void resolveScopedStyles(const Element*, Vector<ScopedStyleResolver*, 8>&); 111 void resolveScopedStyles(const Element*, Vector<ScopedStyleResolver*, 8>&);
113 void collectScopedResolversForHostedShadowTrees(const Element*, Vector<Scope dStyleResolver*, 8>&); 112 void collectScopedResolversForHostedShadowTrees(const Element*, Vector<Scope dStyleResolver*, 8>&);
114 void resolveScopedKeyframesRules(const Element*, Vector<ScopedStyleResolver* , 8>&); 113 void resolveScopedKeyframesRules(const Element*, Vector<ScopedStyleResolver* , 8>&);
115 ScopedStyleResolver* scopedResolverFor(const Element*); 114 ScopedStyleResolver* scopedResolverFor(const Element*);
116 115
117 void remove(const ContainerNode* scopingNode); 116 void remove(const ContainerNode* scopingNode);
118 117
119 void pushStyleCache(const ContainerNode* scopingNode, const ContainerNode* p arent); 118 void pushStyleCache(const ContainerNode& scopingNode, const ContainerNode* p arent);
120 void popStyleCache(const ContainerNode* scopingNode); 119 void popStyleCache(const ContainerNode& scopingNode);
121 120
122 void collectFeaturesTo(RuleFeatureSet& features); 121 void collectFeaturesTo(RuleFeatureSet& features);
123 void setBuildInDocumentOrder(bool enabled) { m_buildInDocumentOrder = enable d; } 122 void setBuildInDocumentOrder(bool enabled) { m_buildInDocumentOrder = enable d; }
124 bool buildInDocumentOrder() const { return m_buildInDocumentOrder; } 123 bool buildInDocumentOrder() const { return m_buildInDocumentOrder; }
125 124
126 private: 125 private:
127 void setupScopedStylesTree(ScopedStyleResolver* target); 126 void setupScopedStylesTree(ScopedStyleResolver* target);
128 127
129 bool cacheIsValid(const ContainerNode* parent) const { return parent && pare nt == m_cache.nodeForScopedStyles; } 128 bool cacheIsValid(const ContainerNode* parent) const { return parent && pare nt == m_cache.nodeForScopedStyles; }
130 void resolveStyleCache(const ContainerNode* scopingNode); 129 void resolveStyleCache(const ContainerNode* scopingNode);
(...skipping 23 matching lines...) Expand all
154 { 153 {
155 if (!cacheIsValid(element)) 154 if (!cacheIsValid(element))
156 resolveStyleCache(element); 155 resolveStyleCache(element);
157 156
158 return m_cache.scopedResolver; 157 return m_cache.scopedResolver;
159 } 158 }
160 159
161 } // namespace WebCore 160 } // namespace WebCore
162 161
163 #endif // ScopedStyleResolver_h 162 #endif // ScopedStyleResolver_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/css/resolver/ScopedStyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698