# HG changeset patch # User Felix Haernstroem # Date 1539419998 -7200 # Sat Oct 13 10:39:58 2018 +0200 # Node ID 19820b54d8350d87c3cfc99741be09821a35465e # Parent ef046dbc381d79a6719c3da5efc615500d78e8fc Bug 670476 - Add zoom controls to status bar diff --git a/suite/base/content/viewZoomOverlay.js b/suite/base/content/viewZoomOverlay.js --- a/suite/base/content/viewZoomOverlay.js +++ b/suite/base/content/viewZoomOverlay.js @@ -445,8 +445,38 @@ function openZoomDialog() { window.openDialog("chrome://communicator/content/askViewZoom.xul", "", "chrome,modal,centerscreen", o); if (o.zoomOK) { zoomOther.setAttribute("value", o.value); ZoomManager.zoom = o.value / 100; } return o.zoomOK; } + +function zoomEnlarge() { + FullZoom.enlarge(); + updateZoomStatus(); +} + +function zoomReduce() { + FullZoom.reduce(); + updateZoomStatus(); +} + +function zoomReset() { + FullZoom.reset(); + updateZoomStatus(); +} + +function zoomSetOther() { + FullZoom.setOther(); + updateZoomStatus(); +} + +function zoomToggle() { + ZoomManager.toggleZoom(); + updateZoomStatus(); +} + +function zoomSet(aValue) { + FullZoom.zoom(aValue) + updateZoomStatus(); +} diff --git a/suite/base/content/viewZoomOverlay.xul b/suite/base/content/viewZoomOverlay.xul --- a/suite/base/content/viewZoomOverlay.xul +++ b/suite/base/content/viewZoomOverlay.xul @@ -19,25 +19,25 @@ - - - - - + + + + + - + Zoom and Ctrl +/- keyboard shortcuts pref("toolkit.zoomManager.zoomValues", "0.2,0.3,0.5,0.67,0.8,0.9,1,1.1,1.2,1.33,1.5,1.7,2,2.4,3,4,5,6,7,8"); pref("javascript.options.showInConsole", true); pref("suite.manager.addons.openAsDialog", false); pref("suite.manager.dataman.openAsDialog", true); diff --git a/suite/browser/navigator.js b/suite/browser/navigator.js --- a/suite/browser/navigator.js +++ b/suite/browser/navigator.js @@ -45,16 +45,93 @@ var gNavigatorRegionBundle; var gLastValidURLStr = ""; var gLastValidURL = null; var gClickSelectsAll = false; var gClickAtEndSelects = false; var gIgnoreFocus = false; var gIgnoreClick = false; var gURIFixup = null; +// Listeners for updating zoom value in status bar +const ZoomListeners = +{ + + // Identifies the setting in the content prefs database. + name: "browser.content.full-zoom", + + QueryInterface: + XPCOMUtils.generateQI([Ci.nsIObserver, + Ci.nsIContentPrefObserver, + Ci.nsIContentPrefCallback2, + Ci.nsISupportsWeakReference, + Ci.nsISupports]), + + init: function () + { + Cc["@mozilla.org/content-pref/service;1"] + .getService(Ci.nsIContentPrefService2) + .addObserverForName(this.name, this); + + Services.prefs.addObserver("browser.zoom.", this, true); + this.updateVisibility(); + }, + + destroy: function () + { + Cc["@mozilla.org/content-pref/service;1"] + .getService(Ci.nsIContentPrefService2) + .removeObserverForName(this.name, this); + + Services.prefs.removeObserver("browser.zoom.", this); + }, + + observe: function (aSubject, aTopic, aData) + { + if (aTopic == "nsPref:changed"){ + switch (aData) { + case "browser.zoom.siteSpecific": + updateZoomStatus(); + break; + case "browser.zoom.showZoomStatusPanel": + this.updateVisibility(); + break; + } + } + }, + + updateVisibility: function() + { + let hidden = !Services.prefs.getBoolPref("browser.zoom.showZoomStatusPanel"); + document.getElementById("zoomOut-button").setAttribute('hidden', hidden); + document.getElementById("zoomIn-button").setAttribute('hidden', hidden); + document.getElementById("zoomLevel-display").setAttribute('hidden', hidden); + }, + + onContentPrefSet: function (aGroup, aName, aValue) + { + updateZoomStatus(); + }, + + onContentPrefRemoved: function (aGroup, aName) + { + updateZoomStatus(); + }, + + handleResult: function(aPref) + { + updateZoomStatus(); + }, + + onLocationChange: function(aURI) + { + // Make sure zoom values loaded before updating + window.setTimeout(updateZoomStatus(), 0); + } +}; + var gInitialPages = new Set([ "about:blank", "about:privatebrowsing", "about:sessionrestore" ]); //cached elements var gBrowser = null; @@ -975,16 +1052,19 @@ function Startup() if (!gPrivate) { // initialize the sync UI // gSyncUI.init(); // initialize the session-restore service setTimeout(InitSessionStoreCallback, 0); } + ZoomListeners.init(); + gBrowser.addTabsProgressListener(ZoomListeners); + window.addEventListener("MozAfterPaint", DelayedStartup, false); } // Minimal gBrowserInit shim to keep the Addon-SDK happy. var gBrowserInit = { delayedStartupFinished: false, } @@ -2913,16 +2993,34 @@ function isClosingLastBrowser() { let win = e.getNext(); if (win != window && win.toolbar.visible) return false; } return true; } +function updateZoomStatus() { + let newLabel = Math.round(ZoomManager.zoom * 100) + " %"; + let zoomStatusElement = document.getElementById("zoomLevel-display"); + if (zoomStatusElement.getAttribute('label') != newLabel){ + zoomStatusElement.setAttribute('label', newLabel); + } +} + +function zoomIn() { + FullZoom.enlarge(); + updateZoomStatus(); +} + +function zoomOut() { + FullZoom.reduce(); + updateZoomStatus(); +} + /** * file upload support */ /* This function returns the URI of the currently focused content frame * or frameset. */ function getCurrentURI() diff --git a/suite/browser/navigator.xul b/suite/browser/navigator.xul --- a/suite/browser/navigator.xul +++ b/suite/browser/navigator.xul @@ -539,16 +539,21 @@ + + +