Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / toolkit / content / viewZoomOverlay.js
blob15f4fd7ddcec821d323fdb5386e1d479fd091437
1 # -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is this file as it was released upon January 6, 2001.
18 # The Initial Developer of the Original Code is
19 # Peter Annema.
20 # Portions created by the Initial Developer are Copyright (C) 2000
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
24 # Peter Annema <disttsc@bart.nl> (Original Author)
25 # Jonas Sicking <sicking@bigfoot.com>
26 # Jason Barnabe <jason_barnabe@fastmail.fm>
27 # Dão Gottwald <dao@mozilla.com>
29 # Alternatively, the contents of this file may be used under the terms of
30 # either the GNU General Public License Version 2 or later (the "GPL"), or
31 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 # in which case the provisions of the GPL or the LGPL are applicable instead
33 # of those above. If you wish to allow use of your version of this file only
34 # under the terms of either the GPL or the LGPL, and not to allow others to
35 # use your version of this file under the terms of the MPL, indicate your
36 # decision by deleting the provisions above and replace them with the notice
37 # and other provisions required by the GPL or the LGPL. If you do not delete
38 # the provisions above, a recipient may use your version of this file under
39 # the terms of any one of the MPL, the GPL or the LGPL.
41 # ***** END LICENSE BLOCK *****
43 /** Document Zoom Management Code
45 * To use this, you'll need to have a getBrowser() function.
46 **/
48 var ZoomManager = {
49 get _prefBranch ZoomManager_get__prefBranch() {
50 delete this._prefBranch;
51 return this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
52 .getService(Components.interfaces.nsIPrefBranch);
55 get MIN ZoomManager_get_MIN() {
56 delete this.MIN;
57 return this.MIN = this._prefBranch.getIntPref("zoom.minPercent") / 100;
60 get MAX ZoomManager_get_MAX() {
61 delete this.MAX;
62 return this.MAX = this._prefBranch.getIntPref("zoom.maxPercent") / 100;
65 get useFullZoom ZoomManager_get_useFullZoom() {
66 return this._prefBranch.getBoolPref("browser.zoom.full");
69 set useFullZoom ZoomManager_set_useFullZoom(aVal) {
70 this._prefBranch.setBoolPref("browser.zoom.full", aVal);
71 return aVal;
74 get zoom ZoomManager_get_zoom() {
75 var markupDocumentViewer = getBrowser().markupDocumentViewer;
77 return this.useFullZoom ? markupDocumentViewer.fullZoom
78 : markupDocumentViewer.textZoom;
81 set zoom ZoomManager_set_zoom(aVal) {
82 if (aVal < this.MIN || aVal > this.MAX)
83 throw Components.results.NS_ERROR_INVALID_ARG;
85 var markupDocumentViewer = getBrowser().markupDocumentViewer;
87 if (this.useFullZoom) {
88 markupDocumentViewer.textZoom = 1;
89 markupDocumentViewer.fullZoom = aVal;
90 } else {
91 markupDocumentViewer.textZoom = aVal;
92 markupDocumentViewer.fullZoom = 1;
95 return aVal;
98 get zoomValues ZoomManager_get_zoomValues() {
99 var zoomValues = this._prefBranch.getCharPref("toolkit.zoomManager.zoomValues")
100 .split(",").map(parseFloat);
101 zoomValues.sort();
103 while (zoomValues[0] < this.MIN)
104 zoomValues.shift();
106 while (zoomValues[zoomValues.length - 1] > this.MAX)
107 zoomValues.pop();
109 delete this.zoomValues;
110 return this.zoomValues = zoomValues;
113 enlarge: function ZoomManager_enlarge() {
114 var i = this.zoomValues.indexOf(this.snap(this.zoom)) + 1;
115 if (i < this.zoomValues.length)
116 this.zoom = this.zoomValues[i];
119 reduce: function ZoomManager_reduce() {
120 var i = this.zoomValues.indexOf(this.snap(this.zoom)) - 1;
121 if (i >= 0)
122 this.zoom = this.zoomValues[i];
125 reset: function ZoomManager_reset() {
126 this.zoom = 1;
129 toggleZoom: function ZoomManager_toggleZoom() {
130 var zoomLevel = this.zoom;
132 this.useFullZoom = !this.useFullZoom;
133 this.zoom = zoomLevel;
136 snap: function ZoomManager_snap(aVal) {
137 var values = this.zoomValues;
138 for (var i = 0; i < values.length; i++) {
139 if (values[i] >= aVal) {
140 if (i > 0 && aVal - values[i - 1] < values[i] - aVal)
141 i--;
142 return values[i];
145 return values[i - 1];