Remove the old signature of NotificationManager::closePersistent().
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / chromevox / speech_rules / speech_rule_functions.js
blobf4edabb8255ec18e7d2dd5b17179c6881d5d57ef
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.
5 /**
6 * @fileoverview Classes for custom functions for the speech rule engine.
8 */
10 goog.provide('cvox.SpeechRuleFunctions');
11 goog.provide('cvox.SpeechRuleFunctions.ContextFunctions');
12 goog.provide('cvox.SpeechRuleFunctions.CustomQueries');
13 goog.provide('cvox.SpeechRuleFunctions.CustomStrings');
17 /**
18 * @constructor
20 cvox.SpeechRuleFunctions = function() { };
23 /**
24 * Private superclass of all the custom function stores.
25 * @constructor
26 * @param {string} prefix A prefix string for the function names.
27 * @param {Object<string, Function>} store Storage object.
28 * @private
30 cvox.SpeechRuleFunctions.Store_ = function(prefix, store) {
31 /** @private */
32 this.prefix_ = prefix;
33 /** @private */
34 this.store_ = store;
38 /**
39 * Adds a new function for the function store.
40 * @param {string} name A name.
41 * @param {!Function} func A function.
43 cvox.SpeechRuleFunctions.Store_.prototype.add = function(name, func) {
44 if (this.checkCustomFunctionSyntax_(name)) {
45 this.store_[name] = func;
50 /**
51 * Retrieves a function with the given name if one exists.
52 * @param {string} name A name.
53 * @return {Function} The function if it exists.
55 cvox.SpeechRuleFunctions.Store_.prototype.lookup = function(name) {
56 return this.store_[name];
60 /**
61 * Context function for use in speech rules.
62 * @typedef {function(!Node): Array<Node>}
64 cvox.SpeechRuleFunctions.CustomQuery;
67 /**
68 * @constructor
69 * @extends {cvox.SpeechRuleFunctions.Store_}
71 cvox.SpeechRuleFunctions.CustomQueries = function() {
72 var store =
73 /** @type {Object<string, cvox.SpeechRuleFunctions.CustomQuery>} */ ({});
74 goog.base(this, 'CQF', store);
76 goog.inherits(cvox.SpeechRuleFunctions.CustomQueries,
77 cvox.SpeechRuleFunctions.Store_);
80 /**
81 * Context function for use in speech rules.
82 * @typedef {function(!Node): string}
84 cvox.SpeechRuleFunctions.CustomString;
87 /**
88 * @constructor
89 * @extends {cvox.SpeechRuleFunctions.Store_}
91 cvox.SpeechRuleFunctions.CustomStrings = function() {
92 var store =
93 /** @type {Object<string, cvox.SpeechRuleFunctions.CustomString>} */ ({});
94 goog.base(this, 'CSF', store);
96 goog.inherits(cvox.SpeechRuleFunctions.CustomStrings,
97 cvox.SpeechRuleFunctions.Store_);
101 * Context function for use in speech rules.
102 * @typedef {function(Array<Node>, ?string): (function(): string)}
104 cvox.SpeechRuleFunctions.ContextFunction;
108 * @constructor
109 * @extends {cvox.SpeechRuleFunctions.Store_}
111 cvox.SpeechRuleFunctions.ContextFunctions = function() {
112 var store =
113 /** @type {Object<string, cvox.SpeechRuleFunctions.ContextFunction>} */
114 ({});
115 goog.base(this, 'CTXF', store);
117 goog.inherits(cvox.SpeechRuleFunctions.ContextFunctions,
118 cvox.SpeechRuleFunctions.Store_);
122 * Checks validity for a custom function name.
123 * @param {string} name The name of the custom function.
124 * @return {!boolean} True if the name is valid.
125 * @private
127 cvox.SpeechRuleFunctions.Store_.prototype.
128 checkCustomFunctionSyntax_ = function(name) {
129 var reg = new RegExp('^' + this.prefix_);
130 if (!name.match(reg)) {
131 console.log(
132 'FunctionError: Invalid function name. Expected prefix' +
133 this.prefix_);
134 return false;
136 return true;