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

Side by Side Diff: Source/core/css/ElementRuleCollector.h

Issue 843773002: Only match style from element's TreeScope for normal rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed custom pseudo and ::cue regressions Created 5 years, 11 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
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 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 21 matching lines...) Expand all
32 32
33 namespace blink { 33 namespace blink {
34 34
35 class CSSStyleSheet; 35 class CSSStyleSheet;
36 class CSSRuleList; 36 class CSSRuleList;
37 class RuleData; 37 class RuleData;
38 class RuleSet; 38 class RuleSet;
39 class SelectorFilter; 39 class SelectorFilter;
40 class StaticCSSRuleList; 40 class StaticCSSRuleList;
41 41
42 typedef unsigned CascadeScope;
43 typedef unsigned CascadeOrder; 42 typedef unsigned CascadeOrder;
44 43
45 const CascadeScope ignoreCascadeScope = 0;
46 const CascadeOrder ignoreCascadeOrder = 0; 44 const CascadeOrder ignoreCascadeOrder = 0;
47 45
48 class MatchedRule { 46 class MatchedRule {
49 ALLOW_ONLY_INLINE_ALLOCATION(); 47 ALLOW_ONLY_INLINE_ALLOCATION();
50 public: 48 public:
51 MatchedRule(const RuleData* ruleData, unsigned specificity, CascadeScope cas cadeScope, CascadeOrder cascadeOrder, unsigned styleSheetIndex, const CSSStyleSh eet* parentStyleSheet) 49 MatchedRule(const RuleData* ruleData, unsigned specificity, CascadeOrder cas cadeOrder, unsigned styleSheetIndex, const CSSStyleSheet* parentStyleSheet)
52 : m_ruleData(ruleData) 50 : m_ruleData(ruleData)
53 , m_specificity(specificity) 51 , m_specificity(specificity)
54 , m_cascadeScope(cascadeScope)
55 , m_parentStyleSheet(parentStyleSheet) 52 , m_parentStyleSheet(parentStyleSheet)
56 { 53 {
57 ASSERT(m_ruleData); 54 ASSERT(m_ruleData);
58 static const unsigned BitsForPositionInRuleData = 18; 55 static const unsigned BitsForPositionInRuleData = 18;
59 static const unsigned BitsForStyleSheetIndex = 32; 56 static const unsigned BitsForStyleSheetIndex = 32;
60 m_position = ((uint64_t)cascadeOrder << (BitsForStyleSheetIndex + BitsFo rPositionInRuleData)) + ((uint64_t)styleSheetIndex << BitsForPositionInRuleData) + m_ruleData->position(); 57 m_position = ((uint64_t)cascadeOrder << (BitsForStyleSheetIndex + BitsFo rPositionInRuleData)) + ((uint64_t)styleSheetIndex << BitsForPositionInRuleData) + m_ruleData->position();
61 } 58 }
62 59
63 const RuleData* ruleData() const { return m_ruleData; } 60 const RuleData* ruleData() const { return m_ruleData; }
64 uint32_t cascadeScope() const { return m_cascadeScope; }
65 uint64_t position() const { return m_position; } 61 uint64_t position() const { return m_position; }
66 unsigned specificity() const { return ruleData()->specificity() + m_specific ity; } 62 unsigned specificity() const { return ruleData()->specificity() + m_specific ity; }
67 const CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } 63 const CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; }
68 void trace(Visitor* visitor) 64 void trace(Visitor* visitor)
69 { 65 {
70 visitor->trace(m_parentStyleSheet); 66 visitor->trace(m_parentStyleSheet);
71 } 67 }
72 68
73 private: 69 private:
74 // FIXME: Oilpan: RuleData is in the oilpan heap and this pointer 70 // FIXME: Oilpan: RuleData is in the oilpan heap and this pointer
75 // really should be traced. However, RuleData objects are 71 // really should be traced. However, RuleData objects are
76 // allocated inside larger TerminatedArray objects and we cannot 72 // allocated inside larger TerminatedArray objects and we cannot
77 // trace a raw rule data pointer at this point. 73 // trace a raw rule data pointer at this point.
78 const RuleData* m_ruleData; 74 const RuleData* m_ruleData;
79 unsigned m_specificity; 75 unsigned m_specificity;
80 CascadeScope m_cascadeScope;
81 uint64_t m_position; 76 uint64_t m_position;
82 RawPtrWillBeMember<const CSSStyleSheet> m_parentStyleSheet; 77 RawPtrWillBeMember<const CSSStyleSheet> m_parentStyleSheet;
83 }; 78 };
84 79
85 } // namespace blink 80 } // namespace blink
86 81
87 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedRule); 82 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedRule);
88 83
89 namespace blink { 84 namespace blink {
90 85
(...skipping 29 matching lines...) Expand all
120 115
121 void setMatchingUARules(bool matchingUARules) { m_matchingUARules = matching UARules; } 116 void setMatchingUARules(bool matchingUARules) { m_matchingUARules = matching UARules; }
122 void setScopeContainsLastMatchedElement(bool scopeContainsLastMatchedElement ) { m_scopeContainsLastMatchedElement = scopeContainsLastMatchedElement; } 117 void setScopeContainsLastMatchedElement(bool scopeContainsLastMatchedElement ) { m_scopeContainsLastMatchedElement = scopeContainsLastMatchedElement; }
123 bool scopeContainsLastMatchedElement() const { return m_scopeContainsLastMat chedElement; } 118 bool scopeContainsLastMatchedElement() const { return m_scopeContainsLastMat chedElement; }
124 bool hasAnyMatchingRules(RuleSet*); 119 bool hasAnyMatchingRules(RuleSet*);
125 120
126 MatchResult& matchedResult(); 121 MatchResult& matchedResult();
127 PassRefPtrWillBeRawPtr<StyleRuleList> matchedStyleRuleList(); 122 PassRefPtrWillBeRawPtr<StyleRuleList> matchedStyleRuleList();
128 PassRefPtrWillBeRawPtr<CSSRuleList> matchedCSSRuleList(); 123 PassRefPtrWillBeRawPtr<CSSRuleList> matchedCSSRuleList();
129 124
130 void collectMatchingRules(const MatchRequest&, RuleRange&, CascadeScope = ig noreCascadeScope, CascadeOrder = ignoreCascadeOrder, bool matchingTreeBoundaryRu les = false); 125 void collectMatchingRules(const MatchRequest&, RuleRange&, CascadeOrder = ig noreCascadeOrder, bool matchingTreeBoundaryRules = false);
131 void collectMatchingShadowHostRules(const MatchRequest&, RuleRange&, Cascade Scope = ignoreCascadeScope, CascadeOrder = ignoreCascadeOrder, bool matchingTree BoundaryRules = false); 126 void collectMatchingShadowHostRules(const MatchRequest&, RuleRange&, Cascade Order = ignoreCascadeOrder, bool matchingTreeBoundaryRules = false);
132 void sortAndTransferMatchedRules(); 127 void sortAndTransferMatchedRules();
133 void clearMatchedRules(); 128 void clearMatchedRules();
134 void addElementStyleProperties(const StylePropertySet*, bool isCacheable = t rue); 129 void addElementStyleProperties(const StylePropertySet*, bool isCacheable = t rue);
135 130
136 private: 131 private:
137 void collectRuleIfMatches(const RuleData&, CascadeScope, CascadeOrder, const MatchRequest&, RuleRange&); 132 void collectRuleIfMatches(const RuleData&, CascadeOrder, const MatchRequest& , RuleRange&);
138 133
139 template<typename RuleDataListType> 134 template<typename RuleDataListType>
140 void collectMatchingRulesForList(const RuleDataListType* rules, CascadeScope cascadeScope, CascadeOrder cascadeOrder, const MatchRequest& matchRequest, Rule Range& ruleRange) 135 void collectMatchingRulesForList(const RuleDataListType* rules, CascadeOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange)
141 { 136 {
142 if (!rules) 137 if (!rules)
143 return; 138 return;
144 139
145 for (const auto& rule : *rules) 140 for (const auto& rule : *rules)
146 collectRuleIfMatches(rule, cascadeScope, cascadeOrder, matchRequest, ruleRange); 141 collectRuleIfMatches(rule, cascadeOrder, matchRequest, ruleRange);
147 } 142 }
148 143
149 bool ruleMatches(const RuleData&, const ContainerNode* scope, SelectorChecke r::MatchResult*); 144 bool ruleMatches(const RuleData&, const ContainerNode* scope, SelectorChecke r::MatchResult*);
150 145
151 CSSRuleList* nestedRuleList(CSSRule*); 146 CSSRuleList* nestedRuleList(CSSRule*);
152 template<class CSSRuleCollection> 147 template<class CSSRuleCollection>
153 CSSRule* findStyleRule(CSSRuleCollection*, StyleRule*); 148 CSSRule* findStyleRule(CSSRuleCollection*, StyleRule*);
154 void appendCSSOMWrapperForRule(CSSStyleSheet*, StyleRule*); 149 void appendCSSOMWrapperForRule(CSSStyleSheet*, StyleRule*);
155 150
156 void sortMatchedRules(); 151 void sortMatchedRules();
157 void addMatchedRule(const RuleData*, unsigned specificity, CascadeScope, Cas cadeOrder, unsigned styleSheetIndex, const CSSStyleSheet* parentStyleSheet); 152 void addMatchedRule(const RuleData*, unsigned specificity, CascadeOrder, uns igned styleSheetIndex, const CSSStyleSheet* parentStyleSheet);
158 153
159 StaticCSSRuleList* ensureRuleList(); 154 StaticCSSRuleList* ensureRuleList();
160 StyleRuleList* ensureStyleRuleList(); 155 StyleRuleList* ensureStyleRuleList();
161 156
162 private: 157 private:
163 const ElementResolveContext& m_context; 158 const ElementResolveContext& m_context;
164 const SelectorFilter& m_selectorFilter; 159 const SelectorFilter& m_selectorFilter;
165 RefPtr<RenderStyle> m_style; // FIXME: This can be mutated during matching! 160 RefPtr<RenderStyle> m_style; // FIXME: This can be mutated during matching!
166 161
167 PseudoStyleRequest m_pseudoStyleRequest; 162 PseudoStyleRequest m_pseudoStyleRequest;
168 SelectorChecker::Mode m_mode; 163 SelectorChecker::Mode m_mode;
169 bool m_canUseFastReject; 164 bool m_canUseFastReject;
170 bool m_sameOriginOnly; 165 bool m_sameOriginOnly;
171 bool m_matchingUARules; 166 bool m_matchingUARules;
172 bool m_scopeContainsLastMatchedElement; 167 bool m_scopeContainsLastMatchedElement;
173 168
174 WillBeHeapVector<MatchedRule, 32> m_matchedRules; 169 WillBeHeapVector<MatchedRule, 32> m_matchedRules;
175 170
176 // Output. 171 // Output.
177 RefPtrWillBeMember<StaticCSSRuleList> m_cssRuleList; 172 RefPtrWillBeMember<StaticCSSRuleList> m_cssRuleList;
178 RefPtrWillBeMember<StyleRuleList> m_styleRuleList; 173 RefPtrWillBeMember<StyleRuleList> m_styleRuleList;
179 MatchResult m_result; 174 MatchResult m_result;
180 }; 175 };
181 176
182 } // namespace blink 177 } // namespace blink
183 178
184 #endif // ElementRuleCollector_h 179 #endif // ElementRuleCollector_h
OLDNEW
« no previous file with comments | « LayoutTests/fast/dom/shadow/custom-pseudo-scope-expected.html ('k') | Source/core/css/ElementRuleCollector.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698