Chromium Code Reviews| 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 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-main' displays the selected settings page. | 7 * 'settings-main' displays the selected settings page. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-main', | 10 is: 'settings-main', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @private */ | 13 /** @private */ |
| 14 isAdvancedMenuOpen_: { | 14 isAdvancedMenuOpen_: { |
| 15 type: Boolean, | 15 type: Boolean, |
| 16 value: false, | 16 value: false, |
| 17 }, | 17 }, |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Preferences state. | 20 * Preferences state. |
| 21 */ | 21 */ |
| 22 prefs: { | 22 prefs: { |
| 23 type: Object, | 23 type: Object, |
| 24 notify: true, | 24 notify: true, |
| 25 }, | 25 }, |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * The current active route. | 28 * The current active route. |
| 29 * @type {!SettingsRoute} | 29 * @type {!settings.Route} |
| 30 */ | 30 */ |
| 31 currentRoute: { | 31 currentRoute: { |
| 32 type: Object, | 32 type: Object, |
| 33 notify: true, | 33 notify: true, |
| 34 observer: 'currentRouteChanged_', | 34 observer: 'currentRouteChanged_', |
| 35 }, | 35 }, |
| 36 | 36 |
| 37 /** @private */ | 37 /** @private */ |
| 38 showAdvancedPage_: { | 38 showAdvancedPage_: { |
| 39 type: Boolean, | 39 type: Boolean, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 settings.getSearchManager().setCallback(function(isRunning) { | 77 settings.getSearchManager().setCallback(function(isRunning) { |
| 78 this.toolbarSpinnerActive = isRunning; | 78 this.toolbarSpinnerActive = isRunning; |
| 79 }.bind(this)); | 79 }.bind(this)); |
| 80 }, | 80 }, |
| 81 | 81 |
| 82 /** @override */ | 82 /** @override */ |
| 83 attached: function() { | 83 attached: function() { |
| 84 document.addEventListener('toggle-advanced-page', function(e) { | 84 document.addEventListener('toggle-advanced-page', function(e) { |
| 85 this.showAdvancedPage_ = e.detail; | 85 this.showAdvancedPage_ = e.detail; |
| 86 this.isAdvancedMenuOpen_ = e.detail; | 86 this.isAdvancedMenuOpen_ = e.detail; |
| 87 this.currentRoute = { | 87 settings.navigateTo(this.isAdvancedMenuOpen_ ? |
| 88 page: this.isAdvancedMenuOpen_ ? 'advanced' : 'basic', | 88 settings.Route.ADVANCED : settings.Route.BASIC); |
| 89 section: '', | |
| 90 subpage: [], | |
| 91 }; | |
| 92 }.bind(this)); | 89 }.bind(this)); |
| 93 | 90 |
| 94 doWhenReady( | 91 doWhenReady( |
| 95 function() { | 92 function() { |
| 96 var basicPage = this.$$('settings-basic-page'); | 93 var basicPage = this.$$('settings-basic-page'); |
| 97 return !!basicPage && basicPage.scrollHeight > 0; | 94 return !!basicPage && basicPage.scrollHeight > 0; |
| 98 }.bind(this), | 95 }.bind(this), |
| 99 function() { | 96 function() { |
| 100 this.resolver_.resolve(); | 97 this.resolver_.resolve(); |
| 101 }.bind(this)); | 98 }.bind(this)); |
| 102 }, | 99 }, |
| 103 | 100 |
| 104 /** | 101 /** |
| 105 * @param {boolean} opened Whether the menu is expanded. | 102 * @param {boolean} opened Whether the menu is expanded. |
| 106 * @return {string} Which icon to use. | 103 * @return {string} Which icon to use. |
| 107 * @private | 104 * @private |
| 108 * */ | 105 * */ |
| 109 arrowState_: function(opened) { | 106 arrowState_: function(opened) { |
| 110 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 107 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 111 }, | 108 }, |
| 112 | 109 |
| 113 /** | 110 /** |
| 114 * @param {!SettingsRoute} newRoute | 111 * @param {!settings.Route} newRoute |
| 115 * @private | 112 * @private |
| 116 */ | 113 */ |
| 117 currentRouteChanged_: function(newRoute) { | 114 currentRouteChanged_: function(newRoute) { |
| 118 var isSubpage = !!newRoute.subpage.length; | 115 var isSubpage = !!newRoute.subpage.length; |
| 119 | 116 |
| 120 this.showAboutPage_ = newRoute.page == 'about'; | 117 this.showAboutPage_ = newRoute.page == 'about'; |
| 121 | 118 |
| 122 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; | 119 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; |
| 123 | 120 |
| 124 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; | 121 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; |
| 125 | 122 |
| 126 this.showAdvancedPage_ = | 123 this.showAdvancedPage_ = |
| 127 (this.isAdvancedMenuOpen_ && this.showAdvancedToggle_) || | 124 (this.isAdvancedMenuOpen_ && this.showAdvancedToggle_) || |
| 128 newRoute.page == 'advanced'; | 125 newRoute.page == 'advanced'; |
| 129 | 126 |
| 130 this.style.height = isSubpage ? '100%' : ''; | 127 this.style.height = isSubpage ? '100%' : ''; |
| 131 }, | 128 }, |
| 132 | 129 |
| 133 /** @private */ | 130 /** @private */ |
| 134 toggleAdvancedPage_: function() { | 131 toggleAdvancedPage_: function() { |
| 135 this.fire('toggle-advanced-page', !this.isAdvancedMenuOpen_); | 132 this.fire('toggle-advanced-page', !this.isAdvancedMenuOpen_); |
| 136 }, | 133 }, |
| 137 | 134 |
| 138 /** | 135 /** |
| 139 * Navigates to the default search page (if necessary). | 136 * Navigates to the default search page (if necessary). |
| 140 * @private | 137 * @private |
| 141 */ | 138 */ |
| 142 ensureInDefaultSearchPage_: function() { | 139 ensureInDefaultSearchPage_: function() { |
| 143 if (this.currentRoute.page != 'basic' || | 140 if (this.currentRoute != settings.Route.BASIC) |
| 144 this.currentRoute.section != '' || | 141 settings.navigateTo(settings.Route.BASIC); |
|
Dan Beam
2016/07/23 00:17:11
nit: maybe considering putting
if (this.current
tommycli
2016/07/25 16:47:20
Done.
| |
| 145 this.currentRoute.subpage.length != 0) { | |
| 146 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; | |
| 147 } | |
| 148 }, | 142 }, |
| 149 | 143 |
| 150 /** | 144 /** |
| 151 * @param {string} query | 145 * @param {string} query |
| 152 */ | 146 */ |
| 153 searchContents: function(query) { | 147 searchContents: function(query) { |
| 154 this.ensureInDefaultSearchPage_(); | 148 this.ensureInDefaultSearchPage_(); |
| 155 | 149 |
| 156 // Trigger rendering of the basic and advanced pages and search once ready. | 150 // Trigger rendering of the basic and advanced pages and search once ready. |
| 157 // Even if those are already rendered, yield to the message loop before | 151 // Even if those are already rendered, yield to the message loop before |
| 158 // initiating searching. | 152 // initiating searching. |
| 159 this.showBasicPage_ = true; | 153 this.showBasicPage_ = true; |
| 160 setTimeout(function() { | 154 setTimeout(function() { |
| 161 settings.getSearchManager().search( | 155 settings.getSearchManager().search( |
| 162 query, assert(this.$$('settings-basic-page'))); | 156 query, assert(this.$$('settings-basic-page'))); |
| 163 }.bind(this), 0); | 157 }.bind(this), 0); |
| 164 | 158 |
| 165 this.showAdvancedPage_ = true; | 159 this.showAdvancedPage_ = true; |
| 166 setTimeout(function() { | 160 setTimeout(function() { |
| 167 settings.getSearchManager().search( | 161 settings.getSearchManager().search( |
| 168 query, assert(this.$$('settings-advanced-page'))); | 162 query, assert(this.$$('settings-advanced-page'))); |
| 169 }.bind(this), 0); | 163 }.bind(this), 0); |
| 170 }, | 164 }, |
| 171 }); | 165 }); |
| OLD | NEW |