Bug 832984 - Ctrl + Shift + K shortcut for the Web Console stopped working (sometimes). r=jwalker, a=lsblakk
authorPaul Rouget <paul@mozilla.com>
Tue, 22 Jan 2013 20:10:21 +0200
changeset 127333 ca21e77bb5e7cec1b0c4c48c0ba41a0cf6a15e09
parent 127332 a0a5f778473ad5fe98cf7f2d4c3449d73325b098
child 127334 a83f24162110fb15c816416353685c42ecb8d044
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker, lsblakk
bugs832984
milestone20.0a2
Bug 832984 - Ctrl + Shift + K shortcut for the Web Console stopped working (sometimes). r=jwalker, a=lsblakk
browser/devtools/framework/gDevTools.jsm
--- a/browser/devtools/framework/gDevTools.jsm
+++ b/browser/devtools/framework/gDevTools.jsm
@@ -327,16 +327,38 @@ let gDevToolsBrowser = {
     gDevToolsBrowser._addAllToolsToMenu(win.document);
 
     let tabContainer = win.document.getElementById("tabbrowser-tabs")
     tabContainer.addEventListener("TabSelect",
                                   gDevToolsBrowser._updateMenuCheckbox, false);
   },
 
   /**
+   * Add a <key> to <keyset id="devtoolsKeyset">.
+   * Appending a <key> element is not always enough. The <keyset> needs
+   * to be detached and reattached to make sure the <key> is taken into
+   * account (see bug 832984).
+   *
+   * @param {XULDocument} doc
+   *        The document to which keys are to be added
+   * @param {XULElement} or {DocumentFragment} keys
+   *        Keys to add
+   */
+  attachKeybindingsToBrowser: function DT_attachKeybindingsToBrowser(doc, keys) {
+    let devtoolsKeyset = doc.getElementById("devtoolsKeyset");
+    if (!devtoolsKeyset) {
+      devtoolsKeyset = doc.createElement("keyset");
+      devtoolsKeyset.setAttribute("id", "devtoolsKeyset");
+    }
+    devtoolsKeyset.appendChild(keys);
+    let mainKeyset = doc.getElementById("mainKeyset");
+    mainKeyset.parentNode.insertBefore(devtoolsKeyset, mainKeyset);
+  },
+
+  /**
    * Add the menuitem for a tool to all open browser windows.
    *
    * @param {object} toolDefinition
    *        properties of the tool to add
    */
   _addToolToWindows: function DT_addToolToWindows(toolDefinition) {
     // We need to insert the new tool in the right place, which means knowing
     // the tool that comes before the tool that we're trying to add
@@ -351,17 +373,17 @@ let gDevToolsBrowser = {
 
     for (let win of gDevToolsBrowser._trackedBrowserWindows) {
       let doc = win.document;
       let elements = gDevToolsBrowser._createToolMenuElements(toolDefinition, doc);
 
       doc.getElementById("mainCommandSet").appendChild(elements.cmd);
 
       if (elements.key) {
-        doc.getElementById("mainKeyset").appendChild(elements.key);
+        this.attachKeybindingsToBrowser(doc, elements.keys);
       }
 
       doc.getElementById("mainBroadcasterSet").appendChild(elements.bc);
 
       let amp = doc.getElementById("appmenu_webDeveloper_popup");
       if (amp) {
         let ref = (prevDef != null) ?
             doc.getElementById("appmenuitem_" + prevDef.id).nextSibling :
@@ -405,18 +427,17 @@ let gDevToolsBrowser = {
       fragBroadcasters.appendChild(elements.bc);
       fragAppMenuItems.appendChild(elements.appmenuitem);
       fragMenuItems.appendChild(elements.menuitem);
     }
 
     let mcs = doc.getElementById("mainCommandSet");
     mcs.appendChild(fragCommands);
 
-    let mks = doc.getElementById("mainKeyset");
-    mks.appendChild(fragKeys);
+    this.attachKeybindingsToBrowser(doc, fragKeys);
 
     let mbs = doc.getElementById("mainBroadcasterSet");
     mbs.appendChild(fragBroadcasters);
 
     let amp = doc.getElementById("appmenu_webDeveloper_popup");
     if (amp) {
       let amps = doc.getElementById("appmenu_devtools_separator");
       amp.insertBefore(fragAppMenuItems, amps);