Bug 1291839 - Change the Narrate input[type=range] to use 'change' events instead of 'input' events because we are not interested in intermediate values of the slider. r=eeejay. r=ritu
authorJared Wein <jwein@mozilla.com>
Tue, 16 Aug 2016 15:44:15 -0400
changeset 350650 61f5a6000c752b08ba01a18d64a186d500cb91a4
parent 350649 da1c556f903c52918b73061c63fe682eb0ee58c6
child 350651 97b73c8ba503bf0fb54136258a8c9653e5b50e9b
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseeejay, ritu
bugs1291839
milestone50.0
Bug 1291839 - Change the Narrate input[type=range] to use 'change' events instead of 'input' events because we are not interested in intermediate values of the slider. r=eeejay. r=ritu MozReview-Commit-ID: JpGbdSonDTD
toolkit/components/narrate/NarrateControls.jsm
toolkit/components/narrate/test/browser_narrate.js
--- a/toolkit/components/narrate/NarrateControls.jsm
+++ b/toolkit/components/narrate/NarrateControls.jsm
@@ -116,46 +116,39 @@ function NarrateControls(mm, win) {
   this.voiceSelect.element.id = "voice-select";
   win.speechSynthesis.addEventListener("voiceschanged", this);
   dropdown.querySelector("#narrate-voices").appendChild(
     this.voiceSelect.element);
 
   dropdown.addEventListener("click", this, true);
 
   let rateRange = dropdown.querySelector("#narrate-rate > input");
-  rateRange.addEventListener("input", this);
-  rateRange.addEventListener("mousedown", this);
-  rateRange.addEventListener("mouseup", this);
+  rateRange.addEventListener("change", this);
 
   // The rate is stored as an integer.
   rateRange.value = branch.getIntPref("rate");
 
   if (this._setupVoices(branch.getCharPref("voice"))) {
     // We disable this entire feature if there are no synthesis voices.
     dropdown.querySelector("#narrate-toggle").hidden = false;
   }
 
   let tb = win.document.getElementById("reader-toolbar");
   tb.appendChild(dropdown);
 }
 
 NarrateControls.prototype = {
   handleEvent: function(evt) {
     switch (evt.type) {
-      case "mousedown":
-        this._rateMousedown = true;
-        break;
-      case "mouseup":
-        this._rateMousedown = false;
-        break;
-      case "input":
-        this._onRateInput(evt);
-        break;
       case "change":
-        this._onVoiceChange();
+        if (evt.target.id == "narrate-rate-input") {
+          this._onRateInput(evt);
+        } else {
+          this._onVoiceChange();
+        }
         break;
       case "click":
         this._onButtonClick(evt);
         break;
       case "voiceschanged":
         // We disable this entire feature if there are no synthesis voices.
         this._doc.getElementById("narrate-toggle").hidden =
           !this._setupVoices(Services.prefs.getCharPref("narrate.voice"));
@@ -185,20 +178,18 @@ NarrateControls.prototype = {
       });
       this.voiceSelect.addOptions(options, selectedVoice);
     }
 
     return !!options.length;
   },
 
   _onRateInput: function(evt) {
-    if (!this._rateMousedown) {
-      AsyncPrefs.set("narrate.rate", parseInt(evt.target.value, 10));
-      this.narrator.setRate(this._convertRate(evt.target.value));
-    }
+    AsyncPrefs.set("narrate.rate", parseInt(evt.target.value, 10));
+    this.narrator.setRate(this._convertRate(evt.target.value));
   },
 
   _onVoiceChange: function() {
     let voice = this.voice;
     AsyncPrefs.set("narrate.voice", voice);
     this.narrator.setVoice(voice);
   },
 
--- a/toolkit/components/narrate/test/browser_narrate.js
+++ b/toolkit/components/narrate/test/browser_narrate.js
@@ -70,17 +70,17 @@ add_task(function* testNarrate() {
 
     NarrateTestUtils.isStartedState(content, ok);
 
     let eventUtils = NarrateTestUtils.getEventUtils(content);
 
     promiseEvent = ContentTaskUtils.waitForEvent(content, "paragraphstart");
     prefChanged = NarrateTestUtils.waitForPrefChange("narrate.rate");
     $(NarrateTestUtils.RATE).focus();
-    eventUtils.sendKey("PAGE_UP", content);
+    eventUtils.sendKey("UP", content);
     let newspeechinfo = (yield promiseEvent).detail;
     is(newspeechinfo.paragraph, speechinfo.paragraph, "same paragraph");
     isnot(newspeechinfo.rate, speechinfo.rate, "rate changed");
     yield prefChanged;
 
     promiseEvent = ContentTaskUtils.waitForEvent(content, "paragraphend");
     $(NarrateTestUtils.STOP).click();
     yield promiseEvent;