mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 21:37:58 +01:00
speeded up hints display on large sites by factor 2
This commit is contained in:
@@ -167,7 +167,7 @@ vimperator.Buffer = function() //{{{
|
|||||||
});
|
});
|
||||||
|
|
||||||
// returns an XPathResult object
|
// returns an XPathResult object
|
||||||
this.evaluateXPath = function(expression, doc, elem, ordered)
|
this.evaluateXPath = function(expression, doc, elem, asIterator)
|
||||||
{
|
{
|
||||||
if (!doc)
|
if (!doc)
|
||||||
doc = window.content.document;
|
doc = window.content.document;
|
||||||
@@ -183,7 +183,7 @@ vimperator.Buffer = function() //{{{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ordered ? XPathResult.ORDERED_NODE_SNAPSHOT_TYPE : XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
asIterator ? XPathResult.UNORDERED_NODE_ITERATOR_TYPE : XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -149,12 +149,20 @@ vimperator.Hints = function() //{{{
|
|||||||
if (hintsGenerated)
|
if (hintsGenerated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var startDate = Date.now();
|
||||||
|
hints = [];
|
||||||
|
|
||||||
if (!win)
|
if (!win)
|
||||||
win = window.content;
|
win = window.content;
|
||||||
|
|
||||||
var doc = win.document;
|
var doc = win.document;
|
||||||
docs.push(doc);
|
docs.push(doc);
|
||||||
|
|
||||||
|
var height = win.innerHeight;
|
||||||
|
var width = win.innerWidth;
|
||||||
|
var scrollX = doc.defaultView.scrollX;
|
||||||
|
var scrollY = doc.defaultView.scrollY;
|
||||||
|
|
||||||
var baseNodeAbsolute = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
|
var baseNodeAbsolute = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
|
||||||
baseNodeAbsolute.style.backgroundColor = "red";
|
baseNodeAbsolute.style.backgroundColor = "red";
|
||||||
baseNodeAbsolute.style.color = "white";
|
baseNodeAbsolute.style.color = "white";
|
||||||
@@ -164,21 +172,18 @@ vimperator.Hints = function() //{{{
|
|||||||
baseNodeAbsolute.style.lineHeight = "10px";
|
baseNodeAbsolute.style.lineHeight = "10px";
|
||||||
baseNodeAbsolute.style.padding = "0px 1px 0px 0px";
|
baseNodeAbsolute.style.padding = "0px 1px 0px 0px";
|
||||||
baseNodeAbsolute.style.zIndex = "10000001";
|
baseNodeAbsolute.style.zIndex = "10000001";
|
||||||
|
baseNodeAbsolute.style.display = "none";
|
||||||
baseNodeAbsolute.className = "vimperator-hint";
|
baseNodeAbsolute.className = "vimperator-hint";
|
||||||
|
|
||||||
var res = vimperator.buffer.evaluateXPath(vimperator.options["hinttags"], doc, null, true);
|
|
||||||
var elem, tagname, text, span, rect;
|
var elem, tagname, text, span, rect;
|
||||||
vimperator.log("Hinting " + res.snapshotLength + " items on " + doc.title);
|
var res = vimperator.buffer.evaluateXPath(vimperator.options["hinttags"], doc, null, true);
|
||||||
|
vimperator.log("evaluated XPath after: " + (Date.now() - startDate) + "ms");
|
||||||
|
|
||||||
var height = window.content.innerHeight;
|
var fragment = doc.createDocumentFragment();
|
||||||
var width = window.content.innerWidth;
|
while ((elem = res.iterateNext()) != null)
|
||||||
hints = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < res.snapshotLength; i++)
|
|
||||||
{
|
{
|
||||||
elem = res.snapshotItem(i);
|
|
||||||
rect = elem.getBoundingClientRect();
|
rect = elem.getBoundingClientRect();
|
||||||
if (!rect || rect.bottom < 0 || rect.top > height || rect.right < 0 || rect.left > width)
|
if (!rect || rect.top > height || rect.bottom < 0 || rect.left > width || rect.right < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rect = elem.getClientRects()[0];
|
rect = elem.getClientRects()[0];
|
||||||
@@ -199,13 +204,15 @@ vimperator.Hints = function() //{{{
|
|||||||
text = elem.textContent.toLowerCase();
|
text = elem.textContent.toLowerCase();
|
||||||
|
|
||||||
span = baseNodeAbsolute.cloneNode(true);
|
span = baseNodeAbsolute.cloneNode(true);
|
||||||
span.innerHTML = "";
|
span.style.left = (rect.left + scrollX) + "px";
|
||||||
span.style.display = "none";
|
span.style.top = (rect.top + scrollY) + "px";
|
||||||
doc.body.appendChild(span);
|
fragment.appendChild(span);
|
||||||
|
|
||||||
hints.push([elem, text, span, null, elem.style.backgroundColor, elem.style.color]);
|
hints.push([elem, text, span, null, elem.style.backgroundColor, elem.style.color]);
|
||||||
}
|
}
|
||||||
|
doc.body.appendChild(fragment);
|
||||||
|
|
||||||
|
vimperator.log("hints.generate() completed after: " + (Date.now() - startDate) + "ms");
|
||||||
hintsGenerated = true;
|
hintsGenerated = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -234,6 +241,8 @@ vimperator.Hints = function() //{{{
|
|||||||
|
|
||||||
function showHints(win, start_idx)
|
function showHints(win, start_idx)
|
||||||
{
|
{
|
||||||
|
var startDate = Date.now();
|
||||||
|
|
||||||
if (!win)
|
if (!win)
|
||||||
win = window.content;
|
win = window.content;
|
||||||
|
|
||||||
@@ -256,6 +265,7 @@ vimperator.Hints = function() //{{{
|
|||||||
var height = window.content.innerHeight;
|
var height = window.content.innerHeight;
|
||||||
var width = window.content.innerWidth;
|
var width = window.content.innerWidth;
|
||||||
var find_tokens = hintString.split(/ +/);
|
var find_tokens = hintString.split(/ +/);
|
||||||
|
var activeHint = hintNumber || 1;
|
||||||
valid_hints = [];
|
valid_hints = [];
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
@@ -283,53 +293,38 @@ outer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (text == "" && elem.firstChild && elem.firstChild.tagName == "IMG")
|
if (text == "" && elem.firstChild && elem.firstChild.tagName == "IMG")
|
||||||
|
{
|
||||||
|
if (!imgspan)
|
||||||
{
|
{
|
||||||
rect = elem.firstChild.getBoundingClientRect();
|
rect = elem.firstChild.getBoundingClientRect();
|
||||||
if (!rect)
|
if (!rect)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!imgspan)
|
|
||||||
{
|
|
||||||
imgspan = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
|
imgspan = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
|
||||||
imgspan.style.backgroundColor = "yellow";
|
|
||||||
imgspan.style.position = "absolute";
|
imgspan.style.position = "absolute";
|
||||||
imgspan.style.opacity = 0.5;
|
imgspan.style.opacity = 0.5;
|
||||||
imgspan.style.zIndex = "10000000";
|
imgspan.style.zIndex = "10000000";
|
||||||
imgspan.className = "vimperator-hint";
|
|
||||||
hints[i][3] = imgspan;
|
|
||||||
doc.body.appendChild(imgspan);
|
|
||||||
}
|
|
||||||
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 = "vimperator-hint";
|
||||||
|
hints[i][3] = imgspan;
|
||||||
|
doc.body.appendChild(imgspan);
|
||||||
|
}
|
||||||
|
imgspan.style.backgroundColor = (activeHint == i + 1) ? "#88FF00" : "yellow";
|
||||||
imgspan.style.display = "inline";
|
imgspan.style.display = "inline";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
rect = elem.getClientRects()[0];
|
|
||||||
|
|
||||||
if (rect)
|
|
||||||
{
|
|
||||||
if (!imgspan)
|
if (!imgspan)
|
||||||
{
|
elem.style.backgroundColor = (activeHint == i + 1) ? "#88FF00" : "yellow";
|
||||||
var activeNum = hintNumber || 1;
|
|
||||||
if (hintnum == activeNum)
|
|
||||||
elem.style.backgroundColor = "#88FF00";
|
|
||||||
else
|
|
||||||
elem.style.backgroundColor = "yellow";
|
|
||||||
}
|
|
||||||
|
|
||||||
elem.style.color = "black";
|
elem.style.color = "black";
|
||||||
span.style.left = (rect.left + scrollX) + "px";
|
span.textContent = "" + (hintnum++);
|
||||||
span.style.top = (rect.top + scrollY) + "px";
|
|
||||||
span.innerHTML = "" + (hintnum++);
|
|
||||||
span.style.display = "inline";
|
span.style.display = "inline";
|
||||||
valid_hints.push(elem);
|
valid_hints.push(elem);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vimperator.log("Hinted " + valid_hints.length + " items of " + hints.length + " matching " + hintString, 7);
|
vimperator.log("showHints() completed after: " + (Date.now() - startDate) + "ms");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,6 +496,8 @@ outer:
|
|||||||
|
|
||||||
canUpdate = true;
|
canUpdate = true;
|
||||||
showHints(null);
|
showHints(null);
|
||||||
|
|
||||||
|
vimperator.log("hints.show(" + filter + ") took: " + (Date.now() - startDate) + "ms");
|
||||||
if (valid_hints.length == 0)
|
if (valid_hints.length == 0)
|
||||||
{
|
{
|
||||||
vimperator.beep();
|
vimperator.beep();
|
||||||
@@ -605,6 +602,15 @@ outer:
|
|||||||
hintNumber = (hintNumber * 10) + parseInt(key, 10);
|
hintNumber = (hintNumber * 10) + parseInt(key, 10);
|
||||||
|
|
||||||
vimperator.statusline.updateInputBuffer(hintString + (hintNumber > 0 ? hintNumber : ""));
|
vimperator.statusline.updateInputBuffer(hintString + (hintNumber > 0 ? hintNumber : ""));
|
||||||
|
if (!canUpdate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!hintsGenerated)
|
||||||
|
{
|
||||||
|
generate();
|
||||||
|
showHints();
|
||||||
|
}
|
||||||
|
|
||||||
if (hintNumber == 0 || hintNumber > valid_hints.length)
|
if (hintNumber == 0 || hintNumber > valid_hints.length)
|
||||||
{
|
{
|
||||||
vimperator.beep();
|
vimperator.beep();
|
||||||
@@ -623,10 +629,10 @@ outer:
|
|||||||
if (!hintsGenerated && hintString.length > 0)
|
if (!hintsGenerated && hintString.length > 0)
|
||||||
generate();
|
generate();
|
||||||
|
|
||||||
showHints(null);
|
showHints();
|
||||||
processHints(followFirst);
|
processHints(followFirst);
|
||||||
}
|
}
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ vimperator.modes = (function()
|
|||||||
// for its cleanup here
|
// for its cleanup here
|
||||||
function handleModeChange(oldmode, newmode)
|
function handleModeChange(oldmode, newmode)
|
||||||
{
|
{
|
||||||
vimperator.log("switching from mode " + oldmode + " to mode " + newmode, 7);
|
// TODO: fix v.log() to work verbosity level
|
||||||
|
// vimperator.log("switching from mode " + oldmode + " to mode " + newmode, 7);
|
||||||
|
|
||||||
switch (oldmode)
|
switch (oldmode)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user