From bf881b0292e2f87860df5d7465c6f9492566b540 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Mon, 27 Aug 2007 14:26:43 +0000 Subject: [PATCH] add menu mode --- chrome/content/vimperator/events.js | 49 +++++++++++++++++++++++++ chrome/content/vimperator/vimperator.js | 4 +- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/chrome/content/vimperator/events.js b/chrome/content/vimperator/events.js index e4fd58d8..cf81346b 100644 --- a/chrome/content/vimperator/events.js +++ b/chrome/content/vimperator/events.js @@ -72,6 +72,47 @@ function Events() //{{{ vimperator.setMode(); // trick to reshow the mode in the command line }, null); + // + // track if a popup is open or the menubar is active + // + + var popup_count = 0; + var active_menubar = false; + + function enterPopupMode() + { + popup_count++; + vimperator.log("Open popup window count: " + popup_count, 9); + vimperator.addMode(null, vimperator.modes.MENU); + } + + function exitPopupMode() + { + popup_count--; + vimperator.log("Open popup window count: " + popup_count, 9); + if (popup_count == 0) + vimperator.removeMode(null, vimperator.modes.MENU); + } + + function enterMenuMode() + { + active_menubar = true; + vimperator.log("Menubar is active", 9); + vimperator.addMode(null, vimperator.modes.MENU) + } + + function exitMenuMode() + { + active_menubar = false; + vimperator.log("Menubar is inactive", 9); + vimperator.removeMode(null, vimperator.modes.MENU); + } + + window.addEventListener("popupshown", enterPopupMode, true); + window.addEventListener("popuphidden", exitPopupMode, true); + window.addEventListener("DOMMenuBarActive", enterMenuMode, true); + window.addEventListener("DOMMenuBarInactive", exitMenuMode, true); + window.document.addEventListener("DOMTitleChanged", function(event) { //alert("titlechanged"); @@ -209,6 +250,11 @@ function Events() //{{{ window.dump("TODO: remove all eventlisteners"); getBrowser().removeProgressListener(this.progressListener); + + window.removeEventListener("popupshowing", enterPopupMode(), true); + window.removeEventListener("popuphidden", exitPopupMode(), true); + window.removeEventListener("DOMMenuBarActive", enterMenuMode(), true); + window.removeEventListener("DOMMenuBarInactive", exitMenuMode(), true); } // This method pushes keys into the event queue from vimperator @@ -356,12 +402,15 @@ function Events() //{{{ // if (event.target.id == "main-window") // alert("focusContent();"); + if (vimperator.hasMode(vimperator.modes.MENU)) + return false; // XXX: ugly hack for now pass certain keys to firefox as they are without beeping // also fixes key navigation in menus, etc. if (key == "" || key == "" || key == "" || key == "" || key == "") return false; + // XXX: for now only, later: input mappings if form element focused if (isFormElemFocused()) { diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js index d0e6019a..16d35791 100644 --- a/chrome/content/vimperator/vimperator.js +++ b/chrome/content/vimperator/vimperator.js @@ -49,7 +49,8 @@ const vimperator = (function() //{{{ ESCAPE_ALL_KEYS: 1 << 15, QUICK_HINT: 1 << 16, EXTENDED_HINT: 1 << 17, - ALWAYS_HINT: 1 << 18 + ALWAYS_HINT: 1 << 18, + MENU: 1 << 19 // a popupmenu is active } var mode_messages = {}; @@ -63,6 +64,7 @@ const vimperator = (function() //{{{ mode_messages[modes.QUICK_HINT] = "quick"; mode_messages[modes.EXTENDED_HINT] = "extended"; mode_messages[modes.ALWAYS_HINT] = "always"; + mode_messages[modes.MENU] = "menu"; // TODO: desirable? var mode = modes.NORMAL; var extended_mode = modes.NONE;