Bug 1197913 - Keep the last hovered item highlighted after moving the cursor outside the <select> drop-down list on Windows. r=neil, a=ritu
authorTing-Yu Chou <janus926@gmail.com>
Fri, 25 Mar 2016 17:10:16 +0800
changeset 325790 f4cacfbeef6bdcecc07fcc5c20d2c53d3f9b6e7b
parent 325789 6dd378769cc5366ce32c810653adeb52d0792b72
child 325791 2ff41ae73a118a7c132ab9de2b09cf7d34120bcd
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)
reviewersneil, ritu
bugs1197913
milestone47.0a2
Bug 1197913 - Keep the last hovered item highlighted after moving the cursor outside the <select> drop-down list on Windows. r=neil, a=ritu MozReview-Commit-ID: 1mWm5ltckHl
layout/xul/nsMenuFrame.cpp
layout/xul/test/mochitest.ini
layout/xul/test/test_bug1197913.xul
--- a/layout/xul/nsMenuFrame.cpp
+++ b/layout/xul/nsMenuFrame.cpp
@@ -462,17 +462,21 @@ nsMenuFrame::HandleEvent(nsPresContext* 
 
     // Deactivate the menu.
     if (menuParent) {
       bool onmenubar = menuParent->IsMenuBar();
       if (!(onmenubar && menuParent->IsActive())) {
         if (IsMenu() && !onmenubar && IsOpen()) {
           // Submenus don't get closed up immediately.
         }
-        else if (this == menuParent->GetCurrentMenuItem()) {
+        else if (this == menuParent->GetCurrentMenuItem()
+#ifdef XP_WIN
+                 && GetParentMenuListType() == eNotMenuList
+#endif
+        ) {
           menuParent->ChangeMenuItem(nullptr, false, false);
         }
       }
     }
   }
   else if (aEvent->mMessage == eMouseMove &&
            (onmenu || (menuParent && menuParent->IsMenuBar()))) {
     if (gEatMouseMove) {
--- a/layout/xul/test/mochitest.ini
+++ b/layout/xul/test/mochitest.ini
@@ -4,8 +4,10 @@ skip-if = buildapp == 'mulet' || buildap
 [test_bug386386.html]
 [test_bug394800.xhtml]
 [test_bug511075.html]
 skip-if = toolkit == 'android' #bug 798806
 [test_bug563416.html]
 [test_resizer_incontent.xul]
 [test_splitter.xul]
 skip-if = toolkit == 'android' # no XUL theme
+[test_bug1197913.xul]
+skip-if = toolkit == 'android'
new file mode 100644
--- /dev/null
+++ b/layout/xul/test/test_bug1197913.xul
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1197913
+-->
+<window title="Mozilla Bug 1197913"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        onload="SimpleTest.waitForFocus(nextTest, window)">
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"/>
+
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1197913"
+     target="_blank">Mozilla Bug 1197913</a>
+  </body>
+
+  <menulist>
+    <menupopup>
+      <menuitem label="Car" />
+      <menuitem label="Taxi" id="target" />
+      <menuitem label="Bus" />
+    </menupopup>
+  </menulist>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+  SimpleTest.waitForExplicitFinish();
+
+  let menulist = document.getElementsByTagName("menulist")[0];
+  let menuitem = document.getElementById("target");
+
+  function onDOMMenuItemActive(e) {
+    menuitem.removeEventListener("DOMMenuItemActive", onDOMMenuItemActive);
+
+    synthesizeMouse(menuitem, 0, 0, { type: "mousemove" });
+    synthesizeMouse(menuitem, -1, 0, { type: "mousemove" });
+
+    setTimeout(() => {
+      if (navigator.platform.toLowerCase().startsWith("win")) {
+        ok(menuitem.getAttribute("_moz-menuactive"));
+      } else {
+        ok(!menuitem.getAttribute("_moz-menuactive"));
+      }
+
+      SimpleTest.finish();
+    });
+  }
+
+  function onPopupShown(e) {
+    menulist.removeEventListener("popupshown", onPopupShown);
+    menuitem.addEventListener("DOMMenuItemActive", onDOMMenuItemActive);
+    synthesizeMouse(menuitem, 0, 0, { type: "mousemove" });
+    synthesizeMouse(menuitem, 1, 0, { type: "mousemove" });
+  }
+
+  function nextTest(e) {
+    menulist.addEventListener("popupshown", onPopupShown);
+    synthesizeMouseAtCenter(menulist, {});
+  }
+
+  ]]>
+  </script>
+</window>