Bug 332275 - Let user set (Default) Zoom - Initial commit for review purposes.
Similar bug: 409011
To start let’s set Default User Zoom from new optional browser.zoom.userDefaultFullZoom about:config preference. If such preference does not exists than nothing is going to be affected. Maybe eventually the default zoom setting can be exposed via about:preferences, similar to: https://dt.azadicdn.com/wp-content/uploads/2015/02/change-default-zoom-level-in-Chrome-b.png
Why:
Before the move to Web-Extensions
Bug 332275 could be addressed via NoSquint or ZoomPage extensions. It is impossible to properly set and keep a user default zoom level via a web-extension because of the API limitations, for example: View->Zoom->Reset, urlbar zoom button or Ctrl+0 will always set zoom to 1 which might not be what the user wants, etc...
MozReview-Commit-ID: G6FE6E3Yw9H
--- a/browser/base/content/browser-fullZoom.js
+++ b/browser/base/content/browser-fullZoom.js
@@ -32,16 +32,21 @@ var FullZoom = {
if (this._siteSpecificPref === undefined) {
this._siteSpecificPref =
!gPrefService.getBoolPref("privacy.resistFingerprinting") &&
gPrefService.getBoolPref("browser.zoom.siteSpecific");
}
return this._siteSpecificPref;
},
+ // @see ZoomUI.updateZoomUI and ext-tabs._getZoomSettings
+ get defaultUserZoom() {
+ return Number(this._ensureValid(this._globalValue).toFixed(2));
+ },
+
// nsISupports
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMEventListener,
Ci.nsIObserver,
Ci.nsIContentPrefObserver,
Ci.nsISupportsWeakReference,
Ci.nsISupports]),
@@ -50,21 +55,29 @@ var FullZoom = {
init: function FullZoom_init() {
gBrowser.addEventListener("ZoomChangeUsingMouseWheel", this);
// Register ourselves with the service so we know when our pref changes.
this._cps2 = Cc["@mozilla.org/content-pref/service;1"].
getService(Ci.nsIContentPrefService2);
this._cps2.addObserverForName(this.name, this);
+ if (!("_globalValue" in this)){ // @see this._getGlobalValue
+ // Get user default zoom from pref
+ let value=gPrefService.getCharPref("browser.zoom.userDefaultFullZoom","");
+ // Set default zoom only if we have the pref
+ if (value) this._setDefaultUserZoom(value);
+ }
+
this.updateBackgroundTabs =
gPrefService.getBoolPref("browser.zoom.updateBackgroundTabs");
// Listen for changes to the browser.zoom branch so we can enable/disable
- // updating background tabs and per-site saving and restoring of zoom levels.
+ // updating background tabs and per-site saving and restoring of zoom levels,
+ // and set user default zoom levels.
gPrefService.addObserver("browser.zoom.", this, true);
// Also need to listen to privacy.resistFingerprinting in order to update
// this._siteSpecificPref.
gPrefService.addObserver("privacy.resistFingerprinting", this, true);
// If we received onLocationChange events for any of the current browsers
// before we were initialized we want to replay those upon initialization.
@@ -79,16 +92,29 @@ var FullZoom = {
},
destroy: function FullZoom_destroy() {
gPrefService.removeObserver("browser.zoom.", this);
this._cps2.removeObserverForName(this.name, this);
gBrowser.removeEventListener("ZoomChangeUsingMouseWheel", this);
},
+ _setDefaultUserZoom: function FullZoom__setDefaultUserZoom(aValue){
+ // "Snap" to one of the toolkit.zoomManager.zoomValues
+ let value = ZoomManager.snap(this._ensureValid(parseFloat(aValue)));
+ let browser = gBrowser.selectedBrowser;
+ // this._onContentPrefChanged should take care of the rest, since
+ // we are the nsIContentPrefObserver
+ if (value!=1) {
+ this._cps2.setGlobal(this.name,value,this._loadContextFromBrowser(browser));
+ }else{
+ // 1 is the default value... might as well remove the nsIContentPrefService2 global
+ this._cps2.removeGlobal(this.name,this._loadContextFromBrowser(browser));
+ }
+ },
// Event Handlers
// nsIDOMEventListener
handleEvent: function FullZoom_handleEvent(event) {
switch (event.type) {
case "ZoomChangeUsingMouseWheel":
@@ -110,16 +136,20 @@ var FullZoom = {
case "browser.zoom.siteSpecific":
// Invalidate pref cache.
this._siteSpecificPref = undefined;
break;
case "browser.zoom.updateBackgroundTabs":
this.updateBackgroundTabs =
gPrefService.getBoolPref("browser.zoom.updateBackgroundTabs");
break;
+ case "browser.zoom.userDefaultFullZoom":
+ let value=gPrefService.getCharPref("browser.zoom.userDefaultFullZoom");
+ this._setDefaultUserZoom(value);
+ break;
}
break;
}
},
// nsIContentPrefObserver
onContentPrefSet: function FullZoom_onContentPrefSet(aGroup, aName, aValue, aIsPrivate) {
@@ -368,23 +398,29 @@ var FullZoom = {
* @param browser The zoom of this browser will be saved. Required.
*/
_applyZoomToPref: function FullZoom__applyZoomToPref(browser) {
if (!this.siteSpecific ||
gInPrintPreviewMode ||
browser.isSyntheticDocument)
return;
- this._cps2.set(browser.currentURI.spec, this.name,
- ZoomManager.getZoomForBrowser(browser),
- this._loadContextFromBrowser(browser), {
- handleCompletion: () => {
- this._isNextContentPrefChangeInternal = true;
- },
- });
+ // Is it better(cleaner) to remove the pref if we are at the default zoom ???
+ let zoom=ZoomManager.getZoomForBrowser(browser);
+ if (zoom!==this._ensureValid(this._globalValue)) {
+ this._cps2.set(browser.currentURI.spec, this.name,
+ zoom,
+ this._loadContextFromBrowser(browser), {
+ handleCompletion: () => {
+ this._isNextContentPrefChangeInternal = true;
+ },
+ });
+ }else
+ this._removePref(browser);
+
},
/**
* Removes from the content prefs store the zoom level of the given browser.
*
* @param browser The zoom of this browser will be removed. Required.
*/
_removePref: function FullZoom__removePref(browser) {
--- a/browser/components/extensions/ext-tabs.js
+++ b/browser/components/extensions/ext-tabs.js
@@ -714,17 +714,17 @@ this.tabs = class extends ExtensionAPI {
_getZoomSettings(tabId) {
let nativeTab = getTabOrActive(tabId);
let {FullZoom} = nativeTab.ownerGlobal;
return {
mode: "automatic",
scope: FullZoom.siteSpecific ? "per-origin" : "per-tab",
- defaultZoomFactor: 1,
+ defaultZoomFactor: 1, // <-- Should this be FullZoom.defaultUserZoom ???
};
},
getZoomSettings(tabId) {
return Promise.resolve(this._getZoomSettings(tabId));
},
setZoomSettings(tabId, settings) {
--- a/browser/modules/ZoomUI.jsm
+++ b/browser/modules/ZoomUI.jsm
@@ -71,20 +71,20 @@ function updateZoomUI(aBrowser, aAnimate
}
let appMenuZoomReset = win.document.getElementById("appMenu-zoomReset-button");
let customizableZoomControls = win.document.getElementById("zoom-controls");
let customizableZoomReset = win.document.getElementById("zoom-reset-button");
let urlbarZoomButton = win.document.getElementById("urlbar-zoom-button");
let zoomFactor = Math.round(win.ZoomManager.zoom * 100);
- // Hide urlbar zoom button if zoom is at 100% or the customizable control is
+ // Hide urlbar zoom button if zoom is at (User)Default Value or the customizable control is
// in the toolbar.
urlbarZoomButton.hidden =
- (zoomFactor == 100 ||
+ (zoomFactor == Math.round(win.FullZoom.defaultUserZoom*100) ||
(customizableZoomControls &&
customizableZoomControls.getAttribute("cui-areatype") == "toolbar"));
let label = win.gNavigatorBundle.getFormattedString("zoom-button.label", [zoomFactor]);
if (appMenuZoomReset) {
appMenuZoomReset.setAttribute("label", label);
}
if (customizableZoomReset) {