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

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

Issue 6672063: web-ui settings: Font setting fixes and improvements.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: code review fix Created 9 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 12 matching lines...) Expand all
23 FontSettings.prototype = { 23 FontSettings.prototype = {
24 __proto__: OptionsPage.prototype, 24 __proto__: OptionsPage.prototype,
25 25
26 /** 26 /**
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 = $('fixed-font-size').valueMap = [9, 10, 11, 33 standardFontRange.valueMap = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20,
34 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 40, 34 22, 24, 26, 28, 30, 32, 34, 36, 40, 44, 48, 56, 64, 72];
35 44, 48, 56, 64, 72];
36 standardFontRange.continuous = false; 35 standardFontRange.continuous = false;
37 standardFontRange.fontSampleEl = $('standard-font-sample'); 36 standardFontRange.notifyChange = this.standardRangeChanged_.bind(this);
38 standardFontRange.notifyChange = this.rangeChanged_.bind(this);
39 37
40 var minimumFontRange = $('minimum-font-size'); 38 var minimumFontRange = $('minimum-font-size');
41 minimumFontRange.valueMap = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 39 minimumFontRange.valueMap = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
42 18, 20, 22, 24]; 40 18, 20, 22, 24];
43 minimumFontRange.continuous = false; 41 minimumFontRange.continuous = false;
44 minimumFontRange.fontSampleEl = $('minimum-font-sample'); 42 minimumFontRange.notifyChange = this.minimumRangeChanged_.bind(this);
45 minimumFontRange.notifyChange = this.rangeChanged_.bind(this);
46 minimumFontRange.notifyPrefChange = 43 minimumFontRange.notifyPrefChange =
47 this.minimumFontSizeChanged_.bind(this); 44 this.minimumFontSizeChanged_.bind(this);
48 45
49 var placeholder = localStrings.getString('fontSettingsPlaceholder'); 46 var placeholder = localStrings.getString('fontSettingsPlaceholder');
50 $('standard-font-family').appendChild(new Option(placeholder)); 47 $('standard-font-family').appendChild(new Option(placeholder));
48 $('serif-font-family').appendChild(new Option(placeholder));
49 $('sans-serif-font-family').appendChild(new Option(placeholder));
51 $('fixed-font-family').appendChild(new Option(placeholder)); 50 $('fixed-font-family').appendChild(new Option(placeholder));
52 $('font-encoding').appendChild(new Option(placeholder)); 51 $('font-encoding').appendChild(new Option(placeholder));
53 }, 52 },
54 53
55 /** 54 /**
56 * Called by the options page when this page has been shown. 55 * Called by the options page when this page has been shown.
57 */ 56 */
58 didShowPage: function() { 57 didShowPage: function() {
59 // The fonts list may be large so we only load it when this page is 58 // The fonts list may be large so we only load it when this page is
60 // loaded for the first time. This makes opening the options window 59 // loaded for the first time. This makes opening the options window
61 // faster and consume less memory if the user never opens the fonts 60 // faster and consume less memory if the user never opens the fonts
62 // dialog. 61 // dialog.
63 if (!this.hasShown) { 62 if (!this.hasShown) {
64 chrome.send('fetchFontsData'); 63 chrome.send('fetchFontsData');
65 this.hasShown = true; 64 this.hasShown = true;
66 } 65 }
67 }, 66 },
68 67
69 /** 68 /**
70 * Called as the user changes a non-continuous slider. This allows for 69 * Called as the user changes the standard font size. This allows for
71 * reflecting the change in the UI before the preference has been changed. 70 * reflecting the change in the UI before the preference has been changed.
72 * @param {Element} el The slider input element. 71 * @param {Element} el The slider input element.
73 * @param {number} value The mapped value currently set by the slider. 72 * @param {number} value The mapped value currently set by the slider.
74 * @private 73 * @private
75 */ 74 */
76 rangeChanged_: function(el, value) { 75 standardRangeChanged_: function(el, value) {
77 this.setupFontSample_(el.fontSampleEl, value, 76 var fontSampleEl = $('standard-font-sample');
78 el.fontSampleEl.style.fontFamily); 77 this.setupFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
78 true);
79
80 fontSampleEl = $('serif-font-sample');
81 this.setupFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
82 true);
83
84 fontSampleEl = $('sans-serif-font-sample');
85 this.setupFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
86 true);
87 },
88
89 /**
90 * Called as the user changes the miniumum font size. This allows for
91 * reflecting the change in the UI before the preference has been changed.
92 * @param {Element} el The slider input element.
93 * @param {number} value The mapped value currently set by the slider.
94 * @private
95 */
96 minimumRangeChanged_: function(el, value) {
97 var fontSampleEl = $('minimum-font-sample');
98 this.setupFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
99 true);
79 }, 100 },
80 101
81 /** 102 /**
82 * Sets the 'minimum_logical_font_size' preference when the minimum font 103 * Sets the 'minimum_logical_font_size' preference when the minimum font
83 * size has been changed by the user. 104 * size has been changed by the user.
84 * @param {Element} el The slider input element. 105 * @param {Element} el The slider input element.
85 * @param {number} value The mapped value that has been saved. 106 * @param {number} value The mapped value that has been saved.
86 * @private 107 * @private
87 */ 108 */
88 minimumFontSizeChanged_: function(el, value) { 109 minimumFontSizeChanged_: function(el, value) {
89 Preferences.setIntegerPref('webkit.webprefs.minimum_logical_font_size', 110 Preferences.setIntegerPref('webkit.webprefs.minimum_logical_font_size',
90 value, ''); 111 value, '');
91 }, 112 },
92 113
93 /** 114 /**
94 * Sets the text, font size and font family of the sample text. 115 * Sets the text, font size and font family of the sample text.
95 * @param {Element} el The div containing the sample text. 116 * @param {Element} el The div containing the sample text.
96 * @param {number} size The font size of the sample text. 117 * @param {number} size The font size of the sample text.
97 * @param {string} font The font family of the sample text. 118 * @param {string} font The font family of the sample text.
119 * @param {bool} showSize True if the font size should appear in the sample.
98 * @private 120 * @private
99 */ 121 */
100 setupFontSample_: function(el, size, font) { 122 setupFontSample_: function(el, size, font, showSize) {
101 el.textContent = 123 var prefix = showSize ? (size + ': ') : '';
102 size + ": " + localStrings.getString('fontSettingsLoremIpsum'); 124 el.textContent = prefix +
103 el.style.fontSize = size + "px"; 125 localStrings.getString('fontSettingsLoremIpsum');
126 el.style.fontSize = size + 'px';
104 if (font) 127 if (font)
105 el.style.fontFamily = font; 128 el.style.fontFamily = font;
106 }, 129 },
107 130
108 /** 131 /**
109 * Populates a select list and selects the specified item. 132 * Populates a select list and selects the specified item.
110 * @param {Element} element The select element to populate. 133 * @param {Element} element The select element to populate.
111 * @param {Array} items The array of items from which to populate. 134 * @param {Array} items The array of items from which to populate.
112 * @param {string} selectedValue The selected item. 135 * @param {string} selectedValue The selected item.
113 * @private 136 * @private
(...skipping 18 matching lines...) Expand all
132 // Enable if not a managed pref. 155 // Enable if not a managed pref.
133 if (!element.managed) 156 if (!element.managed)
134 element.disabled = false; 157 element.disabled = false;
135 } 158 }
136 }; 159 };
137 160
138 // Chrome callbacks 161 // Chrome callbacks
139 FontSettings.setFontsData = function(fonts, encodings, selectedValues) { 162 FontSettings.setFontsData = function(fonts, encodings, selectedValues) {
140 FontSettings.getInstance().populateSelect_($('standard-font-family'), fonts, 163 FontSettings.getInstance().populateSelect_($('standard-font-family'), fonts,
141 selectedValues[0]); 164 selectedValues[0]);
165 FontSettings.getInstance().populateSelect_($('serif-font-family'), fonts,
166 selectedValues[1]);
167 FontSettings.getInstance().populateSelect_($('sans-serif-font-family'),
168 fonts, selectedValues[2]);
142 FontSettings.getInstance().populateSelect_($('fixed-font-family'), fonts, 169 FontSettings.getInstance().populateSelect_($('fixed-font-family'), fonts,
143 selectedValues[1]); 170 selectedValues[3]);
144 FontSettings.getInstance().populateSelect_($('font-encoding'), encodings, 171 FontSettings.getInstance().populateSelect_($('font-encoding'), encodings,
145 selectedValues[2]); 172 selectedValues[4]);
146 }; 173 };
147 174
148 FontSettings.setupStandardFontSample = function(font, size) { 175 FontSettings.setupStandardFontSample = function(font, size) {
149 FontSettings.getInstance().setupFontSample_($('standard-font-sample'), size, 176 FontSettings.getInstance().setupFontSample_($('standard-font-sample'), size,
150 font); 177 font, true);
178 };
179
180 FontSettings.setupSerifFontSample = function(font, size) {
181 FontSettings.getInstance().setupFontSample_($('serif-font-sample'), size,
182 font, true);
183 };
184
185 FontSettings.setupSansSerifFontSample = function(font, size) {
186 FontSettings.getInstance().setupFontSample_($('sans-serif-font-sample'),
187 size, font, true);
151 }; 188 };
152 189
153 FontSettings.setupFixedFontSample = function(font, size) { 190 FontSettings.setupFixedFontSample = function(font, size) {
154 FontSettings.getInstance().setupFontSample_($('fixed-font-sample'), size, 191 FontSettings.getInstance().setupFontSample_($('fixed-font-sample'),
155 font); 192 size, font, false);
156 }; 193 };
157 194
158 FontSettings.setupMinimumFontSample = function(size) { 195 FontSettings.setupMinimumFontSample = function(size) {
159 FontSettings.getInstance().setupFontSample_($('minimum-font-sample'), size); 196 // If size is less than 6, represent it as six in the sample to account
197 // for the minimum logical font size.
198 if (size < 6)
199 size = 6;
200 FontSettings.getInstance().setupFontSample_($('minimum-font-sample'), size,
201 true);
160 }; 202 };
161 203
162 // Export 204 // Export
163 return { 205 return {
164 FontSettings: FontSettings 206 FontSettings: FontSettings
165 }; 207 };
166 }); 208 });
167 209
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/font_settings.html ('k') | chrome/browser/ui/webui/options/advanced_options_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698