| 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.NO_TREE_CHANGES, FindHandler.onTextMatch_); |
| 31 }; | 34 }; |
| 32 | 35 |
| 33 /** | 36 /** |
| 34 * Uninitializes this module. | 37 * Uninitializes this module. |
| 35 * @private | 38 * @private |
| 36 */ | 39 */ |
| 37 FindHandler.uninit_ = function() { | 40 FindHandler.uninit_ = function() { |
| 38 chrome.automation.removeTreeChangeObserver(FindHandler.onTextMatch_); | 41 chrome.automation.removeTreeChangeObserver(FindHandler.onTextMatch_); |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 /** | 44 /** |
| 42 * @param {Object} evt | 45 * @param {Object} evt |
| 43 * @private | 46 * @private |
| 44 */ | 47 */ |
| 45 FindHandler.onTextMatch_ = function(evt) { | 48 FindHandler.onTextMatch_ = function(evt) { |
| 46 if (!evt.target.markerTypes.some(function(markerType) { | 49 if (!evt.target.markerTypes.some(function(markerType) { |
| 47 return markerType & 4 /* Text match */; | 50 return markerType & 4 /* Text match */; |
| 48 })) | 51 })) |
| 49 return; | 52 return; |
| 50 | 53 |
| 51 var range = cursors.Range.fromNode(evt.target); | 54 var range = cursors.Range.fromNode(evt.target); |
| 52 ChromeVoxState.instance.setCurrentRange(range); | 55 ChromeVoxState.instance.setCurrentRange(range); |
| 53 new Output() | 56 new Output() |
| 54 .withRichSpeechAndBraille(range, null, Output.EventType.NAVIGATE) | 57 .withRichSpeechAndBraille(range, null, Output.EventType.NAVIGATE) |
| 55 .go(); | 58 .go(); |
| 56 }; | 59 }; |
| 60 |
| 61 }); // goog.scope |
| OLD | NEW |