Changeset 285262 in webkit
- Timestamp:
- Nov 4, 2021 9:15:14 AM (9 months ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
LayoutTests/imported/w3c/web-platform-tests/css/css-shadow-parts/host-part-001-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/css/SelectorChecker.cpp (modified) (9 diffs)
-
Source/WebCore/style/ElementRuleCollector.cpp (modified) (2 diffs)
-
Source/WebCore/style/ElementRuleCollector.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-shadow-parts/host-part-001-expected.txt
r264522 r285262 1 1 2 FAIL :host::part works assert_equals: :host::part() works expected "rgb(0, 255, 0)" but got "rgb(0, 0, 0)" 2 PASS :host::part works 3 3 -
trunk/Source/WebCore/ChangeLog
r285258 r285262 1 2021-11-04 Antti Koivisto <antti@apple.com> 2 3 :host::part(foo) selector does not select elements inside shadow roots 4 https://bugs.webkit.org/show_bug.cgi?id=232261 5 <rdar://problem/84894922> 6 7 Reviewed by Simon Fraser. 8 9 We need to also look for ::part rules from the element's own scope. 10 11 * css/SelectorChecker.cpp: 12 (WebCore::SelectorChecker::match const): 13 14 Rename mayMatchHostPseudoClass -> mustMatchHostPseudoClass for clarity. 15 16 (WebCore::localContextForParent): 17 (WebCore::SelectorChecker::matchRecursively const): 18 19 Split ShadowDescendant and ShadowPartDescendant handling as they are sufficiently different. 20 Set nextContext.mustMatchHostPseudoClass bit for ::part rules coming from the Element's scope as 21 it is the only way they can match. 22 23 (WebCore::SelectorChecker::checkOne const): 24 25 No name mapping for rules from the element's own scope. 26 27 * style/ElementRuleCollector.cpp: 28 (WebCore::Style::ElementRuleCollector::matchPartPseudoElementRules): 29 (WebCore::Style::ElementRuleCollector::matchPartPseudoElementRulesForScope): 30 31 Also check ::part rules from the element scope. 32 33 * style/ElementRuleCollector.h: 34 1 35 2021-11-04 Andres Gonzalez <andresg_22@apple.com> 2 36 -
trunk/Source/WebCore/css/SelectorChecker.cpp
r285209 r285262 77 77 bool hasScrollbarPseudo { false }; 78 78 bool hasSelectionPseudo { false }; 79 bool m ayMatchHostPseudoClass { false };79 bool mustMatchHostPseudoClass { false }; 80 80 }; 81 81 … … 178 178 if (checkingContext.isMatchingHostPseudoClass) { 179 179 ASSERT(element.shadowRoot()); 180 context.m ayMatchHostPseudoClass = true;180 context.mustMatchHostPseudoClass = true; 181 181 } 182 182 … … 237 237 updatedContext.isSubjectOrAdjacentElement = false; 238 238 239 if (updatedContext.m ayMatchHostPseudoClass) {239 if (updatedContext.mustMatchHostPseudoClass) { 240 240 updatedContext.element = nullptr; 241 241 return updatedContext; … … 245 245 if (context.selector->match() == CSSSelector::PseudoClass && context.selector->pseudoClassType() == CSSSelector::PseudoClassHost && is<ShadowRoot>(context.element->parentNode())) { 246 246 updatedContext.element = downcast<ShadowRoot>(*context.element->parentNode()).host(); 247 updatedContext.m ayMatchHostPseudoClass = true;247 updatedContext.mustMatchHostPseudoClass = true; 248 248 return updatedContext; 249 249 } … … 407 407 return MatchResult::updateWithMatchType(result, matchType); 408 408 } 409 case CSSSelector::ShadowDescendant: 410 case CSSSelector::ShadowPartDescendant: { 411 // Continue matching in the scope where this rule came from. 412 auto* host = relation == CSSSelector::ShadowPartDescendant 413 ? Style::hostForScopeOrdinal(*context.element, checkingContext.styleScopeOrdinal) 414 : context.element->shadowHost(); 409 case CSSSelector::ShadowDescendant: { 410 auto* host = context.element->shadowHost(); 415 411 if (!host) 416 412 return MatchResult::fails(Match::SelectorFailsCompletely); … … 419 415 nextContext.firstSelectorOfTheFragment = nextContext.selector; 420 416 nextContext.isSubjectOrAdjacentElement = false; 417 PseudoIdSet ignoreDynamicPseudo; 418 MatchResult result = matchRecursively(checkingContext, nextContext, ignoreDynamicPseudo); 419 420 return MatchResult::updateWithMatchType(result, matchType); 421 } 422 case CSSSelector::ShadowPartDescendant: { 423 // Continue matching in the scope where this rule came from. 424 auto* host = checkingContext.styleScopeOrdinal == Style::ScopeOrdinal::Element 425 ? context.element->shadowHost() 426 : Style::hostForScopeOrdinal(*context.element, checkingContext.styleScopeOrdinal); 427 if (!host) 428 return MatchResult::fails(Match::SelectorFailsCompletely); 429 430 nextContext.element = host; 431 nextContext.firstSelectorOfTheFragment = nextContext.selector; 432 nextContext.isSubjectOrAdjacentElement = false; 433 // ::part rules from the element's own scope can only match if they apply to :host. 434 nextContext.mustMatchHostPseudoClass = checkingContext.styleScopeOrdinal == Style::ScopeOrdinal::Element; 421 435 PseudoIdSet ignoreDynamicPseudo; 422 436 MatchResult result = matchRecursively(checkingContext, nextContext, ignoreDynamicPseudo); … … 642 656 const CSSSelector& selector = *context.selector; 643 657 644 if (context.m ayMatchHostPseudoClass) {658 if (context.mustMatchHostPseudoClass) { 645 659 // :host doesn't combine with anything except pseudo elements. 646 660 bool isHostPseudoClass = selector.match() == CSSSelector::PseudoClass && selector.pseudoClassType() == CSSSelector::PseudoClassHost; … … 1090 1104 } 1091 1105 case CSSSelector::PseudoClassHost: { 1092 if (!context.m ayMatchHostPseudoClass)1106 if (!context.mustMatchHostPseudoClass) 1093 1107 return false; 1094 1108 return matchHostPseudoClass(selector, element, checkingContext); … … 1172 1186 auto translatePartNameToRuleScope = [&](AtomString partName) { 1173 1187 Vector<AtomString, 1> mappedNames { partName }; 1188 1189 if (checkingContext.styleScopeOrdinal == Style::ScopeOrdinal::Element) 1190 return mappedNames; 1191 1174 1192 auto* ruleScopeHost = Style::hostForScopeOrdinal(*context.element, checkingContext.styleScopeOrdinal); 1175 1193 -
trunk/Source/WebCore/style/ElementRuleCollector.cpp
r285202 r285262 302 302 return; 303 303 304 matchPartPseudoElementRulesForScope( *partMatchingElement.containingShadowRoot());305 } 306 307 void ElementRuleCollector::matchPartPseudoElementRulesForScope(const ShadowRoot& scopeShadowRoot)308 { 309 auto* host = scopeShadowRoot.host();310 auto styleScopeOrdinal = ScopeOrdinal:: ContainingHost;311 312 for (; host; host = host->shadowHost(), --styleScopeOrdinal) {313 auto& styleScope = Scope::forNode( *host);304 matchPartPseudoElementRulesForScope(partMatchingElement); 305 } 306 307 void ElementRuleCollector::matchPartPseudoElementRulesForScope(const Element& partMatchingElement) 308 { 309 auto* element = &partMatchingElement; 310 auto styleScopeOrdinal = ScopeOrdinal::Element; 311 312 for (; element; element = element->shadowHost(), --styleScopeOrdinal) { 313 auto& styleScope = Scope::forNode(const_cast<Element&>(*element)); 314 314 if (!styleScope.resolver().ruleSets().isAuthorStyleDefined()) 315 315 continue; … … 321 321 322 322 // Element may only be exposed to styling from enclosing scopes via exportparts attributes. 323 if ( host->shadowRoot()->partMappings().isEmpty())323 if (element != &partMatchingElement && element->shadowRoot()->partMappings().isEmpty()) 324 324 break; 325 325 } -
trunk/Source/WebCore/style/ElementRuleCollector.h
r285202 r285262 133 133 void matchSlottedPseudoElementRules(); 134 134 void matchPartPseudoElementRules(); 135 void matchPartPseudoElementRulesForScope(const ShadowRoot& scopeShadowRoot);135 void matchPartPseudoElementRulesForScope(const Element& partMatchingElement); 136 136 137 137 void collectMatchingShadowPseudoElementRules(const MatchRequest&);
Note: See TracChangeset
for help on using the changeset viewer.