Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: chrome/browser/resources/settings/settings_page/settings_section.js

Issue 1358313004: Settings Rewrite: Make subpage scrolling work. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ee64994ae9b8d3dcee1c1004dda28935b5964b9d 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,39 @@ 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 section = config.node;
+ var card = section.$.card;
+ var containerRect = section.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 = section.$.placeholder;
+ placeholder.style.top = card.offsetTop + 'px';
+ placeholder.style.height = card.offsetHeight + 'px';
+
+ section.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 section = config.node;
+ section.classList.remove('neon-animating');
+ section.classList.add('expanded');
+ section.expandContainer.classList.add('expanded');
+
+ // This event fires on itself as well, but that is benign.
+ var sections = section.parentNode.querySelectorAll('cr-settings-section');
+ for (var i = 0; i < sections.length; ++i) {
Dan Beam 2015/09/26 00:22:07 assert(sections[i].parent == section.parent);
Dan Beam 2015/09/26 00:22:29 parentNode* (or parentElement?)
tommycli 2015/09/26 00:32:16 It would be benign to fire these on deeper descend
+ sections[i].fire('expand-animation-complete');
+ }
+
+ section.expandContainer.scrollTop = 0;
}
});
@@ -131,30 +152,25 @@ Polymer({
],
configure: function(config) {
- var node = config.node;
-
- var oldRect = node.getBoundingClientRect();
+ var section = config.node;
+ var oldRect = section.expandContainer.getBoundingClientRect();
- // Temporarily set position to static to determine new height.
- node.style.position = '';
- var newTop = node.getBoundingClientRect().top;
+ section.classList.remove('expanded');
+ section.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 = section.$.placeholder.getBoundingClientRect();
- node.style.position = 'fixed';
+ section.classList.add('neon-animating');
- this._effect = new KeyframeEffect(node, [
+ this._effect = new KeyframeEffect(section.$.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');
}
});

Powered by Google App Engine
This is Rietveld 408576698