2007-06-19 22:58:14 +04:00
|
|
|
/*
|
|
|
|
#ifdef 0
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/.
|
2007-06-19 22:58:14 +04:00
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
2007-10-26 03:02:20 +04:00
|
|
|
// One of the possible values for the mousewheel.* preferences.
|
|
|
|
// From nsEventStateManager.cpp.
|
2008-02-13 14:00:45 +03:00
|
|
|
const MOUSE_SCROLL_ZOOM = 3;
|
2007-06-19 22:58:14 +04:00
|
|
|
|
|
|
|
/**
|
2007-10-26 03:02:20 +04:00
|
|
|
* Controls the "full zoom" setting and its site-specific preferences.
|
2007-06-19 22:58:14 +04:00
|
|
|
*/
|
2007-10-26 03:02:20 +04:00
|
|
|
var FullZoom = {
|
2010-07-24 12:57:04 +04:00
|
|
|
// Identifies the setting in the content prefs database.
|
2007-10-26 03:02:20 +04:00
|
|
|
name: "browser.content.full-zoom",
|
2007-06-19 22:58:14 +04:00
|
|
|
|
2008-02-27 02:05:53 +03:00
|
|
|
// browser.zoom.siteSpecific preference cache
|
2009-01-23 12:12:51 +03:00
|
|
|
_siteSpecificPref: undefined,
|
2008-02-27 02:05:53 +03:00
|
|
|
|
2009-03-01 14:22:44 +03:00
|
|
|
// browser.zoom.updateBackgroundTabs preference cache
|
|
|
|
updateBackgroundTabs: undefined,
|
|
|
|
|
2013-06-06 04:05:36 +04:00
|
|
|
// Incremented each time the zoom is changed so that operations that change
|
|
|
|
// the zoom asynchronously don't clobber more recent zoom changes. See
|
|
|
|
// _getState below.
|
|
|
|
_zoomChangeToken: 0,
|
|
|
|
|
2010-04-17 14:19:33 +04:00
|
|
|
get siteSpecific() {
|
bug 679784: let nsIContentPrefService handle private browsing mode; r=ehsan
Manage private browsing mode in content pref service. CPS should be available
in private browsing mode, but should not store informations on disk, and should
clear all informations once the private session ends.
When setting a pref in private mode, it is stored in an in-memory hash table.
When getting a pref, it is retrieved from that hash table if available.
Otherwise, it is retrieved using the standard mechanism. When removing a pref,
it is retrieved from the hash table. The rationale is that in private mode,
it's ok to read a pref from normal database, but not ok to set it.
The in-memory hash table is cleared when leaving the private browsing mode.
When removing a set of preferences (with removeGroupedPrefs or
removePrefsByName), preferences are removed from the in-memory hashtable, *and*
from normal mode database. The rationale is that visiting a website may trigger
setting/getting/removing for a specific preference only. But removing many
prefs at once is the result of an action not associated with a website. For
example, user may wish to delete all its informations. In that case, user
probably expects to not have those informations restored once it leaves private
browsing mode.
2011-09-01 22:13:03 +04:00
|
|
|
return this._siteSpecificPref;
|
2009-01-23 12:12:51 +03:00
|
|
|
},
|
2007-06-19 22:58:14 +04:00
|
|
|
|
|
|
|
//**************************************************************************//
|
|
|
|
// nsISupports
|
|
|
|
|
2010-07-24 12:57:04 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMEventListener,
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsIContentPrefObserver,
|
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsISupports]),
|
2007-06-19 22:58:14 +04:00
|
|
|
|
|
|
|
//**************************************************************************//
|
|
|
|
// Initialization & Destruction
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
init: function FullZoom_init() {
|
2013-04-23 06:47:52 +04:00
|
|
|
// Bug 691614 - zooming support for electrolysis
|
|
|
|
if (gMultiProcessBrowser)
|
|
|
|
return;
|
|
|
|
|
2007-06-19 22:58:14 +04:00
|
|
|
// Listen for scrollwheel events so we can save scrollwheel-based changes.
|
|
|
|
window.addEventListener("DOMMouseScroll", this, false);
|
|
|
|
|
|
|
|
// Register ourselves with the service so we know when our pref changes.
|
2013-03-17 02:12:31 +04:00
|
|
|
this._cps2 = Cc["@mozilla.org/content-pref/service;1"].
|
|
|
|
getService(Ci.nsIContentPrefService2);
|
|
|
|
this._cps2.addObserverForName(this.name, this);
|
2008-02-27 02:05:53 +03:00
|
|
|
|
2009-01-23 12:12:51 +03:00
|
|
|
this._siteSpecificPref =
|
2010-03-09 10:49:46 +03:00
|
|
|
gPrefService.getBoolPref("browser.zoom.siteSpecific");
|
2010-05-11 08:28:19 +04:00
|
|
|
this.updateBackgroundTabs =
|
2010-03-09 10:49:46 +03:00
|
|
|
gPrefService.getBoolPref("browser.zoom.updateBackgroundTabs");
|
2009-03-01 14:22:44 +03:00
|
|
|
// 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.
|
2010-03-09 10:49:46 +03:00
|
|
|
gPrefService.addObserver("browser.zoom.", this, true);
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
destroy: function FullZoom_destroy() {
|
2013-04-23 06:47:52 +04:00
|
|
|
// Bug 691614 - zooming support for electrolysis
|
|
|
|
if (gMultiProcessBrowser)
|
|
|
|
return;
|
|
|
|
|
2010-03-09 10:49:46 +03:00
|
|
|
gPrefService.removeObserver("browser.zoom.", this);
|
2013-03-17 02:12:31 +04:00
|
|
|
this._cps2.removeObserverForName(this.name, this);
|
2007-06-19 22:58:14 +04:00
|
|
|
window.removeEventListener("DOMMouseScroll", this, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
//**************************************************************************//
|
|
|
|
// Event Handlers
|
|
|
|
|
|
|
|
// nsIDOMEventListener
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
handleEvent: function FullZoom_handleEvent(event) {
|
2007-10-26 03:02:20 +04:00
|
|
|
switch (event.type) {
|
|
|
|
case "DOMMouseScroll":
|
|
|
|
this._handleMouseScrolled(event);
|
|
|
|
break;
|
|
|
|
}
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
_handleMouseScrolled: function FullZoom__handleMouseScrolled(event) {
|
2007-06-19 22:58:14 +04:00
|
|
|
// Construct the "mousewheel action" pref key corresponding to this event.
|
2012-08-15 19:51:13 +04:00
|
|
|
// Based on nsEventStateManager::WheelPrefs::GetBasePrefName().
|
|
|
|
var pref = "mousewheel.";
|
|
|
|
|
|
|
|
var pressedModifierCount = event.shiftKey + event.ctrlKey + event.altKey +
|
|
|
|
event.metaKey + event.getModifierState("OS");
|
|
|
|
if (pressedModifierCount != 1) {
|
|
|
|
pref += "default.";
|
|
|
|
} else if (event.shiftKey) {
|
|
|
|
pref += "with_shift.";
|
|
|
|
} else if (event.ctrlKey) {
|
|
|
|
pref += "with_control.";
|
|
|
|
} else if (event.altKey) {
|
|
|
|
pref += "with_alt.";
|
|
|
|
} else if (event.metaKey) {
|
|
|
|
pref += "with_meta.";
|
|
|
|
} else {
|
|
|
|
pref += "with_win.";
|
|
|
|
}
|
|
|
|
|
|
|
|
pref += "action";
|
2007-06-19 22:58:14 +04:00
|
|
|
|
2007-10-26 03:02:20 +04:00
|
|
|
// Don't do anything if this isn't a "zoom" scroll event.
|
|
|
|
var isZoomEvent = false;
|
|
|
|
try {
|
2008-02-13 14:00:45 +03:00
|
|
|
isZoomEvent = (gPrefService.getIntPref(pref) == MOUSE_SCROLL_ZOOM);
|
2007-10-26 03:02:20 +04:00
|
|
|
} catch (e) {}
|
|
|
|
if (!isZoomEvent)
|
2007-06-19 22:58:14 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// XXX Lazily cache all the possible action prefs so we don't have to get
|
|
|
|
// them anew from the pref service for every scroll event? We'd have to
|
|
|
|
// make sure to observe them so we can update the cache when they change.
|
|
|
|
|
2013-06-06 04:05:36 +04:00
|
|
|
// We have to call _applyZoomToPref in a timeout because we handle the
|
|
|
|
// event before the event state manager has a chance to apply the zoom
|
2007-06-19 22:58:14 +04:00
|
|
|
// during nsEventStateManager::PostHandleEvent.
|
2013-06-06 04:05:36 +04:00
|
|
|
let state = this._getState();
|
|
|
|
window.setTimeout(function () {
|
|
|
|
if (this._isStateCurrent(state))
|
|
|
|
this._applyZoomToPref();
|
|
|
|
}.bind(this), 0);
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2008-02-27 02:05:53 +03:00
|
|
|
// nsIObserver
|
|
|
|
|
|
|
|
observe: function (aSubject, aTopic, aData) {
|
2010-02-06 13:40:06 +03:00
|
|
|
switch (aTopic) {
|
2008-02-27 02:05:53 +03:00
|
|
|
case "nsPref:changed":
|
2010-02-06 13:40:06 +03:00
|
|
|
switch (aData) {
|
2008-02-27 02:05:53 +03:00
|
|
|
case "browser.zoom.siteSpecific":
|
2009-01-23 12:12:51 +03:00
|
|
|
this._siteSpecificPref =
|
2010-03-09 10:49:46 +03:00
|
|
|
gPrefService.getBoolPref("browser.zoom.siteSpecific");
|
2008-02-27 02:05:53 +03:00
|
|
|
break;
|
2009-03-01 14:22:44 +03:00
|
|
|
case "browser.zoom.updateBackgroundTabs":
|
|
|
|
this.updateBackgroundTabs =
|
2010-03-09 10:49:46 +03:00
|
|
|
gPrefService.getBoolPref("browser.zoom.updateBackgroundTabs");
|
2009-03-01 14:22:44 +03:00
|
|
|
break;
|
2008-02-27 02:05:53 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-06-19 22:58:14 +04:00
|
|
|
// nsIContentPrefObserver
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
onContentPrefSet: function FullZoom_onContentPrefSet(aGroup, aName, aValue) {
|
2013-03-17 02:12:31 +04:00
|
|
|
this._onContentPrefChanged(aGroup, aValue);
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
onContentPrefRemoved: function FullZoom_onContentPrefRemoved(aGroup, aName) {
|
2013-03-17 02:12:31 +04:00
|
|
|
this._onContentPrefChanged(aGroup, undefined);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Appropriately updates the zoom level after a content preference has
|
|
|
|
* changed.
|
|
|
|
*
|
|
|
|
* @param aGroup The group of the changed preference.
|
|
|
|
* @param aValue The new value of the changed preference. Pass undefined to
|
|
|
|
* indicate the preference's removal.
|
|
|
|
*/
|
|
|
|
_onContentPrefChanged: function FullZoom__onContentPrefChanged(aGroup, aValue) {
|
2013-06-06 04:05:36 +04:00
|
|
|
if (this._isNextContentPrefChangeInternal) {
|
|
|
|
// Ignore changes that FullZoom itself makes. This works because the
|
|
|
|
// content pref service calls callbacks before notifying observers, and it
|
|
|
|
// does both in the same turn of the event loop.
|
|
|
|
delete this._isNextContentPrefChangeInternal;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
if (!gBrowser.currentURI)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let domain = this._cps2.extractDomain(gBrowser.currentURI.spec);
|
|
|
|
if (aGroup) {
|
|
|
|
if (aGroup == domain)
|
2013-06-06 04:05:36 +04:00
|
|
|
this._applyPrefToZoom(aValue);
|
2013-03-17 02:12:31 +04:00
|
|
|
return;
|
2007-06-19 22:58:14 +04:00
|
|
|
}
|
2013-03-17 02:12:31 +04:00
|
|
|
|
|
|
|
this._globalValue = aValue === undefined ? aValue :
|
|
|
|
this._ensureValid(aValue);
|
|
|
|
|
|
|
|
// If the current page doesn't have a site-specific preference, then its
|
|
|
|
// zoom should be set to the new global preference now that the global
|
|
|
|
// preference has changed.
|
2013-06-06 04:05:36 +04:00
|
|
|
let state = this._getState();
|
2013-03-17 02:12:31 +04:00
|
|
|
let hasPref = false;
|
|
|
|
let ctxt = this._loadContextFromWindow(gBrowser.contentWindow);
|
|
|
|
this._cps2.getByDomainAndName(gBrowser.currentURI.spec, this.name, ctxt, {
|
|
|
|
handleResult: function () hasPref = true,
|
|
|
|
handleCompletion: function () {
|
2013-06-06 04:05:36 +04:00
|
|
|
if (!hasPref && this._isStateCurrent(state))
|
|
|
|
this._applyPrefToZoom(undefined, { state: state });
|
2013-03-17 02:12:31 +04:00
|
|
|
}.bind(this)
|
|
|
|
});
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
// location change observer
|
2007-06-19 22:58:14 +04:00
|
|
|
|
2009-08-02 21:53:01 +04:00
|
|
|
/**
|
|
|
|
* Called when the location of a tab changes.
|
|
|
|
* When that happens, we need to update the current zoom level if appropriate.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* A URI object representing the new location.
|
|
|
|
* @param aIsTabSwitch
|
|
|
|
* Whether this location change has happened because of a tab switch.
|
|
|
|
* @param aBrowser
|
|
|
|
* (optional) browser object displaying the document
|
|
|
|
*/
|
|
|
|
onLocationChange: function FullZoom_onLocationChange(aURI, aIsTabSwitch, aBrowser) {
|
2013-04-23 06:47:52 +04:00
|
|
|
// Bug 691614 - zooming support for electrolysis
|
|
|
|
if (gMultiProcessBrowser)
|
|
|
|
return;
|
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
if (!aURI || (aIsTabSwitch && !this.siteSpecific)) {
|
|
|
|
this._notifyOnLocationChange();
|
2007-11-26 11:35:22 +03:00
|
|
|
return;
|
2013-03-17 02:12:31 +04:00
|
|
|
}
|
2010-03-25 13:52:21 +03:00
|
|
|
|
|
|
|
// Avoid the cps roundtrip and apply the default/global pref.
|
2012-04-25 23:50:09 +04:00
|
|
|
if (aURI.spec == "about:blank") {
|
2013-06-06 04:05:36 +04:00
|
|
|
this._applyPrefToZoom(undefined, {
|
|
|
|
browser: aBrowser,
|
|
|
|
onDone: this._notifyOnLocationChange.bind(this),
|
|
|
|
});
|
2010-03-25 13:52:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-28 23:45:04 +03:00
|
|
|
let browser = aBrowser || gBrowser.selectedBrowser;
|
|
|
|
|
2012-01-20 23:43:24 +04:00
|
|
|
// Media documents should always start at 1, and are not affected by prefs.
|
|
|
|
if (!aIsTabSwitch && browser.contentDocument.mozSyntheticDocument) {
|
2012-01-19 04:01:19 +04:00
|
|
|
ZoomManager.setZoomForBrowser(browser, 1);
|
2013-06-06 04:05:36 +04:00
|
|
|
this._zoomChangeToken++;
|
2013-03-17 02:12:31 +04:00
|
|
|
this._notifyOnLocationChange();
|
2013-03-17 02:12:31 +04:00
|
|
|
return;
|
2013-03-17 05:28:48 +04:00
|
|
|
}
|
2013-03-17 02:12:31 +04:00
|
|
|
|
2013-06-06 04:05:36 +04:00
|
|
|
// See if the zoom pref is cached.
|
2013-03-17 02:12:31 +04:00
|
|
|
let ctxt = this._loadContextFromWindow(browser.contentWindow);
|
|
|
|
let pref = this._cps2.getCachedByDomainAndName(aURI.spec, this.name, ctxt);
|
|
|
|
if (pref) {
|
2013-06-06 04:05:36 +04:00
|
|
|
this._applyPrefToZoom(pref.value, {
|
|
|
|
browser: browser,
|
|
|
|
onDone: this._notifyOnLocationChange.bind(this),
|
|
|
|
});
|
2013-03-17 02:12:31 +04:00
|
|
|
return;
|
2013-03-26 23:45:57 +04:00
|
|
|
}
|
2013-03-17 02:12:31 +04:00
|
|
|
|
2013-06-06 04:05:36 +04:00
|
|
|
// It's not cached, so have to asynchronously fetch it.
|
|
|
|
let state = this._getState(browser);
|
2013-03-17 02:12:31 +04:00
|
|
|
let value = undefined;
|
|
|
|
this._cps2.getByDomainAndName(aURI.spec, this.name, ctxt, {
|
|
|
|
handleResult: function (resultPref) value = resultPref.value,
|
|
|
|
handleCompletion: function () {
|
2013-06-06 04:05:36 +04:00
|
|
|
if (this._isStateCurrent(state)) {
|
|
|
|
this._applyPrefToZoom(value, {
|
|
|
|
browser: browser,
|
|
|
|
state: state,
|
|
|
|
onDone: this._notifyOnLocationChange.bind(this),
|
|
|
|
});
|
2013-03-17 02:12:31 +04:00
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
});
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2008-02-13 14:00:45 +03:00
|
|
|
// update state of zoom type menu item
|
|
|
|
|
|
|
|
updateMenu: function FullZoom_updateMenu() {
|
|
|
|
var menuItem = document.getElementById("toggle_zoom");
|
|
|
|
|
|
|
|
menuItem.setAttribute("checked", !ZoomManager.useFullZoom);
|
|
|
|
},
|
2007-06-19 22:58:14 +04:00
|
|
|
|
|
|
|
//**************************************************************************//
|
|
|
|
// Setting & Pref Manipulation
|
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
/**
|
|
|
|
* Reduces the zoom level of the page in the current browser.
|
|
|
|
*/
|
2013-06-06 04:05:36 +04:00
|
|
|
reduce: function FullZoom_reduce() {
|
2007-10-26 03:02:20 +04:00
|
|
|
ZoomManager.reduce();
|
2013-06-06 04:05:36 +04:00
|
|
|
this._zoomChangeToken++;
|
|
|
|
this._applyZoomToPref();
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
/**
|
|
|
|
* Enlarges the zoom level of the page in the current browser.
|
|
|
|
*/
|
2013-06-06 04:05:36 +04:00
|
|
|
enlarge: function FullZoom_enlarge() {
|
2007-10-26 03:02:20 +04:00
|
|
|
ZoomManager.enlarge();
|
2013-06-06 04:05:36 +04:00
|
|
|
this._zoomChangeToken++;
|
|
|
|
this._applyZoomToPref();
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
/**
|
|
|
|
* Sets the zoom level of the page in the current browser to the global zoom
|
|
|
|
* level.
|
|
|
|
*/
|
2013-06-06 04:05:36 +04:00
|
|
|
reset: function FullZoom_reset() {
|
|
|
|
let state = this._getState();
|
2013-03-17 02:12:31 +04:00
|
|
|
this._getGlobalValue(gBrowser.contentWindow, function (value) {
|
2013-06-06 04:05:36 +04:00
|
|
|
if (this._isStateCurrent(state)) {
|
|
|
|
if (value === undefined)
|
|
|
|
ZoomManager.reset();
|
|
|
|
else
|
|
|
|
ZoomManager.zoom = value;
|
|
|
|
this._zoomChangeToken++;
|
|
|
|
}
|
2013-03-17 02:12:31 +04:00
|
|
|
});
|
2013-06-06 04:05:36 +04:00
|
|
|
this._removePref();
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-10-26 03:02:20 +04:00
|
|
|
* Set the zoom level for the current tab.
|
2007-06-19 22:58:14 +04:00
|
|
|
*
|
2007-11-26 11:35:22 +03:00
|
|
|
* Per nsPresContext::setFullZoom, we can set the zoom to its current value
|
|
|
|
* without significant impact on performance, as the setting is only applied
|
|
|
|
* if it differs from the current setting. In fact getting the zoom and then
|
|
|
|
* checking ourselves if it differs costs more.
|
|
|
|
*
|
|
|
|
* And perhaps we should always set the zoom even if it was more expensive,
|
2012-11-29 04:26:39 +04:00
|
|
|
* since nsDocumentViewer::SetTextZoom claims that child documents can have
|
2007-11-26 11:35:22 +03:00
|
|
|
* a different text zoom (although it would be unusual), and it implies that
|
|
|
|
* those child text zooms should get updated when the parent zoom gets set,
|
|
|
|
* and perhaps the same is true for full zoom
|
2012-11-29 04:26:39 +04:00
|
|
|
* (although nsDocumentViewer::SetFullZoom doesn't mention it).
|
2007-06-19 22:58:14 +04:00
|
|
|
*
|
|
|
|
* So when we apply new zoom values to the browser, we simply set the zoom.
|
|
|
|
* We don't check first to see if the new value is the same as the current
|
|
|
|
* one.
|
2013-03-17 02:12:31 +04:00
|
|
|
*
|
2013-06-06 04:05:36 +04:00
|
|
|
* @param aValue The zoom level value.
|
|
|
|
* @param aOptions An object with the following optional propeties:
|
|
|
|
* @prop browser The browser containing the page whose zoom level is to be
|
|
|
|
* set. If falsey, the currently selected browser is used.
|
|
|
|
* @prop state This method may need to update the zoom asynchronously.
|
|
|
|
* If the caller is itself asynchronous, then it should have
|
|
|
|
* access to a FullZoom state (see _getState); pass that
|
|
|
|
* state here. If not given, the state is automatically
|
|
|
|
* captured.
|
|
|
|
* @prop onDone If given, it's asynchronously called when complete.
|
2013-03-17 02:12:31 +04:00
|
|
|
*/
|
2013-06-06 04:05:36 +04:00
|
|
|
_applyPrefToZoom: function FullZoom__applyPrefToZoom(aValue, aOptions={}) {
|
2013-03-17 02:12:31 +04:00
|
|
|
if (!this.siteSpecific || gInPrintPreviewMode) {
|
2013-06-06 04:05:36 +04:00
|
|
|
this._executeSoon(aOptions.onDone);
|
2009-09-10 00:04:05 +04:00
|
|
|
return;
|
2013-03-17 02:12:31 +04:00
|
|
|
}
|
2007-11-09 13:19:12 +03:00
|
|
|
|
2013-06-06 04:05:36 +04:00
|
|
|
var browser = aOptions.browser || (gBrowser && gBrowser.selectedBrowser);
|
2013-03-17 02:12:31 +04:00
|
|
|
if (browser.contentDocument.mozSyntheticDocument) {
|
2013-06-06 04:05:36 +04:00
|
|
|
this._executeSoon(aOptions.onDone);
|
2013-03-17 02:12:31 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-01-19 04:01:19 +04:00
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
if (aValue !== undefined) {
|
|
|
|
ZoomManager.setZoomForBrowser(browser, this._ensureValid(aValue));
|
2013-06-06 04:05:36 +04:00
|
|
|
this._zoomChangeToken++;
|
|
|
|
this._executeSoon(aOptions.onDone);
|
2013-03-17 02:12:31 +04:00
|
|
|
return;
|
2007-06-19 22:58:14 +04:00
|
|
|
}
|
2013-03-17 02:12:31 +04:00
|
|
|
|
2013-06-06 04:05:36 +04:00
|
|
|
let state = aOptions.state || this._getState(browser);
|
2013-03-17 02:12:31 +04:00
|
|
|
this._getGlobalValue(browser.contentWindow, function (value) {
|
2013-06-06 04:05:36 +04:00
|
|
|
if (this._isStateCurrent(state)) {
|
2013-03-17 02:12:31 +04:00
|
|
|
ZoomManager.setZoomForBrowser(browser, value === undefined ? 1 : value);
|
2013-06-06 04:05:36 +04:00
|
|
|
this._zoomChangeToken++;
|
|
|
|
}
|
|
|
|
this._executeSoon(aOptions.onDone);
|
2013-03-17 02:12:31 +04:00
|
|
|
});
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
/**
|
|
|
|
* Saves the zoom level of the page in the current browser to the content
|
|
|
|
* prefs store.
|
|
|
|
*/
|
2013-06-06 04:05:36 +04:00
|
|
|
_applyZoomToPref: function FullZoom__applyZoomToPref() {
|
2013-03-17 02:12:31 +04:00
|
|
|
if (!this.siteSpecific ||
|
|
|
|
gInPrintPreviewMode ||
|
2013-06-06 04:05:36 +04:00
|
|
|
content.document.mozSyntheticDocument)
|
2007-11-09 13:19:12 +03:00
|
|
|
return;
|
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
this._cps2.set(gBrowser.currentURI.spec, this.name, ZoomManager.zoom,
|
|
|
|
this._loadContextFromWindow(gBrowser.contentWindow), {
|
|
|
|
handleCompletion: function () {
|
2013-06-06 04:05:36 +04:00
|
|
|
this._isNextContentPrefChangeInternal = true;
|
|
|
|
}.bind(this),
|
2013-03-17 02:12:31 +04:00
|
|
|
});
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
2013-03-17 02:12:31 +04:00
|
|
|
/**
|
|
|
|
* Removes from the content prefs store the zoom level of the current browser.
|
|
|
|
*/
|
2013-06-06 04:05:36 +04:00
|
|
|
_removePref: function FullZoom__removePref() {
|
|
|
|
if (content.document.mozSyntheticDocument)
|
2013-03-17 02:12:31 +04:00
|
|
|
return;
|
|
|
|
let ctxt = this._loadContextFromWindow(gBrowser.contentWindow);
|
|
|
|
this._cps2.removeByDomainAndName(gBrowser.currentURI.spec, this.name, ctxt, {
|
|
|
|
handleCompletion: function () {
|
2013-06-06 04:05:36 +04:00
|
|
|
this._isNextContentPrefChangeInternal = true;
|
|
|
|
}.bind(this),
|
2013-03-17 02:12:31 +04:00
|
|
|
});
|
2007-06-19 22:58:14 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
//**************************************************************************//
|
|
|
|
// Utilities
|
|
|
|
|
2013-06-06 04:05:36 +04:00
|
|
|
/**
|
|
|
|
* Returns the current FullZoom "state". Asynchronous operations that change
|
|
|
|
* the zoom should use this method to capture the state before starting and
|
|
|
|
* use _isStateCurrent to determine if it's still current when done. If the
|
|
|
|
* captured state is no longer current, then the zoom should not be changed.
|
|
|
|
* Doing so would either change the zoom of the wrong tab or clobber an
|
|
|
|
* earlier zoom change that occurred after the operation started.
|
|
|
|
*
|
|
|
|
* @param browser The browser associated with the state. If not given, the
|
|
|
|
* currently selected browser is used.
|
|
|
|
*/
|
|
|
|
_getState: function FullZoom__getState(browser) {
|
|
|
|
let browser = browser || gBrowser.selectedBrowser;
|
|
|
|
return { uri: browser.currentURI, token: this._zoomChangeToken };
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given state is current.
|
|
|
|
*/
|
|
|
|
_isStateCurrent: function FullZoom__isStateCurrent(state) {
|
|
|
|
let currState = this._getState();
|
|
|
|
return currState.token === state.token &&
|
|
|
|
currState.uri && state.uri &&
|
|
|
|
this._cps2.extractDomain(currState.uri.spec) ==
|
|
|
|
this._cps2.extractDomain(state.uri.spec);
|
|
|
|
},
|
|
|
|
|
2007-11-26 11:35:22 +03:00
|
|
|
_ensureValid: function FullZoom__ensureValid(aValue) {
|
2013-03-17 02:12:31 +04:00
|
|
|
// Note that undefined is a valid value for aValue that indicates a known-
|
|
|
|
// not-to-exist value.
|
2007-06-19 22:58:14 +04:00
|
|
|
if (isNaN(aValue))
|
2007-10-26 03:02:20 +04:00
|
|
|
return 1;
|
2007-06-19 22:58:14 +04:00
|
|
|
|
2007-10-26 03:02:20 +04:00
|
|
|
if (aValue < ZoomManager.MIN)
|
|
|
|
return ZoomManager.MIN;
|
2007-06-19 22:58:14 +04:00
|
|
|
|
2007-10-26 03:02:20 +04:00
|
|
|
if (aValue > ZoomManager.MAX)
|
|
|
|
return ZoomManager.MAX;
|
2007-06-19 22:58:14 +04:00
|
|
|
|
|
|
|
return aValue;
|
2013-03-17 02:12:31 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the global browser.content.full-zoom content preference.
|
|
|
|
*
|
|
|
|
* WARNING: callback may be called synchronously or asynchronously. The
|
|
|
|
* reason is that it's usually desirable to avoid turns of the event loop
|
|
|
|
* where possible, since they can lead to visible, jarring jumps in zoom
|
|
|
|
* level. It's not always possible to avoid them, though. As a convenience,
|
|
|
|
* then, this method takes a callback and returns nothing.
|
|
|
|
*
|
|
|
|
* @param window The content window pertaining to the zoom.
|
|
|
|
* @param callback Synchronously or asynchronously called when done. It's
|
|
|
|
* bound to this object (FullZoom) and passed the preference
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
_getGlobalValue: function FullZoom__getGlobalValue(window, callback) {
|
|
|
|
// * !("_globalValue" in this) => global value not yet cached.
|
|
|
|
// * this._globalValue === undefined => global value known not to exist.
|
|
|
|
// * Otherwise, this._globalValue is a number, the global value.
|
|
|
|
if ("_globalValue" in this) {
|
|
|
|
callback.call(this, this._globalValue);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let value = undefined;
|
|
|
|
this._cps2.getGlobal(this.name, this._loadContextFromWindow(window), {
|
|
|
|
handleResult: function (pref) value = pref.value,
|
|
|
|
handleCompletion: function () {
|
|
|
|
this._globalValue = this._ensureValid(value);
|
|
|
|
callback.call(this, this._globalValue);
|
|
|
|
}.bind(this)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the load context from the given window.
|
|
|
|
*
|
|
|
|
* @param window The window whose load context will be returned.
|
|
|
|
* @return The nsILoadContext of the given window.
|
|
|
|
*/
|
|
|
|
_loadContextFromWindow: function FullZoom__loadContextFromWindow(window) {
|
|
|
|
return window.
|
|
|
|
QueryInterface(Ci.nsIInterfaceRequestor).
|
|
|
|
getInterface(Ci.nsIWebNavigation).
|
|
|
|
QueryInterface(Ci.nsILoadContext);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously broadcasts a "browser-fullZoom:locationChange" notification
|
|
|
|
* so that tests can select tabs, load pages, etc. and be notified when the
|
|
|
|
* zoom levels on those pages change. The notification is always asynchronous
|
|
|
|
* so that observers are guaranteed a consistent behavior.
|
|
|
|
*/
|
|
|
|
_notifyOnLocationChange: function FullZoom__notifyOnLocationChange() {
|
|
|
|
this._executeSoon(function () {
|
|
|
|
Services.obs.notifyObservers(null, "browser-fullZoom:locationChange", "");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_executeSoon: function FullZoom__executeSoon(callback) {
|
|
|
|
if (!callback)
|
|
|
|
return;
|
|
|
|
Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
},
|
2007-06-19 22:58:14 +04:00
|
|
|
};
|