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

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 * '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:
11 * 11 *
12 * <cr-settings-section page-title="[[pageTitle]]"> 12 * <settings-section page-title="[[pageTitle]]">
13 * <!-- Insert your section controls here --> 13 * <!-- Insert your section controls here -->
14 * </cr-settings-section> 14 * </settings-section>
Dan Beam 2015/09/25 23:18:57 you should probably do this separately
tommycli 2015/09/25 23:36:40 Done.
15 * 15 *
16 * @group Chrome Settings Elements 16 * @group Chrome Settings Elements
17 * @element cr-settings-section 17 * @element settings-section
18 */ 18 */
19 Polymer({ 19 Polymer({
20 is: 'cr-settings-section', 20 is: 'settings-section',
21 21
22 behaviors: [ 22 behaviors: [
23 Polymer.NeonAnimationRunnerBehavior, 23 Polymer.NeonAnimationRunnerBehavior,
24 ], 24 ],
25 25
26 properties: { 26 properties: {
27 /** 27 /**
28 * The current active route. 28 * The current active route.
29 */ 29 */
30 currentRoute: { 30 currentRoute: {
(...skipping 12 matching lines...) Expand all
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.hidden = false;
86 }, 94 },
95
96 /** @private */
97 onExpandAnimationComplete_: function() {
98 this.hidden = this.currentRoute.section != '' &&
99 this.currentRoute.section != this.section;
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 section = config.node.$.section;
98 var containerRect = node.expandContainer.getBoundingClientRect(); 112 var containerRect = config.node.expandContainer.getBoundingClientRect();
99 var nodeRect = node.getBoundingClientRect(); 113 var sectionRect = section.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 // TODO(tommycli): For URLs that directly load subpages, this does not work.
117 var placeholder = config.node.$.placeholder;
118 placeholder.style.top = section.offsetTop + 'px';
119 placeholder.style.height = section.offsetHeight + 'px';
103 120
104 var headerHeight = node.$.header.getBoundingClientRect().height; 121 config.node.classList.add('neon-animating');
105 var newTop = containerRect.top - headerHeight;
106 var newHeight = containerRect.height + headerHeight;
107 122
108 node.style.position = 'fixed'; 123 this._effect = new KeyframeEffect(section, [
109 node.style.zIndex = '1'; 124 {'top': sectionRect.top + 'px', 'height': sectionRect.height + 'px'},
110 125 {'top': containerRect.top + 'px', 'height': containerRect.height + 'px'},
111 this._effect = new KeyframeEffect(node, [
112 {'top': nodeRect.top + 'px', 'height': nodeRect.height + 'px'},
113 {'top': newTop + 'px', 'height': newHeight + 'px'},
114 ], this.timingFromConfig(config)); 126 ], this.timingFromConfig(config));
115 return this._effect; 127 return this._effect;
116 }, 128 },
117 129
118 complete: function(config) { 130 complete: function(config) {
119 config.node.style.position = 'absolute'; 131 config.node.classList.remove('neon-animating');
Dan Beam 2015/09/25 23:18:02 what is config.node? can you make a short, descri
tommycli 2015/09/25 23:36:40 Done. Sure. Not sure what to call it other than 'e
Dan Beam 2015/09/25 23:38:45 it's at least a parent of a section, right? secti
tommycli 2015/09/26 00:17:33 Done.
120 config.node.style.top = 132 config.node.classList.add('expanded');
121 -config.node.$.header.getBoundingClientRect().height + 'px'; 133 config.node.expandContainer.classList.add('expanded');
122 config.node.style.bottom = 0; 134
135 for (var i = 0; i < config.node.parentNode.children.length; ++i) {
136 if (config.node.parentNode.children[i].nodeName == config.node.nodeName)
Dan Beam 2015/09/25 23:18:02 i'm confused. can this be .querySelectorAll('tag-
tommycli 2015/09/25 23:36:40 Done.
137 config.node.parentNode.children[i].fire('expand-animation-complete');
138 }
139
140 config.node.expandContainer.scrollTop = 0;
123 } 141 }
124 }); 142 });
125 143
126 Polymer({ 144 Polymer({
127 is: 'collapse-card-animation', 145 is: 'collapse-card-animation',
128 146
129 behaviors: [ 147 behaviors: [
130 Polymer.NeonAnimationBehavior 148 Polymer.NeonAnimationBehavior
131 ], 149 ],
132 150
133 configure: function(config) { 151 configure: function(config) {
134 var node = config.node; 152 var section = config.node.$.section;
Dan Beam 2015/09/25 23:18:02 move lower, closer to where it's actually used
tommycli 2015/09/25 23:36:40 Done.
153 var oldRect = config.node.expandContainer.getBoundingClientRect();
135 154
136 var oldRect = node.getBoundingClientRect(); 155 config.node.classList.remove('expanded');
156 config.node.expandContainer.classList.remove('expanded');
137 157
138 // Temporarily set position to static to determine new height. 158 // Get the placeholder coordinates before reflowing.
139 node.style.position = ''; 159 var newRect = config.node.$.placeholder.getBoundingClientRect();
140 var newTop = node.getBoundingClientRect().top;
141 160
142 // TODO(tommycli): This value is undefined when the user navigates to a 161 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 162
147 node.style.position = 'fixed'; 163 this._effect = new KeyframeEffect(section, [
148
149 this._effect = new KeyframeEffect(node, [
150 {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'}, 164 {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'},
151 {'top': newTop + 'px', 'height': newHeight + 'px'}, 165 {'top': newRect.top + 'px', 'height': newRect.height + 'px'},
152 ], this.timingFromConfig(config)); 166 ], this.timingFromConfig(config));
153 return this._effect; 167 return this._effect;
154 }, 168 },
155 169
156 complete: function(config) { 170 complete: function(config) {
157 config.node.style.position = ''; 171 config.node.classList.remove('neon-animating');
158 config.node.style.zIndex = '0';
159 } 172 }
160 }); 173 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698