summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/content/buffer.js6
-rw-r--r--common/content/commandline.js14
-rw-r--r--common/content/dactyl.js34
-rw-r--r--common/content/editor.js15
-rw-r--r--common/content/events.js38
-rw-r--r--common/content/finder.js2
-rw-r--r--common/content/hints.js2
-rw-r--r--pentadactyl/content/config.js18
8 files changed, 81 insertions, 48 deletions
diff --git a/common/content/buffer.js b/common/content/buffer.js
index 781c6a14..537fc0b7 100644
--- a/common/content/buffer.js
+++ b/common/content/buffer.js
@@ -296,7 +296,7 @@ const Buffer = Module("buffer", {
// Workaround for bugs 591425 and 606877, dactyl bug #81
let collapse = uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
if (collapse)
- config.focus.setFocus(window.documentElement);
+ dactyl.focus(document.documentElement);
config.browser.mCurrentBrowser.collapsed = collapse;
uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
@@ -543,7 +543,7 @@ const Buffer = Module("buffer", {
buffer.lastInputField = elem;
}
else {
- elem.focus();
+ dactyl.focus(elem);
if (elem instanceof Window) {
let sel = elem.getSelection();
if (sel && !sel.rangeCount)
@@ -873,7 +873,7 @@ const Buffer = Module("buffer", {
next = Math.constrain(next, 0, frames.length - 1);
// focus next frame and scroll into view
- frames[next].focus();
+ dactyl.focus(frames[next]);
if (frames[next] != content)
frames[next].frameElement.scrollIntoView(false);
diff --git a/common/content/commandline.js b/common/content/commandline.js
index 77161ab0..74cd9bbe 100644
--- a/common/content/commandline.js
+++ b/common/content/commandline.js
@@ -42,7 +42,7 @@ const CommandWidgets = Class("CommandWidgets", {
getElement: CommandWidgets.getEditor,
getGroup: function (value) this.activeGroup.commandline,
onChange: function (elem) {
- if (elem.inputField != dactyl.focus) {
+ if (elem.inputField != dactyl.focusedElement) {
try {
elem.selectionStart = elem.value.length;
elem.selectionEnd = elem.value.length;
@@ -50,9 +50,9 @@ const CommandWidgets = Class("CommandWidgets", {
catch (e) {}
}
if (!elem.collapsed)
- elem.focus();
+ dactyl.focus(elem);
},
- onVisibility: function (elem, visible) { visible && elem.focus(); }
+ onVisibility: function (elem, visible) { visible && dactyl.focus(elem)}
});
this.addElement({
name: "prompt",
@@ -627,7 +627,7 @@ const CommandLine = Module("commandline", {
else
win.scrollTo(0, doc.height);
- win.focus();
+ dactyl.focus(win);
commandline.updateMorePrompt();
},
@@ -775,7 +775,7 @@ const CommandLine = Module("commandline", {
this.widgets.multilineInput.value = "";
this._autosizeMultilineInputWidget();
- this.timeout(function () { this.widgets.multilineInput.focus(); }, 10);
+ this.timeout(function () { dactyl.focus(this.widgets.multilineInput); }, 10);
},
onContext: function onContext(event) {
@@ -807,7 +807,7 @@ const CommandLine = Module("commandline", {
// prevent losing focus, there should be a better way, but it just didn't work otherwise
this.timeout(function () {
if (this.commandVisible && event.originalTarget == this.widgets.active.command.inputField)
- this.widgets.active.command.inputField.focus();
+ dactyl.focus(this.widgets.active.command.inputField);
}, 0);
}
else if (event.type == "focus") {
@@ -908,7 +908,7 @@ const CommandLine = Module("commandline", {
}
else if (event.type == "blur") {
if (modes.extended & modes.INPUT_MULTILINE)
- this.timeout(function () { this.widgets.multilineInput.inputField.focus(); }, 0);
+ this.timeout(function () { dactyl.focus(this.widgets.multilineInput.inputField); }, 0);
}
else if (event.type == "input")
this._autosizeMultilineInputWidget();
diff --git a/common/content/dactyl.js b/common/content/dactyl.js
index 938536fd..c5273ffa 100644
--- a/common/content/dactyl.js
+++ b/common/content/dactyl.js
@@ -87,9 +87,6 @@ const Dactyl = Module("dactyl", {
get menuItems() Dactyl.getMenuItems(),
- /** @property {Element} The currently focused element. */
- get focus() document.commandDispatcher.focusedElement,
-
// Global constants
CURRENT_TAB: [],
NEW_TAB: [],
@@ -385,6 +382,20 @@ const Dactyl = Module("dactyl", {
return res;
},
+ focus: function (elem, flags) {
+ try {
+ if (elem instanceof Document)
+ elem = elem.defaultView;
+ if (elem instanceof Window)
+ services.focus.clearFocus(elem);
+ else
+ services.focus.setFocus(elem, flags || Ci.nsIFocusManager.FLAG_BYMOUSE|Ci.nsIFocusManager.FLAG_BYMOVEFOCUS);
+ } catch (e) {
+ util.dump(elem);
+ util.reportError(e);
+ }
+ },
+
/**
* Focuses the content window.
*
@@ -413,21 +424,24 @@ const Dactyl = Module("dactyl", {
}
catch (e) {}
- if (clearFocusedElement)
- if (dactyl.focus)
- dactyl.focus.blur();
- else if (win && Editor.getEditor(win)) {
+ if (clearFocusedElement) {
+ services.focus.clearFocus(window);
+ if (win && Editor.getEditor(win)) {
win.blur();
if (win.frameElement)
win.frameElement.blur();
}
+ }
if (elem instanceof Window && Editor.getEditor(elem))
elem = window;
- if (elem && elem != dactyl.focus)
- elem.focus();
- },
+ if (elem && elem != dactyl.focusedElement)
+ dactyl.focus(elem);
+ },
+
+ /** @property {Element} The currently focused element. */
+ get focusedElement() services.focus.getFocusedElementForWindow(window, true, {}),
/**
* Returns whether this Dactyl extension supports *feature*.
diff --git a/common/content/editor.js b/common/content/editor.js
index c79c89c5..05ea807c 100644
--- a/common/content/editor.js
+++ b/common/content/editor.js
@@ -30,7 +30,7 @@ const Editor = Module("editor", {
return;
}
- let elem = dactyl.focus;
+ let elem = dactyl.focusedElement;
if (elem.setSelectionRange) {
let text = dactyl.clipboardRead(clipboard);
@@ -254,7 +254,7 @@ const Editor = Module("editor", {
if (!options["editor"])
return;
- let textBox = config.isComposeWindow ? null : dactyl.focus;
+ let textBox = config.isComposeWindow ? null : dactyl.focusedElement;
let line, column;
if (!forceEditing && textBox && textBox.type == "password") {
@@ -373,12 +373,12 @@ const Editor = Module("editor", {
}, {
getEditor: function (elem) {
if (arguments.length === 0) {
- dactyl.assert(dactyl.focus);
- return dactyl.focus;
+ dactyl.assert(dactyl.focusedElement);
+ return dactyl.focusedElement;
}
if (!elem)
- elem = dactyl.focus || document.commandDispatcher.focusedWindow;
+ elem = dactyl.focusedElement || document.commandDispatcher.focusedWindow;
dactyl.assert(elem);
if (elem instanceof Element)
@@ -394,7 +394,7 @@ const Editor = Module("editor", {
},
getController: function () {
- let ed = dactyl.focus;
+ let ed = dactyl.focusedElement;
if (!ed || !ed.controllers)
return null;
@@ -597,7 +597,8 @@ const Editor = Module("editor", {
["<Tab>"], "Expand insert mode abbreviation",
function () {
editor.expandAbbreviation(modes.INSERT);
- document.commandDispatcher.advanceFocus();
+ services.focus.moveFocus(window, null, Ci.nsIFocusManager.MOVEFOCUS_FORWARD,
+ Ci.nsIFocusManager.FLAG_BYKEY);
});
mappings.add([modes.INSERT],
diff --git a/common/content/events.js b/common/content/events.js
index c121882e..f1c1e117 100644
--- a/common/content/events.js
+++ b/common/content/events.js
@@ -259,7 +259,7 @@ const Events = Module("events", {
let event = events.create(document.commandDispatcher.focusedWindow.document, type, evt);
if (!evt_obj.dactylString && !evt_obj.dactylShift)
- events.dispatch(dactyl.focus || buffer.focusedFrame, event);
+ events.dispatch(dactyl.focusedElement || buffer.focusedFrame, event);
else
events.onKeyPress(event);
}
@@ -675,10 +675,10 @@ const Events = Module("events", {
* it if it's not.
*/
checkFocus: function () {
- if (dactyl.focus) {
- let rect = dactyl.focus.getBoundingClientRect();
+ if (dactyl.focusedElement) {
+ let rect = dactyl.focusedElement.getBoundingClientRect();
if (!rect.width || !rect.height) {
- dactyl.focus.blur();
+ services.focusManager.clearFocus(window);
// onFocusChange needs to die.
this.onFocusChange();
}
@@ -698,6 +698,30 @@ const Events = Module("events", {
}
},
+ /*
+ onFocus: function onFocus(event) {
+ let elem = event.originalTarget;
+ if (!(elem instanceof Element))
+ return;
+ let win = elem.ownerDocument.defaultView;
+
+ try {
+ util.dump(elem, services.focus.getLastFocusMethod(win) & (0x7000));
+ if (buffer.focusAllowed(win))
+ win.dactylLastFocus = elem;
+ else if (isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement])) {
+ if (win.dactylLastFocus)
+ dactyl.focus(win.dactylLastFocus);
+ else
+ elem.blur();
+ }
+ } catch (e) {
+ util.dump(win, String(elem.ownerDocument), String(elem.ownerDocument && elem.ownerDocument.defaultView));
+ util.reportError(e);
+ }
+ },
+ */
+
// argument "event" is deliberately not used, as i don't seem to have
// access to the real focus target
// Huh? --djk
@@ -829,7 +853,7 @@ const Events = Module("events", {
var main = mode.main;
function shouldPass()
- (!dactyl.focus || Events.isContentNode(dactyl.focus)) &&
+ (!dactyl.focusedElement || Events.isContentNode(dactyl.focusedElement)) &&
options.get("passkeys").has(events.toString(event));
// menus have their own command handlers
@@ -1005,7 +1029,7 @@ const Events = Module("events", {
// "keypress" event.
function shouldPass() // FIXME.
- (!dactyl.focus || Events.isContentNode(dactyl.focus)) &&
+ (!dactyl.focusedElement || Events.isContentNode(dactyl.focusedElement)) &&
options.get("passkeys").has(events.toString(event));
if (modes.main == modes.PASS_THROUGH ||
@@ -1069,7 +1093,7 @@ const Events = Module("events", {
return false;
},
isInputElemFocused: function isInputElemFocused() {
- let elem = dactyl.focus;
+ let elem = dactyl.focusedElement;
return elem instanceof HTMLInputElement && set.has(util.editableInputs, elem.type) ||
isinstance(elem, [HTMLIsIndexElement, HTMLEmbedElement,
HTMLObjectElement, HTMLTextAreaElement]);
diff --git a/common/content/finder.js b/common/content/finder.js
index 1c5f096b..0ed495ec 100644
--- a/common/content/finder.js
+++ b/common/content/finder.js
@@ -340,7 +340,7 @@ const RangeFind = Class("RangeFind", {
var node = util.evaluateXPath(RangeFind.selectNodePath, this.range.document,
this.lastRange.commonAncestorContainer).snapshotItem(0);
if (node) {
- node.focus();
+ dactyl.focus(node);
// Re-highlight collapsed selection
this.selectedRange = this.lastRange;
}
diff --git a/common/content/hints.js b/common/content/hints.js
index fda1fbae..eb47296f 100644
--- a/common/content/hints.js
+++ b/common/content/hints.js
@@ -52,7 +52,7 @@ const Hints = Module("hints", {
this.addMode("?", "Show information for hint", function (elem) buffer.showElementInfo(elem));
this.addMode("s", "Save hint", function (elem) buffer.saveLink(elem, true));
this.addMode("a", "Save hint with prompt", function (elem) buffer.saveLink(elem, false));
- this.addMode("f", "Focus frame", function (elem) elem.ownerDocument.defaultView.focus(), function () ["body"]);
+ this.addMode("f", "Focus frame", function (elem) dactyl.focus(elem.ownerDocument.defaultView));
this.addMode("F", "Focus frame or pseudo-frame", buffer.closure.focusElement, null, isScrollable);
this.addMode("o", "Follow hint", function (elem) buffer.followLink(elem, dactyl.CURRENT_TAB));
this.addMode("t", "Follow hint in a new tab", function (elem) buffer.followLink(elem, dactyl.NEW_TAB));
diff --git a/pentadactyl/content/config.js b/pentadactyl/content/config.js
index 58241b95..e298ffb4 100644
--- a/pentadactyl/content/config.js
+++ b/pentadactyl/content/config.js
@@ -180,25 +180,19 @@ const Config = Module("config", ConfigBase, {
commands.add(["sideb[ar]", "sb[ar]", "sbope[n]"],
"Open the sidebar window",
function (args) {
- let arg = args.literalArg;
function compare(a, b) util.compareIgnoreCase(a, b) == 0
// focus if the requested sidebar is already open
- if (compare(document.getElementById("sidebar-title").value, arg)) {
- document.getElementById("sidebar-box").focus();
- return;
- }
+ if (compare(document.getElementById("sidebar-title").value, args[0]))
+ return dactyl.focus(document.getElementById("sidebar-box"));
let menu = document.getElementById("viewSidebarMenu");
- for (let [, panel] in Iterator(menu.childNodes)) {
- if (compare(panel.label, arg)) {
- panel.doCommand();
- return;
- }
- }
+ for (let [, panel] in Iterator(menu.childNodes))
+ if (compare(panel.label, args[0]))
+ return panel.doCommand();
- dactyl.echoerr("No sidebar " + arg + " found");
+ return dactyl.echoerr("No sidebar " + args[0] + " found");
},
{
argCount: "1",