OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 New tab page | 6 * @fileoverview New tab page |
7 * This is the main code for the new tab page used by touch-enabled Chrome | 7 * This is the main code for the new tab page used by touch-enabled Chrome |
8 * browsers. NewTabView manages page list and dot list and handles apps pages | 8 * browsers. NewTabView manages page list and dot list and handles apps pages |
9 * callbacks from backend. | 9 * callbacks from backend. |
10 * | 10 * |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 function closeFunc(e) { | 841 function closeFunc(e) { |
842 if (opt_closeHandler) | 842 if (opt_closeHandler) |
843 opt_closeHandler(); | 843 opt_closeHandler(); |
844 hideNotification(); | 844 hideNotification(); |
845 } | 845 } |
846 | 846 |
847 document.querySelector('#notification button').onclick = closeFunc; | 847 document.querySelector('#notification button').onclick = closeFunc; |
848 document.addEventListener('dragstart', closeFunc); | 848 document.addEventListener('dragstart', closeFunc); |
849 | 849 |
850 notificationContainer.hidden = false; | 850 notificationContainer.hidden = false; |
851 showNotificationOnCurrentPage(); | 851 window.setTimeout(function() { |
852 | 852 notificationContainer.classList.remove('inactive'); |
853 newTabView.cardSlider.frame.addEventListener( | 853 }, 0); |
854 'cardSlider:card_change_ended', onCardChangeEnded); | |
855 | 854 |
856 var timeout = opt_timeout || 10000; | 855 var timeout = opt_timeout || 10000; |
857 notificationTimeout = window.setTimeout(hideNotification, timeout); | 856 notificationTimeout = window.setTimeout(hideNotification, timeout); |
858 } | 857 } |
859 | 858 |
860 /** | 859 /** |
861 * Hide the notification bubble. | 860 * Hide the notification bubble. |
862 */ | 861 */ |
863 function hideNotification() { | 862 function hideNotification() { |
864 notificationContainer.classList.add('inactive'); | 863 notificationContainer.classList.add('inactive'); |
865 | |
866 newTabView.cardSlider.frame.removeEventListener( | |
867 'cardSlider:card_change_ended', onCardChangeEnded); | |
868 } | 864 } |
869 | 865 |
870 /** | 866 /** |
871 * Happens when 1 or more consecutive card changes end. | |
872 * @param {Event} e The cardSlider:card_change_ended event. | |
873 */ | |
874 function onCardChangeEnded(e) { | |
875 // If we ended on the same page as we started, ignore. | |
876 if (newTabView.cardSlider.currentCardValue.notification) | |
877 return; | |
878 | |
879 // Hide the notification the old page. | |
880 notificationContainer.classList.add('card-changed'); | |
881 | |
882 showNotificationOnCurrentPage(); | |
883 } | |
884 | |
885 /** | |
886 * Move and show the notification on the current page. | |
887 */ | |
888 function showNotificationOnCurrentPage() { | |
889 var page = newTabView.cardSlider.currentCardValue; | |
890 doWhenAllSectionsReady(function() { | |
891 if (page != newTabView.cardSlider.currentCardValue) | |
892 return; | |
893 | |
894 // NOTE: This moves the notification to inside of the current page. | |
895 page.notification = notificationContainer; | |
896 | |
897 // Reveal the notification and instruct it to hide itself if ignored. | |
898 notificationContainer.classList.remove('inactive'); | |
899 | |
900 // Gives the browser time to apply this rule before we remove it (causing | |
901 // a transition). | |
902 window.setTimeout(function() { | |
903 notificationContainer.classList.remove('card-changed'); | |
904 }, 0); | |
905 }); | |
906 } | |
907 | |
908 /** | |
909 * When done fading out, set hidden to true so the notification can't be | 867 * When done fading out, set hidden to true so the notification can't be |
910 * tabbed to or clicked. | 868 * tabbed to or clicked. |
911 * @param {Event} e The webkitTransitionEnd event. | 869 * @param {Event} e The webkitTransitionEnd event. |
912 */ | 870 */ |
913 function onNotificationTransitionEnd(e) { | 871 function onNotificationTransitionEnd(e) { |
914 if (notificationContainer.classList.contains('inactive')) | 872 if (notificationContainer.classList.contains('inactive')) |
915 notificationContainer.hidden = true; | 873 notificationContainer.hidden = true; |
916 } | 874 } |
917 | 875 |
918 function setRecentlyClosedTabs(data) { | 876 function setRecentlyClosedTabs(data) { |
919 newTabView.recentlyClosedPage.data = data; | 877 newTabView.recentlyClosedPage.setData(data); |
920 } | 878 } |
921 | 879 |
922 function setMostVisitedPages(data, hasBlacklistedUrls) { | 880 function setMostVisitedPages(data, hasBlacklistedUrls) { |
923 newTabView.mostVisitedPage.data = data; | 881 newTabView.mostVisitedPage.setData(data); |
924 cr.dispatchSimpleEvent(document, 'sectionready', true, true); | 882 cr.dispatchSimpleEvent(document, 'sectionready', true, true); |
925 } | 883 } |
926 | 884 |
927 function getThumbnailUrl(url) { | 885 function getThumbnailUrl(url) { |
928 return 'chrome://thumb/' + url; | 886 return 'chrome://thumb/' + url; |
929 } | 887 } |
930 | 888 |
931 /** | 889 /** |
932 * Updates the text displayed in the login container. If there is no text then | 890 * Updates the text displayed in the login container. If there is no text then |
933 * the login container is hidden. | 891 * the login container is hidden. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 setRecentlyClosedTabs: setRecentlyClosedTabs, | 996 setRecentlyClosedTabs: setRecentlyClosedTabs, |
1039 showNotification: showNotification, | 997 showNotification: showNotification, |
1040 themeChanged: themeChanged, | 998 themeChanged: themeChanged, |
1041 updateLogin: updateLogin | 999 updateLogin: updateLogin |
1042 }; | 1000 }; |
1043 }); | 1001 }); |
1044 | 1002 |
1045 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 1003 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
1046 | 1004 |
1047 var toCssPx = cr.ui.toCssPx; | 1005 var toCssPx = cr.ui.toCssPx; |
OLD | NEW |