1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-31 01:03:31 +02:00

don't attempt to add the frame indicator if v.buffer.shiftFrameFocus is called

on a non-HTML document
This commit is contained in:
Doug Kearns
2007-11-06 12:10:25 +00:00
parent 4faab88df1
commit 235dd7bc60

View File

@@ -311,103 +311,100 @@ vimperator.Buffer = function() //{{{
// TODO: allow callback for filtering out unwanted frames? User defined? // TODO: allow callback for filtering out unwanted frames? User defined?
this.shiftFrameFocus = function(count, forward) this.shiftFrameFocus = function(count, forward)
{ {
try if (!window.content.document instanceof HTMLDocument)
return;
var frames = [];
// find all frames - depth-first search
(function(frame)
{ {
var frames = []; if (frame.document.body.localName.toLowerCase() == "body")
frames.push(frame);
for (var i = 0; i < frame.frames.length; i++)
arguments.callee(frame.frames[i])
})(window.content);
// find all frames - depth-first search if (frames.length == 0) // currently top is always included
(function(frame) return;
// remove all unfocusable frames
// TODO: find a better way to do this - walking the tree is too slow
var start = document.commandDispatcher.focusedWindow;
frames = frames.filter(function(frame) {
frame.focus();
if (document.commandDispatcher.focusedWindow == frame)
return frame;
});
start.focus();
// find the currently focused frame index
// TODO: If the window is a frameset then the first _frame_ should be
// focused. Since this is not the current FF behaviour,
// we initalize current to -1 so the first call takes us to the
// first frame.
var current = -1;
for (var i = 0; i < frames.length; i++)
{
if (frames[i] == document.commandDispatcher.focusedWindow)
{ {
if (frame.document.body.localName.toLowerCase() == "body") var current = i;
frames.push(frame); break;
for (var i = 0; i < frame.frames.length; i++)
arguments.callee(frame.frames[i])
})(window.content);
if (frames.length == 0) // currently top is always included
return;
// remove all unfocusable frames
// TODO: find a better way to do this
var start = document.commandDispatcher.focusedWindow;
frames = frames.filter(function(frame) {
frame.focus();
if (document.commandDispatcher.focusedWindow == frame)
return frame;
});
start.focus();
// find the currently focused frame index
// TODO: If the window is a frameset then the first _frame_ should be
// focused. Since this is not the current FF behaviour,
// we initalize current to -1 so the first call takes us to the
// first frame.
var current = -1;
for (var i = 0; i < frames.length; i++)
{
if (frames[i] == document.commandDispatcher.focusedWindow)
{
var current = i;
break;
}
} }
}
// calculate the next frame to focus // calculate the next frame to focus
var next = current; var next = current;
if (forward) if (forward)
{ {
if (count > 1) if (count > 1)
next = current + count; next = current + count;
else
next++;
if (next > frames.length - 1)
{
if (current == frames.length - 1)
vimperator.beep(); // still allow the frame indicator to be activated
next = frames.length - 1;
}
}
else else
next++;
if (next > frames.length - 1)
{ {
if (count > 1) if (current == frames.length - 1)
next = current - count; vimperator.beep(); // still allow the frame indicator to be activated
else
next--;
if (next < 0) next = frames.length - 1;
{
if (current == 0)
vimperator.beep(); // still allow the frame indicator to be activated
next = 0;
}
} }
// focus next frame and scroll into view
frames[next].focus();
if (frames[next] != window.content)
frames[next].frameElement.scrollIntoView(false);
// add the frame indicator
var doc = frames[next].document;
var indicator = doc.createElement("div");
indicator.id = "vimperator-frame-indicator";
// NOTE: need to set a high z-index - it's a crapshoot!
var style = "background-color: red; opacity: 0.5; z-index: 999;" +
"position: fixed; top: 0; bottom: 0; left: 0; right: 0;";
indicator.setAttribute("style", style);
doc.body.appendChild(indicator);
// remove the frame indicator
setTimeout(function() { doc.body.removeChild(indicator); }, 500);
} }
catch (e) else
{ {
// FIXME: fail silently here for now if (count > 1)
//vimperator.log(e); next = current - count;
else
next--;
if (next < 0)
{
if (current == 0)
vimperator.beep(); // still allow the frame indicator to be activated
next = 0;
}
} }
// focus next frame and scroll into view
frames[next].focus();
if (frames[next] != window.content)
frames[next].frameElement.scrollIntoView(false);
// add the frame indicator
// TODO: make this an XBL element rather than messing with the content
// document
var doc = frames[next].document;
var indicator = doc.createElement("div");
indicator.id = "vimperator-frame-indicator";
// NOTE: need to set a high z-index - it's a crapshoot!
var style = "background-color: red; opacity: 0.5; z-index: 999;" +
"position: fixed; top: 0; bottom: 0; left: 0; right: 0;";
indicator.setAttribute("style", style);
doc.body.appendChild(indicator);
// remove the frame indicator
setTimeout(function() { doc.body.removeChild(indicator); }, 500);
} }
// updates the buffer preview in place only if list is visible // updates the buffer preview in place only if list is visible
@@ -506,13 +503,13 @@ vimperator.Buffer = function() //{{{
if (!aData || !aPrincipal) if (!aData || !aPrincipal)
return false; return false;
if (!aIsFeed) if (!aIsFeed)
{ {
var type = aData.type && aData.type.toLowerCase(); var type = aData.type && aData.type.toLowerCase();
type = type.replace(/^\s+|\s*(?:;.*)?$/g, ""); type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
aIsFeed = (type == "application/rss+xml" || type == "application/atom+xml"); aIsFeed = (type == "application/rss+xml" || type == "application/atom+xml");
if (!aIsFeed) if (!aIsFeed)
{ {
// really slimy: general XML types with magic letters in the title // really slimy: general XML types with magic letters in the title
const titleRegex = /(^|\s)rss($|\s)/i; const titleRegex = /(^|\s)rss($|\s)/i;
@@ -521,7 +518,7 @@ vimperator.Buffer = function() //{{{
} }
} }
if (aIsFeed) if (aIsFeed)
{ {
try try
{ {
@@ -595,7 +592,7 @@ vimperator.Buffer = function() //{{{
// put feeds rss into pageFeeds[] // put feeds rss into pageFeeds[]
var linkNodes = window.content.document.getElementsByTagName("link"); var linkNodes = window.content.document.getElementsByTagName("link");
var length = linkNodes.length; var length = linkNodes.length;
for (var i = 0; i < length; i++) for (var i = 0; i < length; i++)
{ {
var link = linkNodes[i]; var link = linkNodes[i];
if (!link.href) if (!link.href)
@@ -603,16 +600,16 @@ vimperator.Buffer = function() //{{{
var rel = link.rel && link.rel.toLowerCase(); var rel = link.rel && link.rel.toLowerCase();
var rels = {}; var rels = {};
if (rel) if (rel)
{ {
for each (let relVal in rel.split(/\s+/)) for each (let relVal in rel.split(/\s+/))
rels[relVal] = true; rels[relVal] = true;
} }
if (rels.feed || (link.type && rels.alternate && !rels.stylesheet)) if (rels.feed || (link.type && rels.alternate && !rels.stylesheet))
{ {
var feed = { title: link.title, href: link.href, type: link.type || "" }; var feed = { title: link.title, href: link.href, type: link.type || "" };
if (isValidFeed(feed, window.content.document.nodePrincipal, rels.feed)) if (isValidFeed(feed, window.content.document.nodePrincipal, rels.feed))
{ {
// var type = feedTypes[feed.type] || feedTypes["application/rss+xml"]; // TODO: dig into that.. --calmar // var type = feedTypes[feed.type] || feedTypes["application/rss+xml"]; // TODO: dig into that.. --calmar
var type = feed.type || "application/rss+xml"; var type = feed.type || "application/rss+xml";
@@ -628,18 +625,18 @@ vimperator.Buffer = function() //{{{
var file = window.content.document.location.pathname.split("/").pop() || "[No Name]"; var file = window.content.document.location.pathname.split("/").pop() || "[No Name]";
var title = window.content.document.title || "[No Title]"; var title = window.content.document.title || "[No Title]";
if (pageSize[1]) if (pageSize[1])
info.push(pageSize[1] + "KiB"); info.push(pageSize[1] + "KiB");
var lastMod = window.content.document.lastModified.slice(0, -3); var lastMod = window.content.document.lastModified.slice(0, -3);
if (lastMod) if (lastMod)
info.push(lastMod); info.push(lastMod);
var countFeeds = ""; var countFeeds = "";
if (pageFeeds.length) if (pageFeeds.length)
countFeeds = pageFeeds.length + (pageFeeds.length == 1 ? " feed" : " feeds"); countFeeds = pageFeeds.length + (pageFeeds.length == 1 ? " feed" : " feeds");
if (countFeeds) if (countFeeds)
info.push(countFeeds); info.push(countFeeds);
var pageInfoText = '"' + file + '" [' + info.join(", ") + "] " + title; var pageInfoText = '"' + file + '" [' + info.join(", ") + "] " + title;
@@ -652,7 +649,7 @@ vimperator.Buffer = function() //{{{
pageGeneral.push(["URL", vimperator.util.highlightURL(window.content.document.location.toString(), true)]); pageGeneral.push(["URL", vimperator.util.highlightURL(window.content.document.location.toString(), true)]);
var ref = "referrer" in window.content.document && window.content.document.referrer; var ref = "referrer" in window.content.document && window.content.document.referrer;
if (ref) if (ref)
pageGeneral.push(["Referrer", vimperator.util.highlightURL(ref, true)]); pageGeneral.push(["Referrer", vimperator.util.highlightURL(ref, true)]);
if (pageSize[0]) if (pageSize[0])
@@ -697,26 +694,26 @@ vimperator.Buffer = function() //{{{
{ {
switch (option[z]) switch (option[z])
{ {
case "g": case "g":
if (pageGeneral.length > 1) if (pageGeneral.length > 1)
{ {
pageInfoText += br + createTable(pageGeneral); pageInfoText += br + createTable(pageGeneral);
if (!br) if (!br)
br = "<br/>"; br = "<br/>";
} }
break; break;
case "f": case "f":
if (pageFeeds.length > 1) if (pageFeeds.length > 1)
{ {
pageInfoText += br + createTable(pageFeeds); pageInfoText += br + createTable(pageFeeds);
if (!br) if (!br)
br = "<br/>"; br = "<br/>";
} }
break; break;
case "m": case "m":
if (pageMeta.length > 1) if (pageMeta.length > 1)
{ {
pageInfoText += br + createTable(pageMeta); pageInfoText += br + createTable(pageMeta);
if (!br) if (!br)
br = "<br/>"; br = "<br/>";
} }