summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/chromeos/chromevox/walkers/abstract_shifter.js
blob: 3da50994e6b8aa238e34ab4943bc5b5474d32060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview An interface for an ordered collection of walkers, called a
 * shifter.
 */


goog.provide('cvox.AbstractShifter');

goog.require('cvox.AbstractWalker');
goog.require('cvox.CursorSelection');
goog.require('cvox.NavBraille');


/**
 * @constructor
 */
cvox.AbstractShifter = function() {
  this.isSubnavigating_ = false;
};


/**
 * Moves to the next selection in the DOM, performing any walker shifts as
 * necessary.
 * @param {!cvox.CursorSelection} sel The selection to go next from.
 * @return {cvox.CursorSelection} The resulting selection.
 */
cvox.AbstractShifter.prototype.next = goog.abstractMethod;


/**
 * Gets the first (or last) selection for this shifter's current granularity.
 * @param {?} sel
 * @param {{reversed: (undefined|boolean)}=} kwargs Extra arguments.
 *  reversed: If true, syncs to the end and returns a reversed selection.
 *    False by default.
 * @return {!cvox.CursorSelection} The valid selection.
 */
cvox.AbstractShifter.prototype.begin = function(sel, kwargs) {
  return this.currentWalker_.begin(kwargs);
};


/**
 * Syncs to this shifter.
 * @param {!cvox.CursorSelection} sel The selection to sync, if any.
 * @return {cvox.CursorSelection} The selection.
 */
cvox.AbstractShifter.prototype.sync = goog.abstractMethod;


/**
 * Name of this shifter.
 * @return {string} The shifter's name.
 */
cvox.AbstractShifter.prototype.getName = goog.abstractMethod;


/**
 * Gets the current description.
 * @param {!cvox.CursorSelection} prevSel The previous selection, for context.
 * @param {!cvox.CursorSelection} sel The current selection.
 * @return {Array<cvox.NavDescription>} The description array.
 */
cvox.AbstractShifter.prototype.getDescription = goog.abstractMethod;


/**
 * Gets the current braille.
 * @param {!cvox.CursorSelection} prevSel The previous selection, for context.
 * @param {!cvox.CursorSelection} sel The current selection.
 * @return {!cvox.NavBraille} The braille description.
 */
cvox.AbstractShifter.prototype.getBraille = goog.abstractMethod;


/**
 * Gets the granularity message.
 * @return {string} The message string.
 */
cvox.AbstractShifter.prototype.getGranularityMsg = goog.abstractMethod;


/**
 * Shifts to a less granular level.
 */
cvox.AbstractShifter.prototype.makeLessGranular = function() {
  this.ensureNotSubnavigating();
};


/**
 * Shifts to a more granular level.
 * NOTE: after a shift, we are no longer subnavigating, if we were.
 */
cvox.AbstractShifter.prototype.makeMoreGranular = function() {
  this.ensureNotSubnavigating();
};


/**
 * Enters subnavigation mode, if it was not already in it.
 * Subnavigation mode is where the shifter is temporarily one level
 * more granular (until either the next granularity shift or
 * ensureNotSubnavigating is called).
 */
cvox.AbstractShifter.prototype.ensureSubnavigating = function() {
  if (this.isSubnavigating_ == false) {
    this.makeMoreGranular();
    this.isSubnavigating_ = true;
  }
};


/**
 * Exits subnavigation mode, if it was in it.
 */
cvox.AbstractShifter.prototype.ensureNotSubnavigating = function() {
  if (this.isSubnavigating_ == true) {
    this.isSubnavigating_ = false;
    this.makeLessGranular();
  }
};


/**
 * Returns true if the shifter is currently in subnavigation mode.
 * @return {boolean} If in subnavigation mode.
 */
cvox.AbstractShifter.prototype.isSubnavigating = function() {
  return this.isSubnavigating_;
};


/**
 * Delegates to current walker.
  * @param {string} name Action name.
 * @return {boolean} True if this shifter contains action.
 */
cvox.AbstractShifter.prototype.hasAction = function(name) {
return this.currentWalker_.hasAction(name);
};


/**
 * Delegates an action to the current walker.
 * @param {string} name The action name.
 * @param {!cvox.CursorSelection} sel The current selection.
 * @return {cvox.CursorSelection} The selection after the action.
 */
cvox.AbstractShifter.prototype.performAction = function(name, sel) {
  return this.currentWalker_.performAction(name, sel);
};


/**
 * Factory method to create an instance of this shifter.
 * @param {!cvox.CursorSelection} sel The initial selection.
 * @return {cvox.AbstractShifter} The shifter or null if given a selection not
 * within the shifter's domain.
 */
cvox.AbstractShifter.create = goog.abstractMethod;