1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 08:27:59 +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

@@ -11,6 +11,8 @@ syntax: glob
*/locale/*/*.html */locale/*/*.html
*/chrome */chrome
*/contrib/vim/*.vba */contrib/vim/*.vba
*/bak/*
downloads/*
## Editor backup and swap files ## Editor backup and swap files
*~ *~

View File

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

View File

@@ -200,19 +200,7 @@ const Buffer = Module("buffer", {
// any buffer, even in a background tab // any buffer, even in a background tab
doc.pageIsFullyLoaded = 1; doc.pageIsFullyLoaded = 1;
// code which is only relevant if the page load is the current tab goes here: if (doc != config.browser.contentDocument)
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
liberator.echomsg("Background tab loaded: " + doc.title || doc.location.href, 3); liberator.echomsg("Background tab loaded: " + doc.title || doc.location.href, 3);
this._triggerLoadAutocmd("PageLoad", doc); this._triggerLoadAutocmd("PageLoad", doc);
@@ -474,6 +462,18 @@ const Buffer = Module("buffer", {
return String(selection); 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 * Focuses the given element. In contrast to a simple
* elem.focus() call, this function works for iframes and * elem.focus() call, this function works for iframes and
@@ -483,7 +483,10 @@ const Buffer = Module("buffer", {
*/ */
focusElement: function (elem) { focusElement: function (elem) {
let doc = window.content.document; 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(); elem.contentWindow.focus();
else if (elem instanceof HTMLInputElement && elem.type == "file") { else if (elem instanceof HTMLInputElement && elem.type == "file") {
Buffer.openUploadPrompt(elem); Buffer.openUploadPrompt(elem);

View File

@@ -103,32 +103,16 @@ const Events = Module("events", {
} }
}, 100); }, 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._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, "DOMMenuBarActive", this.closure.onDOMMenuBarActive, true);
this.addSessionListener(window, "DOMMenuBarInactive", this.closure.onDOMMenuBarInactive, 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); this.addSessionListener(window, "resize", this.closure.onResize, true);
}, },
@@ -151,10 +135,28 @@ const Events = Module("events", {
*/ */
addSessionListener: function (target, event, callback, capture) { addSessionListener: function (target, event, callback, capture) {
let args = Array.slice(arguments, 0); 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); 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 * @property {boolean} Whether synthetic key events are currently being
* processed. * processed.
@@ -651,89 +653,14 @@ const Events = Module("events", {
return ret; return ret;
}, },
// argument "event" is deliberately not used, as i don't seem to have onDOMMenuBarActive: function () {
// access to the real focus target this._activeMenubar = true;
// Huh? --djk modes.add(modes.MENU);
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;
}
}, },
onSelectionChange: function (event) { onDOMMenuBarInactive: function () {
let couldCopy = false; this._activeMenubar = false;
let controller = document.commandDispatcher.getControllerForCommand("cmd_copy"); modes.remove(modes.MENU);
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;
// }
}, },
/** /**
@@ -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. // this keypress handler gets always called first, even if e.g.
// the commandline has focus // the commandline has focus
// TODO: ...help me...please... // TODO: ...help me...please...
@@ -1052,6 +1051,13 @@ const Events = Module("events", {
event.stopPropagation(); 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) { onPopupShown: function (event) {
if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "liberator-visualbell") if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "liberator-visualbell")
return; return;
@@ -1064,22 +1070,36 @@ const Events = Module("events", {
modes.remove(modes.MENU); 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) { onResize: function (event) {
if (window.fullScreen != this._fullscreen) { if (window.fullScreen != this._fullscreen) {
this._fullscreen = window.fullScreen; this._fullscreen = window.fullScreen;
liberator.triggerObserver("fullscreen", this._fullscreen); liberator.triggerObserver("fullscreen", this._fullscreen);
autocommands.trigger("Fullscreen", { state: 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 () { isInputElemFocused: function () {

View File

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

View File

@@ -151,8 +151,9 @@
<item> <item>
<tags>:extens :extensions</tags> <tags>:exts :extens :extensions</tags>
<spec>:extens<oa>ions</oa></spec> <spec>:extens<oa>ions</oa></spec>
<spec>:exts</spec>
<description> <description>
<p>List all installed extensions.</p> <p>List all installed extensions.</p>
</description> </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>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>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>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>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>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> <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>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>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>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>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>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> <dt><o>urlseparator</o></dt> <dd>Set the separator regex used to separate multiple URL args</dd>

View File

@@ -519,19 +519,14 @@
<item> <item>
<tags>'nofc' 'nofocuscontent'</tags> <tags>'nosf' 'nostrictfocus'</tags>
<tags>'fc' 'focuscontent'</tags> <tags>'sf' 'strictfocus'</tags>
<spec>'focuscontent' 'fc'</spec> <spec>'strictfocus' 'sf'</spec>
<type>boolean</type> <type>boolean</type>
<default>off</default> <default>on</default>
<description> <description>
<p> <p>
Focus the content after a page has loaded. This is useful if you Prevent scripts from focusing input elements without user intervention.
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.
</p> </p>
</description> </description>
</item> </item>

View File

@@ -1,11 +1,15 @@
2009-XX-XX: 2009-XX-XX:
* version 2.3a1pre * Replaced 'focuscontent' with 'strictfocus'
* add basic plugin authorship documentation * Replaced previous incremental search implementation
* plugins may now provide full-fleged ':help' documentation * :open now only opens files begining with / or ./
* asciidoc is no longer required to build Vimperator * Page zoom information is now shown in the status bar
* the help system is newly modularized * Added ZO, ZI, ZM, and ZR as aliases for zO, zI, zM, and zR
* remove [c]:edit[c], [c]:tabedit[c], and [c]:winedit[c] * Add basic plugin authorship documentation
* add 'jsdebugger' option - switch on/off javascript debugger service * Plugins may now provide full-fleged ':help' documentation
* The help system is newly modularized
* Asciidoc is no longer for building
* Remove [c]:edit[c], [c]:tabedit[c], and [c]:winedit[c]
* Add 'jsdebugger' option - switch on/off javascript debugger service
2009-10-28: 2009-10-28:
* version 2.2 * version 2.2
@@ -26,8 +30,6 @@
................................... ...................................
* IMPORTANT: shifted key notation now matches Vim's behaviour. E.g. <C-a> * IMPORTANT: shifted key notation now matches Vim's behaviour. E.g. <C-a>
and <C-A> are equivalent, to map the uppercase character use <C-S-A>. and <C-A> are equivalent, to map the uppercase character use <C-S-A>.
(this might change again, as this is REALLY inconsistent, and i don't
know if I like copying bugs)
* IMPORTANT: 'popups' now takes a stringlist rather than a number. * IMPORTANT: 'popups' now takes a stringlist rather than a number.
* add [c]:winonly[c] * add [c]:winonly[c]