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

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

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
« 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ASSERT(m_mode == SelectorChecker::CollectingStyleRules); 72 ASSERT(m_mode == SelectorChecker::CollectingStyleRules);
73 return m_styleRuleList.release(); 73 return m_styleRuleList.release();
74 } 74 }
75 75
76 PassRefPtrWillBeRawPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList() 76 PassRefPtrWillBeRawPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList()
77 { 77 {
78 ASSERT(m_mode == SelectorChecker::CollectingCSSRules); 78 ASSERT(m_mode == SelectorChecker::CollectingCSSRules);
79 return m_cssRuleList.release(); 79 return m_cssRuleList.release();
80 } 80 }
81 81
82 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, unsigned specificity, CascadeScope cascadeScope, CascadeOrder cascadeOrder, unsigned styl eSheetIndex, const CSSStyleSheet* parentStyleSheet) 82 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, unsigned specificity, CascadeOrder cascadeOrder, unsigned styleSheetIndex, const CSSStyle Sheet* parentStyleSheet)
83 { 83 {
84 m_matchedRules.append(MatchedRule(rule, specificity, cascadeScope, cascadeOr der, styleSheetIndex, parentStyleSheet)); 84 m_matchedRules.append(MatchedRule(rule, specificity, cascadeOrder, styleShee tIndex, parentStyleSheet));
85 } 85 }
86 86
87 void ElementRuleCollector::clearMatchedRules() 87 void ElementRuleCollector::clearMatchedRules()
88 { 88 {
89 m_matchedRules.clear(); 89 m_matchedRules.clear();
90 } 90 }
91 91
92 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList() 92 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList()
93 { 93 {
94 if (!m_styleRuleList) 94 if (!m_styleRuleList)
(...skipping 28 matching lines...) Expand all
123 return true; 123 return true;
124 // c) the rules comes from a scoped style sheet within the same tree scope 124 // c) the rules comes from a scoped style sheet within the same tree scope
125 if (!scopingNode || element->treeScope() == scopingNode->treeScope()) 125 if (!scopingNode || element->treeScope() == scopingNode->treeScope())
126 return true; 126 return true;
127 // d) the rules comes from a scoped style sheet within an active shadow root whose host is the given element 127 // d) the rules comes from a scoped style sheet within an active shadow root whose host is the given element
128 if (SelectorChecker::isHostInItsShadowTree(*element, scopingNode)) 128 if (SelectorChecker::isHostInItsShadowTree(*element, scopingNode))
129 return true; 129 return true;
130 return false; 130 return false;
131 } 131 }
132 132
133 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest , RuleRange& ruleRange, CascadeScope cascadeScope, CascadeOrder cascadeOrder, bo ol matchingTreeBoundaryRules) 133 void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest , RuleRange& ruleRange, CascadeOrder cascadeOrder, bool matchingTreeBoundaryRule s)
134 { 134 {
135 ASSERT(matchRequest.ruleSet); 135 ASSERT(matchRequest.ruleSet);
136 ASSERT(m_context.element()); 136 ASSERT(m_context.element());
137 137
138 Element& element = *m_context.element(); 138 Element& element = *m_context.element();
139 const AtomicString& pseudoId = element.shadowPseudoId(); 139 const AtomicString& pseudoId = element.shadowPseudoId();
140 if (!pseudoId.isEmpty()) { 140 if (!pseudoId.isEmpty()) {
141 ASSERT(element.isStyledElement()); 141 ASSERT(element.isStyledElement());
142 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul es(pseudoId), ignoreCascadeScope, cascadeOrder, matchRequest, ruleRange); 142 collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRul es(pseudoId), cascadeOrder, matchRequest, ruleRange);
143 } 143 }
144 144
145 if (element.isVTTElement()) 145 if (element.isVTTElement())
146 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), casc adeScope, cascadeOrder, matchRequest, ruleRange); 146 collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), casc adeOrder, matchRequest, ruleRange);
147 // Check whether other types of rules are applicable in the current tree sco pe. Criteria for this: 147 // Check whether other types of rules are applicable in the current tree sco pe. Criteria for this:
148 // a) it's a UA rule 148 // a) it's a UA rule
149 // b) the rules comes from a scoped style sheet within the same tree scope 149 // b) the rules comes from a scoped style sheet within the same tree scope
150 // c) the rules comes from a scoped style sheet within an active shadow root whose host is the given element 150 // c) the rules comes from a scoped style sheet within an active shadow root whose host is the given element
151 // d) the rules can cross boundaries 151 // d) the rules can cross boundaries
152 // b)-e) is checked in rulesApplicableInCurrentTreeScope. 152 // b)-e) is checked in rulesApplicableInCurrentTreeScope.
153 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match Request.scope, matchingTreeBoundaryRules)) 153 if (!m_matchingUARules && !rulesApplicableInCurrentTreeScope(&element, match Request.scope, matchingTreeBoundaryRules))
154 return; 154 return;
155 155
156 // We need to collect the rules for id, class, tag, and everything else into a buffer and 156 // We need to collect the rules for id, class, tag, and everything else into a buffer and
157 // then sort the buffer. 157 // then sort the buffer.
158 if (element.hasID()) 158 if (element.hasID())
159 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS tyleResolution()), cascadeScope, cascadeOrder, matchRequest, ruleRange); 159 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS tyleResolution()), cascadeOrder, matchRequest, ruleRange);
160 if (element.isStyledElement() && element.hasClass()) { 160 if (element.isStyledElement() && element.hasClass()) {
161 for (size_t i = 0; i < element.classNames().size(); ++i) 161 for (size_t i = 0; i < element.classNames().size(); ++i)
162 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element .classNames()[i]), cascadeScope, cascadeOrder, matchRequest, ruleRange); 162 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element .classNames()[i]), cascadeOrder, matchRequest, ruleRange);
163 } 163 }
164 164
165 if (element.isLink()) 165 if (element.isLink())
166 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules() , cascadeScope, cascadeOrder, matchRequest, ruleRange); 166 collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules() , cascadeOrder, matchRequest, ruleRange);
167 if (SelectorChecker::matchesFocusPseudoClass(element)) 167 if (SelectorChecker::matchesFocusPseudoClass(element))
168 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules( ), cascadeScope, cascadeOrder, matchRequest, ruleRange); 168 collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules( ), cascadeOrder, matchRequest, ruleRange);
169 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName ()), cascadeScope, cascadeOrder, matchRequest, ruleRange); 169 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName ()), cascadeOrder, matchRequest, ruleRange);
170 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeS cope, cascadeOrder, matchRequest, ruleRange); 170 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeO rder, matchRequest, ruleRange);
171 } 171 }
172 172
173 void ElementRuleCollector::collectMatchingShadowHostRules(const MatchRequest& ma tchRequest, RuleRange& ruleRange, CascadeScope cascadeScope, CascadeOrder cascad eOrder, bool matchingTreeBoundaryRules) 173 void ElementRuleCollector::collectMatchingShadowHostRules(const MatchRequest& ma tchRequest, RuleRange& ruleRange, CascadeOrder cascadeOrder, bool matchingTreeBo undaryRules)
174 { 174 {
175 collectMatchingRulesForList(matchRequest.ruleSet->shadowHostRules(), cascade Scope, cascadeOrder, matchRequest, ruleRange); 175 collectMatchingRulesForList(matchRequest.ruleSet->shadowHostRules(), cascade Order, matchRequest, ruleRange);
176 } 176 }
177 177
178 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule) 178 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule)
179 { 179 {
180 switch (rule->type()) { 180 switch (rule->type()) {
181 case CSSRule::MEDIA_RULE: 181 case CSSRule::MEDIA_RULE:
182 return toCSSMediaRule(rule)->cssRules(); 182 return toCSSMediaRule(rule)->cssRules();
183 case CSSRule::KEYFRAMES_RULE: 183 case CSSRule::KEYFRAMES_RULE:
184 return toCSSKeyframesRule(rule)->cssRules(); 184 return toCSSKeyframesRule(rule)->cssRules();
185 case CSSRule::SUPPORTS_RULE: 185 case CSSRule::SUPPORTS_RULE:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 context.isUARule = m_matchingUARules; 267 context.isUARule = m_matchingUARules;
268 context.scopeContainsLastMatchedElement = m_scopeContainsLastMatchedElement; 268 context.scopeContainsLastMatchedElement = m_scopeContainsLastMatchedElement;
269 SelectorChecker::Match match = selectorChecker.match(context, DOMSiblingTrav ersalStrategy(), result); 269 SelectorChecker::Match match = selectorChecker.match(context, DOMSiblingTrav ersalStrategy(), result);
270 if (match != SelectorChecker::SelectorMatches) 270 if (match != SelectorChecker::SelectorMatches)
271 return false; 271 return false;
272 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo Id != result->dynamicPseudo) 272 if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudo Id != result->dynamicPseudo)
273 return false; 273 return false;
274 return true; 274 return true;
275 } 275 }
276 276
277 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad eScope cascadeScope, CascadeOrder cascadeOrder, const MatchRequest& matchRequest , RuleRange& ruleRange) 277 void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad eOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange)
278 { 278 {
279 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes())) 279 if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maxi mumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes()))
280 return; 280 return;
281 281
282 StyleRule* rule = ruleData.rule(); 282 StyleRule* rule = ruleData.rule();
283 SelectorChecker::MatchResult result; 283 SelectorChecker::MatchResult result;
284 if (ruleMatches(ruleData, matchRequest.scope, &result)) { 284 if (ruleMatches(ruleData, matchRequest.scope, &result)) {
285 // If the rule has no properties to apply, then ignore it in the non-deb ug mode. 285 // If the rule has no properties to apply, then ignore it in the non-deb ug mode.
286 const StylePropertySet& properties = rule->properties(); 286 const StylePropertySet& properties = rule->properties();
287 if (properties.isEmpty() && !matchRequest.includeEmptyRules) 287 if (properties.isEmpty() && !matchRequest.includeEmptyRules)
(...skipping 14 matching lines...) Expand all
302 if ((dynamicPseudo == BEFORE || dynamicPseudo == AFTER) && !ruleData .rule()->properties().hasProperty(CSSPropertyContent)) 302 if ((dynamicPseudo == BEFORE || dynamicPseudo == AFTER) && !ruleData .rule()->properties().hasProperty(CSSPropertyContent))
303 return; 303 return;
304 m_style->setHasPseudoStyle(dynamicPseudo); 304 m_style->setHasPseudoStyle(dynamicPseudo);
305 } else { 305 } else {
306 // Update our first/last rule indices in the matched rules array. 306 // Update our first/last rule indices in the matched rules array.
307 ++ruleRange.lastRuleIndex; 307 ++ruleRange.lastRuleIndex;
308 if (ruleRange.firstRuleIndex == -1) 308 if (ruleRange.firstRuleIndex == -1)
309 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; 309 ruleRange.firstRuleIndex = ruleRange.lastRuleIndex;
310 310
311 // Add this rule to our list of matched rules. 311 // Add this rule to our list of matched rules.
312 addMatchedRule(&ruleData, result.specificity, cascadeScope, cascadeO rder, matchRequest.styleSheetIndex, matchRequest.styleSheet); 312 addMatchedRule(&ruleData, result.specificity, cascadeOrder, matchReq uest.styleSheetIndex, matchRequest.styleSheet);
313 return; 313 return;
314 } 314 }
315 } 315 }
316 } 316 }
317 317
318 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu le& matchedRule2) 318 static inline bool compareRules(const MatchedRule& matchedRule1, const MatchedRu le& matchedRule2)
319 { 319 {
320 if (matchedRule1.cascadeScope() != matchedRule2.cascadeScope())
321 return matchedRule1.cascadeScope() > matchedRule2.cascadeScope();
322
323 unsigned specificity1 = matchedRule1.specificity(); 320 unsigned specificity1 = matchedRule1.specificity();
324 unsigned specificity2 = matchedRule2.specificity(); 321 unsigned specificity2 = matchedRule2.specificity();
325 if (specificity1 != specificity2) 322 if (specificity1 != specificity2)
326 return specificity1 < specificity2; 323 return specificity1 < specificity2;
327 324
328 return matchedRule1.position() < matchedRule2.position(); 325 return matchedRule1.position() < matchedRule2.position();
329 } 326 }
330 327
331 void ElementRuleCollector::sortMatchedRules() 328 void ElementRuleCollector::sortMatchedRules()
332 { 329 {
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); 343 collectMatchingRules(MatchRequest(ruleSet), ruleRange);
348 344
349 return !m_matchedRules.isEmpty(); 345 return !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