Commit a3680df5 authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

An accessible click action on an element should focus the element too.

When you click on a focusable element with the mouse, the element gets
focused in addition to receiving click events.

In contrast, this wasn't always happening when using accessibility APIs to
click on an element. Note that on many platforms, assistive technology
was already triggering a focus action, when the user has enabled automatic
focus. In those cases, this change will have no effect. If the user turns off
automatic focusing in their AT, this change will have the effect of focusing
an element before clicking on it.

This bug was reported on Android. Prior to Android O, TalkBack used to
send a click event when the user double-tapped. Now, TalkBack sends
ACTION_CLICK, which results in clicking elements without first focusing them.

Bug: 791285, 901511
Change-Id: I0ae7664c4e80bd806e008fb86740fbae547ef582
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864416Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710232}
parent 4f640a8f
......@@ -136,6 +136,38 @@ class AccessibilityCanvasActionBrowserTest
}
};
IN_PROC_BROWSER_TEST_F(AccessibilityActionBrowserTest, DoDefaultAction) {
LoadInitialAccessibilityTreeFromHtml(R"HTML(
<div id="button" role="button" tabIndex=0>Click</div>
<p></p>
<script>
document.getElementById('button').addEventListener('click', () => {
document.querySelector('p').setAttribute('aria-label', 'success');
});
</script>
)HTML");
BrowserAccessibility* target = FindNode(ax::mojom::Role::kButton, "Click");
ASSERT_NE(nullptr, target);
// Call DoDefaultAction.
AccessibilityNotificationWaiter waiter2(
shell()->web_contents(), ui::kAXModeComplete, ax::mojom::Event::kClicked);
GetManager()->DoDefaultAction(*target);
waiter2.WaitForNotification();
// Ensure that the button was clicked - it should change the paragraph
// text to "success".
WaitForAccessibilityTreeToContainNodeWithName(shell()->web_contents(),
"success");
// When calling DoDefault on a focusable element, the element should get
// focused, just like what happens when you click it with the mouse.
BrowserAccessibility* focus = GetManager()->GetFocus();
ASSERT_NE(nullptr, focus);
EXPECT_EQ(target->GetId(), focus->GetId());
}
IN_PROC_BROWSER_TEST_F(AccessibilityActionBrowserTest, FocusAction) {
LoadInitialAccessibilityTreeFromHtml(R"HTML(
<button>One</button>
......
......@@ -52,6 +52,7 @@
#include "third_party/blink/renderer/core/layout/layout_box_model_object.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/modules/accessibility/ax_object_cache_impl.h"
#include "third_party/blink/renderer/modules/accessibility/ax_range.h"
......@@ -3133,6 +3134,26 @@ bool AXObject::OnNativeClickAction() {
return OnNativeFocusAction();
if (element) {
// Always set the sequential focus navigation starting point.
// Even if this element isn't focusable, if you press "Tab" it will
// start the search from this element.
GetDocument()->SetSequentialFocusNavigationStartingPoint(element);
// Explicitly focus the element if it's focusable but not currently
// the focused element, to be consistent with
// EventHandler::HandleMousePressEvent.
if (element->IsMouseFocusable() && !element->IsFocusedElementInDocument()) {
Page* const page = GetDocument()->GetPage();
if (page) {
page->GetFocusController().SetFocusedElement(
element, GetDocument()->GetFrame(),
FocusParams(SelectionBehaviorOnFocus::kNone, kWebFocusTypeMouse,
nullptr));
}
}
// For most elements, AccessKeyAction triggers sending a simulated
// click, including simulating the mousedown, mouseup, and click events.
element->AccessKeyAction(true);
return true;
}
......
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