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 */ | |
| 14 isAdvancedMenuOpen_: { | |
| 15 type: Boolean, | |
| 16 value: false, | |
| 17 }, | |
| 18 | |
| 19 /** | 13 /** |
| 20 * Preferences state. | 14 * Preferences state. |
| 21 */ | 15 */ |
| 22 prefs: { | 16 prefs: { |
| 23 type: Object, | 17 type: Object, |
| 24 notify: true, | 18 notify: true, |
| 25 }, | 19 }, |
| 26 | 20 |
| 27 /** | 21 /** |
| 28 * The current active route. | 22 * The current active route. |
| 29 * @type {!SettingsRoute} | 23 * @type {!SettingsRoute} |
| 30 */ | 24 */ |
| 31 currentRoute: { | 25 currentRoute: { |
| 32 type: Object, | 26 type: Object, |
| 33 notify: true, | 27 notify: true, |
| 34 observer: 'currentRouteChanged_', | 28 observer: 'currentRouteChanged_', |
| 35 }, | 29 }, |
| 36 | 30 |
| 37 /** @private */ | 31 /** @private */ |
| 32 advancedToggleExpanded_: { | |
| 33 type: Boolean, | |
| 34 value: false, | |
| 35 }, | |
| 36 | |
| 37 /** @private */ | |
| 38 inSubpage_: { | |
| 39 type: Boolean, | |
| 40 computed: 'computeInSubpage_(currentRoute.subpage)', | |
| 41 }, | |
| 42 | |
| 43 /** @private */ | |
| 44 showAboutPage_: { | |
| 45 type: Boolean, | |
| 46 computed: 'computeShowAboutPage_(currentRoute.page)', | |
| 47 }, | |
| 48 | |
| 49 /** @private */ | |
| 50 showBasicPage_: { | |
| 51 type: Boolean, | |
| 52 computed: 'computeShowBasicPage_(currentRoute.page, inSubpage_)', | |
| 53 }, | |
| 54 | |
| 55 /** @private */ | |
| 38 showAdvancedPage_: { | 56 showAdvancedPage_: { |
| 39 type: Boolean, | 57 type: Boolean, |
| 40 value: false, | 58 computed: 'computeShowAdvancedPage_(' + |
| 41 }, | 59 'currentRoute.page, advancedToggleExpanded_, inSubpage_)', |
| 42 | |
| 43 /** @private */ | |
| 44 showAdvancedToggle_: { | |
| 45 type: Boolean, | |
| 46 value: true, | |
| 47 }, | |
| 48 | |
| 49 /** @private */ | |
| 50 showBasicPage_: { | |
| 51 type: Boolean, | |
| 52 value: true, | |
| 53 }, | |
| 54 | |
| 55 /** @private */ | |
| 56 showAboutPage_: { | |
| 57 type: Boolean, | |
| 58 value: false, | |
| 59 }, | 60 }, |
| 60 }, | 61 }, |
| 61 | 62 |
| 62 /** @override */ | 63 /** @override */ |
| 63 created: function() { | 64 created: function() { |
| 64 /** @private {!PromiseResolver} */ | 65 /** @private {!PromiseResolver} */ |
| 65 this.resolver_ = new PromiseResolver; | 66 this.resolver_ = new PromiseResolver; |
| 66 settings.main.rendered = this.resolver_.promise; | 67 settings.main.rendered = this.resolver_.promise; |
| 67 }, | 68 }, |
| 68 | 69 |
| 69 attached: function() { | 70 attached: function() { |
| 70 document.addEventListener('toggle-advanced-page', function(e) { | 71 document.addEventListener('toggle-advanced-page', function(e) { |
| 71 this.showAdvancedPage_ = e.detail; | 72 this.advancedToggleExpanded_ = e.detail; |
| 72 this.isAdvancedMenuOpen_ = e.detail; | |
| 73 this.currentRoute = { | 73 this.currentRoute = { |
| 74 page: this.isAdvancedMenuOpen_ ? 'advanced' : 'basic', | 74 page: this.advancedToggleExpanded_ ? 'advanced' : 'basic', |
| 75 section: '', | 75 section: '', |
| 76 subpage: [], | 76 subpage: [], |
| 77 }; | 77 }; |
| 78 if (this.showAdvancedPage_) { | 78 if (this.advancedToggleExpanded_) { |
| 79 doWhenReady( | 79 doWhenReady( |
| 80 function() { | 80 function() { |
| 81 var advancedPage = this.$$('settings-advanced-page'); | 81 var advancedPage = this.$$('settings-advanced-page'); |
| 82 return !!advancedPage && advancedPage.scrollHeight > 0; | 82 return !!advancedPage && advancedPage.scrollHeight > 0; |
| 83 }.bind(this), | 83 }.bind(this), |
| 84 function() { | 84 function() { |
| 85 this.$$('#toggleContainer').scrollIntoView(); | 85 this.$$('#toggleContainer').scrollIntoView(); |
| 86 }.bind(this)); | 86 }.bind(this)); |
| 87 } | 87 } |
| 88 }.bind(this)); | 88 }.bind(this)); |
| 89 | 89 |
| 90 doWhenReady( | 90 doWhenReady( |
| 91 function() { | 91 function() { |
| 92 var basicPage = this.$$('settings-basic-page'); | 92 var basicPage = this.$$('settings-basic-page'); |
| 93 return !!basicPage && basicPage.scrollHeight > 0; | 93 return !!basicPage && basicPage.scrollHeight > 0; |
| 94 }.bind(this), | 94 }.bind(this), |
| 95 function() { | 95 function() { |
| 96 this.resolver_.resolve(); | 96 this.resolver_.resolve(); |
| 97 }.bind(this)); | 97 }.bind(this)); |
| 98 }, | 98 }, |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * @param {boolean} opened Whether the menu is expanded. | 101 * @param {boolean} opened Whether the menu is expanded. |
| 102 * @return {string} Which icon to use. | 102 * @return {string} Which icon to use. |
| 103 * @private | 103 * @private |
| 104 * */ | 104 */ |
| 105 arrowState_: function(opened) { | 105 arrowState_: function(opened) { |
| 106 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 106 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 107 }, | 107 }, |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * @param {!SettingsRoute} newRoute | 110 * @param {!SettingsRoute} newRoute |
| 111 * @private | 111 * @private |
| 112 */ | 112 */ |
| 113 currentRouteChanged_: function(newRoute) { | 113 currentRouteChanged_: function(newRoute) { |
| 114 var isSubpage = !!newRoute.subpage.length; | 114 // If we navigated to an advanced section, ensure the toggle is opened. |
| 115 if (newRoute.page == 'advanced') | |
| 116 this.advancedToggleExpanded_ = true; | |
| 115 | 117 |
| 116 this.showAboutPage_ = newRoute.page == 'about'; | 118 this.style.height = this.inSubpage_ ? '100%' : ''; |
| 117 | |
| 118 this.showAdvancedToggle_ = !this.showAboutPage_ && !isSubpage; | |
| 119 | |
| 120 this.showBasicPage_ = this.showAdvancedToggle_ || newRoute.page == 'basic'; | |
| 121 | |
| 122 this.showAdvancedPage_ = | |
| 123 (this.isAdvancedMenuOpen_ && this.showAdvancedToggle_) || | |
| 124 newRoute.page == 'advanced'; | |
| 125 | |
| 126 this.style.height = isSubpage ? '100%' : ''; | |
| 127 }, | 119 }, |
| 128 | 120 |
| 129 /** @private */ | 121 /** @private */ |
| 130 toggleAdvancedPage_: function() { | 122 toggleAdvancedPage_: function() { |
| 131 this.fire('toggle-advanced-page', !this.isAdvancedMenuOpen_); | 123 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
| 132 }, | 124 }, |
| 133 | 125 |
| 134 /** | 126 /** |
| 135 * Navigates to the default search page (if necessary). | 127 * Navigates to the default search page (if necessary). |
| 136 * @private | 128 * @private |
| 137 */ | 129 */ |
| 138 ensureInDefaultSearchPage_: function() { | 130 ensureInDefaultSearchPage_: function() { |
| 139 if (this.currentRoute.page != 'basic' || | 131 if (this.currentRoute.page != 'basic' || |
| 140 this.currentRoute.section != '' || | 132 this.currentRoute.section != '' || |
| 141 this.currentRoute.subpage.length != 0) { | 133 this.currentRoute.subpage.length != 0) { |
| 142 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; | 134 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''}; |
| 143 } | 135 } |
| 144 }, | 136 }, |
| 145 | 137 |
| 146 /** | 138 /** |
| 147 * @param {string} query | 139 * @param {string} query |
| 148 */ | 140 */ |
| 149 searchContents: function(query) { | 141 searchContents: function(query) { |
| 150 this.ensureInDefaultSearchPage_(); | 142 this.ensureInDefaultSearchPage_(); |
| 151 | 143 |
| 152 // Trigger rendering of the basic and advanced pages and search once ready. | 144 // Trigger rendering of the basic and advanced pages and search once ready. |
| 153 // Even if those are already rendered, yield to the message loop before | 145 // Even if those are already rendered, yield to the message loop before |
| 154 // initiating searching. | 146 // initiating searching. |
| 155 this.showBasicPage_ = true; | 147 this.showBasicPage_ = true; |
|
michaelpg
2016/07/19 23:55:35
damn. I guess I can't make these computed properti
| |
| 156 setTimeout(function() { | 148 setTimeout(function() { |
| 157 settings.search(query, assert(this.$$('settings-basic-page'))); | 149 settings.search(query, assert(this.$$('settings-basic-page'))); |
| 158 }.bind(this), 0); | 150 }.bind(this), 0); |
| 159 | 151 |
| 160 this.showAdvancedPage_ = true; | 152 this.showAdvancedPage_ = true; |
| 161 setTimeout(function() { | 153 setTimeout(function() { |
| 162 settings.search(query, assert(this.$$('settings-advanced-page'))); | 154 settings.search(query, assert(this.$$('settings-advanced-page'))); |
| 163 }.bind(this), 0); | 155 }.bind(this), 0); |
| 164 }, | 156 }, |
| 157 | |
| 158 /** | |
| 159 * @return {boolean} | |
| 160 * @param {!Array<string>} subpage | |
| 161 * @private | |
| 162 */ | |
| 163 computeInSubpage_: function(subpage) { | |
| 164 return !!subpage.length; | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 168 * @param {string} page | |
| 169 * @return {boolean} | |
| 170 * @private | |
| 171 */ | |
| 172 computeShowAboutPage_: function(page) { | |
| 173 return page == 'about'; | |
| 174 }, | |
| 175 | |
| 176 /** | |
| 177 * @param {string} page | |
| 178 * @param {boolean} inSubpage | |
| 179 * @return {boolean} | |
| 180 * @private | |
| 181 */ | |
| 182 computeShowBasicPage_: function(page, inSubpage) { | |
| 183 return page == 'basic' || | |
| 184 (page == 'advanced' && !inSubpage); | |
| 185 }, | |
| 186 | |
| 187 /** | |
| 188 * @param {string} page | |
| 189 * @param {boolean} advancedToggleExpanded | |
| 190 * @param {boolean} inSubpage | |
| 191 * @return {boolean} | |
| 192 * @private | |
| 193 */ | |
| 194 computeShowAdvancedPage_: function(page, advancedToggleExpanded, inSubpage) { | |
| 195 return page == 'advanced' || | |
| 196 (page == 'basic' && advancedToggleExpanded && !inSubpage); | |
| 197 }, | |
| 165 }); | 198 }); |
| OLD | NEW |