OLD | NEW |
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 * @fileoverview Handles output for Chrome's built-in find. | 5 * @fileoverview Handles output for Chrome's built-in find. |
6 */ | 6 */ |
7 goog.provide('FindHandler'); | 7 goog.provide('FindHandler'); |
8 | 8 |
9 goog.require('Output'); | 9 goog.require('Output'); |
10 | 10 |
| 11 goog.scope(function() { |
| 12 var TreeChangeObserverFilter = chrome.automation.TreeChangeObserverFilter; |
| 13 |
11 /** | 14 /** |
12 * Responds to mode changes. | 15 * Responds to mode changes. |
13 * @param {ChromeVoxMode} newMode | 16 * @param {ChromeVoxMode} newMode |
14 * @param {?ChromeVoxMode} oldMode Can be null at startup when no range was | 17 * @param {?ChromeVoxMode} oldMode Can be null at startup when no range was |
15 * previously set. | 18 * previously set. |
16 */ | 19 */ |
17 FindHandler.onModeChanged = function(newMode, oldMode) { | 20 FindHandler.onModeChanged = function(newMode, oldMode) { |
18 if (newMode == ChromeVoxMode.FORCE_NEXT) | 21 if (newMode == ChromeVoxMode.FORCE_NEXT) |
19 FindHandler.init_(); | 22 FindHandler.init_(); |
20 else | 23 else |
21 FindHandler.uninit_(); | 24 FindHandler.uninit_(); |
22 }; | 25 }; |
23 | 26 |
24 /** | 27 /** |
25 * Initializes this module. | 28 * Initializes this module. |
26 * @private | 29 * @private |
27 */ | 30 */ |
28 FindHandler.init_ = function() { | 31 FindHandler.init_ = function() { |
29 chrome.automation.addTreeChangeObserver( | 32 chrome.automation.addTreeChangeObserver( |
30 'textMarkerChanges', FindHandler.onTextMatch_); | 33 TreeChangeObserverFilter.textMarkerChanges, |
| 34 FindHandler.onTextMatch_); |
31 }; | 35 }; |
32 | 36 |
33 /** | 37 /** |
34 * Uninitializes this module. | 38 * Uninitializes this module. |
35 * @private | 39 * @private |
36 */ | 40 */ |
37 FindHandler.uninit_ = function() { | 41 FindHandler.uninit_ = function() { |
38 chrome.automation.removeTreeChangeObserver(FindHandler.onTextMatch_); | 42 chrome.automation.removeTreeChangeObserver(FindHandler.onTextMatch_); |
39 }; | 43 }; |
40 | 44 |
41 /** | 45 /** |
42 * @param {Object} evt | 46 * @param {Object} evt |
43 * @private | 47 * @private |
44 */ | 48 */ |
45 FindHandler.onTextMatch_ = function(evt) { | 49 FindHandler.onTextMatch_ = function(evt) { |
46 if (!evt.target.markerTypes.some(function(markerType) { | 50 if (!evt.target.markerTypes.some(function(markerType) { |
47 return markerType & 4 /* Text match */; | 51 return markerType & 4 /* Text match */; |
48 })) | 52 })) |
49 return; | 53 return; |
50 | 54 |
51 var range = cursors.Range.fromNode(evt.target); | 55 var range = cursors.Range.fromNode(evt.target); |
52 ChromeVoxState.instance.setCurrentRange(range); | 56 ChromeVoxState.instance.setCurrentRange(range); |
53 new Output() | 57 new Output() |
54 .withRichSpeechAndBraille(range, null, Output.EventType.NAVIGATE) | 58 .withRichSpeechAndBraille(range, null, Output.EventType.NAVIGATE) |
55 .go(); | 59 .go(); |
56 }; | 60 }; |
| 61 |
| 62 }); // goog.scope |
OLD | NEW |