| 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 representing a DOM selection conveyed through | 6 * @fileoverview A class representing a DOM selection conveyed through |
| 7 * CursorSelection idioms. | 7 * CursorSelection idioms. |
| 8 * A PageSelection is just a DOM selection. The class itself manages a single | 8 * A PageSelection is just a DOM selection. The class itself manages a single |
| 9 * CursorSelection that surrounds a fragment on the page. It also provides an | 9 * CursorSelection that surrounds a fragment on the page. It also provides an |
| 10 * extend operation to either grow or shrink the selection given a | 10 * extend operation to either grow or shrink the selection given a |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Gets a description for the DOM selection during the course of navigation. | 34 * Gets a description for the DOM selection during the course of navigation. |
| 35 * @param {cvox.AbstractShifter} navShifter Used to obtain walker-based | 35 * @param {cvox.AbstractShifter} navShifter Used to obtain walker-based |
| 36 * descriptions. | 36 * descriptions. |
| 37 * @param {!cvox.CursorSelection} prevSel Previous CursorSelection in | 37 * @param {!cvox.CursorSelection} prevSel Previous CursorSelection in |
| 38 * navigation. | 38 * navigation. |
| 39 * @param {!cvox.CursorSelection} curSel Current CursorSelection in navigation. | 39 * @param {!cvox.CursorSelection} curSel Current CursorSelection in navigation. |
| 40 * @return {Array<cvox.NavDescription>} The new description. | 40 * @return {Array<cvox.NavDescription>} The new description. |
| 41 */ | 41 */ |
| 42 cvox.PageSelection.prototype.getDescription = | 42 cvox.PageSelection.prototype.getDescription = function( |
| 43 function(navShifter, prevSel, curSel) { | 43 navShifter, prevSel, curSel) { |
| 44 var desc = []; | 44 var desc = []; |
| 45 if (this.sel_.isReversed() != curSel.isReversed()) { | 45 if (this.sel_.isReversed() != curSel.isReversed()) { |
| 46 // A shrinking selection. | 46 // A shrinking selection. |
| 47 desc = navShifter.getDescription(curSel, prevSel); | 47 desc = navShifter.getDescription(curSel, prevSel); |
| 48 desc[0].annotation = Msgs.getMsg('describe_unselected'); | 48 desc[0].annotation = Msgs.getMsg('describe_unselected'); |
| 49 desc[0].pushEarcon(cvox.Earcon.SELECTION_REVERSE); | 49 desc[0].pushEarcon(cvox.Earcon.SELECTION_REVERSE); |
| 50 } else { | 50 } else { |
| 51 // A growing selection. | 51 // A growing selection. |
| 52 desc = navShifter.getDescription(prevSel, curSel); | 52 desc = navShifter.getDescription(prevSel, curSel); |
| 53 desc[0].annotation = Msgs.getMsg('describe_selected'); | 53 desc[0].annotation = Msgs.getMsg('describe_selected'); |
| 54 desc[0].pushEarcon(cvox.Earcon.SELECTION); | 54 desc[0].pushEarcon(cvox.Earcon.SELECTION); |
| 55 if (!this.wasBegin_ && this.sel_.absEquals(curSel.clone().normalize())) { | 55 if (!this.wasBegin_ && this.sel_.absEquals(curSel.clone().normalize())) { |
| 56 // A selection has inverted across the start cursor. Describe it. | 56 // A selection has inverted across the start cursor. Describe it. |
| 57 var prevDesc = navShifter.getDescription(curSel, prevSel); | 57 var prevDesc = navShifter.getDescription(curSel, prevSel); |
| 58 prevDesc[0].annotation = | 58 prevDesc[0].annotation = Msgs.getMsg('describe_unselected'); |
| 59 Msgs.getMsg('describe_unselected'); | |
| 60 prevDesc[0].pushEarcon(cvox.Earcon.SELECTION_REVERSE); | 59 prevDesc[0].pushEarcon(cvox.Earcon.SELECTION_REVERSE); |
| 61 prevDesc[0].pushEarcon(cvox.Earcon.WRAP); | 60 prevDesc[0].pushEarcon(cvox.Earcon.WRAP); |
| 62 desc = prevDesc.concat(desc); | 61 desc = prevDesc.concat(desc); |
| 63 } | 62 } |
| 64 } | 63 } |
| 65 return desc; | 64 return desc; |
| 66 }; | 65 }; |
| 67 | 66 |
| 68 | 67 |
| 69 /** | 68 /** |
| 70 * Gets a full description for the entire DOM selection. | 69 * Gets a full description for the entire DOM selection. |
| 71 * Use this description when you want to describe the entire selection | 70 * Use this description when you want to describe the entire selection |
| 72 * represented by this instance. | 71 * represented by this instance. |
| 73 * | 72 * |
| 74 * @return {Array<cvox.NavDescription>} The new description. | 73 * @return {Array<cvox.NavDescription>} The new description. |
| 75 */ | 74 */ |
| 76 cvox.PageSelection.prototype.getFullDescription = function() { | 75 cvox.PageSelection.prototype.getFullDescription = function() { |
| 77 return [new cvox.NavDescription( | 76 return [new cvox.NavDescription({ |
| 78 {text: window.getSelection().toString(), | 77 text: window.getSelection().toString(), |
| 79 context: Msgs.getMsg('selection_is')})]; | 78 context: Msgs.getMsg('selection_is') |
| 79 })]; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Extends this selection. | 84 * Extends this selection. |
| 85 * @param {!cvox.CursorSelection} sel Extend DOM selection to the selection. | 85 * @param {!cvox.CursorSelection} sel Extend DOM selection to the selection. |
| 86 * @return {boolean} True if the extension occurred, false if the PageSelection | 86 * @return {boolean} True if the extension occurred, false if the PageSelection |
| 87 * was reset to sel. | 87 * was reset to sel. |
| 88 */ | 88 */ |
| 89 cvox.PageSelection.prototype.extend = function(sel) { | 89 cvox.PageSelection.prototype.extend = function(sel) { |
| 90 if (!this.sel_.directedBefore(sel)) { | 90 if (!this.sel_.directedBefore(sel)) { |
| 91 // Do not allow for crossed selections. This restarts a page selection that | 91 // Do not allow for crossed selections. This restarts a page selection that |
| 92 // has been collapsed. This occurs when two CursorSelection's point away | 92 // has been collapsed. This occurs when two CursorSelection's point away |
| 93 // from one another. | 93 // from one another. |
| 94 this.sel_ = sel.clone(); | 94 this.sel_ = sel.clone(); |
| 95 } else { | 95 } else { |
| 96 // Otherwise, it is assumed that the CursorSelection's are in directed | 96 // Otherwise, it is assumed that the CursorSelection's are in directed |
| 97 // document order. The CursorSelection's are either pointing in the same | 97 // document order. The CursorSelection's are either pointing in the same |
| 98 // direction or towards one another. In the first case, shrink/extend this | 98 // direction or towards one another. In the first case, shrink/extend this |
| 99 // PageSelection to the end of "sel". In the second case, shrink/extend this | 99 // PageSelection to the end of "sel". In the second case, shrink/extend this |
| 100 // PageSelection to the start of "sel". | 100 // PageSelection to the start of "sel". |
| 101 this.sel_.end = this.sel_.isReversed() == sel.isReversed() ? | 101 this.sel_.end = this.sel_.isReversed() == sel.isReversed() ? |
| 102 sel.end.clone() : sel.start.clone(); | 102 sel.end.clone() : |
| 103 sel.start.clone(); |
| 103 } | 104 } |
| 104 this.sel_.select(); | 105 this.sel_.select(); |
| 105 this.wasBegin_ = false; | 106 this.wasBegin_ = false; |
| 106 return !this.sel_.absEquals(sel); | 107 return !this.sel_.absEquals(sel); |
| 107 }; | 108 }; |
| OLD | NEW |