diff --git a/common/content/buffer.js b/common/content/buffer.js index 1827d00c..955737ce 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -14,7 +14,7 @@ * files. * @instance buffer */ -var Buffer = Module("buffer", { +var Buffer = Module("buffer", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { init: function () { this.evaluateXPath = util.evaluateXPath; this.pageInfo = {}; @@ -153,10 +153,12 @@ var Buffer = Module("buffer", { for (let tab in values(tabs.allTabs)) if (tab.linkedBrowser.contentDocument.readyState === "complete") dactyl.initDocument(tab.linkedBrowser.contentDocument); + util.addObserver(this); }, cleanup: function () { this.cleanupProgressListener(); + this.observe.unregister(); }, getDefaultNames: function getDefaultNames(node) { @@ -199,7 +201,7 @@ var Buffer = Module("buffer", { if (!(uri || doc.location)) return; - uri = uri || util.newURI(doc.location.href); + uri = isObject(uri) ? uri : util.newURI(uri || doc.location.href); let args = { url: { toString: function () uri.spec, valueOf: function () uri }, title: doc.title @@ -222,6 +224,18 @@ var Buffer = Module("buffer", { commandline.clear(); }, + observers: { + "chrome-document-global-created": function (win, uri) { this.observe(win, "content-document-global-created", null); }, + "content-document-global-created": function (win, uri) { + let top = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); + + if (top == window) + this._triggerLoadAutocmd("PageLoadPre", win.document, win.location.href != "null" ? window.location.href : uri); + } + }, + onDOMContentLoaded: function onDOMContentLoaded(event) { let doc = event.originalTarget; if (doc instanceof HTMLDocument) @@ -269,8 +283,6 @@ var Buffer = Module("buffer", { // only thrown for the current tab, not when another tab changes if (flags & Ci.nsIWebProgressListener.STATE_START) { statusline.progress = 0; - - buffer._triggerLoadAutocmd("PageLoadPre", webProgress.DOMWindow.document); } else if (flags & Ci.nsIWebProgressListener.STATE_STOP) { // Workaround for bugs 591425 and 606877, dactyl bug #81 @@ -528,11 +540,8 @@ var Buffer = Module("buffer", { let range = selection.getRangeAt(0).cloneRange(); if (range.collapsed) { let re = options.get("iskeyword").regexp; - util.dump(String.quote(range)); Editor.extendRange(range, true, re, true); - util.dump(String.quote(range)); Editor.extendRange(range, false, re, true); - util.dump(String.quote(range) + "\n\n\n"); } return util.domToString(range); }, diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 9fc2f70e..8e9baae6 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -1832,8 +1832,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { function () { dactyl.restart(); }); function findToolbar(name) util.evaluateXPath( - "./*[@toolbarname=" + util.escapeString(name, "'") + "]", - toolbox).snapshotItem(0); + "//*[@toolbarname=" + util.escapeString(name, "'") + "]", + document).snapshotItem(0); var toolbox = document.getElementById("navigator-toolbox"); if (toolbox) { @@ -2017,7 +2017,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { completion.toolbar = function toolbar(context) { context.title = ["Toolbar"]; context.keys = { text: function (item) item.getAttribute("toolbarname"), description: function () "" }; - context.completions = util.evaluateXPath("./*[@toolbarname]", toolbox); + context.completions = util.evaluateXPath("//*[@toolbarname]", document); }; completion.window = function window(context) { diff --git a/common/content/hints.js b/common/content/hints.js index 7b6d6d52..2b7a6cab 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -1160,21 +1160,23 @@ var Hints = Module("hints", { }, options: function () { const DEFAULT_HINTTAGS = - util.makeXPath(["input[not(@type='hidden')]", "a", "area", "iframe", "textarea", "button", "select", - "*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @tabindex or @role='link' or @role='button']"]); - function xpath(arg) Option.quote(util.makeXPath(arg)); + function xpath(arg) util.makeXPath(arg); options.add(["extendedhinttags", "eht"], "XPath strings of hintable elements for extended hint modes", - "regexpmap", "[iI]:" + xpath(["img"]) + - ",[asOTivVWy]:" + xpath(["{a,area}[@href]", "{img,iframe}[@src]"]) + - ",[F]:" + xpath(["body", "code", "div", "html", "p", "pre", "span"]) + - ",[S]:" + xpath(["input[not(@type='hidden')]", "textarea", "button", "select"]), + "regexpmap", { + "[iI]": xpath(["img"]), + "[asOTivVWy]": xpath(["{a,area}[@href]", "{img,iframe}[@src]"]), + "[F]": xpath(["body", "code", "div", "html", "p", "pre", "span"]), + "[S]": xpath(["input[not(@type='hidden')]", "textarea", "button", "select"]) + }, { validator: Option.validateXPath }); options.add(["hinttags", "ht"], "XPath string of hintable elements activated by 'f' and 'F'", - "string", DEFAULT_HINTTAGS, + "string", xpath(["input[not(@type='hidden')]", "a", "area", "iframe", "textarea", "button", "select", + "*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or " + + "@tabindex or @role='link' or @role='button']"]), { validator: Option.validateXPath }); options.add(["hintkeys", "hk"], diff --git a/common/content/options.js b/common/content/options.js index 5ac9218e..67a4e3ec 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -62,6 +62,13 @@ var Option = Class("Option", { if (arguments.length > 3) { if (this.type == "string") defaultValue = Commands.quote(defaultValue); + + if (isObject(defaultValue)) + defaultValue = iter(defaultValue).map(function (val) val.map(Option.quote).join(":")).join(","); + + if (isArray(defaultValue)) + defaultValue = defaultValue.map(Option.quote).join(","); + this.defaultValue = this.parse(defaultValue); } diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index dbe669d4..1c53104f 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -81,7 +81,7 @@ update(Highlight.prototype, { get cssText() this.inheritedCSS + this.value, toString: function () "Highlight(" + this.class + ")\n\t" + - [k + ": " + String.quote(v) for ([k, v] in this)] .join("\n\t") + [k + ": " + String(v).quote() for ([k, v] in this)] .join("\n\t") }); /** diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index c9f59d6d..921e11bc 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -512,7 +512,7 @@ var Styles = Module("Styles", { { names: ["-name", "-n"], description: "The name of this stylesheet", - completer: function () [[k, v.css] for ([k, v] in Iterator(args["-group"].names))], + completer: function (context, args) [[k, v.css] for ([k, v] in Iterator(args["-group"].hive.names))], type: modules.CommandOption.STRING } ], diff --git a/common/modules/template.jsm b/common/modules/template.jsm index d3e7dcd0..be1e5ab7 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -6,7 +6,7 @@ Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("template", { - exports: ["Template", "template"], + exports: ["Binding", "Template", "template"], require: ["util"], use: ["services"] }, this); @@ -14,8 +14,9 @@ defineModule("template", { default xml namespace = XHTML; var Binding = Class("Binding", { - init: function (node) { + init: function (node, nodes) { this.node = node; + this.nodes = nodes; node.dactylBinding = this; Object.defineProperties(node, this.constructor.properties); @@ -32,9 +33,13 @@ var Binding = Class("Binding", { }, get collapsed() !!this.getAttribute("collapsed"), - __noSuchMethod__: function __noSuchMethod__(meth, args) { - return this.node[meth].apply(this.node, args); - } + __noSuchMethod__: Class.Property({ + configurable: true, + writeable: true, + value: function __noSuchMethod__(meth, args) { + return this.node[meth].apply(this.node, args); + } + }) }, { get bindings() { let bindingProto = Object.getPrototypeOf(Binding.prototype); @@ -66,10 +71,12 @@ var Binding = Class("Binding", { for (let obj in this.bindings) for (let prop in properties(obj)) { let desc = Object.getOwnPropertyDescriptor(obj, prop); - for (let k in values(["get", "set", "value"])) - if (typeof desc[k] === "function") - desc[k] = this.bind(desc[k]); - res[prop] = desc; + if (desc.enumerable) { + for (let k in values(["get", "set", "value"])) + if (typeof desc[k] === "function") + desc[k] = this.bind(desc[k]); + res[prop] = desc; + } } return res; }) diff --git a/common/modules/util.jsm b/common/modules/util.jsm index aa3d7d71..5cd21681 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -1083,6 +1083,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), this._loadOverlay(window, obj(window)); } }, + _loadOverlay: function _loadOverlay(window, obj) { let doc = window.document; if (!doc.dactylOverlayElements) {