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

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: Reviewer comments + self review 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 function renderForeignSessions() { 130 function renderForeignSessions() {
131 // Remove all existing items and create new items. 131 // Remove all existing items and create new items.
132 var sessionElement = $('foreign-sessions'); 132 var sessionElement = $('foreign-sessions');
133 var parentSessionElement = sessionElement.lastElementChild; 133 var parentSessionElement = sessionElement.lastElementChild;
134 parentSessionElement.textContent = ''; 134 parentSessionElement.textContent = '';
135 135
136 // For each client, create entries and append the lists together. 136 // For each client, create entries and append the lists together.
137 sessionItems.forEach(function(item, i) { 137 sessionItems.forEach(function(item, i) {
138 // TODO(zea): Get real client names. See issue 59672 138 // TODO(zea): Get real client names. See crbug/59672.
139 var name = 'Client ' + i; 139 var name = 'Client ' + i;
140 parentSessionElement.appendChild(createForeignSession(item, name)); 140 parentSessionElement.appendChild(createForeignSession(item, name));
141 }); 141 });
142 142
143 layoutForeignSessions(); 143 layoutForeignSessions();
144 } 144 }
145 145
146 function layoutForeignSessions() { 146 function layoutForeignSessions() {
147 var sessionElement = $('foreign-sessions'); 147 var sessionElement = $('foreign-sessions');
148 // We cannot use clientWidth here since the width has a transition. 148 // We cannot use clientWidth here since the width has a transition.
149 var availWidth = useSmallGrid() ? 692 : 920; 149 var availWidth = useSmallGrid() ? 692 : 920;
150 var parentSessEl = sessionElement.lastElementChild; 150 var parentSessEl = sessionElement.lastElementChild;
151 151
152 if (parentSessEl.hasChildNodes()) { 152 if (parentSessEl.hasChildNodes()) {
153 sessionElement.classList.remove('disabled'); 153 sessionElement.classList.remove('disabled');
154 } else { 154 } else {
155 sessionElement.classList.add('disabled'); 155 sessionElement.classList.add('disabled');
156 } 156 }
157 } 157 }
158 158
159 function createForeignSession(client, name) { 159 function createForeignSession(client, name) {
160 // Vertically stack the windows in a client. 160 // Vertically stack the windows in a client.
161 var stack = document.createElement('div'); 161 var stack = document.createElement('div');
162 stack.className = 'foreign-session-client'; 162 stack.className = 'foreign-session-client item link';
163 stack.textContent = name; 163 stack.textContent = name;
164 stack.sessionTag = client[0].sessionTag;
164 165
165 client.forEach(function(win) { 166 client.forEach(function(win, i) {
166 // We know these are lists of multiple tabs, don't need the special case for 167 // Create a window entry.
167 // single url + favicon. 168 var winSpan = document.createElement('span');
168 var el = document.createElement('p'); 169 var winEl = document.createElement('p');
169 el.className = 'item link window'; 170 winEl.className = 'item link window';
170 el.tabItems = win.tabs; 171 winEl.tabItems = win.tabs;
171 el.tabIndex = 0; 172 winEl.tabIndex = 0;
172 el.textContent = formatTabsText(win.tabs.length); 173 winEl.textContent = formatTabsText(win.tabs.length);
174 winEl.xtitle = win.title;
175 winEl.sessionTag = win.sessionTag;
176 winEl.winNum = i;
177 winEl.addEventListener('click', maybeOpenForeignWindow);
178 winEl.addEventListener('keydown',
179 handleIfEnterKey(maybeOpenForeignWindow));
180 winSpan.appendChild(winEl);
173 181
174 el.sessionId = win.sessionId; 182 // Sort tabs by MRU order
175 el.xtitle = win.title; 183 win.tabs.sort(function(a, b) {
176 el.sessionTag = win.sessionTag; 184 return a.timestamp < b.timestamp;
185 })
177 186
178 // Add the actual tab listing. 187 // Create individual tab information.
179 stack.appendChild(el); 188 win.tabs.forEach(function(data) {
189 var tabEl = document.createElement('a');
190 tabEl.className = 'item link tab';
191 tabEl.href = data.timestamp;
192 tabEl.style.backgroundImage = url('chrome://favicon/' + data.url);
193 tabEl.dir = data.direction;
194 tabEl.textContent = data.title;
195 tabEl.sessionTag = win.sessionTag;
196 tabEl.winNum = i;
197 tabEl.sessionId = data.sessionId;
198 tabEl.addEventListener('click', maybeOpenForeignTab);
199 tabEl.addEventListener('keydown',
200 handleIfEnterKey(maybeOpenForeignTab));
180 201
181 // TODO(zea): Should there be a clickHandler as well? We appear to be 202 winSpan.appendChild(tabEl);
182 // breaking windowTooltip's hide: removeEventListener(onMouseOver) when we 203 })
183 // click. 204
205 // Append the window.
206 stack.appendChild(winSpan);
184 }); 207 });
185 return stack; 208 return stack;
186 } 209 }
187 210
188 var recentItems = []; 211 var recentItems = [];
189 212
190 function recentlyClosedTabs(data) { 213 function recentlyClosedTabs(data) {
191 logEvent('received recently closed tabs'); 214 logEvent('received recently closed tabs');
192 // We need to store the recent items so we can update the layout on a resize. 215 // We need to store the recent items so we can update the layout on a resize.
193 recentItems = data; 216 recentItems = data;
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 return el.sessionId !== undefined; 970 return el.sessionId !== undefined;
948 }); 971 });
949 if (el) { 972 if (el) {
950 chrome.send('reopenTab', [String(el.sessionId)]); 973 chrome.send('reopenTab', [String(el.sessionId)]);
951 e.preventDefault(); 974 e.preventDefault();
952 975
953 setWindowTooltipTimeout(); 976 setWindowTooltipTimeout();
954 } 977 }
955 } 978 }
956 979
957 function maybeReopenSession(e) { 980 // Note that the openForeignSession calls can fail, resulting this method to
981 // not have any action (hence the maybe).
tim (not reviewing) 2010/12/20 18:58:44 Can't this case be made for any function ever? (i.
982 function maybeOpenForeignSession(e) {
958 var el = findAncestor(e.target, function(el) { 983 var el = findAncestor(e.target, function(el) {
959 return el.sessionId; 984 return el.sessionTag !== undefined;
960 }); 985 });
961 if (el) { 986 if (el) {
962 chrome.send('reopenForeignSession', [String(el.sessionTag)]); 987 chrome.send('openForeignSession', [String(el.sessionTag)]);
988 e.stopPropagation();
989 e.preventDefault();
990 setWindowTooltipTimeout();
991 }
992 }
963 993
994 function maybeOpenForeignWindow(e) {
995 var el = findAncestor(e.target, function(el) {
996 return el.winNum !== undefined;
997 });
998 if (el) {
999 chrome.send('openForeignSession', [String(el.sessionTag),
1000 String(el.winNum)]);
1001 e.stopPropagation();
1002 e.preventDefault();
1003 setWindowTooltipTimeout();
1004 }
1005 }
1006
1007 function maybeOpenForeignTab(e) {
1008 var el = findAncestor(e.target, function(el) {
1009 return el.sessionId !== undefined;
1010 });
1011 if (el) {
1012 chrome.send('openForeignSession', [String(el.sessionTag), String(el.winNum),
1013 String(el.sessionId)]);
1014 e.stopPropagation();
1015 e.preventDefault();
964 setWindowTooltipTimeout(); 1016 setWindowTooltipTimeout();
965 } 1017 }
966 } 1018 }
967 1019
968 // HACK(arv): After the window onblur event happens we get a mouseover event 1020 // HACK(arv): After the window onblur event happens we get a mouseover event
969 // on the next item and we want to make sure that we do not show a tooltip 1021 // on the next item and we want to make sure that we do not show a tooltip
970 // for that. 1022 // for that.
971 function setWindowTooltipTimeout(e) { 1023 function setWindowTooltipTimeout(e) {
972 window.setTimeout(function() { 1024 window.setTimeout(function() {
973 windowTooltip.hide(); 1025 windowTooltip.hide();
(...skipping 16 matching lines...) Expand all
990 1042
991 recentlyClosedElement.addEventListener('click', maybeReopenTab); 1043 recentlyClosedElement.addEventListener('click', maybeReopenTab);
992 recentlyClosedElement.addEventListener('keydown', 1044 recentlyClosedElement.addEventListener('keydown',
993 handleIfEnterKey(maybeReopenTab)); 1045 handleIfEnterKey(maybeReopenTab));
994 1046
995 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); 1047 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip);
996 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); 1048 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true);
997 1049
998 var foreignSessionElement = $('foreign-sessions'); 1050 var foreignSessionElement = $('foreign-sessions');
999 1051
1000 foreignSessionElement.addEventListener('click', maybeReopenSession); 1052 foreignSessionElement.addEventListener('click', maybeOpenForeignSession);
1001 foreignSessionElement.addEventListener('keydown', 1053 foreignSessionElement.addEventListener('keydown',
1002 handleIfEnterKey(maybeReopenSession)); 1054 handleIfEnterKey(
1055 maybeOpenForeignSession));
1003 1056
1004 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); 1057 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip);
1005 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); 1058 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true);
1006 1059
1007 /** 1060 /**
1008 * This object represents a tooltip representing a closed window. It is 1061 * This object represents a tooltip representing a closed window. It is
1009 * shown when hovering over a closed window item or when the item is focused. It 1062 * shown when hovering over a closed window item or when the item is focused. It
1010 * gets hidden when blurred or when mousing out of the menu or the item. 1063 * gets hidden when blurred or when mousing out of the menu or the item.
1011 * @param {Element} tooltipEl The element to use as the tooltip. 1064 * @param {Element} tooltipEl The element to use as the tooltip.
1012 * @constructor 1065 * @constructor
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 var promoLink = promoText1.querySelector('a'); 1299 var promoLink = promoText1.querySelector('a');
1247 promoLink.id = 'apps-promo-link'; 1300 promoLink.id = 'apps-promo-link';
1248 promoLink.href = localStrings.getString('web_store_url'); 1301 promoLink.href = localStrings.getString('web_store_url');
1249 1302
1250 $('apps-promo-hide').addEventListener('click', function() { 1303 $('apps-promo-hide').addEventListener('click', function() {
1251 chrome.send('hideAppsPromo', []); 1304 chrome.send('hideAppsPromo', []);
1252 document.documentElement.classList.remove('apps-promo-visible'); 1305 document.documentElement.classList.remove('apps-promo-visible');
1253 layoutSections(); 1306 layoutSections();
1254 }); 1307 });
1255 }); 1308 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698