| 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 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Live region events received in fewer than this many milliseconds will | 49 * Live region events received in fewer than this many milliseconds will |
| 50 * queue, otherwise they'll be output with a category flush. | 50 * queue, otherwise they'll be output with a category flush. |
| 51 * @type {number} | 51 * @type {number} |
| 52 * @const | 52 * @const |
| 53 */ | 53 */ |
| 54 LiveRegions.LIVE_REGION_QUEUE_TIME_MS = 500; | 54 LiveRegions.LIVE_REGION_QUEUE_TIME_MS = 500; |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * Live region events received on the same node in fewer than this many |
| 58 * milliseconds will be dropped to avoid a stream of constant chatter. |
| 59 * @type {number} |
| 60 * @const |
| 61 */ |
| 62 LiveRegions.LIVE_REGION_MIN_SAME_NODE_MS = 20; |
| 63 |
| 64 /** |
| 57 * Whether live regions from background tabs should be announced or not. | 65 * Whether live regions from background tabs should be announced or not. |
| 58 * @type {boolean} | 66 * @type {boolean} |
| 59 * @private | 67 * @private |
| 60 */ | 68 */ |
| 61 LiveRegions.announceLiveRegionsFromBackgroundTabs_ = true; | 69 LiveRegions.announceLiveRegionsFromBackgroundTabs_ = true; |
| 62 | 70 |
| 63 LiveRegions.prototype = { | 71 LiveRegions.prototype = { |
| 64 /** | 72 /** |
| 65 * Called when the automation tree is changed. | 73 * Called when the automation tree is changed. |
| 66 * @param {TreeChange} treeChange | 74 * @param {TreeChange} treeChange |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 136 |
| 129 output.withSpeechCategory(cvox.TtsCategory.LIVE); | 137 output.withSpeechCategory(cvox.TtsCategory.LIVE); |
| 130 | 138 |
| 131 if (!output.hasSpeech) | 139 if (!output.hasSpeech) |
| 132 return; | 140 return; |
| 133 | 141 |
| 134 // Enqueue live region updates that were received at approximately | 142 // Enqueue live region updates that were received at approximately |
| 135 // the same time, otherwise flush previous live region updates. | 143 // the same time, otherwise flush previous live region updates. |
| 136 var currentTime = new Date(); | 144 var currentTime = new Date(); |
| 137 var queueTime = LiveRegions.LIVE_REGION_QUEUE_TIME_MS; | 145 var queueTime = LiveRegions.LIVE_REGION_QUEUE_TIME_MS; |
| 138 if (currentTime - this.lastLiveRegionTime_ > queueTime) { | 146 var delta = currentTime - this.lastLiveRegionTime_; |
| 139 this.liveRegionNodeSet_ = new WeakSet(); | 147 if (delta > queueTime) { |
| 140 output.withQueueMode(cvox.QueueMode.CATEGORY_FLUSH); | 148 output.withQueueMode(cvox.QueueMode.CATEGORY_FLUSH); |
| 141 this.lastLiveRegionTime_ = currentTime; | 149 this.lastLiveRegionTime_ = currentTime; |
| 142 } else { | 150 } else { |
| 143 output.withQueueMode(cvox.QueueMode.QUEUE); | 151 output.withQueueMode(cvox.QueueMode.QUEUE); |
| 144 } | 152 } |
| 145 | 153 |
| 154 if (delta > LiveRegions.LIVE_REGION_MIN_SAME_NODE_MS) |
| 155 this.liveRegionNodeSet_ = new WeakSet(); |
| 156 |
| 146 var parent = node; | 157 var parent = node; |
| 147 while (parent) { | 158 while (parent) { |
| 148 if (this.liveRegionNodeSet_.has(parent)) | 159 if (this.liveRegionNodeSet_.has(parent)) |
| 149 return; | 160 return; |
| 150 parent = parent.parent; | 161 parent = parent.parent; |
| 151 } | 162 } |
| 152 | 163 |
| 153 this.liveRegionNodeSet_.add(node); | 164 this.liveRegionNodeSet_.add(node); |
| 154 output.go(); | 165 output.go(); |
| 155 }, | 166 }, |
| 156 }; | 167 }; |
| 157 | 168 |
| 158 }); // goog.scope | 169 }); // goog.scope |
| OLD | NEW |