Bug 1275384 - Dispatch mousedown, mouseup and click events manually on <select> for e10s instead of using DOMWindowUtils. r?felipe draft
authorMike Conley <mconley@mozilla.com>
Wed, 25 May 2016 13:21:23 -0400
changeset 371470 5d1704567dd03056038420a0d2b13b54949e495b
parent 370842 d6d4e8417d2fd71fdf47c319b7a217f6ace9d5a5
child 521999 6bdd7b6020e6833c999b0e634fea97c19de6fd63
push id19334
push usermconley@mozilla.com
push dateThu, 26 May 2016 18:10:29 +0000
reviewersfelipe
bugs1275384
milestone49.0a1
Bug 1275384 - Dispatch mousedown, mouseup and click events manually on <select> for e10s instead of using DOMWindowUtils. r?felipe We were using nsIDOMWindowUtils to send mousedown and mouseup events to the <select> input after a selection was made in e10s mode, but doing so causes focus to be pulled back to the <select> if any input or change event handlers tried to shift focus. For example, the reviewer input on Bugzilla was having its focus stolen after setting the review flag to r?, which was how this bug was discovered. We're going for mostly-Blink parity here, where it seems (at least on Windows) a mouseup and click event are dispatched on <select> elements after the dropdown is closed (either by mouse or keyboard). We're adding a mousedown just before those, since that seems to make the most sense. MozReview-Commit-ID: HAThE6ClBWT
toolkit/modules/SelectContentHelper.jsm
--- a/toolkit/modules/SelectContentHelper.jsm
+++ b/toolkit/modules/SelectContentHelper.jsm
@@ -119,21 +119,30 @@ this.SelectContentHelper.prototype = {
           });
           this.element.dispatchEvent(inputEvent);
 
           let changeEvent = new win.Event("change", {
             bubbles: true,
           });
           this.element.dispatchEvent(changeEvent);
 
-          let dwu = win.QueryInterface(Ci.nsIInterfaceRequestor)
-                       .getInterface(Ci.nsIDOMWindowUtils);
-          let rect = this.element.getBoundingClientRect();
-          dwu.sendMouseEvent("mousedown", rect.left, rect.top, 0, 1, 0, true);
-          dwu.sendMouseEvent("mouseup", rect.left, rect.top, 0, 1, 0, true);
+          // 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,
+            });
+            this.element.dispatchEvent(mouseEvent);
+          }
         }
 
         this.uninit();
         break;
 
       case "Forms:MouseOver":
         DOMUtils.setContentState(this.element, kStateHover);
         break;