OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 An interface for querying and modifying the global |
| 7 * ChromeVox state, to avoid direct dependencies on the Background |
| 8 * object and to facilitate mocking for tests. |
| 9 */ |
| 10 |
| 11 goog.provide('ChromeVoxMode'); |
| 12 goog.provide('ChromeVoxState'); |
| 13 |
| 14 goog.require('cursors.Cursor'); |
| 15 |
| 16 /** |
| 17 * All possible modes ChromeVox can run. |
| 18 * @enum {string} |
| 19 */ |
| 20 ChromeVoxMode = { |
| 21 CLASSIC: 'classic', |
| 22 COMPAT: 'compat', |
| 23 NEXT: 'next', |
| 24 FORCE_NEXT: 'force_next' |
| 25 }; |
| 26 |
| 27 /** |
| 28 * ChromeVox2 state object. |
| 29 * @constructor |
| 30 */ |
| 31 ChromeVoxState = function() { |
| 32 if (ChromeVoxState.instance) |
| 33 throw 'Trying to create two instances of singleton ChromeVoxState.'; |
| 34 ChromeVoxState.instance = this; |
| 35 }; |
| 36 |
| 37 /** |
| 38 * @type {ChromeVoxState} |
| 39 */ |
| 40 ChromeVoxState.instance; |
| 41 |
| 42 ChromeVoxState.prototype = { |
| 43 /** @type {ChromeVoxMode} */ |
| 44 get mode() { |
| 45 return this.getMode(); |
| 46 }, |
| 47 |
| 48 /** |
| 49 * @return {ChromeVoxMode} The current mode. |
| 50 * @protected |
| 51 */ |
| 52 getMode: function() { |
| 53 return ChromeVoxMode.NEXT; |
| 54 }, |
| 55 |
| 56 /** |
| 57 * Sets the current ChromeVox mode. |
| 58 * @param {ChromeVoxMode} mode |
| 59 * @param {boolean=} opt_injectClassic Injects ChromeVox classic into tabs; |
| 60 * defaults to false. |
| 61 */ |
| 62 setMode: function(mode, opt_injectClassic) { |
| 63 throw new Error('setMode must be implemented by subclass.'); |
| 64 }, |
| 65 |
| 66 /** |
| 67 * Refreshes the current mode based on a url. |
| 68 * @param {string} url |
| 69 */ |
| 70 refreshMode: function(url) { |
| 71 throw new Error('refresthMode must be implemented by subclass.'); |
| 72 }, |
| 73 |
| 74 /** @type {cursors.Range} */ |
| 75 get currentRange() { |
| 76 return this.getCurrentRange(); |
| 77 }, |
| 78 |
| 79 /** |
| 80 * @return {cursors.Range} The current range. |
| 81 * @protected |
| 82 */ |
| 83 getCurrentRange: function() { |
| 84 return null; |
| 85 }, |
| 86 |
| 87 /** |
| 88 * @param {cursors.Range} newRange The new range. |
| 89 */ |
| 90 setCurrentRange: function(newRange) { |
| 91 throw new Error('setCurrentRange must be implemented by subclass.'); |
| 92 }, |
| 93 }; |
OLD | NEW |