OLD | NEW |
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 Loading... |
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 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 return el.sessionId !== undefined; | 1056 return el.sessionId !== undefined; |
1034 }); | 1057 }); |
1035 if (el) { | 1058 if (el) { |
1036 chrome.send('reopenTab', [String(el.sessionId)]); | 1059 chrome.send('reopenTab', [String(el.sessionId)]); |
1037 e.preventDefault(); | 1060 e.preventDefault(); |
1038 | 1061 |
1039 setWindowTooltipTimeout(); | 1062 setWindowTooltipTimeout(); |
1040 } | 1063 } |
1041 } | 1064 } |
1042 | 1065 |
1043 function maybeReopenSession(e) { | 1066 // Note that the openForeignSession calls can fail, resulting this method to |
| 1067 // not have any action (hence the maybe). |
| 1068 function maybeOpenForeignSession(e) { |
1044 var el = findAncestor(e.target, function(el) { | 1069 var el = findAncestor(e.target, function(el) { |
1045 return el.sessionId; | 1070 return el.sessionTag !== undefined; |
1046 }); | 1071 }); |
1047 if (el) { | 1072 if (el) { |
1048 chrome.send('reopenForeignSession', [String(el.sessionTag)]); | 1073 chrome.send('openForeignSession', [String(el.sessionTag)]); |
| 1074 e.stopPropagation(); |
| 1075 e.preventDefault(); |
| 1076 setWindowTooltipTimeout(); |
| 1077 } |
| 1078 } |
1049 | 1079 |
| 1080 function maybeOpenForeignWindow(e) { |
| 1081 var el = findAncestor(e.target, function(el) { |
| 1082 return el.winNum !== undefined; |
| 1083 }); |
| 1084 if (el) { |
| 1085 chrome.send('openForeignSession', [String(el.sessionTag), |
| 1086 String(el.winNum)]); |
| 1087 e.stopPropagation(); |
| 1088 e.preventDefault(); |
| 1089 setWindowTooltipTimeout(); |
| 1090 } |
| 1091 } |
| 1092 |
| 1093 function maybeOpenForeignTab(e) { |
| 1094 var el = findAncestor(e.target, function(el) { |
| 1095 return el.sessionId !== undefined; |
| 1096 }); |
| 1097 if (el) { |
| 1098 chrome.send('openForeignSession', [String(el.sessionTag), String(el.winNum), |
| 1099 String(el.sessionId)]); |
| 1100 e.stopPropagation(); |
| 1101 e.preventDefault(); |
1050 setWindowTooltipTimeout(); | 1102 setWindowTooltipTimeout(); |
1051 } | 1103 } |
1052 } | 1104 } |
1053 | 1105 |
1054 // HACK(arv): After the window onblur event happens we get a mouseover event | 1106 // HACK(arv): After the window onblur event happens we get a mouseover event |
1055 // on the next item and we want to make sure that we do not show a tooltip | 1107 // on the next item and we want to make sure that we do not show a tooltip |
1056 // for that. | 1108 // for that. |
1057 function setWindowTooltipTimeout(e) { | 1109 function setWindowTooltipTimeout(e) { |
1058 window.setTimeout(function() { | 1110 window.setTimeout(function() { |
1059 windowTooltip.hide(); | 1111 windowTooltip.hide(); |
(...skipping 16 matching lines...) Expand all Loading... |
1076 | 1128 |
1077 recentlyClosedElement.addEventListener('click', maybeReopenTab); | 1129 recentlyClosedElement.addEventListener('click', maybeReopenTab); |
1078 recentlyClosedElement.addEventListener('keydown', | 1130 recentlyClosedElement.addEventListener('keydown', |
1079 handleIfEnterKey(maybeReopenTab)); | 1131 handleIfEnterKey(maybeReopenTab)); |
1080 | 1132 |
1081 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); | 1133 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); |
1082 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); | 1134 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); |
1083 | 1135 |
1084 var foreignSessionElement = $('foreign-sessions'); | 1136 var foreignSessionElement = $('foreign-sessions'); |
1085 | 1137 |
1086 foreignSessionElement.addEventListener('click', maybeReopenSession); | 1138 foreignSessionElement.addEventListener('click', maybeOpenForeignSession); |
1087 foreignSessionElement.addEventListener('keydown', | 1139 foreignSessionElement.addEventListener('keydown', |
1088 handleIfEnterKey(maybeReopenSession)); | 1140 handleIfEnterKey( |
| 1141 maybeOpenForeignSession)); |
1089 | 1142 |
1090 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); | 1143 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); |
1091 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); | 1144 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); |
1092 | 1145 |
1093 /** | 1146 /** |
1094 * This object represents a tooltip representing a closed window. It is | 1147 * This object represents a tooltip representing a closed window. It is |
1095 * shown when hovering over a closed window item or when the item is focused. It | 1148 * shown when hovering over a closed window item or when the item is focused. It |
1096 * gets hidden when blurred or when mousing out of the menu or the item. | 1149 * gets hidden when blurred or when mousing out of the menu or the item. |
1097 * @param {Element} tooltipEl The element to use as the tooltip. | 1150 * @param {Element} tooltipEl The element to use as the tooltip. |
1098 * @constructor | 1151 * @constructor |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 var promoLink = promoText1.querySelector('a'); | 1385 var promoLink = promoText1.querySelector('a'); |
1333 promoLink.id = 'apps-promo-link'; | 1386 promoLink.id = 'apps-promo-link'; |
1334 promoLink.href = localStrings.getString('web_store_url'); | 1387 promoLink.href = localStrings.getString('web_store_url'); |
1335 | 1388 |
1336 $('apps-promo-hide').addEventListener('click', function() { | 1389 $('apps-promo-hide').addEventListener('click', function() { |
1337 chrome.send('hideAppsPromo', []); | 1390 chrome.send('hideAppsPromo', []); |
1338 document.documentElement.classList.remove('apps-promo-visible'); | 1391 document.documentElement.classList.remove('apps-promo-visible'); |
1339 layoutSections(); | 1392 layoutSections(); |
1340 }); | 1393 }); |
1341 }); | 1394 }); |
OLD | NEW |