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', |
(...skipping 16 matching lines...) Expand all Loading... | |
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, |
34 value: false, | 34 value: false, |
35 }, | 35 }, |
36 | 36 |
37 /** @private */ | 37 /** |
38 inSubpage_: Boolean, | 38 * True if a section is fully expanded to hide other sections beneath it. |
39 * Not true otherwise (even while animating a section open/closed). | |
40 * @private | |
41 */ | |
42 hasExpandedSection_: Boolean, | |
39 | 43 |
40 /** | 44 /** |
41 * Controls which main pages are displayed via dom-ifs. | 45 * Controls which main pages are displayed via dom-ifs. |
42 * @type {!{about: boolean, basic: boolean, advanced: boolean}} | 46 * @type {!{about: boolean, basic: boolean, advanced: boolean}} |
43 * @private | 47 * @private |
44 */ | 48 */ |
45 showPages_: { | 49 showPages_: { |
46 type: Object, | 50 type: Object, |
47 value: function() { | 51 value: function() { |
48 return {about: false, basic: false, advanced: false}; | 52 return {about: false, basic: false, advanced: false}; |
(...skipping 15 matching lines...) Expand all Loading... | |
64 /** | 68 /** |
65 * Dictionary defining page visibility. | 69 * Dictionary defining page visibility. |
66 * @type {!GuestModePageVisibility} | 70 * @type {!GuestModePageVisibility} |
67 */ | 71 */ |
68 pageVisibility: { | 72 pageVisibility: { |
69 type: Object, | 73 type: Object, |
70 value: function() { return {}; }, | 74 value: function() { return {}; }, |
71 }, | 75 }, |
72 }, | 76 }, |
73 | 77 |
78 listeners: { | |
79 // Used to control overscroll behavior while animating sections. | |
michaelpg
2016/08/04 07:07:36
Dave, these events let transitions actually start
| |
80 'overscroll-recalc': 'onOverscrollRecalc_', | |
81 'overscroll-suppress': 'onOverscrollSuppress_', | |
82 }, | |
83 | |
74 /** @override */ | 84 /** @override */ |
75 attached: function() { | 85 attached: function() { |
76 document.addEventListener('toggle-advanced-page', function(e) { | 86 document.addEventListener('toggle-advanced-page', function(e) { |
77 this.advancedToggleExpanded_ = e.detail; | 87 this.advancedToggleExpanded_ = e.detail; |
78 settings.navigateTo(this.advancedToggleExpanded_ ? | 88 settings.navigateTo(this.advancedToggleExpanded_ ? |
79 settings.Route.ADVANCED : settings.Route.BASIC); | 89 settings.Route.ADVANCED : settings.Route.BASIC); |
80 }.bind(this)); | 90 }.bind(this)); |
91 | |
92 this.hasExpandedSection_ = | |
93 this.currentRoute && this.currentRoute.subpage.length > 0; | |
94 }, | |
95 | |
96 /** @private Enables overscroll calculating and recalculates it. */ | |
97 onOverscrollRecalc_: function() { | |
98 this.overscrollSuppressed_ = false; | |
99 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px'; | |
dschuyler
2016/08/04 18:36:51
The overscroll calculation changed in a CL yesterd
Dan Beam
2016/08/05 00:47:06
yep, this it out of date
| |
100 }, | |
101 | |
102 /** @private Disables overscroll calculating. */ | |
103 onOverscrollSuppress_: function() { | |
104 this.overscrollSuppressed_ = true; | |
81 }, | 105 }, |
82 | 106 |
83 /** | 107 /** |
84 * @param {boolean} opened Whether the menu is expanded. | 108 * @param {boolean} opened Whether the menu is expanded. |
85 * @return {string} Which icon to use. | 109 * @return {string} Which icon to use. |
86 * @private | 110 * @private |
87 */ | 111 */ |
88 arrowState_: function(opened) { | 112 arrowState_: function(opened) { |
89 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 113 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
90 }, | 114 }, |
91 | 115 |
92 /** | 116 /** |
93 * @param {boolean} showBasicPage | 117 * @param {boolean} showBasicPage |
94 * @param {boolean} inSubpage | 118 * @param {boolean} hasExpandedSection |
95 * @return {boolean} | 119 * @return {boolean} |
96 * @private | 120 * @private |
97 */ | 121 */ |
98 showAdvancedToggle_: function(showBasicPage, inSubpage) { | 122 showAdvancedToggle_: function(showBasicPage, hasExpandedSection) { |
99 return showBasicPage && !inSubpage; | 123 return showBasicPage && !hasExpandedSection; |
124 }, | |
125 | |
126 /** @private */ | |
127 currentRouteChanged_: function(newRoute) { | |
128 // When the route changes from a sub-page to the main page, immediately | |
129 // update hasExpandedSection_ to unhide the other sections. | |
130 if (newRoute.subpage.length == 0) | |
131 this.hasExpandedSection_ = false; | |
132 | |
133 this.updatePagesShown_(); | |
134 }, | |
135 | |
136 /** @private */ | |
137 onSubpageExpand_: function() { | |
138 // The subpage finished expanding fully. Hide pages other than the current | |
139 // section's parent page. | |
140 this.hasExpandedSection_ = true; | |
141 this.updatePagesShown_(); | |
100 }, | 142 }, |
101 | 143 |
102 /** | 144 /** |
145 * Updates the hidden state of the about, basic and advanced pages, based on | |
146 * the current route and the Advanced toggle state. | |
103 * @private | 147 * @private |
104 */ | 148 */ |
105 currentRouteChanged_: function(newRoute) { | 149 updatePagesShown_: function() { |
106 this.inSubpage_ = newRoute.subpage.length > 0; | 150 if (settings.Route.ABOUT.contains(this.currentRoute)) { |
107 this.style.height = this.inSubpage_ ? '100%' : ''; | |
108 | |
109 if (settings.Route.ABOUT.contains(newRoute)) { | |
110 this.showPages_ = {about: true, basic: false, advanced: false}; | 151 this.showPages_ = {about: true, basic: false, advanced: false}; |
111 } else { | 152 } else { |
112 this.showPages_ = { | 153 this.showPages_ = { |
113 about: false, | 154 about: false, |
114 basic: settings.Route.BASIC.contains(newRoute) || !this.inSubpage_, | 155 basic: settings.Route.BASIC.contains(this.currentRoute) || |
115 advanced: settings.Route.ADVANCED.contains(newRoute) || | 156 !this.hasExpandedSection_, |
116 (!this.inSubpage_ && this.advancedToggleExpanded_), | 157 advanced: settings.Route.ADVANCED.contains(this.currentRoute) || |
158 (!this.hasExpandedSection_ && this.advancedToggleExpanded_), | |
117 }; | 159 }; |
118 | 160 |
119 if (this.showPages_.advanced) { | 161 if (this.showPages_.advanced) { |
120 assert(!this.pageVisibility || | 162 assert(!this.pageVisibility || |
121 this.pageVisibility.advancedSettings !== false); | 163 this.pageVisibility.advancedSettings !== false); |
122 this.advancedToggleExpanded_ = true; | 164 this.advancedToggleExpanded_ = true; |
123 } | 165 } |
124 } | 166 } |
125 | 167 |
126 // Wait for any other changes prior to calculating the overflow padding. | 168 // Wait for any other changes prior to calculating the overflow padding. |
127 setTimeout(function() { | 169 setTimeout(function() { |
128 // Ensure any dom-if reflects the current properties. | 170 // Ensure any dom-if reflects the current properties. |
129 Polymer.dom.flush(); | 171 Polymer.dom.flush(); |
130 | 172 |
131 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px'; | 173 if (!this.overscrollSuppressed_) |
174 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px'; | |
132 }.bind(this)); | 175 }.bind(this)); |
133 }, | 176 }, |
134 | 177 |
135 /** | 178 /** |
136 * Return the height that the overscroll padding should be set to. | 179 * Return the height that the overscroll padding should be set to. |
137 * This is used to determine how much padding to apply to the end of the | 180 * This is used to determine how much padding to apply to the end of the |
138 * content so that the last element may align with the top of the content | 181 * content so that the last element may align with the top of the content |
139 * area. | 182 * area. |
140 * @return {number} | 183 * @return {number} |
141 * @private | 184 * @private |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 | 256 |
214 /** | 257 /** |
215 * @param {(boolean|undefined)} visibility | 258 * @param {(boolean|undefined)} visibility |
216 * @return {boolean} True unless visibility is false. | 259 * @return {boolean} True unless visibility is false. |
217 * @private | 260 * @private |
218 */ | 261 */ |
219 showAdvancedSettings_: function(visibility) { | 262 showAdvancedSettings_: function(visibility) { |
220 return visibility !== false; | 263 return visibility !== false; |
221 }, | 264 }, |
222 }); | 265 }); |
OLD | NEW |