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 340274 989dd4e6803e
parent 340273 ef550c3f5a77
child 340275 63cdaf45dd02
push id6284
push userkwierso@gmail.com
push dateWed, 10 Aug 2016 17:55:00 +0000
treeherdermozilla-beta@39ad687dbbae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEnn, lizzard
bugs1291078
milestone49.0
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
@@ -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);