Commit 650740ea authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

Avoid dynamic specificity calculation for ::slotted()

I want to try and remove the dynamic specificity calculation
altogether. After this, it's only used by :host and :host-context.

Also, we currently return kClassLikeSpecificity for pseudo-elements
(for some reason), so use this for ::slotted as well. Even though
it's not observable for authors, it makes things somewhat consistent
internally at least.

Test: external/wpt/css/css-scoping/slotted-specificity.html
Change-Id: Ie64144dfca7439cb02ee839d33c53a409e3cc523
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505751Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821882}
parent 316a3fe6
......@@ -146,8 +146,16 @@ inline unsigned CSSSelector::SpecificityForOneSelector() const {
break;
}
return kClassLikeSpecificity;
case kClass:
case kPseudoElement:
switch (GetPseudoType()) {
case kPseudoSlotted:
DCHECK(SelectorList()->HasOneSelector());
return kClassLikeSpecificity + SelectorList()->First()->Specificity();
default:
break;
}
return kClassLikeSpecificity;
case kClass:
case kAttributeExact:
case kAttributeSet:
case kAttributeList:
......
......@@ -123,6 +123,11 @@ TEST(CSSSelector, Specificity_Where) {
Specificity("*"));
}
TEST(CSSSelector, Specificity_Slotted) {
EXPECT_EQ(Specificity("::slotted(.a)"), Specificity(".a::first-line"));
EXPECT_EQ(Specificity("::slotted(*)"), Specificity("::first-line"));
}
TEST(CSSSelector, HasLinkOrVisited) {
EXPECT_FALSE(HasLinkOrVisited("tag"));
EXPECT_FALSE(HasLinkOrVisited("visited"));
......
......@@ -1249,9 +1249,6 @@ bool SelectorChecker::CheckPseudoElement(const SelectorCheckingContext& context,
MatchResult sub_result;
if (MatchSelector(sub_context, sub_result) != kSelectorMatches)
return false;
result.specificity += sub_context.selector->Specificity() +
sub_result.specificity +
CSSSelector::kTagSpecificity;
return true;
}
case CSSSelector::kPseudoContent:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment