1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 07:28:00 +01:00

Make 'strictfocus' a currently undocumented sitemap option.

This commit is contained in:
Kris Maglione
2011-03-12 14:36:07 -05:00
parent 9ba3635bc1
commit b7822c5cb2
5 changed files with 41 additions and 10 deletions

View File

@@ -352,8 +352,16 @@ var Buffer = Module("buffer", {
focusAllowed: function focusAllowed(elem) { focusAllowed: function focusAllowed(elem) {
if (elem instanceof Window && !Editor.getEditor(elem)) if (elem instanceof Window && !Editor.getEditor(elem))
return true; return true;
let doc = elem.ownerDocument || elem.document || elem; let doc = elem.ownerDocument || elem.document || elem;
return !options["strictfocus"] || doc.dactylFocusAllowed; switch (options.get("strictfocus").getKey(doc.documentURI, "moderate")) {
case "despotic":
return elem.dactylFocusAllowed;
case "moderate":
return doc.dactylFocusAllowed;
default:
return true;
}
}, },
/** /**
@@ -365,6 +373,7 @@ var Buffer = Module("buffer", {
*/ */
focusElement: function focusElement(elem) { focusElement: function focusElement(elem) {
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem; let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
elem.dactylFocusAllowed = true;
win.document.dactylFocusAllowed = true; win.document.dactylFocusAllowed = true;
if (isinstance(elem, [HTMLFrameElement, HTMLIFrameElement])) if (isinstance(elem, [HTMLFrameElement, HTMLIFrameElement]))
@@ -1655,7 +1664,7 @@ var Buffer = Module("buffer", {
let elem = buffer.lastInputField; let elem = buffer.lastInputField;
if (args.count >= 1 || !elem || !events.isContentNode(elem)) { if (args.count >= 1 || !elem || !events.isContentNode(elem)) {
let xpath = ["frame", "iframe", "input", "textarea[not(@disabled) and not(@readonly)]"]; let xpath = ["frame", "iframe", "input", "xul:textbox", "textarea[not(@disabled) and not(@readonly)]"];
let frames = buffer.allFrames(null, true); let frames = buffer.allFrames(null, true);
@@ -1670,7 +1679,8 @@ var Buffer = Module("buffer", {
let computedStyle = util.computedStyle(elem); let computedStyle = util.computedStyle(elem);
let rect = elem.getBoundingClientRect(); let rect = elem.getBoundingClientRect();
return computedStyle.visibility != "hidden" && computedStyle.display != "none" && return computedStyle.visibility != "hidden" && computedStyle.display != "none" &&
computedStyle.MozUserFocus != "ignore" && rect.width && rect.height; (elem instanceof Ci.nsIDOMXULTextBoxElement || computedStyle.MozUserFocus != "ignore") &&
rect.width && rect.height;
}); });
dactyl.assert(elements.length > 0); dactyl.assert(elements.length > 0);

View File

@@ -654,7 +654,10 @@ var Editor = Module("editor", {
}); });
mappings.add([modes.INPUT], mappings.add([modes.INPUT],
["<BS>", "<Del>", "<Left>", "<Right>", "<Up>", "<Down>"], ["<BS>", "<Del>", "<Left>", "<Right>", "<Up>", "<Down>",
"<Home>", "<End>", "<PageUp>", "<PageDown>",
"<C-BS>", "<C-Del>", "<C-Left>", "<C-Right>", "<C-Up>", "<C-Down>",
"<C-Home>", "<C-End>", "<C-PageUp>", "<C-PageDown>"],
"Handled by " + config.host, "Handled by " + config.host,
function () Events.PASS); function () Events.PASS);

View File

@@ -1135,14 +1135,19 @@ var Events = Module("events", {
let win = (elem.ownerDocument || elem).defaultView || elem; let win = (elem.ownerDocument || elem).defaultView || elem;
if (events.isContentNode(elem) && !buffer.focusAllowed(elem) if (!(services.focus.getLastFocusMethod(win) & 0x7000)
&& !(services.focus.getLastFocusMethod(win) & 0x7000) && events.isContentNode(elem)
&& !buffer.focusAllowed(elem)
&& isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, Window])) { && isinstance(elem, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, Window])) {
if (elem.frameElement) if (elem.frameElement)
dactyl.focusContent(true); dactyl.focusContent(true);
else if (!(elem instanceof Window) || Editor.getEditor(elem)) else if (!(elem instanceof Window) || Editor.getEditor(elem))
dactyl.focus(window); dactyl.focus(window);
} }
if (elem instanceof Element)
elem.dactylFocusAllowed = undefined;
}, },
/* /*
@@ -1329,8 +1334,11 @@ var Events = Module("events", {
let elem = event.target; let elem = event.target;
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem; let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
for (; win; win = win != win.parent && win.parent) for (; win; win = win != win.parent && win.parent) {
for (; elem instanceof Element; elem = elem.parentNode)
elem.dactylFocusAllowed = true;
win.document.dactylFocusAllowed = true; win.document.dactylFocusAllowed = true;
}
}, },
popupshown: function onPopupShown(event) { popupshown: function onPopupShown(event) {
@@ -1650,7 +1658,14 @@ var Events = Module("events", {
options.add(["strictfocus", "sf"], options.add(["strictfocus", "sf"],
"Prevent scripts from focusing input elements without user intervention", "Prevent scripts from focusing input elements without user intervention",
"boolean", true); "sitemap", "*:moderate",
{
values: {
despotic: "Only allow focus changes when explicitly requested by the user",
moderate: "Allow focus changes after user-initiated focus change",
"laisses-faire": "Always allow focus changes"
}
});
options.add(["timeout", "tmo"], options.add(["timeout", "tmo"],
"Whether to execute a shorter key command after a timeout when a longer command exists", "Whether to execute a shorter key command after a timeout when a longer command exists",

View File

@@ -311,7 +311,10 @@ var Option = Class("Option", {
* @property {function(CompletionContext, Args)} This option's completer. * @property {function(CompletionContext, Args)} This option's completer.
* @see CompletionContext * @see CompletionContext
*/ */
completer: function completer(context) { completer: function completer(context, extra) {
if (/map$/.test(this.type) && extra.value == null)
return;
if (this.values) if (this.values)
context.completions = this.values; context.completions = this.values;
}, },

View File

@@ -950,7 +950,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
*/ */
makeXPath: function makeXPath(nodes) { makeXPath: function makeXPath(nodes) {
return array(nodes).map(util.debrace).flatten() return array(nodes).map(util.debrace).flatten()
.map(function (node) [node, "xhtml:" + node]).flatten() .map(function (node) /^[a-z]+:/.test(node) ? node : [node, "xhtml:" + node]).flatten()
.map(function (node) "//" + node).join(" | "); .map(function (node) "//" + node).join(" | ");
}, },