node_search_widget.js revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1// Copyright 2014 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/**
6 * @fileoverview A search Widget presenting a list of nodes with the ability
7 * to sync selection when chosen.
8 */
9
10goog.provide('cvox.NodeSearchWidget');
11
12goog.require('cvox.ChromeVox');
13goog.require('cvox.DomUtil');
14goog.require('cvox.SearchWidget');
15goog.require('cvox.SpokenMessages');
16
17
18/**
19 * @constructor
20 * @param {string} typeMsg A message id identifying the type of items
21 * contained in the list.
22 * @param {?function(Array.<Node>)} predicate A predicate; if null, no predicate
23 * applies.
24 * @extends {cvox.SearchWidget}
25 */
26cvox.NodeSearchWidget = function(typeMsg, predicate) {
27  this.typeMsg_ = typeMsg;
28  this.predicate_ = predicate;
29  goog.base(this);
30};
31goog.inherits(cvox.NodeSearchWidget, cvox.SearchWidget);
32
33
34/**
35 * @override
36 */
37cvox.NodeSearchWidget.prototype.getNameMsg = function() {
38  return ['choice_widget_name', [cvox.ChromeVox.msgs.getMsg(this.typeMsg_)]];
39};
40
41
42/**
43 * @override
44 */
45cvox.NodeSearchWidget.prototype.getHelpMsg = function() {
46  return 'choice_widget_help';
47};
48
49
50/**
51 * @override
52 */
53cvox.NodeSearchWidget.prototype.getPredicate = function() {
54  return this.predicate_;
55};
56
57
58/**
59 * Shows a list generated dynamic satisfying some predicate.
60 * @param {string} typeMsg The message id of the type contained in nodes.
61 * @param {function(Array.<Node>)} predicate The predicate.
62 * @return {cvox.NodeSearchWidget} The widget.
63 */
64cvox.NodeSearchWidget.create = function(typeMsg, predicate) {
65  return new cvox.NodeSearchWidget(typeMsg, predicate);
66};
67