Index: third_party/google_input_tools/src/chrome/os/soundcontroller.js |
diff --git a/third_party/google_input_tools/src/chrome/os/inputview/soundcontroller.js b/third_party/google_input_tools/src/chrome/os/soundcontroller.js |
similarity index 73% |
rename from third_party/google_input_tools/src/chrome/os/inputview/soundcontroller.js |
rename to third_party/google_input_tools/src/chrome/os/soundcontroller.js |
index 19b702450d76ed6c7040d037dc2ab180dede980b..7b57e3b557da44c6c7c0e6ca7dbd0d7ebc4de00d 100644 |
--- a/third_party/google_input_tools/src/chrome/os/inputview/soundcontroller.js |
+++ b/third_party/google_input_tools/src/chrome/os/soundcontroller.js |
@@ -1,4 +1,4 @@ |
-// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. |
+// Copyright 2015 The ChromeOS IME Authors. All Rights Reserved. |
// limitations under the License. |
// See the License for the specific language governing permissions and |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
@@ -11,7 +11,7 @@ |
// you may not use this file except in compliance with the License. |
// Licensed under the Apache License, Version 2.0 (the "License"); |
// |
-goog.provide('i18n.input.chrome.inputview.SoundController'); |
+goog.provide('i18n.input.chrome.SoundController'); |
goog.require('goog.Disposable'); |
goog.require('goog.dom'); |
@@ -25,40 +25,43 @@ var keyToSoundIdOnKeyUp = {}; |
var keyToSoundIdOnKeyRepeat = {}; |
+ |
/** |
* Sound controller for the keyboard. |
* |
* @param {!boolean} enabled Whether sounds is enabled by default. |
- * @param {?number} opt_volume The default volume for sound tracks. |
+ * @param {?number=} opt_volume The default volume for sound tracks. |
* @constructor |
* @extends {goog.Disposable} |
*/ |
-i18n.input.chrome.inputview.SoundController = function(enabled, opt_volume) { |
+i18n.input.chrome.SoundController = function(enabled, opt_volume) { |
/** |
* Collection of all the sound pools. |
* |
- * @type {!Object.<string, !Object>} |
+ * @private {!Object.<string, !Object>} |
*/ |
this.sounds_ = {}; |
+ /** @private {boolean} */ |
this.enabled_ = enabled; |
/** |
* The default volume for all audio tracks. Tracks with volume 0 will be |
* skipped. |
* |
- * @type {number} |
+ * @private {number} |
*/ |
this.volume_ = opt_volume || this.DEFAULT_VOLUME; |
- if (enabled) |
+ if (enabled) { |
this.initialize(); |
+ } |
}; |
-goog.inherits(i18n.input.chrome.inputview.SoundController, goog.Disposable); |
+goog.inherits(i18n.input.chrome.SoundController, goog.Disposable); |
-var Controller = i18n.input.chrome.inputview.SoundController; |
+var Controller = i18n.input.chrome.SoundController; |
/** |
@@ -73,17 +76,24 @@ Controller.prototype.POOL_SIZE = 10; |
Controller.prototype.DEFAULT_VOLUME = 0.6; |
+/** @private {boolean} */ |
+Controller.prototype.initialized_ = false; |
+ |
+ |
/** |
* Initializes the sound controller. |
*/ |
Controller.prototype.initialize = function() { |
- for (var sound in Sounds) { |
+ if (!this.initialized_) { |
+ for (var sound in Sounds) { |
this.addSound_(Sounds[sound]); |
+ } |
+ keyToSoundIdOnKeyUp[ElementType.BACKSPACE_KEY] = Sounds.NONE; |
+ keyToSoundIdOnKeyUp[ElementType.ENTER_KEY] = Sounds.RETURN; |
+ keyToSoundIdOnKeyUp[ElementType.SPACE_KEY] = Sounds.SPACEBAR; |
+ keyToSoundIdOnKeyRepeat[ElementType.BACKSPACE_KEY] = Sounds.DELETE; |
+ this.initialized_ = true; |
} |
- keyToSoundIdOnKeyUp[ElementType.BACKSPACE_KEY] = Sounds.NONE; |
- keyToSoundIdOnKeyUp[ElementType.ENTER_KEY] = Sounds.RETURN; |
- keyToSoundIdOnKeyUp[ElementType.SPACE_KEY] = Sounds.SPACEBAR; |
- keyToSoundIdOnKeyRepeat[ElementType.BACKSPACE_KEY] = Sounds.DELETE; |
}; |
@@ -137,8 +147,19 @@ Controller.prototype.setVolume = function(soundId, volume) { |
*/ |
Controller.prototype.setEnabled = function(enabled) { |
this.enabled_ = enabled; |
- if (this.enabled_) |
+ if (this.enabled_) { |
this.initialize(); |
+ } |
+}; |
+ |
+ |
+/** |
+ * Gets the flag whether sound controller is enabled or not. |
+ * |
+ * @return {!boolean} |
+ */ |
+Controller.prototype.getEnabled = function() { |
+ return this.enabled_; |
}; |
@@ -159,12 +180,18 @@ Controller.prototype.setMasterVolume = function(volume) { |
* Plays the specified sound. |
* |
* @param {string} soundId The id of the audio tag. |
- * @private |
+ * @param {boolean=} opt_force Force to play sound whatever the enabled flags is |
+ * turned on. |
*/ |
-Controller.prototype.playSound_ = function(soundId) { |
+Controller.prototype.playSound = function(soundId, opt_force) { |
+ if (opt_force) { |
+ this.initialize(); |
+ } |
// If master volume is zero, ignore the request. |
- if (!this.enabled_ || this.volume_ == 0 || soundId == Sounds.NONE) |
+ if (!opt_force && !this.enabled_ || this.volume_ == 0 || |
+ soundId == Sounds.NONE) { |
return; |
+ } |
var pool = this.sounds_[soundId]; |
if (!pool) { |
console.error('Cannot find sound: ' + soundId); |
@@ -185,25 +212,25 @@ Controller.prototype.playSound_ = function(soundId) { |
* |
* @param {ElementType} key The key released. |
*/ |
- Controller.prototype.onKeyUp = function(key) { |
+Controller.prototype.onKeyUp = function(key) { |
var sound = keyToSoundIdOnKeyUp[key] || Sounds.STANDARD; |
- this.playSound_(sound); |
- }; |
+ this.playSound(sound); |
+}; |
- /** |
+/** |
* On key repeat. |
* |
* @param {ElementType} key The key that is being repeated. |
*/ |
- Controller.prototype.onKeyRepeat = function(key) { |
+Controller.prototype.onKeyRepeat = function(key) { |
var sound = keyToSoundIdOnKeyRepeat[key] || Sounds.NONE; |
- this.playSound_(sound); |
- }; |
+ this.playSound(sound); |
+}; |
- /** @override */ |
- Controller.prototype.disposeInternal = function() { |
+/** @override */ |
+Controller.prototype.disposeInternal = function() { |
for (var soundId in this.sounds_) { |
var pool = this.sounds_[soundId]; |
for (var i = 0; i < pool.length; i++) { |
@@ -221,6 +248,6 @@ Controller.prototype.playSound_ = function(soundId) { |
keyToSoundIdOnKeyUp = {}; |
keyToSoundIdOnKeyRepeat = {}; |
goog.base(this, 'disposeInternal'); |
- }; |
+}; |
}); // goog.scope |