Commit c38ae4cd authored by David Tseng's avatar David Tseng Committed by Commit Bot

Send focus events when old focus is invalidated

R=dmazzoni@chromium.org

Fixed: 1101496
Change-Id: I05693c9d6a5b21b0875c14f9e664337121651734
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2558745
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830798}
parent d96563a1
...@@ -2507,29 +2507,33 @@ void AutomationInternalCustomBindings::SendAutomationEvent( ...@@ -2507,29 +2507,33 @@ void AutomationInternalCustomBindings::SendAutomationEvent(
void AutomationInternalCustomBindings::MaybeSendFocusAndBlur( void AutomationInternalCustomBindings::MaybeSendFocusAndBlur(
AutomationAXTreeWrapper* tree, AutomationAXTreeWrapper* tree,
const ExtensionMsg_AccessibilityEventBundleParams& event_bundle) { const ExtensionMsg_AccessibilityEventBundleParams& event_bundle) {
// Only send focus or blur if we got one of these events from the originating ui::AXNode* old_node = nullptr;
// renderer. While sending events purely based upon whether the targeted AutomationAXTreeWrapper* old_wrapper =
// focus/blur node changed may work, we end up firing too many events since GetAutomationAXTreeWrapperFromTreeID(focus_tree_id_);
// intermediate states trigger more events than likely necessary. Also, the if (old_wrapper) {
// |event_from| field is only properly associated with focus/blur when the old_node =
// event type is also focus/blur. old_wrapper->GetNodeFromTree(old_wrapper->GetTreeID(), focus_id_);
base::Optional<ax::mojom::EventFrom> event_from; }
// Determine whether old focus was lost.
bool lost_old_focus = old_node == nullptr;
// Determine whether there's a focus or blur event and take its event from.
ax::mojom::EventFrom event_from = ax::mojom::EventFrom::kNone;
bool event_bundle_has_focus_or_blur;
for (const auto& event : event_bundle.events) { for (const auto& event : event_bundle.events) {
if (event.event_type == ax::mojom::Event::kBlur || if (event.event_type == ax::mojom::Event::kBlur ||
event.event_type == ax::mojom::Event::kFocus) event.event_type == ax::mojom::Event::kFocus) {
event_from = event.event_from; event_from = event.event_from;
event_bundle_has_focus_or_blur = true;
break;
}
} }
if (!event_from) { bool is_from_desktop = tree->IsDesktopTree();
// There was no explicit focus/blur; return early. if (!event_bundle_has_focus_or_blur && !lost_old_focus && !is_from_desktop)
// Make an exception for the desktop tree, where we can reliably infer
// focus/blur even without an explicit event.
if (!tree->IsDesktopTree())
return; return;
event_from = ax::mojom::EventFrom::kNone;
}
// Get the root-most tree. // Get the root-most tree.
AutomationAXTreeWrapper* root_tree = tree; AutomationAXTreeWrapper* root_tree = tree;
while ((tree = AutomationAXTreeWrapper::GetParentOfTreeId( while ((tree = AutomationAXTreeWrapper::GetParentOfTreeId(
...@@ -2541,13 +2545,6 @@ void AutomationInternalCustomBindings::MaybeSendFocusAndBlur( ...@@ -2541,13 +2545,6 @@ void AutomationInternalCustomBindings::MaybeSendFocusAndBlur(
if (!GetFocusInternal(root_tree, &new_wrapper, &new_node)) if (!GetFocusInternal(root_tree, &new_wrapper, &new_node))
return; return;
ui::AXNode* old_node = nullptr;
AutomationAXTreeWrapper* old_wrapper =
GetAutomationAXTreeWrapperFromTreeID(focus_tree_id_);
if (old_wrapper)
old_node =
old_wrapper->GetNodeFromTree(old_wrapper->GetTreeID(), focus_id_);
if (new_wrapper == old_wrapper && new_node == old_node) if (new_wrapper == old_wrapper && new_node == old_node)
return; return;
...@@ -2555,7 +2552,7 @@ void AutomationInternalCustomBindings::MaybeSendFocusAndBlur( ...@@ -2555,7 +2552,7 @@ void AutomationInternalCustomBindings::MaybeSendFocusAndBlur(
if (old_node) { if (old_node) {
ui::AXEvent blur_event; ui::AXEvent blur_event;
blur_event.id = old_node->id(); blur_event.id = old_node->id();
blur_event.event_from = *event_from; blur_event.event_from = event_from;
blur_event.event_type = ax::mojom::Event::kBlur; blur_event.event_type = ax::mojom::Event::kBlur;
SendAutomationEvent(old_wrapper->GetTreeID(), event_bundle.mouse_location, SendAutomationEvent(old_wrapper->GetTreeID(), event_bundle.mouse_location,
blur_event); blur_event);
...@@ -2568,7 +2565,7 @@ void AutomationInternalCustomBindings::MaybeSendFocusAndBlur( ...@@ -2568,7 +2565,7 @@ void AutomationInternalCustomBindings::MaybeSendFocusAndBlur(
if (new_node) { if (new_node) {
ui::AXEvent focus_event; ui::AXEvent focus_event;
focus_event.id = new_node->id(); focus_event.id = new_node->id();
focus_event.event_from = *event_from; focus_event.event_from = event_from;
focus_event.event_type = ax::mojom::Event::kFocus; focus_event.event_type = ax::mojom::Event::kFocus;
SendAutomationEvent(new_wrapper->GetTreeID(), event_bundle.mouse_location, SendAutomationEvent(new_wrapper->GetTreeID(), event_bundle.mouse_location,
focus_event); focus_event);
......
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