Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/common/traverse_content.js

Issue 2943193002: Run clang-format on .js files in c/b/r/chromeos/chromevox (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /** 6 /**
7 * @fileoverview A DOM traversal interface for moving a selection around a 7 * @fileoverview A DOM traversal interface for moving a selection around a
8 * webpage. Provides multiple granularities: 8 * webpage. Provides multiple granularities:
9 * 1. Move by paragraph. 9 * 1. Move by paragraph.
10 * 2. Move by sentence. 10 * 2. Move by sentence.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 * @type {string} 111 * @type {string}
112 * @const 112 * @const
113 */ 113 */
114 cvox.TraverseContent.kParagraph = 'paragraph'; 114 cvox.TraverseContent.kParagraph = 'paragraph';
115 115
116 /** 116 /**
117 * A constant array of all granularities. 117 * A constant array of all granularities.
118 * @type {Array<string>} 118 * @type {Array<string>}
119 * @const 119 * @const
120 */ 120 */
121 cvox.TraverseContent.kAllGrains = 121 cvox.TraverseContent.kAllGrains = [
122 [cvox.TraverseContent.kParagraph, 122 cvox.TraverseContent.kParagraph, cvox.TraverseContent.kSentence,
123 cvox.TraverseContent.kSentence, 123 cvox.TraverseContent.kLine, cvox.TraverseContent.kWord,
124 cvox.TraverseContent.kLine, 124 cvox.TraverseContent.kCharacter
125 cvox.TraverseContent.kWord, 125 ];
126 cvox.TraverseContent.kCharacter];
127 126
128 /** 127 /**
129 * Set the current position to match the current WebKit selection. 128 * Set the current position to match the current WebKit selection.
130 */ 129 */
131 cvox.TraverseContent.prototype.syncToSelection = function() { 130 cvox.TraverseContent.prototype.syncToSelection = function() {
132 this.normalizeSelection(); 131 this.normalizeSelection();
133 132
134 var selection = window.getSelection(); 133 var selection = window.getSelection();
135 if (!selection || !selection.anchorNode || !selection.focusNode) { 134 if (!selection || !selection.anchorNode || !selection.focusNode) {
136 return; 135 return;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 375
377 /** 376 /**
378 * Get the tag names that should break a sentence or line. Currently 377 * Get the tag names that should break a sentence or line. Currently
379 * just an anchor 'A' should break a sentence or line if the breakAtLinks 378 * just an anchor 'A' should break a sentence or line if the breakAtLinks
380 * flag is true, but in the future we might have other rules for breaking. 379 * flag is true, but in the future we might have other rules for breaking.
381 * 380 *
382 * @return {Object} An associative array mapping a tag name to true if 381 * @return {Object} An associative array mapping a tag name to true if
383 * it should break a sentence or line. 382 * it should break a sentence or line.
384 */ 383 */
385 cvox.TraverseContent.prototype.getBreakTags = function() { 384 cvox.TraverseContent.prototype.getBreakTags = function() {
386 return { 385 return {'A': this.breakAtLinks, 'BR': true, 'HR': true};
387 'A': this.breakAtLinks,
388 'BR': true,
389 'HR': true
390 };
391 }; 386 };
392 387
393 /** 388 /**
394 * Selects the next element of the document or within the provided DOM object. 389 * Selects the next element of the document or within the provided DOM object.
395 * Scrolls the window as appropriate. 390 * Scrolls the window as appropriate.
396 * 391 *
397 * @param {string} grain specifies "sentence", "word", "character", 392 * @param {string} grain specifies "sentence", "word", "character",
398 * or "paragraph" granularity. 393 * or "paragraph" granularity.
399 * @param {Node=} domObj a DOM node (optional). 394 * @param {Node=} domObj a DOM node (optional).
400 * @return {?string} Either: 395 * @return {?string} Either:
401 * 1) The new selected text. 396 * 1) The new selected text.
402 * 2) null if the end of the domObj has been reached. 397 * 2) null if the end of the domObj has been reached.
403 */ 398 */
404 cvox.TraverseContent.prototype.nextElement = function(grain, domObj) { 399 cvox.TraverseContent.prototype.nextElement = function(grain, domObj) {
405 if (domObj != null) { 400 if (domObj != null) {
406 this.currentDomObj = domObj; 401 this.currentDomObj = domObj;
407 } 402 }
408 403
409 var result = this.moveNext(grain); 404 var result = this.moveNext(grain);
410 if (result != null && 405 if (result != null &&
411 (!cvox.DomUtil.isDescendantOfNode( 406 (!cvox.DomUtil.isDescendantOfNode(
412 this.startCursor_.node, this.currentDomObj) || 407 this.startCursor_.node, this.currentDomObj) ||
413 !cvox.DomUtil.isDescendantOfNode( 408 !cvox.DomUtil.isDescendantOfNode(
414 this.endCursor_.node, this.currentDomObj))) { 409 this.endCursor_.node, this.currentDomObj))) {
415 return null; 410 return null;
416 } 411 }
417 412
418 return result; 413 return result;
419 }; 414 };
420 415
421 416
422 /** 417 /**
423 * Selects the previous element of the document or within the provided DOM 418 * Selects the previous element of the document or within the provided DOM
424 * object. Scrolls the window as appropriate. 419 * object. Scrolls the window as appropriate.
425 * 420 *
426 * @param {string} grain specifies "sentence", "word", "character", 421 * @param {string} grain specifies "sentence", "word", "character",
427 * or "paragraph" granularity. 422 * or "paragraph" granularity.
428 * @param {Node=} domObj a DOM node (optional). 423 * @param {Node=} domObj a DOM node (optional).
429 * @return {?string} Either: 424 * @return {?string} Either:
430 * 1) The new selected text. 425 * 1) The new selected text.
431 * 2) null if the beginning of the domObj has been reached. 426 * 2) null if the beginning of the domObj has been reached.
432 */ 427 */
433 cvox.TraverseContent.prototype.prevElement = function(grain, domObj) { 428 cvox.TraverseContent.prototype.prevElement = function(grain, domObj) {
434 if (domObj != null) { 429 if (domObj != null) {
435 this.currentDomObj = domObj; 430 this.currentDomObj = domObj;
436 } 431 }
437 432
438 var result = this.movePrev(grain); 433 var result = this.movePrev(grain);
439 if (result != null && 434 if (result != null &&
440 (!cvox.DomUtil.isDescendantOfNode( 435 (!cvox.DomUtil.isDescendantOfNode(
441 this.startCursor_.node, this.currentDomObj) || 436 this.startCursor_.node, this.currentDomObj) ||
442 !cvox.DomUtil.isDescendantOfNode( 437 !cvox.DomUtil.isDescendantOfNode(
443 this.endCursor_.node, this.currentDomObj))) { 438 this.endCursor_.node, this.currentDomObj))) {
444 return null; 439 return null;
445 } 440 }
446 441
447 return result; 442 return result;
448 }; 443 };
449 444
450 /** 445 /**
451 * Make sure that exactly one item is selected. If there's no selection, 446 * Make sure that exactly one item is selected. If there's no selection,
(...skipping 21 matching lines...) Expand all
473 468
474 /** 469 /**
475 * Resets the selection. 470 * Resets the selection.
476 * 471 *
477 * @param {Node=} domObj a DOM node. Optional. 472 * @param {Node=} domObj a DOM node. Optional.
478 * 473 *
479 */ 474 */
480 cvox.TraverseContent.prototype.reset = function(domObj) { 475 cvox.TraverseContent.prototype.reset = function(domObj) {
481 window.getSelection().removeAllRanges(); 476 window.getSelection().removeAllRanges();
482 }; 477 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698