Bug 1247420 - Part 2: IPC hover state management for select. r=Felipc, a=ritu
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Wed, 30 Mar 2016 11:54:31 +0200
changeset 325758 9c27561989150a7e66ca7a9e2cb73e6ca688f384
parent 325757 02165cf8bba15513b33f035523b51b35c2d565b9
child 325759 f21cae54c71a57194cc27de8da8d4a4a05298d89
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipc, ritu
bugs1247420
milestone47.0a2
Bug 1247420 - Part 2: IPC hover state management for select. r=Felipc, a=ritu
toolkit/modules/SelectContentHelper.jsm
toolkit/modules/SelectParentHelper.jsm
--- a/toolkit/modules/SelectContentHelper.jsm
+++ b/toolkit/modules/SelectContentHelper.jsm
@@ -7,16 +7,20 @@
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
                                   "resource://gre/modules/BrowserUtils.jsm");
+XPCOMUtils.defineLazyServiceGetter(this, "DOMUtils",
+                                   "@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
+
+const kStateHover = 0x00000004; // NS_EVENT_STATE_HOVER
 
 this.EXPORTED_SYMBOLS = [
   "SelectContentHelper"
 ];
 
 this.SelectContentHelper = function (aElement, aGlobal) {
   this.element = aElement;
   this.initialSelection = aElement[aElement.selectedIndex] || null;
@@ -24,22 +28,26 @@ this.SelectContentHelper = function (aEl
   this.init();
   this.showDropDown();
 }
 
 this.SelectContentHelper.prototype = {
   init: function() {
     this.global.addMessageListener("Forms:SelectDropDownItem", this);
     this.global.addMessageListener("Forms:DismissedDropDown", this);
+    this.global.addMessageListener("Forms:MouseOver", this);
+    this.global.addMessageListener("Forms:MouseOut", this);
     this.global.addEventListener("pagehide", this);
   },
 
   uninit: function() {
     this.global.removeMessageListener("Forms:SelectDropDownItem", this);
     this.global.removeMessageListener("Forms:DismissedDropDown", this);
+    this.global.removeMessageListener("Forms:MouseOver", this);
+    this.global.removeMessageListener("Forms:MouseOut", this);
     this.global.removeEventListener("pagehide", this);
     this.element = null;
     this.global = null;
   },
 
   showDropDown: function() {
     let rect = this._getBoundingContentRect();
 
@@ -69,16 +77,25 @@ this.SelectContentHelper.prototype = {
         if (this.initialSelection != this.element.item(this.element.selectedIndex)) {
           let event = this.element.ownerDocument.createEvent("Events");
           event.initEvent("change", true, true);
           this.element.dispatchEvent(event);
         }
 
         this.uninit();
         break;
+
+      case "Forms:MouseOver":
+        DOMUtils.setContentState(this.element, kStateHover);
+        break;
+
+      case "Forms:MouseOut":
+        DOMUtils.removeContentState(this.element, kStateHover);
+        break;
+
     }
   },
 
   handleEvent: function(event) {
     switch (event.type) {
       case "pagehide":
         this.global.sendAsyncMessage("Forms:HideDropDown", {});
         this.uninit();
--- a/toolkit/modules/SelectParentHelper.jsm
+++ b/toolkit/modules/SelectParentHelper.jsm
@@ -27,16 +27,24 @@ this.SelectParentHelper = {
   },
 
   hide: function(menulist) {
     menulist.menupopup.hidePopup();
   },
 
   handleEvent: function(event) {
     switch (event.type) {
+      case "mouseover":
+        currentBrowser.messageManager.sendAsyncMessage("Forms:MouseOver", {});
+        break;
+
+      case "mouseout":
+        currentBrowser.messageManager.sendAsyncMessage("Forms:MouseOut", {});
+        break;
+
       case "command":
         if (event.target.hasAttribute("value")) {
           currentBrowser.messageManager.sendAsyncMessage("Forms:SelectDropDownItem", {
             value: event.target.value
           });
         }
         break;
 
@@ -48,21 +56,25 @@ this.SelectParentHelper = {
         popup.parentNode.hidden = true;
         break;
     }
   },
 
   _registerListeners: function(popup) {
     popup.addEventListener("command", this);
     popup.addEventListener("popuphidden", this);
+    popup.addEventListener("mouseover", this);
+    popup.addEventListener("mouseout", this);
   },
 
   _unregisterListeners: function(popup) {
     popup.removeEventListener("command", this);
     popup.removeEventListener("popuphidden", this);
+    popup.removeEventListener("mouseover", this);
+    popup.removeEventListener("mouseout", this);
   },
 
 };
 
 function populateChildren(menulist, options, selectedIndex, zoom,
                           isInGroup = false, isGroupDisabled = false, adjustedTextSize = -1) {
   let element = menulist.menupopup;