Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: chrome/browser/resources/settings/settings_main/settings_main.js

Issue 2156413002: Settings Router Refactor: Migrate to settings.Route.navigateTo calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use timing fix Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /** 13 /**
14 * Preferences state. 14 * Preferences state.
15 */ 15 */
16 prefs: { 16 prefs: {
17 type: Object, 17 type: Object,
18 notify: true, 18 notify: true,
19 }, 19 },
20 20
21 /** 21 /**
22 * The current active route. 22 * The current active route.
23 * @type {!SettingsRoute} 23 * @type {!settings.Route}
24 */ 24 */
25 currentRoute: { 25 currentRoute: {
26 type: Object, 26 type: Object,
27 notify: true, 27 notify: true,
28 observer: 'currentRouteChanged_', 28 observer: 'currentRouteChanged_',
29 }, 29 },
30 30
31 /** @private */ 31 /** @private */
32 advancedToggleExpanded_: { 32 advancedToggleExpanded_: {
33 type: Boolean, 33 type: Boolean,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 created: function() { 75 created: function() {
76 /** @private {!PromiseResolver} */ 76 /** @private {!PromiseResolver} */
77 this.resolver_ = new PromiseResolver; 77 this.resolver_ = new PromiseResolver;
78 settings.main.rendered = this.resolver_.promise; 78 settings.main.rendered = this.resolver_.promise;
79 }, 79 },
80 80
81 /** @override */ 81 /** @override */
82 attached: function() { 82 attached: function() {
83 document.addEventListener('toggle-advanced-page', function(e) { 83 document.addEventListener('toggle-advanced-page', function(e) {
84 this.advancedToggleExpanded_ = e.detail; 84 this.advancedToggleExpanded_ = e.detail;
85 this.currentRoute = { 85 settings.navigateTo(this.advancedToggleExpanded_ ?
86 page: this.advancedToggleExpanded_ ? 'advanced' : 'basic', 86 settings.Route.ADVANCED : settings.Route.BASIC);
87 section: '',
88 subpage: [],
89 };
90 }.bind(this)); 87 }.bind(this));
91 88
92 doWhenReady( 89 doWhenReady(
93 function() { 90 function() {
94 var basicPage = this.$$('settings-basic-page'); 91 var basicPage = this.$$('settings-basic-page');
95 return !!basicPage && basicPage.scrollHeight > 0; 92 return !!basicPage && basicPage.scrollHeight > 0;
96 }.bind(this), 93 }.bind(this),
97 function() { 94 function() {
98 this.resolver_.resolve(); 95 this.resolver_.resolve();
99 }.bind(this)); 96 }.bind(this));
(...skipping 12 matching lines...) Expand all
112 * @param {boolean} showBasicPage 109 * @param {boolean} showBasicPage
113 * @param {boolean} inSubpage 110 * @param {boolean} inSubpage
114 * @return {boolean} 111 * @return {boolean}
115 * @private 112 * @private
116 */ 113 */
117 showAdvancedToggle_: function(showBasicPage, inSubpage) { 114 showAdvancedToggle_: function(showBasicPage, inSubpage) {
118 return showBasicPage && !inSubpage; 115 return showBasicPage && !inSubpage;
119 }, 116 },
120 117
121 /** 118 /**
122 * @param {!SettingsRoute} newRoute
123 * @private 119 * @private
124 */ 120 */
125 currentRouteChanged_: function(newRoute) { 121 currentRouteChanged_: function(newRoute) {
126 this.inSubpage_ = newRoute.subpage.length > 0; 122 this.inSubpage_ = newRoute.subpage.length > 0;
127 this.style.height = this.inSubpage_ ? '100%' : ''; 123 this.style.height = this.inSubpage_ ? '100%' : '';
128 124
129 if (newRoute.page == 'about') { 125 if (newRoute.page == 'about') {
130 this.showPages_ = {about: true, basic: false, advanced: false}; 126 this.showPages_ = {about: true, basic: false, advanced: false};
131 } else { 127 } else {
132 this.showPages_ = { 128 this.showPages_ = {
133 about: false, 129 about: false,
134 basic: newRoute.page == 'basic' || !this.inSubpage_, 130 basic: newRoute.page == 'basic' || !this.inSubpage_,
135 advanced: newRoute.page == 'advanced' || 131 advanced: newRoute.page == 'advanced' ||
136 (!this.inSubpage_ && this.advancedToggleExpanded_), 132 (!this.inSubpage_ && this.advancedToggleExpanded_),
137 }; 133 };
138 134
139 if (this.showPages_.advanced) { 135 if (this.showPages_.advanced) {
140 assert(!this.pageVisibility || 136 assert(!this.pageVisibility ||
141 this.pageVisibility.advancedSettings !== false); 137 this.pageVisibility.advancedSettings !== false);
142 this.advancedToggleExpanded_ = true; 138 this.advancedToggleExpanded_ = true;
143 } 139 }
144 } 140 }
145 141
146 // Wait for any other changes prior to calculating the overflow padding. 142 // Wait for any other changes prior to calculating the overflow padding.
147 this.async(function() { 143 setTimeout(function() {
148 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px'; 144 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px';
149 }); 145 }.bind(this));
150 }, 146 },
151 147
152 /** 148 /**
153 * Return the height that the over scroll padding should be set to. 149 * Return the height that the over scroll padding should be set to.
154 * This is used to determine how much padding to apply to the end of the 150 * This is used to determine how much padding to apply to the end of the
155 * content so that the last element may align with the top of the content 151 * content so that the last element may align with the top of the content
156 * area. 152 * area.
157 * @return {number} 153 * @return {number}
158 * @private 154 * @private
159 */ 155 */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 /** @private */ 197 /** @private */
202 toggleAdvancedPage_: function() { 198 toggleAdvancedPage_: function() {
203 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); 199 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_);
204 }, 200 },
205 201
206 /** 202 /**
207 * Navigates to the default search page (if necessary). 203 * Navigates to the default search page (if necessary).
208 * @private 204 * @private
209 */ 205 */
210 ensureInDefaultSearchPage_: function() { 206 ensureInDefaultSearchPage_: function() {
211 if (this.currentRoute.page != 'basic' || 207 settings.navigateTo(settings.Route.BASIC);
212 this.currentRoute.section != '' ||
213 this.currentRoute.subpage.length != 0) {
214 this.currentRoute = {page: 'basic', section: '', subpage: [], url: ''};
215 }
216 }, 208 },
217 209
218 /** 210 /**
219 * @param {string} query 211 * @param {string} query
220 */ 212 */
221 searchContents: function(query) { 213 searchContents: function(query) {
222 this.ensureInDefaultSearchPage_(); 214 this.ensureInDefaultSearchPage_();
223 this.toolbarSpinnerActive = true; 215 this.toolbarSpinnerActive = true;
224 216
225 // Trigger rendering of the basic and advanced pages and search once ready. 217 // Trigger rendering of the basic and advanced pages and search once ready.
(...skipping 23 matching lines...) Expand all
249 241
250 /** 242 /**
251 * @param {(boolean|undefined)} visibility 243 * @param {(boolean|undefined)} visibility
252 * @return {boolean} True unless visibility is false. 244 * @return {boolean} True unless visibility is false.
253 * @private 245 * @private
254 */ 246 */
255 showAdvancedSettings_: function(visibility) { 247 showAdvancedSettings_: function(visibility) {
256 return visibility !== false; 248 return visibility !== false;
257 }, 249 },
258 }); 250 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698