| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Custom bindings for the automation API. | 5 // Custom bindings for the automation API. |
| 6 var AutomationNode = require('automationNode').AutomationNode; | 6 var AutomationNode = require('automationNode').AutomationNode; |
| 7 var AutomationRootNode = require('automationNode').AutomationRootNode; | 7 var AutomationRootNode = require('automationNode').AutomationRootNode; |
| 8 var automation = require('binding').Binding.create('automation'); | 8 var automation = require('binding').Binding.create('automation'); |
| 9 var automationInternal = | 9 var automationInternal = |
| 10 require('binding').Binding.create('automationInternal').generate(); | 10 require('binding').Binding.create('automationInternal').generate(); |
| 11 var eventBindings = require('event_bindings'); | 11 var eventBindings = require('event_bindings'); |
| 12 var Event = eventBindings.Event; | 12 var Event = eventBindings.Event; |
| 13 var exceptionHandler = require('uncaught_exception_handler'); | 13 var exceptionHandler = require('uncaught_exception_handler'); |
| 14 var forEach = require('utils').forEach; | 14 var forEach = require('utils').forEach; |
| 15 var lastError = require('lastError'); | 15 var lastError = require('lastError'); |
| 16 var logging = requireNative('logging'); | 16 var logging = requireNative('logging'); |
| 17 var nativeAutomationInternal = requireNative('automationInternal'); | 17 var nativeAutomationInternal = requireNative('automationInternal'); |
| 18 var GetRoutingID = nativeAutomationInternal.GetRoutingID; | 18 var GetRoutingID = nativeAutomationInternal.GetRoutingID; |
| 19 var GetSchemaAdditions = nativeAutomationInternal.GetSchemaAdditions; | 19 var GetSchemaAdditions = nativeAutomationInternal.GetSchemaAdditions; |
| 20 var DestroyAccessibilityTree = | 20 var DestroyAccessibilityTree = |
| 21 nativeAutomationInternal.DestroyAccessibilityTree; | 21 nativeAutomationInternal.DestroyAccessibilityTree; |
| 22 var GetIntAttribute = nativeAutomationInternal.GetIntAttribute; | 22 var GetIntAttribute = nativeAutomationInternal.GetIntAttribute; |
| 23 var StartCachingAccessibilityTrees = | 23 var StartCachingAccessibilityTrees = |
| 24 nativeAutomationInternal.StartCachingAccessibilityTrees; | 24 nativeAutomationInternal.StartCachingAccessibilityTrees; |
| 25 var AddTreeChangeObserver = nativeAutomationInternal.AddTreeChangeObserver; | 25 var AddTreeChangeObserver = nativeAutomationInternal.AddTreeChangeObserver; |
| 26 var RemoveTreeChangeObserver = | 26 var RemoveTreeChangeObserver = |
| 27 nativeAutomationInternal.RemoveTreeChangeObserver; | 27 nativeAutomationInternal.RemoveTreeChangeObserver; |
| 28 var GetFocus = nativeAutomationInternal.GetFocus; | 28 var GetFocusNative = nativeAutomationInternal.GetFocus; |
| 29 var schema = GetSchemaAdditions(); | 29 var schema = GetSchemaAdditions(); |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * A namespace to export utility functions to other files in automation. | 32 * A namespace to export utility functions to other files in automation. |
| 33 */ | 33 */ |
| 34 window.automationUtil = function() {}; | 34 window.automationUtil = function() {}; |
| 35 | 35 |
| 36 // TODO(aboxhall): Look into using WeakMap | 36 // TODO(aboxhall): Look into using WeakMap |
| 37 var idToCallback = {}; | 37 var idToCallback = {}; |
| 38 | 38 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 67 */ | 67 */ |
| 68 automationUtil.nextTreeChangeObserverId = 1; | 68 automationUtil.nextTreeChangeObserverId = 1; |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * @type {AutomationNode} The current focused node. This is only updated | 71 * @type {AutomationNode} The current focused node. This is only updated |
| 72 * when calling automationUtil.updateFocusedNode. | 72 * when calling automationUtil.updateFocusedNode. |
| 73 */ | 73 */ |
| 74 automationUtil.focusedNode = null; | 74 automationUtil.focusedNode = null; |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * Gets the currently focused AutomationNode. |
| 78 * @return {AutomationNode} |
| 79 */ |
| 80 automationUtil.getFocus = function() { |
| 81 var focusedNodeInfo = GetFocusNative(DESKTOP_TREE_ID); |
| 82 if (!focusedNodeInfo) |
| 83 return null; |
| 84 var tree = AutomationRootNode.getOrCreate(focusedNodeInfo.treeId); |
| 85 if (tree) |
| 86 return privates(tree).impl.get(focusedNodeInfo.nodeId); |
| 87 }; |
| 88 |
| 89 /** |
| 77 * Update automationUtil.focusedNode to be the node that currently has focus. | 90 * Update automationUtil.focusedNode to be the node that currently has focus. |
| 78 */ | 91 */ |
| 79 automationUtil.updateFocusedNode = function() { | 92 automationUtil.updateFocusedNode = function() { |
| 80 automationUtil.focusedNode = null; | 93 automationUtil.focusedNode = automationUtil.getFocus(); |
| 81 var focusedNodeInfo = GetFocus(DESKTOP_TREE_ID); | |
| 82 if (!focusedNodeInfo) | |
| 83 return; | |
| 84 var tree = AutomationRootNode.getOrCreate(focusedNodeInfo.treeId); | |
| 85 if (tree) { | |
| 86 automationUtil.focusedNode = | |
| 87 privates(tree).impl.get(focusedNodeInfo.nodeId); | |
| 88 } | |
| 89 }; | 94 }; |
| 90 | 95 |
| 91 automation.registerCustomHook(function(bindingsAPI) { | 96 automation.registerCustomHook(function(bindingsAPI) { |
| 92 var apiFunctions = bindingsAPI.apiFunctions; | 97 var apiFunctions = bindingsAPI.apiFunctions; |
| 93 | 98 |
| 94 // TODO(aboxhall, dtseng): Make this return the speced AutomationRootNode obj. | 99 // TODO(aboxhall, dtseng): Make this return the speced AutomationRootNode obj. |
| 95 apiFunctions.setHandleRequest('getTree', function getTree(tabID, callback) { | 100 apiFunctions.setHandleRequest('getTree', function getTree(tabID, callback) { |
| 96 var routingID = GetRoutingID(); | 101 var routingID = GetRoutingID(); |
| 97 StartCachingAccessibilityTrees(); | 102 StartCachingAccessibilityTrees(); |
| 98 | 103 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 callback(); | 139 callback(); |
| 135 return; | 140 return; |
| 136 } | 141 } |
| 137 }); | 142 }); |
| 138 } else { | 143 } else { |
| 139 callback(desktopTree); | 144 callback(desktopTree); |
| 140 } | 145 } |
| 141 }); | 146 }); |
| 142 | 147 |
| 143 apiFunctions.setHandleRequest('getFocus', function(callback) { | 148 apiFunctions.setHandleRequest('getFocus', function(callback) { |
| 144 automationUtil.updateFocusedNode(); | 149 callback(automationUtil.getFocus()); |
| 145 callback(automationUtil.focusedNode); | |
| 146 }); | 150 }); |
| 147 | 151 |
| 148 function removeTreeChangeObserver(observer) { | 152 function removeTreeChangeObserver(observer) { |
| 149 for (var id in automationUtil.treeChangeObserverMap) { | 153 for (var id in automationUtil.treeChangeObserverMap) { |
| 150 if (automationUtil.treeChangeObserverMap[id] == observer) { | 154 if (automationUtil.treeChangeObserverMap[id] == observer) { |
| 151 RemoveTreeChangeObserver(id); | 155 RemoveTreeChangeObserver(id); |
| 152 delete automationUtil.treeChangeObserverMap[id]; | 156 delete automationUtil.treeChangeObserverMap[id]; |
| 153 return; | 157 return; |
| 154 } | 158 } |
| 155 } | 159 } |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 337 |
| 334 var binding = automation.generate(); | 338 var binding = automation.generate(); |
| 335 // Add additional accessibility bindings not specified in the automation IDL. | 339 // Add additional accessibility bindings not specified in the automation IDL. |
| 336 // Accessibility and automation share some APIs (see | 340 // Accessibility and automation share some APIs (see |
| 337 // ui/accessibility/ax_enums.idl). | 341 // ui/accessibility/ax_enums.idl). |
| 338 forEach(schema, function(k, v) { | 342 forEach(schema, function(k, v) { |
| 339 binding[k] = v; | 343 binding[k] = v; |
| 340 }); | 344 }); |
| 341 | 345 |
| 342 exports.$set('binding', binding); | 346 exports.$set('binding', binding); |
| OLD | NEW |