Commit 242ce7d8 authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

Add use counters for delegatesFocus

The focus delegation behavior might change as proposed in
https://github.com/w3c/webcomponents/issues/830.

This CL adds use counter for when a host with delegatesFocus is focused,
and when the result of the focus delegation is different than the
proposed change, to see the possible impact of the change.

Bug: 692678
Change-Id: I90a0a10e1e5adbd3fe018ea772e1d560fedec9a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1794945Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695100}
parent feae6e0e
...@@ -2410,6 +2410,8 @@ enum WebFeature { ...@@ -2410,6 +2410,8 @@ enum WebFeature {
kPointerLockUnadjustedMovement = 3027, kPointerLockUnadjustedMovement = 3027,
kCreateObjectBlob = 3028, kCreateObjectBlob = 3028,
kQuotaRead = 3029, kQuotaRead = 3029,
kDelegateFocus = 3030,
kDelegateFocusNotFirstInFlatTree = 3031,
// 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.
......
...@@ -3740,6 +3740,7 @@ void Element::focus(const FocusParams& params) { ...@@ -3740,6 +3740,7 @@ void Element::focus(const FocusParams& params) {
return; return;
if (AuthorShadowRoot() && AuthorShadowRoot()->delegatesFocus()) { if (AuthorShadowRoot() && AuthorShadowRoot()->delegatesFocus()) {
UseCounter::Count(GetDocument(), WebFeature::kDelegateFocus);
Element* focused_element = GetDocument().FocusedElement(); Element* focused_element = GetDocument().FocusedElement();
if (focused_element && if (focused_element &&
IsShadowIncludingInclusiveAncestorOf(*focused_element)) IsShadowIncludingInclusiveAncestorOf(*focused_element))
......
...@@ -649,6 +649,7 @@ bool MouseEventManager::SlideFocusOnShadowHostIfNecessary( ...@@ -649,6 +649,7 @@ bool MouseEventManager::SlideFocusOnShadowHostIfNecessary(
if (element.AuthorShadowRoot() && if (element.AuthorShadowRoot() &&
element.AuthorShadowRoot()->delegatesFocus()) { element.AuthorShadowRoot()->delegatesFocus()) {
Document* doc = frame_->GetDocument(); Document* doc = frame_->GetDocument();
UseCounter::Count(doc, WebFeature::kDelegateFocus);
Element* focused_element = doc->FocusedElement(); Element* focused_element = doc->FocusedElement();
if (focused_element && if (focused_element &&
element.IsShadowIncludingInclusiveAncestorOf(*focused_element)) { element.IsShadowIncludingInclusiveAncestorOf(*focused_element)) {
......
...@@ -1190,8 +1190,29 @@ Element* FocusController::FindFocusableElementInShadowHost( ...@@ -1190,8 +1190,29 @@ Element* FocusController::FindFocusableElementInShadowHost(
OwnerMap owner_map; OwnerMap owner_map;
ScopedFocusNavigation scope = ScopedFocusNavigation scope =
ScopedFocusNavigation::OwnedByShadowHost(shadow_host, owner_map); ScopedFocusNavigation::OwnedByShadowHost(shadow_host, owner_map);
return FindFocusableElementAcrossFocusScopes(kWebFocusTypeForward, scope, Element* result = FindFocusableElementAcrossFocusScopes(kWebFocusTypeForward,
owner_map); scope, owner_map);
if (!result)
return nullptr;
// Check if |found| is the first focusable element under |element|, and count
// if it's not.
const Node* current = &shadow_host;
while ((current = FlatTreeTraversal::Next(*current))) {
if (!current->IsElementNode())
continue;
if (current == result) {
// We've reached |found|, which means |found| is the first focusable
// element so we don't count this.
break;
}
if (ToElement(current)->IsFocusable()) {
UseCounter::Count(shadow_host.GetDocument(),
WebFeature::kDelegateFocusNotFirstInFlatTree);
break;
}
}
return result;
} }
Element* FocusController::FindFocusableElementAfter(Element& element, Element* FocusController::FindFocusableElementAfter(Element& element,
......
...@@ -24615,6 +24615,8 @@ Called by update_net_error_codes.py.--> ...@@ -24615,6 +24615,8 @@ Called by update_net_error_codes.py.-->
<int value="3027" label="PointerLockUnadjustedMovement"/> <int value="3027" label="PointerLockUnadjustedMovement"/>
<int value="3028" label="CreateObjectBlob"/> <int value="3028" label="CreateObjectBlob"/>
<int value="3029" label="QuotaRead"/> <int value="3029" label="QuotaRead"/>
<int value="3030" label="DelegateFocus"/>
<int value="3031" label="DelegateFocusNotFirstInFlatTree"/>
</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