Skip to content

Commit

Permalink
Remove the zooming functionality. It conflict's with Chrome's native …
Browse files Browse the repository at this point in the history
…zooming and doesn't work as well.

Now that Chrome saves your zoom settings, there's no need for our own zoom implementation.
This also fixes #370.
  • Loading branch information
philc committed Jul 30, 2011
1 parent 9a7a2ef commit dc114c1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 133 deletions.
5 changes: 0 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ Navigating the current page:
F open a link in a new tab
r reload
gs view source
zi zoom in
zo zoom out

This comment has been minimized.

Copy link
@philc

philc Aug 22, 2011

Author Owner

testing github's comments

i enter insert mode -- all commands will be ignored until you hit esc to exit
yy copy the current url to the clipboard
yf copy a link url to the clipboard
Expand Down Expand Up @@ -75,8 +73,6 @@ Additional advanced browsing commands:
gu go up one level in the URL hierarchy
zH scroll all the way left
zL scroll all the way right
z0 reset zoom to default value


Vimium supports command repetition so, for example, hitting '5t' will open 5 tabs in rapid succession. ESC (or
<c-[>) will clear any partial commands in the queue and will also exit insert and find modes.
Expand Down Expand Up @@ -157,7 +153,6 @@ Release Notes
- Some sites are now excluded by default.
- View source (`gs`) now opens in a new tab.
- Support for browsing paginated sites using `]]` and `[[` to go forward and backward respectively.
- `z0` will reset the zoom level for the current page.
- Many of the less-used commands are now marked as "advanced" and hidden in the help dialog by default, so
that the core command set is more focused and approachable.
- Improvements to link hinting.
Expand Down
24 changes: 0 additions & 24 deletions background_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

var defaultSettings = {
scrollStepSize: 60,
defaultZoomLevel: 100,
linkHintCharacters: "sadfjklewcmpgh",
filterLinkHints: false,
userDefinedLinkHintCss:
Expand Down Expand Up @@ -64,8 +63,6 @@
keyDown: handleKeyDown,
returnScrollPosition: handleReturnScrollPosition,
getCurrentTabUrl: getCurrentTabUrl,
getZoomLevel: getZoomLevel,
saveZoomLevel: saveZoomLevel,
getSetting: getSetting,
getBookmarks: getBookmarks
};
Expand Down Expand Up @@ -159,17 +156,6 @@
localStorage["helpDialog_showAdvancedCommands"] = request.showAdvancedCommands;
}

/*
* Returns the previously saved zoom level for the current tab, or the default zoom level
*/
function getZoomLevel(args, port) {
var returnPort = chrome.tabs.connect(port.tab.id, { name: "returnZoomLevel" });
var localStorageKey = "zoom" + args.domain;
var zoomLevelForDomain = (localStorage[localStorageKey] || "").split(",")[1];
var zoomLevel = parseInt(zoomLevelForDomain || getSettingFromLocalStorage("defaultZoomLevel"));
returnPort.postMessage({ zoomLevel: zoomLevel });
}

function showHelp(callback, frameId) {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id,
Expand Down Expand Up @@ -319,16 +305,6 @@
}
}

/*
* Persists the current zoom level for a given domain
*/
function saveZoomLevel(args) {
var localStorageKey = "zoom" + args.domain;
// TODO(philc): We might want to consider expiring these entries after X months as NoSquint does.
// Note(philc): We might also want to jsonify this hash instead of polluting our local storage keyspace.
localStorage[localStorageKey] = [getCurrentTimeInSeconds(), args.zoomLevel].join(",");
}

function getCurrentTimeInSeconds() { Math.floor((new Date()).getTime() / 1000); }

