Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5786)

Unified Diff: chrome/browser/resources/chromeos/chromevox/s2s/background/background.js

Issue 1536493002: Working proof of concept of select to speak (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Drag across multiple objects Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/s2s/background/background.js
diff --git a/chrome/browser/resources/chromeos/chromevox/s2s/background/background.js b/chrome/browser/resources/chromeos/chromevox/s2s/background/background.js
new file mode 100644
index 0000000000000000000000000000000000000000..52926f7693d7af637338600cd7543d261ecdd08a
--- /dev/null
+++ b/chrome/browser/resources/chromeos/chromevox/s2s/background/background.js
@@ -0,0 +1,103 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+goog.provide('s2s.Background');
+goog.require('AutomationUtil');
+
+goog.scope(function() {
+var RoleType = chrome.automation.RoleType;
+
+s2s.Background = function() {
+ chrome.tts.speak('Select to speak');
+ this.spokenSelection_ = new s2s.SpokenSelection();
+};
+
+s2s.Background.prototype = {
+};
+
+s2s.SpokenSelection = function() {
+ this.node_ = null;
+ this.down_ = false;
+
+ chrome.automation.getDesktop(function(d) {
+ d.addEventListener('mousePressed', this.onMousePressed.bind(this), true);
+ d.addEventListener('mouseDragged', this.onMouseDragged.bind(this), true);
+ d.addEventListener('mouseMoved', this.onMouseDragged.bind(this), true);
+ d.addEventListener('mouseReleased', this.onMouseReleased.bind(this), true);
+ }.bind(this));
+};
+
+s2s.SpokenSelection.prototype = {
+ onMousePressed: function(evt) {
+ this.node_ = null;
+ this.down_ = true;
+ chrome.tts.stop();
+ this.onMouseDragged(evt);
+ },
+
+ onMouseDragged: function(evt) {
+ if (!this.down_)
+ return;
+
+ var node = evt.target;
+ if (!this.node_) {
+ while (node && !node.name)
+ node = node.parent;
+ this.node_ = node;
+ } else {
+ var a1 = AutomationUtil.getAncestors(this.node_);
+ var a2 = AutomationUtil.getAncestors(node);
+ var d = AutomationUtil.getDivergence(a1, a2);
+ if (d > 0) {
+ this.node_ = a1[d - 1];
+ }
+ }
+
+ chrome.accessibilityPrivate.setFocusRing([this.node_.location]);
+ },
+
+ onMouseReleased: function(evt) {
+ this.onMouseDragged(evt);
+ this.down_ = false;
+
+ if (!this.node_) {
+ chrome.accessibilityPrivate.setFocusRing([]);
+ return;
+ }
+
+ this.enqueue_ = false;
+ this.speakAllDescendants_(this.node_);
+
+ window.setTimeout(function() {
+ chrome.accessibilityPrivate.setFocusRing([]);
+ }, 1000);
+ },
+
+ speakAllDescendants_: function(node) {
+ if (this.node_.role == RoleType.inlineTextBox ||
+ this.node_.role == RoleType.staticText) {
+ chrome.tts.speak(node.name, {lang: 'en-US',
+ 'enqueue': this.enqueue_});
+ this.enqueue_ = true;
+ return true;
+ }
+
+ var spoke = false;
+ for (var c = node.firstChild; c; c = c.nextSibling) {
+ if (this.speakAllDescendants_(c))
+ spoke = true;
+ }
+ if (!spoke && node.name) {
+ chrome.tts.speak(node.name, {lang: 'en-US',
+ 'enqueue': this.enqueue_});
+ this.enqueue_ = true;
+ spoke = true;
+ }
+ return spoke;
+ }
+};
+
+new s2s.Background();
+
+}); // goog.scope

Powered by Google App Engine
This is Rietveld 408576698