1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 09:48:00 +01:00

Bunch-o-fixes, plus some non-trivial changes that I may wind up weeding out.

This commit is contained in:
Kris Maglione
2008-10-04 04:08:03 +00:00
parent 3ceecbaf52
commit 1891746b9e
15 changed files with 144 additions and 93 deletions

View File

@@ -47,7 +47,7 @@ liberator.Buffer = function () //{{{
const sss = Components.classes["@mozilla.org/content/style-sheet-service;1"] const sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
.getService(Components.interfaces.nsIStyleSheetService); .getService(Components.interfaces.nsIStyleSheetService);
let cssUri = function (css) ios.newURI("data:text/css," + encodeURI(css), null, null); let cssUri = function (css) "data:text/css," + encodeURI(css);
let sheets = []; let sheets = [];
this.__iterator__ = function () Iterator(sheets); this.__iterator__ = function () Iterator(sheets);
@@ -58,15 +58,11 @@ liberator.Buffer = function () //{{{
if (errors.length) if (errors.length)
return errors.map(function (e) "CSS: " + filter + ": " + e).join("\n"); return errors.map(function (e) "CSS: " + filter + ": " + e).join("\n");
let chrome = /^chrome:/.test(filter);
if (chrome)
return "Chrome styling not supported"; /* For now. */
if (sheets.some(function (s) s[0] == filter && s[1] == css)) if (sheets.some(function (s) s[0] == filter && s[1] == css))
return null; return null;
sheets.push([filter, css]); sheets.push([filter, css]);
let uri = cssUri(wrapCSS(filter, css)); let uri = cssUri(wrapCSS(filter, css));
sss.loadAndRegisterSheet(uri, sss.USER_SHEET); this.registerSheet(uri, sss.USER_SHEET);
return null; return null;
} }
@@ -76,10 +72,24 @@ liberator.Buffer = function () //{{{
return false; return false;
let sheet = sheets.splice(number)[0]; let sheet = sheets.splice(number)[0];
let uri = cssUri(wrapCSS(sheet[0], sheet[1])); let uri = cssUri(wrapCSS(sheet[0], sheet[1]));
sss.unregisterSheet(uri, sss.USER_SHEET); this.unregisterSheet(uri, sss.USER_SHEET);
return true; return true;
} }
this.registerSheet = function (uri)
{
let uri = ios.newURI(uri, null, null);
if (!sss.sheetRegistered(uri, sss.USER_SHEET))
sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
}
this.unregisterSheet = function (uri)
{
let uri = ios.newURI(uri, null, null);
if (sss.sheetRegistered(uri, sss.USER_SHEET))
sss.unregisterSheet(uri, sss.USER_SHEET);
}
function wrapCSS(filter, css) function wrapCSS(filter, css)
{ {
if (filter == "*") if (filter == "*")
@@ -91,11 +101,12 @@ liberator.Buffer = function () //{{{
/* } vim */ /* } vim */
} }
let queryinterface = XPCOMUtils.generateQI([Components.interfaces.nsIConsoleListener]);
function checkSyntax(css) function checkSyntax(css)
{ {
let errors = []; let errors = [];
let listener = { let listener = {
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIConsoleListener]), QueryInterface: queryinterface,
observe: function (message) observe: function (message)
{ {
try try
@@ -116,7 +127,7 @@ liberator.Buffer = function () //{{{
{ {
var doc = document.implementation.createDocument(XHTML, "doc", null); var doc = document.implementation.createDocument(XHTML, "doc", null);
doc.documentElement.appendChild(liberator.util.xmlToDom( doc.documentElement.appendChild(liberator.util.xmlToDom(
<html><head><link type="text/css" rel="stylesheet" href={cssUri(css).spec}/></head></html>, doc)); <html><head><link type="text/css" rel="stylesheet" href={cssUri(css)}/></head></html>, doc));
while (true) while (true)
{ {
@@ -126,7 +137,7 @@ liberator.Buffer = function () //{{{
break; break;
} catch (e) { } catch (e) {
if (e.name != "NS_ERROR_DOM_INVALID_ACCESS_ERR") if (e.name != "NS_ERROR_DOM_INVALID_ACCESS_ERR")
throw e; return [e.toString()];
liberator.sleep(10); liberator.sleep(10);
} }
} }
@@ -141,6 +152,18 @@ liberator.Buffer = function () //{{{
let styles = liberator.storage.newObject(styles, Styles, false); let styles = liberator.storage.newObject(styles, Styles, false);
for (let sheet in arrayIter(liberator.config.userSheets || []))
styles.registerSheet(sheet);
/* FIXME: This doesn't belong here. */
let mainWindowID = liberator.config.mainWindowID || "main-window";
let fontSize = document.defaultView.getComputedStyle(document.getElementById(mainWindowID), null)
.getPropertyValue("font-size");
let name = liberator.config.name.toLowerCase();
let error = styles.addSheet("chrome://" + name + "/skin/blank-" + name + ".xhtml",
"body { font-size: " + fontSize + "}");
function setZoom(value, fullZoom) function setZoom(value, fullZoom)
{ {
if (value < 1 || value > 2000) if (value < 1 || value > 2000)
@@ -1375,10 +1398,14 @@ liberator.Buffer = function () //{{{
// add the frame indicator // add the frame indicator
var doc = frames[next].document; var doc = frames[next].document;
var indicator =
<div id="liberator-frame-indicator" /* Doesn't unapply...
style="background-color: red; opacity: 0.5; z-index: 999 var class = doc.body.class || "";
position: fixed; top: 0; bottom: 0; left: 0; right: 0"/>; doc.body.setAttribute("class", class + " liberator-frame-indicator");
setTimeout(function () doc.body.setAttribute("class", class), 500);
*/
var indicator = <div id="liberator-frame-indicator"/>;
doc.body.appendChild(liberator.util.xmlToDom(indicator)); doc.body.appendChild(liberator.util.xmlToDom(indicator));
// remove the frame indicator // remove the frame indicator
@@ -1389,7 +1416,7 @@ liberator.Buffer = function () //{{{
// TODO: print more useful information, just like the DOM inspector // TODO: print more useful information, just like the DOM inspector
showElementInfo: function (elem) showElementInfo: function (elem)
{ {
liberator.echo("Element:<br/>" + liberator.util.objectToString(elem), liberator.commandline.FORCE_MULTILINE); liberator.echo(<>Element:<br/></> + liberator.util.objectToString(elem), liberator.commandline.FORCE_MULTILINE);
}, },
showPageInfo: function (verbose) showPageInfo: function (verbose)
@@ -1400,8 +1427,8 @@ liberator.Buffer = function () //{{{
let file = content.document.location.pathname.split("/").pop() || "[No Name]"; let file = content.document.location.pathname.split("/").pop() || "[No Name]";
let title = content.document.title || "[No Title]"; let title = content.document.title || "[No Title]";
let info = liberator.template.map("gf", function (opt) let info = liberator.template.map("gf",
liberator.template.map(pageInfo[opt][0](), function (val) val, ", "), function (opt) liberator.template.map(pageInfo[opt][0](), function (val) val, ", "),
", "); ", ");
if (liberator.bookmarks.isBookmarked(this.URL)) if (liberator.bookmarks.isBookmarked(this.URL))
@@ -1418,10 +1445,7 @@ liberator.Buffer = function () //{{{
let opt = pageInfo[option]; let opt = pageInfo[option];
if (opt) if (opt)
return liberator.template.table(opt[1], opt[0](true)); return liberator.template.table(opt[1], opt[0](true));
else
alert(option);
}, <br/>); }, <br/>);
XML.prettyPrinting = false;
liberator.echo(list, liberator.commandline.FORCE_MULTILINE); liberator.echo(list, liberator.commandline.FORCE_MULTILINE);
}, },
@@ -1872,9 +1896,11 @@ liberator.template = {
maybeXML: function (xml) maybeXML: function (xml)
{ {
if (typeof xml == "xml")
return xml;
try try
{ {
return new XML(xml) return new XMLList(xml)
} }
catch (e) {} catch (e) {}
return <>{xml}</>; return <>{xml}</>;
@@ -1882,8 +1908,7 @@ liberator.template = {
generic: function (xml) generic: function (xml)
{ {
XML.prettyPrinting = false; return <>:{liberator.commandline.getCommand()}<br/></> + xml
return (<>:{liberator.commandline.getCommand()}<br/></> + xml).toXMLString();
}, },
bookmarks: function (header, items) bookmarks: function (header, items)

View File

@@ -710,7 +710,9 @@ liberator.Commands = function () //{{{
if (cmdlist.length > 0) if (cmdlist.length > 0)
{ {
var str = liberator.template.tabular(["Name", "Args", "Definition"], [], var str = liberator.template.tabular(["Name", "Args", "Definition"], [],
([cmd.name, "*", cmd.replacementText || "function () { ... }"] ([cmd.name,
"*",
cmd.replacementText || "function () { ... }"]
for each (cmd in cmdlist))); for each (cmd in cmdlist)));
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
} }

View File

@@ -928,31 +928,26 @@ liberator.Editor = function () //{{{
} }
else // list all (for that filter {i,c,!}) else // list all (for that filter {i,c,!})
{ {
var searchFilter = (filter == "!") ? "!ci" : filter + "!"; // ! -> list all, on c or i ! matches too) var searchFilter = (filter == "!") ? "!ci"
: filter + "!"; // ! -> list all, on c or i ! matches too)
XML.prettyPrinting = false; let list =
let list = <table/>; <table>
for (let tmplhs in abbrev)
{
abbrev[tmplhs].forEach(function (abbr)
{ {
if (searchFilter.indexOf(abbr[0]) > -1) liberator.template.map2(abbrev, function (lhs, rhs)
{ liberator.template.map(rhs, function (abbr)
list.* += <tr> searchFilter.indexOf(abbr[0]) < 0 ? undefined :
<td>{abbr[0]}</td> <tr>
<td>{tmplhs}</td> <td>{abbr[0]}</td>
<td>{abbr[1]}</td> <td>{lhs}</td>
</tr>; <td>{abbr[1]}</td>
} </tr>))
}); }
} </table>;
if (list.*.length())
if (!list.*.length()) liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
{ else
liberator.echoerr("No abbreviations found"); liberator.echoerr("No abbreviations found");
return;
}
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
} }
}, },

