// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
lazyRequire("io", ["io"]);
lazyRequire("finder", ["RangeFind"]);
lazyRequire("overlay", ["overlay"]);
+lazyRequire("promises", ["Promise", "promises"]);
lazyRequire("sanitizer", ["sanitizer"]);
lazyRequire("storage", ["File", "storage"]);
lazyRequire("template", ["template"]);
this.win = win;
},
- get addPageInfoSection() Buffer.closure.addPageInfoSection,
+ get addPageInfoSection() Buffer.bound.addPageInfoSection,
get pageInfo() Buffer.pageInfo,
);
},
+ /**
+ * 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.
*
* @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.
* @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;
};
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();
return newURI.spec;
}
- for each (let shortener in Buffer.uriShorteners)
+ for (let shortener of Buffer.uriShorteners)
try {
let shortened = shortener(uri, doc);
if (shortened)
}
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;
},
* @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;
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;
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);
}
}
/**
* 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];
}
}),
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";
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"));
},
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;
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;
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;