Commit 0b789948 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Reland: Fire focus if needed in automation api

TBR=dtseng@chromium.org
Bug: 773866

Original change

Reviewed-on: https://chromium-review.googlesource.com/723606
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#509911}
Change-Id: I74c39f7d8372b623a827dff89cc20b25f6485a2f
Reviewed-on: https://chromium-review.googlesource.com/727122Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510006}
parent d7b19dd0
......@@ -513,16 +513,6 @@ IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, OverviewMode) {
IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, MAYBE_ChromeVoxShiftSearch) {
EnableChromeVox();
ui_test_utils::NavigateToURL(
browser(),
GURL("data:text/html;charset=utf-8,<button autofocus>Click me</button>"));
while (true) {
std::string utterance = speech_monitor_.GetNextUtterance();
if (utterance == "Click me")
break;
}
EXPECT_EQ("Button", speech_monitor_.GetNextUtterance());
// Press Search+/ to enter ChromeVox's "find in page".
SendKeyPressWithSearch(ui::VKEY_OEM_2);
......
......@@ -285,11 +285,7 @@ automationInternal.onNodesRemoved.addListener(function(treeID, nodeIDs) {
automationInternal.onAccessibilityEvent.addListener(function(eventParams) {
var id = eventParams.treeID;
var targetTree = AutomationRootNode.getOrCreate(id);
var isFocusEvent = false;
if (eventParams.eventType == 'focus') {
isFocusEvent = true;
} else if (eventParams.eventType == 'blur') {
if (eventParams.eventType == 'blur') {
// Work around an issue where Chrome sends us 'blur' events on the
// root node when nothing has focus, we need to treat those as focus
// events but otherwise not handle blur events specially.
......@@ -300,27 +296,31 @@ automationInternal.onAccessibilityEvent.addListener(function(eventParams) {
eventParams.eventType == 'mediaStoppedPlaying') {
// These events are global to the tree.
eventParams.targetID = privates(targetTree).impl.id;
}
// When we get a focus event, ignore the actual event target, and instead
// check what node has focus globally. If that represents a focus change,
// fire a focus event on the correct target.
if (isFocusEvent) {
} else {
var previousFocusedNode = automationUtil.focusedNode;
automationUtil.updateFocusedNode();
if (automationUtil.focusedNode &&
automationUtil.focusedNode == previousFocusedNode) {
return;
}
if (automationUtil.focusedNode) {
targetTree = automationUtil.focusedNode.root;
eventParams.treeID = privates(targetTree).impl.treeID;
eventParams.targetID = privates(automationUtil.focusedNode).impl.id;
// Fire focus events if necessary.
if (automationUtil.focusedNode &&
automationUtil.focusedNode != previousFocusedNode) {
var eventParamsCopy = {};
for (var key in eventParams)
eventParamsCopy[key] = eventParams[key];
eventParamsCopy['eventType'] = 'focus';
eventParamsCopy['treeID'] =
privates(automationUtil.focusedNode.root).impl.treeID;
eventParamsCopy['targetID'] =
privates(automationUtil.focusedNode).impl.id;
privates(automationUtil.focusedNode.root)
.impl.onAccessibilityEvent(eventParamsCopy);
}
}
if (!privates(targetTree).impl.onAccessibilityEvent(eventParams))
// Note that focus type events have already been handled above if there was a
// focused node. All other events, even non-focus events that triggered a
// focus dispatch, still need to have their original event fired.
if ((!automationUtil.focusedNode || eventParams.eventType != 'focus') &&
!privates(targetTree).impl.onAccessibilityEvent(eventParams))
return;
// If we're not waiting on a callback to getTree(), we can early out here.
......
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