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.
6 * @fileoverview Walkers to traverse a table.
10 goog.provide('cvox.TableShifter');
12 goog.require('cvox.AbstractShifter');
13 goog.require('cvox.ColumnWalker');
14 goog.require('cvox.CursorSelection');
15 goog.require('cvox.DomPredicates');
16 goog.require('cvox.DomUtil');
17 goog.require('cvox.NavBraille');
18 goog.require('cvox.RowWalker');
23 * @extends {cvox.AbstractShifter}
25 cvox.TableShifter = function() {
26 this.rowWalker_ = new cvox.RowWalker();
27 this.columnWalker_ = new cvox.ColumnWalker();
28 this.currentWalker_ = this.rowWalker_;
29 this.bumpedEdge_ = false;
33 goog.inherits(cvox.TableShifter, cvox.AbstractShifter);
39 cvox.TableShifter.prototype.next = function(sel) {
40 var nextSel = this.currentWalker_.next(sel);
43 this.bumpedEdge_ = true;
53 cvox.TableShifter.prototype.sync = function(sel) {
54 if (sel.start.node.tagName == 'TABLE') {
55 return sel.isReversed() ? this.currentWalker_.goToLastCell(sel) :
56 this.currentWalker_.goToFirstCell(sel);
58 return this.currentWalker_.sync(sel);
65 cvox.TableShifter.prototype.getName = function() {
66 return cvox.ChromeVox.msgs.getMsg('table_shifter');
72 * @suppress {checkTypes} actual parameter 2 of
73 * cvox.Msgs.prototype.getMsg does not match formal parameter
74 * found : Array<number>
75 * required: (Array<string>|null|undefined)
77 cvox.TableShifter.prototype.getDescription = function(prevSel, sel) {
78 var descs = this.currentWalker_.getDescription(prevSel, sel);
79 if (descs.length > 0) {
80 if (this.bumpedEdge_) {
81 descs[0].pushEarcon(cvox.Earcon.WRAP_EDGE);
82 this.bumpedEdge_ = false;
85 var len = descs.length;
86 var summaryText = this.currentWalker_.tt.summaryText();
87 var locationInfo = this.currentWalker_.getLocationInfo(sel);
88 if (locationInfo != null) {
89 descs.push(new cvox.NavDescription({
90 context: cvox.ChromeVox.msgs.getMsg('table_location', locationInfo),
92 annotation: summaryText ? summaryText + ' ' : ''
95 if (this.currentWalker_.tt.isSpanned()) {
96 descs.push(new cvox.NavDescription({
98 annotation: cvox.ChromeVox.msgs.getMsg('spanned')
111 cvox.TableShifter.prototype.getBraille = function(prevSel, sel) {
112 return this.currentWalker_.getBraille(prevSel, sel);
119 cvox.TableShifter.prototype.getGranularityMsg = function() {
120 return this.currentWalker_.getGranularityMsg();
127 cvox.TableShifter.prototype.makeLessGranular = function() {
128 goog.base(this, 'makeLessGranular');
129 this.currentWalker_ = this.rowWalker_;
136 cvox.TableShifter.prototype.makeMoreGranular = function() {
137 goog.base(this, 'makeMoreGranular');
138 this.currentWalker_ = this.columnWalker_;
145 cvox.TableShifter.create = function(sel) {
146 var ancestors = cvox.DomUtil.getAncestors(sel.start.node);
147 if (cvox.DomPredicates.tablePredicate(ancestors) &&
148 !cvox.DomPredicates.captionPredicate(ancestors)) {
149 return new cvox.TableShifter();