Bug 1291078 - Have SelectContentHelper dispatch events on <option> instead of <select>. r=Enn a=lizzard
authorMike Conley <mconley@mozilla.com>
Fri, 05 Aug 2016 17:13:10 -0400
changeset 332650 cff9e0a1ca42
parent 332649 d67e58e5ad8c
child 332651 fb956712e50f
push id9888
push userkwierso@gmail.com
push dateWed, 10 Aug 2016 17:37:29 +0000
treeherdermozilla-aurora@f5a9d33557dd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEnn, lizzard
bugs1291078
milestone50.0a2
Bug 1291078 - Have SelectContentHelper dispatch events on <option> instead of <select>. r=Enn a=lizzard MozReview-Commit-ID: 7dxVipFqhiV
layout/forms/nsListControlFrame.cpp
toolkit/modules/SelectContentHelper.jsm
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -1832,16 +1832,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
@@ -110,17 +110,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,
@@ -134,17 +135,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);
             if (eventName == "mouseup") {
               DOMUtils.removeContentState(this.element, kStateActive);
             }
           }
         }
 
         this.uninit();
         break;