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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/i_search.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 Objects related to incremental search. 6 * @fileoverview Objects related to incremental search.
7 */ 7 */
8 8
9 goog.provide('ISearch'); 9 goog.provide('ISearch');
10 goog.provide('ISearchHandler'); 10 goog.provide('ISearchHandler');
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 /** 46 /**
47 * Controls an incremental search. 47 * Controls an incremental search.
48 * @param {!cursors.Cursor} cursor 48 * @param {!cursors.Cursor} cursor
49 * @constructor 49 * @constructor
50 */ 50 */
51 ISearch = function(cursor) { 51 ISearch = function(cursor) {
52 if (!cursor.node) 52 if (!cursor.node)
53 throw 'Incremental search started from invalid range.'; 53 throw 'Incremental search started from invalid range.';
54 54
55 var leaf = AutomationUtil.findNodePre( 55 var leaf = AutomationUtil.findNodePre(
56 cursor.node, Dir.FORWARD, AutomationPredicate.leaf) || cursor.node; 56 cursor.node, Dir.FORWARD, AutomationPredicate.leaf) ||
57 cursor.node;
57 58
58 /** @type {!cursors.Cursor} */ 59 /** @type {!cursors.Cursor} */
59 this.cursor = cursors.Cursor.fromNode(leaf); 60 this.cursor = cursors.Cursor.fromNode(leaf);
60 61
61 /** 62 /**
62 * This tracks the id of a search that is in progress. 63 * This tracks the id of a search that is in progress.
63 * @type {number} @private 64 * @type {number} @private
64 */ 65 */
65 this.pendingSearchId_ = 0; 66 this.pendingSearchId_ = 0;
66 67
(...skipping 16 matching lines...) Expand all
83 * @param {Dir} dir 84 * @param {Dir} dir
84 */ 85 */
85 search: function(searchStr, dir) { 86 search: function(searchStr, dir) {
86 searchStr = searchStr.toLocaleLowerCase(); 87 searchStr = searchStr.toLocaleLowerCase();
87 // Keep things responsive by chunking cursor moves up into discrete 88 // Keep things responsive by chunking cursor moves up into discrete
88 // blocks. We can, if needed, simulate getting interrupted by the enter key. 89 // blocks. We can, if needed, simulate getting interrupted by the enter key.
89 var currentSearchId = ++this.pendingSearchId_; 90 var currentSearchId = ++this.pendingSearchId_;
90 var move = function(curNode) { 91 var move = function(curNode) {
91 var cur = cursors.Cursor.fromNode(curNode); 92 var cur = cursors.Cursor.fromNode(curNode);
92 var prev = cur; 93 var prev = cur;
93 cur = 94 cur = cur.move(cursors.Unit.NODE, cursors.Movement.DIRECTIONAL, dir);
94 cur.move(cursors.Unit.NODE, cursors.Movement.DIRECTIONAL, dir);
95 if (prev.equals(cur)) { 95 if (prev.equals(cur)) {
96 this.handler_.onSearchReachedBoundary(this.cursor.node); 96 this.handler_.onSearchReachedBoundary(this.cursor.node);
97 return; 97 return;
98 } 98 }
99 99
100 if (cur.getText().toLocaleLowerCase().indexOf(searchStr) != -1) { 100 if (cur.getText().toLocaleLowerCase().indexOf(searchStr) != -1) {
101 this.cursor = cur; 101 this.cursor = cur;
102 this.handler_.onSearchResultChanged(this.cursor.node); 102 this.handler_.onSearchResultChanged(this.cursor.node);
103 return; 103 return;
104 } 104 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 case 'Escape': 164 case 'Escape':
165 this.pendingSearchId_ = 0; 165 this.pendingSearchId_ = 0;
166 Panel.closeMenusAndRestoreFocus(); 166 Panel.closeMenusAndRestoreFocus();
167 return false; 167 return false;
168 case 'Enter': 168 case 'Enter':
169 this.pendingSearchId_ = 0; 169 this.pendingSearchId_ = 0;
170 Panel.setPendingCallback(function() { 170 Panel.setPendingCallback(function() {
171 var node = this.iSearch_.cursor.node; 171 var node = this.iSearch_.cursor.node;
172 if (!node) 172 if (!node)
173 return; 173 return;
174 chrome.extension.getBackgroundPage().ChromeVoxState.instance[ 174 chrome.extension.getBackgroundPage()
175 'navigateToRange']( 175 .ChromeVoxState.instance['navigateToRange'](
176 cursors.Range.fromNode(node)); 176 cursors.Range.fromNode(node));
177 }.bind(this)); 177 }.bind(this));
178 Panel.closeMenusAndRestoreFocus(); 178 Panel.closeMenusAndRestoreFocus();
179 return false; 179 return false;
180 default: 180 default:
181 this.pendingSearchId_ = 0; 181 this.pendingSearchId_ = 0;
182 return false; 182 return false;
183 } 183 }
184 this.iSearch_.search(this.input_.value, this.dir_); 184 this.iSearch_.search(this.input_.value, this.dir_);
185 evt.preventDefault(); 185 evt.preventDefault();
186 evt.stopPropagation(); 186 evt.stopPropagation();
(...skipping 24 matching lines...) Expand all
211 onSearchResultChanged: function(node) { 211 onSearchResultChanged: function(node) {
212 this.output_(node); 212 this.output_(node);
213 }, 213 },
214 214
215 /** 215 /**
216 * @param {!AutomationNode} node 216 * @param {!AutomationNode} node
217 * @private 217 * @private
218 */ 218 */
219 output_: function(node) { 219 output_: function(node) {
220 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.FLUSH); 220 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.FLUSH);
221 var o = new Output().withRichSpeechAndBraille( 221 var o =
222 cursors.Range.fromNode(node), null, Output.EventType.NAVIGATE).go(); 222 new Output()
223 .withRichSpeechAndBraille(
224 cursors.Range.fromNode(node), null, Output.EventType.NAVIGATE)
225 .go();
223 226
224 this.background_.setCurrentRange(cursors.Range.fromNode(node)); 227 this.background_.setCurrentRange(cursors.Range.fromNode(node));
225 }, 228 },
226 229
227 /** Unregisters event handlers. */ 230 /** Unregisters event handlers. */
228 destroy: function() { 231 destroy: function() {
229 this.iSearch_.handler_ = null; 232 this.iSearch_.handler_ = null;
230 this.iSearch_ = null; 233 this.iSearch_ = null;
231 var input = this.input_; 234 var input = this.input_;
232 this.input_ = null; 235 this.input_ = null;
233 input.removeEventListener('keydown', this.onKeyDown, true); 236 input.removeEventListener('keydown', this.onKeyDown, true);
234 input.removeEventListener('textInput', this.onTextInput, true); 237 input.removeEventListener('textInput', this.onTextInput, true);
235 } 238 }
236 }; 239 };
237 240
238 }); // goog.scope 241 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698