OLD | NEW |
---|---|
1 // Copyright (c) 2010 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 |
11 * Encapsulated handling of the 'Font Settings' page. | 11 * Encapsulated handling of the 'Fonts and Encoding' page. |
12 * @class | 12 * @class |
13 */ | 13 */ |
14 function FontSettings() { | 14 function FontSettings() { |
15 OptionsPage.call(this, | 15 OptionsPage.call(this, |
16 'fontSettings', | 16 'fontSettings', |
17 templateData.fontSettingsTitle, | 17 templateData.fontSettingsTitle, |
18 'font-settings'); | 18 'font-settings'); |
19 } | 19 } |
20 | 20 |
21 cr.addSingletonGetter(FontSettings); | 21 cr.addSingletonGetter(FontSettings); |
22 | 22 |
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 // Call base class implementation to starts preference initialization. | |
31 OptionsPage.prototype.initializePage.call(this); | 30 OptionsPage.prototype.initializePage.call(this); |
32 } | 31 |
32 var serifFontRange = $('serif-font-size'); | |
33 serifFontRange.valueMap = $('fixed-font-size').valueMap = new Array( | |
arv (Not doing code reviews)
2011/01/11 21:50:35
Use an array literal instead.
[9, 10, ...]
James Hawkins
2011/01/11 23:45:54
Done.
| |
34 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, | |
35 36, 40, 44, 48, 56, 64, 72); | |
36 serifFontRange.continuous = false; | |
37 serifFontRange.fontSampleEl = $('serif-font-sample'); | |
38 serifFontRange.notifyChange = this.rangeChanged_.bind(this); | |
39 | |
40 var minimumFontRange = $('minimum-font-size'); | |
41 minimumFontRange.valueMap = new Array( | |
42 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24); | |
43 minimumFontRange.continuous = false; | |
44 minimumFontRange.fontSampleEl = $('minimum-font-sample'); | |
45 minimumFontRange.notifyChange = this.rangeChanged_.bind(this); | |
46 }, | |
47 | |
48 /** | |
49 * @inheritDoc | |
50 */ | |
51 rangeChanged_: function(el, value) { | |
52 this.setupFontSample_( | |
53 el.fontSampleEl, value, el.fontSampleEl.style.fontFamily); | |
54 }, | |
55 | |
56 /** | |
57 * Sets the text, font size and font family of the sample text. | |
58 * @param {Element} el The div containing the sample text. | |
59 * @param {Integer} size The font size of the sample text. | |
arv (Not doing code reviews)
2011/01/11 21:50:35
@param {number}
James Hawkins
2011/01/11 23:45:54
Done.
| |
60 * @param {String} font The font family of the sample text. | |
arv (Not doing code reviews)
2011/01/11 21:50:35
@param {string}
James Hawkins
2011/01/11 23:45:54
Done.
| |
61 * @private | |
62 */ | |
63 setupFontSample_: function(el, size, font) { | |
64 el.textContent = size + "pt: " + templateData.fontSettingsLoremIpsum; | |
arv (Not doing code reviews)
2011/01/11 21:50:35
localStrings.getString for consistency
James Hawkins
2011/01/11 23:45:54
Done.
| |
65 el.style.fontSize = size + "pt"; | |
66 if (font) | |
67 el.style.fontFamily = font; | |
68 }, | |
33 }; | 69 }; |
34 | 70 |
35 FontSettings.setupFontPreview = function(id, font, size) { | 71 // Chrome callbacks |
36 $(id).textContent = font + " " + size; | 72 FontSettings.setupSerifFontSample = function(font, size) { |
37 $(id).style.fontFamily = font; | 73 FontSettings.getInstance().setupFontSample_( |
38 $(id).style.fontSize = size + "pt"; | 74 $('serif-font-sample'), size, font); |
39 } | 75 }; |
40 | 76 |
41 // Chrome callbacks | 77 FontSettings.setupFixedFontSample = function(font, size) { |
42 FontSettings.setupSerifFontPreview = function(text, size) { | 78 FontSettings.getInstance().setupFontSample_( |
43 this.setupFontPreview('fontSettingsSerifPreview', text, size); | 79 $('fixed-font-sample'), size, font); |
44 } | 80 }; |
45 | 81 |
46 FontSettings.setupSansSerifFontPreview = function(text, size) { | 82 FontSettings.setupMinimumFontSample = function(size) { |
47 this.setupFontPreview('fontSettingsSansSerifPreview', text, size); | 83 FontSettings.getInstance().setupFontSample_( |
48 } | 84 $('minimum-font-sample'), size); |
49 | 85 }; |
50 FontSettings.setupFixedFontPreview = function(text, size) { | |
51 this.setupFontPreview('fontSettingsFixedWidthPreview', text, size); | |
52 } | |
53 | 86 |
54 // Export | 87 // Export |
55 return { | 88 return { |
56 FontSettings: FontSettings | 89 FontSettings: FontSettings |
57 }; | 90 }; |
58 | |
59 }); | 91 }); |
60 | 92 |
OLD | NEW |