Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Side by Side Diff: chrome/browser/resources/options/font_settings.js

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('options', function() {
6
7 var OptionsPage = options.OptionsPage;
8
9 /**
10 * FontSettings class
11 * Encapsulated handling of the 'Fonts and Encoding' page.
12 * @class
13 */
14 function FontSettings() {
15 OptionsPage.call(this,
16 'fonts',
17 templateData.fontSettingsPageTabTitle,
18 'font-settings');
19 }
20
21 cr.addSingletonGetter(FontSettings);
22
23 FontSettings.prototype = {
24 __proto__: OptionsPage.prototype,
25
26 /**
27 * Initialize the page.
28 */
29 initializePage: function() {
30 OptionsPage.prototype.initializePage.call(this);
31
32 var standardFontRange = $('standard-font-size');
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];
35 standardFontRange.continuous = false;
36 standardFontRange.notifyChange = this.standardRangeChanged_.bind(this);
37 standardFontRange.notifyPrefChange =
38 this.standardFontSizeChanged_.bind(this);
39
40 var minimumFontRange = $('minimum-font-size');
41 minimumFontRange.valueMap = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
42 18, 20, 22, 24];
43 minimumFontRange.continuous = false;
44 minimumFontRange.notifyChange = this.minimumRangeChanged_.bind(this);
45 minimumFontRange.notifyPrefChange =
46 this.minimumFontSizeChanged_.bind(this);
47
48 var placeholder = localStrings.getString('fontSettingsPlaceholder');
49 var elements = [$('standard-font-family'), $('serif-font-family'),
50 $('sans-serif-font-family'), $('fixed-font-family'),
51 $('font-encoding')];
52 elements.forEach(function(el) {
53 el.appendChild(new Option(placeholder));
54 el.setDisabled('noFontsAvailable', true);
55 });
56 },
57
58 /**
59 * Called by the options page when this page has been shown.
60 */
61 didShowPage: function() {
62 // The fonts list may be large so we only load it when this page is
63 // loaded for the first time. This makes opening the options window
64 // faster and consume less memory if the user never opens the fonts
65 // dialog.
66 if (!this.hasShown) {
67 chrome.send('fetchFontsData');
68 this.hasShown = true;
69 }
70 },
71
72 /**
73 * Called as the user changes the standard font size. This allows for
74 * reflecting the change in the UI before the preference has been changed.
75 * @param {Element} el The slider input element.
76 * @param {number} value The mapped value currently set by the slider.
77 * @private
78 */
79 standardRangeChanged_: function(el, value) {
80 var fontSampleEl = $('standard-font-sample');
81 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
82 true);
83
84 fontSampleEl = $('serif-font-sample');
85 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
86 true);
87
88 fontSampleEl = $('sans-serif-font-sample');
89 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
90 true);
91
92 fontSampleEl = $('fixed-font-sample');
93 this.setUpFontSample_(fontSampleEl,
94 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD,
95 fontSampleEl.style.fontFamily, false);
96 },
97
98 /**
99 * Sets the 'default_fixed_font_size' preference when the standard font
100 * size has been changed by the user.
101 * @param {Element} el The slider input element.
102 * @param {number} value The mapped value that has been saved.
103 * @private
104 */
105 standardFontSizeChanged_: function(el, value) {
106 Preferences.setIntegerPref(
107 'webkit.webprefs.global.default_fixed_font_size',
108 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, '');
109 },
110
111 /**
112 * Called as the user changes the miniumum font size. This allows for
113 * reflecting the change in the UI before the preference has been changed.
114 * @param {Element} el The slider input element.
115 * @param {number} value The mapped value currently set by the slider.
116 * @private
117 */
118 minimumRangeChanged_: function(el, value) {
119 var fontSampleEl = $('minimum-font-sample');
120 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
121 true);
122 },
123
124 /**
125 * Sets the 'minimum_logical_font_size' preference when the minimum font
126 * size has been changed by the user.
127 * @param {Element} el The slider input element.
128 * @param {number} value The mapped value that has been saved.
129 * @private
130 */
131 minimumFontSizeChanged_: function(el, value) {
132 Preferences.setIntegerPref(
133 'webkit.webprefs.global.minimum_logical_font_size', value, '');
134 },
135
136 /**
137 * Sets the text, font size and font family of the sample text.
138 * @param {Element} el The div containing the sample text.
139 * @param {number} size The font size of the sample text.
140 * @param {string} font The font family of the sample text.
141 * @param {bool} showSize True if the font size should appear in the sample.
142 * @private
143 */
144 setUpFontSample_: function(el, size, font, showSize) {
145 var prefix = showSize ? (size + ': ') : '';
146 el.textContent = prefix +
147 localStrings.getString('fontSettingsLoremIpsum');
148 el.style.fontSize = size + 'px';
149 if (font)
150 el.style.fontFamily = font;
151 },
152
153 /**
154 * Populates a select list and selects the specified item.
155 * @param {Element} element The select element to populate.
156 * @param {Array} items The array of items from which to populate.
157 * @param {string} selectedValue The selected item.
158 * @private
159 */
160 populateSelect_: function(element, items, selectedValue) {
161 // Remove any existing content.
162 element.textContent = '';
163
164 // Insert new child nodes into select element.
165 var value, text, selected, option;
166 for (var i = 0; i < items.length; i++) {
167 value = items[i][0];
168 text = items[i][1];
169 if (text) {
170 selected = value == selectedValue;
171 element.appendChild(new Option(text, value, false, selected));
172 } else {
173 element.appendChild(document.createElement('hr'));
174 }
175 }
176
177 element.setDisabled('noFontsAvailable', false);
178 }
179 };
180
181 // Chrome callbacks
182 FontSettings.setFontsData = function(fonts, encodings, selectedValues) {
183 FontSettings.getInstance().populateSelect_($('standard-font-family'), fonts,
184 selectedValues[0]);
185 FontSettings.getInstance().populateSelect_($('serif-font-family'), fonts,
186 selectedValues[1]);
187 FontSettings.getInstance().populateSelect_($('sans-serif-font-family'),
188 fonts, selectedValues[2]);
189 FontSettings.getInstance().populateSelect_($('fixed-font-family'), fonts,
190 selectedValues[3]);
191 FontSettings.getInstance().populateSelect_($('font-encoding'), encodings,
192 selectedValues[4]);
193 };
194
195 FontSettings.setUpStandardFontSample = function(font, size) {
196 FontSettings.getInstance().setUpFontSample_($('standard-font-sample'), size,
197 font, true);
198 };
199
200 FontSettings.setUpSerifFontSample = function(font, size) {
201 FontSettings.getInstance().setUpFontSample_($('serif-font-sample'), size,
202 font, true);
203 };
204
205 FontSettings.setUpSansSerifFontSample = function(font, size) {
206 FontSettings.getInstance().setUpFontSample_($('sans-serif-font-sample'),
207 size, font, true);
208 };
209
210 FontSettings.setUpFixedFontSample = function(font, size) {
211 FontSettings.getInstance().setUpFontSample_($('fixed-font-sample'),
212 size, font, false);
213 };
214
215 FontSettings.setUpMinimumFontSample = function(size) {
216 // If size is less than 6, represent it as six in the sample to account
217 // for the minimum logical font size.
218 if (size < 6)
219 size = 6;
220 FontSettings.getInstance().setUpFontSample_($('minimum-font-sample'), size,
221 null, true);
222 };
223
224 // Export
225 return {
226 FontSettings: FontSettings
227 };
228 });
229
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698