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

Side by Side Diff: chrome/browser/resources/chromeos/switch_access/switch_access.js

Issue 2711343005: Set keys to traverse accessibility tree. Using focus ring to highlight selected node. (Closed)
Patch Set: Fixing closure compilation error Created 3 years, 9 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 console.log("Switch access is enabled"); 5 var AutomationNode = chrome.automation.AutomationNode;
6
7 /**
8 * @constructor
9 */
10 var SwitchAccess = function() {
11 console.log("Switch access is enabled");
12
13 // Currently selected node.
14 /** @private {AutomationNode} */
15 this.node_ = null;
16
17 // List of nodes to push to / pop from in case this.node_ is lost.
18 /** @private {!Array<!AutomationNode>} */
19 this.ancestorList_ = [];
20
21 chrome.automation.getDesktop(function(desktop) {
22 this.node_ = desktop;
23 console.log("AutomationNode for desktop is loaded");
24 this.printDetails_();
25
26 document.addEventListener("keyup", function(event) {
27 if (event.key === "1") {
28 console.log("1 = go to previous element");
29 this.moveToPrevious_();
30 } else if (event.key === "2") {
31 console.log("2 = go to next element");
32 this.moveToNext_();
33 } else if (event.key === "3") {
34 console.log("3 = go to child element");
35 this.moveToFirstChild_();
36 } else if (event.key === "4") {
37 console.log("4 = go to parent element");
38 this.moveToParent_();
39 } else if (event.key === "5") {
40 console.log("5 is not yet implemented");
41 console.log("\n");
42 }
43 chrome.accessibilityPrivate.setFocusRing([this.node_.location]);
44 }.bind(this));
45 }.bind(this));
46 };
47
48 SwitchAccess.prototype = {
49 /**
50 * Move to the previous sibling of this.node_ if it has one.
51 */
52 moveToPrevious_: function() {
53 var previous = this.node_.previousSibling;
54 if (previous) {
55 this.node_ = previous;
56 this.printDetails_();
57 } else {
58 console.log("Node is first of siblings");
59 console.log("\n");
60 }
61 },
62
63 /**
64 * Move to the next sibling of this.node_ if it has one.
65 */
66 moveToNext_: function() {
67 var next = this.node_.nextSibling;
68 if (next) {
69 this.node_ = next;
70 this.printDetails_();
71 } else {
72 console.log("Node is last of siblings");
73 console.log("\n");
74 }
75 },
76
77 /**
78 * Move to the first child of this.node_ if it has one.
79 */
80 moveToFirstChild_: function() {
81 var child = this.node_.firstChild;
82 if (child) {
83 this.ancestorList_.push(this.node_);
84 this.node_ = child;
85 this.printDetails_();
86 } else {
87 console.log("Node has no children");
88 console.log("\n");
89 }
90 },
91
92 /**
93 * Move to the parent of this.node_ if it has one. If it does not have a
94 * parent but it is not the top level root node, then this.node_ lost track of
95 * its neighbors, and we move to an ancestor node.
96 */
97 moveToParent_: function() {
98 var parent = this.node_.parent;
99 if (parent) {
100 this.ancestorList_.pop();
101 this.node_ = parent;
102 this.printDetails_();
103 } else if (this.ancestorList_.length === 0) {
104 console.log("Node has no parent");
105 console.log("\n");
106 } else {
107 console.log(
108 "Node could not find its parent, so moved to recent ancestor");
109 var ancestor = this.ancestorList_.pop();
110 this.node_ = ancestor;
111 this.printDetails_();
112 }
113 },
114
115 /**
116 * Print out details about the currently selected node and the list of
117 * ancestors.
118 *
119 * @private
120 */
121 printDetails_: function() {
122 this.printNode_(this.node_);
123 console.log(this.ancestorList_);
124 console.log("\n");
125 },
126
127 /**
128 * Print out details about a node.
129 *
130 * @param {AutomationNode} node
131 * @private
132 */
133 printNode_: function(node) {
134 if (node) {
135 console.log("Name = " + node.name);
136 console.log("Role = " + node.role);
137 if (!node.parent) {
138 console.log("At index " + node.indexInParent + ", has no parent");
139 } else {
140 var numSiblings = node.parent.children.length;
141 console.log(
142 "At index " + node.indexInParent + ", there are "
143 + numSiblings + " siblings");
144 }
145 console.log("Has " + node.children.length + " children");
146 } else {
147 console.log("Node is null");
148 }
149 console.log(node);
150 }
151 };
152
153 new SwitchAccess();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698