Commit 2e639e94 authored by Richard Pospesel's avatar Richard Pospesel Committed by Georg Koppen
Browse files

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'.
parent 3bb82140
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -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 */

+2 −1
Original line number Diff line number Diff line
<toolbarbutton id="security-level-button" class="toolbarbutton-1 chromeclass-toolbar-additional badged-button"
               removable="true"
               onmousedown="SecurityLevelButton.onCommand();"
               onmousedown="SecurityLevelButton.onCommand(event);"
               onkeypress="SecurityLevelButton.onCommand(event);"
               closemenu="none"
               cui-areatype="toolbar"/>