diff --git a/common/content/buffer.js b/common/content/buffer.js index 05223fe4..df6e2329 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -551,7 +551,7 @@ var Buffer = Module("buffer", { * @returns {boolean} */ focusAllowed: function (elem) { - if (elem instanceof Window && !Editor.getEditor(window)) + if (elem instanceof Window && !Editor.getEditor(elem)) return true; let doc = elem.ownerDocument || elem.document || elem; return !options["strictfocus"] || doc.dactylFocusAllowed; diff --git a/common/content/dactyl.js b/common/content/dactyl.js index a24ae25b..50339829 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -482,6 +482,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { let win = document.commandDispatcher.focusedWindow; let elem = config.mainWidget || content; + // TODO: make more generic try { if (this.has("mail") && !config.isComposeWindow) { diff --git a/common/content/events.js b/common/content/events.js index 130b9aa1..bc2b1e63 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -960,32 +960,31 @@ var Events = Module("events", { // the main window does not restore focus and we lose key // input. services.focus.clearFocus(window); - document.commandDispatcher.focusedWindow = content; + document.commandDispatcher.focusedWindow = Editor.getEditor(content) ? window : content; } }, // TODO: Merge with onFocusChange focus: function onFocus(event) { let elem = event.originalTarget; - if (elem instanceof Element) { - let win = elem.ownerDocument.defaultView; - if (event.target instanceof Ci.nsIDOMXULTextBoxElement) - for (let e = elem; e instanceof Element; e = e.parentNode) - if (util.computedStyle(e).visibility !== "visible" || - e.boxObject && e.boxObject.height === 0) { - elem.blur(); - break; - } - - if (events.isContentNode(elem) && !buffer.focusAllowed(elem) - && !(services.focus.getLastFocusMethod(win) & 0x7000) - && isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, Window])) { - if (elem.frameElement) - dactyl.focusContent(true); - else if (!(elem instanceof Window) || Editor.getEditor(elem)) + if (event.target instanceof Ci.nsIDOMXULTextBoxElement) + for (let e = elem; e instanceof Element; e = e.parentNode) + if (util.computedStyle(e).visibility !== "visible" || + e.boxObject && e.boxObject.height === 0) { elem.blur(); - } + break; + } + + let win = (elem.ownerDocument || elem).defaultView || elem; + + if (events.isContentNode(elem) && !buffer.focusAllowed(elem) + && !(services.focus.getLastFocusMethod(win) & 0x7000) + && isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, Window])) { + if (elem.frameElement) + dactyl.focusContent(true); + else if (!(elem instanceof Window) || Editor.getEditor(elem)) + dactyl.focus(window); } },