| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 var AutomationEvent = chrome.automation.AutomationEvent; | 5 var AutomationEvent = chrome.automation.AutomationEvent; |
| 6 var AutomationNode = chrome.automation.AutomationNode; | 6 var AutomationNode = chrome.automation.AutomationNode; |
| 7 var EventType = chrome.automation.EventType; | 7 var EventType = chrome.automation.EventType; |
| 8 var RoleType = chrome.automation.RoleType; | 8 var RoleType = chrome.automation.RoleType; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 this.node_ = null; | 53 this.node_ = null; |
| 54 | 54 |
| 55 /** @private { boolean } */ | 55 /** @private { boolean } */ |
| 56 this.down_ = false; | 56 this.down_ = false; |
| 57 | 57 |
| 58 /** @private {{x: number, y: number}} */ | 58 /** @private {{x: number, y: number}} */ |
| 59 this.mouseStart_ = {x: 0, y: 0}; | 59 this.mouseStart_ = {x: 0, y: 0}; |
| 60 | 60 |
| 61 chrome.automation.getDesktop(function(desktop) { | 61 chrome.automation.getDesktop(function(desktop) { |
| 62 desktop.addEventListener( | 62 desktop.addEventListener( |
| 63 EventType.MOUSE_PRESSED, this.onMousePressed_.bind(this), true); | 63 EventType.mousePressed, this.onMousePressed_.bind(this), true); |
| 64 desktop.addEventListener( | 64 desktop.addEventListener( |
| 65 EventType.MOUSE_DRAGGED, this.onMouseDragged_.bind(this), true); | 65 EventType.mouseDragged, this.onMouseDragged_.bind(this), true); |
| 66 desktop.addEventListener( | 66 desktop.addEventListener( |
| 67 EventType.MOUSE_RELEASED, this.onMouseReleased_.bind(this), true); | 67 EventType.mouseReleased, this.onMouseReleased_.bind(this), true); |
| 68 desktop.addEventListener( | 68 desktop.addEventListener( |
| 69 EventType.MOUSE_CANCELED, this.onMouseCanceled_.bind(this), true); | 69 EventType.mouseCanceled, this.onMouseCanceled_.bind(this), true); |
| 70 }.bind(this)); | 70 }.bind(this)); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 SelectToSpeak.prototype = { | 73 SelectToSpeak.prototype = { |
| 74 /** | 74 /** |
| 75 * Called when the mouse is pressed and the user is in a mode where | 75 * Called when the mouse is pressed and the user is in a mode where |
| 76 * select-to-speak is capturing mouse events (for example holding down | 76 * select-to-speak is capturing mouse events (for example holding down |
| 77 * Search). | 77 * Search). |
| 78 * | 78 * |
| 79 * @param {!AutomationEvent} evt | 79 * @param {!AutomationEvent} evt |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 this.down_ = false; | 115 this.down_ = false; |
| 116 | 116 |
| 117 chrome.accessibilityPrivate.setFocusRing([]); | 117 chrome.accessibilityPrivate.setFocusRing([]); |
| 118 | 118 |
| 119 // Walk up to the nearest window, web area, or dialog that the | 119 // Walk up to the nearest window, web area, or dialog that the |
| 120 // hit node is contained inside. Only speak objects within that | 120 // hit node is contained inside. Only speak objects within that |
| 121 // container. In the future we might include other container-like | 121 // container. In the future we might include other container-like |
| 122 // roles here. | 122 // roles here. |
| 123 var root = this.startNode_; | 123 var root = this.startNode_; |
| 124 while (root.parent && | 124 while (root.parent && |
| 125 root.role != RoleType.WINDOW && | 125 root.role != RoleType.window && |
| 126 root.role != RoleType.ROOT_WEB_AREA && | 126 root.role != RoleType.rootWebArea && |
| 127 root.role != RoleType.DESKTOP && | 127 root.role != RoleType.desktop && |
| 128 root.role != RoleType.DIALOG) { | 128 root.role != RoleType.dialog) { |
| 129 root = root.parent; | 129 root = root.parent; |
| 130 } | 130 } |
| 131 | 131 |
| 132 var rect = rectFromPoints( | 132 var rect = rectFromPoints( |
| 133 this.mouseStart_.x, this.mouseStart_.y, | 133 this.mouseStart_.x, this.mouseStart_.y, |
| 134 evt.mouseX, evt.mouseY); | 134 evt.mouseX, evt.mouseY); |
| 135 var nodes = []; | 135 var nodes = []; |
| 136 this.findAllMatching_(root, rect, nodes); | 136 this.findAllMatching_(root, rect, nodes); |
| 137 this.startSpeechQueue_(nodes); | 137 this.startSpeechQueue_(nodes); |
| 138 }, | 138 }, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * Enqueue speech commands for all of the given nodes. | 184 * Enqueue speech commands for all of the given nodes. |
| 185 * @param {Array<AutomationNode>} nodes The nodes to speak. | 185 * @param {Array<AutomationNode>} nodes The nodes to speak. |
| 186 */ | 186 */ |
| 187 startSpeechQueue_: function(nodes) { | 187 startSpeechQueue_: function(nodes) { |
| 188 chrome.tts.stop(); | 188 chrome.tts.stop(); |
| 189 for (var i = 0; i < nodes.length; i++) { | 189 for (var i = 0; i < nodes.length; i++) { |
| 190 var node = nodes[i]; | 190 var node = nodes[i]; |
| 191 var isLast = (i == nodes.length - 1); | 191 var isLast = (i == nodes.length - 1); |
| 192 chrome.tts.speak(node.name || '', { | 192 chrome.tts.speak(node.name, { |
| 193 lang: 'en-US', | 193 lang: 'en-US', |
| 194 'enqueue': true, | 194 'enqueue': true, |
| 195 onEvent: (function(node, isLast, event) { | 195 onEvent: (function(node, isLast, event) { |
| 196 if (event.type == 'start') { | 196 if (event.type == 'start') { |
| 197 chrome.accessibilityPrivate.setFocusRing([node.location]); | 197 chrome.accessibilityPrivate.setFocusRing([node.location]); |
| 198 } else if (event.type == 'interrupted' || | 198 } else if (event.type == 'interrupted' || |
| 199 event.type == 'cancelled') { | 199 event.type == 'cancelled') { |
| 200 chrome.accessibilityPrivate.setFocusRing([]); | 200 chrome.accessibilityPrivate.setFocusRing([]); |
| 201 } else if (event.type == 'end') { | 201 } else if (event.type == 'end') { |
| 202 if (isLast) { | 202 if (isLast) { |
| 203 chrome.accessibilityPrivate.setFocusRing([]); | 203 chrome.accessibilityPrivate.setFocusRing([]); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 }).bind(this, node, isLast) | 206 }).bind(this, node, isLast) |
| 207 }); | 207 }); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 new SelectToSpeak(); | 212 new SelectToSpeak(); |
| OLD | NEW |