| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 showNoResultsFound_: { | 53 showNoResultsFound_: { |
| 54 type: Boolean, | 54 type: Boolean, |
| 55 value: false, | 55 value: false, |
| 56 }, | 56 }, |
| 57 | 57 |
| 58 toolbarSpinnerActive: { | 58 toolbarSpinnerActive: { |
| 59 type: Boolean, | 59 type: Boolean, |
| 60 value: false, | 60 value: false, |
| 61 notify: true, | 61 notify: true, |
| 62 }, | 62 }, |
| 63 |
| 64 /** |
| 65 * Dictionary defining page visibility. |
| 66 * @type {!GuestModePageVisibility} |
| 67 */ |
| 68 pageVisibility: { |
| 69 type: Object, |
| 70 value: function() { return {}; }, |
| 71 }, |
| 63 }, | 72 }, |
| 64 | 73 |
| 65 /** @override */ | 74 /** @override */ |
| 66 created: function() { | 75 created: function() { |
| 67 /** @private {!PromiseResolver} */ | 76 /** @private {!PromiseResolver} */ |
| 68 this.resolver_ = new PromiseResolver; | 77 this.resolver_ = new PromiseResolver; |
| 69 settings.main.rendered = this.resolver_.promise; | 78 settings.main.rendered = this.resolver_.promise; |
| 70 }, | 79 }, |
| 71 | 80 |
| 72 /** @override */ | 81 /** @override */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 96 * @private | 105 * @private |
| 97 */ | 106 */ |
| 98 arrowState_: function(opened) { | 107 arrowState_: function(opened) { |
| 99 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; | 108 return opened ? 'settings:arrow-drop-up' : 'cr:arrow-drop-down'; |
| 100 }, | 109 }, |
| 101 | 110 |
| 102 /** | 111 /** |
| 103 * @param {boolean} showBasicPage | 112 * @param {boolean} showBasicPage |
| 104 * @param {boolean} inSubpage | 113 * @param {boolean} inSubpage |
| 105 * @return {boolean} | 114 * @return {boolean} |
| 115 * @private |
| 106 */ | 116 */ |
| 107 showAdvancedToggle_: function(showBasicPage, inSubpage) { | 117 showAdvancedToggle_: function(showBasicPage, inSubpage) { |
| 108 return showBasicPage && !inSubpage; | 118 return showBasicPage && !inSubpage; |
| 109 }, | 119 }, |
| 110 | 120 |
| 111 /** | 121 /** |
| 112 * @param {!SettingsRoute} newRoute | 122 * @param {!SettingsRoute} newRoute |
| 113 * @private | 123 * @private |
| 114 */ | 124 */ |
| 115 currentRouteChanged_: function(newRoute) { | 125 currentRouteChanged_: function(newRoute) { |
| 116 this.inSubpage_ = newRoute.subpage.length > 0; | 126 this.inSubpage_ = newRoute.subpage.length > 0; |
| 117 this.style.height = this.inSubpage_ ? '100%' : ''; | 127 this.style.height = this.inSubpage_ ? '100%' : ''; |
| 118 | 128 |
| 119 if (newRoute.page == 'about') { | 129 if (newRoute.page == 'about') { |
| 120 this.showPages_ = {about: true, basic: false, advanced: false}; | 130 this.showPages_ = {about: true, basic: false, advanced: false}; |
| 121 } else { | 131 } else { |
| 122 this.showPages_ = { | 132 this.showPages_ = { |
| 123 about: false, | 133 about: false, |
| 124 basic: newRoute.page == 'basic' || !this.inSubpage_, | 134 basic: newRoute.page == 'basic' || !this.inSubpage_, |
| 125 advanced: newRoute.page == 'advanced' || | 135 advanced: newRoute.page == 'advanced' || |
| 126 (!this.inSubpage_ && this.advancedToggleExpanded_), | 136 (!this.inSubpage_ && this.advancedToggleExpanded_), |
| 127 }; | 137 }; |
| 128 | 138 |
| 129 if (this.showPages_.advanced) | 139 if (this.showPages_.advanced) { |
| 140 assert(!this.pageVisibility || |
| 141 this.pageVisibility.advancedSettings !== false); |
| 130 this.advancedToggleExpanded_ = true; | 142 this.advancedToggleExpanded_ = true; |
| 143 } |
| 131 } | 144 } |
| 132 | 145 |
| 133 // Wait for the dom-if changes prior to calculating the overflow padding. | 146 // Wait for the dom-if changes prior to calculating the overflow padding. |
| 134 this.async(function() { | 147 this.async(function() { |
| 135 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px'; | 148 this.$.overscroll.style.paddingBottom = this.overscrollHeight_() + 'px'; |
| 136 }); | 149 }); |
| 137 }, | 150 }, |
| 138 | 151 |
| 139 /** | 152 /** |
| 140 * Return the height that the over scroll padding should be set to. | 153 * Return the height that the over scroll padding should be set to. |
| 141 * This is used to determine how much padding to apply to the end of the | 154 * This is used to determine how much padding to apply to the end of the |
| 142 * content so that the last element may align with the top of the content | 155 * content so that the last element may align with the top of the content |
| 143 * area. | 156 * area. |
| 144 * @return {number} | 157 * @return {number} |
| 145 * @private | 158 * @private |
| 146 */ | 159 */ |
| 147 overscrollHeight_: function() { | 160 overscrollHeight_: function() { |
| 148 if (!this.currentRoute || this.currentRoute.subpage.length != 0 || | 161 if (!this.currentRoute || this.currentRoute.subpage.length != 0 || |
| 149 this.showPages_.about) { | 162 this.showPages_.about) { |
| 150 return 0; | 163 return 0; |
| 151 } | 164 } |
| 152 | 165 |
| 166 // Ensure any dom-if reflects the current properties. |
| 167 Polymer.dom.flush(); |
| 168 |
| 153 /** | 169 /** |
| 154 * @param {!Element} element | 170 * @param {!Element} element |
| 155 * @return {number} | 171 * @return {number} |
| 156 */ | 172 */ |
| 157 var calcHeight = function(element) { | 173 var calcHeight = function(element) { |
| 158 var style = getComputedStyle(element); | 174 var style = getComputedStyle(element); |
| 159 var height = this.parentNode.scrollHeight - element.offsetHeight + | 175 var height = this.parentNode.scrollHeight - element.offsetHeight + |
| 160 parseFloat(style.marginTop) + parseFloat(style.marginBottom); | 176 parseFloat(style.marginTop) + parseFloat(style.marginBottom); |
| 161 assert(height >= 0); | 177 assert(height >= 0); |
| 162 return height; | 178 return height; |
| 163 }.bind(this); | 179 }.bind(this); |
| 164 | 180 |
| 165 if (this.showPages_.advanced) { | 181 if (this.showPages_.advanced) { |
| 166 var lastSection = this.$$('settings-advanced-page').$$( | 182 var lastSection = this.$$('settings-advanced-page').$$( |
| 167 'settings-section:last-of-type'); | 183 'settings-section:last-of-type'); |
| 168 // |lastSection| may be null in unit tests. | 184 // |lastSection| may be null in unit tests. |
| 169 if (!lastSection) | 185 if (!lastSection) |
| 170 return 0; | 186 return 0; |
| 171 return calcHeight(lastSection); | 187 return calcHeight(lastSection); |
| 172 } | 188 } |
| 173 | 189 |
| 174 assert(this.showPages_.basic); | 190 assert(this.showPages_.basic); |
| 175 var lastSection = this.$$('settings-basic-page').$$( | 191 var lastSection = this.$$('settings-basic-page').$$( |
| 176 'settings-section:last-of-type'); | 192 'settings-section:last-of-type'); |
| 177 // |lastSection| may be null in unit tests. | 193 // |lastSection| may be null in unit tests. |
| 178 if (!lastSection) | 194 if (!lastSection) |
| 179 return 0; | 195 return 0; |
| 180 return calcHeight(lastSection) - this.$$('#toggleContainer').offsetHeight; | 196 var toggleContainer = this.$$('#toggleContainer'); |
| 197 return calcHeight(lastSection) - |
| 198 (toggleContainer ? toggleContainer.offsetHeight : 0); |
| 181 }, | 199 }, |
| 182 | 200 |
| 183 /** @private */ | 201 /** @private */ |
| 184 toggleAdvancedPage_: function() { | 202 toggleAdvancedPage_: function() { |
| 185 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); | 203 this.fire('toggle-advanced-page', !this.advancedToggleExpanded_); |
| 186 }, | 204 }, |
| 187 | 205 |
| 188 /** | 206 /** |
| 189 * Navigates to the default search page (if necessary). | 207 * Navigates to the default search page (if necessary). |
| 190 * @private | 208 * @private |
| (...skipping 30 matching lines...) Expand all Loading... |
| 221 // completed. | 239 // completed. |
| 222 return; | 240 return; |
| 223 } | 241 } |
| 224 | 242 |
| 225 this.toolbarSpinnerActive = false; | 243 this.toolbarSpinnerActive = false; |
| 226 this.showNoResultsFound_ = | 244 this.showNoResultsFound_ = |
| 227 !request.isSame('') && !request.didFindMatches(); | 245 !request.isSame('') && !request.didFindMatches(); |
| 228 }.bind(this)); | 246 }.bind(this)); |
| 229 }.bind(this), 0); | 247 }.bind(this), 0); |
| 230 }, | 248 }, |
| 249 |
| 250 /** |
| 251 * @param {(boolean|undefined)} visibility |
| 252 * @return {boolean} True unless visibility is false. |
| 253 * @private |
| 254 */ |
| 255 showAdvancedSettings_: function(visibility) { |
| 256 return visibility !== false; |
| 257 }, |
| 231 }); | 258 }); |
| OLD | NEW |