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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 settings.navigateTo(this.advancedToggleExpanded_ ? | 95 settings.navigateTo(this.advancedToggleExpanded_ ? |
92 settings.Route.ADVANCED : settings.Route.BASIC); | 96 settings.Route.ADVANCED : settings.Route.BASIC); |
93 }.bind(this)); | 97 }.bind(this)); |
94 | 98 |
| 99 var currentRoute = settings.getCurrentRoute(); |
| 100 this.hasExpandedSection_ = currentRoute && currentRoute.isSubpage(); |
95 }, | 101 }, |
96 | 102 |
97 /** @private */ | 103 /** @private */ |
98 overscrollChanged_: function() { | 104 overscrollChanged_: function() { |
99 if (!this.overscroll_ && this.boundScroll_) { | 105 if (!this.overscroll_ && this.boundScroll_) { |
100 this.offsetParent.removeEventListener('scroll', this.boundScroll_); | 106 this.offsetParent.removeEventListener('scroll', this.boundScroll_); |
101 this.boundScroll_ = null; | 107 this.boundScroll_ = null; |
102 } else if (this.overscroll_ && !this.boundScroll_) { | 108 } else if (this.overscroll_ && !this.boundScroll_) { |
103 this.boundScroll_ = this.setOverscroll_.bind(this, 0); | 109 this.boundScroll_ = this.setOverscroll_.bind(this, 0); |
104 this.offsetParent.addEventListener('scroll', this.boundScroll_); | 110 this.offsetParent.addEventListener('scroll', this.boundScroll_); |
(...skipping 26 matching lines...) Expand all Loading... |
131 arrowState_: function(opened) { | 137 arrowState_: function(opened) { |
132 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 138 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
133 }, | 139 }, |
134 | 140 |
135 /** | 141 /** |
136 * @return {boolean} | 142 * @return {boolean} |
137 * @private | 143 * @private |
138 */ | 144 */ |
139 showAdvancedToggle_: function() { | 145 showAdvancedToggle_: function() { |
140 var inSearchMode = !!this.previousShowPages_; | 146 var inSearchMode = !!this.previousShowPages_; |
141 return this.showPages_.basic && !this.inSubpage_ && !inSearchMode; | 147 return !inSearchMode && this.showPages_.basic && !this.hasExpandedSection_; |
142 }, | 148 }, |
143 | 149 |
144 /** @protected */ | 150 /** @private */ |
145 currentRouteChanged: function(newRoute) { | 151 currentRouteChanged: function(newRoute) { |
146 this.inSubpage_ = newRoute.isSubpage(); | 152 // When the route changes from a sub-page to the main page, immediately |
147 this.style.height = this.inSubpage_ ? '100%' : ''; | 153 // update hasExpandedSection_ to unhide the other sections. |
| 154 if (!newRoute.isSubpage()) |
| 155 this.hasExpandedSection_ = false; |
148 | 156 |
149 if (settings.Route.ABOUT.contains(newRoute)) { | 157 this.updatePagesShown_(); |
| 158 }, |
| 159 |
| 160 /** @private */ |
| 161 onSubpageExpand_: function() { |
| 162 // The subpage finished expanding fully. Hide pages other than the current |
| 163 // section's parent page. |
| 164 this.hasExpandedSection_ = true; |
| 165 this.updatePagesShown_(); |
| 166 }, |
| 167 |
| 168 /** |
| 169 * Updates the hidden state of the about, basic and advanced pages, based on |
| 170 * the current route and the Advanced toggle state. |
| 171 * @private |
| 172 */ |
| 173 updatePagesShown_: function() { |
| 174 var currentRoute = settings.getCurrentRoute(); |
| 175 if (settings.Route.ABOUT.contains(currentRoute)) { |
150 this.showPages_ = {about: true, basic: false, advanced: false}; | 176 this.showPages_ = {about: true, basic: false, advanced: false}; |
151 } else { | 177 } else { |
152 this.showPages_ = { | 178 this.showPages_ = { |
153 about: false, | 179 about: false, |
154 basic: settings.Route.BASIC.contains(newRoute) || !this.inSubpage_, | 180 basic: settings.Route.BASIC.contains(currentRoute) || |
155 advanced: settings.Route.ADVANCED.contains(newRoute) || | 181 !this.hasExpandedSection_, |
156 (!this.inSubpage_ && this.advancedToggleExpanded_), | 182 advanced: settings.Route.ADVANCED.contains(currentRoute) || |
| 183 (!this.hasExpandedSection_ && this.advancedToggleExpanded_), |
157 }; | 184 }; |
158 | 185 |
159 if (this.showPages_.advanced) { | 186 if (this.showPages_.advanced) { |
160 assert(!this.pageVisibility || | 187 assert(!this.pageVisibility || |
161 this.pageVisibility.advancedSettings !== false); | 188 this.pageVisibility.advancedSettings !== false); |
162 this.advancedToggleExpanded_ = true; | 189 this.advancedToggleExpanded_ = true; |
163 } | 190 } |
164 } | 191 } |
165 | 192 |
166 // Wait for any other changes prior to calculating the overflow padding. | 193 // Wait for any other changes prior to calculating the overflow padding. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 312 |
286 /** | 313 /** |
287 * @param {(boolean|undefined)} visibility | 314 * @param {(boolean|undefined)} visibility |
288 * @return {boolean} True unless visibility is false. | 315 * @return {boolean} True unless visibility is false. |
289 * @private | 316 * @private |
290 */ | 317 */ |
291 showAdvancedSettings_: function(visibility) { | 318 showAdvancedSettings_: function(visibility) { |
292 return visibility !== false; | 319 return visibility !== false; |
293 }, | 320 }, |
294 }); | 321 }); |
OLD | NEW |