X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fstyles.jsm;fp=common%2Fmodules%2Fstyles.jsm;h=9ee7f6286f581ca56f5b6630946c4c13a8cdb2cc;hb=9044153cb63835e39b9de8ec4ade237c03e3888a;hp=70608b9fb170eca5cddec2992b490b093028bb25;hpb=70740024f9c028c1fd63e1a1850ab062ff956054;p=dactyl.git diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 70608b9..9ee7f62 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -2,13 +2,12 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -"use strict"; +/* use strict */ Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("styles", { exports: ["Style", "Styles", "styles"], - require: ["services", "util"], - use: ["contexts", "messages", "template"] + require: ["services", "util"] }, this); function cssUri(css) "chrome-data:text/css," + encodeURI(css); @@ -74,11 +73,11 @@ update(Sheet.prototype, { return preamble + css; let selectors = filter.map(function (part) - !/^(?:[a-z-]+[:*]|[a-z-.]+$)/i.test(part) ? "regexp(" + (".*(?:" + part + ").*").quote() + ")" : + !/^(?:[a-z-]+[:*]|[a-z-.]+$)/i.test(part) ? "regexp(" + Styles.quote(".*(?:" + part + ").*") + ")" : (/[*]$/.test(part) ? "url-prefix" : /[\/:]/.test(part) ? "url" : "domain") - + '("' + part.replace(/"/g, "%22").replace(/\*$/, "") + '")') + + '(' + Styles.quote(part.replace(/\*$/, "")) + ')') .join(",\n "); return preamble + "@-moz-document " + selectors + " {\n\n" + css + "\n\n}\n"; @@ -97,7 +96,7 @@ var Hive = Class("Hive", { get modifiable() this.name !== "system", addRef: function (obj) { - this.refs.push(Cu.getWeakReference(obj)); + this.refs.push(util.weakReference(obj)); this.dropRef(null); }, dropRef: function (obj) { @@ -254,12 +253,14 @@ var Styles = Module("Styles", { this.cleanup(); this.allSheets = {}; - services["dactyl:"].providers["style"] = function styleProvider(uri) { - let id = /^\/(\d*)/.exec(uri.path)[1]; - if (Set.has(styles.allSheets, id)) - return ["text/css", styles.allSheets[id].fullCSS]; - return null; - }; + update(services["dactyl:"].providers, { + "style": function styleProvider(uri, path) { + let id = parseInt(path); + if (Set.has(styles.allSheets, id)) + return ["text/css", styles.allSheets[id].fullCSS]; + return null; + } + }); }, cleanup: function cleanup() { @@ -434,6 +435,7 @@ var Styles = Module("Styles", { else test = function test(uri) { try { return util.isSubdomain(uri.host, filter); } catch (e) { return false; } }; test.toString = function toString() filter; + test.key = filter; if (arguments.length < 2) return test; return test(arguments[1]); @@ -529,7 +531,17 @@ var Styles = Module("Styles", { | [^;}\s]+ ) ]]>, "gix", this) - }) + }), + + /** + * Quotes a string for use in CSS stylesheets. + * + * @param {string} str + * @returns {string} + */ + quote: function quote(str) { + return '"' + str.replace(/([\\"])/g, "\\$1").replace(/\n/g, "\\00000a") + '"'; + }, }, { commands: function (dactyl, modules, window) { const { commands, contexts, styles } = modules; @@ -616,9 +628,10 @@ var Styles = Module("Styles", { command: "style", arguments: [style.sites.join(",")], literalArg: style.css, - options: update( - hive.name == "user" ? {} : { "-group": hive.name }, - style.name ? { "-name": style.name } : {}) + options: { + "-group": hive.name == "user" ? undefined : hive.name, + "-name": style.name || undefined + } }))) .flatten().array }); @@ -701,7 +714,7 @@ var Styles = Module("Styles", { })); }, completion: function (dactyl, modules, window) { - const names = Array.slice(util.computedStyle(window.document.createElement("div"))); + const names = Array.slice(DOM(
, window.document).style); modules.completion.css = function (context) { context.title = ["CSS Property"]; context.keys = { text: function (p) p + ":", description: function () "" }; @@ -716,7 +729,7 @@ var Styles = Module("Styles", { }; }, javascript: function (dactyl, modules, window) { - modules.JavaScript.setCompleter(["get", "add", "remove", "find"].map(function (m) styles.user[m]), + modules.JavaScript.setCompleter(["get", "add", "remove", "find"].map(function (m) Hive.prototype[m]), [ // Prototype: (name, filter, css, index) function (context, obj, args) this.names, function (context, obj, args) Styles.completeSite(context, window.content), @@ -730,8 +743,10 @@ var Styles = Module("Styles", { template.highlightCSS = function highlightCSS(css) { XML.prettyPrinting = XML.ignoreWhitespace = false; - return this.highlightRegexp(css, patterns.property, function (match) <>{ - match.preSpace}{template.filter(match.name)}: { + return this.highlightRegexp(css, patterns.property, function (match) { + if (!match.length) + return <>; + return <>{match.preSpace}{template.filter(match.name)}: { template.highlightRegexp(match.value, patterns.token, function (match) { if (match.function) @@ -748,7 +763,7 @@ var Styles = Module("Styles", { }) }{ match.postSpace } - ) + }) } }, });