Bug 1291078 - More closely mimic non-e10s order of events when choosing <select> elements in e10s mode. r=enndeakin+6102
authorMike Conley <mconley@mozilla.com>
Tue, 02 Aug 2016 15:09:59 -0400
changeset 307997 62a983c56050
parent 307996 6732d24079ca
child 307998 fd861f275e09
child 308025 0e51d95ded87
push id31062
push usermconley@mozilla.com
push dateThu, 04 Aug 2016 06:23:16 +0000
treeherderautoland@62a983c56050 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin
bugs1291078
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1291078 - More closely mimic non-e10s order of events when choosing <select> elements in e10s mode. r=enndeakin+6102 MozReview-Commit-ID: 4CkFUy1nLbo
browser/base/content/test/general/browser_selectpopup.js
toolkit/modules/SelectContentHelper.jsm
--- a/browser/base/content/test/general/browser_selectpopup.js
+++ b/browser/base/content/test/general/browser_selectpopup.js
@@ -315,36 +315,36 @@ add_task(function* test_event_order() {
         type: "change",
         cancelable: false,
         targetIsOption: false,
       },
     ];
 
     let expectedClick = [
       {
+        type: "mousedown",
+        cancelable: true,
+        targetIsOption: true,
+      },
+      {
+        type: "mouseup",
+        cancelable: true,
+        targetIsOption: true,
+      },
+      {
         type: "input",
         cancelable: false,
         targetIsOption: false,
       },
       {
         type: "change",
         cancelable: false,
         targetIsOption: false,
       },
       {
-        type: "mousedown",
-        cancelable: true,
-        targetIsOption: true,
-      },
-      {
-        type: "mouseup",
-        cancelable: true,
-        targetIsOption: true,
-      },
-      {
         type: "click",
         cancelable: true,
         targetIsOption: true,
       },
     ];
 
     for (let mode of ["enter", "click"]) {
       let expected = mode == "enter" ? expectedEnter : expectedClick;
--- a/toolkit/modules/SelectContentHelper.jsm
+++ b/toolkit/modules/SelectContentHelper.jsm
@@ -115,44 +115,52 @@ this.SelectContentHelper.prototype = {
         this.element.selectedIndex = message.data.value;
         this.closedWithEnter = message.data.closedWithEnter;
         break;
 
       case "Forms:DismissedDropDown":
         let selectedOption = this.element.item(this.element.selectedIndex);
         if (this.initialSelection != selectedOption) {
           let win = this.element.ownerDocument.defaultView;
+          // For ordering of events, we're using non-e10s as our guide here,
+          // since the spec isn't exactly clear. In non-e10s, we fire:
+          // mousedown, mouseup, input, change, click if the user clicks
+          // on an element in the dropdown. If the user uses the keyboard
+          // to select an element in the dropdown, we only fire input and
+          // change events.
+          if (!this.closedWithEnter) {
+            const MOUSE_EVENTS = ["mousedown", "mouseup"];
+            for (let eventName of MOUSE_EVENTS) {
+              let mouseEvent = new win.MouseEvent(eventName, {
+                view: win,
+                bubbles: true,
+                cancelable: true,
+              });
+              selectedOption.dispatchEvent(mouseEvent);
+            }
+            DOMUtils.removeContentState(this.element, kStateActive);
+          }
+
           let inputEvent = new win.UIEvent("input", {
             bubbles: true,
           });
           this.element.dispatchEvent(inputEvent);
 
           let changeEvent = new win.Event("change", {
             bubbles: true,
           });
           this.element.dispatchEvent(changeEvent);
 
           if (!this.closedWithEnter) {
-            // Going for mostly-Blink parity here, which (at least on Windows)
-            // fires a mouseup and click event after each selection -
-            // even by keyboard. We're firing a mousedown too, since that
-            // seems to make more sense. Unfortunately, the spec on form
-            // control behaviours for these events is really not clear.
-            const MOUSE_EVENTS = ["mousedown", "mouseup", "click"];
-            for (let eventName of MOUSE_EVENTS) {
-              let mouseEvent = new win.MouseEvent(eventName, {
-                view: win,
-                bubbles: true,
-                cancelable: true,
-              });
-              selectedOption.dispatchEvent(mouseEvent);
-              if (eventName == "mouseup") {
-                DOMUtils.removeContentState(this.element, kStateActive);
-              }
-            }
+            let mouseEvent = new win.MouseEvent("click", {
+              view: win,
+              bubbles: true,
+              cancelable: true,
+            });
+            selectedOption.dispatchEvent(mouseEvent);
           }
         }
 
         this.uninit();
         break;
 
       case "Forms:MouseOver":
         DOMUtils.setContentState(this.element, kStateHover);