Chromium Code Reviews| 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 FindHandler.uninit_(); | |
| 30 chrome.automation.addTreeChangeObserver( | |
| 31 'textMarkerChanges', FindHandler.onTextMatch_); | |
| 32 }; | |
| 33 | |
| 34 /** | |
| 35 * Uninitializes this module. | |
| 36 * @private | |
| 37 */ | |
| 38 FindHandler.uninit_ = function() { | |
| 39 chrome.automation.removeTreeChangeObserver(FindHandler.onTextMatch_); | |
| 40 }; | |
| 41 | |
| 42 /** | |
| 43 * @param {Object} evt | |
| 44 * @private | |
| 45 */ | |
| 46 FindHandler.onTextMatch_ = function(evt) { | |
| 47 if (!evt.target.markerTypes.some(function(markerType) { | |
| 48 return markerType == 3 /* Text match */; | |
| 49 })) | |
| 50 return; | |
| 51 | |
| 52 var range = cursors.Range.fromNode(evt.target); | |
|
dmazzoni
2016/08/10 22:12:10
Does this work if there are multiple matches?
| |
| 53 ChromeVoxState.instance.setCurrentRange(range); | |
| 54 new Output() | |
| 55 .withRichSpeechAndBraille(range, null, Output.EventType.NAVIGATE) | |
| 56 .go(); | |
| 57 }; | |
| OLD | NEW |