[tor-commits] [tor-browser/tor-browser-45.1.1esr-6.0-1] Bug 1266963, stop propagation before other steps, r=masayuki

gk at torproject.org gk at torproject.org
Fri Jun 3 06:57:05 UTC 2016


commit e38872520658a519cca3c69e635cd5cb6d825d21
Author: Neil Deakin <neil at mozilla.com>
Date:   Wed May 4 10:07:45 2016 -0400

    Bug 1266963, stop propagation before other steps, r=masayuki
    
    This is a backport of
    https://hg.mozilla.org/mozilla-central/rev/1d23af51e886.
    
    Note we don't call `AsEvent()` as the original patch is doing as that
    change got introduced by bug 1230216 which landed in mozilla46.
---
 layout/xul/nsXULPopupManager.cpp                 | 16 +++++++++-------
 toolkit/content/tests/widgets/window_menubar.xul | 24 ++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/layout/xul/nsXULPopupManager.cpp b/layout/xul/nsXULPopupManager.cpp
index a31dbdb..4176727 100644
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -2514,6 +2514,12 @@ nsXULPopupManager::KeyDown(nsIDOMKeyEvent* aKeyEvent)
   if (!mActiveMenuBar && (!item || item->PopupType() != ePopupTypeMenu))
     return NS_OK;
 
+  // Since a menu was open, stop propagation of the event to keep other event
+  // listeners from becoming confused.
+  if (!item || item->IgnoreKeys() != eIgnoreKeys_Handled) {
+    aKeyEvent->StopPropagation();
+  }
+
   int32_t menuAccessKey = -1;
 
   // If the key just pressed is the access key (usually Alt),
@@ -2544,19 +2550,15 @@ nsXULPopupManager::KeyDown(nsIDOMKeyEvent* aKeyEvent)
           Rollup(0, false, nullptr, nullptr);
         else if (mActiveMenuBar)
           mActiveMenuBar->MenuClosed();
+
+        // Clear the item to avoid bugs as it may have been deleted during rollup.
+        item = nullptr;
       }
       aKeyEvent->StopPropagation();
       aKeyEvent->PreventDefault();
     }
   }
 
-  // Since a menu was open, stop propagation of the event to keep other event
-  // listeners from becoming confused.
-
-  if (!item || item->IgnoreKeys() != eIgnoreKeys_Handled) {
-    aKeyEvent->StopPropagation();
-  }
-
   aKeyEvent->StopCrossProcessForwarding();
   return NS_OK;
 }
diff --git a/toolkit/content/tests/widgets/window_menubar.xul b/toolkit/content/tests/widgets/window_menubar.xul
index 41b74f3..b7669e0 100644
--- a/toolkit/content/tests/widgets/window_menubar.xul
+++ b/toolkit/content/tests/widgets/window_menubar.xul
@@ -706,6 +706,30 @@ var popupTests = [
   }
 },
 
+{
+  testname: "Open menu and press alt key by itself - open menu",
+  events: [ "DOMMenuBarActive menubar",
+            "popupshowing filepopup", "DOMMenuItemActive filemenu",
+            "DOMMenuItemActive item1", "popupshown filepopup" ],
+  test: function() { synthesizeKey("F", { altKey: true }); },
+  result: function (testname) {
+    checkOpen("filemenu", testname);
+  }
+},
+{
+  testname: "Open menu and press alt key by itself - close menu",
+  events: [ "popuphiding filepopup", "popuphidden filepopup",
+            "DOMMenuItemInactive item1", "DOMMenuInactive filepopup",
+            "DOMMenuBarInactive menubar", "DOMMenuItemInactive filemenu",
+            "DOMMenuItemInactive filemenu" ],
+  test: function() {
+    synthesizeKey("VK_ALT", { });
+  },
+  result: function (testname) {
+    checkClosed("filemenu", testname);
+  }
+},
+
 // Fllowing 4 tests are a test of bug 616797, don't insert any new tests
 // between them.
 {



More information about the tor-commits mailing list