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

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

Issue 10827141: Move handling of dialog preferences to Preferences class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed PrefCheckbox. Created 8 years, 3 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) 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 14 matching lines...) Expand all
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 = [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.addEventListener(
36 standardFontRange.notifyChange = this.standardRangeChanged_.bind(this); 36 'change', this.standardRangeChanged_.bind(this, standardFontRange));
37 standardFontRange.notifyPrefChange = 37 standardFontRange.customChangeHandler =
38 this.standardFontSizeChanged_.bind(this); 38 this.standardFontSizeChanged_.bind(standardFontRange);
39 39
40 var minimumFontRange = $('minimum-font-size'); 40 var minimumFontRange = $('minimum-font-size');
41 minimumFontRange.valueMap = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 41 minimumFontRange.valueMap = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
42 18, 20, 22, 24]; 42 18, 20, 22, 24];
43 minimumFontRange.continuous = false; 43 minimumFontRange.addEventListener(
44 minimumFontRange.notifyChange = this.minimumRangeChanged_.bind(this); 44 'change', this.minimumRangeChanged_.bind(this, minimumFontRange));
45 minimumFontRange.notifyPrefChange = 45 minimumFontRange.customChangeHandler =
46 this.minimumFontSizeChanged_.bind(this); 46 this.minimumFontSizeChanged_.bind(minimumFontRange);
47 47
48 var placeholder = loadTimeData.getString('fontSettingsPlaceholder'); 48 var placeholder = loadTimeData.getString('fontSettingsPlaceholder');
49 var elements = [$('standard-font-family'), $('serif-font-family'), 49 var elements = [$('standard-font-family'), $('serif-font-family'),
50 $('sans-serif-font-family'), $('fixed-font-family'), 50 $('sans-serif-font-family'), $('fixed-font-family'),
51 $('font-encoding')]; 51 $('font-encoding')];
52 elements.forEach(function(el) { 52 elements.forEach(function(el) {
53 el.appendChild(new Option(placeholder)); 53 el.appendChild(new Option(placeholder));
54 el.setDisabled('noFontsAvailable', true); 54 el.setDisabled('noFontsAvailable', true);
55 }); 55 });
56 56
(...skipping 10 matching lines...) Expand all
67 // loaded for the first time. This makes opening the options window 67 // loaded for the first time. This makes opening the options window
68 // faster and consume less memory if the user never opens the fonts 68 // faster and consume less memory if the user never opens the fonts
69 // dialog. 69 // dialog.
70 if (!this.hasShown) { 70 if (!this.hasShown) {
71 chrome.send('fetchFontsData'); 71 chrome.send('fetchFontsData');
72 this.hasShown = true; 72 this.hasShown = true;
73 } 73 }
74 }, 74 },
75 75
76 /** 76 /**
77 * Called as the user changes the standard font size. This allows for 77 * Handler that is called when the user changes the position of the standard
78 * reflecting the change in the UI before the preference has been changed. 78 * font size slider. This allows the UI to show a preview of the change
79 * before the slider has been released and the associated prefs updated.
79 * @param {Element} el The slider input element. 80 * @param {Element} el The slider input element.
80 * @param {number} value The mapped value currently set by the slider. 81 * @param {Event} event Change event.
81 * @private 82 * @private
82 */ 83 */
83 standardRangeChanged_: function(el, value) { 84 standardRangeChanged_: function(el, event) {
85 var value = el.mapValueToRange(el.value);
84 var fontSampleEl = $('standard-font-sample'); 86 var fontSampleEl = $('standard-font-sample');
85 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily, 87 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
86 true); 88 true);
87 89
88 fontSampleEl = $('serif-font-sample'); 90 fontSampleEl = $('serif-font-sample');
89 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily, 91 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
90 true); 92 true);
91 93
92 fontSampleEl = $('sans-serif-font-sample'); 94 fontSampleEl = $('sans-serif-font-sample');
93 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily, 95 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
94 true); 96 true);
95 97
96 fontSampleEl = $('fixed-font-sample'); 98 fontSampleEl = $('fixed-font-sample');
97 this.setUpFontSample_(fontSampleEl, 99 this.setUpFontSample_(fontSampleEl,
98 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, 100 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD,
99 fontSampleEl.style.fontFamily, false); 101 fontSampleEl.style.fontFamily, false);
100 }, 102 },
101 103
102 /** 104 /**
103 * Sets the 'default_fixed_font_size' preference when the standard font 105 * Sets the 'default_fixed_font_size' preference when the user changes the
104 * size has been changed by the user. 106 * standard font size.
105 * @param {Element} el The slider input element. 107 * @param {Event} event Change event.
106 * @param {number} value The mapped value that has been saved.
107 * @private 108 * @private
108 */ 109 */
109 standardFontSizeChanged_: function(el, value) { 110 standardFontSizeChanged_: function(event) {
111 var value = this.mapValueToRange(this.value);
110 Preferences.setIntegerPref( 112 Preferences.setIntegerPref(
111 'webkit.webprefs.default_fixed_font_size', 113 'webkit.webprefs.default_fixed_font_size',
112 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, ''); 114 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, true);
115 return false;
113 }, 116 },
114 117
115 /** 118 /**
116 * Called as the user changes the miniumum font size. This allows for 119 * Handler that is called when the user changes the position of the minimum
117 * reflecting the change in the UI before the preference has been changed. 120 * font size slider. This allows the UI to show a preview of the change
121 * before the slider has been released and the associated prefs updated.
118 * @param {Element} el The slider input element. 122 * @param {Element} el The slider input element.
119 * @param {number} value The mapped value currently set by the slider. 123 * @param {Event} event Change event.
120 * @private 124 * @private
121 */ 125 */
122 minimumRangeChanged_: function(el, value) { 126 minimumRangeChanged_: function(el, event) {
127 var value = el.mapValueToRange(el.value);
123 var fontSampleEl = $('minimum-font-sample'); 128 var fontSampleEl = $('minimum-font-sample');
124 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily, 129 this.setUpFontSample_(fontSampleEl, value, fontSampleEl.style.fontFamily,
125 true); 130 true);
126 }, 131 },
127 132
128 /** 133 /**
129 * Sets the 'minimum_logical_font_size' preference when the minimum font 134 * Sets the 'minimum_logical_font_size' preference when the user changes the
130 * size has been changed by the user. 135 * minimum font size.
131 * @param {Element} el The slider input element. 136 * @param {Event} event Change event.
132 * @param {number} value The mapped value that has been saved.
133 * @private 137 * @private
134 */ 138 */
135 minimumFontSizeChanged_: function(el, value) { 139 minimumFontSizeChanged_: function(event) {
140 var value = this.mapValueToRange(this.value);
136 Preferences.setIntegerPref( 141 Preferences.setIntegerPref(
137 'webkit.webprefs.minimum_logical_font_size', value, ''); 142 'webkit.webprefs.minimum_logical_font_size', value, true);
143 return false;
138 }, 144 },
139 145
140 /** 146 /**
141 * Sets the text, font size and font family of the sample text. 147 * Sets the text, font size and font family of the sample text.
142 * @param {Element} el The div containing the sample text. 148 * @param {Element} el The div containing the sample text.
143 * @param {number} size The font size of the sample text. 149 * @param {number} size The font size of the sample text.
144 * @param {string} font The font family of the sample text. 150 * @param {string} font The font family of the sample text.
145 * @param {bool} showSize True if the font size should appear in the sample. 151 * @param {bool} showSize True if the font size should appear in the sample.
146 * @private 152 * @private
147 */ 153 */
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 FontSettings.getInstance().setUpFontSample_($('minimum-font-sample'), size, 233 FontSettings.getInstance().setUpFontSample_($('minimum-font-sample'), size,
228 null, true); 234 null, true);
229 }; 235 };
230 236
231 // Export 237 // Export
232 return { 238 return {
233 FontSettings: FontSettings 239 FontSettings: FontSettings
234 }; 240 };
235 }); 241 });
236 242
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/controlled_setting.js ('k') | chrome/browser/resources/options/import_data_overlay.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698