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

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

Issue 5705004: [SYNC] Sessions datatype refactor. Most things related to sessions under-the-... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Tests! And the refactors that helped them. And Rebase. And Comments. Created 10 years 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
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 142
143 function renderForeignSessions() { 143 function renderForeignSessions() {
144 // Remove all existing items and create new items. 144 // Remove all existing items and create new items.
145 var sessionElement = $('foreign-sessions'); 145 var sessionElement = $('foreign-sessions');
146 var parentSessionElement = sessionElement.lastElementChild; 146 var parentSessionElement = sessionElement.lastElementChild;
147 parentSessionElement.textContent = ''; 147 parentSessionElement.textContent = '';
148 148
149 // For each client, create entries and append the lists together. 149 // For each client, create entries and append the lists together.
150 sessionItems.forEach(function(item, i) { 150 sessionItems.forEach(function(item, i) {
151 // TODO(zea): Get real client names. See issue 59672 151 // TODO(zea): Get real client names. See crbug/59672.
152 var name = 'Client ' + i; 152 var name = 'Client ' + i;
153 parentSessionElement.appendChild(createForeignSession(item, name)); 153 parentSessionElement.appendChild(createForeignSession(item, name));
154 }); 154 });
155 155
156 layoutForeignSessions(); 156 layoutForeignSessions();
157 } 157 }
158 158
159 function layoutForeignSessions() { 159 function layoutForeignSessions() {
160 var sessionElement = $('foreign-sessions'); 160 var sessionElement = $('foreign-sessions');
161 // We cannot use clientWidth here since the width has a transition. 161 // We cannot use clientWidth here since the width has a transition.
162 var availWidth = useSmallGrid() ? 692 : 920; 162 var availWidth = useSmallGrid() ? 692 : 920;
163 var parentSessEl = sessionElement.lastElementChild; 163 var parentSessEl = sessionElement.lastElementChild;
164 164
165 if (parentSessEl.hasChildNodes()) { 165 if (parentSessEl.hasChildNodes()) {
166 sessionElement.classList.remove('disabled'); 166 sessionElement.classList.remove('disabled');
167 } else { 167 } else {
168 sessionElement.classList.add('disabled'); 168 sessionElement.classList.add('disabled');
169 } 169 }
170 } 170 }
171 171
172 function createForeignSession(client, name) { 172 function createForeignSession(client, name) {
173 // Vertically stack the windows in a client. 173 // Vertically stack the windows in a client.
174 var stack = document.createElement('div'); 174 var stack = document.createElement('div');
175 stack.className = 'foreign-session-client'; 175 stack.className = 'foreign-session-client item link';
176 stack.textContent = name; 176 stack.textContent = name;
177 stack.sessionTag = client[0].sessionTag;
177 178
178 client.forEach(function(win) { 179 client.forEach(function(win, i) {
179 // We know these are lists of multiple tabs, don't need the special case for 180 // Create a window entry.
180 // single url + favicon. 181 var winSpan = document.createElement('span');
181 var el = document.createElement('p'); 182 var winEl = document.createElement('p');
182 el.className = 'item link window'; 183 winEl.className = 'item link window';
183 el.tabItems = win.tabs; 184 winEl.tabItems = win.tabs;
184 el.tabIndex = 0; 185 winEl.tabIndex = 0;
185 el.textContent = formatTabsText(win.tabs.length); 186 winEl.textContent = formatTabsText(win.tabs.length);
187 winEl.xtitle = win.title;
188 winEl.sessionTag = win.sessionTag;
189 winEl.winNum = i;
190 winEl.addEventListener('click', maybeOpenForeignWindow);
191 winEl.addEventListener('keydown',
192 handleIfEnterKey(maybeOpenForeignWindow));
193 winSpan.appendChild(winEl);
186 194
187 el.sessionId = win.sessionId; 195 // Sort tabs by MRU order
188 el.xtitle = win.title; 196 win.tabs.sort(function(a, b) {
189 el.sessionTag = win.sessionTag; 197 return a.timestamp < b.timestamp;
198 })
190 199
191 // Add the actual tab listing. 200 // Create individual tab information.
192 stack.appendChild(el); 201 win.tabs.forEach(function(data) {
202 var tabEl = document.createElement('a');
203 tabEl.className = 'item link tab';
204 tabEl.href = data.timestamp;
205 tabEl.style.backgroundImage = url('chrome://favicon/' + data.url);
206 tabEl.dir = data.direction;
207 tabEl.textContent = data.title;
208 tabEl.sessionTag = win.sessionTag;
209 tabEl.winNum = i;
210 tabEl.sessionId = data.sessionId;
211 tabEl.addEventListener('click', maybeOpenForeignTab);
212 tabEl.addEventListener('keydown',
213 handleIfEnterKey(maybeOpenForeignTab));
193 214
194 // TODO(zea): Should there be a clickHandler as well? We appear to be 215 winSpan.appendChild(tabEl);
195 // breaking windowTooltip's hide: removeEventListener(onMouseOver) when we 216 })
196 // click. 217
218 // Append the window.
219 stack.appendChild(winSpan);
197 }); 220 });
198 return stack; 221 return stack;
199 } 222 }
200 223
201 var recentItems = []; 224 var recentItems = [];
202 225
203 function recentlyClosedTabs(data) { 226 function recentlyClosedTabs(data) {
204 logEvent('received recently closed tabs'); 227 logEvent('received recently closed tabs');
205 // We need to store the recent items so we can update the layout on a resize. 228 // We need to store the recent items so we can update the layout on a resize.
206 recentItems = data; 229 recentItems = data;
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 return el.sessionId !== undefined; 1057 return el.sessionId !== undefined;
1035 }); 1058 });
1036 if (el) { 1059 if (el) {
1037 chrome.send('reopenTab', [String(el.sessionId)]); 1060 chrome.send('reopenTab', [String(el.sessionId)]);
1038 e.preventDefault(); 1061 e.preventDefault();
1039 1062
1040 setWindowTooltipTimeout(); 1063 setWindowTooltipTimeout();
1041 } 1064 }
1042 } 1065 }
1043 1066
1044 function maybeReopenSession(e) { 1067 // Note that the openForeignSession calls can fail, resulting this method to
1068 // not have any action (hence the maybe).
1069 function maybeOpenForeignSession(e) {
1045 var el = findAncestor(e.target, function(el) { 1070 var el = findAncestor(e.target, function(el) {
1046 return el.sessionId; 1071 return el.sessionTag !== undefined;
1047 }); 1072 });
1048 if (el) { 1073 if (el) {
1049 chrome.send('reopenForeignSession', [String(el.sessionTag)]); 1074 chrome.send('openForeignSession', [String(el.sessionTag)]);
1075 e.stopPropagation();
1076 e.preventDefault();
1077 setWindowTooltipTimeout();
1078 }
1079 }
1050 1080
1081 function maybeOpenForeignWindow(e) {
1082 var el = findAncestor(e.target, function(el) {
1083 return el.winNum !== undefined;
1084 });
1085 if (el) {
1086 chrome.send('openForeignSession', [String(el.sessionTag),
1087 String(el.winNum)]);
1088 e.stopPropagation();
1089 e.preventDefault();
1090 setWindowTooltipTimeout();
1091 }
1092 }
1093
1094 function maybeOpenForeignTab(e) {
1095 var el = findAncestor(e.target, function(el) {
1096 return el.sessionId !== undefined;
1097 });
1098 if (el) {
1099 chrome.send('openForeignSession', [String(el.sessionTag), String(el.winNum),
1100 String(el.sessionId)]);
1101 e.stopPropagation();
1102 e.preventDefault();
1051 setWindowTooltipTimeout(); 1103 setWindowTooltipTimeout();
1052 } 1104 }
1053 } 1105 }
1054 1106
1055 // HACK(arv): After the window onblur event happens we get a mouseover event 1107 // HACK(arv): After the window onblur event happens we get a mouseover event
1056 // on the next item and we want to make sure that we do not show a tooltip 1108 // on the next item and we want to make sure that we do not show a tooltip
1057 // for that. 1109 // for that.
1058 function setWindowTooltipTimeout(e) { 1110 function setWindowTooltipTimeout(e) {
1059 window.setTimeout(function() { 1111 window.setTimeout(function() {
1060 windowTooltip.hide(); 1112 windowTooltip.hide();
(...skipping 16 matching lines...) Expand all
1077 1129
1078 recentlyClosedElement.addEventListener('click', maybeReopenTab); 1130 recentlyClosedElement.addEventListener('click', maybeReopenTab);
1079 recentlyClosedElement.addEventListener('keydown', 1131 recentlyClosedElement.addEventListener('keydown',
1080 handleIfEnterKey(maybeReopenTab)); 1132 handleIfEnterKey(maybeReopenTab));
1081 1133
1082 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); 1134 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip);
1083 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); 1135 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true);
1084 1136
1085 var foreignSessionElement = $('foreign-sessions'); 1137 var foreignSessionElement = $('foreign-sessions');
1086 1138
1087 foreignSessionElement.addEventListener('click', maybeReopenSession); 1139 foreignSessionElement.addEventListener('click', maybeOpenForeignSession);
1088 foreignSessionElement.addEventListener('keydown', 1140 foreignSessionElement.addEventListener('keydown',
1089 handleIfEnterKey(maybeReopenSession)); 1141 handleIfEnterKey(
1142 maybeOpenForeignSession));
1090 1143
1091 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); 1144 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip);
1092 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); 1145 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true);
1093 1146
1094 /** 1147 /**
1095 * This object represents a tooltip representing a closed window. It is 1148 * This object represents a tooltip representing a closed window. It is
1096 * shown when hovering over a closed window item or when the item is focused. It 1149 * shown when hovering over a closed window item or when the item is focused. It
1097 * gets hidden when blurred or when mousing out of the menu or the item. 1150 * gets hidden when blurred or when mousing out of the menu or the item.
1098 * @param {Element} tooltipEl The element to use as the tooltip. 1151 * @param {Element} tooltipEl The element to use as the tooltip.
1099 * @constructor 1152 * @constructor
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 var promoLink = promoText1.querySelector('a'); 1386 var promoLink = promoText1.querySelector('a');
1334 promoLink.id = 'apps-promo-link'; 1387 promoLink.id = 'apps-promo-link';
1335 promoLink.href = localStrings.getString('web_store_url'); 1388 promoLink.href = localStrings.getString('web_store_url');
1336 1389
1337 $('apps-promo-hide').addEventListener('click', function() { 1390 $('apps-promo-hide').addEventListener('click', function() {
1338 chrome.send('hideAppsPromo', []); 1391 chrome.send('hideAppsPromo', []);
1339 document.documentElement.classList.remove('apps-promo-visible'); 1392 document.documentElement.classList.remove('apps-promo-visible');
1340 layoutSections(); 1393 layoutSections();
1341 }); 1394 });
1342 }); 1395 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698