| 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 Utilities for finding DOM nodes and CursorSelection's. | 6 * @fileoverview Utilities for finding DOM nodes and CursorSelection's. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 goog.provide('cvox.FindUtil'); | 10 goog.provide('cvox.FindUtil'); |
| 11 | 11 |
| 12 goog.require('cvox.BareObjectWalker'); | 12 goog.require('cvox.BareObjectWalker'); |
| 13 goog.require('cvox.CursorSelection'); | 13 goog.require('cvox.CursorSelection'); |
| 14 | 14 |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * @type {!cvox.BareObjectWalker} | 17 * @type {!cvox.BareObjectWalker} |
| 18 * @private | 18 * @private |
| 19 */ | 19 */ |
| 20 cvox.FindUtil.objectWalker_ = new cvox.BareObjectWalker(); | 20 cvox.FindUtil.objectWalker_ = new cvox.BareObjectWalker(); |
| 21 | 21 |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Finds the next selection that matches the predicate function starting from | 24 * Finds the next selection that matches the predicate function starting from |
| 25 * sel. Undefined if the nodes in sel are not attached to the document. | 25 * sel. Undefined if the nodes in sel are not attached to the document. |
| 26 * @param {!cvox.CursorSelection} sel The selection from which to start. | 26 * @param {!cvox.CursorSelection} sel The selection from which to start. |
| 27 * @param {function(Array.<Node>):Node} predicate A function taking a | 27 * @param {function(Array<Node>):Node} predicate A function taking a |
| 28 * unique ancestor tree and outputting Node if the ancestor tree matches | 28 * unique ancestor tree and outputting Node if the ancestor tree matches |
| 29 * the desired node to find. | 29 * the desired node to find. |
| 30 * @param {boolean=} opt_initialNode Whether to start the search from node | 30 * @param {boolean=} opt_initialNode Whether to start the search from node |
| 31 * (true), or the next node (false); defaults to false. | 31 * (true), or the next node (false); defaults to false. |
| 32 * @return {cvox.CursorSelection} The selection that was found. | 32 * @return {cvox.CursorSelection} The selection that was found. |
| 33 * null if end of document reached. | 33 * null if end of document reached. |
| 34 */ | 34 */ |
| 35 cvox.FindUtil.findNext = function(sel, predicate, opt_initialNode) { | 35 cvox.FindUtil.findNext = function(sel, predicate, opt_initialNode) { |
| 36 var r = sel.isReversed(); | 36 var r = sel.isReversed(); |
| 37 var cur = new cvox.CursorSelection(sel.absStart(), sel.absStart()) | 37 var cur = new cvox.CursorSelection(sel.absStart(), sel.absStart()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 return retNode ? cvox.CursorSelection.fromNode(retNode) : null; | 57 return retNode ? cvox.CursorSelection.fromNode(retNode) : null; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Iframes require inter-frame messaging. | 60 // Iframes require inter-frame messaging. |
| 61 if (cur.start.node.tagName == 'IFRAME') { | 61 if (cur.start.node.tagName == 'IFRAME') { |
| 62 return cur; | 62 return cur; |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 return null; | 65 return null; |
| 66 }; | 66 }; |
| OLD | NEW |