From eb1eb18e9deb39aec3fcac1a5e8b2cb6a762a810 Mon Sep 17 00:00:00 2001 From: Richard Pospesel Date: Wed, 16 Oct 2019 15:35:33 -0700 Subject: [PATCH] Bug 31749: Fix security level panel spawning events Fixed logic for when the Security Level panel is spawned based on input to mirror behavior of Downloads, Library and Hamburger menus. The panel now spawns on left-mouse button down, and on keyboard activation when user presses 'space' or 'enter'. --- .../securitylevel/content/securityLevel.js | 19 ++++++++++++++++--- .../content/securityLevelButton.inc.xul | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/browser/components/securitylevel/content/securityLevel.js b/browser/components/securitylevel/content/securityLevel.js index 280a8c2156d14..2081eabb41762 100644 --- a/browser/components/securitylevel/content/securityLevel.js +++ b/browser/components/securitylevel/content/securityLevel.js @@ -160,12 +160,25 @@ const SecurityLevelButton = { } }, - // when toolbar button is pressed - onCommand : function(event) { + // for when the toolbar button needs to be activated and displays the Security Level panel + // + // In the toolbarbutton xul you'll notice we register this callback for both onkeypress and + // onmousedown. We do this to match the behavior of other panel spawning buttons such as Downloads, + // Library, and the Hamburger menus. Using oncommand alone would result in only getting fired + // after onclick, which is mousedown followed by mouseup. + onCommand : function(aEvent) { + // snippet stolen from /browser/components/downloads/indicator.js DownloadsIndicatorView.onCommand(evt) + if ( + (aEvent.type == "mousedown" && aEvent.button != 0) || + (aEvent.type == "keypress" && aEvent.key != " " && aEvent.key != "Enter") + ) { + return; + } + // we need to set this attribute for the button to be shaded correctly to look like it is pressed // while the security level panel is open this.button.setAttribute("open", "true"); - SecurityLevelPanel.show(event); + SecurityLevelPanel.show(); }, }; /* Security Level Button */ diff --git a/browser/components/securitylevel/content/securityLevelButton.inc.xul b/browser/components/securitylevel/content/securityLevelButton.inc.xul index 579a55f46d4a9..d55aacb5c5d4e 100644 --- a/browser/components/securitylevel/content/securityLevelButton.inc.xul +++ b/browser/components/securitylevel/content/securityLevelButton.inc.xul @@ -1,5 +1,6 @@ -- GitLab