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