Commit dde9bf68 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Chromium LUCI CQ

Add use counter for ::target-text

The counter counts the usage of matching non-UA rules with
::target-text.

Bug: 1168273, 1136817
Change-Id: I784680927b62dbd592eb1d05bef5e6edb76805d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2640255Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845336}
parent 750cbd40
......@@ -3102,6 +3102,7 @@ enum WebFeature {
kV8TCPSocket_Writable_AttributeGetter = 3777,
kV8TCPSocket_RemoteAddress_AttributeGetter = 3778,
kV8TCPSocket_RemotePort_AttributeGetter = 3779,
kCSSSelectorTargetText = 3780,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -1112,6 +1112,12 @@ bool SelectorChecker::CheckPseudoElement(const SelectorCheckingContext& context,
return false;
return true;
}
case CSSSelector::kPseudoTargetText:
if (!is_ua_rule_) {
UseCounter::Count(context.element->GetDocument(),
WebFeature::kCSSSelectorTargetText);
}
FALLTHROUGH;
default:
DCHECK_NE(mode_, kQueryingRules);
result.dynamic_pseudo =
......
......@@ -90,11 +90,8 @@ class CORE_EXPORT SelectorChecker {
scrollbar_(init.scrollbar),
part_names_(init.part_names),
scrollbar_part_(init.scrollbar_part),
mode_(init.mode) {
#if DCHECK_IS_ON()
is_ua_rule_ = init.is_ua_rule;
#endif
}
mode_(init.mode),
is_ua_rule_(init.is_ua_rule) {}
SelectorChecker(const SelectorChecker&) = delete;
SelectorChecker& operator=(const SelectorChecker&) = delete;
......@@ -194,11 +191,9 @@ class CORE_EXPORT SelectorChecker {
PartNames* part_names_;
ScrollbarPart scrollbar_part_;
Mode mode_;
bool is_ua_rule_;
#if DCHECK_IS_ON()
mutable bool inside_match_ = false;
bool is_ua_rule_;
#else
static constexpr bool is_ua_rule_ = true;
#endif
};
......
......@@ -4067,4 +4067,28 @@ TEST_F(StyleEngineTest, AudioUAStyleNameSpace) {
EXPECT_FALSE(html_audio->GetComputedStyle());
}
TEST_F(StyleEngineTest, TargetTextUseCount) {
ClearUseCounter(WebFeature::kCSSSelectorTargetText);
GetDocument().body()->setInnerHTML(R"HTML(
<style>
#nevermatch::target-text { background-color: pink }
</style>
)HTML");
UpdateAllLifecyclePhases();
EXPECT_FALSE(IsUseCounted(WebFeature::kCSSSelectorTargetText));
ClearUseCounter(WebFeature::kCSSSelectorTargetText);
// Count ::target-text if we would have matched if the page was loaded with a
// text fragment url.
GetDocument().body()->setInnerHTML(R"HTML(
<style>
div::target-text { background-color: pink }
</style>
<div></div>
)HTML");
UpdateAllLifecyclePhases();
EXPECT_TRUE(IsUseCounted(WebFeature::kCSSSelectorTargetText));
ClearUseCounter(WebFeature::kCSSSelectorTargetText);
}
} // namespace blink
......@@ -31021,6 +31021,7 @@ Called by update_use_counter_feature_enum.py.-->
<int value="3777" label="V8TCPSocket_Writable_AttributeGetter"/>
<int value="3778" label="V8TCPSocket_RemoteAddress_AttributeGetter"/>
<int value="3779" label="V8TCPSocket_RemotePort_AttributeGetter"/>
<int value="3780" label="CSSSelectorTargetText"/>
</enum>
<enum name="FeaturePolicyAllowlistType">
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