mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 20:27: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
|
// Workaround for bugs 591425 and 606877, dactyl bug #81
|
||||||
let collapse = uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
|
let collapse = uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
|
||||||
if (collapse)
|
if (collapse)
|
||||||
config.focus.setFocus(window.documentElement);
|
dactyl.focus(document.documentElement);
|
||||||
config.browser.mCurrentBrowser.collapsed = collapse;
|
config.browser.mCurrentBrowser.collapsed = collapse;
|
||||||
uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
|
uri && uri.scheme === "dactyl" && webProgress.isLoadingDocument;
|
||||||
|
|
||||||
@@ -543,7 +543,7 @@ const Buffer = Module("buffer", {
|
|||||||
buffer.lastInputField = elem;
|
buffer.lastInputField = elem;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
elem.focus();
|
dactyl.focus(elem);
|
||||||
if (elem instanceof Window) {
|
if (elem instanceof Window) {
|
||||||
let sel = elem.getSelection();
|
let sel = elem.getSelection();
|
||||||
if (sel && !sel.rangeCount)
|
if (sel && !sel.rangeCount)
|
||||||
@@ -873,7 +873,7 @@ const Buffer = Module("buffer", {
|
|||||||
next = Math.constrain(next, 0, frames.length - 1);
|
next = Math.constrain(next, 0, frames.length - 1);
|
||||||
|
|
||||||
// focus next frame and scroll into view
|
// focus next frame and scroll into view
|
||||||
frames[next].focus();
|
dactyl.focus(frames[next]);
|
||||||
if (frames[next] != content)
|
if (frames[next] != content)
|
||||||
frames[next].frameElement.scrollIntoView(false);
|
frames[next].frameElement.scrollIntoView(false);
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ const CommandWidgets = Class("CommandWidgets", {
|
|||||||
getElement: CommandWidgets.getEditor,
|
getElement: CommandWidgets.getEditor,
|
||||||
getGroup: function (value) this.activeGroup.commandline,
|
getGroup: function (value) this.activeGroup.commandline,
|
||||||
onChange: function (elem) {
|
onChange: function (elem) {
|
||||||
if (elem.inputField != dactyl.focus) {
|
if (elem.inputField != dactyl.focusedElement) {
|
||||||
try {
|
try {
|
||||||
elem.selectionStart = elem.value.length;
|
elem.selectionStart = elem.value.length;
|
||||||
elem.selectionEnd = elem.value.length;
|
elem.selectionEnd = elem.value.length;
|
||||||
@@ -50,9 +50,9 @@ const CommandWidgets = Class("CommandWidgets", {
|
|||||||
catch (e) {}
|
catch (e) {}
|
||||||
}
|
}
|
||||||
if (!elem.collapsed)
|
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({
|
this.addElement({
|
||||||
name: "prompt",
|
name: "prompt",
|
||||||
@@ -627,7 +627,7 @@ const CommandLine = Module("commandline", {
|
|||||||
else
|
else
|
||||||
win.scrollTo(0, doc.height);
|
win.scrollTo(0, doc.height);
|
||||||
|
|
||||||
win.focus();
|
dactyl.focus(win);
|
||||||
|
|
||||||
commandline.updateMorePrompt();
|
commandline.updateMorePrompt();
|
||||||
},
|
},
|
||||||
@@ -775,7 +775,7 @@ const CommandLine = Module("commandline", {
|
|||||||
this.widgets.multilineInput.value = "";
|
this.widgets.multilineInput.value = "";
|
||||||
this._autosizeMultilineInputWidget();
|
this._autosizeMultilineInputWidget();
|
||||||
|
|
||||||
this.timeout(function () { this.widgets.multilineInput.focus(); }, 10);
|
this.timeout(function () { dactyl.focus(this.widgets.multilineInput); }, 10);
|
||||||
},
|
},
|
||||||
|
|
||||||
onContext: function onContext(event) {
|
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
|
// prevent losing focus, there should be a better way, but it just didn't work otherwise
|
||||||
this.timeout(function () {
|
this.timeout(function () {
|
||||||
if (this.commandVisible && event.originalTarget == this.widgets.active.command.inputField)
|
if (this.commandVisible && event.originalTarget == this.widgets.active.command.inputField)
|
||||||
this.widgets.active.command.inputField.focus();
|
dactyl.focus(this.widgets.active.command.inputField);
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
else if (event.type == "focus") {
|
else if (event.type == "focus") {
|
||||||
@@ -908,7 +908,7 @@ const CommandLine = Module("commandline", {
|
|||||||
}
|
}
|
||||||
else if (event.type == "blur") {
|
else if (event.type == "blur") {
|
||||||
if (modes.extended & modes.INPUT_MULTILINE)
|
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")
|
else if (event.type == "input")
|
||||||
this._autosizeMultilineInputWidget();
|
this._autosizeMultilineInputWidget();
|
||||||
|
|||||||
@@ -87,9 +87,6 @@ const Dactyl = Module("dactyl", {
|
|||||||
|
|
||||||
get menuItems() Dactyl.getMenuItems(),
|
get menuItems() Dactyl.getMenuItems(),
|
||||||
|
|
||||||
/** @property {Element} The currently focused element. */
|
|
||||||
get focus() document.commandDispatcher.focusedElement,
|
|
||||||
|
|
||||||
// Global constants
|
// Global constants
|
||||||
CURRENT_TAB: [],
|
CURRENT_TAB: [],
|
||||||
NEW_TAB: [],
|
NEW_TAB: [],
|
||||||
@@ -385,6 +382,20 @@ const Dactyl = Module("dactyl", {
|
|||||||
return res;
|
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.
|
* Focuses the content window.
|
||||||
*
|
*
|
||||||
@@ -413,22 +424,25 @@ const Dactyl = Module("dactyl", {
|
|||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
|
|
||||||
if (clearFocusedElement)
|
if (clearFocusedElement) {
|
||||||
if (dactyl.focus)
|
services.focus.clearFocus(window);
|
||||||
dactyl.focus.blur();
|
if (win && Editor.getEditor(win)) {
|
||||||
else if (win && Editor.getEditor(win)) {
|
|
||||||
win.blur();
|
win.blur();
|
||||||
if (win.frameElement)
|
if (win.frameElement)
|
||||||
win.frameElement.blur();
|
win.frameElement.blur();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (elem instanceof Window && Editor.getEditor(elem))
|
if (elem instanceof Window && Editor.getEditor(elem))
|
||||||
elem = window;
|
elem = window;
|
||||||
|
|
||||||
if (elem && elem != dactyl.focus)
|
if (elem && elem != dactyl.focusedElement)
|
||||||
elem.focus();
|
dactyl.focus(elem);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** @property {Element} The currently focused element. */
|
||||||
|
get focusedElement() services.focus.getFocusedElementForWindow(window, true, {}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this Dactyl extension supports *feature*.
|
* Returns whether this Dactyl extension supports *feature*.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const Editor = Module("editor", {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let elem = dactyl.focus;
|
let elem = dactyl.focusedElement;
|
||||||
|
|
||||||
if (elem.setSelectionRange) {
|
if (elem.setSelectionRange) {
|
||||||
let text = dactyl.clipboardRead(clipboard);
|
let text = dactyl.clipboardRead(clipboard);
|
||||||
@@ -254,7 +254,7 @@ const Editor = Module("editor", {
|
|||||||
if (!options["editor"])
|
if (!options["editor"])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let textBox = config.isComposeWindow ? null : dactyl.focus;
|
let textBox = config.isComposeWindow ? null : dactyl.focusedElement;
|
||||||
let line, column;
|
let line, column;
|
||||||
|
|
||||||
if (!forceEditing && textBox && textBox.type == "password") {
|
if (!forceEditing && textBox && textBox.type == "password") {
|
||||||
@@ -373,12 +373,12 @@ const Editor = Module("editor", {
|
|||||||
}, {
|
}, {
|
||||||
getEditor: function (elem) {
|
getEditor: function (elem) {
|
||||||
if (arguments.length === 0) {
|
if (arguments.length === 0) {
|
||||||
dactyl.assert(dactyl.focus);
|
dactyl.assert(dactyl.focusedElement);
|
||||||
return dactyl.focus;
|
return dactyl.focusedElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!elem)
|
if (!elem)
|
||||||
elem = dactyl.focus || document.commandDispatcher.focusedWindow;
|
elem = dactyl.focusedElement || document.commandDispatcher.focusedWindow;
|
||||||
dactyl.assert(elem);
|
dactyl.assert(elem);
|
||||||
|
|
||||||
if (elem instanceof Element)
|
if (elem instanceof Element)
|
||||||
@@ -394,7 +394,7 @@ const Editor = Module("editor", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getController: function () {
|
getController: function () {
|
||||||
let ed = dactyl.focus;
|
let ed = dactyl.focusedElement;
|
||||||
if (!ed || !ed.controllers)
|
if (!ed || !ed.controllers)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -597,7 +597,8 @@ const Editor = Module("editor", {
|
|||||||
["<Tab>"], "Expand insert mode abbreviation",
|
["<Tab>"], "Expand insert mode abbreviation",
|
||||||
function () {
|
function () {
|
||||||
editor.expandAbbreviation(modes.INSERT);
|
editor.expandAbbreviation(modes.INSERT);
|
||||||
document.commandDispatcher.advanceFocus();
|
services.focus.moveFocus(window, null, Ci.nsIFocusManager.MOVEFOCUS_FORWARD,
|
||||||
|
Ci.nsIFocusManager.FLAG_BYKEY);
|
||||||
});
|
});
|
||||||
|
|
||||||
mappings.add([modes.INSERT],
|
mappings.add([modes.INSERT],
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ const Events = Module("events", {
|
|||||||
|
|
||||||
let event = events.create(document.commandDispatcher.focusedWindow.document, type, evt);
|
let event = events.create(document.commandDispatcher.focusedWindow.document, type, evt);
|
||||||
if (!evt_obj.dactylString && !evt_obj.dactylShift)
|
if (!evt_obj.dactylString && !evt_obj.dactylShift)
|
||||||
events.dispatch(dactyl.focus || buffer.focusedFrame, event);
|
events.dispatch(dactyl.focusedElement || buffer.focusedFrame, event);
|
||||||
else
|
else
|
||||||
events.onKeyPress(event);
|
events.onKeyPress(event);
|
||||||
}
|
}
|
||||||
@@ -675,10 +675,10 @@ const Events = Module("events", {
|
|||||||
* it if it's not.
|
* it if it's not.
|
||||||
*/
|
*/
|
||||||
checkFocus: function () {
|
checkFocus: function () {
|
||||||
if (dactyl.focus) {
|
if (dactyl.focusedElement) {
|
||||||
let rect = dactyl.focus.getBoundingClientRect();
|
let rect = dactyl.focusedElement.getBoundingClientRect();
|
||||||
if (!rect.width || !rect.height) {
|
if (!rect.width || !rect.height) {
|
||||||
dactyl.focus.blur();
|
services.focusManager.clearFocus(window);
|
||||||
// onFocusChange needs to die.
|
// onFocusChange needs to die.
|
||||||
this.onFocusChange();
|
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
|
// argument "event" is deliberately not used, as i don't seem to have
|
||||||
// access to the real focus target
|
// access to the real focus target
|
||||||
// Huh? --djk
|
// Huh? --djk
|
||||||
@@ -829,7 +853,7 @@ const Events = Module("events", {
|
|||||||
var main = mode.main;
|
var main = mode.main;
|
||||||
|
|
||||||
function shouldPass()
|
function shouldPass()
|
||||||
(!dactyl.focus || Events.isContentNode(dactyl.focus)) &&
|
(!dactyl.focusedElement || Events.isContentNode(dactyl.focusedElement)) &&
|
||||||
options.get("passkeys").has(events.toString(event));
|
options.get("passkeys").has(events.toString(event));
|
||||||
|
|
||||||
// menus have their own command handlers
|
// menus have their own command handlers
|
||||||
@@ -1005,7 +1029,7 @@ const Events = Module("events", {
|
|||||||
// "keypress" event.
|
// "keypress" event.
|
||||||
|
|
||||||
function shouldPass() // FIXME.
|
function shouldPass() // FIXME.
|
||||||
(!dactyl.focus || Events.isContentNode(dactyl.focus)) &&
|
(!dactyl.focusedElement || Events.isContentNode(dactyl.focusedElement)) &&
|
||||||
options.get("passkeys").has(events.toString(event));
|
options.get("passkeys").has(events.toString(event));
|
||||||
|
|
||||||
if (modes.main == modes.PASS_THROUGH ||
|
if (modes.main == modes.PASS_THROUGH ||
|
||||||
@@ -1069,7 +1093,7 @@ const Events = Module("events", {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
isInputElemFocused: function isInputElemFocused() {
|
isInputElemFocused: function isInputElemFocused() {
|
||||||
let elem = dactyl.focus;
|
let elem = dactyl.focusedElement;
|
||||||
return elem instanceof HTMLInputElement && set.has(util.editableInputs, elem.type) ||
|
return elem instanceof HTMLInputElement && set.has(util.editableInputs, elem.type) ||
|
||||||
isinstance(elem, [HTMLIsIndexElement, HTMLEmbedElement,
|
isinstance(elem, [HTMLIsIndexElement, HTMLEmbedElement,
|
||||||
HTMLObjectElement, HTMLTextAreaElement]);
|
HTMLObjectElement, HTMLTextAreaElement]);
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ const RangeFind = Class("RangeFind", {
|
|||||||
var node = util.evaluateXPath(RangeFind.selectNodePath, this.range.document,
|
var node = util.evaluateXPath(RangeFind.selectNodePath, this.range.document,
|
||||||
this.lastRange.commonAncestorContainer).snapshotItem(0);
|
this.lastRange.commonAncestorContainer).snapshotItem(0);
|
||||||
if (node) {
|
if (node) {
|
||||||
node.focus();
|
dactyl.focus(node);
|
||||||
// Re-highlight collapsed selection
|
// Re-highlight collapsed selection
|
||||||
this.selectedRange = this.lastRange;
|
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("?", "Show information for hint", function (elem) buffer.showElementInfo(elem));
|
||||||
this.addMode("s", "Save hint", function (elem) buffer.saveLink(elem, true));
|
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("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("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("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));
|
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]"],
|
commands.add(["sideb[ar]", "sb[ar]", "sbope[n]"],
|
||||||
"Open the sidebar window",
|
"Open the sidebar window",
|
||||||
function (args) {
|
function (args) {
|
||||||
let arg = args.literalArg;
|
|
||||||
function compare(a, b) util.compareIgnoreCase(a, b) == 0
|
function compare(a, b) util.compareIgnoreCase(a, b) == 0
|
||||||
|
|
||||||
// focus if the requested sidebar is already open
|
// focus if the requested sidebar is already open
|
||||||
if (compare(document.getElementById("sidebar-title").value, arg)) {
|
if (compare(document.getElementById("sidebar-title").value, args[0]))
|
||||||
document.getElementById("sidebar-box").focus();
|
return dactyl.focus(document.getElementById("sidebar-box"));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let menu = document.getElementById("viewSidebarMenu");
|
let menu = document.getElementById("viewSidebarMenu");
|
||||||
|
|
||||||
for (let [, panel] in Iterator(menu.childNodes)) {
|
for (let [, panel] in Iterator(menu.childNodes))
|
||||||
if (compare(panel.label, arg)) {
|
if (compare(panel.label, args[0]))
|
||||||
panel.doCommand();
|
return panel.doCommand();
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dactyl.echoerr("No sidebar " + arg + " found");
|
return dactyl.echoerr("No sidebar " + args[0] + " found");
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
argCount: "1",
|
argCount: "1",
|
||||||
|
|||||||
Reference in New Issue
Block a user