Chromium Code Reviews| 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 /** | 5 /** |
| 6 * @fileoverview A drop-down menu in the ChromeVox panel. | 6 * @fileoverview A drop-down menu in the ChromeVox panel. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('PanelMenu'); | 9 goog.provide('PanelMenu'); |
| 10 goog.provide('PanelNodeMenu'); | 10 goog.provide('PanelNodeMenu'); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 break; | 222 break; |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 /** | 228 /** |
| 229 * @param {string} menuMsg The msg id of the menu. | 229 * @param {string} menuMsg The msg id of the menu. |
| 230 * @param {chrome.automation.AutomationNode} node ChromeVox's current position. | 230 * @param {chrome.automation.AutomationNode} node ChromeVox's current position. |
| 231 * @param {AutomationPredicate.Unary} pred Filter to use on the document. | 231 * @param {AutomationPredicate.Unary} pred Filter to use on the document. |
| 232 * @param {boolean} defer If true, defers populating the menu. | |
| 232 * @extends {PanelMenu} | 233 * @extends {PanelMenu} |
| 233 * @constructor | 234 * @constructor |
| 234 */ | 235 */ |
| 235 PanelNodeMenu = function(menuMsg, node, pred) { | 236 PanelNodeMenu = function(menuMsg, node, pred, defer) { |
| 236 PanelMenu.call(this, menuMsg); | 237 PanelMenu.call(this, menuMsg); |
| 237 var nodes = []; | 238 this.node_ = node; |
| 238 var selectNext = false; | 239 this.pred_ = pred; |
| 239 var activeIndex = -1; | |
| 240 AutomationUtil.findNodePre(node.root, constants.Dir.FORWARD, | |
| 241 /** @type {AutomationPredicate.Unary} */(function(n) { | |
| 242 if (n === node) | |
| 243 selectNext = true; | |
| 244 | 240 |
| 245 if (pred(n)) { | 241 if (defer) { |
| 246 var output = new Output(); | 242 window.setTimeout((function() { |
| 247 var range = cursors.Range.fromNode(n); | 243 this.populate_(); |
| 248 output.withSpeech(range, range, Output.EventType.NAVIGATE); | 244 }).bind(this), 500); |
|
David Tseng
2016/10/24 22:19:11
It would be great if defer could populate the menu
dmazzoni
2016/10/27 18:56:36
I tried that, but that would actually be more jank
| |
| 249 var label = output.toString(); | 245 } else { |
| 250 this.addMenuItem(label, '', function() { | 246 this.populate_(); |
| 251 chrome.extension.getBackgroundPage().ChromeVoxState | |
| 252 .instance['navigateToRange'](cursors.Range.fromNode(n)); | |
| 253 }); | |
| 254 if (selectNext) { | |
| 255 activeIndex = this.items_.length - 1; | |
| 256 selectNext = false; | |
| 257 } | |
| 258 } | |
| 259 }).bind(this) | |
| 260 ); | |
| 261 | |
| 262 if (!this.items_.length) { | |
| 263 this.addMenuItem( | |
| 264 Msgs.getMsg('panel_menu_item_none'), '', function() {}); | |
| 265 this.activateItem(0); | |
| 266 } | 247 } |
| 267 if (activeIndex >= 0) | |
| 268 this.activateItem(activeIndex); | |
| 269 }; | 248 }; |
| 270 | 249 |
| 271 PanelNodeMenu.prototype = { | 250 PanelNodeMenu.prototype = { |
| 272 __proto__: PanelMenu.prototype, | 251 __proto__: PanelMenu.prototype, |
| 273 | 252 |
| 274 /** @override */ | 253 /** @override */ |
| 275 activate: function() { | 254 activate: function() { |
| 276 var activeItem = this.activeIndex_; | 255 var activeItem = this.activeIndex_; |
| 277 PanelMenu.prototype.activate.call(this); | 256 PanelMenu.prototype.activate.call(this); |
| 278 this.activateItem(activeItem); | 257 this.activateItem(activeItem); |
| 258 }, | |
| 259 | |
|
David Tseng
2016/10/24 22:19:11
js doc
dmazzoni
2016/10/27 18:56:36
Done.
| |
| 260 populate_: function() { | |
| 261 var nodes = []; | |
| 262 var selectNext = false; | |
| 263 var activeIndex = -1; | |
| 264 AutomationUtil.findNodePre(this.node_.root, constants.Dir.FORWARD, | |
| 265 /** @type {AutomationPredicate.Unary} */(function(n) { | |
| 266 if (n === this.node_) | |
| 267 selectNext = true; | |
| 268 | |
| 269 if (this.pred_(n)) { | |
| 270 var output = new Output(); | |
| 271 var range = cursors.Range.fromNode(n); | |
| 272 output.withSpeech(range, range, Output.EventType.NAVIGATE); | |
| 273 var label = output.toString(); | |
| 274 this.addMenuItem(label, '', function() { | |
| 275 chrome.extension.getBackgroundPage().ChromeVoxState | |
| 276 .instance['navigateToRange'](cursors.Range.fromNode(n)); | |
| 277 }); | |
| 278 if (selectNext) { | |
| 279 activeIndex = this.items_.length - 1; | |
| 280 selectNext = false; | |
| 281 } | |
| 282 } | |
| 283 }).bind(this) | |
| 284 ); | |
| 285 | |
| 286 if (!this.items_.length) { | |
| 287 this.addMenuItem( | |
| 288 Msgs.getMsg('panel_menu_item_none'), '', function() {}); | |
| 289 this.activateItem(0); | |
| 290 } | |
| 291 if (activeIndex >= 0) | |
| 292 this.activateItem(activeIndex); | |
| 279 } | 293 } |
| 280 }; | 294 }; |
| OLD | NEW |