diff --git a/common/content/buffer.js b/common/content/buffer.js index 81b75a68..732f4ae5 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -46,8 +46,8 @@ function Buffer() //{{{ let fontSize = util.computedStyle(document.getElementById(mainWindowID)).fontSize; styles.registerSheet("chrome://liberator/skin/liberator.css"); - let error = styles.addSheet("font-size", "chrome://liberator/content/buffer.xhtml", - "body { font-size: " + fontSize + "; }", true); + let error = styles.addSheet(true, "font-size", "chrome://liberator/content/buffer.xhtml", + "body { font-size: " + fontSize + "; }"); if ("ZoomManager" in window) { diff --git a/common/content/completion.js b/common/content/completion.js index 2c119f95..7eee6591 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -920,8 +920,9 @@ function Completion() //{{{ case "}": pop("{"); /* Fallthrough */ case ";": top[FULL_STATEMENTS].push(i); + break; case ",": - top[COMMA]; + top[COMMA].push(i); break; } @@ -1158,6 +1159,7 @@ function Completion() //{{{ let [offset, obj, func] = getObjKey(-3); if (!obj.length) return; + obj = obj.slice(0, 1); try { @@ -1176,7 +1178,7 @@ function Completion() //{{{ { let arg = str.substring(prev + 1, idx); prev = idx; - args.__defineGetter__(i, function () self.eval(ret)); + args.__defineGetter__(i, function () self.eval(arg)); } let key = getKey(); args.push(key + string); diff --git a/common/content/hints.js b/common/content/hints.js index 283e153b..27a1dbb5 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -271,7 +271,7 @@ function Hints() //{{{ css.push(highlight.selector(group) + "[number='" + elem.getAttribute("number") + "'] { " + elem.style.cssText + " }"); } } - styles.addSheet("hint-positions", "*", css.join("\n"), true, true); + styles.addSheet(true, "hint-positions", "*", css.join("\n")); } return true; @@ -296,7 +296,7 @@ function Hints() //{{{ if (timeout && firstElem) setTimeout(function () { firstElem.removeAttributeNS(NS.uri, "highlight"); }, timeout); } - styles.removeSheet("hint-positions", null, null, null, true); + styles.removeSheet(true, "hint-positions"); reset(); } diff --git a/common/content/liberator.js b/common/content/liberator.js index 015adf07..9bcf8e2d 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -124,9 +124,9 @@ const liberator = (function () //{{{ let class = dir.map(function (dir) "html|html > xul|scrollbar[orient=" + dir + "]"); if (class.length) - styles.addSheet("scrollbar", "*", class.join(", ") + " { visibility: collapse !important; }", true, true); + styles.addSheet(true, "scrollbar", "*", class.join(", ") + " { visibility: collapse !important; }"); else - styles.removeSheet("scrollbar", null, null, null, true); + styles.removeSheet(true, "scrollbar"); options.safeSetPref("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2); }, validator: function (opts) (opts.indexOf("l") < 0 || opts.indexOf("r") < 0) @@ -140,7 +140,7 @@ const liberator = (function () //{{{ { let classes = [v[1] for ([k, v] in Iterator(this.opts)) if (opts.indexOf(k) < 0)]; let css = classes.length ? classes.join(",") + "{ display: none; }" : ""; - styles.addSheet("taboptions", "chrome://*", css, true, true); + styles.addSheet(true, "taboptions", "chrome://*", css); statusline.updateTabCount(); } } diff --git a/common/content/style.js b/common/content/style.js index d2ef4d57..79f616e9 100644 --- a/common/content/style.js +++ b/common/content/style.js @@ -158,7 +158,7 @@ function Highlights(name, store, serial) return "Unknown highlight keyword: " + class; let style = highlight[key] || new Highlight(key); - styles.removeSheet(style.selector, null, null, null, true); + styles.removeSheet(true, style.selector); if (append) newStyle = (style.value || "").replace(/;?\s*$/, "; " + newStyle); @@ -169,7 +169,7 @@ function Highlights(name, store, serial) if (style.default == null) { delete highlight[style.class]; - styles.removeSheet(style.selector, null, null, null, true); + styles.removeSheet(true, style.selector); return null; } newStyle = style.default; @@ -180,7 +180,7 @@ function Highlights(name, store, serial) .replace(";!important;", ";", "g"); // Seeming Spidermonkey bug css = style.selector + " { " + css + " }"; - let error = styles.addSheet(style.selector, style.filter, css, true); + let error = styles.addSheet(true, style.selector, style.filter, css); if (error) return error; style.value = newStyle; @@ -272,22 +272,23 @@ function Styles(name, store, serial) /** * Add a new stylesheet. * + * @param {boolean} system Declares whether this is a system or + * user sheet. System sheets are used internally by + * @liberator. +>>>>>>> master:common/content/style.js * @param {string} name The name given to the stylesheet by * which it may be later referenced. * @param {string} filter The sites to which this sheet will * apply. Can be a domain name or a URL. Any URL ending in * "*" is matched as a prefix. * @param {string} css The CSS to be applied. - * @param {boolean} system Declares whether this is a system or - * user sheet. System sheets are used internally by - * @liberator. */ - this.addSheet = function (name, filter, css, system) + this.addSheet = function (system, name, filter, css) { let sheets = system ? systemSheets : userSheets; let names = system ? systemNames : userNames; if (name && name in names) - this.removeSheet(name, null, null, null, system); + this.removeSheet(system, name); let sheet = sheets.filter(function (s) s.sites.join(",") == filter && s.css == css)[0]; if (!sheet) @@ -315,11 +316,27 @@ function Styles(name, store, serial) return null; }; + /** + * Get a sheet with a given name or index. + * + * @param {boolean} system + * @param {string or number} sheet The sheet to retrieve. Strings indicate + * sheet names, while numbers indicate indices. + */ + this.get = function get(system, sheet) + { + let sheets = system ? systemSheets : userSheets; + let names = system ? systemNames : userNames; + if (typeof sheet == "number") + return sheets[sheet]; + return names[sheet] + }; + /** * Find sheets matching the parameters. See {@link #addSheet} * for parameters. */ - this.findSheets = function (name, filter, css, index, system) + this.findSheets = function (system, name, filter, css, index) { let sheets = system ? systemSheets : userSheets; let names = system ? systemNames : userNames; @@ -343,7 +360,7 @@ function Styles(name, store, serial) * are removed from matching sheets. If any remain, the sheet is * left in place. */ - this.removeSheet = function (name, filter, css, index, system) + this.removeSheet = function (system, name, filter, css, index) { let self = this; let sheets = system ? systemSheets : userSheets; @@ -351,12 +368,12 @@ function Styles(name, store, serial) if (filter && filter.indexOf(",") > -1) return filter.split(",").reduce( - function (n, f) n + self.removeSheet(name, f, index, system), 0); + function (n, f) n + self.removeSheet(system, name, f, index), 0); if (filter == undefined) filter = ""; - let matches = this.findSheets(name, filter, css, index, system); + let matches = this.findSheets(system, name, filter, css, index); if (matches.length == 0) return; @@ -379,7 +396,7 @@ function Styles(name, store, serial) { let sites = sheet.sites.filter(function (f) f != filter); if (sites.length) - this.addSheet(name, sites.join(","), css, system, true); + this.addSheet(system, name, sites.join(","), css); } } return matches.length; @@ -451,7 +468,19 @@ function Styles(name, store, serial) let (array = util.Array) { Styles.prototype = { - get sites() array.uniq(array.flatten([v.sites for ([k, v] in this.userSheets)])) + get sites() array.uniq(array.flatten([v.sites for ([k, v] in this.userSheets)])), + completeSite: function (context, content) + { + let compl = []; + try + { + compl.push([content.location.host, "Current Host"]); + compl.push([content.location.href, "Current URL"]); + } + catch (e) {} + context.anchored = false; + context.completions = compl.concat([[s, ""] for each (s in styles.sites)]); + } }; } @@ -471,6 +500,18 @@ highlight.reload(); liberator.triggerObserver("load_styles", "styles"); liberator.triggerObserver("load_highlight", "highlight"); +liberator.registerObserver("load_completion", function () +{ + completion.setFunctionCompleter(["get", "addSheet", "removeSheet", "findSheets"].map(function (m) styles[m]), + [ // Prototype: (system, name, filter, css, index) + null, + function (context, obj, args) args[0] ? styles.systemNames : styles.userNames, + function (context, obj, args) styles.completeSite(context, content), + null, + function (context, obj, args) args[0] ? styles.systemSheets : styles.userSheets + ]); +}); + liberator.registerObserver("load_commands", function () { // TODO: :colo default needs :hi clear @@ -513,14 +554,14 @@ liberator.registerObserver("load_commands", function () { if ("-append" in args) { - let sheet = styles.findSheets(name, null, null, null, false)[0]; + let sheet = styles.get(false, name); if (sheet) { filter = sheet.sites.concat(filter).join(","); css = sheet.css.replace(/;?\s*$/, "; " + css); } } - let err = styles.addSheet(name, filter, css, false, args.bang); + let err = styles.addSheet(false, name, filter, css); if (err) liberator.echoerr(err); } @@ -532,18 +573,11 @@ liberator.registerObserver("load_commands", function () let compl = []; if (args.completeArg == 0) { - try - { - compl.push([content.location.host, "Current Host"]); - compl.push([content.location.href, "Current URL"]); - } - catch (e) {} - context.anchored = false; - context.completions = compl.concat([[s, ""] for each (s in styles.sites)]); + styles.completeSite(context, content); } else if (args.completeArg == 1) { - let sheet = styles.findSheets(args["-name"], null, null, null, false)[0]; + let sheet = styles.get(false, args["-name"]); if (sheet) context.completions = [[sheet.css, "Current Value"]]; } @@ -567,7 +601,7 @@ liberator.registerObserver("load_commands", function () "Remove a user stylesheet", function (args) { - styles.removeSheet(args["-name"], args[0], args.literalArg, args["-index"], false); + styles.removeSheet(false, args["-name"], args[0], args.literalArg, args["-index"]); }, { completer: function (context) { context.completions = styles.sites.map(function (site) [site, ""]); }, diff --git a/common/content/tabs.js b/common/content/tabs.js index fd3c6a24..6436f8ea 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -220,8 +220,8 @@ function Tabs() //{{{ }); let fragment = liberator.has("MacUnix") ? "tab-mac" : "tab"; // TODO: Add option, or only apply when go~=[nN] - styles.addSheet("tab-binding", "chrome://browser/content/browser.xul", - ".tabbrowser-tab { -moz-binding: url(chrome://liberator/content/bindings.xml#" + fragment + ") !important; }", true); + styles.addSheet(true, "tab-binding", "chrome://browser/content/browser.xul", + ".tabbrowser-tab { -moz-binding: url(chrome://liberator/content/bindings.xml#" + fragment + ") !important; }"); } diff --git a/common/content/ui.js b/common/content/ui.js index bd5a8dfa..1e55e730 100644 --- a/common/content/ui.js +++ b/common/content/ui.js @@ -883,9 +883,9 @@ function CommandLine() //{{{ set silent(val) { silent = val; if (silent) - storage.styles.addSheet("silent-mode", "chrome://*", "#liberator-commandline > * { opacity: 0 }", true, true); + storage.styles.addSheet(true, "silent-mode", "chrome://*", "#liberator-commandline > * { opacity: 0 }"); else - storage.styles.removeSheet("silent-mode", null, null, null, true); + storage.styles.removeSheet(true, "silent-mode"); }, runSilently: function (fn, self)