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

Fix hints with :set usermode. Dont sort location/history/search completions. Highlight via liberator:highlight= attribute rather than by class

This commit is contained in:
Kris Maglione
2008-11-27 05:36:01 +00:00
parent 980e64a22b
commit 5d8992d761
14 changed files with 179 additions and 155 deletions

View File

@@ -6,13 +6,14 @@
]> ]>
<bindings xmlns="http://www.mozilla.org/xbl" <bindings xmlns="http://www.mozilla.org/xbl"
xmlns:liberator="http://vimperator.org/namespaces/liberator"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:xbl="http://www.mozilla.org/xbl" xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml"> xmlns:html="http://www.w3.org/1999/xhtml">
<binding id="frame"> <binding id="frame">
<content> <content>
<div id="liberator-frame-indicator" style="width: 40px; height: 40px"/> <html:div liberator:highlight="FrameIndicator"/>
<children/> <children/>
</content> </content>
</binding> </binding>

View File

@@ -50,8 +50,8 @@ function Bookmarks() //{{{
const Keyword = new Struct("keyword", "title", "icon", "url"); const Keyword = new Struct("keyword", "title", "icon", "url");
Bookmark.defaultValue("icon", function () getFavicon(this.url)); Bookmark.defaultValue("icon", function () getFavicon(this.url));
Bookmark.prototype.__defineGetter__("extra", function () [ Bookmark.prototype.__defineGetter__("extra", function () [
['keyword', this.keyword, "hl-Keyword"], ['keyword', this.keyword, "Keyword"],
['tags', this.tags.join(', '), "hl-Tag"] ['tags', this.tags.join(', '), "Tag"]
].filter(function (item) item[1])); ].filter(function (item) item[1]));
const storage = modules.storage; const storage = modules.storage;
@@ -742,6 +742,8 @@ function History() //{{{
let query = historyService.getNewQuery(); let query = historyService.getNewQuery();
let options = historyService.getNewQueryOptions(); let options = historyService.getNewQueryOptions();
if (typeof filter == "string")
filter = { searchTerms: filter };
for (let [k, v] in Iterator(filter)) for (let [k, v] in Iterator(filter))
query[k] = v; query[k] = v;
options.sortingMode = options.SORT_BY_DATE_DESCENDING; options.sortingMode = options.SORT_BY_DATE_DESCENDING;

View File

@@ -871,6 +871,8 @@ function Buffer() //{{{
{ {
case "xhtml": case "xhtml":
return "http://www.w3.org/1999/xhtml"; return "http://www.w3.org/1999/xhtml";
case "liberator":
return NS.uri;
default: default:
return null; return null;
} }
@@ -1243,12 +1245,15 @@ function Buffer() //{{{
frames[next].frameElement.scrollIntoView(false); frames[next].frameElement.scrollIntoView(false);
// add the frame indicator // add the frame indicator
var doc = frames[next].document; let doc = frames[next].document;
var indicator = util.xmlToDom(<div id="liberator-frame-indicator"/>, doc); var indicator = util.xmlToDom(<div highlight="FrameIndicator"/>, doc);
doc.body.appendChild(indicator); doc.body.appendChild(indicator);
// remove the frame indicator
setTimeout(function () { doc.body.removeChild(indicator); }, 500); setTimeout(function () { doc.body.removeChild(indicator); }, 500);
// Doesn't unattach
//doc.body.setAttributeNS(NS.uri, "activeframe", "true");
//setTimeout(function () { doc.body.removeAttributeNS(NS.uri, "activeframe"); }, 500);
}, },
// similar to pageInfo // similar to pageInfo

View File

