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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * @fileoverview The Advanced Font Settings Extension implementation. | 8 * @fileoverview The Advanced Font Settings Extension implementation. |
9 */ | 9 */ |
10 | 10 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 advancedFonts.getEffectiveFont( | 303 advancedFonts.getEffectiveFont( |
304 advancedFonts.COMMON_SCRIPT, | 304 advancedFonts.COMMON_SCRIPT, |
305 genericFamily, | 305 genericFamily, |
306 callback.bind(null, setting.font, setting.controllable)); | 306 callback.bind(null, setting.font, setting.controllable)); |
307 }); | 307 }); |
308 }; | 308 }; |
309 | 309 |
310 /** | 310 /** |
311 * Refreshes the UI controls related to a font setting. | 311 * Refreshes the UI controls related to a font setting. |
312 * | 312 * |
313 * @param {{fontList: HTMLSelectElement, samples: Array.<HTMLElement>}} | 313 * @param {{fontList: HTMLSelectElement, samples: Array<HTMLElement>}} |
314 * fontSetting The setting object (see advancedFonts.fontSettings). | 314 * fontSetting The setting object (see advancedFonts.fontSettings). |
315 * @param {string} font The value of the font setting. | 315 * @param {string} font The value of the font setting. |
316 * @param {boolean} controllable Whether the font setting can be controlled | 316 * @param {boolean} controllable Whether the font setting can be controlled |
317 * by this extension. | 317 * by this extension. |
318 * @param {string} effectiveFont The font used, including fallback to Common | 318 * @param {string} effectiveFont The font used, including fallback to Common |
319 * script. | 319 * script. |
320 */ | 320 */ |
321 advancedFonts.refreshFont = function( | 321 advancedFonts.refreshFont = function( |
322 fontSetting, font, controllable, effectiveFont) { | 322 fontSetting, font, controllable, effectiveFont) { |
323 for (var i = 0; i < fontSetting.samples.length; ++i) | 323 for (var i = 0; i < fontSetting.samples.length; ++i) |
324 fontSetting.samples[i].style.fontFamily = effectiveFont; | 324 fontSetting.samples[i].style.fontFamily = effectiveFont; |
325 advancedFonts.setSelectedFont(fontSetting.fontList, font); | 325 advancedFonts.setSelectedFont(fontSetting.fontList, font); |
326 fontSetting.fontList.disabled = !controllable; | 326 fontSetting.fontList.disabled = !controllable; |
327 }; | 327 }; |
328 | 328 |
329 /** | 329 /** |
330 * Refreshes the UI controls related to a font size setting. | 330 * Refreshes the UI controls related to a font size setting. |
331 * | 331 * |
332 * @param {{label: HTMLElement, slider: Slider, samples: Array.<HTMLElement>}} | 332 * @param {{label: HTMLElement, slider: Slider, samples: Array<HTMLElement>}} |
333 * fontSizeSetting The setting object (see advancedFonts.fontSizeSettings). | 333 * fontSizeSetting The setting object (see advancedFonts.fontSizeSettings). |
334 * @param size The value of the font size setting. | 334 * @param size The value of the font size setting. |
335 * @param controllable Whether the setting can be controlled by this extension. | 335 * @param controllable Whether the setting can be controlled by this extension. |
336 */ | 336 */ |
337 advancedFonts.refreshFontSize = function(fontSizeSetting, size, controllable) { | 337 advancedFonts.refreshFontSize = function(fontSizeSetting, size, controllable) { |
338 fontSizeSetting.label.textContent = 'Size: ' + size + 'px'; | 338 fontSizeSetting.label.textContent = 'Size: ' + size + 'px'; |
339 advancedFonts.setFontSizeSlider(fontSizeSetting.slider, size, controllable); | 339 advancedFonts.setFontSizeSlider(fontSizeSetting.slider, size, controllable); |
340 for (var i = 0; i < fontSizeSetting.samples.length; ++i) | 340 for (var i = 0; i < fontSizeSetting.samples.length; ++i) |
341 fontSizeSetting.samples[i].style.fontSize = size + 'px'; | 341 fontSizeSetting.samples[i].style.fontSize = size + 'px'; |
342 }; | 342 }; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 /** | 384 /** |
385 * @param {HTMLSelectElement} fontList The <select> containing a list of fonts. | 385 * @param {HTMLSelectElement} fontList The <select> containing a list of fonts. |
386 * @return {string} The currently selected value of |fontList|. | 386 * @return {string} The currently selected value of |fontList|. |
387 */ | 387 */ |
388 advancedFonts.getSelectedFont = function(fontList) { | 388 advancedFonts.getSelectedFont = function(fontList) { |
389 return fontList.options[fontList.selectedIndex].value; | 389 return fontList.options[fontList.selectedIndex].value; |
390 }; | 390 }; |
391 | 391 |
392 /** | 392 /** |
393 * Populates the font lists. | 393 * Populates the font lists. |
394 * @param {Array.<{fontId: string, displayName: string>} fonts The list of | 394 * @param {Array<{fontId: string, displayName: string>} fonts The list of |
395 * fonts on the system. | 395 * fonts on the system. |
396 */ | 396 */ |
397 advancedFonts.populateFontLists = function(fonts) { | 397 advancedFonts.populateFontLists = function(fonts) { |
398 for (var genericFamily in advancedFonts.fontSettings) { | 398 for (var genericFamily in advancedFonts.fontSettings) { |
399 var list = advancedFonts.fontSettings[genericFamily].fontList; | 399 var list = advancedFonts.fontSettings[genericFamily].fontList; |
400 | 400 |
401 // Add a special item to indicate fallback to the non-per-script | 401 // Add a special item to indicate fallback to the non-per-script |
402 // font setting. The Font Settings API uses the empty string to indicate | 402 // font setting. The Font Settings API uses the empty string to indicate |
403 // fallback. | 403 // fallback. |
404 var defaultItem = document.createElement('option'); | 404 var defaultItem = document.createElement('option'); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 advancedFonts.useSystemFont(); | 759 advancedFonts.useSystemFont(); |
760 | 760 |
761 advancedFonts.initFontControls(); | 761 advancedFonts.initFontControls(); |
762 advancedFonts.initFontSizeControls(); | 762 advancedFonts.initFontSizeControls(); |
763 advancedFonts.initScriptList(); | 763 advancedFonts.initScriptList(); |
764 | 764 |
765 advancedFonts.initApplyAndResetButtons(); | 765 advancedFonts.initApplyAndResetButtons(); |
766 }; | 766 }; |
767 | 767 |
768 document.addEventListener('DOMContentLoaded', advancedFonts.init); | 768 document.addEventListener('DOMContentLoaded', advancedFonts.init); |
OLD | NEW |