chrome.tabs.onSelectionChanged.addListener(function(tabId, selectionInfo) {
Expand Down
13 changes: 3 additions & 10 deletions commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ function clearKeyMappingsAndSetDefaults() {
"L": "goForward",
"gu": "goUp",

"zi": "zoomIn",
"zo": "zoomOut",
"z0": "zoomReset",

"gi": "focusInput",

"f": "linkHints.activateMode",
Expand Down Expand Up @@ -170,11 +166,8 @@ var commandDescriptions = {

reload: ["Reload the page"],
toggleViewSource: ["View page source"],
zoomIn: ["Zoom in"],
zoomOut: ["Zoom out"],
zoomReset: ["Reset zoom to default value"],
copyCurrentUrl: ["Copy the current URL to the clipboard"],

'linkHints.activateModeToCopyLinkUrl': ["Copy a link URL to the clipboard"],

enterInsertMode: ["Enter insert mode"],
Expand Down Expand Up @@ -223,7 +216,7 @@ var commandGroups = {
["scrollDown", "scrollUp", "scrollLeft", "scrollRight",
"scrollToTop", "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown",
"scrollPageUp", "scrollFullPageUp", "scrollFullPageDown",
"reload", "toggleViewSource", "zoomIn", "zoomOut", "zoomReset", "copyCurrentUrl", "linkHints.activateModeToCopyLinkUrl", "goUp",
"reload", "toggleViewSource", "copyCurrentUrl", "linkHints.activateModeToCopyLinkUrl", "goUp",
"enterInsertMode", "focusInput",
"linkHints.activateMode", "linkHints.activateModeToOpenInNewTab", "linkHints.activateModeWithQueue",
"activateBookmarkFindMode", "activateBookmarkFindModeToOpenInNewTab",
Expand All @@ -242,5 +235,5 @@ var commandGroups = {
// from Vimium will uncover these gems.
var advancedCommands = [
"scrollToLeft", "scrollToRight",
"zoomReset", "goUp", "focusInput", "linkHints.activateModeWithQueue",
"goUp", "focusInput", "linkHints.activateModeWithQueue",
"goPrevious", "goNext"];
9 changes: 1 addition & 8 deletions helpDialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,7 @@
var advanced = VimiumHelpDialog.dialogElement.getElementsByClassName("advanced");
for (var i = 0; i < advanced.length; i++)
advanced[i].style.display = (visible ? "table-row" : "none");
},

centerDialog: function() {
var zoomFactor = currentZoomLevel / 100.0;
this.dialogElement.style.top = Math.max(
(window.innerHeight - this.dialogElement.clientHeight * zoomFactor) / 2.0,
20) / zoomFactor + "px";
}
}
};

VimiumHelpDialog.init();
Expand Down
15 changes: 6 additions & 9 deletions linkHints.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ var linkHints = {
* Returns true if element is visible.
*/
isVisible: function(element, clientRect) {
// Exclude links which have just a few pixels on screen, because the link hints won't show for them anyway.
var zoomFactor = currentZoomLevel / 100.0;
if (!clientRect || clientRect.top < 0 || clientRect.top * zoomFactor >= window.innerHeight - 4 ||
clientRect.left < 0 || clientRect.left * zoomFactor >= window.innerWidth - 4)
// Exclude links which have just a few pixels on screen, because the link hints won't show for them
// anyway.
if (!clientRect || clientRect.top < 0 || clientRect.top >= window.innerHeight - 4 ||
clientRect.left < 0 || clientRect.left >= window.innerWidth - 4)
return false;

if (clientRect.width < 3 || clientRect.height < 3)
Expand Down Expand Up @@ -575,11 +575,8 @@ var hintUtils = {
marker.clickableItem = link.element;

var clientRect = link.rect;
// The coordinates given by the window do not have the zoom factor included since the zoom is set only on
// the document node.
var zoomFactor = currentZoomLevel / 100.0;
marker.style.left = clientRect.left + window.scrollX / zoomFactor + "px";
marker.style.top = clientRect.top + window.scrollY / zoomFactor + "px";
marker.style.left = clientRect.left + window.scrollX + "px";
marker.style.top = clientRect.top + window.scrollY + "px";

return marker;
}
Expand Down
8 changes: 1 addition & 7 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
$ = function(id) { return document.getElementById(id); };
var defaultSettings = chrome.extension.getBackgroundPage().defaultSettings;

var editableFields = ["scrollStepSize", "defaultZoomLevel", "excludedUrls", "linkHintCharacters",
var editableFields = ["scrollStepSize", "excludedUrls", "linkHintCharacters",
"userDefinedLinkHintCss", "keyMappings", "filterLinkHints"];

var canBeEmptyFields = ["excludedUrls", "keyMappings", "userDefinedLinkHintCss"];
Expand Down Expand Up @@ -210,12 +210,6 @@ <h1>Vimium - Options</h1>
<input id="scrollStepSize" type="text" style="width:50px" />px
</td>
</tr>
<tr>
<td><span class="caption">Default zoom level</span></td>
<td>
<input id="defaultZoomLevel" type="text" value="100" style="width:50px" />%
</td>
</tr>
<tr>
<td colspan="3">
Excluded URLs<br/>
Expand Down
74 changes: 4 additions & 70 deletions vimiumFrontend.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* This content script takes input from its webpage and executes commands locally on behalf of the background
* page. It must be run prior to domReady so that we perform some operations very early, like setting
* the page's zoom level. We tell the background page that we're in domReady and ready to accept normal
* commands by connectiong to a port named "domReady".
* page. It must be run prior to domReady so that we perform some operations very early. We tell the
* background page that we're in domReady and ready to accept normal commands by connectiong to a port named
* "domReady".
*/

var getCurrentUrlHandlers = []; // function(url)
Expand All @@ -15,17 +15,13 @@ var isShowingHelpDialog = false;
var handlerStack = [];
var keyPort;
var settingPort;
var saveZoomLevelPort;
// Users can disable Vimium on URL patterns via the settings page.
var isEnabledForUrl = true;
// The user's operating system.
var currentCompletionKeys;
var validFirstKeys;
var linkHintCss;

// TODO(philc): This should be pulled from the extension's storage when the page loads.
var currentZoomLevel = 100;

// The types in <input type="..."> that we consider for focusInput command. Right now this is recalculated in
// each content script. Alternatively we could calculate it once in the background page and use a request to
// fetch it each time.
Expand Down Expand Up @@ -75,17 +71,13 @@ var hasModifiersRegex = /^<([amc]-)+.>/;
var googleRegex = /:\/\/[^/]*google[^/]+/;

/*
* Complete initialization work that sould be done prior to DOMReady, like setting the page's zoom level.
* Complete initialization work that sould be done prior to DOMReady.
*/
function initializePreDomReady() {
settings.load();

checkIfEnabledForUrl();

var getZoomLevelPort = chrome.extension.connect({ name: "getZoomLevel" });
if (window.self == window.parent)
getZoomLevelPort.postMessage({ domain: window.location.host });

chrome.extension.sendRequest({handler: "getLinkHintCss"}, function (response) {
linkHintCss = response.linkHintCss;
});
Expand Down Expand Up @@ -145,12 +137,6 @@ function initializePreDomReady() {
port.onMessage.addListener(function(args) {
if (getCurrentUrlHandlers.length > 0) { getCurrentUrlHandlers.pop()(args.url); }
});
} else if (port.name == "returnZoomLevel") {
port.onMessage.addListener(function(args) {
currentZoomLevel = args.zoomLevel;
if (isEnabledForUrl)
setPageZoomLevel(currentZoomLevel);
});
} else if (port.name == "returnSetting") {
port.onMessage.addListener(settings.receiveMessage);
} else if (port.name == "refreshCompletionKeys") {
Expand Down Expand Up @@ -223,47 +209,6 @@ function enterInsertModeIfElementIsFocused() {
enterInsertModeWithoutShowingIndicator(document.activeElement);
}

/*
* Asks the background page to persist the zoom level for the given domain to localStorage.
*/
function saveZoomLevel(domain, zoomLevel) {
if (!saveZoomLevelPort)
saveZoomLevelPort = chrome.extension.connect({ name: "saveZoomLevel" });
saveZoomLevelPort.postMessage({ domain: domain, zoomLevel: zoomLevel });
}

/*
* Zoom in increments of 20%; this matches chrome's CMD+ and CMD- keystrokes.
* Set the zoom style on documentElement because document.body does not exist pre-page load.
*/
function setPageZoomLevel(zoomLevel, showUINotification) {
document.documentElement.style.zoom = zoomLevel + "%";
if (document.body)
HUD.updatePageZoomLevel(zoomLevel);
if (showUINotification)
HUD.showForDuration("Zoom: " + currentZoomLevel + "%", 1000);
}

function zoomIn() {
currentZoomLevel += 20;
setAndSaveZoom();
}

function zoomOut() {
currentZoomLevel -= 20;
setAndSaveZoom();
}

function zoomReset() {
currentZoomLevel = 100;
setAndSaveZoom();
}

function setAndSaveZoom() {
setPageZoomLevel(currentZoomLevel, true);
saveZoomLevel(window.location.host, currentZoomLevel);
}

function scrollToBottom() { window.scrollTo(window.pageXOffset, document.body.scrollHeight); }
function scrollToTop() { window.scrollTo(window.pageXOffset, 0); }
function scrollToLeft() { window.scrollTo(0, window.pageYOffset); }
Expand Down Expand Up @@ -853,15 +798,6 @@ HUD = {
function() { HUD.upgradeNotificationElement().style.display = "none"; });
},

updatePageZoomLevel: function(pageZoomLevel) {
// Since the chrome HUD does not scale with the page's zoom level, neither will this HUD.
var inverseZoomLevel = (100.0 / pageZoomLevel) * 100;
if (HUD._displayElement)
HUD.displayElement().style.zoom = inverseZoomLevel + "%";
if (HUD._upgradeNotificationElement)
HUD.upgradeNotificationElement().style.zoom = inverseZoomLevel + "%";
},

/*
* Retrieves the HUD HTML element.
*/
Expand All @@ -870,7 +806,6 @@ HUD = {
HUD._displayElement = HUD.createHudElement();
// Keep this far enough to the right so that it doesn't collide with the "popups blocked" chrome HUD.
HUD._displayElement.style.right = "150px";
HUD.updatePageZoomLevel(currentZoomLevel);
}
return HUD._displayElement;
},
Expand All @@ -880,7 +815,6 @@ HUD = {
HUD._upgradeNotificationElement = HUD.createHudElement();
// Position this just to the left of our normal HUD.
HUD._upgradeNotificationElement.style.right = "315px";
HUD.updatePageZoomLevel(currentZoomLevel);
}
return HUD._upgradeNotificationElement;
},
Expand Down

0 comments on commit dc114c1

Please sign in to comment.