Bug 1247420 - part2: IPC hover state management for select. r=Felipc
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Wed, 30 Mar 2016 11:54:31 +0200
changeset 290893 61241975d4dab068524ab4c77eb045f79815c058
parent 290892 d791887510c81cbea2d241054c6494bd4b712efb
child 290894 dc32b86990d5142169d46d9b1ac75c780d99442c
push id74414
push usergkrizsanits@mozilla.com
push dateWed, 30 Mar 2016 13:31:55 +0000
treeherdermozilla-inbound@61241975d4da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipc
bugs1247420
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1247420 - part2: IPC hover state management for select. r=Felipc
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":
         if (this.element.ownerDocument === event.target) {
           this.global.sendAsyncMessage("Forms:HideDropDown", {});
--- 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;