Bug 1291078 - Have SelectContentHelper dispatch events on <option> instead of <select>. r=Enn, a=sylvestre
authorMike Conley <mconley@mozilla.com>
Wed, 03 Aug 2016 13:17:59 -0400
changeset 335698 f0b7fef514f4
parent 335697 c8f17ac10df5
child 335699 e7d4b84c0ced
push id1153
push usercbook@mozilla.com
push dateTue, 09 Aug 2016 07:12:04 +0000
treeherdermozilla-release@e7d4b84c0ced [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEnn, sylvestre
bugs1291078
milestone48.0.1
Bug 1291078 - Have SelectContentHelper dispatch events on <option> instead of <select>. r=Enn, a=sylvestre MozReview-Commit-ID: 98oLdrutvAC
layout/forms/nsListControlFrame.cpp
toolkit/modules/SelectContentHelper.jsm
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -1817,16 +1817,27 @@ nsListControlFrame::MouseDown(nsIDOMEven
       HandleListSelection(aMouseEvent, selectedIndex); // might destroy us
     if (!weakFrame.IsAlive()) {
       return NS_OK;
     }
     mChangesSinceDragStart = change;
   } else {
     // NOTE: the combo box is responsible for dropping it down
     if (mComboboxFrame) {
+      // Ignore the click that occurs on the option element when one is
+      // selected from the parent process popup.
+      if (mComboboxFrame->IsOpenInParentProcess()) {
+        nsCOMPtr<nsIDOMEventTarget> etarget;
+        aMouseEvent->GetTarget(getter_AddRefs(etarget));
+        nsCOMPtr<nsIDOMHTMLOptionElement> option = do_QueryInterface(etarget);
+        if (option) {
+          return NS_OK;
+        }
+      }
+
       if (FireShowDropDownEvent(mContent)) {
         return NS_OK;
       }
 
       if (!IgnoreMouseEventForSelection(aMouseEvent)) {
         return NS_OK;
       }
 
--- a/toolkit/modules/SelectContentHelper.jsm
+++ b/toolkit/modules/SelectContentHelper.jsm
@@ -109,17 +109,18 @@ this.SelectContentHelper.prototype = {
 
   receiveMessage: function(message) {
     switch (message.name) {
       case "Forms:SelectDropDownItem":
         this.element.selectedIndex = message.data.value;
         break;
 
       case "Forms:DismissedDropDown":
-        if (this.initialSelection != this.element.item(this.element.selectedIndex)) {
+        let selectedOption = this.element.item(this.element.selectedIndex);
+        if (this.initialSelection != selectedOption) {
           let win = this.element.ownerDocument.defaultView;
           let inputEvent = new win.UIEvent("input", {
             bubbles: true,
           });
           this.element.dispatchEvent(inputEvent);
 
           let changeEvent = new win.Event("change", {
             bubbles: true,
@@ -133,17 +134,17 @@ this.SelectContentHelper.prototype = {
           // 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);
+            selectedOption.dispatchEvent(mouseEvent);
           }
         }
 
         this.uninit();
         break;
 
       case "Forms:MouseOver":
         DOMUtils.setContentState(this.element, kStateHover);