@@ -150,6 +150,9 @@ CompletionContext.prototype = {
get caret() (this.editor ? this.editor.selection.getRangeAt(0).startOffset : this.value.length) - this.offset, get caret() (this.editor ? this.editor.selection.getRangeAt(0).startOffset : this.value.length) - this.offset,
get compare() this._compare || function () 0,
set compare(val) this._compare = val,
get completions() this._completions || [], get completions() this._completions || [],
set completions(items) set completions(items)
{ {
@@ -1066,8 +1069,8 @@ function Completion() //{{{
liberator.threadYield(true, true); liberator.threadYield(true, true);
let list = template.generic( let list = template.generic(
<div class="hl-Completions"> <div highlight="Completions">
{ template.completionRow(context.title, "hl-CompTitle") } { template.completionRow(context.title, "CompTitle") }
{ template.map(context.items, function (item) context.createRow(item)) } { template.map(context.items, function (item) context.createRow(item)) }
</div>); </div>);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
@@ -1099,7 +1102,7 @@ function Completion() //{{{
context.keys = { text: "text", description: "url", icon: "icon" }; context.keys = { text: "text", description: "url", icon: "icon" };
let process = context.process[0]; let process = context.process[0];
context.process = [function ({ text: text, item: item }) <> context.process = [function ({ text: text, item: item }) <>
<span class="hl-Indicator" style="display: inline-block; width: 1.5em; text-align: center">{item.indicator}</span> <span highlight="Indicator" style="display: inline-block; width: 1.5em; text-align: center">{item.indicator}</span>
{ process.call(this, { item: item, text: text }) } { process.call(this, { item: item, text: text }) }
</>]; </>];
@@ -1275,9 +1278,10 @@ function Completion() //{{{
{ {
context.format = history.format; context.format = history.format;
context.title = ["History"] context.title = ["History"]
context.compare = null;
context.background = true; context.background = true;
context.regenerate = true; context.regenerate = true;
context.generate = function () history.get({ searchTerms: context.filter }); context.generate = function () history.get(context.filter);
}, },
get javascriptCompleter() javascript, get javascriptCompleter() javascript,
@@ -1293,6 +1297,7 @@ function Completion() //{{{
context.incomplete = true; context.incomplete = true;
context.hasItems = context.completions.length > 0; // XXX context.hasItems = context.completions.length > 0; // XXX
context.filterFunc = null; context.filterFunc = null;
context.compare = null;
let timer = new util.Timer(50, 100, function (result) { let timer = new util.Timer(50, 100, function (result) {
context.completions = [ context.completions = [
[result.getValueAt(i), result.getCommentAt(i), result.getImageAt(i)] [result.getValueAt(i), result.getCommentAt(i), result.getImageAt(i)]
@@ -1331,9 +1336,9 @@ function Completion() //{{{
let engines = bookmarks.getSearchEngines(); let engines = bookmarks.getSearchEngines();
context.title = ["Search Keywords"]; context.title = ["Search Keywords"];
context.keys = { text: 0, description: 1, icon: 2 };
context.completions = keywords.concat(engines);
context.anchored = true; context.anchored = true;
context.completions = keywords.concat(engines);
context.keys = { text: 0, description: 1, icon: 2 };
if (!space || noSuggest) if (!space || noSuggest)
return; return;
@@ -1346,8 +1351,9 @@ function Completion() //{{{
context.fork("keyword/" + keyword, keyword.length + space.length, null, function (context) { context.fork("keyword/" + keyword, keyword.length + space.length, null, function (context) {
context.format = history.format; context.format = history.format;
context.title = [keyword + " Quick Search"]; context.title = [keyword + " Quick Search"];
context.background = true;
context.anchored = true; context.anchored = true;
context.background = true;
context.compare = null;
context.generate = function () { context.generate = function () {
let [begin, end] = item.url.split("%s"); let [begin, end] = item.url.split("%s");
@@ -1384,8 +1390,9 @@ function Completion() //{{{
let ctxt = context.fork(name, 0); let ctxt = context.fork(name, 0);
ctxt.title = [engine.description + " Suggestions"]; ctxt.title = [engine.description + " Suggestions"];
ctxt.regenerate = true;
ctxt.background = true; ctxt.background = true;
ctxt.compare = null;
ctxt.regenerate = true;
ctxt.generate = function () bookmarks.getSuggestions(name, this.filter); ctxt.generate = function () bookmarks.getSuggestions(name, this.filter);
}); });
}, },

View File

@@ -218,12 +218,12 @@ function AutoCommands() //{{{
var list = template.generic( var list = template.generic(
<table> <table>
<tr class="hl-Title"> <tr highlight="Title">
<td colspan="2">----- Auto Commands -----</td> <td colspan="2">----- Auto Commands -----</td>
</tr> </tr>
{ {
template.map(cmds, function ([event, items]) template.map(cmds, function ([event, items])
<tr class="hl-Title"> <tr highlight="Title">
<td colspan="2">{event}</td> <td colspan="2">{event}</td>
</tr> </tr>
+ +

View File

@@ -157,10 +157,10 @@ function Search() //{{{
if (!aWord) if (!aWord)
{ {
let elems = doc.getElementsByClassName("liberator-search"); let elems = highlightObj.getSpans(doc);
for (let i = elems.length; --i >= 0;) for (let i = elems.snapshotLength; --i >= 0;)
{ {
let elem = elems[i]; let elem = elems.snapshotItem(i);
let docfrag = doc.createDocumentFragment(); let docfrag = doc.createDocumentFragment();
let next = elem.nextSibling; let next = elem.nextSibling;
let parent = elem.parentNode; let parent = elem.parentNode;
@@ -176,7 +176,7 @@ function Search() //{{{
return; return;
} }
var baseNode = <span class="liberator-search"/> var baseNode = <span highlight="Search"/>
baseNode = util.xmlToDom(baseNode, window.content.document); baseNode = util.xmlToDom(baseNode, window.content.document);
var body = doc.body; var body = doc.body;
@@ -221,7 +221,9 @@ function Search() //{{{
aNode.appendChild(docfrag); aNode.appendChild(docfrag);
parent.insertBefore(aNode, before); parent.insertBefore(aNode, before);
return aNode; return aNode;
} },
getSpans: function (doc) buffer.evaluateXPath("//*[liberator:highlight='Search']", doc)
}; };
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
@@ -442,7 +444,7 @@ function Search() //{{{
return; return;
// already highlighted? // already highlighted?
if (window.content.document.getElementsByClassName("liberator-search").length > 0) if (highlightObj.getSpans(content.document).snapshotLength > 0)
return; return;
if (!text) if (!text)

View File

@@ -32,7 +32,7 @@ function Hints() //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
const ELEM = 0, TEXT = 1, SPAN = 2, IMGSPAN = 3, BGCOLOR = 4, COLOR = 5; const ELEM = 0, TEXT = 1, SPAN = 2, IMGSPAN = 3;
var myModes = config.browserModes; var myModes = config.browserModes;
@@ -112,13 +112,12 @@ function Hints() //{{{
var scrollX = doc.defaultView.scrollX; var scrollX = doc.defaultView.scrollX;
var scrollY = doc.defaultView.scrollY; var scrollY = doc.defaultView.scrollY;
var baseNodeAbsolute = util.xmlToDom( var baseNodeAbsolute = util.xmlToDom(<span highlight="Hint"/>, doc);
<span class="liberator-hint"/>, doc);
var elem, tagname, text, span, rect; var elem, tagname, text, span, rect;
var res = buffer.evaluateXPath(hintMode.tags(), doc, null, true); var res = buffer.evaluateXPath(hintMode.tags(), doc, null, true);
var fragment = doc.createDocumentFragment(); var fragment = util.xmlToDom(<div highlight="hints"/>, doc);
var start = pageHints.length; var start = pageHints.length;
for (let elem in res) for (let elem in res)
{ {
@@ -171,19 +170,24 @@ function Hints() //{{{
{ {
var oldElem = validHints[oldID - 1]; var oldElem = validHints[oldID - 1];
if (oldElem) if (oldElem)
oldElem.style.backgroundColor = options["linkbgcolor"]; setClass(newElem, false);
var newElem = validHints[newID - 1]; var newElem = validHints[newID - 1];
if (newElem) if (newElem)
newElem.style.backgroundColor = options["activelinkbgcolor"]; setClass(newElem, true);
}
function setClass(elem, active)
{
let prefix = (elem.getAttributeNS(NS.uri, "class") || "") + " ";
if (active)
elem.setAttributeNS(NS.uri, "highlight", prefix + "HintActive");
else
elem.setAttributeNS(NS.uri, "highlight", prefix + "HintElem");
} }
function showHints() function showHints()
{ {
var linkfgcolor = options["linkfgcolor"];
var linkbgcolor = options["linkbgcolor"];
var activelinkfgcolor = options["activelinkfgcolor"];
var activelinkbgcolor = options["activelinkbgcolor"];
let elem, tagname, text, rect, span, imgspan; let elem, tagname, text, rect, span, imgspan;
let hintnum = 1; let hintnum = 1;
@@ -208,9 +212,7 @@ function Hints() //{{{
if (imgspan) if (imgspan)
imgspan.style.display = "none"; imgspan.style.display = "none";
// reset background color elem.removeAttributeNS(NS.uri, "highlight");
elem.style.backgroundColor = hint[BGCOLOR];
elem.style.color = hint[COLOR];
continue inner; continue inner;
} }
@@ -222,61 +224,58 @@ function Hints() //{{{
if (!rect) if (!rect)
continue; continue;
imgspan = doc.createElementNS("http://www.w3.org/1999/xhtml", "span"); imgspan = util.xmlToDom(<span highlight="Hint"/>, doc);
imgspan.style.position = "absolute"; imgspan.setAttributeNS(NS.uri, "class", "HintImage");
imgspan.style.opacity = 0.5;
imgspan.style.zIndex = "10000000";
imgspan.style.left = (rect.left + scrollX) + "px"; imgspan.style.left = (rect.left + scrollX) + "px";
imgspan.style.top = (rect.top + scrollY) + "px"; imgspan.style.top = (rect.top + scrollY) + "px";
imgspan.style.width = (rect.right - rect.left) + "px"; imgspan.style.width = (rect.right - rect.left) + "px";
imgspan.style.height = (rect.bottom - rect.top) + "px"; imgspan.style.height = (rect.bottom - rect.top) + "px";
imgspan.className = "liberator-hint";
hint[IMGSPAN] = imgspan; hint[IMGSPAN] = imgspan;
doc.body.appendChild(imgspan); span.parentNode.appendChild(imgspan);
} }
imgspan.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor; setClass(imgspan, activeHint == hintnum)
imgspan.style.display = "inline";
} }
if (!imgspan) span.setAttribute("number", hintnum++);
elem.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor; if (imgspan)
elem.style.color = (activeHint == hintnum) ? activelinkfgcolor : linkfgcolor; imgspan.setAttribute("number", hintnum++);
span.textContent = String(hintnum++); else
span.style.display = "inline"; setClass(elem, activeHint == hintnum);
validHints.push(elem); validHints.push(elem);
} }
} }
if (options.usermode)
{
let css = [];
// FIXME: Broken for imgspans.
for (let [,{ doc: doc }] in Iterator(docs))
{
for (let elem in buffer.evaluateXPath("//*[@liberator:highlight and @number]", doc))
{
let group = elem.getAttributeNS(NS.uri, "highlight");
css.push(highlight.selector(group) + "[number='" + elem.getAttribute("number") + "'] { " + elem.style.cssText + " }");
}
}
styles.addSheet("hint-positions", "*", css.join("\n"), true, true);
}
return true; return true;
} }
function removeHints(timeout) function removeHints(timeout)
{ {
var firstElem = validHints[0] || null; var firstElem = validHints[0] || null;
var firstElemBgColor = "";
var firstElemColor = "";
for (let [,{ doc: doc, start: start, end: end }] in Iterator(docs)) for (let [,{ doc: doc, start: start, end: end }] in Iterator(docs))
{ {
for (let elem in buffer.evaluateXPath("//*[@liberator:highlight='hints']", doc))
elem.parentNode.removeChild(elem);
for (let i in util.range(start, end + 1)) for (let i in util.range(start, end + 1))
{ {
let hint = pageHints[i]; let hint = pageHints[i];
// remove the span for the numeric display part if (!timeout || hint[ELEM] != firstHint)
doc.body.removeChild(hint[SPAN]); hint[ELEM].removeAttributeNS(NS.uri, "highlight");
if (hint[IMGSPAN]) // a transparent span for images
doc.body.removeChild(hint[IMGSPAN]);
if (timeout && firstElem == hint[ELEM])
{
firstElemBgColor = hint[BGCOLOR];
firstElemColor = hint[COLOR];
}
else
{
// restore colors
var elem = hint[ELEM];
elem.style.backgroundColor = hint[BGCOLOR];
elem.style.color = hint[COLOR]; }
} }
// animate the disappearance of the first hint // animate the disappearance of the first hint
@@ -305,12 +304,10 @@ function Hints() //{{{
// clearTimeout(id); // clearTimeout(id);
// } // }
// }, 100); // }, 100);
setTimeout(function () { setTimeout(function () { firstElem.removeAttributeNS(NS.uri, "highlight") }, timeout);
firstElem.style.backgroundColor = firstElemBgColor;
firstElem.style.color = firstElemColor;
}, timeout);
} }
} }
styles.removeSheet("hint-positions", null, null, null, true);
reset(); reset();
} }
@@ -560,22 +557,6 @@ function Hints() //{{{
"number", 0, "number", 0,
{ validator: function (value) value >= 0 && value < 3 }); { validator: function (value) value >= 0 && value < 3 });
options.add(["linkfgcolor", "lfc"],
"Foreground color of a link during hint mode",
"string", "black");
options.add(["linkbgcolor", "lbc"],
"Background color of a link during hint mode",
"string", "yellow");
options.add(["activelinkfgcolor", "alfc"],
"Foreground color of the current active link during hint mode",
"string", "black");
options.add(["activelinkbgcolor", "albc"],
"Background color of the current active link during hint mode",
"string", "#88FF00");
options.add(["hintmatching", "hm"], options.add(["hintmatching", "hm"],
"How links are matched", "How links are matched",
"string", "contains", "string", "contains",

View File

@@ -26,9 +26,9 @@
Components.utils.import("resource://liberator/storage.jsm", modules); Components.utils.import("resource://liberator/storage.jsm", modules);
["liberator.js", ["liberator.js",
"config.js",
"util.js", "util.js",
"style.js", "style.js",
"config.js",
"buffer.js", "buffer.js",
"commands.js", "commands.js",
"completion.js", "completion.js",

View File

@@ -74,8 +74,8 @@ const liberator = (function () //{{{
"boolean", false); "boolean", false);
const tabopts = [ const tabopts = [
["n", "Tab number", null, ".hl-TabNumber"], ["n", "Tab number", null, highlight.selector("TabNumber")],
["N", "Tab number over icon", null, ".hl-TabIconNumber"] ["N", "Tab number over icon", null, highlight.selector("TabIconNumber")]
]; ];
options.add(["guioptions", "go"], options.add(["guioptions", "go"],
"Show or hide certain GUI elements like the menu or toolbar", "Show or hide certain GUI elements like the menu or toolbar",
@@ -433,7 +433,7 @@ const liberator = (function () //{{{
var str = template.generic( var str = template.generic(
<table> <table>
<tr class="hl-Title" align="left"> <tr highlight="Title" align="left">
<th colspan="3">Code execution summary</th> <th colspan="3">Code execution summary</th>
</tr> </tr>
<tr><td>&#xa0;&#xa0;Executed:</td><td align="right"><span class="times-executed">{count}</span></td><td>times</td></tr> <tr><td>&#xa0;&#xa0;Executed:</td><td align="right"><span class="times-executed">{count}</span></td><td>times</td></tr>

View File

@@ -34,6 +34,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
]> ]>
<overlay id="liberator" <overlay id="liberator"
xmlns:liberator="http://vimperator.org/namespaces/liberator"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:nc="http://home.netscape.com/NC-rdf#" xmlns:nc="http://home.netscape.com/NC-rdf#"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"
@@ -50,7 +51,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
</keyset> </keyset>
<popupset> <popupset>
<panel id="liberator-visualbell"/> <panel id="liberator-visualbell" liberator:highlight="Bell"/>
</popupset> </popupset>
<!--this notifies us also of focus events in the XUL <!--this notifies us also of focus events in the XUL
@@ -78,7 +79,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
onclick="liberator.modules.commandline.onMultilineOutputEvent(event)"/> onclick="liberator.modules.commandline.onMultilineOutputEvent(event)"/>
</vbox> </vbox>
<hbox id="liberator-commandline" hidden="false" class="hl-Normal"> <hbox id="liberator-commandline" hidden="false" liberator:highlight="Normal">
<label class="plain" id="liberator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/> <label class="plain" id="liberator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/>
<textbox class="plain" id="liberator-commandline-command" flex="1" type="timed" timeout="100" <textbox class="plain" id="liberator-commandline-command" flex="1" type="timed" timeout="100"
oninput="liberator.modules.commandline.onEvent(event);" oninput="liberator.modules.commandline.onEvent(event);"
@@ -95,7 +96,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
</window> </window>
<statusbar id="status-bar" class="hl-StatusLine"> <statusbar id="status-bar" liberator:highlight="StatusLine">
<hbox insertbefore="&liberator.statusBefore;" insertafter="&liberator.statusAfter;" <hbox insertbefore="&liberator.statusBefore;" insertafter="&liberator.statusAfter;"
id="liberator-statusline" flex="1" hidden="false" align="center"> id="liberator-statusline" flex="1" hidden="false" align="center">
<textbox class="plain" id="liberator-statusline-field-url" readonly="false" flex="1" crop="end"/> <textbox class="plain" id="liberator-statusline-field-url" readonly="false" flex="1" crop="end"/>

View File

@@ -38,9 +38,9 @@ function Highlights(name, store, serial)
CompResult width: 45%; overflow: hidden; CompResult width: 45%; overflow: hidden;
CompDesc color: gray; width: 50%; CompDesc color: gray; width: 50%;
CompLess text-align: center; height: .5ex; line-height: .5ex; padding-top: 1ex; CompLess text-align: center; height: .5ex; line-height: .5ex; padding-top: 1ex;
CompLess:after content: "\2303" /* Unicode up arrowhead */ CompLess::after content: "\2303" /* Unicode up arrowhead */
CompMore text-align: center; height: .5ex; line-height: .5ex; CompMore text-align: center; height: .5ex; line-height: .5ex;
CompMore:after content: "\2304" /* Unicode down arrowhead */ CompMore::after content: "\2304" /* Unicode down arrowhead */
Indicator color: blue; Indicator color: blue;
Filter font-weight: bold; Filter font-weight: bold;
@@ -70,8 +70,19 @@ function Highlights(name, store, serial)
URL text-decoration: none; color: green; background: inherit; URL text-decoration: none; color: green; background: inherit;
URL:hover text-decoration: underline; cursor: pointer; URL:hover text-decoration: underline; cursor: pointer;
Bell,#liberator-visualbell border: none; background-color: black; FrameIndicator,,* {
Hint,.liberator-hint,* { background-color: red;
opacity: 0.5;
z-index: 999;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
Bell border: none; background-color: black;
Hint,,* {
font-family: monospace; font-family: monospace;
font-size: 10px; font-size: 10px;
font-weight: bold; font-weight: bold;
@@ -82,7 +93,12 @@ function Highlights(name, store, serial)
border-style: solid; border-style: solid;
padding: 0px 1px 0px 1px; padding: 0px 1px 0px 1px;
} }
Search,.liberator-search,* { Hint::after,,* content: attr(number);
HintElem,,* background: yellow; color: black;
HintActive,,* background: #88FF00; color: black;
HintImage,,* opacity: .5;
Search,,* {
font-size: inherit; font-size: inherit;
padding: 0; padding: 0;
color: black; color: black;
@@ -96,7 +112,7 @@ function Highlights(name, store, serial)
const Highlight = Struct("class", "selector", "filter", "default", "value"); const Highlight = Struct("class", "selector", "filter", "default", "value");
Highlight.defaultValue("filter", function () "chrome://liberator/content/buffer.xhtml" + "," + config.styleableChrome); Highlight.defaultValue("filter", function () "chrome://liberator/content/buffer.xhtml" + "," + config.styleableChrome);
Highlight.defaultValue("selector", function () ".hl-" + this.class); Highlight.defaultValue("selector", function () self.selector(this.class));
Highlight.defaultValue("value", function () this.default); Highlight.defaultValue("value", function () this.default);
Highlight.prototype.toString = function () "Highlight(" + this.class + ")\n\t" + [k + ": " + util.escapeString(v || "undefined") for ([k, v] in this)].join("\n\t"); Highlight.prototype.toString = function () "Highlight(" + this.class + ")\n\t" + [k + ": " + util.escapeString(v || "undefined") for ([k, v] in this)].join("\n\t");
@@ -140,11 +156,17 @@ function Highlights(name, store, serial)
highlight[style.class] = style; highlight[style.class] = style;
} }
this.selector = function (class)
{
let [, hl, rest] = class.match(/^(\w*)(.*)/);
return "[liberator|highlight~=" + hl + "]" + rest
};
highlightCSS.replace(/\{((?:.|\n)*?)\}/g, function (_, _1) _1.replace(/\n\s*/g, " ")) highlightCSS.replace(/\{((?:.|\n)*?)\}/g, function (_, _1) _1.replace(/\n\s*/g, " "))
.split("\n").filter(function (s) /\S/.test(s)) .split("\n").filter(function (s) /\S/.test(s))
.forEach(function (style) .forEach(function (style)
{ {
style = Highlight.apply(Highlight, Array.slice(style.match(/^\s*([^,\s]+)(?:,([^,\s]+))?(?:,([^,\s]+))?\s*(.*)$/), 1)); style = Highlight.apply(Highlight, Array.slice(style.match(/^\s*([^,\s]+)(?:,([^,\s]+)?)?(?:,([^,\s]+))?\s*(.*)$/), 1));
highlight[style.class] = style; highlight[style.class] = style;
self.set(style.class); self.set(style.class);
}); });
@@ -165,9 +187,9 @@ function Styles(name, store, serial)
.getService(Components.interfaces.nsIIOService); .getService(Components.interfaces.nsIIOService);
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);
const XHTML = "http://www.w3.org/1999/xhtml"; const namespace = '@namespace html "' + XHTML + '";\n' +
const namespace = "@namespace html url(" + XHTML + ");\n" + '@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' +
"@namespace xul url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);\n"; '@namespace liberator "' + NS.uri + '";\n';
const Sheet = new Struct("name", "sites", "css", "ref"); const Sheet = new Struct("name", "sites", "css", "ref");
let cssUri = function (css) "chrome-data:text/css," + encodeURI(css); let cssUri = function (css) "chrome-data:text/css," + encodeURI(css);
@@ -373,13 +395,13 @@ let (array = util.Array)
}; };
} }
const styles = storage.newObject("styles", Styles, false); const styles = storage.newObject("styles", Styles, false);
try {
const highlight = storage.newObject("highlight", Highlights, false);
} catch(e) { liberator.reportError(e) }
liberator.registerObserver("load_commands", function () liberator.registerObserver("load_commands", function ()
{ {
const highlight = storage.newObject("highlight", Highlights, false);
// TODO: :colo default needs :hi clear // TODO: :colo default needs :hi clear
commands.add(["colo[rscheme]"], commands.add(["colo[rscheme]"],
"Load a color scheme", "Load a color scheme",

View File

@@ -48,13 +48,13 @@ const template = {
var desc = this.process[1].call(this, item, this.getKey(item, "description")); var desc = this.process[1].call(this, item, this.getKey(item, "description"));
} }
return <div class={class || "hl-CompItem"}> return <div highlight={class || "CompItem"}>
<!-- The non-breaking spaces prevent empty elements <!-- The non-breaking spaces prevent empty elements
- from pushing the baseline down and enlarging - from pushing the baseline down and enlarging
- the row. - the row.
--> -->
<li class="hl-CompResult">{text}&#160;</li> <li highlight="CompResult">{text}&#160;</li>
<li class="hl-CompDesc">{desc}&#160;</li> <li highlight="CompDesc">{desc}&#160;</li>
</div>; </div>;
}, },
@@ -62,7 +62,7 @@ const template = {
{ {
let extra = this.getKey(item, "extra"); let extra = this.getKey(item, "extra");
return <> return <>
<a href="#" class="hl-URL">{text}</a>&#160; <a href="#" highlight="URL">{text}</a>&#160;
{ {
!(extra && extra.length) ? "" : !(extra && extra.length) ? "" :
<span class="extra-info"> <span class="extra-info">
@@ -79,10 +79,10 @@ const template = {
icon: function (item, text) icon: function (item, text)
{ {
let icon = this.getKey(item, "icon"); let icon = this.getKey(item, "icon");
return <><span class="hl-CompIcon">{icon ? <img src={icon}/> : <></>}</span>{text}</> return <><span highlight="CompIcon">{icon ? <img src={icon}/> : <></>}</span>{text}</>
}, },
filter: function (str) <span class="hl-Filter">{str}</span>, filter: function (str) <span highlight="Filter">{str}</span>,
// if "processStrings" is true, any passed strings will be surrounded by " and // if "processStrings" is true, any passed strings will be surrounded by " and
// any line breaks are displayed as \n // any line breaks are displayed as \n
@@ -95,29 +95,29 @@ const template = {
switch (arg == null ? "undefined" : typeof arg) switch (arg == null ? "undefined" : typeof arg)
{ {
case "number": case "number":
return <span class="hl-Number">{str}</span>; return <span highlight="Number">{str}</span>;
case "string": case "string":
if (processStrings) if (processStrings)
str = str.quote(); str = str.quote();
return <span class="hl-String">{str}</span>; return <span highlight="String">{str}</span>;
case "boolean": case "boolean":
return <span class="hl-Boolean">{str}</span>; return <span highlight="Boolean">{str}</span>;
case "function": case "function":
// Vim generally doesn't like /foo*/, because */ looks like a comment terminator. // Vim generally doesn't like /foo*/, because */ looks like a comment terminator.
// Using /foo*(:?)/ instead. // Using /foo*(:?)/ instead.
if (processStrings) if (processStrings)
return <span class="hl-Function">{str.replace(/\{(.|\n)*(?:)/g, "{ ... }")}</span>; return <span highlight="Function">{str.replace(/\{(.|\n)*(?:)/g, "{ ... }")}</span>;
return <>{arg}</>; return <>{arg}</>;
case "undefined": case "undefined":
return <span class="hl-Null">{arg}</span>; return <span highlight="Null">{arg}</span>;
case "object": case "object":
// for java packages value.toString() would crash so badly // for java packages value.toString() would crash so badly
// that we cannot even try/catch it // that we cannot even try/catch it
if (/^\[JavaPackage.*\]$/.test(arg)) if (/^\[JavaPackage.*\]$/.test(arg))
return <>[JavaPackage]</>; return <>[JavaPackage]</>;
if (processStrings && false) if (processStrings && false)
str = template.highlightFilter(str, "\n", function () <span class="hl-NonText">^J</span>); str = template.highlightFilter(str, "\n", function () <span highlight="NonText">^J</span>);
return <span class="hl-Object">{str}</span>; return <span highlight="Object">{str}</span>;
case "xml": case "xml":
return arg; return arg;
default: default:
@@ -179,7 +179,7 @@ const template = {
highlightURL: function highlightURL(str, force) highlightURL: function highlightURL(str, force)
{ {
if (force || /^[a-zA-Z]+:\/\//.test(str)) if (force || /^[a-zA-Z]+:\/\//.test(str))
return <a class="hl-URL" href="#">{str}</a>; return <a highlight="URL" href="#">{str}</a>;
else else
return str; return str;
}, },
@@ -205,7 +205,7 @@ const template = {
{ {
return this.generic( return this.generic(
<table> <table>
<tr style="text-align: left;" class="hl-Title"> <tr style="text-align: left;" highlight="Title">
<th colspan="2">jump</th><th>title</th><th>URI</th> <th colspan="2">jump</th><th>title</th><th>URI</th>
</tr> </tr>
{ {
@@ -214,7 +214,7 @@ const template = {
<td class="indicator">{idx == index ? ">" : ""}</td> <td class="indicator">{idx == index ? ">" : ""}</td>
<td>{Math.abs(idx - index)}</td> <td>{Math.abs(idx - index)}</td>
<td style="width: 250px; max-width: 500px; overflow: hidden;">{val.title}</td> <td style="width: 250px; max-width: 500px; overflow: hidden;">{val.title}</td>
<td><a href="#" class="hl-URL jump-list">{val.URI.spec}</a></td> <td><a href="#" highlight="URL jump-list">{val.URI.spec}</a></td>
</tr>) </tr>)
} }
</table>); </table>);
@@ -224,7 +224,7 @@ const template = {
{ {
return this.generic( return this.generic(
<table> <table>
<tr class="hl-Title" align="left"> <tr highlight="Title" align="left">
<th>--- {title} ---</th> <th>--- {title} ---</th>
</tr> </tr>
{ {
@@ -243,7 +243,7 @@ const template = {
{ {
let table = let table =
<table> <table>
<tr class="hl-Title" align="left"> <tr highlight="Title" align="left">
<th colspan="2">{title}</th> <th colspan="2">{title}</th>
</tr> </tr>
{ {
@@ -263,7 +263,7 @@ const template = {
/* This might be mind-bogglingly slow. We'll see. */ /* This might be mind-bogglingly slow. We'll see. */
return this.generic( return this.generic(
<table> <table>
<tr class="hl-Title" align="left"> <tr highlight="Title" align="left">
{ {
this.map(headings, function (h) this.map(headings, function (h)
<th>{h}</th>) <th>{h}</th>)
@@ -288,7 +288,7 @@ const template = {
{ {
this.map(iter, function (item) this.map(iter, function (item)
<tr> <tr>
<td class="hl-Title" style="padding-right: 20px">{item.name || item.names[0]}</td> <td highlight="Title" style="padding-right: 20px">{item.name || item.names[0]}</td>
<td>{item.description}</td> <td>{item.description}</td>
</tr>) </tr>)
} }

View File

@@ -284,7 +284,7 @@ function CommandLine() //{{{
function setHighlightGroup(group) function setHighlightGroup(group)
{ {
commandlineWidget.setAttribute("class", group); commandlineWidget.setAttributeNS(NS.uri, "highlight", group);
} }
// sets the prompt - for example, : or / // sets the prompt - for example, : or /
@@ -301,7 +301,7 @@ function CommandLine() //{{{
{ {
promptWidget.collapsed = true; promptWidget.collapsed = true;
} }
promptWidget.setAttribute("class", highlightGroup || commandline.HL_NORMAL); promptWidget.setAttributeNS(NS.uri, "highlight", highlightGroup || commandline.HL_NORMAL);
} }
// sets the command - e.g. 'tabopen', 'open http://example.com/' // sets the command - e.g. 'tabopen', 'open http://example.com/'
@@ -320,7 +320,7 @@ function CommandLine() //{{{
.scrollWidth > commandWidget.inputField.scrollWidth) .scrollWidth > commandWidget.inputField.scrollWidth)
{ {
setCommand(""); setCommand("");
setMultiline(<span class="hl-Message">{str}</span>, highlightGroup); setMultiline(<span highlight="Message">{str}</span>, highlightGroup);
} }
} }
@@ -616,7 +616,7 @@ function CommandLine() //{{{
let list = <></>; let list = <></>;
for (let [,message] in Iterator(messageHistory.messages)) for (let [,message] in Iterator(messageHistory.messages))
list += <div class={message.highlight + " hl-Message"}>{message.str}</div>; list += <div highlight={message.highlight + " Message"}>{message.str}</div>;
liberator.echo(list, commandline.FORCE_MULTILINE); liberator.echo(list, commandline.FORCE_MULTILINE);
} }
@@ -629,14 +629,14 @@ function CommandLine() //{{{
return { return {
HL_NORMAL : "hl-Normal", HL_NORMAL : "Normal",
HL_ERRORMSG : "hl-ErrorMsg", HL_ERRORMSG : "ErrorMsg",
HL_MODEMSG : "hl-ModeMsg", HL_MODEMSG : "ModeMsg",
HL_MOREMSG : "hl-MoreMsg", HL_MOREMSG : "MoreMsg",
HL_QUESTION : "hl-Question", HL_QUESTION : "Question",
HL_INFOMSG : "hl-InfoMsg", HL_INFOMSG : "InfoMsg",
HL_WARNINGMSG : "hl-WarningMsg", HL_WARNINGMSG : "WarningMsg",
HL_LINENR : "hl-LineNr", HL_LINENR : "LineNr",
FORCE_MULTILINE : 1 << 0, FORCE_MULTILINE : 1 << 0,
FORCE_SINGLELINE : 1 << 1, FORCE_SINGLELINE : 1 << 1,
@@ -1047,7 +1047,7 @@ function CommandLine() //{{{
// TODO: <LeftMouse> on the prompt line should scroll one page // TODO: <LeftMouse> on the prompt line should scroll one page
case "<LeftMouse>": case "<LeftMouse>":
if (event.originalTarget.className == "hl-URL buffer-list") if (event.originalTarget.getAttributeNS(NS.uri, "highlight") == "URL buffer-list")
{ {
tabs.select(parseInt(event.originalTarget.parentNode.parentNode.firstChild.textContent, 10) - 1); tabs.select(parseInt(event.originalTarget.parentNode.parentNode.firstChild.textContent, 10) - 1);
closeWindow = true; closeWindow = true;
@@ -1315,13 +1315,13 @@ function ItemList(id) //{{{
function init() function init()
{ {
div = dom( div = dom(
<div class="ex-command-output hl-Normal" style="white-space: nowrap"> <div class="ex-command-output" highlight="Normal" style="white-space: nowrap">
<div class="hl-Completions" key="noCompletions"><span class="hl-Title">No Completions</span></div> <div highlight="Completions" key="noCompletions"><span highlight="Title">No Completions</span></div>
<div key="completions"/> <div key="completions"/>
<div class="hl-Completions"> <div highlight="Completions">
{ {
template.map(util.range(0, maxItems), function (i) template.map(util.range(0, maxItems), function (i)
<ul><li class="hl-CompTitle hl-NonText">~</li></ul>) <ul><li highlight="CompTitle NonText">~</li></ul>)
} }
</div> </div>
</div>, divNodes); </div>, divNodes);
@@ -1333,12 +1333,12 @@ function ItemList(id) //{{{
return; return;
context.cache.nodes = []; context.cache.nodes = [];
dom(<div key="root"> dom(<div key="root">
<div class="hl-Completions"> <div highlight="Completions">
{context.createRow(context.title || [], "hl-CompTitle")} {context.createRow(context.title || [], "CompTitle")}
</div> </div>
<div key="up" class="hl-CompLess"/> <div key="up" highlight="CompLess"/>
<div key="items" class="hl-Completions"/> <div key="items" highlight="Completions"/>
<div key="down" class="hl-CompMore"/> <div key="down" highlight="CompMore"/>
</div>, context.cache.nodes); </div>, context.cache.nodes);
divNodes.completions.appendChild(context.cache.nodes.root); divNodes.completions.appendChild(context.cache.nodes.root);
}); });
@@ -1400,7 +1400,7 @@ function ItemList(id) //{{{
divNodes.noCompletions.style.display = (off > 0) ? "none" : "block"; divNodes.noCompletions.style.display = (off > 0) ? "none" : "block";
completionElements = buffer.evaluateXPath("//*[@class='hl-CompItem' and not(contains(@style, 'none'))]", doc); completionElements = buffer.evaluateXPath("//*[@liberator:highlight='CompItem' and not(contains(@style, 'none'))]", doc);
autoSize(); autoSize();
return true; return true;
@@ -1549,7 +1549,7 @@ function StatusLine() //{{{
insecure: "StatusLine" insecure: "StatusLine"
}; };
statusBar.setAttribute("class", "chromeclass-status hl-" + highlightGroup[type]); statusBar.setAttributeNS(NS.uri, "highlight", highlightGroup[type]);
}, },
// update all fields of the statusline // update all fields of the statusline

View File

@@ -26,6 +26,10 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL. the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/ }}} ***** END LICENSE BLOCK *****/
const XHTML = "http://www.w3.org/1999/xhtml";
const NS = Namespace("liberator", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML;
const util = { //{{{ const util = { //{{{
Array: { Array: {
@@ -331,8 +335,8 @@ const util = { //{{{
{ {
obj = "[Object]"; obj = "[Object]";
} }
obj = template.highlightFilter(util.clip(obj, 150), "\n", !color ? function () "^J" : function () <span class="hl-NonText">^J</span>); obj = template.highlightFilter(util.clip(obj, 150), "\n", !color ? function () "^J" : function () <span highlight="NonText">^J</span>);
let string = <><span class="hl-Title hl-Object">{obj}</span>::<br/>&#xa;</>; let string = <><span highlight="Title Object">{obj}</span>::<br/>&#xa;</>;
let keys = []; let keys = [];
try // window.content often does not want to be queried with "var i in object" try // window.content often does not want to be queried with "var i in object"
@@ -504,10 +508,9 @@ const util = { //{{{
case "text": case "text":
return doc.createTextNode(node); return doc.createTextNode(node);
case "element": case "element":
// Should use the node's namespace, in the future. let domnode = doc.createElementNS(node.namespace(), node.localName());
let domnode = doc.createElementNS("http://www.w3.org/1999/xhtml", node.localName());
for each (let attr in node.@*) for each (let attr in node.@*)
domnode.setAttribute(attr.name(), String(attr)); domnode.setAttributeNS(attr.name() == "highlight" ? NS.uri : attr.namespace(), attr.name(), String(attr));
for each (let child in node.*) for each (let child in node.*)
domnode.appendChild(arguments.callee(child, doc, nodes)); domnode.appendChild(arguments.callee(child, doc, nodes));
if (nodes && node.@key) if (nodes && node.@key)