View File

@@ -215,11 +215,12 @@ liberator.AutoCommands = function () //{{{
<tr> <tr>
<td class="hl-Title" colspan="2">{event}</td> <td class="hl-Title" colspan="2">{event}</td>
</tr> </tr>
+ liberator.template.map(items, function (item) +
<tr> liberator.template.map(items, function (item)
<td>&#160;{item[0]}</td> <tr>
<td>{item[1]}</td> <td>&#160;{item[0]}</td>
</tr>)) <td>{item[1]}</td>
</tr>))
} }
</table>); </table>);
@@ -666,7 +667,7 @@ liberator.Events = function () //{{{
function (args) function (args)
{ {
XML.prettyPrinting = false; XML.prettyPrinting = false;
var str = liberator.template.tabular(["Macro", "Keys"], [], liberator.events.getMacros(args)); var str = liberator.template.tabular(["Macro", "Keys"], [], liberator.events.getMacros(args));
liberator.echo(str, liberator.commandline.FORCE_MULTILINE); liberator.echo(str, liberator.commandline.FORCE_MULTILINE);
}, },
{ {

View File

@@ -320,7 +320,6 @@ liberator.IO = function () //{{{
"List all sourced script names", "List all sourced script names",
function () function ()
{ {
XML.prettyPrinting = false;
var list = liberator.template.tabular(["Idx", "Filename"], ["text-align: right"], Iterator(scriptNames)); var list = liberator.template.tabular(["Idx", "Filename"], ["text-align: right"], Iterator(scriptNames));
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}, },

View File

@@ -45,6 +45,7 @@ const liberator = (function () //{{{
} }
catch (e) catch (e)
{ {
Components.utils.reportError(e);
liberator.dump(e + "\n"); liberator.dump(e + "\n");
} }
} }
@@ -281,7 +282,6 @@ const liberator = (function () //{{{
else else
{ {
// TODO: clicking on these should open the help // TODO: clicking on these should open the help
XML.prettyPrinting = false;
var usage = <table> var usage = <table>
{ {
liberator.template.map(liberator.commands, function (command) liberator.template.map(liberator.commands, function (command)
@@ -290,7 +290,7 @@ const liberator = (function () //{{{
<td>{command.description}</td> <td>{command.description}</td>
</tr>) </tr>)
} }
</table>.toXMLString(); </table>;
liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE);
} }
}, },
@@ -425,7 +425,6 @@ const liberator = (function () //{{{
<tr><td>  Average time:</td><td align="right"><span style="color: green">{each.toFixed(2)}</span></td><td>{eachUnits}</td></tr> <tr><td>  Average time:</td><td align="right"><span style="color: green">{each.toFixed(2)}</span></td><td>{eachUnits}</td></tr>
<tr><td>  Total time:</td><td align="right"><span style="color: red">{total.toFixed(2)}</span></td><td>{totalUnits}</td></tr> <tr><td>  Total time:</td><td align="right"><span style="color: red">{total.toFixed(2)}</span></td><td>{totalUnits}</td></tr>
</table>); </table>);
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
} }
else else
@@ -486,7 +485,6 @@ const liberator = (function () //{{{
else else
{ {
// TODO: clicking on these should open the help // TODO: clicking on these should open the help
XML.prettyPrinting = false;
var usage = <table> var usage = <table>
{ {
liberator.template.add(liberator.mappings, function (mapping) liberator.template.add(liberator.mappings, function (mapping)
@@ -495,8 +493,7 @@ const liberator = (function () //{{{
<td>{mapping.description}</td> <td>{mapping.description}</td>
</tr>) </tr>)
} }
</table>.toXMLString(); </table>;
liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE);
} }
}, },

