mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 18:07:58 +01:00
Import the bulk of a focus management patch near the top of my queue.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,22 +424,25 @@ 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*.
|
||||
*
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user