OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('options', function() { | 5 cr.define('options', function() { |
6 | 6 |
7 var OptionsPage = options.OptionsPage; | 7 var OptionsPage = options.OptionsPage; |
8 | 8 |
9 /** | 9 /** |
10 * FontSettings class | 10 * FontSettings class |
(...skipping 16 matching lines...) Expand all Loading... |
27 * Initialize the page. | 27 * Initialize the page. |
28 */ | 28 */ |
29 initializePage: function() { | 29 initializePage: function() { |
30 OptionsPage.prototype.initializePage.call(this); | 30 OptionsPage.prototype.initializePage.call(this); |
31 | 31 |
32 var standardFontRange = $('standard-font-size'); | 32 var standardFontRange = $('standard-font-size'); |
33 standardFontRange.valueMap = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, | 33 standardFontRange.valueMap = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, |
34 22, 24, 26, 28, 30, 32, 34, 36, 40, 44, 48, 56, 64, 72]; | 34 22, 24, 26, 28, 30, 32, 34, 36, 40, 44, 48, 56, 64, 72]; |
35 standardFontRange.continuous = false; | 35 standardFontRange.continuous = false; |
36 standardFontRange.notifyChange = this.standardRangeChanged_.bind(this); | 36 standardFontRange.notifyChange = this.standardRangeChanged_.bind(this); |
37 standardFontRange.notifyPrefChange = | 37 Preferences.getInstance().addEventListener( |
38 this.standardFontSizeChanged_.bind(this); | 38 standardFontRange.pref, |
| 39 function(event) { |
| 40 Preferences.setIntegerPref( |
| 41 'webkit.webprefs.default_fixed_font_size', |
| 42 event.value.value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, |
| 43 true); |
| 44 }); |
39 | 45 |
40 var minimumFontRange = $('minimum-font-size'); | 46 var minimumFontRange = $('minimum-font-size'); |
41 minimumFontRange.valueMap = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, | 47 minimumFontRange.valueMap = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, |
42 18, 20, 22, 24]; | 48 18, 20, 22, 24]; |
43 minimumFontRange.continuous = false; | 49 minimumFontRange.continuous = false; |
44 minimumFontRange.notifyChange = this.minimumRangeChanged_.bind(this); | 50 minimumFontRange.notifyChange = this.minimumRangeChanged_.bind(this); |
45 minimumFontRange.notifyPrefChange = | 51 Preferences.getInstance().addEventListener( |
46 this.minimumFontSizeChanged_.bind(this); | 52 minimumFontRange.pref, |
| 53 function(event) { |
| 54 Preferences.setIntegerPref( |
| 55 'webkit.webprefs.minimum_logical_font_size', |
| 56 event.value.value, |
| 57 true); |
| 58 }); |
47 | 59 |
48 var placeholder = loadTimeData.getString('fontSettingsPlaceholder'); | 60 var placeholder = loadTimeData.getString('fontSettingsPlaceholder'); |
49 var elements = [$('standard-font-family'), $('serif-font-family'), | 61 var elements = [$('standard-font-family'), $('serif-font-family'), |
50 $('sans-serif-font-family'), $('fixed-font-family'), | 62 $('sans-serif-font-family'), $('fixed-font-family'), |
51 $('font-encoding')]; | 63 $('font-encoding')]; |
52 elements.forEach(function(el) { | 64 elements.forEach(function(el) { |
53 el.appendChild(new Option(placeholder)); | 65 el.appendChild(new Option(placeholder)); |
54 el.setDisabled('noFontsAvailable', true); | 66 el.setDisabled('noFontsAvailable', true); |
55 }); | 67 }); |
56 | 68 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily, | 105 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily, |
94 true); | 106 true); |
95 | 107 |
96 fontSampleEl = $('fixed-font-sample'); | 108 fontSampleEl = $('fixed-font-sample'); |
97 this.setUpFontSample_(fontSampleEl, | 109 this.setUpFontSample_(fontSampleEl, |
98 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, | 110 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, |
99 fontSampleEl.style.fontFamily, false); | 111 fontSampleEl.style.fontFamily, false); |
100 }, | 112 }, |
101 | 113 |
102 /** | 114 /** |
103 * Sets the 'default_fixed_font_size' preference when the standard font | |
104 * size has been changed by the user. | |
105 * @param {Element} el The slider input element. | |
106 * @param {number} value The mapped value that has been saved. | |
107 * @private | |
108 */ | |
109 standardFontSizeChanged_: function(el, value) { | |
110 Preferences.setIntegerPref( | |
111 'webkit.webprefs.default_fixed_font_size', | |
112 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, ''); | |
113 }, | |
114 | |
115 /** | |
116 * Called as the user changes the miniumum font size. This allows for | 115 * Called as the user changes the miniumum font size. This allows for |
117 * reflecting the change in the UI before the preference has been changed. | 116 * reflecting the change in the UI before the preference has been changed. |
118 * @param {Element} el The slider input element. | 117 * @param {Element} el The slider input element. |
119 * @param {number} value The mapped value currently set by the slider. | 118 * @param {number} value The mapped value currently set by the slider. |
120 * @private | 119 * @private |
121 */ | 120 */ |
122 minimumRangeChanged_: function(el, value) { | 121 minimumRangeChanged_: function(el, value) { |
123 var fontSampleEl = $('minimum-font-sample'); | 122 var fontSampleEl = $('minimum-font-sample'); |
124 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily, | 123 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily, |
125 true); | 124 true); |
126 }, | 125 }, |
127 | 126 |
128 /** | 127 /** |
129 * Sets the 'minimum_logical_font_size' preference when the minimum font | |
130 * size has been changed by the user. | |
131 * @param {Element} el The slider input element. | |
132 * @param {number} value The mapped value that has been saved. | |
133 * @private | |
134 */ | |
135 minimumFontSizeChanged_: function(el, value) { | |
136 Preferences.setIntegerPref( | |
137 'webkit.webprefs.minimum_logical_font_size', value, ''); | |
138 }, | |
139 | |
140 /** | |
141 * Sets the text, font size and font family of the sample text. | 128 * Sets the text, font size and font family of the sample text. |
142 * @param {Element} el The div containing the sample text. | 129 * @param {Element} el The div containing the sample text. |
143 * @param {number} size The font size of the sample text. | 130 * @param {number} size The font size of the sample text. |
144 * @param {string} font The font family of the sample text. | 131 * @param {string} font The font family of the sample text. |
145 * @param {bool} showSize True if the font size should appear in the sample. | 132 * @param {bool} showSize True if the font size should appear in the sample. |
146 * @private | 133 * @private |
147 */ | 134 */ |
148 setUpFontSample_: function(el, size, font, showSize) { | 135 setUpFontSample_: function(el, size, font, showSize) { |
149 var prefix = showSize ? (size + ': ') : ''; | 136 var prefix = showSize ? (size + ': ') : ''; |
150 el.textContent = prefix + | 137 el.textContent = prefix + |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 FontSettings.getInstance().setUpFontSample_($('minimum-font-sample'), size, | 214 FontSettings.getInstance().setUpFontSample_($('minimum-font-sample'), size, |
228 null, true); | 215 null, true); |
229 }; | 216 }; |
230 | 217 |
231 // Export | 218 // Export |
232 return { | 219 return { |
233 FontSettings: FontSettings | 220 FontSettings: FontSettings |
234 }; | 221 }; |
235 }); | 222 }); |
236 | 223 |
OLD | NEW |