OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 goog.provide('s2s.Background'); |
| 6 goog.require('AutomationUtil'); |
| 7 |
| 8 goog.scope(function() { |
| 9 var RoleType = chrome.automation.RoleType; |
| 10 |
| 11 s2s.Background = function() { |
| 12 chrome.tts.speak('Select to speak'); |
| 13 this.spokenSelection_ = new s2s.SpokenSelection(); |
| 14 }; |
| 15 |
| 16 s2s.Background.prototype = { |
| 17 }; |
| 18 |
| 19 s2s.SpokenSelection = function() { |
| 20 this.node_ = null; |
| 21 this.down_ = false; |
| 22 |
| 23 chrome.automation.getDesktop(function(d) { |
| 24 d.addEventListener('mousePressed', this.onMousePressed.bind(this), true); |
| 25 d.addEventListener('mouseDragged', this.onMouseDragged.bind(this), true); |
| 26 d.addEventListener('mouseMoved', this.onMouseDragged.bind(this), true); |
| 27 d.addEventListener('mouseReleased', this.onMouseReleased.bind(this), true); |
| 28 }.bind(this)); |
| 29 }; |
| 30 |
| 31 s2s.SpokenSelection.prototype = { |
| 32 onMousePressed: function(evt) { |
| 33 this.node_ = null; |
| 34 this.down_ = true; |
| 35 chrome.tts.stop(); |
| 36 this.onMouseDragged(evt); |
| 37 }, |
| 38 |
| 39 onMouseDragged: function(evt) { |
| 40 if (!this.down_) |
| 41 return; |
| 42 |
| 43 var node = evt.target; |
| 44 if (!this.node_) { |
| 45 while (node && !node.name) |
| 46 node = node.parent; |
| 47 this.node_ = node; |
| 48 } else { |
| 49 var a1 = AutomationUtil.getAncestors(this.node_); |
| 50 var a2 = AutomationUtil.getAncestors(node); |
| 51 var d = AutomationUtil.getDivergence(a1, a2); |
| 52 if (d > 0) { |
| 53 this.node_ = a1[d - 1]; |
| 54 } |
| 55 } |
| 56 |
| 57 chrome.accessibilityPrivate.setFocusRing([this.node_.location]); |
| 58 }, |
| 59 |
| 60 onMouseReleased: function(evt) { |
| 61 this.onMouseDragged(evt); |
| 62 this.down_ = false; |
| 63 |
| 64 if (!this.node_) { |
| 65 chrome.accessibilityPrivate.setFocusRing([]); |
| 66 return; |
| 67 } |
| 68 |
| 69 this.enqueue_ = false; |
| 70 this.speakAllDescendants_(this.node_); |
| 71 |
| 72 window.setTimeout(function() { |
| 73 chrome.accessibilityPrivate.setFocusRing([]); |
| 74 }, 1000); |
| 75 }, |
| 76 |
| 77 speakAllDescendants_: function(node) { |
| 78 if (this.node_.role == RoleType.inlineTextBox || |
| 79 this.node_.role == RoleType.staticText) { |
| 80 chrome.tts.speak(node.name, {lang: 'en-US', |
| 81 'enqueue': this.enqueue_}); |
| 82 this.enqueue_ = true; |
| 83 return true; |
| 84 } |
| 85 |
| 86 var spoke = false; |
| 87 for (var c = node.firstChild; c; c = c.nextSibling) { |
| 88 if (this.speakAllDescendants_(c)) |
| 89 spoke = true; |
| 90 } |
| 91 if (!spoke && node.name) { |
| 92 chrome.tts.speak(node.name, {lang: 'en-US', |
| 93 'enqueue': this.enqueue_}); |
| 94 this.enqueue_ = true; |
| 95 spoke = true; |
| 96 } |
| 97 return spoke; |
| 98 } |
| 99 }; |
| 100 |
| 101 new s2s.Background(); |
| 102 |
| 103 }); // goog.scope |
OLD | NEW |