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