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

Side by Side Diff: chrome/browser/resources/new_new_tab.js

Issue 3346006: NTP: Add transitions. (Closed)
Patch Set: formatting Created 10 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/new_new_tab.css ('k') | chrome/browser/resources/ntp/apps.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // To avoid creating tons of unnecessary nodes. We assume we cannot fit more 5 // To avoid creating tons of unnecessary nodes. We assume we cannot fit more
6 // than this many items in the miniview. 6 // than this many items in the miniview.
7 var MAX_MINIVIEW_ITEMS = 15; 7 var MAX_MINIVIEW_ITEMS = 15;
8 8
9 // Extra spacing at the top of the layout. 9 // Extra spacing at the top of the layout.
10 var LAYOUT_SPACING_TOP = 25; 10 var LAYOUT_SPACING_TOP = 25;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 91
92 var oldLayoutMode = layoutMode; 92 var oldLayoutMode = layoutMode;
93 var b = useSmallGrid(); 93 var b = useSmallGrid();
94 layoutMode = b ? LayoutMode.SMALL : LayoutMode.NORMAL 94 layoutMode = b ? LayoutMode.SMALL : LayoutMode.NORMAL
95 95
96 if (layoutMode != oldLayoutMode){ 96 if (layoutMode != oldLayoutMode){
97 mostVisited.useSmallGrid = b; 97 mostVisited.useSmallGrid = b;
98 mostVisited.layout(); 98 mostVisited.layout();
99 renderRecentlyClosed(); 99 renderRecentlyClosed();
100 updateAllMiniviewClippings();
100 } 101 }
101 102
102 layoutSections(); 103 layoutSections();
103 } 104 }
104 105
105 // Stores some information about each section necessary to layout. A new 106 // Stores some information about each section necessary to layout. A new
106 // instance is constructed for each section on each layout. 107 // instance is constructed for each section on each layout.
107 function SectionLayoutInfo(section) { 108 function SectionLayoutInfo(section) {
108 this.section = section; 109 this.section = section;
109 this.header = section.getElementsByTagName('h2')[0]; 110 this.header = section.getElementsByTagName('h2')[0];
(...skipping 10 matching lines...) Expand all
120 // Get all sections to be layed out. 121 // Get all sections to be layed out.
121 SectionLayoutInfo.getAll = function() { 122 SectionLayoutInfo.getAll = function() {
122 var sections = document.querySelectorAll('.section:not(.disabled)'); 123 var sections = document.querySelectorAll('.section:not(.disabled)');
123 var result = []; 124 var result = [];
124 for (var i = 0, section; section = sections[i]; i++) { 125 for (var i = 0, section; section = sections[i]; i++) {
125 result.push(new SectionLayoutInfo(section)); 126 result.push(new SectionLayoutInfo(section));
126 } 127 }
127 return result; 128 return result;
128 }; 129 };
129 130
131 // Ensure the miniview sections don't have any clipped items.
132 function updateMiniviewClipping(miniview) {
133 var clipped = false;
134 for (var j = 0, item; item = miniview.children[j]; j++) {
135 item.style.display = '';
136 if (clipped ||
137 (item.offsetLeft + item.offsetWidth) > miniview.offsetWidth) {
138 item.style.display = 'none';
139 clipped = true;
140 } else {
141 item.style.display = '';
142 }
143 }
144 }
145
146 // Ensure none of the miniviews have any clipped items.
147 function updateAllMiniviewClippings() {
148 var miniviews = document.querySelectorAll('.section.hidden .miniview');
149 for (var i = 0, miniview; miniview = miniviews[i]; i++) {
150 updateMiniviewClipping(miniview);
151 }
152 }
153
130 // Layout the sections in a modified accordian. The header and miniview, if 154 // Layout the sections in a modified accordian. The header and miniview, if
131 // visible are fixed within the viewport. If there is an expanded section, its 155 // visible are fixed within the viewport. If there is an expanded section, its
132 // it scrolls. 156 // it scrolls.
133 // 157 //
134 // ============================= 158 // =============================
135 // | collapsed section | <- Any collapsed sections are fixed position. 159 // | collapsed section | <- Any collapsed sections are fixed position.
136 // | and miniview | 160 // | and miniview |
137 // |---------------------------| 161 // |---------------------------|
138 // | expanded section | 162 // | expanded section |
139 // | | <- There can be one expanded section and it 163 // | | <- There can be one expanded section and it
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 document.body.style.height = ''; 233 document.body.style.height = '';
210 } 234 }
211 } 235 }
212 236
213 // Now position all the elements. 237 // Now position all the elements.
214 var y = LAYOUT_SPACING_TOP; 238 var y = LAYOUT_SPACING_TOP;
215 for (i = 0, section; section = sections[i]; i++) { 239 for (i = 0, section; section = sections[i]; i++) {
216 section.section.style.top = y + 'px'; 240 section.section.style.top = y + 'px';
217 y += section.fixedHeight; 241 y += section.fixedHeight;
218 242
219 if (section.maxiview) { 243 if (section.maxiview && section == expandedSection) {
220 section.maxiview.style.top = y + 'px'; 244 section.maxiview.style.top = y + 'px';
221 245 updateMask(section.maxiview, expandedSectionHeight);
222 if (section == expandedSection)
223 updateMask(section.maxiview, expandedSectionHeight);
224 } 246 }
225 247
226 if (section == expandedSection) 248 if (section == expandedSection)
227 y += expandedSectionHeight; 249 y += expandedSectionHeight;
228 } 250 }
229 } 251 }
230 252
231 function updateMask(maxiview, visibleHeightPx) { 253 function updateMask(maxiview, visibleHeightPx) {
232 // We want to end up with 10px gradients at the top and bottom of 254 // We want to end up with 10px gradients at the top and bottom of
233 // visibleHeight, but webkit-mask only supports expression in terms of 255 // visibleHeight, but webkit-mask only supports expression in terms of
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 306 }
285 307
286 function showSection(section) { 308 function showSection(section) {
287 if (!(section & shownSections)) { 309 if (!(section & shownSections)) {
288 shownSections |= section; 310 shownSections |= section;
289 var el = getSectionElement(section); 311 var el = getSectionElement(section);
290 if (el) { 312 if (el) {
291 el.classList.remove('hidden'); 313 el.classList.remove('hidden');
292 314
293 var maxiview = getSectionMaxiview(el); 315 var maxiview = getSectionMaxiview(el);
294 if (maxiview) 316 if (maxiview) {
317 maxiview.classList.remove('hiding');
295 maxiview.classList.remove('hidden'); 318 maxiview.classList.remove('hidden');
319 }
296 } 320 }
297 321
298 switch (section) { 322 switch (section) {
299 case Section.THUMB: 323 case Section.THUMB:
300 mostVisited.visible = true; 324 mostVisited.visible = true;
301 mostVisited.layout(); 325 mostVisited.layout();
302 break; 326 break;
303 } 327 }
304 } 328 }
305 } 329 }
306 330
307 function hideSection(section) { 331 function hideSection(section) {
308 if (section & shownSections) { 332 if (section & shownSections) {
309 shownSections &= ~section; 333 shownSections &= ~section;
310 334
311 switch (section) { 335 switch (section) {
312 case Section.THUMB: 336 case Section.THUMB:
313 mostVisited.visible = false; 337 mostVisited.visible = false;
314 mostVisited.layout(); 338 mostVisited.layout();
315 break; 339 break;
316 } 340 }
317 341
318 var el = getSectionElement(section); 342 var el = getSectionElement(section);
319 if (el) { 343 if (el) {
320 el.classList.add('hidden'); 344 el.classList.add('hidden');
321 345
322 var maxiview = getSectionMaxiview(el); 346 var maxiview = getSectionMaxiview(el);
323 if (maxiview) 347 if (maxiview)
324 maxiview.classList.add('hidden'); 348 maxiview.classList.add('hiding');
349
350 var miniview = el.getElementsByClassName('miniview')[0];
351 if (miniview)
352 updateMiniviewClipping(miniview);
325 } 353 }
326 } 354 }
327 } 355 }
328 356
357 window.addEventListener('webkitTransitionEnd', function(e) {
358 if (e.target.classList.contains('hiding'))
359 e.target.classList.add('hidden');
360
361 document.documentElement.setAttribute("enable-section-animations", "false");
362 });
363
329 /** 364 /**
330 * Callback when the shown sections changes in another NTP. 365 * Callback when the shown sections changes in another NTP.
331 * @param {number} newShownSections Bitmask of the shown sections. 366 * @param {number} newShownSections Bitmask of the shown sections.
332 */ 367 */
333 function setShownSections(newShownSections) { 368 function setShownSections(newShownSections) {
334 for (var key in Section) { 369 for (var key in Section) {
335 if (newShownSections & Section[key]) 370 if (newShownSections & Section[key])
336 showSection(Section[key]); 371 showSection(Section[key]);
337 else 372 else
338 hideSection(Section[key]); 373 hideSection(Section[key]);
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 return; 829 return;
795 } 830 }
796 831
797 p = p.parentNode; 832 p = p.parentNode;
798 if (!getSectionMaxiview(p)) { 833 if (!getSectionMaxiview(p)) {
799 return; 834 return;
800 } 835 }
801 836
802 var section = p.getAttribute('section'); 837 var section = p.getAttribute('section');
803 if (section) { 838 if (section) {
839 // We set it back in webkitTransitionEnd.
840 document.documentElement.setAttribute("enable-section-animations", "true");
804 if (shownSections & Section[section]) { 841 if (shownSections & Section[section]) {
805 hideSection(Section[section]); 842 hideSection(Section[section]);
806 } else { 843 } else {
807 for (var p in Section) { 844 for (var p in Section) {
808 if (p == section) 845 if (p == section)
809 showSection(Section[p]); 846 showSection(Section[p]);
810 else 847 else
811 hideSection(Section[p]); 848 hideSection(Section[p]);
812 } 849 }
813 } 850 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 window.setTimeout(function() { 1114 window.setTimeout(function() {
1078 mostVisited.ensureSmallGridCorrect(); 1115 mostVisited.ensureSmallGridCorrect();
1079 document.body.classList.remove('loading'); 1116 document.body.classList.remove('loading');
1080 }, 1); 1117 }, 1);
1081 1118
1082 // Only show the first run notification if first run. 1119 // Only show the first run notification if first run.
1083 if (firstRun) { 1120 if (firstRun) {
1084 showFirstRunNotification(); 1121 showFirstRunNotification();
1085 } 1122 }
1086 } 1123 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/new_new_tab.css ('k') | chrome/browser/resources/ntp/apps.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698