mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-04-20 06:03:31 +02:00
Muck with event listener registration.
--HG-- branch : key-processing
This commit is contained in:
@@ -112,7 +112,7 @@ var ProcessorStack = Class("ProcessorStack", {
|
|||||||
events.dispatch(event.originalTarget, evt, { skipmap: true, isMacro: true });
|
events.dispatch(event.originalTarget, evt, { skipmap: true, isMacro: true });
|
||||||
}
|
}
|
||||||
else if (i > 0)
|
else if (i > 0)
|
||||||
events.onKeyPress(event);
|
events.events.keypress.call(events, event);
|
||||||
});
|
});
|
||||||
return this.processors.length == 0;
|
return this.processors.length == 0;
|
||||||
}
|
}
|
||||||
@@ -299,17 +299,8 @@ var Events = Module("events", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._activeMenubar = false;
|
this._activeMenubar = false;
|
||||||
this.addSessionListener(window, "DOMMenuBarActive", this.onDOMMenuBarActive, true);
|
for (let [event, callback] in Iterator(this.events))
|
||||||
this.addSessionListener(window, "DOMMenuBarInactive", this.onDOMMenuBarInactive, true);
|
this.addSessionListener(window, event, callback, true);
|
||||||
this.addSessionListener(window, "blur", this.onBlur, true);
|
|
||||||
this.addSessionListener(window, "focus", this.onFocus, true);
|
|
||||||
this.addSessionListener(window, "keydown", this.onKeyUpOrDown, true);
|
|
||||||
this.addSessionListener(window, "keypress", this.onKeyPress, true);
|
|
||||||
this.addSessionListener(window, "keyup", this.onKeyUpOrDown, true);
|
|
||||||
this.addSessionListener(window, "mousedown", this.onMouseDown, true);
|
|
||||||
this.addSessionListener(window, "popuphidden", this.onPopupHidden, true);
|
|
||||||
this.addSessionListener(window, "popupshown", this.onPopupShown, true);
|
|
||||||
this.addSessionListener(window, "resize", this.onResize, true);
|
|
||||||
|
|
||||||
dactyl.registerObserver("modeChange", function () {
|
dactyl.registerObserver("modeChange", function () {
|
||||||
delete self.processor;
|
delete self.processor;
|
||||||
@@ -507,7 +498,7 @@ var Events = Module("events", {
|
|||||||
if (!evt_obj.dactylString && !evt_obj.dactylShift && !mode)
|
if (!evt_obj.dactylString && !evt_obj.dactylShift && !mode)
|
||||||
events.dispatch(dactyl.focusedElement || buffer.focusedFrame, event, evt);
|
events.dispatch(dactyl.focusedElement || buffer.focusedFrame, event, evt);
|
||||||
else
|
else
|
||||||
events.onKeyPress(event);
|
events.events.keypress.call(events, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.feedingKeys)
|
if (!this.feedingKeys)
|
||||||
@@ -908,16 +899,6 @@ var Events = Module("events", {
|
|||||||
return buffer.loaded;
|
return buffer.loaded;
|
||||||
},
|
},
|
||||||
|
|
||||||
onDOMMenuBarActive: function () {
|
|
||||||
this._activeMenubar = true;
|
|
||||||
modes.add(modes.MENU);
|
|
||||||
},
|
|
||||||
|
|
||||||
onDOMMenuBarInactive: function () {
|
|
||||||
this._activeMenubar = false;
|
|
||||||
modes.remove(modes.MENU);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the currently focused element is visible and blurs
|
* Ensures that the currently focused element is visible and blurs
|
||||||
* it if it's not.
|
* it if it's not.
|
||||||
@@ -934,7 +915,18 @@ var Events = Module("events", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onBlur: function onFocus(event) {
|
events: {
|
||||||
|
DOMMenuBarActive: function () {
|
||||||
|
this._activeMenubar = true;
|
||||||
|
modes.add(modes.MENU);
|
||||||
|
},
|
||||||
|
|
||||||
|
DOMMenuBarInactive: function () {
|
||||||
|
this._activeMenubar = false;
|
||||||
|
modes.remove(modes.MENU);
|
||||||
|
},
|
||||||
|
|
||||||
|
blur: function onBlur(event) {
|
||||||
if (event.originalTarget instanceof Window && services.focus.activeWindow == null) {
|
if (event.originalTarget instanceof Window && services.focus.activeWindow == null) {
|
||||||
// Deals with circumstances where, after the main window
|
// Deals with circumstances where, after the main window
|
||||||
// blurs while a collapsed frame has focus, re-activating
|
// blurs while a collapsed frame has focus, re-activating
|
||||||
@@ -946,7 +938,7 @@ var Events = Module("events", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// TODO: Merge with onFocusChange
|
// TODO: Merge with onFocusChange
|
||||||
onFocus: function onFocus(event) {
|
focus: function onFocus(event) {
|
||||||
let elem = event.originalTarget;
|
let elem = event.originalTarget;
|
||||||
if (elem instanceof Element) {
|
if (elem instanceof Element) {
|
||||||
let win = elem.ownerDocument.defaultView;
|
let win = elem.ownerDocument.defaultView;
|
||||||
@@ -994,84 +986,10 @@ var Events = Module("events", {
|
|||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// argument "event" is deliberately not used, as i don't seem to have
|
|
||||||
// access to the real focus target
|
|
||||||
// Huh? --djk
|
|
||||||
onFocusChange: function onFocusChange(event) {
|
|
||||||
// command line has its own focus change handler
|
|
||||||
if (modes.main == modes.COMMAND_LINE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
function hasHTMLDocument(win) win && win.document && win.document instanceof HTMLDocument
|
|
||||||
|
|
||||||
let win = window.document.commandDispatcher.focusedWindow;
|
|
||||||
let elem = window.document.commandDispatcher.focusedElement;
|
|
||||||
|
|
||||||
if (elem == null && Editor.getEditor(win))
|
|
||||||
elem = win;
|
|
||||||
|
|
||||||
if (win && win.top == content && dactyl.has("tabs"))
|
|
||||||
buffer.focusedFrame = win;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (elem && elem.readOnly)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (isinstance(elem, [HTMLEmbedElement, HTMLEmbedElement])) {
|
|
||||||
modes.push(modes.EMBED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Events.isInputElement(elem)) {
|
|
||||||
if (!(modes.main & (modes.INSERT | modes.TEXT_EDIT | modes.VISUAL)))
|
|
||||||
modes.push(modes.INSERT);
|
|
||||||
|
|
||||||
if (hasHTMLDocument(win))
|
|
||||||
buffer.lastInputField = elem;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (elem instanceof HTMLTextAreaElement || (elem && util.computedStyle(elem).MozUserModify == "read-write")
|
|
||||||
|| elem == null && win && Editor.getEditor(win)) {
|
|
||||||
|
|
||||||
if (modes.main == modes.VISUAL && elem.selectionEnd == elem.selectionStart)
|
|
||||||
modes.pop();
|
|
||||||
|
|
||||||
if (!(modes.main & (modes.INSERT | modes.TEXT_EDIT | modes.VISUAL)))
|
|
||||||
if (options["insertmode"])
|
|
||||||
modes.push(modes.INSERT);
|
|
||||||
else {
|
|
||||||
modes.push(modes.TEXT_EDIT);
|
|
||||||
if (elem.selectionEnd - elem.selectionStart > 0)
|
|
||||||
modes.push(modes.VISUAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasHTMLDocument(win))
|
|
||||||
buffer.lastInputField = elem;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.focusChange) {
|
|
||||||
config.focusChange(win);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let urlbar = document.getElementById("urlbar");
|
|
||||||
if (elem == null && urlbar && urlbar.inputField == this._lastFocus)
|
|
||||||
util.threadYield(true);
|
|
||||||
|
|
||||||
while (modes.main.ownsFocus)
|
|
||||||
modes.pop(null, { fromFocus: true });
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
this._lastFocus = elem;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// this keypress handler gets always called first, even if e.g.
|
// this keypress handler gets always called first, even if e.g.
|
||||||
// the command-line has focus
|
// the command-line has focus
|
||||||
// TODO: ...help me...please...
|
// TODO: ...help me...please...
|
||||||
onKeyPress: function onKeyPress(event) {
|
keypress: function onKeyPress(event) {
|
||||||
event.dactylDefaultPrevented = event.getPreventDefault();
|
event.dactylDefaultPrevented = event.getPreventDefault();
|
||||||
|
|
||||||
let duringFeed = this.duringFeed || [];
|
let duringFeed = this.duringFeed || [];
|
||||||
@@ -1184,7 +1102,7 @@ var Events = Module("events", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onKeyUpOrDown: function onKeyUpOrDown(event) {
|
keyup: function onKeyUp(event) {
|
||||||
// Prevent certain sites from transferring focus to an input box
|
// Prevent certain sites from transferring focus to an input box
|
||||||
// before we get a chance to process our key bindings on the
|
// before we get a chance to process our key bindings on the
|
||||||
// "keypress" event.
|
// "keypress" event.
|
||||||
@@ -1199,8 +1117,11 @@ var Events = Module("events", {
|
|||||||
if (!Events.isInputElement(dactyl.focusedElement))
|
if (!Events.isInputElement(dactyl.focusedElement))
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
},
|
},
|
||||||
|
keydown: function onKeyDown(event) {
|
||||||
|
this.events.keyup.call(this, event);
|
||||||
|
},
|
||||||
|
|
||||||
onMouseDown: function onMouseDown(event) {
|
mousedown: function onMouseDown(event) {
|
||||||
let elem = event.target;
|
let elem = event.target;
|
||||||
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
|
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
|
||||||
|
|
||||||
@@ -1208,24 +1129,99 @@ var Events = Module("events", {
|
|||||||
win.document.dactylFocusAllowed = true;
|
win.document.dactylFocusAllowed = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
onPopupShown: function onPopupShown(event) {
|
popupshown: function onPopupShown(event) {
|
||||||
if (event.originalTarget.localName !== "tooltip" && event.originalTarget.id !== "dactyl-visualbell")
|
if (event.originalTarget.localName !== "tooltip" && event.originalTarget.id !== "dactyl-visualbell")
|
||||||
modes.add(modes.MENU);
|
modes.add(modes.MENU);
|
||||||
},
|
},
|
||||||
|
|
||||||
onPopupHidden: function onPopupHidden() {
|
popuphidden: function onPopupHidden() {
|
||||||
// gContextMenu is set to NULL, when a context menu is closed
|
// gContextMenu is set to NULL, when a context menu is closed
|
||||||
if (window.gContextMenu == null && !this._activeMenubar)
|
if (window.gContextMenu == null && !this._activeMenubar)
|
||||||
modes.remove(modes.MENU);
|
modes.remove(modes.MENU);
|
||||||
},
|
},
|
||||||
|
|
||||||
onResize: function onResize(event) {
|
resize: function onResize(event) {
|
||||||
if (window.fullScreen != this._fullscreen) {
|
if (window.fullScreen != this._fullscreen) {
|
||||||
statusline.statusBar.removeAttribute("moz-collapsed");
|
statusline.statusBar.removeAttribute("moz-collapsed");
|
||||||
this._fullscreen = window.fullScreen;
|
this._fullscreen = window.fullScreen;
|
||||||
dactyl.triggerObserver("fullscreen", this._fullscreen);
|
dactyl.triggerObserver("fullscreen", this._fullscreen);
|
||||||
autocommands.trigger("Fullscreen", { url: this._fullscreen ? "on" : "off", state: this._fullscreen });
|
autocommands.trigger("Fullscreen", { url: this._fullscreen ? "on" : "off", state: this._fullscreen });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// argument "event" is deliberately not used, as i don't seem to have
|
||||||
|
// access to the real focus target
|
||||||
|
// Huh? --djk
|
||||||
|
onFocusChange: function onFocusChange(event) {
|
||||||
|
// command line has its own focus change handler
|
||||||
|
if (modes.main == modes.COMMAND_LINE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
function hasHTMLDocument(win) win && win.document && win.document instanceof HTMLDocument
|
||||||
|
|
||||||
|
let win = window.document.commandDispatcher.focusedWindow;
|
||||||
|
let elem = window.document.commandDispatcher.focusedElement;
|
||||||
|
|
||||||
|
if (elem == null && Editor.getEditor(win))
|
||||||
|
elem = win;
|
||||||
|
|
||||||
|
if (win && win.top == content && dactyl.has("tabs"))
|
||||||
|
buffer.focusedFrame = win;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (elem && elem.readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (isinstance(elem, [HTMLEmbedElement, HTMLEmbedElement])) {
|
||||||
|
modes.push(modes.EMBED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Events.isInputElement(elem)) {
|
||||||
|
if (!(modes.main & (modes.INSERT | modes.TEXT_EDIT | modes.VISUAL)))
|
||||||
|
modes.push(modes.INSERT);
|
||||||
|
|
||||||
|
if (hasHTMLDocument(win))
|
||||||
|
buffer.lastInputField = elem;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elem instanceof HTMLTextAreaElement || (elem && util.computedStyle(elem).MozUserModify == "read-write")
|
||||||
|
|| elem == null && win && Editor.getEditor(win)) {
|
||||||
|
|
||||||
|
if (modes.main == modes.VISUAL && elem.selectionEnd == elem.selectionStart)
|
||||||
|
modes.pop();
|
||||||
|
|
||||||
|
if (!(modes.main & (modes.INSERT | modes.TEXT_EDIT | modes.VISUAL)))
|
||||||
|
if (options["insertmode"])
|
||||||
|
modes.push(modes.INSERT);
|
||||||
|
else {
|
||||||
|
modes.push(modes.TEXT_EDIT);
|
||||||
|
if (elem.selectionEnd - elem.selectionStart > 0)
|
||||||
|
modes.push(modes.VISUAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasHTMLDocument(win))
|
||||||
|
buffer.lastInputField = elem;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.focusChange) {
|
||||||
|
config.focusChange(win);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let urlbar = document.getElementById("urlbar");
|
||||||
|
if (elem == null && urlbar && urlbar.inputField == this._lastFocus)
|
||||||
|
util.threadYield(true);
|
||||||
|
|
||||||
|
while (modes.main.ownsFocus)
|
||||||
|
modes.pop(null, { fromFocus: true });
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
this._lastFocus = elem;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onSelectionChange: function onSelectionChange(event) {
|
onSelectionChange: function onSelectionChange(event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user