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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
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 * 'cr-settings-section' shows a paper material themed section with a header 7 * 'cr-settings-section' shows a paper material themed section with a header
8 * which shows its page title. 8 * which shows its page title.
9 * 9 *
10 * Example: 10 * Example:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 /** 43 /**
44 * Title for the page header and navigation menu. 44 * Title for the page header and navigation menu.
45 */ 45 */
46 pageTitle: String, 46 pageTitle: String,
47 47
48 /** 48 /**
49 * Container that determines the sizing of expanded sections. 49 * Container that determines the sizing of expanded sections.
50 */ 50 */
51 expandContainer: { 51 expandContainer: {
52 type: Object, 52 type: Object,
53 notify: true,
54 }, 53 },
55 54
56 animationConfig: { 55 animationConfig: {
57 value: function() { 56 value: function() {
58 return { 57 return {
59 collapse: { 58 collapse: {
60 name: 'collapse-card-animation', 59 name: 'collapse-card-animation',
61 node: this, 60 node: this,
62 }, 61 },
63 expand: { 62 expand: {
64 name: 'expand-card-animation', 63 name: 'expand-card-animation',
65 node: this, 64 node: this,
66 }, 65 },
67 }; 66 };
68 }, 67 },
69 }, 68 },
70 }, 69 },
71 70
71 listeners: {
72 'expand-animation-complete': 'onExpandAnimationComplete_',
73 },
74
72 /** @private */ 75 /** @private */
73 expanded_: false, 76 expanded_: false,
74 77
75 /** @private */ 78 /** @private */
76 currentRouteChanged_: function() { 79 currentRouteChanged_: function() {
77 var expanded = this.currentRoute.section == this.section; 80 var expanded = this.currentRoute.section == this.section;
78 81
79 if (expanded != this.expanded_) { 82 if (expanded != this.expanded_) {
80 this.expanded_ = expanded; 83 this.expanded_ = expanded;
81 this.playAnimation(expanded ? 'expand' : 'collapse'); 84 this.playAnimation(expanded ? 'expand' : 'collapse');
82 } 85 }
83 86
84 var visible = expanded || this.currentRoute.section == ''; 87 var visible = expanded || this.currentRoute.section == '';
85 this.$.section.elevation = visible ? 1 : 0; 88 this.$.section.elevation = visible ? 1 : 0;
89
90 // Remove 'hidden' class immediately, but defer adding it if we are invisble
91 // until the animation is complete.
92 if (visible)
93 this.classList.remove('hidden');
86 }, 94 },
95
96 /** @private */
97 onExpandAnimationComplete_: function() {
98 this.classList.toggle('hidden', this.currentRoute.section != '' &&
99 this.currentRoute.section != this.section);
Dan Beam 2015/09/25 00:49:42 this.classList.toggle('hidden', ...); -> this.hidd
tommycli 2015/09/25 17:23:22 Done.
100 }
87 }); 101 });
88 102
89 Polymer({ 103 Polymer({
90 is: 'expand-card-animation', 104 is: 'expand-card-animation',
91 105
92 behaviors: [ 106 behaviors: [
93 Polymer.NeonAnimationBehavior 107 Polymer.NeonAnimationBehavior
94 ], 108 ],
95 109
96 configure: function(config) { 110 configure: function(config) {
97 var node = config.node; 111 var node = config.node.$.section;
Dan Beam 2015/09/25 00:49:42 update var name
tommycli 2015/09/25 17:23:22 Done.
98 var containerRect = node.expandContainer.getBoundingClientRect(); 112 var containerRect = config.node.expandContainer.getBoundingClientRect();
99 var nodeRect = node.getBoundingClientRect(); 113 var nodeRect = node.getBoundingClientRect();
100 114
101 // Save section's original height. 115 // Set placeholder height so the page does not reflow during animation.
102 node.unexpandedHeight = nodeRect.height; 116 var placeholder = config.node.$.placeholder;
117 placeholder.style.top = node.offsetTop + 'px';
118 placeholder.style.height = node.offsetHeight + 'px';
103 119
104 var headerHeight = node.$.header.getBoundingClientRect().height; 120 config.node.classList.add('neon-animating');
105 var newTop = containerRect.top - headerHeight;
106 var newHeight = containerRect.height + headerHeight;
107
108 node.style.position = 'fixed';
109 node.style.zIndex = '1';
110 121
111 this._effect = new KeyframeEffect(node, [ 122 this._effect = new KeyframeEffect(node, [
112 {'top': nodeRect.top + 'px', 'height': nodeRect.height + 'px'}, 123 {'top': nodeRect.top + 'px', 'height': nodeRect.height + 'px'},
113 {'top': newTop + 'px', 'height': newHeight + 'px'}, 124 {'top': containerRect.top + 'px', 'height': containerRect.height + 'px'},
114 ], this.timingFromConfig(config)); 125 ], this.timingFromConfig(config));
115 return this._effect; 126 return this._effect;
116 }, 127 },
117 128
118 complete: function(config) { 129 complete: function(config) {
119 config.node.style.position = 'absolute'; 130 config.node.classList.remove('neon-animating');
120 config.node.style.top = 131 config.node.classList.add('expanded');
121 -config.node.$.header.getBoundingClientRect().height + 'px'; 132 config.node.expandContainer.classList.add('expanded');
122 config.node.style.bottom = 0; 133
134 for (var i = 0; i < config.node.parentNode.children.length; ++i) {
135 if (config.node.parentNode.children[i].fire)
Dan Beam 2015/09/25 00:49:42 when is this false?
tommycli 2015/09/25 17:23:22 Done. First sibling is a STYLE tag. I updated the
136 config.node.parentNode.children[i].fire('expand-animation-complete');
137 }
138
139 config.node.expandContainer.scrollTop = 0;
123 } 140 }
124 }); 141 });
125 142
126 Polymer({ 143 Polymer({
127 is: 'collapse-card-animation', 144 is: 'collapse-card-animation',
128 145
129 behaviors: [ 146 behaviors: [
130 Polymer.NeonAnimationBehavior 147 Polymer.NeonAnimationBehavior
131 ], 148 ],
132 149
133 configure: function(config) { 150 configure: function(config) {
134 var node = config.node; 151 var node = config.node.$.section;
Dan Beam 2015/09/25 00:49:42 update var name
tommycli 2015/09/25 17:23:22 Done.
152 var oldRect = config.node.expandContainer.getBoundingClientRect();
135 153
136 var oldRect = node.getBoundingClientRect(); 154 config.node.classList.remove('expanded');
155 config.node.expandContainer.classList.remove('expanded');
137 156
138 // Temporarily set position to static to determine new height. 157 // Get the placeholder coordinates before reflowing.
139 node.style.position = ''; 158 var newRect = config.node.$.placeholder.getBoundingClientRect();
140 var newTop = node.getBoundingClientRect().top;
141 159
142 // TODO(tommycli): This value is undefined when the user navigates to a 160 config.node.classList.add('neon-animating');
143 // subpage directly by URL instead of from the settings root. Find a better
144 // method than using 200 as a dummy height.
145 var newHeight = node.unexpandedHeight || 200;
146
147 node.style.position = 'fixed';
148 161
149 this._effect = new KeyframeEffect(node, [ 162 this._effect = new KeyframeEffect(node, [
150 {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'}, 163 {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'},
151 {'top': newTop + 'px', 'height': newHeight + 'px'}, 164 {'top': newRect.top + 'px', 'height': newRect.height + 'px'},
152 ], this.timingFromConfig(config)); 165 ], this.timingFromConfig(config));
153 return this._effect; 166 return this._effect;
154 }, 167 },
155 168
156 complete: function(config) { 169 complete: function(config) {
157 config.node.style.position = ''; 170 config.node.classList.remove('neon-animating');
158 config.node.style.zIndex = '0';
159 } 171 }
160 }); 172 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698