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 { ...@@ -3102,6 +3102,7 @@ enum WebFeature {
kV8TCPSocket_Writable_AttributeGetter = 3777, kV8TCPSocket_Writable_AttributeGetter = 3777,
kV8TCPSocket_RemoteAddress_AttributeGetter = 3778, kV8TCPSocket_RemoteAddress_AttributeGetter = 3778,
kV8TCPSocket_RemotePort_AttributeGetter = 3779, kV8TCPSocket_RemotePort_AttributeGetter = 3779,
kCSSSelectorTargetText = 3780,
// Add new features immediately above this line. Don't change assigned // Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots. // numbers of any item, and don't reuse removed slots.
......
...@@ -1112,6 +1112,12 @@ bool SelectorChecker::CheckPseudoElement(const SelectorCheckingContext& context, ...@@ -1112,6 +1112,12 @@ bool SelectorChecker::CheckPseudoElement(const SelectorCheckingContext& context,
return false; return false;
return true; return true;
} }
case CSSSelector::kPseudoTargetText:
if (!is_ua_rule_) {
UseCounter::Count(context.element->GetDocument(),
WebFeature::kCSSSelectorTargetText);
}
FALLTHROUGH;
default: default:
DCHECK_NE(mode_, kQueryingRules); DCHECK_NE(mode_, kQueryingRules);
result.dynamic_pseudo = result.dynamic_pseudo =
......
...@@ -90,11 +90,8 @@ class CORE_EXPORT SelectorChecker { ...@@ -90,11 +90,8 @@ class CORE_EXPORT SelectorChecker {
scrollbar_(init.scrollbar), scrollbar_(init.scrollbar),
part_names_(init.part_names), part_names_(init.part_names),
scrollbar_part_(init.scrollbar_part), scrollbar_part_(init.scrollbar_part),
mode_(init.mode) { mode_(init.mode),
#if DCHECK_IS_ON() is_ua_rule_(init.is_ua_rule) {}
is_ua_rule_ = init.is_ua_rule;
#endif
}
SelectorChecker(const SelectorChecker&) = delete; SelectorChecker(const SelectorChecker&) = delete;
SelectorChecker& operator=(const SelectorChecker&) = delete; SelectorChecker& operator=(const SelectorChecker&) = delete;
...@@ -194,11 +191,9 @@ class CORE_EXPORT SelectorChecker { ...@@ -194,11 +191,9 @@ class CORE_EXPORT SelectorChecker {
PartNames* part_names_; PartNames* part_names_;
ScrollbarPart scrollbar_part_; ScrollbarPart scrollbar_part_;
Mode mode_; Mode mode_;
bool is_ua_rule_;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
mutable bool inside_match_ = false; mutable bool inside_match_ = false;
bool is_ua_rule_;
#else
static constexpr bool is_ua_rule_ = true;
#endif #endif
}; };
......
...@@ -4067,4 +4067,28 @@ TEST_F(StyleEngineTest, AudioUAStyleNameSpace) { ...@@ -4067,4 +4067,28 @@ TEST_F(StyleEngineTest, AudioUAStyleNameSpace) {
EXPECT_FALSE(html_audio->GetComputedStyle()); 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 } // namespace blink
...@@ -31021,6 +31021,7 @@ Called by update_use_counter_feature_enum.py.--> ...@@ -31021,6 +31021,7 @@ Called by update_use_counter_feature_enum.py.-->
<int value="3777" label="V8TCPSocket_Writable_AttributeGetter"/> <int value="3777" label="V8TCPSocket_Writable_AttributeGetter"/>
<int value="3778" label="V8TCPSocket_RemoteAddress_AttributeGetter"/> <int value="3778" label="V8TCPSocket_RemoteAddress_AttributeGetter"/>
<int value="3779" label="V8TCPSocket_RemotePort_AttributeGetter"/> <int value="3779" label="V8TCPSocket_RemotePort_AttributeGetter"/>
<int value="3780" label="CSSSelectorTargetText"/>
</enum> </enum>
<enum name="FeaturePolicyAllowlistType"> <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