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

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

Issue 150194: Fix performance issues with NNTP.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/new_new_tab.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 // Helpers 2 // Helpers
3 3
4 function $(id) { 4 function $(id) {
5 return document.getElementById(id); 5 return document.getElementById(id);
6 } 6 }
7 7
8 // TODO(arv): Remove these when classList is available in HTML5. 8 // TODO(arv): Remove these when classList is available in HTML5.
9 // https://bugs.webkit.org/show_bug.cgi?id=20709 9 // https://bugs.webkit.org/show_bug.cgi?id=20709
10 function hasClass(el, name) { 10 function hasClass(el, name) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 function bind(fn, selfObj, var_args) { 59 function bind(fn, selfObj, var_args) {
60 var boundArgs = Array.prototype.slice.call(arguments, 2); 60 var boundArgs = Array.prototype.slice.call(arguments, 2);
61 return function() { 61 return function() {
62 var args = Array.prototype.slice.call(arguments); 62 var args = Array.prototype.slice.call(arguments);
63 args.unshift.apply(args, boundArgs); 63 args.unshift.apply(args, boundArgs);
64 return fn.apply(selfObj, args); 64 return fn.apply(selfObj, args);
65 } 65 }
66 } 66 }
67 67
68 var loading = true;
68 var mostVisitedData = []; 69 var mostVisitedData = [];
69 var gotMostVisited = false; 70 var gotMostVisited = false;
70 var gotShownSections = false; 71 var gotShownSections = false;
71 72
72 function mostVisitedPages(data) { 73 function mostVisitedPages(data) {
73 logEvent('received most visited pages'); 74 logEvent('received most visited pages');
74 75
75 // We append the class name with the "filler" so that we can style fillers 76 // We append the class name with the "filler" so that we can style fillers
76 // differently. 77 // differently.
77 var maxItems = 8; 78 var maxItems = 8;
(...skipping 16 matching lines...) Expand all
94 data.length = Math.min(data.length, 5); 95 data.length = Math.min(data.length, 5);
95 processData('#download-items', data); 96 processData('#download-items', data);
96 } 97 }
97 98
98 function recentlyClosedTabs(data) { 99 function recentlyClosedTabs(data) {
99 logEvent('received recently closed tabs'); 100 logEvent('received recently closed tabs');
100 data.length = Math.min(data.length, 5); 101 data.length = Math.min(data.length, 5);
101 processData('#tab-items', data); 102 processData('#tab-items', data);
102 } 103 }
103 104
104 function onShownSections(m) { 105 function onShownSections(mask) {
105 logEvent('received shown sections'); 106 logEvent('received shown sections');
106 setShownSections(m); 107 if (mask != shownSections) {
108 shownSections = mask;
109 // No need to relayout these unless changed.
110 mostVisited.updateDisplayMode();
111 layoutMostVisited();
112 layoutLowerSections();
113 updateOptionMenu();
114 }
115
107 gotShownSections = true; 116 gotShownSections = true;
108 onDataLoaded(); 117 onDataLoaded();
109 } 118 }
110 119
111 function saveShownSections() { 120 function saveShownSections() {
112 chrome.send('setShownSections', [String(shownSections)]); 121 chrome.send('setShownSections', [String(shownSections)]);
113 } 122 }
114 123
115 function tips(data) { 124 function tips(data) {
116 logEvent('received tips data'); 125 logEvent('received tips data');
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 * This matches the Section enum in ../dom_ui/shown_sections_handler.h 329 * This matches the Section enum in ../dom_ui/shown_sections_handler.h
321 * @enum {number} 330 * @enum {number}
322 */ 331 */
323 var Section = { 332 var Section = {
324 THUMB: 1, 333 THUMB: 1,
325 LIST: 2, 334 LIST: 2,
326 RECENT: 4, 335 RECENT: 4,
327 TIPS: 8 336 TIPS: 8
328 }; 337 };
329 338
330 var shownSections = Section.RECENT | Section.TIPS; 339 var shownSections = Section.THUMB | Section.RECENT | Section.TIPS;
331 340
332 function showSection(section) { 341 function showSection(section) {
333 if (!(section & shownSections)) { 342 if (!(section & shownSections)) {
334 // THUMBS and LIST are mutually exclusive. 343 // THUMBS and LIST are mutually exclusive.
335 if (section == Section.THUMB) { 344 if (section == Section.THUMB) {
336 hideSection(Section.LIST); 345 hideSection(Section.LIST);
337 } else if (section == Section.LIST) { 346 } else if (section == Section.LIST) {
338 hideSection(Section.THUMB); 347 hideSection(Section.THUMB);
339 } 348 }
340 349
(...skipping 25 matching lines...) Expand all
366 // we are hiding one of them so if the other one is visible it is now 375 // we are hiding one of them so if the other one is visible it is now
367 // {@code large}. 376 // {@code large}.
368 if (shownSections & Section.RECENT) { 377 if (shownSections & Section.RECENT) {
369 recentChangedSize(large); 378 recentChangedSize(large);
370 } else if (shownSections & Section.TIPS) { 379 } else if (shownSections & Section.TIPS) {
371 tipsChangedSize(large); 380 tipsChangedSize(large);
372 } 381 }
373 } 382 }
374 } 383 }
375 384
376 /**
377 * This is called when we get the shown sections pref from the backend.
378 */
379 function setShownSections(mask) {
380 if (mask != shownSections) {
381 shownSections = mask;
382 mostVisited.updateDisplayMode();
383 layoutMostVisited();
384 layoutLowerSections();
385 updateOptionMenu();
386 }
387 }
388
389 var mostVisited = { 385 var mostVisited = {
390 getItem: function(el) { 386 getItem: function(el) {
391 return findAncestorByClass(el, 'thumbnail-container'); 387 return findAncestorByClass(el, 'thumbnail-container');
392 }, 388 },
393 389
394 getHref: function(el) { 390 getHref: function(el) {
395 return el.href; 391 return el.href;
396 }, 392 },
397 393
398 togglePinned: function(el) { 394 togglePinned: function(el) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 return localStrings.getString('closedwindowsingle'); 585 return localStrings.getString('closedwindowsingle');
590 return localStrings.formatString('closedwindowmultiple', numTabs); 586 return localStrings.formatString('closedwindowmultiple', numTabs);
591 } 587 }
592 588
593 /** 589 /**
594 * We need both most visited and the shown sections to be considered loaded. 590 * We need both most visited and the shown sections to be considered loaded.
595 * @return {boolean} 591 * @return {boolean}
596 */ 592 */
597 function onDataLoaded() { 593 function onDataLoaded() {
598 if (gotMostVisited && gotShownSections) { 594 if (gotMostVisited && gotShownSections) {
595 loading = false;
599 // Remove class name in a timeout so that changes done in this JS thread are 596 // Remove class name in a timeout so that changes done in this JS thread are
600 // not animated. 597 // not animated.
601 window.setTimeout(function() { 598 window.setTimeout(function() {
602 removeClass(document.body, 'loading'); 599 removeClass(document.body, 'loading');
603 }, 10); 600 }, 10);
604 } 601 }
605 } 602 }
606 603
607 // Theme related 604 // Theme related
608 605
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 // We apply the size class here so that we don't trigger layout animations 649 // We apply the size class here so that we don't trigger layout animations
653 // onload. 650 // onload.
654 651
655 handleWindowResize(null, true); 652 handleWindowResize(null, true);
656 653
657 var localStrings = new LocalStrings(); 654 var localStrings = new LocalStrings();
658 655
659 /////////////////////////////////////////////////////////////////////////////// 656 ///////////////////////////////////////////////////////////////////////////////
660 // Things we know are not needed at startup go below here 657 // Things we know are not needed at startup go below here
661 658
659 function afterTransition(f) {
660 if (loading) {
661 // Make sure we do not use a timer during load since it slows down the UI.
662 f();
663 } else {
664 // The duration of all transitions are 500ms
665 window.setTimeout(f, 500);
666 }
667 }
668
662 // Notification 669 // Notification
663 670
664 function afterTransition(f) {
665 // The duration of all transitions are 500ms
666 window.setTimeout(f, 500);
667 }
668
669 function showNotification(text, actionText, f) { 671 function showNotification(text, actionText, f) {
670 var notificationElement = $('notification'); 672 var notificationElement = $('notification');
671 var actionLink = notificationElement.querySelector('.link'); 673 var actionLink = notificationElement.querySelector('.link');
672 notificationElement.firstElementChild.textContent = text; 674 notificationElement.firstElementChild.textContent = text;
673 675
674 actionLink.textContent = actionText; 676 actionLink.textContent = actionText;
675 actionLink.onclick = function() { 677 actionLink.onclick = function() {
676 f(); 678 f();
677 removeClass(notificationElement, 'show'); 679 removeClass(notificationElement, 'show');
678 // Since we have a :hover rule to not hide the notification banner when the 680 // Since we have a :hover rule to not hide the notification banner when the
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 if (this.isMenuShown()) { 750 if (this.isMenuShown()) {
749 this.hideMenu(); 751 this.hideMenu();
750 } else { 752 } else {
751 this.showMenu(); 753 this.showMenu();
752 } 754 }
753 }, 755 },
754 756
755 handleMouseOver: function(e) { 757 handleMouseOver: function(e) {
756 var el = e.target; 758 var el = e.target;
757 var index = Array.prototype.indexOf.call(this.menu.children, el); 759 var index = Array.prototype.indexOf.call(this.menu.children, el);
758 console.log(el, index);
759 this.setSelectedIndex(index); 760 this.setSelectedIndex(index);
760 }, 761 },
761 762
762 handleMouseOut: function(e) { 763 handleMouseOut: function(e) {
763 this.setSelectedIndex(-1); 764 this.setSelectedIndex(-1);
764 }, 765 },
765 766
766 handleMouseUp: function(e) { 767 handleMouseUp: function(e) {
767 var item = this.getSelectedItem(); 768 var item = this.getSelectedItem();
768 if (item) { 769 if (item) {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 el.addEventListener('dragover', bind(this.handleDragOver, this)); 1094 el.addEventListener('dragover', bind(this.handleDragOver, this));
1094 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); 1095 el.addEventListener('dragleave', bind(this.handleDragLeave, this));
1095 el.addEventListener('drop', bind(this.handleDrop, this)); 1096 el.addEventListener('drop', bind(this.handleDrop, this));
1096 el.addEventListener('dragend', bind(this.handleDragEnd, this)); 1097 el.addEventListener('dragend', bind(this.handleDragEnd, this));
1097 el.addEventListener('drag', bind(this.handleDrag, this)); 1098 el.addEventListener('drag', bind(this.handleDrag, this));
1098 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); 1099 el.addEventListener('mousedown', bind(this.handleMouseDown, this));
1099 } 1100 }
1100 }; 1101 };
1101 1102
1102 dnd.init(); 1103 dnd.init();
OLDNEW
« no previous file with comments | « chrome/browser/resources/new_new_tab.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698