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

Side by Side Diff: chrome/browser/resources/settings/settings_page/main_page_behavior.js

Issue 2825203003: MD Settings: Remove subpage animation when landing directly on it. (Closed)
Patch Set: feedback Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 * Responds to route changes by expanding, collapsing, or scrolling to sections 6 * Responds to route changes by expanding, collapsing, or scrolling to sections
7 * on the page. Expanded sections take up the full height of the container. At 7 * on the page. Expanded sections take up the full height of the container. At
8 * most one section should be expanded at any given time. 8 * most one section should be expanded at any given time.
9 * @polymerBehavior MainPageBehavior 9 * @polymerBehavior MainPageBehavior
10 */ 10 */
(...skipping 12 matching lines...) Expand all
23 /** 23 /**
24 * Whether a search operation is in progress or previous search results are 24 * Whether a search operation is in progress or previous search results are
25 * being displayed. 25 * being displayed.
26 * @private {boolean} 26 * @private {boolean}
27 */ 27 */
28 inSearchMode: { 28 inSearchMode: {
29 type: Boolean, 29 type: Boolean,
30 value: false, 30 value: false,
31 observer: 'inSearchModeChanged_', 31 observer: 'inSearchModeChanged_',
32 }, 32 },
33
34 // Controls to show or hide parent container during loading state.
michaelpg 2017/04/27 20:00:20 nit: "Whether to hide parent container..."
scottchen 2017/05/01 19:25:07 Done.
35 shouldHideContainer: {
36 type: Boolean,
37 value: false,
38 notify: true
39 },
33 }, 40 },
34 41
35 /** @type {?HTMLElement} The scrolling container. */ 42 /** @type {?HTMLElement} The scrolling container. */
36 scroller: null, 43 scroller: null,
37 44
38 listeners: { 45 listeners: {'neon-animation-finish': 'onNeonAnimationFinish_'},
39 'neon-animation-finish': 'onNeonAnimationFinish_'
40 },
41 46
42 /** @override */ 47 /** @override */
43 attached: function() { 48 attached: function() {
44 this.scroller = this.domHost ? this.domHost.parentNode : document.body; 49 this.scroller = this.domHost ? this.domHost.parentNode : document.body;
45 }, 50 },
46 51
47 /** 52 /**
48 * Remove the is-animating attribute once the animation is complete. 53 * Remove the is-animating attribute once the animation is complete.
49 * This may catch animations finishing more often than needed, which is not 54 * This may catch animations finishing more often than needed, which is not
50 * known to cause any issues (e.g. when animating from a shallower page to a 55 * known to cause any issues (e.g. when animating from a shallower page to a
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 92
88 // TODO(dschuyler): This doesn't set the flag in the case of going to or 93 // TODO(dschuyler): This doesn't set the flag in the case of going to or
89 // from the main page. It seems sensible to set the flag in those cases, 94 // from the main page. It seems sensible to set the flag in those cases,
90 // unfortunately bug 708465 happens. Figure out why that is and then set 95 // unfortunately bug 708465 happens. Figure out why that is and then set
91 // this flag more broadly. 96 // this flag more broadly.
92 if (oldRoute && oldRoute.isSubpage() && newRoute.isSubpage()) 97 if (oldRoute && oldRoute.isSubpage() && newRoute.isSubpage())
93 this.isSubpageAnimating = true; 98 this.isSubpageAnimating = true;
94 99
95 // For previously uncreated pages (including on first load), allow the page 100 // For previously uncreated pages (including on first load), allow the page
96 // to render before scrolling to or expanding the section. 101 // to render before scrolling to or expanding the section.
97 if (!oldRoute || this.scrollHeight == 0) 102 if (!oldRoute || this.scrollHeight == 0) {
98 setTimeout(this.tryTransitionToSection_.bind(this, scrollToSection)); 103 this.shouldHideContainer = true;
99 else 104 setTimeout(function() {
105 this.shouldHideContainer = false;
106 this.tryTransitionToSection_(scrollToSection, true);
107 }.bind(this));
108 } else
100 this.tryTransitionToSection_(scrollToSection); 109 this.tryTransitionToSection_(scrollToSection);
101 }, 110 },
102 111
103 /** 112 /**
104 * When exiting search mode, we need to make another attempt to scroll to 113 * When exiting search mode, we need to make another attempt to scroll to
105 * the correct section, since it has just been re-rendered. 114 * the correct section, since it has just been re-rendered.
106 * @private 115 * @private
107 */ 116 */
108 inSearchModeChanged_: function(inSearchMode) { 117 inSearchModeChanged_: function(inSearchMode) {
109 if (!this.isAttached) 118 if (!this.isAttached)
110 return; 119 return;
111 120
112 if (!inSearchMode) 121 if (!inSearchMode)
113 this.tryTransitionToSection_(!settings.lastRouteChangeWasPopstate()); 122 this.tryTransitionToSection_(!settings.lastRouteChangeWasPopstate());
114 }, 123 },
115 124
116 /** 125 /**
117 * If possible, transitions to the current route's section (by expanding or 126 * If possible, transitions to the current route's section (by expanding or
118 * scrolling to it). If another transition is running, finishes or cancels 127 * scrolling to it). If another transition is running, finishes or cancels
119 * that one, then schedules this function again. This ensures the current 128 * that one, then schedules this function again. This ensures the current
120 * section is quickly shown, without getting the page into a broken state -- 129 * section is quickly shown, without getting the page into a broken state --
121 * if currentRoute changes in between calls, just transition to the new route. 130 * if currentRoute changes in between calls, just transition to the new route.
122 * @param {boolean} scrollToSection 131 * @param {boolean} scrollToSection
michaelpg 2017/04/27 20:00:20 document immediate
scottchen 2017/05/01 19:25:06 Done.
123 * @private 132 * @private
124 */ 133 */
125 tryTransitionToSection_: function(scrollToSection) { 134 tryTransitionToSection_: function(scrollToSection, immediate) {
126 var currentRoute = settings.getCurrentRoute(); 135 var currentRoute = settings.getCurrentRoute();
127 var currentSection = this.getSection(currentRoute.section); 136 var currentSection = this.getSection(currentRoute.section);
128 137
129 // If an animation is already playing, try finishing or canceling it. 138 // If an animation is already playing, try finishing or canceling it.
130 if (this.currentAnimation_) { 139 if (this.currentAnimation_) {
131 this.maybeStopCurrentAnimation_(); 140 this.maybeStopCurrentAnimation_();
132 // Either way, this function will be called again once the current 141 // Either way, this function will be called again once the current
133 // animation ends. 142 // animation ends.
134 return; 143 return;
135 } 144 }
136 145
137 var promise; 146 var promise;
138 var expandedSection = /** @type {?SettingsSectionElement} */( 147 var expandedSection = /** @type {?SettingsSectionElement} */(
139 this.$$('settings-section.expanded')); 148 this.$$('settings-section.expanded'));
140 if (expandedSection) { 149 if (expandedSection) {
141 // If the section shouldn't be expanded, collapse it. 150 // If the section shouldn't be expanded, collapse it.
142 if (!currentRoute.isSubpage() || expandedSection != currentSection) { 151 if (!currentRoute.isSubpage() || expandedSection != currentSection) {
143 promise = this.collapseSection_(expandedSection); 152 promise = this.collapseSection_(expandedSection);
144 } else { 153 } else {
145 // Scroll to top while sliding to another subpage. 154 // Scroll to top while sliding to another subpage.
146 this.scroller.scrollTop = 0; 155 this.scroller.scrollTop = 0;
147 } 156 }
148 } else if (currentSection) { 157 } else if (currentSection) {
149 // Expand the section into a subpage or scroll to it on the main page. 158 // Expand the section into a subpage or scroll to it on the main page.
150 if (currentRoute.isSubpage()) 159 if (currentRoute.isSubpage())
151 promise = this.expandSection_(currentSection); 160 promise = this.expandSection_(currentSection, immediate);
152 else if (scrollToSection) 161 else if (scrollToSection)
153 currentSection.scrollIntoView(); 162 currentSection.scrollIntoView();
154 } else if ( 163 } else if (
155 this.tagName == 'SETTINGS-BASIC-PAGE' && 164 this.tagName == 'SETTINGS-BASIC-PAGE' &&
156 settings.Route.ADVANCED.contains(currentRoute) && 165 settings.Route.ADVANCED.contains(currentRoute) &&
157 // Need to exclude routes that correspond to 'non-sectioned' children of 166 // Need to exclude routes that correspond to 'non-sectioned' children of
158 // ADVANCED, otherwise tryTransitionToSection_ will recurse endlessly. 167 // ADVANCED, otherwise tryTransitionToSection_ will recurse endlessly.
159 !currentRoute.isNavigableDialog) { 168 !currentRoute.isNavigableDialog) {
160 assert(currentRoute.section); 169 assert(currentRoute.section);
161 promise = this.$$('#advancedPageTemplate').get(); 170 promise = this.$$('#advancedPageTemplate').get();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // Immediately finish the current collapse animation so that can happen. 213 // Immediately finish the current collapse animation so that can happen.
205 this.currentAnimation_.finish(); 214 this.currentAnimation_.finish();
206 }, 215 },
207 216
208 /** 217 /**
209 * Animates the card in |section|, expanding it to fill the page. 218 * Animates the card in |section|, expanding it to fill the page.
210 * @param {!SettingsSectionElement} section 219 * @param {!SettingsSectionElement} section
211 * @return {!Promise} Resolved when the transition is finished or canceled. 220 * @return {!Promise} Resolved when the transition is finished or canceled.
212 * @private 221 * @private
213 */ 222 */
214 expandSection_: function(section) { 223 expandSection_: function(section, immediate) {
215 assert(this.scroller); 224 assert(this.scroller);
216 225
226 if (immediate) {
michaelpg 2017/04/27 20:00:20 how about making this a separate function, instead
scottchen 2017/05/01 19:25:07 Done.
227 section.immediateExpand(this.scroller);
228
229 this.classList.add('showing-subpage');
michaelpg 2017/04/27 20:00:20 if so, we could create a helper method for the com
scottchen 2017/05/01 19:25:07 Done.
230 this.toggleOtherSectionsHidden_(section.section, true);
231 // Notify that the page is fully expanded.
232 this.fire('subpage-expand');
233 return;
234 }
235
217 if (!section.canAnimateExpand()) { 236 if (!section.canAnimateExpand()) {
218 // Try to wait for the section to be created. 237 // Try to wait for the section to be created.
219 return new Promise(function(resolve, reject) { 238 return new Promise(function(resolve, reject) {
220 setTimeout(resolve); 239 setTimeout(resolve);
221 }); 240 });
222 } 241 }
223 242
224 // Save the scroller position before freezing it. 243 // Save the scroller position before freezing it.
225 this.origScrollTop_ = this.scroller.scrollTop; 244 this.origScrollTop_ = this.scroller.scrollTop;
226 this.fire('freeze-scroll', true); 245 this.fire('freeze-scroll', true);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 return /** @type {?SettingsSectionElement} */( 368 return /** @type {?SettingsSectionElement} */(
350 this.$$('settings-section[section="' + section + '"]')); 369 this.$$('settings-section[section="' + section + '"]'));
351 }, 370 },
352 }; 371 };
353 372
354 /** @polymerBehavior */ 373 /** @polymerBehavior */
355 var MainPageBehavior = [ 374 var MainPageBehavior = [
356 settings.RouteObserverBehavior, 375 settings.RouteObserverBehavior,
357 MainPageBehaviorImpl, 376 MainPageBehaviorImpl,
358 ]; 377 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698