Commit e49a7454 authored by Fabian Henneke's avatar Fabian Henneke Committed by Chromium LUCI CQ

Drop HasFocusableNonOptionChild from IsLeaf

In BrowserAccessibilityAndroid, the function HasFocusableNonOptionChild
is used to determine whether an accessibility node can be treated as a
leaf in IsLeaf. This function can be very costly (on the order of a few
milliseconds) since it traverses the tree.

IsLeaf is eventually called by both RetargetForEvent and CanFireEvents,
which in turn are called in every run of the loop over all events in
BrowserAccessibilityManager::OnAccessibilityEvents. For pages with a
complicated tree (e.g. cs.chromium.org), this can cause complete
unresponsiveness for periods of 10s and more.

This change moves the call to HasFocusableNonOptionChild behind the
individual checks for special situations in which the lack of focusable
children would allow to prune the accessibility tree. This results in
far less calls to the function while preserving the structure of the
tree.

Bug: 1014945
Change-Id: Idfde20271847425996d1f370e0fa1d8b964aa3f3
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580802Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836650}
parent d086cd92
......@@ -473,21 +473,27 @@ bool BrowserAccessibilityAndroid::IsLeaf() const {
if (IsLink())
return false;
// If it has a focusable child, we definitely can't leave out children.
if (HasFocusableNonOptionChild())
return false;
BrowserAccessibilityManagerAndroid* manager_android =
static_cast<BrowserAccessibilityManagerAndroid*>(manager());
if (manager_android->prune_tree_for_screen_reader()) {
// Headings with text can drop their children.
base::string16 name = GetInnerText();
if (GetRole() == ax::mojom::Role::kHeading && !name.empty())
return true;
if (GetRole() == ax::mojom::Role::kHeading && !name.empty()) {
if (HasFocusableNonOptionChild()) {
return false;
} else {
return true;
}
}
// Focusable nodes with text can drop their children.
if (HasState(ax::mojom::State::kFocusable) && !name.empty())
return true;
if (HasState(ax::mojom::State::kFocusable) && !name.empty()) {
if (HasFocusableNonOptionChild()) {
return false;
} else {
return true;
}
}
// Nodes with only static text as children can drop their children.
if (HasOnlyTextChildren())
......
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