aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS1
-rw-r--r--README.markdown1
-rw-r--r--background_page.html54
-rw-r--r--manifest.json4
-rw-r--r--vimiumFrontend.js36
5 files changed, 68 insertions, 28 deletions
diff --git a/CREDITS b/CREDITS
index 8c986adc..0f1c5797 100644
--- a/CREDITS
+++ b/CREDITS
@@ -14,6 +14,7 @@ Contributors:
lack
markstos
rodimius
+ Tim Morgan <tim@timmorgan.org> (github: seven1m)
tsigo
Feel free to add real names in addition to GitHub usernames.
diff --git a/README.markdown b/README.markdown
index f05aa3a8..dff5f8da 100644
--- a/README.markdown
+++ b/README.markdown
@@ -84,6 +84,7 @@ Release Notes
- In link hints mode, holding down the shift key will now toggle between opening in the current tab and opening in a new tab.
- Two new commands to scroll to the left and right edges of the page bound to zH and zL respectively.
+- Frame support.
- Bug fixes.
1.19 (06/29/2010)
diff --git a/background_page.html b/background_page.html
index 6014d4c8..fb1eb48b 100644
--- a/background_page.html
+++ b/background_page.html
@@ -14,6 +14,8 @@
var keyQueue = ""; // Queue of keys typed
var validFirstKeys = {};
var singleKeyCommands = [];
+ var focusedFrame = null;
+ var framesForTab = {};
// Keys are either literal characters, or "named" - for example <a-b> (alt+b), <left> (the left arrow) or <f12>
// This regular expression captures two groups, the first is a named key, the second is the remainder of the string.
@@ -69,7 +71,7 @@
openUrlInCurrentTab: openUrlInCurrentTab,
openOptionsPageInNewTab: openOptionsPageInNewTab,
registerFrame: registerFrame,
- focusFrame: focusFrame,
+ frameFocused: handleFrameFocused,
upgradeNotificationClosed: upgradeNotificationClosed,
updateScrollPosition: handleUpdateScrollPosition
};
@@ -93,6 +95,7 @@
}
// domReady is the appropriate time to show the "vimium has been upgraded" message.
+ // TODO: This might be broken on pages with frames.
if (shouldShowUpgradeMessage())
chrome.tabs.sendRequest(senderTabId, { name: "showUpgradeNotification", version: currentVersion });
}
@@ -374,6 +377,7 @@
tabQueue[openTabInfo.windowId] = [openTabInfo];
delete openTabs[tabId];
+ delete framesForTab[tabId];
});
chrome.windows.onRemoved.addListener(function(windowId) {
@@ -595,32 +599,54 @@
});
}
- var framesForTab = {};
-
function registerFrame(request, sender) {
- if(request.top)
- framesForTab[sender.tab.id] = [];
- framesForTab[sender.tab.id].push(request.frameId);
+ if (request.top)
+ framesForTab[sender.tab.id] = { total: request.total, frames: [] };
+ else {
+ framesForTab[sender.tab.id].frames.push({ id: request.frameId, area: request.area });
+
+ // We've seen all the frames. Time to focus the largest one.
+ if (framesForTab[sender.tab.id].frames.length == framesForTab[sender.tab.id].total)
+ focusLargestFrame(sender.tab.id);
+ }
}
- var focusedFrame = null;
- function focusFrame(request, sender) {
+ function focusLargestFrame(tabId) {
+ var mainFrameId = null;
+ var mainFrameArea = 0;
+
+ for (var i = 0; i < framesForTab[tabId].frames.length; i++) {
+ var currentFrame = framesForTab[tabId].frames[i];
+
+ if (currentFrame.area > mainFrameArea) {
+ mainFrameId = currentFrame.id;
+ mainFrameArea = currentFrame.area;
+ }
+ }
+
+ chrome.tabs.sendRequest(tabId, { name: "focusFrame", frameId: mainFrameId, highlight: false });
+ }
+
+ function handleFrameFocused(request, sender) {
focusedFrame = request.frameId;
}
function nextFrame(callback, frameId) {
chrome.tabs.getSelected(null, function(tab) {
- //chrome.tabs.sendRequest(tab.id, { name: "showHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId });
var index;
- var frames = framesForTab[tab.id];
- for(index=0; index<frames.length; index++) {
- if(frames[index] == focusedFrame) break;
+ var frames = framesForTab[tab.id].frames;
+
+ for (index=0; index < frames.length; index++) {
+ if (frames[index].id == focusedFrame)
+ break;
}
- if(index >= frames.length-1)
+
+ if (index >= frames.length-1)
index = 0;
else
index++;
- chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[index] });
+
+ chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[index].id, highlight: true });
});
}
diff --git a/manifest.json b/manifest.json
index 703fd069..d49adfa2 100644
--- a/manifest.json
+++ b/manifest.json
@@ -8,7 +8,9 @@
"background_page": "background_page.html",
"options_page": "options.html",
"permissions": [
- "tabs"
+ "tabs",
+ "http://*/*",
+ "https://*/*"
],
"content_scripts": [
{
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index 685e121f..ac7d366a 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -26,6 +26,11 @@ var linkHintCss;
// TODO(philc): This should be pulled from the extension's storage when the page loads.
var currentZoomLevel = 100;
+/*
+ * Give this frame a unique id.
+ */
+frameId = Math.floor(Math.random()*999999999)
+
var hasModifiersRegex = /^<([amc]-)+.>/;
function getSetting(key) {
@@ -69,7 +74,7 @@ function initializePreDomReady() {
showHelpDialog(request.dialogHtml, request.frameId);
else if (request.name == "focusFrame")
if(frameId == request.frameId)
- focusThisFrame();
+ focusThisFrame(request.highlight);
else if (request.name == "refreshCompletionKeys")
refreshCompletionKeys(request.completionKeys);
sendResponse({}); // Free up the resources used by this open connection.
@@ -137,30 +142,22 @@ function initializeWhenEnabled() {
enterInsertModeIfElementIsFocused();
}
-/*
- * Give this frame a unique id and register with the backend.
- */
-frameId = Math.floor(Math.random()*999999999)
-if(window.top == window.self)
- chrome.extension.sendRequest({handler: "registerFrame", frameId: frameId, top: true});
-else
- chrome.extension.sendRequest({handler: "registerFrame", frameId: frameId});
/*
* The backend needs to know which frame has focus.
*/
window.addEventListener("focus", function(e){
- chrome.extension.sendRequest({handler: "focusFrame", frameId: frameId});
+ chrome.extension.sendRequest({handler: "frameFocused", frameId: frameId});
});
/*
* Called from the backend in order to change frame focus.
*/
-function focusThisFrame() {
+function focusThisFrame(shouldHighlight) {
window.focus();
- if(document.body) {
+ if (document.body && shouldHighlight) {
var borderWas = document.body.style.border;
- document.body.style.border = '1px solid red';
+ document.body.style.border = '5px solid yellow';
setTimeout(function(){document.body.style.border = borderWas}, 200);
}
}
@@ -169,6 +166,11 @@ function focusThisFrame() {
* Initialization tasks that must wait for the document to be ready.
*/
function initializeOnDomReady() {
+ if (window.top == window.self)
+ chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, top: true, total: frames.length });
+ else
+ registerFrameIfSizeAvailable();
+
if (isEnabledForUrl)
enterInsertModeIfElementIsFocused();
@@ -176,6 +178,14 @@ function initializeOnDomReady() {
chrome.extension.connect({ name: "domReady" });
};
+// This is a little hacky but sometimes the size wasn't available on domReady?
+function registerFrameIfSizeAvailable () {
+ if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0)
+ chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, area: innerWidth * innerHeight });
+ else
+ setTimeout(registerFrameIfSizeAvailable, 100);
+}
+
/*
* Checks the currently focused element of the document and will enter insert mode if that element is focusable.
*/