OLD | NEW |
(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 */ |
| 132 prefs: { |
| 133 type: Object, |
| 134 notify: true, |
| 135 }, |
| 136 }, |
| 137 |
| 138 /** |
| 139 * This is the absolute difference maintained between standard and |
| 140 * fixed-width font sizes. http://crbug.com/91922. |
| 141 * @const |
| 142 */ |
| 143 SIZE_DIFFERENCE_FIXED_STANDARD: 3, |
| 144 |
| 145 observers: [ |
| 146 'fontSizeChanged_(prefs.webkit.webprefs.default_font_size.value)', |
| 147 'minimumFontSizeChanged_(prefs.webkit.webprefs.minimum_font_size.value)', |
| 148 ], |
| 149 |
| 150 ready: function() { |
| 151 var self = this; |
| 152 cr.define('Settings', function() { |
| 153 return { |
| 154 setFontsData: function() { |
| 155 return self.setFontsData_.apply(self, arguments); |
| 156 }, |
| 157 }; |
| 158 }); |
| 159 chrome.send('fetchFontsData'); |
| 160 }, |
| 161 |
| 162 /** |
| 163 * @param {number} value The intermediate slider value. |
| 164 * @private |
| 165 */ |
| 166 immediateSizeIndexChanged_: function(value) { |
| 167 this.set('prefs.webkit.webprefs.default_font_size.value', |
| 168 this.fontSizeRange_[this.immediateSizeIndex_]); |
| 169 }, |
| 170 |
| 171 /** |
| 172 * @param {number} value The intermediate slider value. |
| 173 * @private |
| 174 */ |
| 175 immediateMinimumSizeIndexChanged_: function(value) { |
| 176 this.set('prefs.webkit.webprefs.minimum_font_size.value', |
| 177 this.minimumFontSizeRange_[this.immediateMinimumSizeIndex_]); |
| 178 }, |
| 179 |
| 180 /** |
| 181 * @param {!Array<{0: string, 1: (string|undefined), 2: (string|undefined)}>} |
| 182 * fontList The font menu options. |
| 183 * @param {!Array<{0: string, 1: string}>} encodingList The encoding menu |
| 184 * options. |
| 185 * @private |
| 186 */ |
| 187 setFontsData_: function(fontList, encodingList) { |
| 188 this.$.standardFont.menuOptions = fontList; |
| 189 this.$.serifFont.menuOptions = fontList; |
| 190 this.$.sansSerifFont.menuOptions = fontList; |
| 191 this.$.fixedFont.menuOptions = fontList; |
| 192 this.$.encoding.menuOptions = encodingList; |
| 193 }, |
| 194 |
| 195 /** |
| 196 * @param {number} value The changed font size slider value. |
| 197 * @private |
| 198 */ |
| 199 fontSizeChanged_: function(value) { |
| 200 this.defaultFontSize_ = value; |
| 201 if (!this.$.sizeSlider.dragging) { |
| 202 this.fontSizeIndex_ = this.fontSizeRange_.indexOf(value); |
| 203 this.set('prefs.webkit.webprefs.default_fixed_font_size.value', |
| 204 value - SIZE_DIFFERENCE_FIXED_STANDARD); |
| 205 } |
| 206 }, |
| 207 |
| 208 /** |
| 209 * @param {number} value The changed font size slider value. |
| 210 * @private |
| 211 */ |
| 212 minimumFontSizeChanged_: function(value) { |
| 213 this.minimumFontSize_ = value; |
| 214 if (!this.$.minimumSizeSlider.dragging) |
| 215 this.minimumSizeIndex_ = this.minimumFontSizeRange_.indexOf(value); |
| 216 }, |
| 217 |
| 218 /** |
| 219 * Creates an html style value. |
| 220 * @param {number} fontSize The font size to use. |
| 221 * @param {string} fontFamily The name of the font family use. |
| 222 * @private |
| 223 */ |
| 224 computeStyle_: function(fontSize, fontFamily) { |
| 225 return 'font-size: ' + fontSize + "px; font-family: '" + fontFamily + "';"; |
| 226 }, |
| 227 }); |
OLD | NEW |