OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview A class for walking tables. | 6 * @fileoverview A class for walking tables. |
7 * NOTE: This class has a very different interface than the other walkers. | 7 * NOTE: This class has a very different interface than the other walkers. |
8 * This means it does not lend itself easily to e.g. decorators. | 8 * This means it does not lend itself easily to e.g. decorators. |
9 * TODO (stoarca): This might be able to be fixed by breaking it up into | 9 * TODO (stoarca): This might be able to be fixed by breaking it up into |
10 * separate walkers for cell, row and column. | 10 * separate walkers for cell, row and column. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 cvox.TableWalker.prototype.sync = function(sel) { | 50 cvox.TableWalker.prototype.sync = function(sel) { |
51 return this.goTo_(sel, goog.bind(function(position) { | 51 return this.goTo_(sel, goog.bind(function(position) { |
52 return this.tt.goToCell(position); | 52 return this.tt.goToCell(position); |
53 }, this)); | 53 }, this)); |
54 }; | 54 }; |
55 | 55 |
56 /** | 56 /** |
57 * @override | 57 * @override |
58 * @suppress {checkTypes} actual parameter 2 of | 58 * @suppress {checkTypes} actual parameter 2 of |
59 * cvox.Msgs.prototype.getMsg does not match formal parameter | 59 * cvox.Msgs.prototype.getMsg does not match formal parameter |
60 * found : Array.<number> | 60 * found : Array<number> |
61 * required: (Array.<string>|null|undefined) | 61 * required: (Array<string>|null|undefined) |
62 */ | 62 */ |
63 cvox.TableWalker.prototype.getDescription = function(prevSel, sel) { | 63 cvox.TableWalker.prototype.getDescription = function(prevSel, sel) { |
64 var position = this.syncPosition_(sel); | 64 var position = this.syncPosition_(sel); |
65 if (!position) { | 65 if (!position) { |
66 return []; | 66 return []; |
67 } | 67 } |
68 this.tt.goToCell(position); | 68 this.tt.goToCell(position); |
69 var descs = cvox.DescriptionUtil.getCollectionDescription(prevSel, sel); | 69 var descs = cvox.DescriptionUtil.getCollectionDescription(prevSel, sel); |
70 if (descs.length == 0) { | 70 if (descs.length == 0) { |
71 descs.push(new cvox.NavDescription({ | 71 descs.push(new cvox.NavDescription({ |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 259 } |
260 return ( | 260 return ( |
261 this.getRowHeaderText_(position) + | 261 this.getRowHeaderText_(position) + |
262 ' ' + | 262 ' ' + |
263 this.getColHeaderText_(position)); | 263 this.getColHeaderText_(position)); |
264 }; | 264 }; |
265 | 265 |
266 /** | 266 /** |
267 * Returns the location description. | 267 * Returns the location description. |
268 * @param {!cvox.CursorSelection} sel A valid selection. | 268 * @param {!cvox.CursorSelection} sel A valid selection. |
269 * @return {Array.<cvox.NavDescription>} The location description. | 269 * @return {Array<cvox.NavDescription>} The location description. |
270 * @suppress {checkTypes} actual parameter 2 of | 270 * @suppress {checkTypes} actual parameter 2 of |
271 * cvox.Msgs.prototype.getMsg does not match | 271 * cvox.Msgs.prototype.getMsg does not match |
272 * formal parameter | 272 * formal parameter |
273 * found : Array.<number> | 273 * found : Array<number> |
274 * required: (Array.<string>|null|undefined) | 274 * required: (Array<string>|null|undefined) |
275 * @private | 275 * @private |
276 */ | 276 */ |
277 cvox.TableWalker.prototype.getLocationDescription_ = function(sel) { | 277 cvox.TableWalker.prototype.getLocationDescription_ = function(sel) { |
278 var locationInfo = this.getLocationInfo(sel); | 278 var locationInfo = this.getLocationInfo(sel); |
279 if (locationInfo == null) { | 279 if (locationInfo == null) { |
280 return null; | 280 return null; |
281 } | 281 } |
282 return [new cvox.NavDescription({ | 282 return [new cvox.NavDescription({ |
283 text: cvox.ChromeVox.msgs.getMsg('table_location', locationInfo) | 283 text: cvox.ChromeVox.msgs.getMsg('table_location', locationInfo) |
284 })]; | 284 })]; |
285 }; | 285 }; |
286 | 286 |
287 /** | 287 /** |
288 * Returns the text content of the row header(s) of the cell that contains sel. | 288 * Returns the text content of the row header(s) of the cell that contains sel. |
289 * @param {!Array.<number>} position The selection. | 289 * @param {!Array<number>} position The selection. |
290 * @return {!string} The header text. | 290 * @return {!string} The header text. |
291 * @private | 291 * @private |
292 */ | 292 */ |
293 cvox.TableWalker.prototype.getRowHeaderText_ = function(position) { | 293 cvox.TableWalker.prototype.getRowHeaderText_ = function(position) { |
294 // TODO(stoarca): OPTMZ Replace with join(); | 294 // TODO(stoarca): OPTMZ Replace with join(); |
295 var rowHeaderText = ''; | 295 var rowHeaderText = ''; |
296 | 296 |
297 var rowHeaders = this.tt.getCellRowHeaders(); | 297 var rowHeaders = this.tt.getCellRowHeaders(); |
298 if (rowHeaders.length == 0) { | 298 if (rowHeaders.length == 0) { |
299 var firstCellInRow = this.tt.getCellAt([position[0], 0]); | 299 var firstCellInRow = this.tt.getCellAt([position[0], 0]); |
300 rowHeaderText += cvox.DomUtil.collapseWhitespace( | 300 rowHeaderText += cvox.DomUtil.collapseWhitespace( |
301 cvox.DomUtil.getValue(firstCellInRow) + ' ' + | 301 cvox.DomUtil.getValue(firstCellInRow) + ' ' + |
302 cvox.DomUtil.getName(firstCellInRow)); | 302 cvox.DomUtil.getName(firstCellInRow)); |
303 return cvox.ChromeVox.msgs.getMsg('row_header') + rowHeaderText; | 303 return cvox.ChromeVox.msgs.getMsg('row_header') + rowHeaderText; |
304 } | 304 } |
305 | 305 |
306 for (var i = 0; i < rowHeaders.length; ++i) { | 306 for (var i = 0; i < rowHeaders.length; ++i) { |
307 rowHeaderText += cvox.DomUtil.collapseWhitespace( | 307 rowHeaderText += cvox.DomUtil.collapseWhitespace( |
308 cvox.DomUtil.getValue(rowHeaders[i]) + ' ' + | 308 cvox.DomUtil.getValue(rowHeaders[i]) + ' ' + |
309 cvox.DomUtil.getName(rowHeaders[i])); | 309 cvox.DomUtil.getName(rowHeaders[i])); |
310 } | 310 } |
311 if (rowHeaderText == '') { | 311 if (rowHeaderText == '') { |
312 return cvox.ChromeVox.msgs.getMsg('empty_row_header'); | 312 return cvox.ChromeVox.msgs.getMsg('empty_row_header'); |
313 } | 313 } |
314 return cvox.ChromeVox.msgs.getMsg('row_header') + rowHeaderText; | 314 return cvox.ChromeVox.msgs.getMsg('row_header') + rowHeaderText; |
315 }; | 315 }; |
316 | 316 |
317 /** | 317 /** |
318 * Returns the text content of the col header(s) of the cell that contains sel. | 318 * Returns the text content of the col header(s) of the cell that contains sel. |
319 * @param {!Array.<number>} position The selection. | 319 * @param {!Array<number>} position The selection. |
320 * @return {!string} The header text. | 320 * @return {!string} The header text. |
321 * @private | 321 * @private |
322 */ | 322 */ |
323 cvox.TableWalker.prototype.getColHeaderText_ = function(position) { | 323 cvox.TableWalker.prototype.getColHeaderText_ = function(position) { |
324 // TODO(stoarca): OPTMZ Replace with join(); | 324 // TODO(stoarca): OPTMZ Replace with join(); |
325 var colHeaderText = ''; | 325 var colHeaderText = ''; |
326 | 326 |
327 var colHeaders = this.tt.getCellColHeaders(); | 327 var colHeaders = this.tt.getCellColHeaders(); |
328 if (colHeaders.length == 0) { | 328 if (colHeaders.length == 0) { |
329 var firstCellInCol = this.tt.getCellAt([0, position[1]]); | 329 var firstCellInCol = this.tt.getCellAt([0, position[1]]); |
(...skipping 10 matching lines...) Expand all Loading... |
340 } | 340 } |
341 if (colHeaderText == '') { | 341 if (colHeaderText == '') { |
342 return cvox.ChromeVox.msgs.getMsg('empty_row_header'); | 342 return cvox.ChromeVox.msgs.getMsg('empty_row_header'); |
343 } | 343 } |
344 return cvox.ChromeVox.msgs.getMsg('column_header') + colHeaderText; | 344 return cvox.ChromeVox.msgs.getMsg('column_header') + colHeaderText; |
345 }; | 345 }; |
346 | 346 |
347 /** | 347 /** |
348 * Returns the location info of sel within the containing table. | 348 * Returns the location info of sel within the containing table. |
349 * @param {!cvox.CursorSelection} sel The selection. | 349 * @param {!cvox.CursorSelection} sel The selection. |
350 * @return {Array.<number>} The location info: | 350 * @return {Array<number>} The location info: |
351 * [row index, row count, col index, col count]. | 351 * [row index, row count, col index, col count]. |
352 */ | 352 */ |
353 cvox.TableWalker.prototype.getLocationInfo = function(sel) { | 353 cvox.TableWalker.prototype.getLocationInfo = function(sel) { |
354 this.tt.initialize(this.getTableNode_(sel)); | 354 this.tt.initialize(this.getTableNode_(sel)); |
355 var position = this.tt.findNearestCursor(sel.start.node); | 355 var position = this.tt.findNearestCursor(sel.start.node); |
356 if (!position) { | 356 if (!position) { |
357 return null; | 357 return null; |
358 } | 358 } |
359 // + 1 to account for 0-indexed | 359 // + 1 to account for 0-indexed |
360 return [ | 360 return [ |
(...skipping 10 matching lines...) Expand all Loading... |
371 * @return {boolean} True if inside a table node. | 371 * @return {boolean} True if inside a table node. |
372 */ | 372 */ |
373 cvox.TableWalker.prototype.isInTable = function(sel) { | 373 cvox.TableWalker.prototype.isInTable = function(sel) { |
374 return this.getTableNode_(sel) != null; | 374 return this.getTableNode_(sel) != null; |
375 }; | 375 }; |
376 | 376 |
377 /** | 377 /** |
378 * Wrapper for going to somewhere so that boilerplate is not repeated. | 378 * Wrapper for going to somewhere so that boilerplate is not repeated. |
379 * @param {!cvox.CursorSelection} sel The selection from which to base the | 379 * @param {!cvox.CursorSelection} sel The selection from which to base the |
380 * movement. | 380 * movement. |
381 * @param {function(Array.<number>):boolean} f The function to use for moving. | 381 * @param {function(Array<number>):boolean} f The function to use for moving. |
382 * Returns true on success and false on failure. | 382 * Returns true on success and false on failure. |
383 * @return {cvox.CursorSelection} The resulting selection. | 383 * @return {cvox.CursorSelection} The resulting selection. |
384 * @private | 384 * @private |
385 */ | 385 */ |
386 cvox.TableWalker.prototype.goTo_ = function(sel, f) { | 386 cvox.TableWalker.prototype.goTo_ = function(sel, f) { |
387 this.tt.initialize(this.getTableNode_(sel)); | 387 this.tt.initialize(this.getTableNode_(sel)); |
388 var position = this.tt.findNearestCursor(sel.end.node); | 388 var position = this.tt.findNearestCursor(sel.end.node); |
389 if (!position) { | 389 if (!position) { |
390 return null; | 390 return null; |
391 } | 391 } |
(...skipping 11 matching lines...) Expand all Loading... |
403 * @return {Node} The table node containing sel. null if not in a table. | 403 * @return {Node} The table node containing sel. null if not in a table. |
404 * @private | 404 * @private |
405 */ | 405 */ |
406 cvox.TableWalker.prototype.getTableNode_ = function(sel) { | 406 cvox.TableWalker.prototype.getTableNode_ = function(sel) { |
407 return cvox.DomUtil.getContainingTable(sel.end.node); | 407 return cvox.DomUtil.getContainingTable(sel.end.node); |
408 }; | 408 }; |
409 | 409 |
410 /** | 410 /** |
411 * Sync the backing traversal utility to the given selection. | 411 * Sync the backing traversal utility to the given selection. |
412 * @param {!cvox.CursorSelection} sel The selection. | 412 * @param {!cvox.CursorSelection} sel The selection. |
413 * @return {Array.<number>} The position [x, y] of the selection. | 413 * @return {Array<number>} The position [x, y] of the selection. |
414 * @private | 414 * @private |
415 */ | 415 */ |
416 cvox.TableWalker.prototype.syncPosition_ = function(sel) { | 416 cvox.TableWalker.prototype.syncPosition_ = function(sel) { |
417 var tableNode = this.getTableNode_(sel); | 417 var tableNode = this.getTableNode_(sel); |
418 this.tt.initialize(tableNode); | 418 this.tt.initialize(tableNode); |
419 // we need to align the TraverseTable with our sel because our walker | 419 // we need to align the TraverseTable with our sel because our walker |
420 // uses parts of it (for example isSpanned relies on being at a specific cell) | 420 // uses parts of it (for example isSpanned relies on being at a specific cell) |
421 return this.tt.findNearestCursor(sel.end.node); | 421 return this.tt.findNearestCursor(sel.end.node); |
422 }; | 422 }; |
OLD | NEW |