1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-19 11:25:46 +01:00

Replace 'focuscontent' with 'strictfocus'.

--HG--
branch : testing
This commit is contained in:
Kris Maglione
2010-08-26 13:26:34 -04:00
parent 89633538c8
commit 2375a00fb4
9 changed files with 183 additions and 157 deletions

View File

@@ -271,9 +271,9 @@ const AutoCommands = Module("autocommands", {
completer: function () config.autocommands.concat([["all", "All events"]])
});
options.add(["focuscontent", "fc"],
"Try to stay in normal mode after loading a web page",
"boolean", false);
options.add(["strictfocus", "sf"],
"Prevent scripts from focusing input elements without user intervention",
"boolean", true);
}
});

View File

@@ -200,19 +200,7 @@ const Buffer = Module("buffer", {
// any buffer, even in a background tab
doc.pageIsFullyLoaded = 1;
// code which is only relevant if the page load is the current tab goes here:
if (doc == config.browser.contentDocument) {
// we want to stay in command mode after a page has loaded
// TODO: move somewhere else, as focusing can already happen earlier than on "load"
if (options["focuscontent"]) {
setTimeout(function () {
let focused = liberator.focus;
if (focused && (focused.value != null) && focused.value.length == 0)
focused.blur();
}, 0);
}
}
else // background tab
if (doc != config.browser.contentDocument)
liberator.echomsg("Background tab loaded: " + doc.title || doc.location.href, 3);
this._triggerLoadAutocmd("PageLoad", doc);
@@ -474,6 +462,18 @@ const Buffer = Module("buffer", {
return String(selection);
},
/**
* Returns true if a scripts are allowed to focus the given input
* element or input elements in the given window.
*
* @param {Node|Window}
* @returns {boolean}
*/
focusAllowed: function (elem) {
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
return !options["strictfocus"] || elem.liberatorFocusAllowed;
},
/**
* Focuses the given element. In contrast to a simple
* elem.focus() call, this function works for iframes and
@@ -483,7 +483,10 @@ const Buffer = Module("buffer", {
*/
focusElement: function (elem) {
let doc = window.content.document;
if (elem instanceof HTMLFrameElement || elem instanceof HTMLIFrameElement)
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
win.liberatorFocusAllowed = true;
if (isinstance(elem, [HTMLFrameElement, HTMLIFrameElement]))
elem.contentWindow.focus();
else if (elem instanceof HTMLInputElement && elem.type == "file") {
Buffer.openUploadPrompt(elem);

View File

@@ -103,32 +103,16 @@ const Events = Module("events", {
}
}, 100);
function wrapListener(method) {
return function (event) {
try {
self[method](event);
}
catch (e) {
if (e.message == "Interrupted")
liberator.echoerr("Interrupted");
else
liberator.echoerr("Processing " + event.type + " event: " + (e.echoerr || e));
liberator.reportError(e);
}
};
}
this._wrappedOnKeyPress = wrapListener("onKeyPress");
this._wrappedOnKeyUpOrDown = wrapListener("onKeyUpOrDown");
this.addSessionListener(window, "keypress", this.closure._wrappedOnKeyPress, true);
this.addSessionListener(window, "keydown", this.closure._wrappedOnKeyUpOrDown, true);
this.addSessionListener(window, "keyup", this.closure._wrappedOnKeyUpOrDown, true);
this._activeMenubar = false;
this.addSessionListener(window, "popupshown", this.closure.onPopupShown, true);
this.addSessionListener(window, "popuphidden", this.closure.onPopupHidden, true);
this.addSessionListener(window, "DOMMenuBarActive", this.closure.onDOMMenuBarActive, true);
this.addSessionListener(window, "DOMMenuBarInactive", this.closure.onDOMMenuBarInactive, true);
this.addSessionListener(window, "focus", this.wrapListener(this.closure.onFocus), true);
this.addSessionListener(window, "keydown", this.wrapListener(this.closure.onKeyUpOrDown), true);
this.addSessionListener(window, "keypress", this.wrapListener(this.closure.onKeyPress), true);
this.addSessionListener(window, "keyup", this.wrapListener(this.closure.onKeyUpOrDown), true);
this.addSessionListener(window, "mousedown", this.wrapListener(this.closure.onMouseDown), true);
this.addSessionListener(window, "popuphidden", this.closure.onPopupHidden, true);
this.addSessionListener(window, "popupshown", this.closure.onPopupShown, true);
this.addSessionListener(window, "resize", this.closure.onResize, true);
},
@@ -151,10 +135,28 @@ const Events = Module("events", {
*/
addSessionListener: function (target, event, callback, capture) {
let args = Array.slice(arguments, 0);
target.addEventListener.apply(target, args.slice(1));
target.addEventListener.apply(args[0], args.slice(1));
this.sessionListeners.push(args);
},
/**
* Wraps an event listener to ensure that errors are reported.
*/
wrapListener: function wrapListener(method, self) {
return function (event) {
try {
method.apply(self, arguments);
}
catch (e) {
if (e.message == "Interrupted")
liberator.echoerr("Interrupted");
else
liberator.echoerr("Processing " + event.type + " event: " + (e.echoerr || e));
liberator.reportError(e);
}
};
},
/**
* @property {boolean} Whether synthetic key events are currently being
* processed.
@@ -651,89 +653,14 @@ const Events = Module("events", {
return ret;
},
// argument "event" is deliberately not used, as i don't seem to have
// access to the real focus target
// Huh? --djk
onFocusChange: function (event) {
// command line has it's own focus change handler
if (liberator.mode == modes.COMMAND_LINE)
return;
function hasHTMLDocument(win) win && win.document && win.document instanceof HTMLDocument
let win = window.document.commandDispatcher.focusedWindow;
let elem = window.document.commandDispatcher.focusedElement;
if (win && win.top == content && liberator.has("tabs"))
tabs.localStore.focusedFrame = win;
try {
if (elem && elem.readOnly)
return;
if ((elem instanceof HTMLInputElement && /^(search|text|password)$/.test(elem.type)) ||
(elem instanceof HTMLSelectElement)) {
liberator.mode = modes.INSERT;
if (hasHTMLDocument(win))
buffer.lastInputField = elem;
return;
}
if (elem instanceof HTMLEmbedElement || elem instanceof HTMLObjectElement) {
liberator.mode = modes.EMBED;
return;
}
if (elem instanceof HTMLTextAreaElement || (elem && elem.contentEditable == "true")) {
if (options["insertmode"])
modes.set(modes.INSERT);
else if (elem.selectionEnd - elem.selectionStart > 0)
modes.set(modes.VISUAL, modes.TEXTAREA);
else
modes.main = modes.TEXTAREA;
if (hasHTMLDocument(win))
buffer.lastInputField = elem;
return;
}
if (config.focusChange) {
config.focusChange(win);
return;
}
let urlbar = document.getElementById("urlbar");
if (elem == null && urlbar && urlbar.inputField == this._lastFocus)
liberator.threadYield(true);
if (liberator.mode & (modes.EMBED | modes.INSERT | modes.TEXTAREA | modes.VISUAL))
modes.reset();
}
finally {
this._lastFocus = elem;
}
onDOMMenuBarActive: function () {
this._activeMenubar = true;
modes.add(modes.MENU);
},
onSelectionChange: function (event) {
let couldCopy = false;
let controller = document.commandDispatcher.getControllerForCommand("cmd_copy");
if (controller && controller.isCommandEnabled("cmd_copy"))
couldCopy = true;
if (liberator.mode != modes.VISUAL) {
if (couldCopy) {
if ((liberator.mode == modes.TEXTAREA ||
(modes.extended & modes.TEXTAREA))
&& !options["insertmode"])
modes.set(modes.VISUAL, modes.TEXTAREA);
else if (liberator.mode == modes.CARET)
modes.set(modes.VISUAL, modes.CARET);
}
}
// XXX: disabled, as i think automatically starting visual caret mode does more harm than help
// else
// {
// if (!couldCopy && modes.extended & modes.CARET)
// liberator.mode = modes.CARET;
// }
onDOMMenuBarInactive: function () {
this._activeMenubar = false;
modes.remove(modes.MENU);
},
/**
@@ -808,6 +735,78 @@ const Events = Module("events", {
}
},
onFocus: function (event) {
function hasHTMLDocument(win) win && win.document && win.document instanceof HTMLDocument
let elem = event.originalTarget;
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
if (hasHTMLDocument(win) && !buffer.focusAllowed(win))
elem.blur();
},
// argument "event" is deliberately not used, as i don't seem to have
// access to the real focus target
// Huh? --djk
onFocusChange: function (event) {
// command line has it's own focus change handler
if (liberator.mode == modes.COMMAND_LINE)
return;
function hasHTMLDocument(win) win && win.document && win.document instanceof HTMLDocument
let win = window.document.commandDispatcher.focusedWindow;
let elem = window.document.commandDispatcher.focusedElement;
if (win && win.top == content && liberator.has("tabs"))
tabs.localStore.focusedFrame = win;
try {
if (elem && elem.readOnly)
return;
if ((elem instanceof HTMLInputElement && /^(search|text|password)$/.test(elem.type)) ||
(elem instanceof HTMLSelectElement)) {
liberator.mode = modes.INSERT;
if (hasHTMLDocument(win))
buffer.lastInputField = elem;
return;
}
if(isinstance(elem, [HTMLEmbedElement, HTMLEmbedElement])) {
liberator.mode = modes.EMBED;
return;
}
if (elem instanceof HTMLTextAreaElement || (elem && elem.contentEditable == "true")) {
if (options["insertmode"])
modes.set(modes.INSERT);
else if (elem.selectionEnd - elem.selectionStart > 0)
modes.set(modes.VISUAL, modes.TEXTAREA);
else
modes.main = modes.TEXTAREA;
if (hasHTMLDocument(win))
buffer.lastInputField = elem;
return;
}
if (config.focusChange) {
config.focusChange(win);
return;
}
let urlbar = document.getElementById("urlbar");
if (elem == null && urlbar && urlbar.inputField == this._lastFocus)
liberator.threadYield(true);
if (liberator.mode & (modes.EMBED | modes.INSERT | modes.TEXTAREA | modes.VISUAL))
modes.reset();
}
finally {
this._lastFocus = elem;
}
},
// this keypress handler gets always called first, even if e.g.
// the commandline has focus
// TODO: ...help me...please...
@@ -1052,6 +1051,13 @@ const Events = Module("events", {
event.stopPropagation();
},
onMouseDown: function (event) {
let elem = event.target;
let win = elem.ownerDocument && elem.ownerDocument.defaultView || elem;
for(; win; win = win != win.parent && win.parent)
win.liberatorFocusAllowed = true;
},
onPopupShown: function (event) {
if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "liberator-visualbell")
return;
@@ -1064,22 +1070,36 @@ const Events = Module("events", {
modes.remove(modes.MENU);
},
onDOMMenuBarActive: function () {
this._activeMenubar = true;
modes.add(modes.MENU);
},
onDOMMenuBarInactive: function () {
this._activeMenubar = false;
modes.remove(modes.MENU);
},
onResize: function (event) {
if (window.fullScreen != this._fullscreen) {
this._fullscreen = window.fullScreen;
liberator.triggerObserver("fullscreen", this._fullscreen);
autocommands.trigger("Fullscreen", { state: this._fullscreen });
}
},
onSelectionChange: function (event) {
let couldCopy = false;
let controller = document.commandDispatcher.getControllerForCommand("cmd_copy");
if (controller && controller.isCommandEnabled("cmd_copy"))
couldCopy = true;
if (liberator.mode != modes.VISUAL) {
if (couldCopy) {
if ((liberator.mode == modes.TEXTAREA ||
(modes.extended & modes.TEXTAREA))
&& !options["insertmode"])
modes.set(modes.VISUAL, modes.TEXTAREA);
else if (liberator.mode == modes.CARET)
modes.set(modes.VISUAL, modes.CARET);
}
}
// XXX: disabled, as i think automatically starting visual caret mode does more harm than help
// else
// {
// if (!couldCopy && modes.extended & modes.CARET)
// liberator.mode = modes.CARET;
// }
}
}, {
isInputElemFocused: function () {

View File

@@ -59,10 +59,13 @@ const JavaScript = Module("javascript", {
}
// The debugger doesn't list some properties. I can't guess why.
// This only lists ENUMERABLE properties.
for (let k in orig)
if (k in orig && !('|' + k in seen)
&& Object.hasOwnProperty(orig, k) == toplevel)
yield [k, this.getKey(orig, k)]
try {
for (let k in orig)
if (k in orig && !('|' + k in seen)
&& Object.hasOwnProperty(orig, k) == toplevel)
yield [k, this.getKey(orig, k)]
}
catch(e) {}
}
else {
for (let k in allkeys(obj))

View File

@@ -151,8 +151,9 @@
<item>
<tags>:extens :extensions</tags>
<tags>:exts :extens :extensions</tags>
<spec>:extens<oa>ions</oa></spec>
<spec>:exts</spec>
<description>
<p>List all installed extensions.</p>
</description>

View File

@@ -393,7 +393,6 @@ This file contains a list of all available commands, mappings and options.
<dt><o>exrc</o></dt> <dd>Allow reading of an RC file in the current directory</dd>
<dt><o>extendedhinttags</o></dt> <dd>XPath string of hintable elements activated by <k>;</k></dd>
<dt><o>fileencoding</o></dt> <dd>Changes the character encoding that &liberator.appname; uses to read and write files</dd>
<dt><o>focuscontent</o></dt> <dd>Try to stay in Normal mode after loading a web page</dd>
<dt><o>followhints</o></dt> <dd>Change the behaviour of <k name="Return"/> in Hints mode</dd>
<dt><o>fullscreen</o></dt> <dd>Show the current window fullscreen</dd>
<dt><o>guioptions</o></dt> <dd>Show or hide certain GUI elements like the menu or toolbar</dd>
@@ -430,6 +429,7 @@ This file contains a list of all available commands, mappings and options.
<dt><o>showstatuslinks</o></dt> <dd>Show the destination of the link under the cursor in the status bar</dd>
<dt><o>showtabline</o></dt> <dd>Control when to show the tab bar of opened web pages</dd>
<dt><o>smartcase</o></dt> <dd>Override the <o>ignorecase</o> option if the pattern contains uppercase characters</dd>
<dt><o>strictfocus</o></dt> <dd>Prevent scripts from focusing input elements without user intervention</dd>
<dt><o>suggestengines</o></dt> <dd>Engine Alias which has a feature of suggest</dd>
<dt><o>titlestring</o></dt> <dd>Change the title of the window</dd>
<dt><o>urlseparator</o></dt> <dd>Set the separator regex used to separate multiple URL args</dd>

View File

@@ -519,19 +519,14 @@
<item>
<tags>'nofc' 'nofocuscontent'</tags>
<tags>'fc' 'focuscontent'</tags>
<spec>'focuscontent' 'fc'</spec>
<tags>'nosf' 'nostrictfocus'</tags>
<tags>'sf' 'strictfocus'</tags>
<spec>'strictfocus' 'sf'</spec>
<type>boolean</type>
<default>off</default>
<default>on</default>
<description>
<p>
Focus the content after a page has loaded. This is useful if you
always want to stay in Normal mode when browsing between web sites.
When <str>on</str>, it blurs any textbox which often is
automatically focused on page load. If you usually like
<o>focuscontent</o> but sometimes you'd like to focus the first
input field, you can use <k>gi</k> to jump to it.
Prevent scripts from focusing input elements without user intervention.
</p>
</description>
</item>