| Index: chrome/renderer/resources/extensions/automation_custom_bindings.js
|
| diff --git a/chrome/renderer/resources/extensions/automation_custom_bindings.js b/chrome/renderer/resources/extensions/automation_custom_bindings.js
|
| index c09243ae6219431b151093548a5859ca84a1698f..b06dbae096506d2f1b331de2e62ecc1a7f725837 100644
|
| --- a/chrome/renderer/resources/extensions/automation_custom_bindings.js
|
| +++ b/chrome/renderer/resources/extensions/automation_custom_bindings.js
|
| @@ -25,6 +25,7 @@ var StartCachingAccessibilityTrees =
|
| var AddTreeChangeObserver = nativeAutomationInternal.AddTreeChangeObserver;
|
| var RemoveTreeChangeObserver =
|
| nativeAutomationInternal.RemoveTreeChangeObserver;
|
| +var GetFocus = nativeAutomationInternal.GetFocus;
|
| var schema = GetSchemaAdditions();
|
|
|
| /**
|
| @@ -66,6 +67,38 @@ automationUtil.treeChangeObserverMap = {};
|
| */
|
| automationUtil.nextTreeChangeObserverId = 1;
|
|
|
| +/**
|
| + * @type {AutomationNode} The current focused node. This is only updated
|
| + * when calling automationUtil.updateFocusedNode.
|
| + */
|
| +automationUtil.focusedNode = null;
|
| +
|
| +/**
|
| + * Update automationUtil.focusedNode to be the node that currently has focus.
|
| + */
|
| +automationUtil.updateFocusedNode = function() {
|
| + automationUtil.focusedNode = null;
|
| + console.log('updateFocusedNode calling GetFocus');
|
| + var focusedNodeInfo = GetFocus(DESKTOP_TREE_ID);
|
| + console.log('updateFocusedNode calling GetFocus done:');
|
| + console.log(focusedNodeInfo);
|
| + console.log(JSON.stringify(focusedNodeInfo));
|
| + if (!focusedNodeInfo) {
|
| + console.log('updateFocusedNode return 1');
|
| + return;
|
| + }
|
| + var tree = AutomationRootNode.getOrCreate(focusedNodeInfo.treeId);
|
| + if (tree) {
|
| + console.log('updateFocusedNode return 2');
|
| + automationUtil.focusedNode =
|
| + privates(tree).impl.get(focusedNodeInfo.nodeId);
|
| + } else {
|
| + console.log('updateFocusedNode return 3');
|
| + }
|
| +
|
| + console.log('updateFocusedNode returning: ' + automationUtil.focusedNode);
|
| +};
|
| +
|
| automation.registerCustomHook(function(bindingsAPI) {
|
| var apiFunctions = bindingsAPI.apiFunctions;
|
|
|
| @@ -118,6 +151,15 @@ automation.registerCustomHook(function(bindingsAPI) {
|
| }
|
| });
|
|
|
| + apiFunctions.setHandleRequest('getFocus', function() {
|
| + console.log('automation_custom_bindings getFocus');
|
| + automationUtil.updateFocusedNode();
|
| + console.log('automation_custom_bindings getFocus 2');
|
| + console.log('automation_custom_bindings getFocus 2 returning: ' +
|
| + automationUtil.focusedNode);
|
| + return automationUtil.focusedNode;
|
| + });
|
| +
|
| function removeTreeChangeObserver(observer) {
|
| for (var id in automationUtil.treeChangeObserverMap) {
|
| if (automationUtil.treeChangeObserverMap[id] == observer) {
|
| @@ -231,14 +273,34 @@ automationInternal.onNodesRemoved.addListener(function(treeID, nodeIDs) {
|
| }
|
| });
|
|
|
| -// Listen to the automationInternal.onAccessibilityEvent event, which is
|
| -// essentially a proxy for the AccessibilityHostMsg_Events IPC from the
|
| -// renderer.
|
| -automationInternal.onAccessibilityEvent.addListener(function(data) {
|
| - var id = data.treeID;
|
| +/**
|
| + * Dispatch accessibility events fired on individual nodes to its
|
| + * corresponding AutomationNode. Handle focus events specially
|
| + * (see below).
|
| + */
|
| +automationInternal.onAccessibilityEvent.addListener(function(eventParams) {
|
| + var id = eventParams.treeID;
|
| var targetTree = AutomationRootNode.getOrCreate(id);
|
|
|
| - if (!privates(targetTree).impl.onAccessibilityEvent(data))
|
| + // 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 (eventParams.eventType == schema.EventType.focus) {
|
| + 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;
|
| + }
|
| + }
|
| +
|
| + if (!privates(targetTree).impl.onAccessibilityEvent(eventParams))
|
| return;
|
|
|
| // If we're not waiting on a callback to getTree(), we can early out here.
|
|
|