| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 */ | 49 */ |
| 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 * 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({ |
| 72 annotation: cvox.ChromeVox.msgs.getMsg('empty_cell') | 72 annotation: Msgs.getMsg('empty_cell') |
| 73 })); | 73 })); |
| 74 } | 74 } |
| 75 return descs; | 75 return descs; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * @override | 79 * @override |
| 80 */ | 80 */ |
| 81 cvox.TableWalker.prototype.getBraille = function(prevSel, sel) { | 81 cvox.TableWalker.prototype.getBraille = function(prevSel, sel) { |
| 82 var ret = new cvox.NavBraille({}); | 82 var ret = new cvox.NavBraille({}); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 /** | 245 /** |
| 246 * Returns the text content of the header(s) of the cell that contains sel. | 246 * Returns the text content of the header(s) of the cell that contains sel. |
| 247 * @param {!cvox.CursorSelection} sel The selection. | 247 * @param {!cvox.CursorSelection} sel The selection. |
| 248 * @return {!string} The header text. | 248 * @return {!string} The header text. |
| 249 * @private | 249 * @private |
| 250 */ | 250 */ |
| 251 cvox.TableWalker.prototype.getHeaderText_ = function(sel) { | 251 cvox.TableWalker.prototype.getHeaderText_ = function(sel) { |
| 252 this.tt.initialize(this.getTableNode_(sel)); | 252 this.tt.initialize(this.getTableNode_(sel)); |
| 253 var position = this.tt.findNearestCursor(sel.start.node); | 253 var position = this.tt.findNearestCursor(sel.start.node); |
| 254 if (!position) { | 254 if (!position) { |
| 255 return cvox.ChromeVox.msgs.getMsg('not_inside_table'); | 255 return Msgs.getMsg('not_inside_table'); |
| 256 } | 256 } |
| 257 if (!this.tt.goToCell(position)) { | 257 if (!this.tt.goToCell(position)) { |
| 258 return cvox.ChromeVox.msgs.getMsg('not_inside_table'); | 258 return Msgs.getMsg('not_inside_table'); |
| 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 * 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: 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 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 Msgs.getMsg('empty_row_header'); |
| 313 } | 313 } |
| 314 return cvox.ChromeVox.msgs.getMsg('row_header') + rowHeaderText; | 314 return 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]]); |
| 330 colHeaderText += cvox.DomUtil.collapseWhitespace( | 330 colHeaderText += cvox.DomUtil.collapseWhitespace( |
| 331 cvox.DomUtil.getValue(firstCellInCol) + ' ' + | 331 cvox.DomUtil.getValue(firstCellInCol) + ' ' + |
| 332 cvox.DomUtil.getName(firstCellInCol)); | 332 cvox.DomUtil.getName(firstCellInCol)); |
| 333 return cvox.ChromeVox.msgs.getMsg('column_header') + colHeaderText; | 333 return Msgs.getMsg('column_header') + colHeaderText; |
| 334 } | 334 } |
| 335 | 335 |
| 336 for (var i = 0; i < colHeaders.length; ++i) { | 336 for (var i = 0; i < colHeaders.length; ++i) { |
| 337 colHeaderText += cvox.DomUtil.collapseWhitespace( | 337 colHeaderText += cvox.DomUtil.collapseWhitespace( |
| 338 cvox.DomUtil.getValue(colHeaders[i]) + ' ' + | 338 cvox.DomUtil.getValue(colHeaders[i]) + ' ' + |
| 339 cvox.DomUtil.getName(colHeaders[i])); | 339 cvox.DomUtil.getName(colHeaders[i])); |
| 340 } | 340 } |
| 341 if (colHeaderText == '') { | 341 if (colHeaderText == '') { |
| 342 return cvox.ChromeVox.msgs.getMsg('empty_row_header'); | 342 return Msgs.getMsg('empty_row_header'); |
| 343 } | 343 } |
| 344 return cvox.ChromeVox.msgs.getMsg('column_header') + colHeaderText; | 344 return 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 [ |
| 361 position[0] + 1, | 361 position[0] + 1, |
| 362 this.tt.rowCount, | 362 this.tt.rowCount, |
| 363 position[1] + 1, | 363 position[1] + 1, |
| 364 this.tt.colCount | 364 this.tt.colCount |
| 365 ].map(function(x) {return cvox.ChromeVox.msgs.getNumber(x);}); | 365 ].map(function(x) {return Msgs.getNumber(x);}); |
| 366 }; | 366 }; |
| 367 | 367 |
| 368 /** | 368 /** |
| 369 * Returns true if sel is inside a table. | 369 * Returns true if sel is inside a table. |
| 370 * @param {!cvox.CursorSelection} sel The selection. | 370 * @param {!cvox.CursorSelection} sel The selection. |
| 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 }; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |