Skip to content
Browse files

A bunch of changes having to do with the frame support patch:

- Focus the largest frame by default
- Change the border styling to match link hints
- Clean up framesForTab when tab is closed
- Don't cycle through parent. This may break some sites. Needs more testing.
- Fixed some naming and style
- Added seven1m to CREDITS
- Updated README
  • Loading branch information...
1 parent f377565 commit 64b550a4a7fa4af1d9c0996d6f66715dc479ccb5 Ilya Sukhar committed
Showing with 68 additions and 28 deletions.
  1. +1 −0 CREDITS
  2. +1 −0 README.markdown
  3. +40 −14 background_page.html
  4. +3 −1 manifest.json
  5. +23 −13 vimiumFrontend.js
View
1 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.
View
1 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)
View
54 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 });
});
}
View
4 manifest.json
@@ -8,7 +8,9 @@
"background_page": "background_page.html",
"options_page": "options.html",
"permissions": [
- "tabs"
+ "tabs",
+ "http://*/*",
+ "https://*/*"
],
"content_scripts": [
{
View
36 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.
*/

0 comments on commit 64b550a

Please sign in to comment.
Something went wrong with that request. Please try again.