diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/client/shared/zoom-keys.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/shared/zoom-keys.js')
-rw-r--r-- | devtools/client/shared/zoom-keys.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/devtools/client/shared/zoom-keys.js b/devtools/client/shared/zoom-keys.js new file mode 100644 index 000000000..80f4386fb --- /dev/null +++ b/devtools/client/shared/zoom-keys.js @@ -0,0 +1,85 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { Ci } = require("chrome"); +const Services = require("Services"); +const { KeyShortcuts } = require("devtools/client/shared/key-shortcuts"); + +const ZOOM_PREF = "devtools.toolbox.zoomValue"; +const MIN_ZOOM = 0.5; +const MAX_ZOOM = 2; + +const {LocalizationHelper} = require("devtools/shared/l10n"); +const L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties"); + +/** + * Register generic keys to control zoom level of the given document. + * Used by both the toolboxes and the browser console. + * + * @param {DOMWindow} The window on which we should listent to key strokes and + * modify the zoom factor. + */ +exports.register = function (window) { + let shortcuts = new KeyShortcuts({ + window + }); + let docShell = window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShell); + let contViewer = docShell.contentViewer; + let zoomValue = parseFloat(Services.prefs.getCharPref(ZOOM_PREF)); + let zoomIn = function (name, event) { + setZoom(zoomValue + 0.1); + event.preventDefault(); + }; + + let zoomOut = function (name, event) { + setZoom(zoomValue - 0.1); + event.preventDefault(); + }; + + let zoomReset = function (name, event) { + setZoom(1); + event.preventDefault(); + }; + + let setZoom = function (newValue) { + // cap zoom value + zoomValue = Math.max(newValue, MIN_ZOOM); + zoomValue = Math.min(zoomValue, MAX_ZOOM); + + contViewer.fullZoom = zoomValue; + + Services.prefs.setCharPref(ZOOM_PREF, zoomValue); + }; + + // Set zoom to whatever the last setting was. + setZoom(zoomValue); + + shortcuts.on(L10N.getStr("toolbox.zoomIn.key"), zoomIn); + let zoomIn2 = L10N.getStr("toolbox.zoomIn2.key"); + if (zoomIn2) { + shortcuts.on(zoomIn2, zoomIn); + } + let zoomIn3 = L10N.getStr("toolbox.zoomIn2.key"); + if (zoomIn3) { + shortcuts.on(zoomIn3, zoomIn); + } + + shortcuts.on(L10N.getStr("toolbox.zoomOut.key"), + zoomOut); + let zoomOut2 = L10N.getStr("toolbox.zoomOut2.key"); + if (zoomOut2) { + shortcuts.on(zoomOut2, zoomOut); + } + + shortcuts.on(L10N.getStr("toolbox.zoomReset.key"), + zoomReset); + let zoomReset2 = L10N.getStr("toolbox.zoomReset2.key"); + if (zoomReset2) { + shortcuts.on(zoomReset2, zoomReset); + } +}; |