| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
| 6 * @fileoverview Implements support for live regions in ChromeVox Next. | 6 * @fileoverview Implements support for live regions in ChromeVox Next. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('LiveRegions'); | 9 goog.provide('LiveRegions'); |
| 10 | 10 |
| 11 goog.require('ChromeVoxState'); | 11 goog.require('ChromeVoxState'); |
| 12 | 12 |
| 13 goog.scope(function() { | 13 goog.scope(function() { |
| 14 var AutomationNode = chrome.automation.AutomationNode; | 14 var AutomationNode = chrome.automation.AutomationNode; |
| 15 var RoleType = chrome.automation.RoleType; | 15 var RoleType = chrome.automation.RoleType; |
| 16 var TreeChange = chrome.automation.TreeChange; | 16 var TreeChange = chrome.automation.TreeChange; |
| 17 var TreeChangeObserverFilter = chrome.automation.TreeChangeObserverFilter; |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * ChromeVox2 live region handler. | 20 * ChromeVox2 live region handler. |
| 20 * @param {!ChromeVoxState} chromeVoxState The ChromeVox state object, | 21 * @param {!ChromeVoxState} chromeVoxState The ChromeVox state object, |
| 21 * keeping track of the current mode and current range. | 22 * keeping track of the current mode and current range. |
| 22 * @constructor | 23 * @constructor |
| 23 */ | 24 */ |
| 24 LiveRegions = function(chromeVoxState) { | 25 LiveRegions = function(chromeVoxState) { |
| 25 /** | 26 /** |
| 26 * @type {!ChromeVoxState} | 27 * @type {!ChromeVoxState} |
| 27 * @private | 28 * @private |
| 28 */ | 29 */ |
| 29 this.chromeVoxState_ = chromeVoxState; | 30 this.chromeVoxState_ = chromeVoxState; |
| 30 | 31 |
| 31 /** | 32 /** |
| 32 * The time the last live region event was output. | 33 * The time the last live region event was output. |
| 33 * @type {!Date} | 34 * @type {!Date} |
| 34 * @private | 35 * @private |
| 35 */ | 36 */ |
| 36 this.lastLiveRegionTime_ = new Date(0); | 37 this.lastLiveRegionTime_ = new Date(0); |
| 37 | 38 |
| 38 /** | 39 /** |
| 39 * Set of nodes that have been announced as part of a live region since | 40 * Set of nodes that have been announced as part of a live region since |
| 40 * |this.lastLiveRegionTime_|, to prevent duplicate announcements. | 41 * |this.lastLiveRegionTime_|, to prevent duplicate announcements. |
| 41 * @type {!WeakSet<AutomationNode>} | 42 * @type {!WeakSet<AutomationNode>} |
| 42 * @private | 43 * @private |
| 43 */ | 44 */ |
| 44 this.liveRegionNodeSet_ = new WeakSet(); | 45 this.liveRegionNodeSet_ = new WeakSet(); |
| 46 |
| 45 chrome.automation.addTreeChangeObserver( | 47 chrome.automation.addTreeChangeObserver( |
| 46 'liveRegionTreeChanges', this.onTreeChange.bind(this)); | 48 TreeChangeObserverFilter.LIVE_REGION_TREE_CHANGES, |
| 49 this.onTreeChange.bind(this)); |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 /** | 52 /** |
| 50 * Live region events received in fewer than this many milliseconds will | 53 * Live region events received in fewer than this many milliseconds will |
| 51 * queue, otherwise they'll be output with a category flush. | 54 * queue, otherwise they'll be output with a category flush. |
| 52 * @type {number} | 55 * @type {number} |
| 53 * @const | 56 * @const |
| 54 */ | 57 */ |
| 55 LiveRegions.LIVE_REGION_QUEUE_TIME_MS = 5000; | 58 LiveRegions.LIVE_REGION_QUEUE_TIME_MS = 5000; |
| 56 | 59 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 parent = parent.parent; | 183 parent = parent.parent; |
| 181 } | 184 } |
| 182 | 185 |
| 183 this.liveRegionNodeSet_.add(node); | 186 this.liveRegionNodeSet_.add(node); |
| 184 output.go(); | 187 output.go(); |
| 185 this.lastLiveRegionTime_ = currentTime; | 188 this.lastLiveRegionTime_ = currentTime; |
| 186 }, | 189 }, |
| 187 }; | 190 }; |
| 188 | 191 |
| 189 }); // goog.scope | 192 }); // goog.scope |
| OLD | NEW |