1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 14:27:58 +01:00

added full zoom, and changed some zoom shortcuts

This commit is contained in:
Martin Stubenschrott
2007-09-19 03:20:49 +00:00
parent 31ce25344e
commit 8049fd3fe7
5 changed files with 137 additions and 66 deletions

1
NEWS
View File

@@ -2,6 +2,7 @@
2007-xx-xx:
* version 0.6
* THIS VERSION ONLY WORKS WITH FIREFOX 3.0
* added full zoom, and changed keybindings slightly for text zoom
* :buffer partial_string works now as in vim, and with ! even better
* new :time command for profiling
* added new :sidebar and :sbclose commands

5
TODO
View File

@@ -28,12 +28,9 @@ FEATURES:
7 3d should delete 3 tabs
6 downloading of links to filesystem (:save <filename>)
6 autocommands (BrowserStart, BrowserQuit, TabClose, TabOpen, TabChanged, PageLoaded, any more?)
6 vim like mappings for caret mode and textboxes (i to start caret mode?)
http://nigel.mcnie.name/gnawt/ has a somewhat working implementation
6 pipe selected text/link/website to an external command
6 macros (qq)
6 gf = view source?
6 make a real one-tab-mode, divert _all_ other targets, possible by setting a firefox option (set popup=0-3)
6 page info support (ctrl-g, g<C-g>)
5 Use arrow keys in preview window, and ctrl-w+j/k to switch to from preview window
5 Sort :open completion by date? (use 'wildsort')
@@ -42,7 +39,7 @@ FEATURES:
4 Support multiple top-level windows?
3 Splitting Windows with [:sp :vsp ctrl-w,s ctrl-w,v] and closing with [ctrl-w,q], moving with [ctrl-w,w or tab]
have a look into the split browser extension
3 :set should also set about:config options (with autocomplete)
3 :set! should also set about:config options (with autocomplete)
- many other ideas are listed in the wiki
RANDOM IDEAS:

View File

@@ -32,55 +32,67 @@ function Buffer() //{{{
////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
var zoom_manager = ZoomManager.prototype.getInstance();
const ZOOM_INTERVAL = 25;
var zoom_levels = [ 1, 10, 25, 50, 75, 90, 100,
120, 150, 200, 300, 500, 1000, 2000 ];
// initialize the zoom levels
zoom_manager.zoomFactors = [zoom_manager.MIN];
for (var i = ZOOM_INTERVAL; i <= zoom_manager.MAX; i += ZOOM_INTERVAL)
zoom_manager.zoomFactors.push(i);
function setZoom(value)
function setZoom(value, full_zoom)
{
try
if (value < 1 || value > 2000)
{
zoom_manager.textZoom = value;
vimperator.echo("Text zoom: " + zoom_manager.textZoom + "%");
// TODO: shouldn't this just recalculate hint coords, rather than
// unsuccessfully attempt to reshow hints? i.e. isn't it just relying
// on the recalculation side effect? -- djk
// NOTE: we could really do with a zoom event...
vimperator.hints.reshowHints();
}
catch (e) // Components.results.NS_ERROR_INVALID_ARG
{
vimperator.echoerr("Zoom value out of range (" + zoom_manager.MIN + "-" + zoom_manager.MAX + ")");
vimperator.echoerr("Zoom value out of range (1-2000%)");
return false;
}
if (full_zoom)
getBrowser().mCurrentBrowser.markupDocumentViewer.fullZoom = value / 100.0;
else
getBrowser().mCurrentBrowser.markupDocumentViewer.textZoom = value / 100.0;
vimperator.echo((full_zoom ? "Full zoom: " : "Text zoom: ") + value + "%");
// TODO: shouldn't this just recalculate hint coords, rather than
// unsuccessfully attempt to reshow hints? i.e. isn't it just relying
// on the recalculation side effect? -- djk
// NOTE: we could really do with a zoom event...
vimperator.hints.reshowHints();
}
// NOTE: this is only needed as there's currently no way to specify a
// multiplier when calling ZM.reduce()/ZM.enlarge(). TODO: see if we can
// get this added to ZoomManager
function bumpZoomLevel(steps)
function bumpZoomLevel(steps, full_zoom)
{
var adjusted_zoom = zoom_manager.snap(zoom_manager.textZoom);
var current = zoom_manager.indexOf(adjusted_zoom);
var next = current + steps;
if (full_zoom)
var value = getBrowser().mCurrentBrowser.markupDocumentViewer.fullZoom * 100.0;
else
var value = getBrowser().mCurrentBrowser.markupDocumentViewer.textZoom * 100.0;
var start = 0, end = zoom_manager.zoomFactors.length - 1;
if ((current == start && steps < 0) || (current == end && steps > 0))
var index = -1;
if (steps <= 0)
{
for (var i = zoom_levels.length - 1; i >= 0; i--)
{
if ((zoom_levels[i] + 0.01) < value) // 0.01 for float comparison
{
index = i + 1 + steps;
break;
}
}
}
else
{
for (var i = 0; i < zoom_levels.length; i++)
{
if ((zoom_levels[i] - 0.01) > value) // 0.01 for float comparison
{
index = i - 1 + steps;
break;
}
}
}
if (index < 0 || index >= zoom_levels.length)
{
vimperator.beep();
return;
}
if (next < start)
next = start;
else if (next > end)
next = end;
setZoom(zoom_manager.zoomFactors[next]);
setZoom(zoom_levels[index], full_zoom);
}
function checkScrollYBounds(win, direction)
@@ -127,12 +139,20 @@ function Buffer() //{{{
this.__defineGetter__("textZoom", function()
{
return zoom_manager.textZoom;
return getBrowser().mCurrentBrowser.markupDocumentViewer.textZoom * 100;
});
this.__defineSetter__("textZoom", function(value)
{
setZoom(value);
setZoom(value, false);
});
this.__defineGetter__("fullZoom", function()
{
return getBrowser().mCurrentBrowser.markupDocumentViewer.fullZoom * 100;
});
this.__defineSetter__("fullZoom", function(value)
{
setZoom(value, true);
});
this.__defineGetter__("title", function()
@@ -396,14 +416,14 @@ function Buffer() //{{{
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
}
this.zoomIn = function(steps)
this.zoomIn = function(steps, full_zoom)
{
bumpZoomLevel(steps);
bumpZoomLevel(steps, full_zoom);
}
this.zoomOut = function(steps)
this.zoomOut = function(steps, full_zoom)
{
bumpZoomLevel(-steps);
bumpZoomLevel(-steps, full_zoom);
}
//}}}
} //}}}

