summaryrefslogtreecommitdiffstats
path: root/comm/suite/components/pref/content/pref-content.js
blob: 964c216a28419199700a3e1ab68361dc0d1d333a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* 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/. */

var {AppConstants} = ChromeUtils.import(
  "resource://gre/modules/AppConstants.jsm"
);

var minMinValue;
var maxMinValue;

/**
 * When starting up, obtain min and max values for the zoom-range controls
 * from the first and last values of the zoom-levels array.
 */
function Startup()
{
  let minElement  = document.getElementById("minZoom");
  let maxElement  = document.getElementById("maxZoom");
  let minMaxLimit = 200;
  let maxMinLimit = 50;  // allow reasonable amounts of overlap
  let zoomValues  = Services.prefs.getCharPref("toolkit.zoomManager.zoomValues")
                            .split(",").map(parseFloat);
  zoomValues.sort((a, b) => a - b);

  let firstValue  = Math.round(100 * zoomValues[0]);
  let lastValue   = Math.round(100 * zoomValues[zoomValues.length - 1]);

  minMinValue     = firstValue;
  minElement.min  = minMinValue;
  minElement.max  = lastValue  > minMaxLimit ? minMaxLimit : lastValue;

  maxMinValue     = firstValue < maxMinLimit ? maxMinLimit : firstValue;
  maxElement.min  = maxMinValue;
  maxElement.max  = lastValue;

  /*   defaultZoom  stuff   */

  let defaultElement = document.getElementById("defaultZoom");

  defaultElement.min = Services.prefs.getIntPref("zoom.minPercent");
  defaultElement.max = Services.prefs.getIntPref("zoom.maxPercent");

  var zoomValue = Services.contentPrefs2
                          .getCachedGlobal("browser.content.full-zoom", null);
  if (zoomValue && zoomValue.value) {
    defaultElement.value = Math.round(zoomValue.value * 100);
    return;
  }

  defaultElement.value = 100;
  Services.contentPrefs2.getGlobal("browser.content.full-zoom", null, {
    handleResult(pref) {
      defaultElement.value = Math.round(pref.value * 100);
    },
    handleCompletion(reason) {}
  });
}

/**
 * Suspend "min" value while manually typing in a number.
 */
function DisableMinCheck(element)
{
  element.min = 0;
}

/**
 * Modify the maxZoom setting if minZoom was chosen to be larger than it.
 */
function AdjustMaxZoom()
{
  let minElement  = document.getElementById("minZoom");
  let maxElement  = document.getElementById("maxZoom");
  let maxPref     = document.getElementById("zoom.maxPercent");

  if(minElement.valueNumber > maxElement.valueNumber)
    maxPref.value = minElement.value;

  minElement.min  = minMinValue;

  let defaultElement  = document.getElementById("defaultZoom");
  if (defaultElement.valueNumber < minElement.valueNumber) {
    defaultElement.valueNumber = minElement.valueNumber;
    SetDefaultZoom();
  }
  defaultElement.min = minElement.valueNumber;
}

/**
 * Modify the minZoom setting if maxZoom was chosen to be smaller than it,
 * adjusting maxZoom first if it's below maxMinValue.
 */
function AdjustMinZoom()
{
  let minElement  = document.getElementById("minZoom");
  let maxElement  = document.getElementById("maxZoom");
  let minPref     = document.getElementById("zoom.minPercent");
  let maxValue    = maxElement.valueNumber < maxMinValue ?
                    maxMinValue : maxElement.valueNumber;

  if(maxValue < minElement.valueNumber)
    minPref.value = maxValue;

  maxElement.min  = maxMinValue;

  let defaultElement  = document.getElementById("defaultZoom");
  if (defaultElement.valueNumber > maxElement.valueNumber) {
    defaultElement.valueNumber = maxElement.valueNumber;
    SetDefaultZoom();
  }
  defaultElement.max = maxElement.valueNumber;
}

/**
 * Set default zoom.
 */
function SetDefaultZoom()
{
  let defaultElement  = document.getElementById("defaultZoom");

  if (defaultElement.valueNumber == 100) {
    Services.contentPrefs2.removeGlobal("browser.content.full-zoom", null);
    return;
  }

  let new_value = defaultElement.valueNumber / 100.;
  Services.contentPrefs2.setGlobal("browser.content.full-zoom", new_value,
                                   null);
}

/**
 * When the user toggles the layers.acceleration.disabled pref,
 * sync its new value to the gfx.direct2d.disabled pref too.
 */
function updateHardwareAcceleration(aVal)
{
  if (AppConstants.platform == "win") {
    document.getElementById("gfx.direct2d.disabled").value = aVal;
  }
}