Bug 559915 - Handle Menu and Search AppCommand events [r=mfinkle]
authorAlex Pakhotin <apakhotin@mozilla.com>
Tue, 27 Apr 2010 13:33:59 -0700
changeset 66178 81a07876476dad610d92bb2e348ac47e1b7b4e4d
parent 66177 0e9a3ed59dd47c38afa85073e0c1087ef3fb455c
child 66179 8ba0a12654483aecc434ff55895e18205365f524
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs559915
Bug 559915 - Handle Menu and Search AppCommand events [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
mobile/chrome/content/browser.xul
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -420,16 +420,19 @@ var BrowserUI = {
     browsers.addEventListener("DOMWillOpenModalDialog", this, true);
 
     // listening mousedown for automatically dismiss some popups (e.g. larry)
     window.addEventListener("mousedown", this, true);
 
     // listening escape to dismiss dialog on VK_ESCAPE
     window.addEventListener("keypress", this, true);
 
+    // listening AppCommand to handle special keys
+    window.addEventListener("AppCommand", this, true);
+
     // Push the panel initialization out of the startup path
     // (Using an event because we have no good way to delay-init [Bug 535366])
     browsers.addEventListener("load", function() {
       // We only want to delay one time
       browsers.removeEventListener("load", arguments.callee, true);
       
       // We unhide the panelUI so the XBL and settings can initialize
       Elements.panelUI.hidden = false;
@@ -702,16 +705,29 @@ var BrowserUI = {
       // Window events
       case "keypress":
         if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE) {
           let dialog = this.activeDialog;
           if (dialog)
             dialog.close();
         }
         break;
+      case "AppCommand":
+        aEvent.stopPropagation();
+        switch (aEvent.command) {
+          case "Menu":
+            this.doCommand("cmd_menu");
+            break;
+          case "Search":
+            this.doCommand("cmd_openLocation");
+            break;
+          default:
+            break;
+        }
+        break;
       // URL textbox events
       case "mouseup":
         if (!this._isEventInsidePopup(aEvent))
           this._hidePopup();
 
         if (aEvent.detail < 2 && aEvent.button == 0)
           this.doCommand("cmd_openLocation");
         break;
@@ -824,16 +840,17 @@ var BrowserUI = {
         break;
       case "cmd_quit":
         goQuitApplication();
         break;
       case "cmd_close":
         this._closeOrQuit();
         break;
       case "cmd_menu":
+        getIdentityHandler().toggle();
         break;
       case "cmd_newTab":
         this.newTab();
         break;
       case "cmd_closeTab":
         this.closeTab();
         break;
       case "cmd_sanitize":
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -2267,31 +2267,35 @@ IdentityHandler.prototype = {
   hide: function ih_hide() {
     this._identityPopup.hidden = true;
     this._identityBox.removeAttribute("open");
 
     BrowserUI.popPopup();
     BrowserUI.unlockToolbar();
   },
 
+  toggle: function ih_toggle() {
+    if (this._identityPopup.hidden)
+      this.show();
+    else
+      this.hide();
+  },
+
   /**
    * Click handler for the identity-box element in primary chrome.
    */
   handleIdentityButtonEvent: function(event) {
     event.stopPropagation();
 
     if ((event.type == "click" && event.button != 0) ||
         (event.type == "keypress" && event.charCode != KeyEvent.DOM_VK_SPACE &&
          event.keyCode != KeyEvent.DOM_VK_RETURN))
       return; // Left click, space or enter only
 
-    if (this._identityPopup.hidden)
-      this.show();
-    else
-      this.hide();
+    this.toggle();
   }
 };
 
 var gIdentityHandler;
 
 /**
  * Returns the singleton instance of the identity handler class.  Should always be
  * used instead of referencing the global variable directly or creating new instances
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -169,17 +169,16 @@
     <key id="key_pageUp" keycode="VK_UP" modifiers="shift" command="cmd_scrollPageUp"/>
     <key id="key_pageDown" keycode="VK_DOWN" modifiers="shift" command="cmd_scrollPageDown"/>
 
     <!-- misc -->
     <key id="key_zoomin" keycode="VK_UP" modifiers="accel" command="cmd_zoomin"/>
     <key id="key_zoomout" keycode="VK_DOWN" modifiers="accel" command="cmd_zoomout"/>
 #ifndef WINCE
     <key id="key_quit" key="q" modifiers="accel" command="cmd_quit"/>
-    <key id="key_menu" keycode="VK_F4" command="cmd_menu"/>
     <key id="key_fullscreen" keycode="VK_F6" command="cmd_fullscreen"/>
     <key id="key_zoomin2" keycode="VK_F7" command="cmd_zoomin"/>
     <key id="key_zoomout2" keycode="VK_F8" command="cmd_zoomout"/>
 #else
     <key id="key_quit" keycode="VK_F4" command="cmd_quit"/>
     <key id="key_zoomin2" keycode="VK_F1" command="cmd_zoomin"/>
     <key id="key_zoomout2" keycode="VK_F2" command="cmd_zoomout"/>
 #endif