Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3179)

Unified Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/media_automation_handler.js

Issue 2563013003: Support audio ducking and suspension in ChromeVox (Closed)
Patch Set: Support audio ducking and suspension in ChromeVox Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/media_automation_handler.js
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/media_automation_handler.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/media_automation_handler.js
index 8a57c06b0289f5dded396959f3f76eb4fa569425..cffe598693676707e4de0ebcd95fd47a641635c7 100644
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/media_automation_handler.js
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/media_automation_handler.js
@@ -9,6 +9,7 @@
goog.provide('MediaAutomationHandler');
goog.require('BaseAutomationHandler');
+goog.require('cvox.TtsCapturingEventListener');
goog.scope(function() {
var AutomationEvent = chrome.automation.AutomationEvent;
@@ -17,32 +18,108 @@ var EventType = chrome.automation.EventType;
var RoleType = chrome.automation.RoleType;
/**
- * @param {!AutomationNode} node The root to observe media changes.
* @constructor
* @extends {BaseAutomationHandler}
+ * @implements {cvox.TtsCapturingEventListener}
*/
-MediaAutomationHandler = function(node) {
- BaseAutomationHandler.call(this, node);
+MediaAutomationHandler = function() {
+ /** @type {!Set<AutomationNode>} @private */
+ this.mediaRoots_ = new Set();
- var e = EventType;
- this.addListener_(e.mediaStartedPlaying, this.onMediaStartedPlaying);
- this.addListener_(e.mediaStoppedPlaying, this.onMediaStoppedPlaying);
+ /** @type {Date} @private */
+ this.lastTtsEvent_ = new Date();
+
+ cvox.ChromeVox.tts.addCapturingEventListener(this);
+
+ chrome.automation.getDesktop(function(node) {
+ BaseAutomationHandler.call(this, node);
+ node.findAll({role: RoleType.rootWebArea}).forEach(function(r) {
+ if (localStorage['useAudioDucking'] == 'true')
dmazzoni 2016/12/09 18:30:10 It doesn't make sense to me to do both. I'd prefer
+ r.startDuckingMedia()();
+ if (localStorage['useAudioSuspension'] == 'true')
+ r.suspendMedia()();
+ });
+
+ var e = EventType;
+ this.addListener_(e.mediaStartedPlaying, this.onMediaStartedPlaying);
+ this.addListener_(e.mediaStoppedPlaying, this.onMediaStoppedPlaying);
+ }.bind(this));
};
+/** @type {number} */
+MediaAutomationHandler.MIN_WAITTIME_MS = 1000;
+
MediaAutomationHandler.prototype = {
__proto__: BaseAutomationHandler.prototype,
+ /** @override */
+ onTtsStart: function() {
+ this.lastTtsEvent_ = new Date();
+ if (localStorage['useAudioDucking'] == 'true')
+ this.update_({duck: true});
+ if (localStorage['useAudioSuspension'] == 'true')
+ this.update_({suspend: true});
+ },
+
+ /** @override */
+ onTtsEnd: function() {
+ var now = new Date();
+ setTimeout(function() {
+ var then = this.lastTtsEvent_;
+ if (now < then)
+ return;
+ this.lastTtsEvent_ = now;
+ if (localStorage['useAudioDucking'] == 'true')
+ this.update_({unduck: true});
+ if (localStorage['useAudioSuspension'] == 'true')
+ this.update_({resume: true});
+ }.bind(this), MediaAutomationHandler.MIN_WAITTIME_MS);
+ },
+
/**
* @param {!AutomationEvent} evt
*/
onMediaStartedPlaying: function(evt) {
+ if (cvox.ChromeVox.tts.isSpeaking())
+ evt.target.startDuckingMedia();
+
+ this.mediaRoots_.add(evt.target);
},
/**
* @param {!AutomationEvent} evt
*/
onMediaStoppedPlaying: function(evt) {
+ // Intentionally does nothing (to cover resume).
+ },
+
+ /**
+ * Updates the media state for all observed automation roots.
+ * Does not check options.
+ * @param {{duck: (boolean|undefined),
+ * unduck: (boolean|undefined),
+ * resume: (boolean|undefined),
+ * suspend: (boolean|undefined)}} options
+ * @private
+ */
+ update_: function(options) {
+ var it = this.mediaRoots_.values();
+ var item = it.next();
+ while (!item.done) {
+ var root = item.value;
+ if (options.duck)
+ root.startDuckingMedia();
+ if (options.unduck)
+ root.stopDuckingMedia();
+ if (options.resume)
+ root.resumeMedia();
+ if (options.suspend)
+ root.suspendMedia();
+ item = it.next();
+ }
}
};
}); // goog.scope
+
+new MediaAutomationHandler();

Powered by Google App Engine
This is Rietveld 408576698