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 * @typedef {{about: boolean, basic: boolean, advanced: boolean}} | 6 * @typedef {{about: boolean, basic: boolean, advanced: boolean}} |
7 */ | 7 */ |
8 var MainPageVisibility; | 8 var MainPageVisibility; |
9 | 9 |
10 /** | 10 /** |
(...skipping 13 matching lines...) Expand all Loading... |
24 type: Object, | 24 type: Object, |
25 notify: true, | 25 notify: true, |
26 }, | 26 }, |
27 | 27 |
28 /** @private */ | 28 /** @private */ |
29 advancedToggleExpanded_: { | 29 advancedToggleExpanded_: { |
30 type: Boolean, | 30 type: Boolean, |
31 value: false, | 31 value: false, |
32 }, | 32 }, |
33 | 33 |
34 /** @private */ | 34 /** |
35 inSubpage_: Boolean, | 35 * True if a section is fully expanded to hide other sections beneath it. |
| 36 * Not true otherwise (even while animating a section open/closed). |
| 37 * @private |
| 38 */ |
| 39 hasExpandedSection_: Boolean, |
36 | 40 |
37 /** @private */ | 41 /** @private */ |
38 overscroll_: { | 42 overscroll_: { |
39 type: Number, | 43 type: Number, |
40 observer: 'overscrollChanged_', | 44 observer: 'overscrollChanged_', |
41 }, | 45 }, |
42 | 46 |
43 /** | 47 /** |
44 * Controls which main pages are displayed via dom-ifs. | 48 * Controls which main pages are displayed via dom-ifs. |
45 * @private {!MainPageVisibility} | 49 * @private {!MainPageVisibility} |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 value: function() { return {}; }, | 87 value: function() { return {}; }, |
84 }, | 88 }, |
85 }, | 89 }, |
86 | 90 |
87 /** @override */ | 91 /** @override */ |
88 attached: function() { | 92 attached: function() { |
89 document.addEventListener('toggle-advanced-page', function(e) { | 93 document.addEventListener('toggle-advanced-page', function(e) { |
90 this.advancedToggleExpanded_ = e.detail; | 94 this.advancedToggleExpanded_ = e.detail; |
91 this.currentRouteChanged(settings.getCurrentRoute()); | 95 this.currentRouteChanged(settings.getCurrentRoute()); |
92 }.bind(this)); | 96 }.bind(this)); |
| 97 |
| 98 var currentRoute = settings.getCurrentRoute(); |
| 99 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); |
93 }, | 100 }, |
94 | 101 |
95 /** @private */ | 102 /** @private */ |
96 overscrollChanged_: function() { | 103 overscrollChanged_: function() { |
97 if (!this.overscroll_ && this.boundScroll_) { | 104 if (!this.overscroll_ && this.boundScroll_) { |
98 this.offsetParent.removeEventListener('scroll', this.boundScroll_); | 105 this.offsetParent.removeEventListener('scroll', this.boundScroll_); |
99 this.boundScroll_ = null; | 106 this.boundScroll_ = null; |
100 } else if (this.overscroll_ && !this.boundScroll_) { | 107 } else if (this.overscroll_ && !this.boundScroll_) { |
101 this.boundScroll_ = this.setOverscroll_.bind(this, 0); | 108 this.boundScroll_ = this.setOverscroll_.bind(this, 0); |
102 this.offsetParent.addEventListener('scroll', this.boundScroll_); | 109 this.offsetParent.addEventListener('scroll', this.boundScroll_); |
(...skipping 26 matching lines...) Expand all Loading... |
129 arrowState_: function(opened) { | 136 arrowState_: function(opened) { |
130 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 137 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
131 }, | 138 }, |
132 | 139 |
133 /** | 140 /** |
134 * @return {boolean} | 141 * @return {boolean} |
135 * @private | 142 * @private |
136 */ | 143 */ |
137 showAdvancedToggle_: function() { | 144 showAdvancedToggle_: function() { |
138 var inSearchMode = !!this.previousShowPages_; | 145 var inSearchMode = !!this.previousShowPages_; |
139 return this.showPages_.basic && !this.inSubpage_ && !inSearchMode; | 146 return !inSearchMode && this.showPages_.basic && !this.hasExpandedSection_; |
140 }, | 147 }, |
141 | 148 |
142 /** @protected */ | |
143 currentRouteChanged: function(newRoute) { | 149 currentRouteChanged: function(newRoute) { |
144 this.inSubpage_ = newRoute.isSubpage(); | 150 // When the route changes from a sub-page to the main page, immediately |
145 this.style.height = this.inSubpage_ ? '100%' : ''; | 151 // update hasExpandedSection_ to unhide the other sections. |
| 152 if (!newRoute.isSubpage()) |
| 153 this.hasExpandedSection_ = false; |
146 | 154 |
147 if (settings.Route.ABOUT.contains(newRoute)) { | 155 this.updatePagesShown_(); |
| 156 }, |
| 157 |
| 158 /** @private */ |
| 159 onSubpageExpand_: function() { |
| 160 // The subpage finished expanding fully. Hide pages other than the current |
| 161 // section's parent page. |
| 162 this.hasExpandedSection_ = true; |
| 163 this.updatePagesShown_(); |
| 164 }, |
| 165 |
| 166 /** |
| 167 * Updates the hidden state of the about, basic and advanced pages, based on |
| 168 * the current route and the Advanced toggle state. |
| 169 * @private |
| 170 */ |
| 171 updatePagesShown_: function() { |
| 172 var currentRoute = settings.getCurrentRoute(); |
| 173 if (settings.Route.ABOUT.contains(currentRoute)) { |
148 this.showPages_ = {about: true, basic: false, advanced: false}; | 174 this.showPages_ = {about: true, basic: false, advanced: false}; |
149 } else { | 175 } else { |
150 this.showPages_ = { | 176 this.showPages_ = { |
151 about: false, | 177 about: false, |
152 basic: settings.Route.BASIC.contains(newRoute) || !this.inSubpage_, | 178 basic: settings.Route.BASIC.contains(currentRoute) || |
153 advanced: settings.Route.ADVANCED.contains(newRoute) || | 179 !this.hasExpandedSection_, |
154 (!this.inSubpage_ && this.advancedToggleExpanded_), | 180 advanced: settings.Route.ADVANCED.contains(currentRoute) || |
| 181 (!this.hasExpandedSection_ && this.advancedToggleExpanded_), |
155 }; | 182 }; |
156 | 183 |
157 if (this.showPages_.advanced) { | 184 if (this.showPages_.advanced) { |
158 assert(!this.pageVisibility || | 185 assert(!this.pageVisibility || |
159 this.pageVisibility.advancedSettings !== false); | 186 this.pageVisibility.advancedSettings !== false); |
160 this.advancedToggleExpanded_ = true; | 187 this.advancedToggleExpanded_ = true; |
161 } | 188 } |
162 } | 189 } |
163 | 190 |
164 // Wait for any other changes prior to calculating the overflow padding. | 191 // Wait for any other changes prior to calculating the overflow padding. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 310 |
284 /** | 311 /** |
285 * @param {(boolean|undefined)} visibility | 312 * @param {(boolean|undefined)} visibility |
286 * @return {boolean} True unless visibility is false. | 313 * @return {boolean} True unless visibility is false. |
287 * @private | 314 * @private |
288 */ | 315 */ |
289 showAdvancedSettings_: function(visibility) { | 316 showAdvancedSettings_: function(visibility) { |
290 return visibility !== false; | 317 return visibility !== false; |
291 }, | 318 }, |
292 }); | 319 }); |
OLD | NEW |