Prepare the Debian package upload (update release and timestamp in changelog)
[conkeror.git] / modules / stylesheet.js
blob5a60665c6feda630c70daf895bca2ccada87321c
1 /**
2  * (C) Copyright 2004-2007 Shawn Betts
3  * (C) Copyright 2007-2010 John J. Foerch
4  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 in_module(null);
12 function register_user_stylesheet (url) {
13     var uri = make_uri(url);
14     var sss = Cc["@mozilla.org/content/style-sheet-service;1"]
15         .getService(Ci.nsIStyleSheetService);
16     sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
19 function unregister_user_stylesheet (url) {
20     var uri = make_uri(url);
21     var sss = Cc["@mozilla.org/content/style-sheet-service;1"]
22         .getService(Ci.nsIStyleSheetService);
23     if (sss.sheetRegistered(uri, sss.USER_SHEET))
24         sss.unregisterSheet(uri, sss.USER_SHEET);
27 function register_agent_stylesheet (url) {
28     var uri = make_uri(url);
29     var sss = Cc["@mozilla.org/content/style-sheet-service;1"]
30         .getService(Ci.nsIStyleSheetService);
31     sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
34 function unregister_agent_stylesheet (url) {
35     var uri = make_uri(url);
36     var sss = Cc["@mozilla.org/content/style-sheet-service;1"]
37         .getService(Ci.nsIStyleSheetService);
38     if (sss.sheetRegistered(uri, sss.AGENT_SHEET))
39         sss.unregisterSheet(uri, sss.AGENT_SHEET);
42 function agent_stylesheet_registered_p (url) {
43     var uri = make_uri(url);
44     var sss = Cc["@mozilla.org/content/style-sheet-service;1"]
45         .getService(Ci.nsIStyleSheetService);
46     return sss.sheetRegistered(uri, sss.AGENT_SHEET);
49 function user_stylesheet_registered_p (url) {
50     var uri = make_uri(url);
51     var sss = Cc["@mozilla.org/content/style-sheet-service;1"]
52         .getService(Ci.nsIStyleSheetService);
53     return sss.sheetRegistered(uri, sss.USER_SHEET);
56 /**
57  * make_css_data_uri takes specifications for a css data uri in its
58  * positional and keyword arguments, and returns a new nsIURI object.
59  *
60  * rules: css rules, not including any @namespace or @-moz-document
61  *        headers.  given as a string or an array of strings.
62  *
63  * $namespace: optional string url for a @namespace header.
64  *
65  * $domains: optional string, or array of strings, for a @-moz-document
66  *           domain(...) header.
67  *
68  * $urls: optional string, or array of strings, for a @-moz-document
69  *        url(...) header.
70  *
71  * $url_prefixes: optional string, or array of strings, for a
72  *                @-moz-document url-prefix(...) header.
73  */
74 define_keywords("$namespace", "$domains", "$urls", "$url_prefixes");
75 function make_css_data_uri (rules) {
76     keywords(arguments);
77     var namespace = arguments.$namespace;
78     var domains = arguments.$domains;
79     var urls = arguments.$urls;
80     var url_prefixes = arguments.$url_prefixes;
81     rules = make_array(rules).join("\n");
82     var restrictions = Array.prototype.concat(
83         make_array(domains).map(function (x) "domain("+x+")"),
84         make_array(urls).map(function (x) "url("+x+")"),
85         make_array(url_prefixes).map(function (x) "url-prefix("+x+")"))
86         .join(",\n");
87     if (restrictions)
88         rules = "@-moz-document "+restrictions+" {\n"+rules+"\n}";
89     if (namespace)
90         rules = "@namespace url("+namespace+");\n"+rules;
91     return make_uri("data:text/css,"+escape(rules));
94 provide("stylesheet");