From c5ad2a1642d14c23483fc3ebb6b5d1059116e9ea Mon Sep 17 00:00:00 2001
From: Max Cantor
Date: Thu, 5 May 2011 15:58:01 -0400
Subject: changed nextFrame so it works with a count given, and fixed a bug
where refreshing a tab breaks frame support because the framesForTab entry is
appended with every onUpdate instead of being replaced.
---
background_page.html | 43 +++++++++++++++++++++++++++++--------------
commands.js | 2 +-
vimiumFrontend.js | 6 +++---
3 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/background_page.html b/background_page.html
index 4763c0d6..eca7271c 100644
--- a/background_page.html
+++ b/background_page.html
@@ -369,6 +369,8 @@
function updateOpenTabs(tab) {
openTabs[tab.id] = { url: tab.url, positionIndex: tab.index, windowId: tab.windowId };
+ // Frames are recreated on refresh
+ delete framesForTab[tab.id];
}
function handleUpdateScrollPosition(request, sender) {
@@ -575,7 +577,11 @@
refreshedCompletionKeys = true;
} else {
- repeatFunction(this[registryEntry.command], count, 0, frameId);
+ if(registryEntry.passCountToFunction){
+ this[registryEntry.command](count);
+ } else {
+ repeatFunction(this[registryEntry.command], count, 0, frameId);
+ }
}
newKeyQueue = "";
@@ -647,7 +653,7 @@
if (!framesForTab[sender.tab.id])
framesForTab[sender.tab.id] = { frames: [] };
- if (request.top) {
+ if (request.is_top) {
focusedFrame = request.frameId;
framesForTab[sender.tab.id].total = request.total;
}
@@ -680,25 +686,34 @@
focusedFrame = request.frameId;
}
- function nextFrame(callback, frameId) {
+ function nextFrame(count) {
chrome.tabs.getSelected(null, function(tab) {
- var index;
var frames = framesForTab[tab.id].frames;
-
- for (index=0; index < frames.length; index++) {
- if (frames[index].id == focusedFrame)
- break;
+ var curr_index = getCurrFrameIndex(frames);
+ var new_index = curr_index;
+
+ // TODO: Skip the "top" frame (which doesn't actually have a tag),
+ // since it exists only to contain the other frames.
+ for (var i=0; i < count; i++) {
+ new_index++;
+ if (new_index >= frames.length)
+ new_index = 0;
}
- if (index >= frames.length-1)
- index = 0;
- else
- index++;
-
- chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[index].id, highlight: true });
+ chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[new_index].id, highlight: true });
});
}
+ function getCurrFrameIndex(frames) {
+ var index;
+ for (index=0; index < frames.length; index++) {
+ if (frames[index].id == focusedFrame)
+ break;
+ }
+ return index;
+ }
+
+
function init() {
clearKeyMappingsAndSetDefaults();
diff --git a/commands.js b/commands.js
index be01a180..c360729b 100644
--- a/commands.js
+++ b/commands.js
@@ -200,7 +200,7 @@ var commandDescriptions = {
removeTab: ["Close current tab", { background: true }],
restoreTab: ["Restore closed tab", { background: true }],
- nextFrame: ["Cycle forward to the next frame on the page", { background: true }]
+ nextFrame: ["Cycle forward to the next frame on the page", { background: true, passCountToFunction: true }]
};
for (var command in commandDescriptions)
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index cc97da93..c9c81381 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -182,12 +182,12 @@ function initializeOnDomReady() {
};
// This is a little hacky but sometimes the size wasn't available on domReady?
-function registerFrameIfSizeAvailable (top) {
+function registerFrameIfSizeAvailable (is_top) {
if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0)
chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId,
- area: innerWidth * innerHeight, top: top, total: frames.length + 1 });
+ area: innerWidth * innerHeight, is_top: is_top, total: frames.length + 1 });
else
- setTimeout(function () { registerFrameIfSizeAvailable(top); }, 100);
+ setTimeout(function () { registerFrameIfSizeAvailable(is_top); }, 100);
}
/*
--
cgit v1.2.3
From 870183f4b2e755a9e4ae58194d1cd5d03579980b Mon Sep 17 00:00:00 2001
From: Max Cantor
Date: Fri, 6 May 2011 11:47:20 -0400
Subject: implementing ilya's suggestion for incrementing the frame
---
background_page.html | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/background_page.html b/background_page.html
index eca7271c..5849bde3 100644
--- a/background_page.html
+++ b/background_page.html
@@ -690,15 +690,10 @@
chrome.tabs.getSelected(null, function(tab) {
var frames = framesForTab[tab.id].frames;
var curr_index = getCurrFrameIndex(frames);
- var new_index = curr_index;
// TODO: Skip the "top" frame (which doesn't actually have a tag),
// since it exists only to contain the other frames.
- for (var i=0; i < count; i++) {
- new_index++;
- if (new_index >= frames.length)
- new_index = 0;
- }
+ var new_index = (curr_index + count) % frames.length;
chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[new_index].id, highlight: true });
});
--
cgit v1.2.3