| 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 base class for walkers that have a concept of lowest-level | 6 * @fileoverview A base class for walkers that have a concept of lowest-level |
| 7 * node. Base classes must override the stopNodeDescent method to define | 7 * node. Base classes must override the stopNodeDescent method to define |
| 8 * what a lowest-level node is. Then this walker will use those nodes as the | 8 * what a lowest-level node is. Then this walker will use those nodes as the |
| 9 * set of valid CursorSelections. | 9 * set of valid CursorSelections. |
| 10 */ | 10 */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 this.wasBegin_ = false; | 32 this.wasBegin_ = false; |
| 33 }; | 33 }; |
| 34 goog.inherits(cvox.AbstractNodeWalker, cvox.AbstractWalker); | 34 goog.inherits(cvox.AbstractNodeWalker, cvox.AbstractWalker); |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * @override | 37 * @override |
| 38 */ | 38 */ |
| 39 cvox.AbstractNodeWalker.prototype.next = function(sel) { | 39 cvox.AbstractNodeWalker.prototype.next = function(sel) { |
| 40 var r = sel.isReversed(); | 40 var r = sel.isReversed(); |
| 41 var node = sel.end.node || document.body; | 41 var node = sel.end.node || document.body; |
| 42 | 42 if (!node) { |
| 43 return null; |
| 44 } |
| 43 do { | 45 do { |
| 44 node = cvox.DomUtil.directedNextLeafLikeNode(node, r, | 46 node = cvox.DomUtil.directedNextLeafLikeNode(node, r, |
| 45 goog.bind(this.stopNodeDescent, this)); | 47 goog.bind(this.stopNodeDescent, this)); |
| 46 if (!node) { | 48 if (!node) { |
| 47 return null; | 49 return null; |
| 48 } | 50 } |
| 49 // and repeat all of the above until we have a node that is not empty | 51 // and repeat all of the above until we have a node that is not empty |
| 50 } while (node && !cvox.DomUtil.hasContent(node)); | 52 } while (node && !cvox.DomUtil.hasContent(node)); |
| 51 | 53 |
| 52 return cvox.CursorSelection.fromNode(node).setReversed(r); | 54 return cvox.CursorSelection.fromNode(node).setReversed(r); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 80 this.wasBegin_ = true; | 82 this.wasBegin_ = true; |
| 81 } | 83 } |
| 82 | 84 |
| 83 var node = sel.start.node; | 85 var node = sel.start.node; |
| 84 | 86 |
| 85 while (node != document.body && node.parentNode && | 87 while (node != document.body && node.parentNode && |
| 86 this.stopNodeDescent(node.parentNode)) { | 88 this.stopNodeDescent(node.parentNode)) { |
| 87 node = node.parentNode; | 89 node = node.parentNode; |
| 88 } | 90 } |
| 89 | 91 |
| 90 while (!this.stopNodeDescent(node)) { | 92 while (node && !this.stopNodeDescent(node)) { |
| 91 node = cvox.DomUtil.directedFirstChild(node, r); | 93 node = cvox.DomUtil.directedFirstChild(node, r); |
| 92 } | 94 } |
| 93 | 95 |
| 94 var n = cvox.CursorSelection.fromNode(node); | 96 var n = cvox.CursorSelection.fromNode(node); |
| 95 if (!cvox.DomUtil.hasContent(node)) { | 97 if (!cvox.DomUtil.hasContent(node)) { |
| 96 n = this.next(/** @type {!cvox.CursorSelection} */ | 98 n = this.next(/** @type {!cvox.CursorSelection} */ |
| 97 (cvox.CursorSelection.fromNode(node)).setReversed(r)); | 99 (cvox.CursorSelection.fromNode(node)).setReversed(r)); |
| 98 } | 100 } |
| 99 if (n) { | 101 if (n) { |
| 100 return n.setReversed(r); | 102 return n.setReversed(r); |
| 101 } | 103 } |
| 102 return this.begin({reversed: r}); | 104 return this.begin({reversed: r}); |
| 103 }; | 105 }; |
| 104 | 106 |
| 105 /** | 107 /** |
| 106 * Returns true if this is "a leaf node" or lower. That is, | 108 * Returns true if this is "a leaf node" or lower. That is, |
| 107 * it is at the lowest valid level or lower for this granularity. | 109 * it is at the lowest valid level or lower for this granularity. |
| 108 * RESTRICTION: true for a node => true for all child nodes | 110 * RESTRICTION: true for a node => true for all child nodes |
| 109 * RESTRICTION: true if node has no children | 111 * RESTRICTION: true if node has no children |
| 110 * @param {!Node} node The node to check. | 112 * @param {!Node} node The node to check. |
| 111 * @return {boolean} true if this is at the "leaf node" level or lower | 113 * @return {boolean} true if this is at the "leaf node" level or lower |
| 112 * for this granularity. | 114 * for this granularity. |
| 113 * @protected | 115 * @protected |
| 114 */ | 116 */ |
| 115 cvox.AbstractNodeWalker.prototype.stopNodeDescent = goog.abstractMethod; | 117 cvox.AbstractNodeWalker.prototype.stopNodeDescent = goog.abstractMethod; |
| OLD | NEW |