OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 6 /** |
7 * @fileoverview The local InstantExtended NTP. | 7 * @fileoverview The local InstantExtended NTP. |
8 */ | 8 */ |
9 | 9 |
| 10 |
10 /** | 11 /** |
11 * Controls rendering the new tab page for InstantExtended. | 12 * Controls rendering the new tab page for InstantExtended. |
12 * @return {Object} A limited interface for testing the local NTP. | 13 * @return {Object} A limited interface for testing the local NTP. |
13 */ | 14 */ |
14 function LocalNTP() { | 15 function LocalNTP() { |
15 <include src="../../../../ui/webui/resources/js/assert.js"> | 16 <include src="../../../../ui/webui/resources/js/assert.js"> |
16 | 17 <include src="window_disposition_util.js"> |
17 | 18 |
18 | 19 |
19 /** | 20 /** |
20 * Enum for classnames. | 21 * Enum for classnames. |
21 * @enum {string} | 22 * @enum {string} |
22 * @const | 23 * @const |
23 */ | 24 */ |
24 var CLASSES = { | 25 var CLASSES = { |
25 ALTERNATE_LOGO: 'alternate-logo', // Shows white logo if required by theme | 26 ALTERNATE_LOGO: 'alternate-logo', // Shows white logo if required by theme |
26 BLACKLIST: 'mv-blacklist', // triggers tile blacklist animation | 27 BLACKLIST: 'mv-blacklist', // triggers tile blacklist animation |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 95 |
95 /** | 96 /** |
96 * The JavaScript button event value for a middle click. | 97 * The JavaScript button event value for a middle click. |
97 * @type {number} | 98 * @type {number} |
98 * @const | 99 * @const |
99 */ | 100 */ |
100 var MIDDLE_MOUSE_BUTTON = 1; | 101 var MIDDLE_MOUSE_BUTTON = 1; |
101 | 102 |
102 | 103 |
103 /** | 104 /** |
104 * Possible behaviors for navigateContentWindow. | |
105 * @enum {number} | |
106 */ | |
107 var WindowOpenDisposition = { | |
108 CURRENT_TAB: 1, | |
109 NEW_BACKGROUND_TAB: 2 | |
110 }; | |
111 | |
112 | |
113 /** | |
114 * The container for the tile elements. | 105 * The container for the tile elements. |
115 * @type {Element} | 106 * @type {Element} |
116 */ | 107 */ |
117 var tilesContainer; | 108 var tilesContainer; |
118 | 109 |
119 | 110 |
120 /** | 111 /** |
121 * The notification displayed when a page is blacklisted. | 112 * The notification displayed when a page is blacklisted. |
122 * @type {Element} | 113 * @type {Element} |
123 */ | 114 */ |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 * @return {Tile} The new Tile. | 526 * @return {Tile} The new Tile. |
536 */ | 527 */ |
537 function createTile(page, position) { | 528 function createTile(page, position) { |
538 var tileElement = document.createElement('div'); | 529 var tileElement = document.createElement('div'); |
539 tileElement.classList.add(CLASSES.TILE); | 530 tileElement.classList.add(CLASSES.TILE); |
540 | 531 |
541 if (page) { | 532 if (page) { |
542 var rid = page.rid; | 533 var rid = page.rid; |
543 tileElement.classList.add(CLASSES.PAGE); | 534 tileElement.classList.add(CLASSES.PAGE); |
544 | 535 |
545 var navigateFunction = function() { | 536 var navigateFunction = function(e) { |
546 ntpApiHandle.navigateContentWindow(rid); | 537 e.preventDefault(); |
| 538 ntpApiHandle.navigateContentWindow(rid, getDispositionFromEvent(e)); |
547 }; | 539 }; |
548 | 540 |
549 // The click handler for navigating to the page identified by the RID. | 541 // The click handler for navigating to the page identified by the RID. |
550 tileElement.addEventListener('click', navigateFunction); | 542 tileElement.addEventListener('click', navigateFunction); |
551 | 543 |
552 // Make thumbnails tab-accessible. | 544 // Make thumbnails tab-accessible. |
553 tileElement.setAttribute('tabindex', '1'); | 545 tileElement.setAttribute('tabindex', '1'); |
554 registerKeyHandler(tileElement, KEYCODE.ENTER, navigateFunction); | 546 registerKeyHandler(tileElement, KEYCODE.ENTER, navigateFunction); |
555 | 547 |
556 // The iframe which renders the page title. | 548 // The iframe which renders the page title. |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 * @return {Object} the handle to the embeddedSearch API. | 905 * @return {Object} the handle to the embeddedSearch API. |
914 */ | 906 */ |
915 function getEmbeddedSearchApiHandle() { | 907 function getEmbeddedSearchApiHandle() { |
916 if (window.cideb) | 908 if (window.cideb) |
917 return window.cideb; | 909 return window.cideb; |
918 if (window.chrome && window.chrome.embeddedSearch) | 910 if (window.chrome && window.chrome.embeddedSearch) |
919 return window.chrome.embeddedSearch; | 911 return window.chrome.embeddedSearch; |
920 return null; | 912 return null; |
921 } | 913 } |
922 | 914 |
923 /** | |
924 * Extract the desired navigation behavior from a click button. | |
925 * @param {number} button The Event#button property of a click event. | |
926 * @return {WindowOpenDisposition} The desired behavior for | |
927 * navigateContentWindow. | |
928 */ | |
929 function getDispositionFromClickButton(button) { | |
930 if (button == MIDDLE_MOUSE_BUTTON) | |
931 return WindowOpenDisposition.NEW_BACKGROUND_TAB; | |
932 return WindowOpenDisposition.CURRENT_TAB; | |
933 } | |
934 | |
935 | 915 |
936 /** | 916 /** |
937 * Prepares the New Tab Page by adding listeners, rendering the current | 917 * Prepares the New Tab Page by adding listeners, rendering the current |
938 * theme, the most visited pages section, and Google-specific elements for a | 918 * theme, the most visited pages section, and Google-specific elements for a |
939 * Google-provided page. | 919 * Google-provided page. |
940 */ | 920 */ |
941 function init() { | 921 function init() { |
942 tilesContainer = $(IDS.TILES); | 922 tilesContainer = $(IDS.TILES); |
943 notification = $(IDS.NOTIFICATION); | 923 notification = $(IDS.NOTIFICATION); |
944 attribution = $(IDS.ATTRIBUTION); | 924 attribution = $(IDS.ATTRIBUTION); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 | 1040 |
1061 return { | 1041 return { |
1062 init: init, | 1042 init: init, |
1063 listen: listen | 1043 listen: listen |
1064 }; | 1044 }; |
1065 } | 1045 } |
1066 | 1046 |
1067 if (!window.localNTPUnitTest) { | 1047 if (!window.localNTPUnitTest) { |
1068 LocalNTP().listen(); | 1048 LocalNTP().listen(); |
1069 } | 1049 } |
OLD | NEW |