diff options
author | Kris Maglione <maglione.k@gmail.com> | 2011-01-09 16:15:52 -0500 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2011-01-09 16:15:52 -0500 |
commit | 04f55e932497cb43952715e4eab734d88d41e823 (patch) | |
tree | 9d29667f03281d07322a563b8115a1dc276f035e /common | |
parent | 415386a183cb15de80ddc35ff49be620423333ca (diff) | |
download | pentadactyl-04f55e932497cb43952715e4eab734d88d41e823.tar.gz |
Deal with fallout from 609832.
Diffstat (limited to 'common')
-rw-r--r-- | common/components/commandline-handler.js | 4 | ||||
-rw-r--r-- | common/components/protocols.js | 4 | ||||
-rw-r--r-- | common/content/commandline.js | 11 | ||||
-rw-r--r-- | common/content/commands.js | 47 | ||||
-rw-r--r-- | common/content/dactyl.js | 161 | ||||
-rw-r--r-- | common/content/editor.js | 29 | ||||
-rw-r--r-- | common/content/events.js | 8 | ||||
-rw-r--r-- | common/content/tabs.js | 4 | ||||
-rw-r--r-- | common/modules/styles.jsm | 8 | ||||
-rw-r--r-- | common/modules/util.jsm | 23 |
10 files changed, 148 insertions, 151 deletions
diff --git a/common/components/commandline-handler.js b/common/components/commandline-handler.js index b3ba875e..918d7bf3 100644 --- a/common/components/commandline-handler.js +++ b/common/components/commandline-handler.js @@ -9,8 +9,6 @@ function reportError(e) { Cu.reportError(e); } -try { - var global = this; var NAME = "command-line-handler"; var Cc = Components.classes; @@ -61,6 +59,4 @@ else var NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]); var EXPORTED_SYMBOLS = ["NSGetFactory", "global"]; -} catch (e) { reportError(e) } - // vim: set fdm=marker sw=4 ts=4 et: diff --git a/common/components/protocols.js b/common/components/protocols.js index 4151275e..3d7cd5e7 100644 --- a/common/components/protocols.js +++ b/common/components/protocols.js @@ -9,8 +9,6 @@ function reportError(e) { Cu.reportError(e); } -try { - /* Adds support for data: URIs with chrome privileges * and fragment identifiers. * @@ -334,6 +332,4 @@ else var NSGetModule = XPCOMUtils.generateNSGetModule([ChromeData, Dactyl, Shim]); var EXPORTED_SYMBOLS = ["NSGetFactory", "global"]; -} catch (e) { reportError(e) } - // vim: set fdm=marker sw=4 ts=4 et: diff --git a/common/content/commandline.js b/common/content/commandline.js index f2638c78..0ec01707 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -1064,12 +1064,13 @@ var CommandLine = Module("commandline", { let key = events.toString(event); + function openLink(where) { + event.preventDefault(); + dactyl.open(event.target.href, where); + } + // TODO: Wouldn't multiple handlers be cleaner? --djk if (event.type == "click" && event.target instanceof HTMLAnchorElement) { - function openLink(where) { - event.preventDefault(); - dactyl.open(event.target.href, where); - } let command = event.originalTarget.getAttributeNS(NS.uri, "command"); if (command && dactyl.commands[command]) { @@ -1494,7 +1495,7 @@ var CommandLine = Module("commandline", { try { this.waiting = true; for (let [, context] in Iterator(list)) { - function done() !(idx >= n + context.items.length || idx == -2 && !context.items.length); + let done = function done() !(idx >= n + context.items.length || idx == -2 && !context.items.length); while (context.incomplete && !done()) util.threadYield(false, true); diff --git a/common/content/commands.js b/common/content/commands.js index 9b54f4d8..fb334ba3 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -320,11 +320,11 @@ var Command = Class("Command", { let process = util.identity; if (callable(params)) - function makeParams(self, args) + var makeParams = function makeParams(self, args) iter.toObject([k, process(v)] for ([k, v] in iter(params.apply(self, args)))) else if (params) - function makeParams(self, args) + makeParams = function makeParams(self, args) iter.toObject([name, process(args[i])] for ([i, name] in Iterator(params))); @@ -749,25 +749,26 @@ var Commands = Module("commands", { * @returns {Args} */ parseArgs: function (str, params) { - try { - function getNextArg(str, _keepQuotes) { - if (arguments.length < 2) - _keepQuotes = keepQuotes; + function getNextArg(str, _keepQuotes) { + if (arguments.length < 2) + _keepQuotes = keepQuotes; - if (str.substr(0, 2) === "<<" && hereDoc) { - let arg = /^<<(\S*)/.exec(str)[1]; - let count = arg.length + 2; - if (complete) - return [count, "", ""]; - return [count, io.readHeredoc(arg), ""]; - } - let [count, arg, quote] = Commands.parseArg(str, null, _keepQuotes); - if (quote == "\\" && !complete) - return [, , , "Trailing \\"]; - if (quote && !complete) - return [, , , "E114: Missing quote: " + quote]; - return [count, arg, quote]; + if (str.substr(0, 2) === "<<" && hereDoc) { + let arg = /^<<(\S*)/.exec(str)[1]; + let count = arg.length + 2; + if (complete) + return [count, "", ""]; + return [count, io.readHeredoc(arg), ""]; } + let [count, arg, quote] = Commands.parseArg(str, null, _keepQuotes); + if (quote == "\\" && !complete) + return [, , , "Trailing \\"]; + if (quote && !complete) + return [, , , "E114: Missing quote: " + quote]; + return [count, arg, quote]; + } + + try { var { allowUnknownOptions, argCount, complete, extra, hereDoc, literal, options, keepQuotes } = params || {}; @@ -793,12 +794,12 @@ var Commands = Module("commands", { var completeOpts; // XXX - function matchOpts(arg) { + let matchOpts = function matchOpts(arg) { // Push possible option matches into completions if (complete && !onlyArgumentsRemaining) completeOpts = options.filter(function (opt) opt.multiple || !set.has(args, opt.names[0])); } - function resetCompletions() { + let resetCompletions = function resetCompletions() { completeOpts = null; args.completeArg = null; args.completeOpt = null; @@ -812,7 +813,7 @@ var Commands = Module("commands", { args.completeArg = 0; } - function fail(error) { + let fail = function fail(error) { if (complete) complete.message = error; else @@ -1328,7 +1329,7 @@ var Commands = Module("commands", { dactyl.echoerr("E174: Command already exists: add ! to replace it"); } else { - function completerToString(completer) { + let completerToString = function completerToString(completer) { if (completer) return [k for ([k, v] in Iterator(completerMap)) if (completer == completion.closure[v])][0] || "custom"; return ""; diff --git a/common/content/dactyl.js b/common/content/dactyl.js index c9b8bfa2..f58f54f0 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -534,6 +534,29 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * Initialize the help system. */ initHelp: function (force) { + // Find help and overlay files with the given name. + function findHelpFile(file) { + let result = []; + for (let [, namespace] in Iterator(namespaces)) { + let url = ["dactyl://", namespace, "/", file, ".xml"].join(""); + let res = util.httpGet(url); + if (res) { + if (res.responseXML.documentElement.localName == "document") + fileMap[file] = url; + if (res.responseXML.documentElement.localName == "overlay") + overlayMap[file] = url; + result.push(res.responseXML); + } + } + return result; + } + // Find the tags in the document. + function addTags(file, doc) { + for (let elem in util.evaluateXPath("//@tag|//dactyl:tags/text()|//dactyl:tag/text()", doc)) + for (let tag in values((elem.value || elem.textContent).split(/\s+/))) + tagMap[tag] = file; + } + if (!force && !this.helpInitialized) { if ("noscriptOverlay" in window) { noscriptOverlay.safeAllow("chrome-data:", true, false); @@ -547,29 +570,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { let fileMap = services["dactyl:"].FILE_MAP; let overlayMap = services["dactyl:"].OVERLAY_MAP; - // Find help and overlay files with the given name. - function findHelpFile(file) { - let result = []; - for (let [, namespace] in Iterator(namespaces)) { - let url = ["dactyl://", namespace, "/", file, ".xml"].join(""); - let res = util.httpGet(url); - if (res) { - if (res.responseXML.documentElement.localName == "document") - fileMap[file] = url; - if (res.responseXML.documentElement.localName == "overlay") - overlayMap[file] = url; - result.push(res.responseXML); - } - } - return result; - } - // Find the tags in the document. - function addTags(file, doc) { - for (let elem in util.evaluateXPath("//@tag|//dactyl:tags/text()|//dactyl:tag/text()", doc)) - for (let tag in values((elem.value || elem.textContent).split(/\s+/))) - tagMap[tag] = file; - } - // Scrape the list of help files from all.xml // Manually process main and overlay files, since XSLTProcessor and // XMLHttpRequest don't allow access to chrome documents. @@ -658,21 +658,71 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { dactyl.initHelp(); if (FILE.isDirectory()) { - function addDataEntry(file, data) FILE.child(file).write(data); - function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText); + var addDataEntry = function addDataEntry(file, data) FILE.child(file).write(data); + var addURIEntry = function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText); } else { var zip = services.ZipWriter(); zip.open(FILE, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE); - function addURIEntry(file, uri) + + addURIEntry = function addURIEntry(file, uri) zip.addEntryChannel(PATH + file, TIME, 9, services.io.newChannel(uri, null, null), false); - function addDataEntry(file, data) // Unideal to an extreme. + addDataEntry = function addDataEntry(file, data) // Unideal to an extreme. addURIEntry(file, "data:text/plain;charset=UTF-8," + encodeURI(data)); } let empty = set("area base basefont br col frame hr img input isindex link meta param" .split(" ")); + function fix(node) { + switch(node.nodeType) { + case Node.ELEMENT_NODE: + if (isinstance(node, [HTMLBaseElement])) + return; + + data.push("<"); data.push(node.localName); + if (node instanceof HTMLHtmlElement) + data.push(" xmlns=" + XHTML.uri.quote()); + + for (let { name, value } in array.iterValues(node.attributes)) { + if (name == "dactyl:highlight") { + set.add(styles, value); + name = "class"; + value = "hl-" + value; + } + if (name == "href") { + value = node.href; + if (value.indexOf("dactyl://help-tag/") == 0) { + let uri = services.io.newChannel(value, null, null).originalURI; + value = uri.spec == value ? "javascript:;" : uri.path.substr(1); + } + if (!/^#|[\/](#|$)|^[a-z]+:/.test(value)) + value = value.replace(/(#|$)/, ".xhtml$1"); + } + if (name == "src" && value.indexOf(":") > 0) { + chromeFiles[value] = value.replace(/.*\//, ""); + value = value.replace(/.*\//, ""); + } + data.push(" "); + data.push(name); + data.push('="'); + data.push(<>{value}</>.toXMLString()); + data.push('"'); + } + if (node.localName in empty) + data.push(" />"); + else { + data.push(">"); + if (node instanceof HTMLHeadElement) + data.push(<link rel="stylesheet" type="text/css" href="help.css"/>.toXMLString()); + Array.map(node.childNodes, fix); + data.push("</"); data.push(node.localName); data.push(">"); + } + break; + case Node.TEXT_NODE: + data.push(<>{node.textContent}</>.toXMLString()); + } + } let chromeFiles = {}; let styles = {}; @@ -684,55 +734,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n', ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' ]; - function fix(node) { - switch(node.nodeType) { - case Node.ELEMENT_NODE: - if (isinstance(node, [HTMLBaseElement])) - return; - - data.push("<"); data.push(node.localName); - if (node instanceof HTMLHtmlElement) - data.push(" xmlns=" + XHTML.uri.quote()); - - for (let { name, value } in array.iterValues(node.attributes)) { - if (name == "dactyl:highlight") { - set.add(styles, value); - name = "class"; - value = "hl-" + value; - } - if (name == "href") { - value = node.href; - if (value.indexOf("dactyl://help-tag/") == 0) { - let uri = services.io.newChannel(value, null, null).originalURI; - value = uri.spec == value ? "javascript:;" : uri.path.substr(1); - } - if (!/^#|[\/](#|$)|^[a-z]+:/.test(value)) - value = value.replace(/(#|$)/, ".xhtml$1"); - } - if (name == "src" && value.indexOf(":") > 0) { - chromeFiles[value] = value.replace(/.*\//, ""); - value = value.replace(/.*\//, ""); - } - data.push(" "); - data.push(name); - data.push('="'); - data.push(<>{value}</>.toXMLString()); - data.push('"'); - } - if (node.localName in empty) - data.push(" />"); - else { - data.push(">"); - if (node instanceof HTMLHeadElement) - data.push(<link rel="stylesheet" type="text/css" href="help.css"/>.toXMLString()); - Array.map(node.childNodes, fix); - data.push("</"); data.push(node.localName); data.push(">"); - } - break; - case Node.TEXT_NODE: - data.push(<>{node.textContent}</>.toXMLString()); - } - } fix(content.document.documentElement); addDataEntry(file + ".xhtml", data.join("")); } @@ -1893,12 +1894,12 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { "Force " + config.appName + " to restart", function () { dactyl.restart(); }); + function findToolbar(name) util.evaluateXPath( + "./*[@toolbarname=" + util.escapeString(name, "'") + "]", + document, toolbox).snapshotItem(0); + var toolbox = document.getElementById("navigator-toolbox"); if (toolbox) { - function findToolbar(name) util.evaluateXPath( - "./*[@toolbarname=" + util.escapeString(name, "'") + "]", - document, toolbox).snapshotItem(0); - let toolbarCommand = function (names, desc, action, filter) { commands.add(names, desc, function (args) { diff --git a/common/content/editor.js b/common/content/editor.js index 2448c7cb..90baf1ed 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -307,6 +307,21 @@ var Editor = Module("editor", { } }); + function update(force) { + if (force !== true && tmpfile.lastModifiedTime <= lastUpdate) + return; + lastUpdate = Date.now(); + + let val = tmpfile.read(); + if (textBox) + textBox.value = val; + else { + while (editor.rootElement.firstChild) + editor.rootElement.removeChild(editor.rootElement.firstChild); + editor.rootElement.innerHTML = val; + } + } + try { var tmpfile = io.createTempFile(); if (!tmpfile) @@ -322,20 +337,6 @@ var Editor = Module("editor", { "file encoding"); let lastUpdate = Date.now(); - function update(force) { - if (force !== true && tmpfile.lastModifiedTime <= lastUpdate) - return; - lastUpdate = Date.now(); - - let val = tmpfile.read(); - if (textBox) - textBox.value = val; - else { - while (editor.rootElement.firstChild) - editor.rootElement.removeChild(editor.rootElement.firstChild); - editor.rootElement.innerHTML = val; - } - } var timer = services.Timer(update, 100, services.Timer.TYPE_REPEATING_SLACK); this.editFileExternally({ file: tmpfile.path, line: line, column: column }, cleanup); diff --git a/common/content/events.js b/common/content/events.js index 91959680..f14d950a 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -899,15 +899,15 @@ var Events = Module("events", { return killEvent(); } + function shouldPass() + (!dactyl.focusedElement || events.isContentNode(dactyl.focusedElement)) && + options.get("passkeys").has(events.toString(event)); + try { let mode = modes.getStack(0); if (event.dactylMode) mode = Modes.StackElement(event.dactylMode); - function shouldPass() - (!dactyl.focusedElement || events.isContentNode(dactyl.focusedElement)) && - options.get("passkeys").has(events.toString(event)); - let input = this._input; this._input = null; if (!input) { diff --git a/common/content/tabs.js b/common/content/tabs.js index 0583c177..5077055a 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -43,7 +43,7 @@ var Tabs = Module("tabs", { cleanup: function cleanup() { for (let [i, tab] in Iterator(this.allTabs)) { - function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas); + let node = function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas); for (let elem in values(["dactyl-tab-icon-number", "dactyl-tab-number"].map(node))) if (elem) elem.parentNode.parentNode.removeChild(elem.parentNode); @@ -53,7 +53,7 @@ var Tabs = Module("tabs", { updateTabCount: function () { for (let [i, tab] in Iterator(this.visibleTabs)) { if (dactyl.has("Gecko2")) { - function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas); + let node = function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas); if (!node("dactyl-tab-number")) { let nodes = {}; let dom = util.xmlToDom(<xul xmlns:xul={XUL} xmlns:html={XHTML} diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 6d2343d2..3321dbc2 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -309,15 +309,15 @@ var Styles = Module("Styles", { */ matchFilter: function (filter) { if (filter === "*") - function test(uri) true; + var test = function test(uri) true; else if (/[*]$/.test(filter)) { let re = RegExp("^" + util.regexp.escape(filter.substr(0, filter.length - 1))); - function test(uri) re.test(uri.spec); + test = function test(uri) re.test(uri.spec); } else if (/[\/:]/.test(filter)) - function test(uri) uri.spec === filter; + test = function test(uri) uri.spec === filter; else - function test(uri) { try { return util.isSubdomain(uri.host, filter); } catch (e) { return false; } }; + test = function test(uri) { try { return util.isSubdomain(uri.host, filter); } catch (e) { return false; } }; test.toString = function toString() filter; if (arguments.length < 2) return test; diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 6fe6c639..a6acb0cf 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -31,8 +31,8 @@ memoize(this, "Commands", function () { var FailedAssertion = Class("FailedAssertion", ErrorBase); var Point = Struct("x", "y"); -function wrapCallback(fn) - fn.wrapper = function wrappedCallback () { +var wrapCallback = function wrapCallback(fn) + fn.wrapper = (function wrappedCallback () { try { return fn.apply(this, arguments); } @@ -40,7 +40,7 @@ function wrapCallback(fn) util.reportError(e); return undefined; } - } + }) var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { init: function () { @@ -820,6 +820,15 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), if (!isObject(object)) return String(object); + function namespaced(node) { + var ns = NAMESPACES[node.namespaceURI] || /^(?:(.*?):)?/.exec(node.name)[0]; + if (!ns) + return node.localName; + if (color) + return <><span highlight="HelpXMLNamespace">{ns}</span>{node.localName}</> + return ns + ":" + node.localName; + } + if (object instanceof Ci.nsIDOMElement) { const NAMESPACES = array.toObject([ [NS, "dactyl"], @@ -830,14 +839,6 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), if (elem.nodeType == elem.TEXT_NODE) return elem.data; - function namespaced(node) { - var ns = NAMESPACES[node.namespaceURI] || /^(?:(.*?):)?/.exec(node.name)[0]; - if (!ns) - return node.localName; - if (color) - return <><span highlight="HelpXMLNamespace">{ns}</span>{node.localName}</> - return ns + ":" + node.localName; - } try { let hasChildren = elem.firstChild && (!/^\s*$/.test(elem.firstChild) || elem.firstChild.nextSibling) if (color) |