Commit 32e39dcd authored by David Tseng's avatar David Tseng Committed by Commit Bot

Do not infer focus/blur events on some AXTrees

On trunk, we currently fire (infer) a focus event when the focused node changes.

For events originating from Blink, it is not reliable to infer focus events because |event_from| cannot be properly associated with the generated or inferred event or even the set of node updates.

This issue only comes up when repeated accessibility actions are performed, quickly.

The change will fix firing of some focus events that contain the wrong event from value. The user visible change is that ChromeVox will not sync focus (thinking it is not a focus triggered from its own action).

Change-Id: I9926e1d0a03f8a70011c7d38d709eb1c77baee26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1640141
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665585}
parent 1fc6b437
......@@ -1994,6 +1994,29 @@ void AutomationInternalCustomBindings::SendAutomationEvent(
void AutomationInternalCustomBindings::MaybeSendFocusAndBlur(
AutomationAXTreeWrapper* tree,
const ExtensionMsg_AccessibilityEventBundleParams& event_bundle) {
// Only send focus or blur if we got one of these events from the originating
// renderer. While sending events purely based upon whether the targeted
// focus/blur node changed may work, we end up firing too many events since
// intermediate states trigger more events than likely necessary. Also, the
// |event_from| field is only properly associated with focus/blur when the
// event type is also focus/blur.
base::Optional<ax::mojom::EventFrom> event_from;
for (const auto& event : event_bundle.events) {
if (event.event_type == ax::mojom::Event::kBlur ||
event.event_type == ax::mojom::Event::kFocus)
event_from = event.event_from;
}
if (!event_from) {
// There was no explicit focus/blur; return early.
// Make an exception for the desktop tree, where we can reliably infer
// focus/blur even without an explicit event.
if (!tree->IsDesktopTree())
return;
event_from = ax::mojom::EventFrom::kNone;
}
// Get the root-most tree.
AutomationAXTreeWrapper* root_tree = tree;
while (
......@@ -2014,18 +2037,11 @@ void AutomationInternalCustomBindings::MaybeSendFocusAndBlur(
if (new_wrapper == old_wrapper && new_node == old_node)
return;
ax::mojom::EventFrom event_from = ax::mojom::EventFrom::kNone;
for (const auto& event : event_bundle.events) {
if (event.event_type == ax::mojom::Event::kFocus ||
event.event_type == ax::mojom::Event::kBlur)
event_from = event.event_from;
}
// Blur previous focus.
if (old_node) {
ui::AXEvent blur_event;
blur_event.id = old_node->id();
blur_event.event_from = event_from;
blur_event.event_from = *event_from;
SendAutomationEvent(old_wrapper->tree_id(), event_bundle.mouse_location,
blur_event, api::automation::EVENT_TYPE_BLUR);
......@@ -2037,7 +2053,7 @@ void AutomationInternalCustomBindings::MaybeSendFocusAndBlur(
if (new_node) {
ui::AXEvent focus_event;
focus_event.id = new_node->id();
focus_event.event_from = event_from;
focus_event.event_from = *event_from;
SendAutomationEvent(new_wrapper->tree_id(), event_bundle.mouse_location,
focus_event, api::automation::EVENT_TYPE_FOCUS);
focus_id_ = new_node->id();
......
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