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

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

Issue 451983002: Remove cascadeScope (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 6 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 | « Source/core/css/ElementRuleCollector.h ('k') | Source/core/css/TreeBoundaryCrossingRules.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 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 ASSERT(m_mode == SelectorChecker::CollectingStyleRules); 71 ASSERT(m_mode == SelectorChecker::CollectingStyleRules);
72 return m_styleRuleList.release(); 72 return m_styleRuleList.release();
73 } 73 }
74 74
75 PassRefPtrWillBeRawPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList() 75 PassRefPtrWillBeRawPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList()
76 { 76 {
77 ASSERT(m_mode == SelectorChecker::CollectingCSSRules); 77 ASSERT(m_mode == SelectorChecker::CollectingCSSRules);
78 return m_cssRuleList.release(); 78 return m_cssRuleList.release();
79 } 79 }
80 80
81 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, unsigned specificity, CascadeScope cascadeScope, CascadeOrder cascadeOrder, unsigned styl eSheetIndex, const CSSStyleSheet* parentStyleSheet) 81 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, unsigned specificity, CascadeOrder cascadeOrder, unsigned styleSheetIndex, const CSSStyle Sheet* parentStyleSheet)
82 { 82 {
83 if (!m_matchedRules) 83 if (!m_matchedRules)
84 m_matchedRules = adoptPtrWillBeNoop(new WillBeHeapVector<MatchedRule, 32 >); 84 m_matchedRules = adoptPtrWillBeNoop(new WillBeHeapVector<MatchedRule, 32 >);
85 m_matchedRules->append(MatchedRule(rule, specificity, cascadeScope, cascadeO rder, styleSheetIndex, parentStyleSheet)); 85 m_matchedRules->append(MatchedRule(rule, specificity, cascadeOrder, styleShe etIndex, parentStyleSheet));
86 } 86 }
87 87
88 void ElementRuleCollector::clearMatchedRules() 88 void ElementRuleCollector::clearMatchedRules()
89 { 89 {
90 if (!m_matchedRules) 90 if (!m_matchedRules)
91 return; 91 return;
92 m_matchedRules->clear(); 92 m_matchedRules->clear();
93 } 93 }
94 94
95 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList() 95 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return true; 128 return true;
129 // c) the rules comes from a scoped style sheet within the same tree scope 129 // c) the rules comes from a scoped style sheet within the same tree scope
130 if (!scopingNode || treeScope == scopingNode->treeScope()) 130 if (!scopingNode || treeScope == scopingNode->treeScope())
131 return true; 131 return true;
132 // d) the rules comes from a scoped style sheet within an active shadow root whose host is the given element 132 // d) the rules comes from a scoped style sheet within an active shadow root whose host is the given element
133 if (SelectorChecker::isHostInItsShadowTree(*element, scopingNode)) 133 if (SelectorChecker::isHostInItsShadowTree(*element, scopingNode))
134 return true; 134 return true;
135 return false; 135 return false;
136 } 136 }
137 137
138 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest , RuleRange& ruleRange, SelectorChecker::ContextFlags contextFlags, CascadeScope cascadeScope, CascadeOrder cascadeOrder) 138 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest , RuleRange& ruleRange, SelectorChecker::ContextFlags contextFlags, CascadeOrder cascadeOrder)
139 { 139 {
140 ASSERT(matchRequest.ruleSet); 140 ASSERT(matchRequest.ruleSet);
141 ASSERT(m_context.element()); 141 ASSERT(m_context.element());
142 142
143 Element& element = *m_context.element(); 143 Element& element = *m_context.element();
144 const AtomicString& pseudoId = element.shadowPseudoId(); 144 const AtomicString& pseudoId = element.shadowPseudoId();
145 if (!pseudoId.isEmpty()) { 145 if (!pseudoId.isEmpty()) {
146 ASSERT(element.isStyledElement()); 146 ASSERT(element.isStyledElement());
147 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul es(pseudoId), contextFlags, ignoreCascadeScope, cascadeOrder, matchRequest, rule Range); 147 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul es(pseudoId), contextFlags, cascadeOrder, matchRequest, ruleRange);
148 } 148 }
149 149
150 if (element.isVTTElement()) 150 if (element.isVTTElement())
151 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), cont extFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); 151 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), cont extFlags, cascadeOrder, matchRequest, ruleRange);
152 // Check whether other types of rules are applicable in the current tree sco pe. Criteria for this: 152 // Check whether other types of rules are applicable in the current tree sco pe. Criteria for this:
153 // a) it's a UA rule 153 // a) it's a UA rule
154 // b) the tree scope allows author rules 154 // b) the tree scope allows author rules
155 // c) the rules comes from a scoped style sheet within the same tree scope 155 // c) the rules comes from a scoped style sheet within the same tree scope
156 // d) the rules comes from a scoped style sheet within an active shadow root whose host is the given element 156 // d) the rules comes from a scoped style sheet within an active shadow root whose host is the given element
157 // e) the rules can cross boundaries 157 // e) the rules can cross boundaries
158 // b)-e) is checked in rulesApplicableInCurrentTreeScope. 158 // b)-e) is checked in rulesApplicableInCurrentTreeScope.
159 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match Request.scope, matchRequest.elementApplyAuthorStyles)) 159 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match Request.scope, matchRequest.elementApplyAuthorStyles))
160 return; 160 return;
161 161
162 // We need to collect the rules for id, class, tag, and everything else into a buffer and 162 // We need to collect the rules for id, class, tag, and everything else into a buffer and
163 // then sort the buffer. 163 // then sort the buffer.
164 if (element.hasID()) 164 if (element.hasID())
165 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS tyleResolution()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR ange); 165 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS tyleResolution()), contextFlags, cascadeOrder, matchRequest, ruleRange);
166 if (element.isStyledElement() && element.hasClass()) { 166 if (element.isStyledElement() && element.hasClass()) {
167 for (size_t i = 0; i < element.classNames().size(); ++i) 167 for (size_t i = 0; i < element.classNames().size(); ++i)
168 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element .classNames()[i]), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR ange); 168 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element .classNames()[i]), contextFlags, cascadeOrder, matchRequest, ruleRange);
169 } 169 }
170 170
171 if (element.isLink()) 171 if (element.isLink())
172 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules() , contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); 172 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules() , contextFlags, cascadeOrder, matchRequest, ruleRange);
173 if (SelectorChecker::matchesFocusPseudoClass(element)) 173 if (SelectorChecker::matchesFocusPseudoClass(element))
174 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules( ), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); 174 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules( ), contextFlags, cascadeOrder, matchRequest, ruleRange);
175 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName ()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); 175 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName ()), contextFlags, cascadeOrder, matchRequest, ruleRange);
176 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), contextF lags, cascadeScope, cascadeOrder, matchRequest, ruleRange); 176 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), contextF lags, cascadeOrder, matchRequest, ruleRange);
177 } 177 }
178 178
179 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule) 179 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule)
180 { 180 {
181 switch (rule->type()) { 181 switch (rule->type()) {
182 case CSSRule::MEDIA_RULE: 182 case CSSRule::MEDIA_RULE:
183 return toCSSMediaRule(rule)->cssRules(); 183 return toCSSMediaRule(rule)->cssRules();
184 case CSSRule::KEYFRAMES_RULE: 184 case CSSRule::KEYFRAMES_RULE:
185 return toCSSKeyframesRule(rule)->cssRules(); 185 return toCSSKeyframesRule(rule)->cssRules();
186 case CSSRule::SUPPORTS_RULE: 186 case CSSRule::SUPPORTS_RULE:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 context.isUARule = m_matchingUARules; 269 context.isUARule = m_matchingUARules;
270 context.contextFlags = contextFlags; 270 context.contextFlags = contextFlags;
271 SelectorChecker::Match match = selectorChecker.match(context, DOMSiblingTrav ersalStrategy(), result); 271 SelectorChecker::Match match = selectorChecker.match(context, DOMSiblingTrav ersalStrategy(), result);
272 if (match != SelectorChecker::SelectorMatches) 272 if (match != SelectorChecker::SelectorMatches)
273 return false; 273 return false;
274 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo Id != result->dynamicPseudo) 274 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo Id != result->dynamicPseudo)
275 return false; 275 return false;
276 return true; 276 return true;
277 } 277 }
278 278
279 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Select orChecker::ContextFlags contextFlags, CascadeScope cascadeScope, CascadeOrder ca scadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) 279 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Select orChecker::ContextFlags contextFlags, CascadeOrder cascadeOrder, const MatchRequ est& matchRequest, RuleRange& ruleRange)
280 { 280 {
281 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes())) 281 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes()))
282 return; 282 return;
283 283
284 StyleRule* rule = ruleData.rule(); 284 StyleRule* rule = ruleData.rule();
285 SelectorChecker::MatchResult result; 285 SelectorChecker::MatchResult result;
286 if (ruleMatches(ruleData, matchRequest.scope, contextFlags, &result)) { 286 if (ruleMatches(ruleData, matchRequest.scope, contextFlags, &result)) {
287 // If the rule has no properties to apply, then ignore it in the non-deb ug mode. 287 // If the rule has no properties to apply, then ignore it in the non-deb ug mode.
288 const StylePropertySet& properties = rule->properties(); 288 const StylePropertySet& properties = rule->properties();
289 if (properties.isEmpty() && !matchRequest.includeEmptyRules) 289 if (properties.isEmpty() && !matchRequest.includeEmptyRules)
(...skipping 11 matching lines...) Expand all
301 // FIXME: Matching should not modify the style directly. 301 // FIXME: Matching should not modify the style directly.
302 if (m_style && dynamicPseudo < FIRST_INTERNAL_PSEUDOID) 302 if (m_style && dynamicPseudo < FIRST_INTERNAL_PSEUDOID)
303 m_style->setHasPseudoStyle(dynamicPseudo); 303 m_style->setHasPseudoStyle(dynamicPseudo);
304 } else { 304 } else {
305 // Update our first/last rule indices in the matched rules array. 305 // Update our first/last rule indices in the matched rules array.
306 ++ruleRange.lastRuleIndex; 306 ++ruleRange.lastRuleIndex;
307 if (ruleRange.firstRuleIndex == -1) 307 if (ruleRange.firstRuleIndex == -1)
308 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; 308 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex;
309 309
310 // Add this rule to our list of matched rules. 310 // Add this rule to our list of matched rules.
311 addMatchedRule(&ruleData, result.specificity, cascadeScope, cascadeO rder, matchRequest.styleSheetIndex, matchRequest.styleSheet); 311 addMatchedRule(&ruleData, result.specificity, cascadeOrder, matchReq uest.styleSheetIndex, matchRequest.styleSheet);
312 return; 312 return;
313 } 313 }
314 } 314 }
315 } 315 }
316 316
317 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu le& matchedRule2) 317 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu le& matchedRule2)
318 { 318 {
319 if (matchedRule1.cascadeScope() != matchedRule2.cascadeScope())
320 return matchedRule1.cascadeScope() > matchedRule2.cascadeScope();
321
322 unsigned specificity1 = matchedRule1.specificity(); 319 unsigned specificity1 = matchedRule1.specificity();
323 unsigned specificity2 = matchedRule2.specificity(); 320 unsigned specificity2 = matchedRule2.specificity();
324 if (specificity1 != specificity2) 321 if (specificity1 != specificity2)
325 return specificity1 < specificity2; 322 return specificity1 < specificity2;
326 323
327 return matchedRule1.position() < matchedRule2.position(); 324 return matchedRule1.position() < matchedRule2.position();
328 } 325 }
329 326
330 void ElementRuleCollector::sortMatchedRules() 327 void ElementRuleCollector::sortMatchedRules()
331 { 328 {
332 ASSERT(m_matchedRules); 329 ASSERT(m_matchedRules);
333 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules); 330 std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules);
334 } 331 }
335 332
336 bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet) 333 bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet)
337 { 334 {
338 clearMatchedRules(); 335 clearMatchedRules();
339 336
340 m_mode = SelectorChecker::SharingRules; 337 m_mode = SelectorChecker::SharingRules;
341 // To check whether a given RuleSet has any rule matching a given element, 338 // To check whether a given RuleSet has any rule matching a given element,
342 // should not see the element's treescope. Because RuleSet has no 339 // should not see the element's treescope. Because RuleSet has no
343 // information about "scope". 340 // information about "scope".
344 int firstRuleIndex = -1, lastRuleIndex = -1; 341 int firstRuleIndex = -1, lastRuleIndex = -1;
345 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); 342 RuleRange ruleRange(firstRuleIndex, lastRuleIndex);
346 // FIXME: Verify whether it's ok to ignore CascadeScope here.
347 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Defa ultBehavior); 343 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Defa ultBehavior);
348 344
349 return m_matchedRules && !m_matchedRules->isEmpty(); 345 return m_matchedRules && !m_matchedRules->isEmpty();
350 } 346 }
351 347
352 } // namespace blink 348 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/ElementRuleCollector.h ('k') | Source/core/css/TreeBoundaryCrossingRules.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698