| 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 /** | 5 /** |
| 6 * 'settings-appearance-page' is the settings page containing appearance | 6 * 'settings-appearance-page' is the settings page containing appearance |
| 7 * settings. | 7 * settings. |
| 8 * | 8 * |
| 9 * Example: | 9 * Example: |
| 10 * | 10 * |
| 11 * <iron-animated-pages> | 11 * <iron-animated-pages> |
| 12 * <settings-appearance-page prefs="{{prefs}}"> | 12 * <settings-appearance-page prefs="{{prefs}}"> |
| 13 * </settings-appearance-page> | 13 * </settings-appearance-page> |
| 14 * ... other pages ... | 14 * ... other pages ... |
| 15 * </iron-animated-pages> | 15 * </iron-animated-pages> |
| 16 */ | 16 */ |
| 17 Polymer({ | 17 Polymer({ |
| 18 is: 'settings-appearance-page', | 18 is: 'settings-appearance-page', |
| 19 | 19 |
| 20 behaviors: [I18nBehavior], | 20 behaviors: [I18nBehavior], |
| 21 | 21 |
| 22 properties: { | 22 properties: { |
| 23 /** @private {!settings.AppearanceBrowserProxy} */ | 23 /** @private {!settings.AppearanceBrowserProxy} */ |
| 24 browserProxy_: Object, | 24 browserProxy_: Object, |
| 25 | 25 |
| 26 /** | |
| 27 * Preferences state. | |
| 28 */ | |
| 29 prefs: { | 26 prefs: { |
| 30 type: Object, | 27 type: Object, |
| 31 notify: true, | 28 notify: true, |
| 32 }, | 29 }, |
| 33 | 30 |
| 34 /** | 31 /** @private */ |
| 35 * @private | 32 useSystemTheme_: { |
| 36 */ | |
| 37 allowResetTheme_: { | |
| 38 notify: true, | |
| 39 type: Boolean, | 33 type: Boolean, |
| 40 value: false, | 34 value: false, // Can only be true on Linux, but value exists everywhere. |
| 41 }, | 35 }, |
| 42 | 36 |
| 43 /** | 37 /** @private */ |
| 44 * @private | |
| 45 */ | |
| 46 defaultZoomLevel_: { | 38 defaultZoomLevel_: { |
| 47 notify: true, | 39 notify: true, |
| 48 type: Object, | 40 type: Object, |
| 49 value: function() { | 41 value: function() { |
| 50 return { | 42 return { |
| 51 type: chrome.settingsPrivate.PrefType.NUMBER, | 43 type: chrome.settingsPrivate.PrefType.NUMBER, |
| 52 }; | 44 }; |
| 53 }, | 45 }, |
| 54 }, | 46 }, |
| 55 | 47 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 themeSublabel_: String, | 95 themeSublabel_: String, |
| 104 | 96 |
| 105 /** | 97 /** |
| 106 * Dictionary defining page visibility. | 98 * Dictionary defining page visibility. |
| 107 * @type {!AppearancePageVisibility} | 99 * @type {!AppearancePageVisibility} |
| 108 */ | 100 */ |
| 109 pageVisibility: Object, | 101 pageVisibility: Object, |
| 110 }, | 102 }, |
| 111 | 103 |
| 112 observers: [ | 104 observers: [ |
| 113 'themeChanged_(prefs.extensions.theme.id.value)', | 105 'themeChanged_(prefs.extensions.theme.id.value, useSystemTheme_)', |
| 106 |
| 107 <if expr="is_linux and not chromeos"> |
| 108 // NOTE: this pref only exists on Linux. |
| 109 'useSystemThemePrefChanged_(prefs.extensions.theme.use_system.value)', |
| 110 </if> |
| 111 |
| 114 'zoomLevelChanged_(defaultZoomLevel_.value)', | 112 'zoomLevelChanged_(defaultZoomLevel_.value)', |
| 115 ], | 113 ], |
| 116 | 114 |
| 117 created: function() { | 115 created: function() { |
| 118 this.browserProxy_ = settings.AppearanceBrowserProxyImpl.getInstance(); | 116 this.browserProxy_ = settings.AppearanceBrowserProxyImpl.getInstance(); |
| 119 }, | 117 }, |
| 120 | 118 |
| 121 ready: function() { | 119 ready: function() { |
| 122 this.$.defaultFontSize.menuOptions = this.fontSizeOptions_; | 120 this.$.defaultFontSize.menuOptions = this.fontSizeOptions_; |
| 123 this.$.pageZoom.menuOptions = this.pageZoomOptions_; | 121 this.$.pageZoom.menuOptions = this.pageZoomOptions_; |
| 124 // TODO(dschuyler): Look into adding a listener for the | 122 // TODO(dschuyler): Look into adding a listener for the |
| 125 // default zoom percent. | 123 // default zoom percent. |
| 126 chrome.settingsPrivate.getDefaultZoomPercent( | 124 chrome.settingsPrivate.getDefaultZoomPercent( |
| 127 this.zoomPrefChanged_.bind(this)); | 125 this.zoomPrefChanged_.bind(this)); |
| 128 }, | 126 }, |
| 129 | 127 |
| 130 /** @override */ | |
| 131 attached: function() { | |
| 132 // Query the initial state. | |
| 133 this.browserProxy_.getResetThemeEnabled().then( | |
| 134 this.setResetThemeEnabled.bind(this)); | |
| 135 | |
| 136 // Set up the change event listener. | |
| 137 cr.addWebUIListener('reset-theme-enabled-changed', | |
| 138 this.setResetThemeEnabled.bind(this)); | |
| 139 }, | |
| 140 | |
| 141 /** | 128 /** |
| 142 * @param {boolean} isNtp Whether to use the NTP as the home page. | 129 * @param {boolean} isNtp Whether to use the NTP as the home page. |
| 143 * @param {string} homepage If not using NTP, use this URL. | 130 * @param {string} homepage If not using NTP, use this URL. |
| 144 * @return {string} The sub-label. | 131 * @return {string} The sub-label. |
| 145 * @private | 132 * @private |
| 146 */ | 133 */ |
| 147 getShowHomeSubLabel_: function(isNtp, homepage) { | 134 getShowHomeSubLabel_: function(isNtp, homepage) { |
| 148 if (isNtp) | 135 if (isNtp) |
| 149 return this.i18n('homePageNtp'); | 136 return this.i18n('homePageNtp'); |
| 150 return homepage || this.i18n('exampleDotCom'); | 137 return homepage || this.i18n('exampleDotCom'); |
| 151 }, | 138 }, |
| 152 | 139 |
| 153 /** | |
| 154 * @param {boolean} enabled Whether the theme reset is available. | |
| 155 */ | |
| 156 setResetThemeEnabled: function(enabled) { | |
| 157 this.allowResetTheme_ = enabled; | |
| 158 }, | |
| 159 | |
| 160 /** @private */ | 140 /** @private */ |
| 161 onCustomizeFontsTap_: function() { | 141 onCustomizeFontsTap_: function() { |
| 162 settings.navigateTo(settings.Route.FONTS); | 142 settings.navigateTo(settings.Route.FONTS); |
| 163 }, | 143 }, |
| 164 | 144 |
| 165 /** @private */ | 145 /** @private */ |
| 166 openThemesGallery_: function() { | 146 openThemesGallery_: function() { |
| 147 // TODO(dbeam): open the theme detail page when a custom theme is installed |
| 148 // (or otherwise handle the [//] open in new icon in a better way). |
| 167 window.open(loadTimeData.getString('themesGalleryUrl')); | 149 window.open(loadTimeData.getString('themesGalleryUrl')); |
| 168 }, | 150 }, |
| 169 | 151 |
| 170 <if expr="chromeos"> | 152 <if expr="chromeos"> |
| 171 /** | 153 /** |
| 172 * ChromeOS only. | 154 * ChromeOS only. |
| 173 * @private | 155 * @private |
| 174 */ | 156 */ |
| 175 openWallpaperManager_: function() { | 157 openWallpaperManager_: function() { |
| 176 this.browserProxy_.openWallpaperManager(); | 158 this.browserProxy_.openWallpaperManager(); |
| 177 }, | 159 }, |
| 178 </if> | 160 </if> |
| 179 | 161 |
| 180 /** @private */ | 162 /** @private */ |
| 181 resetTheme_: function() { | 163 onUseDefaultTap_: function() { |
| 182 this.browserProxy_.resetTheme(); | 164 this.browserProxy_.useDefaultTheme(); |
| 165 }, |
| 166 |
| 167 <if expr="is_linux and not chromeos"> |
| 168 /** |
| 169 * @param {boolean} useSystemTheme |
| 170 * @private |
| 171 */ |
| 172 useSystemThemePrefChanged_: function(useSystemTheme) { |
| 173 this.useSystemTheme_ = useSystemTheme; |
| 183 }, | 174 }, |
| 184 | 175 |
| 185 /** | 176 /** |
| 186 * @param {string} themeId The theme ID. | 177 * @param {string} themeId |
| 178 * @param {boolean} useSystemTheme |
| 179 * @return {boolean} Whether to show the "USE CLASSIC" button. |
| 187 * @private | 180 * @private |
| 188 */ | 181 */ |
| 189 themeChanged_: function(themeId) { | 182 showUseClassic_: function(themeId, useSystemTheme) { |
| 190 if (themeId) { | 183 return !!themeId || useSystemTheme; |
| 191 chrome.management.get(themeId, | |
| 192 function(info) { | |
| 193 this.themeSublabel_ = info.name; | |
| 194 }.bind(this)); | |
| 195 } else { | |
| 196 this.themeSublabel_ = this.i18n('chooseFromWebStore'); | |
| 197 } | |
| 198 }, | 184 }, |
| 199 | 185 |
| 200 /** | 186 /** |
| 187 * @param {string} themeId |
| 188 * @param {boolean} useSystemTheme |
| 189 * @return {boolean} Whether to show the "USE GTK+" button. |
| 190 * @private |
| 191 */ |
| 192 showUseSystem_: function(themeId, useSystemTheme) { |
| 193 return !!themeId || !useSystemTheme; |
| 194 }, |
| 195 |
| 196 /** @private */ |
| 197 onUseSystemTap_: function() { |
| 198 this.browserProxy_.useSystemTheme(); |
| 199 }, |
| 200 </if> |
| 201 |
| 202 /** |
| 203 * @param {string} themeId |
| 204 * @param {boolean} useSystemTheme |
| 205 * @private |
| 206 */ |
| 207 themeChanged_: function(themeId, useSystemTheme) { |
| 208 if (themeId) { |
| 209 assert(!useSystemTheme); |
| 210 this.browserProxy_.getThemeInfo(themeId).then(function(info) { |
| 211 this.themeSublabel_ = info.name; |
| 212 }.bind(this)); |
| 213 return; |
| 214 } |
| 215 |
| 216 var i18nId; |
| 217 <if expr="is_linux and not chromeos"> |
| 218 i18nId = useSystemTheme ? 'systemTheme' : 'classicTheme'; |
| 219 </if> |
| 220 <if expr="not is_linux or chromeos"> |
| 221 i18nId = 'chooseFromWebStore'; |
| 222 </if> |
| 223 this.themeSublabel_ = this.i18n(i18nId); |
| 224 }, |
| 225 |
| 226 /** |
| 201 * @param {number} percent The integer percentage of the page zoom. | 227 * @param {number} percent The integer percentage of the page zoom. |
| 202 * @private | 228 * @private |
| 203 */ | 229 */ |
| 204 zoomPrefChanged_: function(percent) { | 230 zoomPrefChanged_: function(percent) { |
| 205 this.set('defaultZoomLevel_.value', percent); | 231 this.set('defaultZoomLevel_.value', percent); |
| 206 }, | 232 }, |
| 207 | 233 |
| 208 /** | 234 /** |
| 209 * @param {number} percent The integer percentage of the page zoom. | 235 * @param {number} percent The integer percentage of the page zoom. |
| 210 * @private | 236 * @private |
| 211 */ | 237 */ |
| 212 zoomLevelChanged_: function(percent) { | 238 zoomLevelChanged_: function(percent) { |
| 213 // The |percent| may be undefined on startup. | 239 // The |percent| may be undefined on startup. |
| 214 if (percent === undefined) | 240 if (percent === undefined) |
| 215 return; | 241 return; |
| 216 chrome.settingsPrivate.setDefaultZoomPercent(percent); | 242 chrome.settingsPrivate.setDefaultZoomPercent(percent); |
| 217 }, | 243 }, |
| 218 | 244 |
| 219 /** | 245 /** |
| 220 * @param {boolean} bookmarksBarVisible if bookmarks bar option is visible. | 246 * @param {boolean} bookmarksBarVisible if bookmarks bar option is visible. |
| 221 * @return {string} 'first' if the argument is false or empty otherwise. | 247 * @return {string} 'first' if the argument is false or empty otherwise. |
| 222 * @private | 248 * @private |
| 223 */ | 249 */ |
| 224 getFirst_: function(bookmarksBarVisible) { | 250 getFirst_: function(bookmarksBarVisible) { |
| 225 return !bookmarksBarVisible ? 'first' : ''; | 251 return !bookmarksBarVisible ? 'first' : ''; |
| 226 } | 252 } |
| 227 }); | 253 }); |
| OLD | NEW |