1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 23:32:26 +01:00

More reliable Menu mode handling. Closes issue #335.

This commit is contained in:
Kris Maglione
2011-09-10 14:05:21 -04:00
parent 4d9a4b02a8
commit 525a575a72
3 changed files with 42 additions and 12 deletions

View File

@@ -493,6 +493,29 @@ var Events = Module("events", {
this._activeMenubar = false;
this.listen(window, this, "events", true);
this.popups = {
active: [],
update: function update(elem) {
if (elem) {
if (elem instanceof Ci.nsIAutoCompletePopup
|| elem.localName == "tooltip"
|| !elem.popupBoxObject)
return;
if (!~this.active.indexOf(elem))
this.active.push(elem);
}
this.active = this.active.filter(function (e) e.popupBoxObject.popupState != "closed");
if (!this.active.length && !events._activeMenubar)
modes.remove(modes.MENU, true);
else if (modes.main != modes.MENU)
modes.push(modes.MENU);
}
};
},
signals: {
@@ -1118,13 +1141,13 @@ var Events = Module("events", {
},
events: {
DOMMenuBarActive: function () {
DOMMenuBarActive: function onDOMMenuBarActive() {
this._activeMenubar = true;
if (modes.main != modes.MENU)
modes.push(modes.MENU);
},
DOMMenuBarInactive: function () {
DOMMenuBarInactive: function onDOMMenuBarInactive() {
this._activeMenubar = false;
modes.remove(modes.MENU, true);
},
@@ -1376,24 +1399,27 @@ var Events = Module("events", {
}
},
popupshowing: function onPopupShowing(event) {
this.popups.update(event.originalTarget);
},
popupshown: function onPopupShown(event) {
let elem = event.originalTarget;
this.popups.update(elem);
if (elem instanceof Ci.nsIAutoCompletePopup) {
if (modes.main != modes.AUTOCOMPLETE)
modes.push(modes.AUTOCOMPLETE);
}
else if (elem.localName !== "tooltip")
if (Events.isHidden(elem)) {
else if (elem.localName !== "tooltip") {
if (Events.isHidden(elem))
if (elem.hidePopup && Events.isHidden(elem.parentNode))
elem.hidePopup();
}
else if (modes.main != modes.MENU)
modes.push(modes.MENU);
},
popuphidden: function onPopupHidden(event) {
if (window.gContextMenu == null && !this._activeMenubar)
modes.remove(modes.MENU, true);
this.popups.update();
modes.remove(modes.AUTOCOMPLETE);
},

View File

@@ -608,7 +608,11 @@ var Modes = Module("modes", {
mappings.add([modes.MENU], ["<Esc>"],
"Close the current popup",
function () { return Events.PASS_THROUGH; });
function () {
if (modes.popup.active.length)
return Events.PASS_THROUGH;
modes.pop();
});
mappings.add([modes.MENU], ["<C-[>"],
"Close the current popup",

View File

@@ -821,8 +821,8 @@ var DOM = Class("DOM", {
};
opts = opts || {};
var t = this.constructor.types[type];
var evt = doc.createEvent((t || "HTML") + "Events");
var t = this.constructor.types[type] || "";
var evt = doc.createEvent(t + "Events");
let defaults = DEFAULTS[t || "HTML"];
update(defaults, this.constructor.defaults[type]);