X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fbuffer.jsm;fp=common%2Fmodules%2Fbuffer.jsm;h=97398efa920803e5a35375396ddf893eb8fcc43f;hb=0bcd111e64a8cb0f8019a4cb3270fc5b46270a1b;hp=97b37b25787e0e88a1ba67e5efcb81b06c02d615;hpb=4385b68da3a031ef7347f966df57b6e52d48ec94;p=dactyl.git diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index 97b37b2..97398ef 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -1,6 +1,6 @@ // Copyright (c) 2006-2008 by Martin Stubenschrott // Copyright (c) 2007-2011 by Doug Kearns -// Copyright (c) 2008-2013 Kris Maglione +// Copyright (c) 2008-2014 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. @@ -16,6 +16,7 @@ lazyRequire("contexts", ["Group"]); lazyRequire("io", ["io"]); lazyRequire("finder", ["RangeFind"]); lazyRequire("overlay", ["overlay"]); +lazyRequire("promises", ["Promise", "promises"]); lazyRequire("sanitizer", ["sanitizer"]); lazyRequire("storage", ["File", "storage"]); lazyRequire("template", ["template"]); @@ -45,7 +46,7 @@ var Buffer = Module("Buffer", { this.win = win; }, - get addPageInfoSection() Buffer.closure.addPageInfoSection, + get addPageInfoSection() Buffer.bound.addPageInfoSection, get pageInfo() Buffer.pageInfo, @@ -68,6 +69,71 @@ var Buffer = Module("Buffer", { ); }, + /** + * The load context of the window bound to this buffer. + */ + get loadContext() sanitizer.getContext(this.win), + + /** + * Content preference methods. + */ + prefs: Class.Memoize(function () + let (self = this) ({ + /** + * Returns a promise for the given preference name. + * + * @param {string} pref The name of the preference to return. + * @returns {Promise<*>} + */ + get: promises.withCallbacks(function get([resolve, reject], pref) { + let val = services.contentPrefs.getCachedByDomainAndName( + self.uri.spec, pref, self.loadContext); + + let found = false; + if (val) + resolve(val.value); + else + services.contentPrefs.getByDomainAndName( + self.uri.spec, pref, self.loadContext, + { handleCompletion: () => { + if (!found) + resolve(undefined); + }, + handleResult: (pref) => { + found = true; + resolve(pref.value); + }, + handleError: reject }); + }), + + /** + * Sets a content preference for the given buffer. + * + * @param {string} pref The preference to set. + * @param {string} value The value to store. + */ + set: promises.withCallbacks(function set([resolve, reject], pref, value) { + services.contentPrefs.set( + self.uri.spec, pref, value, self.loadContext, + { handleCompletion: () => {}, + handleResult: resolve, + handleError: reject }); + }), + + /** + * Clear a content preference for the given buffer. + * + * @param {string} pref The preference to clear. + */ + clear: promises.withCallbacks(function clear([resolve, reject], pref) { + services.contentPrefs.removeByDomainAndName( + self.uri.spec, pref, self.loadContext, + { handleCompletion: () => {}, + handleResult: resolve, + handleError: reject }); + }) + })), + /** * Gets a content preference for the given buffer. * @@ -77,14 +143,10 @@ var Buffer = Module("Buffer", { * @returns {string|number|boolean} The value of the preference, if * callback is not provided. */ - getPref: function getPref(pref, callback) { - // God damn it. - if (config.haveGecko("19.0a1")) - services.contentPrefs.getPref(this.uri, pref, - sanitizer.getContext(this.win), callback); - else - services.contentPrefs.getPref(this.uri, pref, callback); - }, + getPref: deprecated("prefs.get", function getPref(pref, callback) { + services.contentPrefs.getPref(this.uri, pref, + this.loadContext, callback); + }), /** * Sets a content preference for the given buffer. @@ -92,20 +154,20 @@ var Buffer = Module("Buffer", { * @param {string} pref The preference to set. * @param {string} value The value to store. */ - setPref: function setPref(pref, value) { + setPref: deprecated("prefs.set", function setPref(pref, value) { services.contentPrefs.setPref( - this.uri, pref, value, sanitizer.getContext(this.win)); - }, + this.uri, pref, value, this.loadContext); + }), /** * Clear a content preference for the given buffer. * * @param {string} pref The preference to clear. */ - clearPref: function clearPref(pref) { + clearPref: deprecated("prefs.clear", function clearPref(pref) { services.contentPrefs.removePref( - this.uri, pref, sanitizer.getContext(this.win)); - }, + this.uri, pref, this.loadContext); + }), climbUrlPath: function climbUrlPath(count) { let { dactyl } = this.modules; @@ -525,8 +587,6 @@ var Buffer = Module("Buffer", { }; DOM(elem).mousedown(params).mouseup(params); - if (!config.haveGecko("2b")) - DOM(elem).click(params); let sel = util.selectionController(win); sel.getSelection(sel.SELECTION_FOCUS_REGION).collapseToStart(); @@ -633,7 +693,7 @@ var Buffer = Module("Buffer", { return newURI.spec; } - for each (let shortener in Buffer.uriShorteners) + for (let shortener of Buffer.uriShorteners) try { let shortened = shortener(uri, doc); if (shortened) @@ -644,9 +704,10 @@ var Buffer = Module("Buffer", { } let link = DOM("link[href][rev=canonical], \ - link[href][rel=shortlink]", doc); - if (link.length) - return hashify(link.attr("href")); + link[href][rel=shortlink]", doc) + .attr("href"); + if (link) + return hashify(link); return null; }, @@ -793,7 +854,7 @@ var Buffer = Module("Buffer", { * @param {number} count The multiple of 'scroll' lines to scroll. * @optional */ - scrollByScrollSize: function scrollByScrollSize(direction, count = 1) { + scrollByScrollSize: function scrollByScrollSize(direction, count=1) { let { options } = this.modules; direction = direction ? 1 : -1; @@ -1104,7 +1165,7 @@ var Buffer = Module("Buffer", { else { let url = loc || doc.location.href; const PREFIX = "view-source:"; - if (url.indexOf(PREFIX) == 0) + if (url.startsWith(PREFIX)) url = url.substr(PREFIX.length); else url = PREFIX + url; @@ -1249,12 +1310,12 @@ var Buffer = Module("Buffer", { if (prefs.get("browser.zoom.siteSpecific")) { var privacy = sanitizer.getContext(this.win); if (value == 1) { - this.clearPref("browser.content.full-zoom"); - this.clearPref("dactyl.content.full-zoom"); + this.prefs.clear("browser.content.full-zoom"); + this.prefs.clear("dactyl.content.full-zoom"); } else { - this.setPref("browser.content.full-zoom", value); - this.setPref("dactyl.content.full-zoom", fullZoom); + this.prefs.set("browser.content.full-zoom", value); + this.prefs.set("dactyl.content.full-zoom", fullZoom); } } @@ -1264,15 +1325,15 @@ var Buffer = Module("Buffer", { /** * Updates the zoom level of this buffer from a content preference. */ - updateZoom: util.wrapCallback(function updateZoom() { + updateZoom: promises.task(function updateZoom() { let uri = this.uri; if (prefs.get("browser.zoom.siteSpecific")) { - this.getPref("dactyl.content.full-zoom", (val) => { - if (val != null && uri.equals(this.uri) && val != prefs.get("browser.zoom.full")) - [this.contentViewer.textZoom, this.contentViewer.fullZoom] = - [this.contentViewer.fullZoom, this.contentViewer.textZoom]; - }); + let val = yield this.prefs.get("dactyl.content.full-zoom"); + + if (val != null && uri.equals(this.uri) && val != prefs.get("browser.zoom.full")) + [this.contentViewer.textZoom, this.contentViewer.fullZoom] = + [this.contentViewer.fullZoom, this.contentViewer.textZoom]; } }), @@ -1751,7 +1812,7 @@ var Buffer = Module("Buffer", { let arg = args[0]; // FIXME: arg handling is a bit of a mess, check for filename - dactyl.assert(!arg || arg[0] == ">" && !config.OS.isWindows, + dactyl.assert(!arg || arg[0] == ">", _("error.trailingCharacters")); const PRINTER = "PostScript/default"; @@ -1761,26 +1822,25 @@ var Buffer = Module("Buffer", { BRANCHES.forEach(function (branch) { prefs.set(branch + pref, value); }); } - prefs.withContext(function () { - if (arg) { - prefs.set("print.print_printer", PRINTER); - - let { path } = io.File(arg.substr(1)); - set("print_to_file", true); - set("print_to_filename", path); - prefs.set("print_to_filename", path); + let settings = services.printSettings.newPrintSettings; + settings.printSilent = args.bang; + if (arg) { + settings.printToFile = true; + settings.toFileName = io.File(arg.substr(1)).path; + settings.outputFormat = settings.kOutputFormatPDF; - dactyl.echomsg(_("print.toFile", arg.substr(1))); - } - else - dactyl.echomsg(_("print.sending")); + dactyl.echomsg(_("print.toFile", arg.substr(1))); + } + else { + dactyl.echomsg(_("print.sending")); - prefs.set("print.always_print_silent", args.bang); if (false) prefs.set("print.show_print_progress", !args.bang); + } - config.browser.contentWindow.print(); - }); + config.browser.contentWindow + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebBrowserPrint).print(settings, null); dactyl.echomsg(_("print.sent")); }, @@ -2009,7 +2069,7 @@ var Buffer = Module("Buffer", { events: function initEvents(dactyl, modules, window) { let { buffer, config, events } = modules; - events.listen(config.browser, "scroll", buffer.closure._updateBufferPosition, false); + events.listen(config.browser, "scroll", buffer.bound._updateBufferPosition, false); }, mappings: function initMappings(dactyl, modules, window) { let { Editor, Events, buffer, editor, events, ex, mappings, modes, options, tabs } = modules; @@ -2230,7 +2290,7 @@ var Buffer = Module("Buffer", { elem = DOM(elem); - if (elem[0].readOnly || !DOM(elem).isEditable) + if (elem[0].readOnly || elem[0].disabled || !DOM(elem).isEditable) return false; let style = elem.style; @@ -2428,10 +2488,9 @@ var Buffer = Module("Buffer", { if (/^func:/.test(filter.result)) var res = dactyl.userEval("(" + Option.dequote(filter.result.substr(5)) + ")")(doc, line); else - res = iter.nth(filter.matcher(doc), - elem => ((elem.nodeValue || elem.textContent).trim() == line && - DOM(elem).display != "none"), - 0) + res = iter.find(filter.matcher(doc), + elem => ((elem.nodeValue || elem.textContent).trim() == line && + DOM(elem).display != "none")) || iter.nth(filter.matcher(doc), util.identity, line - 1); if (res) break;