diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js index 6aa00d2a..0fe23af4 100644 --- a/chrome/content/vimperator/commands.js +++ b/chrome/content/vimperator/commands.js @@ -1155,11 +1155,11 @@ function Commands() //{{{ } )); addDefaultCommand(new Command(["zo[om]"], - zoom_to, + vimperator.zoom, { - usage: ["zo[om] {value}"], + usage: ["zo[om] [+-]{value}[%]"], short_help: "Set zoom value of the web page", - help: "{value} can be between 25 and 500%. If it is omitted, zoom is reset to 100%." + help: "{value} can be an absolute value between 25 and 500% or a relative value if prefixed with - or +. If {value} is omitted, zoom is reset to 100%." } )); //}}} @@ -1334,76 +1334,6 @@ function scrollBufferAbsolute(horizontal, vertical) win.scrollTo(horiz, vert); } -/////////////////////////////////////////////////////////////////////}}} -// zooming ///////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////{{{ - -/* also used to zoom out, when factor is negative */ -function zoom_in(factor) -{ - if (vimperator.input.count < 1) - vimperator.input.count = 1; - - //ZoomManager.prototype.getInstance().enlarge(); - var zoomMgr = ZoomManager.prototype.getInstance(); - if (zoomMgr.textZoom == 25 && factor < 0) - { - vimperator.echoerr("Minimum zoom level of 25% reached"); - vimperator.beep(); - } - else if (zoomMgr.textZoom == 500 && factor > 0) - { - vimperator.echoerr("Maximum zoom level of 500% reached"); - vimperator.beep(); - } - else - { - var value = zoomMgr.textZoom + factor*vimperator.input.count*25; - if (value < 25) value = 25; - if (value > 500) value = 500; - - zoomMgr.textZoom = value; - - vimperator.hints.reshowHints(); - - vimperator.echo("Zoom value: " + value + "%"); - } -} - -//vimperator.zoom_to = function(value) -function zoom_to(value) -{ - var zoomMgr = ZoomManager.prototype.getInstance(); - value = parseInt(value); - if (!value || isNaN(value) || value <= 0) - value = 100; - - // convert to int, if string was given - if (typeof value != "number") - { - oldval = value; - value = parseInt(oldval, 10); - if (isNaN(value)) - { - vimperator.echoerr("Cannot convert " + oldval + " to a number"); - return; - } - } - - if (value < 25 || value > 500) - { - vimperator.echoerr("Zoom value must be between 25% and 500%"); - vimperator.beep(); - return; - } - - zoomMgr.textZoom = value; - - vimperator.hints.reshowHints(); - - vimperator.echo("Zoom value: " + value + "%"); -} - /////////////////////////////////////////////////////////////////////}}} // DOM related helper functions //////////////////////////////////////// /////////////////////////////////////////////////////////////////////{{{ diff --git a/chrome/content/vimperator/events.js b/chrome/content/vimperator/events.js index baf5db68..e6d65b3a 100644 --- a/chrome/content/vimperator/events.js +++ b/chrome/content/vimperator/events.js @@ -137,16 +137,9 @@ function Events() //{{{ this.onKeyPress = function(event) { -// alert(event) -// if (event.type != "keypress") -// return false; -// vimperator.logObject(event); var key = event.toString() -// alert(key); if (!key) return false; -// event.stopPropagation(); -// event.preventDefault(); // sometimes the non-content area has focus, making our keys not work // if (event.target.id == "main-window") // alert("focusContent();"); @@ -183,7 +176,6 @@ function Events() //{{{ return false; } - // handle Escape-one-key mode (Ctrl-v) if (vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY) && !vimperator.hasMode(vimperator.modes.ESCAPE_ALL_KEYS)) { @@ -222,7 +214,6 @@ function Events() //{{{ // } }}} - // if Hit-a-hint mode is on, special handling of keys is required // FIXME: total mess if (vimperator.hasMode(vimperator.modes.HINTS)) @@ -236,7 +227,6 @@ function Events() //{{{ { if (map.always_active || vimperator.hints.currentState() == 1) { - //g_hint_mappings[i][1].call(this, event); map.execute(); if (map.cancel_mode) // stop processing this event { diff --git a/chrome/content/vimperator/hints.js b/chrome/content/vimperator/hints.js index 6f8b341a..f3caf17d 100644 --- a/chrome/content/vimperator/hints.js +++ b/chrome/content/vimperator/hints.js @@ -26,15 +26,11 @@ function Hints() //{{{ { const HINT_PREFIX = 'hah_hint_'; // prefix for the hint id - // public accessors - //this.hintsVisible = function() { return isHahModeEnabled; }; this.hintedElements = function() { return hintedElems; }; this.currentState = function() { return state;}; this.setCurrentState = function(s) { state = s;}; - //this.currentMode = function() { return hintmode;}; var isHahModeEnabled = false; // is typing mode on - //var hintmode = HINT_MODE_QUICK; var hintedElems = []; var linkNumString = ""; // the typed link number is in this string var linkCount = 0; @@ -45,20 +41,10 @@ function Hints() //{{{ // each hint element is a clone of this element var hintElemSpan; - //////////////////////////////////////////////////////////////////////////////// - // configuration and initialization related functions - //////////////////////////////////////////////////////////////////////////////// - -// function load() -// { -// isHahModeEnabled = false; -// hintedElem = null; -// } - //////////////////////////////////////////////////////////////////////////////// // hint activating and loading related functions //////////////////////////////////////////////////////////////////////////////// - + function startCoordLoader(doc) { win = doc.defaultView; @@ -101,17 +87,15 @@ function Hints() //{{{ function genElemCoords(elem) { // NOTE: experiment for making the function faster, report problems - // -> does not work on www.orf.at with frames - // try { - // var box = window.content.document.getBoxObjectFor(elem); - // elem.absoLeft = box.x; - // elem.absoTop = box.y; - // elem.validCoord = elem.ownerDocument.validCoords; - // } catch(e) { - // elem.absoLeft = 0; - // elem.absoTop = 0; - // } - // return; + // only works for FF3.0: + //var rect = elem.getBoundingClientRect(); + //if (rect) + //{ + // elem.absoLeft = rect.left; + // elem.absoTop = rect.top; + //} + //return; + if (typeof(elem.validCoord) != "undefined") { if (elem.validCoord == elem.ownerDocument.validCoords) @@ -136,7 +120,7 @@ function Hints() //{{{ { if (!win) { - win = window._content; + win = window.content; linkCount = 0; } @@ -156,7 +140,6 @@ function Hints() //{{{ hintElemSpan.setAttribute('name', 'hah_hint'); var hintContainer = doc.getElementById('hah_hints'); - if (hintContainer == null) { genHintContainer(doc); @@ -176,12 +159,11 @@ function Hints() //{{{ genElemCoords(elem); // for extended hint mode, show all - even currently hidden - hints - //if (hintmode == HINT_MODE_QUICK && (elem.absoTop < area[1] || elem.absoTop > area[3] || - if (vimperator.hasMode(vimperator.modes.QUICK_HINT) && (elem.absoTop < area[1] || elem.absoTop > area[3] || + //if (vimperator.hasMode(vimperator.modes.QUICK_HINT) && (elem.absoTop < area[1] || elem.absoTop > area[3] || + if ((elem.absoTop < area[1] || elem.absoTop > area[3] || elem.absoLeft > area[2] || elem.absoLeft < area[0])) continue; - // XXX: what does that do // if (elem.offsetWidth == 0 && elem.offsetHeight == 0) // continue; @@ -222,17 +204,10 @@ function Hints() //{{{ if (!win) win = window.content; - //if (linkCount == 0 && hintmode != HINT_MODE_ALWAYS) if (linkCount == 0 && !vimperator.hasMode(vimperator.modes.ALWAYS_HINT)) { vimperator.beep(); - //alert('h'); this.disableHahMode(win); - //alert('g'); -// setCurrentMode(MODE_NORMAL); -// linkNumString = ''; -// hintedElems = []; -// isHahModeEnabled = false; return; } @@ -409,9 +384,7 @@ function Hints() //{{{ //function enableHahMode(event, mode) this.enableHahMode = function(mode) { - //setCurrentMode(mode); vimperator.setMode(vimperator.modes.HINTS, mode); - //hintmode = mode; state = 0; linkCount = 0; linkNumString = ''; @@ -438,14 +411,10 @@ function Hints() //{{{ if(!isHahModeEnabled) return; - //setCurrentMode(MODE_NORMAL); vimperator.setMode(vimperator.modes.NORMAL); isHahModeEnabled = false; - //hintmode = HINT_MODE_QUICK; linkNumString = ''; hintedElems = []; -// if (!silent && vimperator.options["showmode"]) -// vimperator.echo(''); removeHints(win); return 0; @@ -519,7 +488,6 @@ function Hints() //{{{ evt.initMouseEvent('click', true, true, view, 1, x+1, y+1, 0, 0, /*ctrl*/ new_tab, /*event.altKey*/0, /*event.shiftKey*/ new_window, /*event.metaKey*/ new_tab, 0, null); elem.dispatchEvent(evt); - // for 'pure' open calls without a new tab or window it doesn't // make sense to open more hints in the current tab, open new tabs // for it @@ -539,7 +507,11 @@ function Hints() //{{{ { tmp = elems[i].refElem.href; if (typeof(tmp) != 'undefined' && tmp.length > 0) - loc += tmp + "\n"; + { + if (i > 0) + loc += "\n"; + loc += tmp; + } } // disable the hints before we can echo() an information @@ -558,7 +530,11 @@ function Hints() //{{{ { tmp = elems[i].refElem.textContent; if (typeof(tmp) != 'undefined' && tmp.length > 0) - loc += tmp + "\n"; + { + if (i > 0) + loc += "\n"; + loc += tmp; + } } // disable the hints before we can echo() an information @@ -659,7 +635,8 @@ function Hints() //{{{ function initDoc(event) { - // vimperator.echo("Content loaded"); + // vimperator.echoerr("Content loaded"); + doc = event.originalTarget; genHintContainer(doc); isHahModeEnabled = false; @@ -678,7 +655,6 @@ function Hints() //{{{ startCoordLoader(doc); - //if (hintmode == HINT_MODE_ALWAYS) if (vimperator.hasMode(vimperator.modes.ALWAYS_HINT)) { state = 0; @@ -686,10 +662,11 @@ function Hints() //{{{ linkNumString = ''; isHahModeEnabled = true; - createHints(); - showHints(null, 0); + setTimeout( function() { + createHints(); + showHints(null, 0); + }, 100); } - // vimperator.echo("Done."); } window.document.addEventListener("DOMContentLoaded", initDoc, null); diff --git a/chrome/content/vimperator/mappings.js b/chrome/content/vimperator/mappings.js index e0f9512c..81de194c 100644 --- a/chrome/content/vimperator/mappings.js +++ b/chrome/content/vimperator/mappings.js @@ -332,7 +332,7 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["b"], - function(args) { vimperator.commandline.open(":", "buffer ", vimperator.modes.EX); }, + function() { vimperator.commandline.open(":", "buffer ", vimperator.modes.EX); }, { short_help: "Open a prompt to switch buffers", help: "Typing the corresponding number opens switches to this buffer." @@ -369,7 +369,7 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["gH"], - function(count) { vimperator.open("", vimperator.NEW_TAB); BrowserHome(); }, + function() { vimperator.open("", vimperator.NEW_TAB); BrowserHome(); }, { short_help: "Go home in a new tab", help: "Opens the homepage in a new tab." @@ -402,7 +402,7 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["gP"], - function(count) + function() { vimperator.open(readFromClipboard(), vimperator.options["activate"].search(/\bpaste\b/) > -1 ? @@ -476,28 +476,28 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["o"], - function(count) { vimperator.commandline.open(":", "open ", vimperator.modes.EX); }, + function() { vimperator.commandline.open(":", "open ", vimperator.modes.EX); }, { short_help: "Open one or more URLs in the current tab", help: "See :open for more details." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["O"], - function(count) { vimperator.commandline.open(":", "open " + getCurrentLocation(), vimperator.modes.EX); }, + function() { vimperator.commandline.open(":", "open " + getCurrentLocation(), vimperator.modes.EX); }, { short_help: "Open one or more URLs in the current tab, based on current location", help: "Works like o, but preselects current URL in the :open query." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["p", ""], - function(count) { vimperator.open(readFromClipboard()); }, + function() { vimperator.open(readFromClipboard()); }, { short_help: "Open (put) a URL based on the current clipboard contents in the current buffer", help: "You can also just select some non-URL text, and search for it with the default search engine or keyword (specified by the 'defsearch' option) with p." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["P"], - function(count) + function() { vimperator.open(readFromClipboard(), vimperator.options["activate"].search(/\bpaste\b/) > -1 ? @@ -510,21 +510,21 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["r"], - function(count) { vimperator.tabs.reload(getBrowser().mCurrentTab, false); }, + function() { vimperator.tabs.reload(getBrowser().mCurrentTab, false); }, { short_help: "Reload", help: "Forces reloading of the current page." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["R"], - function(count) { vimperator.tabs.reload(getBrowser().mCurrentTab, true); }, + function() { vimperator.tabs.reload(getBrowser().mCurrentTab, true); }, { short_help: "Reload while skipping the cache", help: "Forces reloading of the current page skipping the cache." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["t"], - function(count) { vimperator.commandline.open(":", "tabopen ", vimperator.modes.EX); }, + function() { vimperator.commandline.open(":", "tabopen ", vimperator.modes.EX); }, { short_help: "Open one or more URLs in a new tab", help: "Like o but open URLs in a new tab.
" + @@ -532,7 +532,7 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["T"], - function(count) { vimperator.commandline.open(":", "tabopen " + getCurrentLocation(), vimperator.modes.EX); }, + function() { vimperator.commandline.open(":", "tabopen " + getCurrentLocation(), vimperator.modes.EX); }, { short_help: "Open one ore more URLs in a new tab, based on current location", help: "Works like t, but preselects current URL in the :tabopen query." @@ -571,35 +571,39 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["zi", "+"], - function(count) { zoom_in(1); }, + function(count) { vimperator.zoom("+" + (count > 0 ? count * 25 : 25) + "%"); }, { short_help: "Zoom in current web page by 25%", - help: "Currently no count supported." + help: "Currently no count supported.", + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["zI"], - function(count) { zoom_in(4); }, + function(count) { vimperator.zoom("+" + (count > 0 ? count * 100 : 100) + "%"); }, { short_help: "Zoom in current web page by 100%", - help: "Currently no count supported." + help: "Currently no count supported.", + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["zo", "-"], - function(count) { zoom_in(-1); }, + function(count) { vimperator.zoom("-" + (count > 0 ? count * 25 : 25) + "%"); }, { short_help: "Zoom out current web page by 25%", - help: "Currently no count supported." + help: "Currently no count supported.", + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["zO"], - function(count) { zoom_in(-4); }, + function(count) { vimperator.zoom("-" + (count > 0 ? count * 100 : 100) + "%"); }, { short_help: "Zoom out current web page by 100%", - help: "Currently no count supported." + help: "Currently no count supported.", + flags: Mappings.flags.COUNT } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["zz"], - zoom_to, + function(count) { vimperator.zoom(count > 0 ? "" + count + "%" : "100%"); }, { short_help: "Set zoom value of the web page", help: "Zoom value can be between 25 and 500%. If it is omitted, zoom is reset to 100%.", @@ -607,14 +611,14 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["ZQ"], - function(count) { vimperator.quit(false); }, + function() { vimperator.quit(false); }, { short_help: "Quit and don't save the session", help: "Works like :qall." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["ZZ"], - function(count) { vimperator.quit(true); }, + function() { vimperator.quit(true); }, { short_help: "Quit and save the session", help: "Quit Vimperator, no matter how many tabs/windows are open. The session is stored.
" + @@ -624,14 +628,14 @@ function Mappings() //{{{ // scrolling commands addDefaultMap(new Map(vimperator.modes.NORMAL, ["0", "^"], - function(count) { scrollBufferAbsolute(0, -1); }, + function() { scrollBufferAbsolute(0, -1); }, { short_help: "Scroll to the absolute left of the document", help: "Unlike in vim, 0 and ^ work exactly the same way." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["$"], - function(count) { scrollBufferAbsolute(100, -1); }, + function() { scrollBufferAbsolute(100, -1); }, { short_help: "Scroll to the absolute right of the document" } @@ -689,14 +693,14 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["", "", "", ""], - function(count) { goDoCommand('cmd_scrollPageUp'); }, + function() { goDoCommand('cmd_scrollPageUp'); }, { short_help: "Scroll up a full page of the current document", help: "No count support for now." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["", "", "", ""], - function(count) { goDoCommand('cmd_scrollPageDown'); }, + function() { goDoCommand('cmd_scrollPageDown'); }, { short_help: "Scroll down a full page of the current document", help: "No count support for now." @@ -760,7 +764,7 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["gU", ""], - function(count) { vimperator.open("..."); }, + function() { vimperator.open("..."); }, { short_help: "Go to the root of the website", help: "gU on http://www.example.com/dir1/dir2/file.htm opens http://www.example.com/.
" + @@ -770,7 +774,7 @@ function Mappings() //{{{ // hint managment addDefaultMap(new Map(vimperator.modes.NORMAL, ["f"], - function(count) { vimperator.hints.enableHahMode(vimperator.modes.QUICK_HINT); }, + function() { vimperator.hints.enableHahMode(vimperator.modes.QUICK_HINT); }, { short_help: "Start QuickHint mode", help: "In QuickHint mode, every hintable item (according to the 'hinttags' XPath query) is assigned a label.
" + @@ -779,7 +783,7 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["F"], - function(count) { vimperator.hints.enableHahMode(vimperator.modes.ALWAYS_HINT); }, + function() { vimperator.hints.enableHahMode(vimperator.modes.ALWAYS_HINT); }, { short_help: "Start AlwaysHint mode", help: "In AlwaysHint mode, every hintable item (according to the 'hinttags' XPath query) is assigned a label.
" + @@ -789,7 +793,7 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, [";"], - function(count) { vimperator.hints.enableHahMode(vimperator.modes.EXTENDED_HINT); }, + function() { vimperator.hints.enableHahMode(vimperator.modes.EXTENDED_HINT); }, { short_help: "Start ExtendedHint mode", help: "ExtendedHint mode is useful, since in this mode you can yank link locations, or open them in a new window.
" + @@ -813,21 +817,21 @@ function Mappings() //{{{ // search management addDefaultMap(new Map(vimperator.modes.NORMAL, ["g/"], - function(count) { vimperator.search.openSearchDialog(); }, + function() { vimperator.search.openSearchDialog(); }, { short_help: "Search forward for a pattern", help: "Buggy on many sites, use / if you want a reliable search!" } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["n"], - function(count) { vimperator.search.findNext(); }, + function() { vimperator.search.findNext(); }, { short_help: "Find next", help: "Repeat the last \"/\" 1 time (until count is supported)." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["N"], - function(count) { vimperator.search.findPrevious(); }, + function() { vimperator.search.findPrevious(); }, { short_help: "Find previous", help: "Repeat the last \"/\" 1 time (until count is supported) in the opposite direction." @@ -836,21 +840,21 @@ function Mappings() //{{{ // vimperator management addDefaultMap(new Map(vimperator.modes.NORMAL, [""], - function(count) { vimperator.help(null); }, + function() { vimperator.help(null); }, { short_help: "Open help window", help: "The default section is shown, if you need help for a specific topic, try :help <F1> (jumping to a specific section not implemented yet)." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, [":"], - function(count) { vimperator.commandline.open(":", "", vimperator.modes.EX); }, + function() { vimperator.commandline.open(":", "", vimperator.modes.EX); }, { short_help: "Start command line mode", help: "In command line mode, you can perform extended commands, which may require arguments." } )); addDefaultMap(new Map(vimperator.modes.NORMAL, ["I"], - function(count) { vimperator.addMode(null, vimperator.modes.ESCAPE_ALL_KEYS); }, + function() { vimperator.addMode(null, vimperator.modes.ESCAPE_ALL_KEYS); }, { short_help: "Disable vimperator keys", help: "Starts an 'ignorekeys' mode, where all keys except <Esc> are passed to the next event handler.
" + @@ -860,7 +864,7 @@ function Mappings() //{{{ } )); addDefaultMap(new Map(vimperator.modes.NORMAL, [""], - function(count) { vimperator.addMode(null, vimperator.modes.ESCAPE_ONE_KEY); }, + function() { vimperator.addMode(null, vimperator.modes.ESCAPE_ONE_KEY); }, { short_help: "Escape next key", help: "If you need to pass a certain key to a javascript form field or another extension prefix the key with <C-v>.
" + diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js index de5de64f..c53ce3b0 100644 --- a/chrome/content/vimperator/vimperator.js +++ b/chrome/content/vimperator/vimperator.js @@ -677,7 +677,42 @@ const vimperator = (function() //{{{ if (Options.getFirefoxPref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit') == popup_allowed_events + " keypress") Options.setFirefoxPref('dom.popup_allowed_events', popup_allowed_events); + }, + + // @param value MUST be a string, it can have the following form: "+20%", "200%", "-30" + // @return false if argument could not be parsed or zoom level too high + zoom: function(value) + { + if (typeof value != "string") + return false; + + var zoomMgr = ZoomManager.prototype.getInstance(); + var new_zoom_value = 100; + + var matches = value.match(/^\s*(\+|-)?(\d+)(%)?\s*/); + if (!matches || !matches[2]) + return false; + + if (matches[1] == "+") + new_zoom_value = zoomMgr.textZoom + parseInt(matches[2]); + else if (matches[1] == "-") + new_zoom_value = zoomMgr.textZoom - parseInt(matches[2]); + else + new_zoom_value = parseInt(matches[2]); + + + if (new_zoom_value < 25 || new_zoom_value > 500) + { + vimperator.echoerr("Zoom value must be between 25% and 500%"); + vimperator.beep(); + return false; + } + + zoomMgr.textZoom = new_zoom_value; + vimperator.hints.reshowHints(); + vimperator.echo("Zoom value: " + new_zoom_value + "%"); } + } //}}} })(); //}}}