diff options
| -rw-r--r-- | background_page.html | 31 | ||||
| -rw-r--r-- | commands.js | 8 | ||||
| -rw-r--r-- | vimiumFrontend.js | 28 |
3 files changed, 64 insertions, 3 deletions
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; index++) { + if(frames[index] == focusedFrame) break; + } + if(index >= frames.length-1) + index = 0; + else + index++; + chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[index] }); + }); + } + function init() { clearKeyMappingsAndSetDefaults(); diff --git a/commands.js b/commands.js index 477e5cd3..e49574e3 100644 --- a/commands.js +++ b/commands.js @@ -92,7 +92,7 @@ function clearKeyMappingsAndSetDefaults() { mapKeyToCommand('<c-f>', 'scrollFullPageDown'); mapKeyToCommand('<c-b>', 'scrollFullPageUp'); mapKeyToCommand('r', 'reload'); - mapKeyToCommand('gf', 'toggleViewSource'); + mapKeyToCommand('gs', 'toggleViewSource'); mapKeyToCommand('i', 'enterInsertMode'); @@ -120,6 +120,8 @@ function clearKeyMappingsAndSetDefaults() { mapKeyToCommand('t', 'createTab'); mapKeyToCommand('d', 'removeTab'); mapKeyToCommand('u', 'restoreTab'); + + mapKeyToCommand('gf', 'nextFrame'); } // Navigating the current page: @@ -166,6 +168,8 @@ addCommand('createTab', 'Create new tab', true); addCommand('removeTab', 'Close current tab', true); addCommand('restoreTab', "Restore closed tab", true); +addCommand('nextFrame', "Cycle forward to the next frame on the page", true); + // An ordered listing of all available commands, grouped by type. This is the order they will // be shown in the help page. @@ -175,7 +179,7 @@ var commandGroups = { "scrollToTop", "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown", "scrollPageUp", "scrollFullPageDown", "reload", "toggleViewSource", "zoomIn", "zoomOut", "copyCurrentUrl", "goUp", "enterInsertMode", "activateLinkHintsMode", "activateLinkHintsModeToOpenInNewTab", - "enterFindMode", "performFind", "performBackwardsFind"], + "enterFindMode", "performFind", "performBackwardsFind", "nextFrame"], historyNavigation: ["goBack", "goForward"], tabManipulation: diff --git a/vimiumFrontend.js b/vimiumFrontend.js index 829ded5e..685e121f 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -67,6 +67,9 @@ function initializePreDomReady() { hideHelpDialog(); else showHelpDialog(request.dialogHtml, request.frameId); + else if (request.name == "focusFrame") + if(frameId == request.frameId) + focusThisFrame(); else if (request.name == "refreshCompletionKeys") refreshCompletionKeys(request.completionKeys); sendResponse({}); // Free up the resources used by this open connection. @@ -135,9 +138,32 @@ function initializeWhenEnabled() { } /* - * Give this frame a unique id. + * 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}); +}); + +/* + * Called from the backend in order to change frame focus. + */ +function focusThisFrame() { + window.focus(); + if(document.body) { + var borderWas = document.body.style.border; + document.body.style.border = '1px solid red'; + setTimeout(function(){document.body.style.border = borderWas}, 200); + } +} /* * Initialization tasks that must wait for the document to be ready. |