View File

@@ -417,7 +417,6 @@ liberator.Mappings = function () //{{{
let _maps = (map for ([i, map] in Iterator(maps)) let _maps = (map for ([i, map] in Iterator(maps))
if (output[i])); if (output[i]));
XML.prettyPrinting = false;
let list = <table> let list = <table>
{ {
liberator.template.map(_maps, function (map) liberator.template.map(_maps, function (map)
@@ -428,8 +427,7 @@ liberator.Mappings = function () //{{{
<td>{map.rhs || "function () { ... }"}</td> <td>{map.rhs || "function () { ... }"}</td>
</tr>)) </tr>))
} }
</table> </table>;
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
} }

View File

@@ -268,18 +268,20 @@ liberator.Options = function () //{{{
{ {
if (!args) if (!args)
{ {
XML.prettyPrinting = false; var str =
var str = <table/> <table>
for (let [i, value] in Iterator(liberator.globalVariables)) {
{ liberator.template.map2(liberator.globalVariables, function (i, value) {
let prefix = typeof value == "number" ? "#" : let prefix = typeof value == "number" ? "#" :
typeof value == "function" ? "*" : typeof value == "function" ? "*" :
" "; " ";
str.* += <tr> return <tr>
<td style="width: 200px;">{i}</td> <td style="width: 200px;">{i}</td>
<td>{prefix}{value}</td> <td>{prefix}{value}</td>
</tr>; </tr>
} })
}
</table>;
if (str.*.length()) if (str.*.length())
liberator.echo(str, liberator.commandline.FORCE_MULTILINE); liberator.echo(str, liberator.commandline.FORCE_MULTILINE);
else else

View File

@@ -726,7 +726,7 @@ liberator.Tabs = function () //{{{
<tr> <tr>
<td align="right"> {number}</td> <td align="right"> {number}</td>
<td><span style="color: blue"> {indicator} </span></td> <td><span style="color: blue"> {indicator} </span></td>
<td style="width:250px; max-width: 500px; overflow: hidden">{title}</td> <td style="width: 250px; max-width: 500px; overflow: hidden">{title}</td>
<td><a href="#" class="hl-URL buffer-list">{item[1]}</a></td> <td><a href="#" class="hl-URL buffer-list">{item[1]}</a></td>
</tr>; </tr>;
} }

View File

@@ -121,8 +121,7 @@ liberator.CommandLine = function () //{{{
// the widget used for multiline output // the widget used for multiline output
var multilineOutputWidget = document.getElementById("liberator-multiline-output"); var multilineOutputWidget = document.getElementById("liberator-multiline-output");
multilineOutputWidget.setAttribute("src", liberator.util.blankDocument(multilineOutputWidget, "liberator-multiline-output-content");
liberator.util.blankDocument("liberator-multiline-output-content"));
var outputContainer = multilineOutputWidget.parentNode; var outputContainer = multilineOutputWidget.parentNode;
@@ -209,7 +208,9 @@ liberator.CommandLine = function () //{{{
let doc = multilineOutputWidget.contentDocument; let doc = multilineOutputWidget.contentDocument;
let win = multilineOutputWidget.contentWindow; let win = multilineOutputWidget.contentWindow;
XML.ignoreWhitespace = false;
var output = <div class={"ex-command-output " + highlightGroup}>{liberator.template.maybeXML(str)}</div>; var output = <div class={"ex-command-output " + highlightGroup}>{liberator.template.maybeXML(str)}</div>;
XML.ignoreWhitespace = true;
lastMowOutput = output; lastMowOutput = output;
@@ -1190,7 +1191,7 @@ liberator.ItemList = function (id) //{{{
var doc; var doc;
var container = iframe.parentNode; var container = iframe.parentNode;
iframe.setAttribute("src", liberator.util.blankDocument(id + "-content")); liberator.util.blankDocument(iframe, id + "-content");
var completions = []; // a reference to the Array of completions var completions = []; // a reference to the Array of completions
var listOffset = -1; // how many items is the displayed list shifted from the internal tab index var listOffset = -1; // how many items is the displayed list shifted from the internal tab index

View File

@@ -77,22 +77,11 @@ liberator.util = { //{{{
yield ary[i]; yield ary[i];
}, },
blankDocument: function (bodyId) blankDocument: function (iframe, bodyId)
{ {
let mainWindowID = liberator.config.mainWindowID || "main-window"; let name = liberator.config.name.toLowerCase();
let fontSize = document.defaultView.getComputedStyle(document.getElementById(mainWindowID), null) iframe.addEventListener("load", function () iframe.contentDocument.body.setAttribute("id", bodyId), true);
.getPropertyValue("font-size"); iframe.setAttribute("src", "chrome://" + name + "/skin/blank-" + name + ".xhtml");
return 'data:application/xhtml+xml,' + encodeURI('<?xml version="1.0" encoding="UTF-8"?>' +
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' +
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
<link rel="stylesheet" type="text/css"
href={"chrome://" + liberator.config.name.toLowerCase() + "/skin/vimperator.css"}/>
</head>
<body id={bodyId} style={"font-size: " + fontSize}/>
</html>)
}, },
clip: function (str, length) clip: function (str, length)

View File

@@ -110,6 +110,10 @@ liberator.config = { //{{{
"message.html", "developer.html", "various.html", "index.html" "message.html", "developer.html", "various.html", "index.html"
], ],
userSheets: [
"chrome://vimperator/skin/content.css",
],
init: function () init: function ()
{ {
function incrementURL(count) function incrementURL(count)

11
skin/blank-muttator.xhtml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
<link rel="stylesheet" type="text/css"
href="chrome://muttator/skin/vimperator.css"/>
</head>
<body/>
</html>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
<link rel="stylesheet" type="text/css"
href="chrome://vimperator/skin/vimperator.css"/>
</head>
<body/>
</html>

16
skin/content.css Normal file
View File

@@ -0,0 +1,16 @@
.liberator-frame-indicator {
-moz-binding: url(chrome://vimperator/content/bindings.xml#frame);
}
#liberator-frame-indicator {
background-color: red;
opacity: 0.5;
z-index: 999
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}