From b489a9e4034e35c897083f9ce97866fd837680d8 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Fri, 3 Sep 2010 06:31:09 -0500 Subject: Basic Support for Frames Only the focused frame will act on key commands. On some sites (such as Gmail), the main frame is already focused, so commands just work. For other sites, focusing the desired frame may be necessary, which can be done with the Tab key (not optimal) or by clicking with the mouse (even less optimal). An additional command to cycle through frames is desirable, which will likely come in a future commit. --- background_page.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index 349212ef..4133a023 100644 --- a/background_page.html +++ b/background_page.html @@ -480,19 +480,20 @@ return {count: count, command: command}; } - function handleKeyDown(key, port) { + function handleKeyDown(request, port) { + var key = request.keyChar; if (key == "") { console.log("clearing keyQueue"); keyQueue = "" } else { console.log("checking keyQueue: [", keyQueue + key, "]"); - keyQueue = checkKeyQueue(keyQueue + key, port.tab.id); + keyQueue = checkKeyQueue(keyQueue + key, port.tab.id, request.frameId); console.log("new KeyQueue: " + keyQueue); } } - function checkKeyQueue(keysToCheck, tabId) { + function checkKeyQueue(keysToCheck, tabId, frameId) { var refreshedCompletionKeys = false; var splitHash = splitKeyQueue(keysToCheck); command = splitHash.command; @@ -507,7 +508,7 @@ if (!registryEntry.isBackgroundCommand) { var port = chrome.tabs.connect(tabId, { name: "executePageCommand" }); - port.postMessage({ command: registryEntry.command, count: count, + port.postMessage({ command: registryEntry.command, count: count, frameId: frameId, completionKeys: generateCompletionKeys("") }); refreshedCompletionKeys = true; -- cgit v1.2.3 From c1d255a662390027a5a61360d173f46b136478b8 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Fri, 3 Sep 2010 19:59:36 -0500 Subject: Fix view source toggle when inside a frame. --- background_page.html | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index 4133a023..1efd6ae0 100644 --- a/background_page.html +++ b/background_page.html @@ -66,6 +66,7 @@ var sendRequestHandlers = { getCompletionKeys: getCompletionKeys, getLinkHintCss: getLinkHintCss, + openUrlInCurrentTab: openUrlInCurrentTab, openOptionsPageInNewTab: openOptionsPageInNewTab, upgradeNotificationClosed: upgradeNotificationClosed, updateScrollPosition: handleUpdateScrollPosition @@ -219,6 +220,15 @@ return {completionKeys: generateCompletionKeys()}; } + /** + * Opens the url in the current tab. + */ + function openUrlInCurrentTab(request) { + chrome.tabs.getSelected(null, function(tab) { + chrome.tabs.update(tab.id, {url: request.url}); + }); + } + /* * Returns the core CSS used for link hints, along with any user-provided overrides. */ -- cgit v1.2.3 From f9f5208f4d88873ee55a4c54062920981ad22eb8 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Fri, 3 Sep 2010 20:15:59 -0500 Subject: Only show the Help Dialog on the focused frame. --- background_page.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index 1efd6ae0..8abe2f9e 100644 --- a/background_page.html +++ b/background_page.html @@ -153,9 +153,9 @@ returnPort.postMessage({ zoomLevel: zoomLevel }); } - function showHelp() { + function showHelp(callback, frameId) { chrome.tabs.getSelected(null, function(tab) { - chrome.tabs.sendRequest(tab.id, { name: "showHelpDialog", dialogHtml: helpDialogHtml() }); + chrome.tabs.sendRequest(tab.id, { name: "showHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId }); }); } @@ -271,9 +271,9 @@ if (selectionChangedHandlers.length > 0) { selectionChangedHandlers.pop().call(); } }); - function repeatFunction(func, totalCount, currentCount) { + function repeatFunction(func, totalCount, currentCount, frameId) { if (currentCount < totalCount) - func(function() { repeatFunction(func, totalCount, currentCount + 1); }); + func(function() { repeatFunction(func, totalCount, currentCount + 1, frameId); }, frameId); } // Returns the scroll coordinates of the given tab. Pass in a callback of the form: @@ -523,7 +523,7 @@ refreshedCompletionKeys = true; } else { - repeatFunction(this[registryEntry.command], count, 0); + repeatFunction(this[registryEntry.command], count, 0, frameId); } newKeyQueue = ""; -- cgit v1.2.3 From f146e5908bd79dcab4d4afa219af79d4a892b099 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Fri, 3 Sep 2010 22:38:45 -0500 Subject: Command to go to next frame. I remapped toggleViewSource to 'gs' and set 'gf' to nextFrame. Sorry this is such a huge commit. This is really the simplest way I can find to allow the extension to track all available frames as well as the currently-focused frame. If Chrome would allow access to window.frames[i], then this could probably be simpler. --- background_page.html | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index 8abe2f9e..6014d4c8 100644 --- a/background_page.html +++ b/background_page.html @@ -68,6 +68,8 @@ getLinkHintCss: getLinkHintCss, openUrlInCurrentTab: openUrlInCurrentTab, openOptionsPageInNewTab: openOptionsPageInNewTab, + registerFrame: registerFrame, + focusFrame: focusFrame, upgradeNotificationClosed: upgradeNotificationClosed, updateScrollPosition: handleUpdateScrollPosition }; @@ -593,6 +595,35 @@ }); } + var framesForTab = {}; + + function registerFrame(request, sender) { + if(request.top) + framesForTab[sender.tab.id] = []; + framesForTab[sender.tab.id].push(request.frameId); + } + + var focusedFrame = null; + function focusFrame(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-1) + index = 0; + else + index++; + chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[index] }); + }); + } + function init() { clearKeyMappingsAndSetDefaults(); -- cgit v1.2.3 From 64b550a4a7fa4af1d9c0996d6f66715dc479ccb5 Mon Sep 17 00:00:00 2001 From: Ilya Sukhar Date: Thu, 23 Sep 2010 23:27:56 -0700 Subject: 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--- background_page.html | 54 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) (limited to 'background_page.html') 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 (alt+b), (the left arrow) or // 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-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 }); }); } -- cgit v1.2.3 From 11b879f6d49f6f5c08cd3276ab871d1ccffb179d Mon Sep 17 00:00:00 2001 From: Ilya Sukhar Date: Fri, 24 Sep 2010 00:37:21 -0700 Subject: Fix some frame logic and disable focusing the largest one for now because it's buggy with iframes. --- background_page.html | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'background_page.html') diff --git a/background_page.html b/background_page.html index b862a881..48084f77 100644 --- a/background_page.html +++ b/background_page.html @@ -604,15 +604,20 @@ } function registerFrame(request, sender) { - if (request.top) - framesForTab[sender.tab.id] = { total: request.total, frames: [] }; - else { - framesForTab[sender.tab.id].frames.push({ id: request.frameId, area: request.area }); + if (!framesForTab[sender.tab.id]) + framesForTab[sender.tab.id] = { frames: [] }; - // 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); + if (request.top) { + focusedFrame = request.frameId; + framesForTab[sender.tab.id].total = request.total; } + + framesForTab[sender.tab.id].frames.push({ id: request.frameId, area: request.area }); + + // We've seen all the frames. Time to focus the largest one. + // NOTE: Disabled because it's buggy with iframes. + // if (framesForTab[sender.tab.id].frames.length >= framesForTab[sender.tab.id].total) + // focusLargestFrame(sender.tab.id); } function focusLargestFrame(tabId) { -- cgit v1.2.3