Bug 1291078 - More closely mimic non-e10s order of events when choosing <select> elements in e10s mode. r?Enn
MozReview-Commit-ID: 4CkFUy1nLbo
--- 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);