| 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 this.browserProxy_.observeAdvancedFontExtensionAvailable(); |
| 167 |
| 155 this.browserProxy_.fetchFontsData().then( | 168 this.browserProxy_.fetchFontsData().then( |
| 156 this.setFontsData_.bind(this)); | 169 this.setFontsData_.bind(this)); |
| 157 }, | 170 }, |
| 158 | 171 |
| 159 /** | 172 /** |
| 160 * @param {number} value The intermediate slider value. | 173 * @param {number} value The intermediate slider value. |
| 161 * @private | 174 * @private |
| 162 */ | 175 */ |
| 163 immediateSizeIndexChanged_: function(value) { | 176 immediateSizeIndexChanged_: function(value) { |
| 164 this.set('prefs.webkit.webprefs.default_font_size.value', | 177 this.set('prefs.webkit.webprefs.default_font_size.value', |
| 165 this.fontSizeRange_[this.immediateSizeIndex_]); | 178 this.fontSizeRange_[this.immediateSizeIndex_]); |
| 166 }, | 179 }, |
| 167 | 180 |
| 168 /** | 181 /** |
| 169 * @param {number} value The intermediate slider value. | 182 * @param {number} value The intermediate slider value. |
| 170 * @private | 183 * @private |
| 171 */ | 184 */ |
| 172 immediateMinimumSizeIndexChanged_: function(value) { | 185 immediateMinimumSizeIndexChanged_: function(value) { |
| 173 this.set('prefs.webkit.webprefs.minimum_font_size.value', | 186 this.set('prefs.webkit.webprefs.minimum_font_size.value', |
| 174 this.minimumFontSizeRange_[this.immediateMinimumSizeIndex_]); | 187 this.minimumFontSizeRange_[this.immediateMinimumSizeIndex_]); |
| 175 }, | 188 }, |
| 176 | 189 |
| 190 /** @private */ |
| 191 openAdvancedExtension_: function() { |
| 192 if (this.advancedExtensionInstalled_) |
| 193 this.browserProxy_.openAdvancedFontSettings(); |
| 194 else |
| 195 window.open(this.advancedExtensionUrl_); |
| 196 }, |
| 197 |
| 177 /** | 198 /** |
| 178 * @param {!FontsData} response A list of fonts and encodings. | 199 * @param {boolean} isInstalled Whether the advanced font settings |
| 200 * extension is installed. |
| 201 * @private |
| 202 */ |
| 203 setAdvancedExtensionInstalled_: function(isInstalled) { |
| 204 this.advancedExtensionInstalled_ = isInstalled; |
| 205 this.advancedExtensionSublabel_ = this.i18n(isInstalled ? |
| 206 'openAdvancedFontSettings' : 'requiresWebStoreExtension'); |
| 207 }, |
| 208 |
| 209 /** |
| 210 * @param {!FontsData} response A list of fonts, encodings and the advanced |
| 211 * font settings extension URL. |
| 179 * @private | 212 * @private |
| 180 */ | 213 */ |
| 181 setFontsData_: function(response) { | 214 setFontsData_: function(response) { |
| 182 var fontMenuOptions = []; | 215 var fontMenuOptions = []; |
| 183 for (var i = 0; i < response.fontList.length; ++i) { | 216 for (var i = 0; i < response.fontList.length; ++i) { |
| 184 fontMenuOptions.push({ | 217 fontMenuOptions.push({ |
| 185 value: response.fontList[i][0], | 218 value: response.fontList[i][0], |
| 186 name: response.fontList[i][1] | 219 name: response.fontList[i][1] |
| 187 }); | 220 }); |
| 188 } | 221 } |
| 189 this.$.standardFont.menuOptions = fontMenuOptions; | 222 this.$.standardFont.menuOptions = fontMenuOptions; |
| 190 this.$.serifFont.menuOptions = fontMenuOptions; | 223 this.$.serifFont.menuOptions = fontMenuOptions; |
| 191 this.$.sansSerifFont.menuOptions = fontMenuOptions; | 224 this.$.sansSerifFont.menuOptions = fontMenuOptions; |
| 192 this.$.fixedFont.menuOptions = fontMenuOptions; | 225 this.$.fixedFont.menuOptions = fontMenuOptions; |
| 193 | 226 |
| 194 var encodingMenuOptions = []; | 227 var encodingMenuOptions = []; |
| 195 for (i = 0; i < response.encodingList.length; ++i) { | 228 for (i = 0; i < response.encodingList.length; ++i) { |
| 196 encodingMenuOptions.push({ | 229 encodingMenuOptions.push({ |
| 197 value: response.encodingList[i][0], | 230 value: response.encodingList[i][0], |
| 198 name: response.encodingList[i][1] | 231 name: response.encodingList[i][1] |
| 199 }); | 232 }); |
| 200 } | 233 } |
| 201 this.$.encoding.menuOptions = encodingMenuOptions; | 234 this.$.encoding.menuOptions = encodingMenuOptions; |
| 235 this.advancedExtensionUrl_ = response.extensionUrl; |
| 202 }, | 236 }, |
| 203 | 237 |
| 204 /** | 238 /** |
| 205 * @param {number} value The changed font size slider value. | 239 * @param {number} value The changed font size slider value. |
| 206 * @private | 240 * @private |
| 207 */ | 241 */ |
| 208 fontSizeChanged_: function(value) { | 242 fontSizeChanged_: function(value) { |
| 209 this.defaultFontSize_ = value; | 243 this.defaultFontSize_ = value; |
| 210 if (!this.$.sizeSlider.dragging) { | 244 if (!this.$.sizeSlider.dragging) { |
| 211 this.fontSizeIndex_ = this.fontSizeRange_.indexOf(value); | 245 this.fontSizeIndex_ = this.fontSizeRange_.indexOf(value); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 230 * @param {string} fontFamily The name of the font family use. | 264 * @param {string} fontFamily The name of the font family use. |
| 231 * @return {string} | 265 * @return {string} |
| 232 * @private | 266 * @private |
| 233 */ | 267 */ |
| 234 computeStyle_: function(fontSize, fontFamily) { | 268 computeStyle_: function(fontSize, fontFamily) { |
| 235 return 'font-size: ' + fontSize + "px; font-family: '" + fontFamily + | 269 return 'font-size: ' + fontSize + "px; font-family: '" + fontFamily + |
| 236 "';"; | 270 "';"; |
| 237 }, | 271 }, |
| 238 }); | 272 }); |
| 239 })(); | 273 })(); |
| OLD | NEW |