| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 (function() { | 5 (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * This is the absolute difference maintained between standard and | 9 * This is the absolute difference maintained between standard and |
| 10 * fixed-width font sizes. http://crbug.com/91922. | 10 * fixed-width font sizes. http://crbug.com/91922. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * settings. | 28 * settings. |
| 29 * | 29 * |
| 30 * Example: | 30 * Example: |
| 31 * | 31 * |
| 32 * <settings-appearance-fonts-page prefs="{{prefs}}"> | 32 * <settings-appearance-fonts-page prefs="{{prefs}}"> |
| 33 * </settings-appearance-fonts-page> | 33 * </settings-appearance-fonts-page> |
| 34 */ | 34 */ |
| 35 Polymer({ | 35 Polymer({ |
| 36 is: 'settings-appearance-fonts-page', | 36 is: 'settings-appearance-fonts-page', |
| 37 | 37 |
| 38 behaviors: [I18nBehavior], | 38 behaviors: [I18nBehavior, WebUIListenerBehavior], |
| 39 | 39 |
| 40 properties: { | 40 properties: { |
| 41 /** @private */ |
| 42 advancedExtensionInstalled_: Boolean, |
| 43 |
| 44 /** @private */ |
| 45 advancedExtensionSublabel_: String, |
| 46 |
| 47 /** @private */ |
| 48 advancedExtensionUrl_: String, |
| 49 |
| 41 /** @private {!settings.FontsBrowserProxy} */ | 50 /** @private {!settings.FontsBrowserProxy} */ |
| 42 browserProxy_: Object, | 51 browserProxy_: Object, |
| 43 | 52 |
| 44 /** | 53 /** |
| 45 * The font size used by default. | 54 * The font size used by default. |
| 46 * @private | 55 * @private |
| 47 */ | 56 */ |
| 48 defaultFontSize_: { | 57 defaultFontSize_: { |
| 49 type: Number, | 58 type: Number, |
| 50 }, | 59 }, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 'minimumFontSizeChanged_(prefs.webkit.webprefs.minimum_font_size.value)', | 154 'minimumFontSizeChanged_(prefs.webkit.webprefs.minimum_font_size.value)', |
| 146 ], | 155 ], |
| 147 | 156 |
| 148 /** @override */ | 157 /** @override */ |
| 149 created: function() { | 158 created: function() { |
| 150 this.browserProxy_ = settings.FontsBrowserProxyImpl.getInstance(); | 159 this.browserProxy_ = settings.FontsBrowserProxyImpl.getInstance(); |
| 151 }, | 160 }, |
| 152 | 161 |
| 153 /** @override */ | 162 /** @override */ |
| 154 ready: function() { | 163 ready: function() { |
| 164 this.addWebUIListener('advanced-font-settings-installed', |
| 165 this.setAdvancedExtensionInstalled_.bind(this)); |
| 166 |
| 155 this.browserProxy_.fetchFontsData().then( | 167 this.browserProxy_.fetchFontsData().then( |
| 156 this.setFontsData_.bind(this)); | 168 this.setFontsData_.bind(this)); |
| 157 }, | 169 }, |
| 158 | 170 |
| 159 /** | 171 /** |
| 160 * @param {number} value The intermediate slider value. | 172 * @param {number} value The intermediate slider value. |
| 161 * @private | 173 * @private |
| 162 */ | 174 */ |
| 163 immediateSizeIndexChanged_: function(value) { | 175 immediateSizeIndexChanged_: function(value) { |
| 164 this.set('prefs.webkit.webprefs.default_font_size.value', | 176 this.set('prefs.webkit.webprefs.default_font_size.value', |
| 165 this.fontSizeRange_[this.immediateSizeIndex_]); | 177 this.fontSizeRange_[this.immediateSizeIndex_]); |
| 166 }, | 178 }, |
| 167 | 179 |
| 168 /** | 180 /** |
| 169 * @param {number} value The intermediate slider value. | 181 * @param {number} value The intermediate slider value. |
| 170 * @private | 182 * @private |
| 171 */ | 183 */ |
| 172 immediateMinimumSizeIndexChanged_: function(value) { | 184 immediateMinimumSizeIndexChanged_: function(value) { |
| 173 this.set('prefs.webkit.webprefs.minimum_font_size.value', | 185 this.set('prefs.webkit.webprefs.minimum_font_size.value', |
| 174 this.minimumFontSizeRange_[this.immediateMinimumSizeIndex_]); | 186 this.minimumFontSizeRange_[this.immediateMinimumSizeIndex_]); |
| 175 }, | 187 }, |
| 176 | 188 |
| 189 /** @private */ |
| 190 openAdvancedExtension_: function() { |
| 191 if (this.advancedExtensionInstalled_) |
| 192 this.browserProxy_.openAdvancedFontSettings(); |
| 193 else |
| 194 window.open(this.advancedExtensionUrl_); |
| 195 }, |
| 196 |
| 177 /** | 197 /** |
| 178 * @param {!FontsData} response A list of fonts and encodings. | 198 * @param {boolean} isInstalled Whether the advanced font settings |
| 199 * extension is installed. |
| 200 * @private |
| 201 */ |
| 202 setAdvancedExtensionInstalled_: function(isInstalled) { |
| 203 this.advancedExtensionInstalled_ = isInstalled; |
| 204 this.advancedExtensionSublabel_ = this.i18n(isInstalled ? |
| 205 'openAdvancedFontSettings' : 'requiresWebStoreExtension'); |
| 206 }, |
| 207 |
| 208 /** |
| 209 * @param {!FontsData} response A list of fonts, encodings and the advanced |
| 210 * font settings extension URL. |
| 179 * @private | 211 * @private |
| 180 */ | 212 */ |
| 181 setFontsData_: function(response) { | 213 setFontsData_: function(response) { |
| 182 var fontMenuOptions = []; | 214 var fontMenuOptions = []; |
| 183 for (var i = 0; i < response.fontList.length; ++i) { | 215 for (var i = 0; i < response.fontList.length; ++i) { |
| 184 fontMenuOptions.push({ | 216 fontMenuOptions.push({ |
| 185 value: response.fontList[i][0], | 217 value: response.fontList[i][0], |
| 186 name: response.fontList[i][1] | 218 name: response.fontList[i][1] |
| 187 }); | 219 }); |
| 188 } | 220 } |
| 189 this.$.standardFont.menuOptions = fontMenuOptions; | 221 this.$.standardFont.menuOptions = fontMenuOptions; |
| 190 this.$.serifFont.menuOptions = fontMenuOptions; | 222 this.$.serifFont.menuOptions = fontMenuOptions; |
| 191 this.$.sansSerifFont.menuOptions = fontMenuOptions; | 223 this.$.sansSerifFont.menuOptions = fontMenuOptions; |
| 192 this.$.fixedFont.menuOptions = fontMenuOptions; | 224 this.$.fixedFont.menuOptions = fontMenuOptions; |
| 193 | 225 |
| 194 var encodingMenuOptions = []; | 226 var encodingMenuOptions = []; |
| 195 for (i = 0; i < response.encodingList.length; ++i) { | 227 for (i = 0; i < response.encodingList.length; ++i) { |
| 196 encodingMenuOptions.push({ | 228 encodingMenuOptions.push({ |
| 197 value: response.encodingList[i][0], | 229 value: response.encodingList[i][0], |
| 198 name: response.encodingList[i][1] | 230 name: response.encodingList[i][1] |
| 199 }); | 231 }); |
| 200 } | 232 } |
| 201 this.$.encoding.menuOptions = encodingMenuOptions; | 233 this.$.encoding.menuOptions = encodingMenuOptions; |
| 234 this.advancedExtensionUrl_ = response.extensionUrl; |
| 202 }, | 235 }, |
| 203 | 236 |
| 204 /** | 237 /** |
| 205 * @param {number} value The changed font size slider value. | 238 * @param {number} value The changed font size slider value. |
| 206 * @private | 239 * @private |
| 207 */ | 240 */ |
| 208 fontSizeChanged_: function(value) { | 241 fontSizeChanged_: function(value) { |
| 209 this.defaultFontSize_ = value; | 242 this.defaultFontSize_ = value; |
| 210 if (!this.$.sizeSlider.dragging) { | 243 if (!this.$.sizeSlider.dragging) { |
| 211 this.fontSizeIndex_ = this.fontSizeRange_.indexOf(value); | 244 this.fontSizeIndex_ = this.fontSizeRange_.indexOf(value); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 230 * @param {string} fontFamily The name of the font family use. | 263 * @param {string} fontFamily The name of the font family use. |
| 231 * @return {string} | 264 * @return {string} |
| 232 * @private | 265 * @private |
| 233 */ | 266 */ |
| 234 computeStyle_: function(fontSize, fontFamily) { | 267 computeStyle_: function(fontSize, fontFamily) { |
| 235 return 'font-size: ' + fontSize + "px; font-family: '" + fontFamily + | 268 return 'font-size: ' + fontSize + "px; font-family: '" + fontFamily + |
| 236 "';"; | 269 "';"; |
| 237 }, | 270 }, |
| 238 }); | 271 }); |
| 239 })(); | 272 })(); |
| OLD | NEW |