Chromium Code Reviews| Index: chrome/browser/resources/settings/settings_page/settings_section.js |
| diff --git a/chrome/browser/resources/settings/settings_page/settings_section.js b/chrome/browser/resources/settings/settings_page/settings_section.js |
| index 123ce46ceadfdd45909321023bbc8713a40289c4..7e166a74dc44b0c41aa23b03b10b681fd232f03a 100644 |
| --- a/chrome/browser/resources/settings/settings_page/settings_section.js |
| +++ b/chrome/browser/resources/settings/settings_page/settings_section.js |
| @@ -50,7 +50,6 @@ Polymer({ |
| */ |
| expandContainer: { |
| type: Object, |
| - notify: true, |
| }, |
| animationConfig: { |
| @@ -69,6 +68,10 @@ Polymer({ |
| }, |
| }, |
| + listeners: { |
| + 'expand-animation-complete': 'onExpandAnimationComplete_', |
| + }, |
| + |
| /** @private */ |
| expanded_: false, |
| @@ -82,8 +85,19 @@ Polymer({ |
| } |
| var visible = expanded || this.currentRoute.section == ''; |
| - this.$.section.elevation = visible ? 1 : 0; |
| + this.$.card.elevation = visible ? 1 : 0; |
| + |
| + // Remove 'hidden' class immediately, but defer adding it if we are invisble |
| + // until the animation is complete. |
| + if (visible) |
| + this.hidden = false; |
| }, |
| + |
| + /** @private */ |
| + onExpandAnimationComplete_: function() { |
| + this.hidden = this.currentRoute.section != '' && |
| + this.currentRoute.section != this.section; |
| + } |
| }); |
| Polymer({ |
| @@ -94,32 +108,41 @@ Polymer({ |
| ], |
| configure: function(config) { |
| - var node = config.node; |
| - var containerRect = node.expandContainer.getBoundingClientRect(); |
| - var nodeRect = node.getBoundingClientRect(); |
| - |
| - // Save section's original height. |
| - node.unexpandedHeight = nodeRect.height; |
| - |
| - var headerHeight = node.$.header.getBoundingClientRect().height; |
| - var newTop = containerRect.top - headerHeight; |
| - var newHeight = containerRect.height + headerHeight; |
| - |
| - node.style.position = 'fixed'; |
| - node.style.zIndex = '1'; |
| - |
| - this._effect = new KeyframeEffect(node, [ |
| - {'top': nodeRect.top + 'px', 'height': nodeRect.height + 'px'}, |
| - {'top': newTop + 'px', 'height': newHeight + 'px'}, |
| + var sectionWrapper = config.node; |
|
Dan Beam
2015/09/26 00:09:11
like in packaging, a wrapper is around something.
tommycli
2015/09/26 00:17:33
Done.
|
| + var card = sectionWrapper.$.card; |
| + var containerRect = sectionWrapper.expandContainer.getBoundingClientRect(); |
| + var cardRect = card.getBoundingClientRect(); |
| + |
| + // Set placeholder height so the page does not reflow during animation. |
| + // TODO(tommycli): For URLs that directly load subpages, this does not work. |
| + var placeholder = sectionWrapper.$.placeholder; |
| + placeholder.style.top = card.offsetTop + 'px'; |
| + placeholder.style.height = card.offsetHeight + 'px'; |
| + |
| + sectionWrapper.classList.add('neon-animating'); |
| + |
| + this._effect = new KeyframeEffect(card, [ |
| + {'top': cardRect.top + 'px', 'height': cardRect.height + 'px'}, |
| + {'top': containerRect.top + 'px', 'height': containerRect.height + 'px'}, |
| ], this.timingFromConfig(config)); |
| return this._effect; |
| }, |
| complete: function(config) { |
| - config.node.style.position = 'absolute'; |
| - config.node.style.top = |
| - -config.node.$.header.getBoundingClientRect().height + 'px'; |
| - config.node.style.bottom = 0; |
| + var sectionWrapper = config.node; |
| + sectionWrapper.classList.remove('neon-animating'); |
| + sectionWrapper.classList.add('expanded'); |
| + sectionWrapper.expandContainer.classList.add('expanded'); |
| + |
| + // Iterate through sibling elements of the same type. This event fires |
| + // on itself as well, but that is benign. |
| + var siblings = sectionWrapper.parentNode.children; |
|
Dan Beam
2015/09/26 00:09:10
i think just naming this var `sections` or somethi
tommycli
2015/09/26 00:17:33
Done.
|
| + for (var i = 0; i < siblings.length; ++i) { |
| + if (siblings[i].tagName == sectionWrapper.tagName) |
| + siblings[i].fire('expand-animation-complete'); |
| + } |
| + |
| + sectionWrapper.expandContainer.scrollTop = 0; |
| } |
| }); |
| @@ -131,30 +154,25 @@ Polymer({ |
| ], |
| configure: function(config) { |
| - var node = config.node; |
| - |
| - var oldRect = node.getBoundingClientRect(); |
| + var sectionWrapper = config.node; |
| + var oldRect = sectionWrapper.expandContainer.getBoundingClientRect(); |
| - // Temporarily set position to static to determine new height. |
| - node.style.position = ''; |
| - var newTop = node.getBoundingClientRect().top; |
| + sectionWrapper.classList.remove('expanded'); |
| + sectionWrapper.expandContainer.classList.remove('expanded'); |
| - // TODO(tommycli): This value is undefined when the user navigates to a |
| - // subpage directly by URL instead of from the settings root. Find a better |
| - // method than using 200 as a dummy height. |
| - var newHeight = node.unexpandedHeight || 200; |
| + // Get the placeholder coordinates before reflowing. |
| + var newRect = sectionWrapper.$.placeholder.getBoundingClientRect(); |
| - node.style.position = 'fixed'; |
| + sectionWrapper.classList.add('neon-animating'); |
| - this._effect = new KeyframeEffect(node, [ |
| + this._effect = new KeyframeEffect(sectionWrapper.$.card, [ |
| {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'}, |
| - {'top': newTop + 'px', 'height': newHeight + 'px'}, |
| + {'top': newRect.top + 'px', 'height': newRect.height + 'px'}, |
| ], this.timingFromConfig(config)); |
| return this._effect; |
| }, |
| complete: function(config) { |
| - config.node.style.position = ''; |
| - config.node.style.zIndex = '0'; |
| + config.node.classList.remove('neon-animating'); |
| } |
| }); |