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

Side by Side Diff: chrome/browser/resources/settings/appearance_page/appearance_fonts_page.js

Issue 1415463013: [MD settings] adding font settings files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review changes Created 5 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2015 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 /**
6 * This is the absolute difference maintained between standard and
7 * fixed-width font sizes. http://crbug.com/91922.
8 * @const
9 */
10 var SIZE_DIFFERENCE_FIXED_STANDARD = 3;
11
12 var FONT_SIZE_RANGE = [
13 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36,
14 40, 44, 48, 56, 64, 72,
15 ];
16
17 var FONT_SIZE_RANGE_LIMIT = FONT_SIZE_RANGE.length - 1;
18
19 var MINIMUM_FONT_SIZE_RANGE = [
20 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24
21 ];
22
23 var MINIMUM_FONT_SIZE_RANGE_LIMIT = MINIMUM_FONT_SIZE_RANGE.length - 1;
24
25 /**
26 * 'settings-appearance-page' is the settings page containing appearance
27 * settings.
28 *
29 * Example:
30 *
31 * <settings-appearance-fonts-page prefs="{{prefs}}">
32 * </settings-appearance-fonts-page>
33 *
34 * @group Chrome Settings Elements
35 * @element settings-appearance-page
36 */
37 Polymer({
38 is: 'settings-appearance-fonts-page',
39
40 properties: {
41 /**
42 * The font size used by default.
43 * @private
44 */
45 defaultFontSize_: {
46 type: Number,
47 },
48
49 /**
50 * The value of the font size slider.
51 * @private
52 */
53 fontSizeIndex_: {
54 type: Number,
55 },
56
57 /**
58 * Common font sizes.
59 * @private {!Array<number>}
60 */
61 fontSizeRange_: {
62 readOnly: true,
63 type: Array,
64 value: FONT_SIZE_RANGE,
65 },
66
67 /**
68 * Upper bound of the font size slider.
69 * @private
70 */
71 fontSizeRangeLimit_: {
72 readOnly: true,
73 type: Number,
74 value: MINIMUM_FONT_SIZE_RANGE_LIMIT,
75 },
76
77 /**
78 * The interactive value of the minimum font size slider.
79 * @private
80 */
81 immediateMinimumSizeIndex_: {
82 type: Number,
83 },
84
85 /**
86 * The interactive value of the font size slider.
87 * @private
88 */
89 immediateSizeIndex_: {
90 type: Number,
91 },
92
93 /**
94 * Reasonable, minimum font sizes.
95 * @private {!Array<number>}
96 */
97 minimumFontSizeRange_: {
98 readOnly: true,
99 type: Array,
100 value: MINIMUM_FONT_SIZE_RANGE,
101 },
102
103 /**
104 * Upper bound of the minimum font size slider.
105 * @private
106 */
107 minimumFontSizeRangeLimit_: {
108 readOnly: true,
109 type: Number,
110 value: MINIMUM_FONT_SIZE_RANGE_LIMIT,
111 },
112
113 /**
114 * The font size used at minimum.
115 * @private
116 */
117 minimumFontSize_: {
118 type: Number,
119 },
120
121 /**
122 * The value of the minimum font size slider.
123 * @private
124 */
125 minimumSizeIndex_: {
126 type: Number,
127 },
128
129 /**
130 * Preferences state.
131 * @type {!Object}
stevenjb 2015/10/29 19:56:02 Not needed. In this case the entire pref store is
dschuyler 2015/11/04 22:10:56 Done.
132 */
133 prefs: {
134 type: Object,
135 notify: true,
136 },
137 },
138
139 /**
140 * This is the absolute difference maintained between standard and
141 * fixed-width font sizes. http://crbug.com/91922.
142 * @const
143 */
144 SIZE_DIFFERENCE_FIXED_STANDARD: 3,
145
146 observers: [
147 'fontSizeChanged_(prefs.webkit.webprefs.default_font_size.value)',
148 'minimumFontSizeChanged_(prefs.webkit.webprefs.minimum_font_size.value)',
149 ],
150
151 ready: function() {
152 var self = this;
153 cr.define('Settings', function() {
154 return {
155 setFontsData: function() {
156 return self.setFontsData_.apply(self, arguments);
157 },
158 };
159 });
160 chrome.send('fetchFontsData');
161 },
162
163 /**
164 * @param {number} value The intermediate slider value.
165 * @private
166 */
167 immediateSizeIndexChanged_: function(value) {
168 this.set('prefs.webkit.webprefs.default_font_size.value',
169 this.fontSizeRange_[this.immediateSizeIndex_]);
170 },
171
172 /**
173 * @param {number} value The intermediate slider value.
174 * @private
175 */
176 immediateMinimumSizeIndexChanged_: function(value) {
177 this.set('prefs.webkit.webprefs.minimum_font_size.value',
178 this.minimumFontSizeRange_[this.immediateMinimumSizeIndex_]);
179 },
180
181 /**
182 * @param {!Array<{0: string, 1: (string|undefined), 2: (string|undefined)}>}
183 * fontList The font menu options.
184 * @param {!Array<{0: string, 1: string}>} encodingList The encoding menu
185 * options.
186 * @private
187 */
188 setFontsData_: function(fontList, encodingList) {
189 this.$.standardFont.menuOptions = fontList;
190 this.$.serifFont.menuOptions = fontList;
191 this.$.sansSerifFont.menuOptions = fontList;
192 this.$.fixedFont.menuOptions = fontList;
193 this.$.encoding.menuOptions = encodingList;
194 },
195
196 /**
197 * @param {number} value The changed font size slider value.
198 * @private
199 */
200 fontSizeChanged_: function(value) {
201 this.defaultFontSize_ = value;
202 if (!this.$.sizeSlider.dragging) {
203 this.fontSizeIndex_ = this.fontSizeRange_.indexOf(value);
204 this.set('prefs.webkit.webprefs.default_fixed_font_size.value',
205 value - SIZE_DIFFERENCE_FIXED_STANDARD);
206 }
207 },
208
209 /**
210 * @param {number} value The changed font size slider value.
211 * @private
212 */
213 minimumFontSizeChanged_: function(value) {
214 this.minimumFontSize_ = value;
215 if (!this.$.minimumSizeSlider.dragging)
216 this.minimumSizeIndex_ = this.minimumFontSizeRange_.indexOf(value);
217 },
218
219 /**
220 * Creates an html style value.
221 * @param {number} fontSize The font size to use.
222 * @param {string} fontFamily The name of the font family use.
223 * @private
224 */
225 computeStyle_: function(fontSize, fontFamily) {
226 return 'font-size: ' + fontSize + "px; font-family: '" + fontFamily + "';";
227 },
228 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698