diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js index 8bc78c5480d..a7fd4bd03a1 100644 --- a/browser/base/content/browser-places.js +++ b/browser/base/content/browser-places.js @@ -53,12 +53,48 @@ var PlacesCommandHook = { return document.getElementById("editBookmarkPanel"); }, + // list of command elements (by id) to disable when the panel is opened + _blockedCommands: ["cmd_close", "cmd_closeWindow"], + + _blockCommands: function PCH__blockCommands() { + for each(var key in this._blockedCommands) { + var elt = document.getElementById(key); + if (elt.getAttribute("disabled") == "true") + elt.setAttribute("wasDisabled", "true"); + else { + elt.setAttribute("wasDisabled", "false"); + elt.setAttribute("disabled", "true"); + } + } + }, + + _restoreCommandsState: function PCH__restoreCommandsState() { + for each(var key in this._blockedCommands) { + var elt = document.getElementById(key); + if (elt.getAttribute("wasDisabled") != "true") + elt.removeAttribute("disabled"); + elt.removeAttribute("wasDisabled"); + } + }, + // nsIDOMEventListener handleEvent: function PCH_handleEvent(aEvent) { - if (aEvent.originalTarget != this.panel) - return; - - gEditItemOverlay.uninitPanel(true); + switch (aEvent.type) { + case "popuphiding": + if (aEvent.originalTarget == this.panel) { + gEditItemOverlay.uninitPanel(true); + this._restoreCommandsState(); + } + break; + case "keypress": + if (aEvent.keyCode == KeyEvent.DOM_VK_ESCAPE || + aEvent.keyCode == KeyEvent.DOM_VK_RETURN) { + // focus the content area and hide the panel + window.content.focus(); + this.panel.hidePopup(); + } + break; + } }, _overlayLoaded: false, @@ -98,10 +134,17 @@ var PlacesCommandHook = { _doShowEditBookmarkPanel: function PCH__doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition) { + this.panel.addEventListener("keypress", this, true); + this._blockCommands(); // un-done in the popuphiding handler this.panel.openPopup(aAnchorElement, aPosition, -1, -1); gEditItemOverlay.initPanel(aItemId, { hiddenRows: ["description", "location"] }); + setTimeout(function() { + var namePicker = document.getElementById("editBMPanel_namePicker"); + namePicker.focus(); + namePicker.editor.selectAll(); + }, 0); }, /**