diff options
| author | Ilya Sukhar | 2010-09-23 23:27:56 -0700 |
|---|---|---|
| committer | Ilya Sukhar | 2010-09-23 23:34:54 -0700 |
| commit | 64b550a4a7fa4af1d9c0996d6f66715dc479ccb5 (patch) | |
| tree | 97b9a995a70c725c2168eb9eb27e75f6ed204e82 | |
| parent | f377565c3b5c3731623c24da96c8623860cec3f2 (diff) | |
| download | vimium-64b550a4a7fa4af1d9c0996d6f66715dc479ccb5.tar.bz2 | |
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
| -rw-r--r-- | CREDITS | 1 | ||||
| -rw-r--r-- | README.markdown | 1 | ||||
| -rw-r--r-- | background_page.html | 54 | ||||
| -rw-r--r-- | manifest.json | 4 | ||||
| -rw-r--r-- | vimiumFrontend.js | 36 |
5 files changed, 68 insertions, 28 deletions
@@ -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. */ |