View File

@@ -1498,7 +1498,7 @@ function Commands() //{{{
}
));
addDefaultCommand(new Command(["zo[om]"],
function(args)
function(args, special)
{
var level;
@@ -1512,7 +1512,10 @@ function Commands() //{{{
}
else if (/^[+-]\d+$/.test(args))
{
level = vimperator.buffer.textZoom + parseInt(args);
if (special)
level = vimperator.buffer.fullZoom + parseInt(args);
else
level = vimperator.buffer.textZoom + parseInt(args);
// relative args shouldn't take us out of range
if (level < 1)
@@ -1526,13 +1529,17 @@ function Commands() //{{{
return;
}
vimperator.buffer.textZoom = level;
if (special)
vimperator.buffer.fullZoom = level;
else
vimperator.buffer.textZoom = level;
},
{
usage: ["zo[om] [value]", "zo[om] +{value} | -{value}"],
short_help: "Set zoom value of the web page",
usage: ["zo[om][!] [value]", "zo[om][!] +{value} | -{value}"],
short_help: "Set zoom value of current web page",
help: "If <code class=\"argument\">{value}</code> can be an absolute value between 1 and 2000% or a relative value if prefixed with - or +. " +
"If <code class=\"argument\">{value}</code> is omitted, zoom is reset to 100%."
"If <code class=\"argument\">{value}</code> is omitted, zoom is reset to 100%.<br/>" +
"Normally this command operates on the text zoom, if used with <code class=\"argument\">[!]</code> it operates on full zoom."
}
));
//}}}

View File

@@ -689,42 +689,88 @@ function Mappings() //{{{
help: "The currently selected text is copied to the system clipboard."
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zi", "+"],
function(count) { vimperator.buffer.zoomIn(count > 1 ? count : 1); },
function(count) { vimperator.buffer.zoomIn(count > 1 ? count : 1, false); },
{
short_help: "Zoom in current web page by 25%",
short_help: "Enlarge text zoom of current web page",
help: "Mnemonic: zoom in",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zI"],
function(count) { vimperator.buffer.zoomIn((count > 1 ? count : 1) * 4); },
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zm"],
function(count) { vimperator.buffer.zoomIn((count > 1 ? count : 1) * 3, false); },
{
short_help: "Zoom in current web page by 100%",
short_help: "Enlarge text zoom of current web page by a larger amount",
help: "Mnemonic: zoom more",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zo", "-"],
function(count) { vimperator.buffer.zoomOut(count > 1 ? count : 1); },
function(count) { vimperator.buffer.zoomOut(count > 1 ? count : 1, false); },
{
short_help: "Zoom out current web page by 25%",
short_help: "Reduce text zoom of current web page",
help: "Mnemonic: zoom out",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zO"],
function(count) { vimperator.buffer.zoomOut((count > 1 ? count : 1) * 4); },
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zr"],
function(count) { vimperator.buffer.zoomOut((count > 1 ? count : 1) * 3, false); },
{
short_help: "Zoom out current web page by 100%",
short_help: "Reduce text zoom of current web page by a larger amount",
help: "Mnemonic: zoom reduce",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zz"],
function(count) { vimperator.buffer.textZoom = count > 1 ? count : 100; },
{
short_help: "Set zoom value of the web page",
help: "Zoom value can be between 1 and 2000%. If it is omitted, zoom is reset to 100%.",
short_help: "Set text zoom value of current web page",
help: "Zoom value can be between 1 and 2000%. If it is omitted, text zoom is reset to 100%.",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zI"],
function(count) { vimperator.buffer.zoomIn(count > 1 ? count : 1, true); },
{
short_help: "Enlarge full zoom of current web page",
help: "Mnemonic: zoom in",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zM"],
function(count) { vimperator.buffer.zoomIn((count > 1 ? count : 1) * 3, true); },
{
short_help: "Enlarge full zoom of current web page by a larger amount",
help: "Mnemonic: zoom more",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zO"],
function(count) { vimperator.buffer.zoomOut(count > 1 ? count : 1, true); },
{
short_help: "Reduce full zoom of current web page",
help: "Mnemonic: zoom out",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zR"],
function(count) { vimperator.buffer.zoomOut((count > 1 ? count : 1) * 3, true); },
{
short_help: "Reduce full zoom of current web page by a larger amount",
help: "Mnemonic: zoom reduce",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["zZ"],
function(count) { vimperator.buffer.fullZoom = count > 1 ? count : 100; },
{
short_help: "Set full zoom value of current web page",
help: "Zoom value can be between 1 and 2000%. If it is omitted, full zoom is reset to 100%.",
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map([vimperator.modes.NORMAL], ["ZQ"],
function() { vimperator.quit(false); },
{