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

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.$.card.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 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.
98 var containerRect = node.expandContainer.getBoundingClientRect(); 112 var card = sectionWrapper.$.card;
99 var nodeRect = node.getBoundingClientRect(); 113 var containerRect = sectionWrapper.expandContainer.getBoundingClientRect();
114 var cardRect = card.getBoundingClientRect();
100 115
101 // Save section's original height. 116 // Set placeholder height so the page does not reflow during animation.
102 node.unexpandedHeight = nodeRect.height; 117 // TODO(tommycli): For URLs that directly load subpages, this does not work.
118 var placeholder = sectionWrapper.$.placeholder;
119 placeholder.style.top = card.offsetTop + 'px';
120 placeholder.style.height = card.offsetHeight + 'px';
103 121
104 var headerHeight = node.$.header.getBoundingClientRect().height; 122 sectionWrapper.classList.add('neon-animating');
105 var newTop = containerRect.top - headerHeight;
106 var newHeight = containerRect.height + headerHeight;
107 123
108 node.style.position = 'fixed'; 124 this._effect = new KeyframeEffect(card, [
109 node.style.zIndex = '1'; 125 {'top': cardRect.top + 'px', 'height': cardRect.height + 'px'},
110 126 {'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)); 127 ], this.timingFromConfig(config));
115 return this._effect; 128 return this._effect;
116 }, 129 },
117 130
118 complete: function(config) { 131 complete: function(config) {
119 config.node.style.position = 'absolute'; 132 var sectionWrapper = config.node;
120 config.node.style.top = 133 sectionWrapper.classList.remove('neon-animating');
121 -config.node.$.header.getBoundingClientRect().height + 'px'; 134 sectionWrapper.classList.add('expanded');
122 config.node.style.bottom = 0; 135 sectionWrapper.expandContainer.classList.add('expanded');
136
137 // Iterate through sibling elements of the same type. This event fires
138 // on itself as well, but that is benign.
139 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.
140 for (var i = 0; i < siblings.length; ++i) {
141 if (siblings[i].tagName == sectionWrapper.tagName)
142 siblings[i].fire('expand-animation-complete');
143 }
144
145 sectionWrapper.expandContainer.scrollTop = 0;
123 } 146 }
124 }); 147 });
125 148
126 Polymer({ 149 Polymer({
127 is: 'collapse-card-animation', 150 is: 'collapse-card-animation',
128 151
129 behaviors: [ 152 behaviors: [
130 Polymer.NeonAnimationBehavior 153 Polymer.NeonAnimationBehavior
131 ], 154 ],
132 155
133 configure: function(config) { 156 configure: function(config) {
134 var node = config.node; 157 var sectionWrapper = config.node;
158 var oldRect = sectionWrapper.expandContainer.getBoundingClientRect();
135 159
136 var oldRect = node.getBoundingClientRect(); 160 sectionWrapper.classList.remove('expanded');
161 sectionWrapper.expandContainer.classList.remove('expanded');
137 162
138 // Temporarily set position to static to determine new height. 163 // Get the placeholder coordinates before reflowing.
139 node.style.position = ''; 164 var newRect = sectionWrapper.$.placeholder.getBoundingClientRect();
140 var newTop = node.getBoundingClientRect().top;
141 165
142 // TODO(tommycli): This value is undefined when the user navigates to a 166 sectionWrapper.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 167
147 node.style.position = 'fixed'; 168 this._effect = new KeyframeEffect(sectionWrapper.$.card, [
148
149 this._effect = new KeyframeEffect(node, [
150 {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'}, 169 {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'},
151 {'top': newTop + 'px', 'height': newHeight + 'px'}, 170 {'top': newRect.top + 'px', 'height': newRect.height + 'px'},
152 ], this.timingFromConfig(config)); 171 ], this.timingFromConfig(config));
153 return this._effect; 172 return this._effect;
154 }, 173 },
155 174
156 complete: function(config) { 175 complete: function(config) {
157 config.node.style.position = ''; 176 config.node.classList.remove('neon-animating');
158 config.node.style.zIndex = '0';
159 } 177 }
160 }); 178 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698