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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 return el.sessionId !== undefined; | 974 return el.sessionId !== undefined; |
952 }); | 975 }); |
953 if (el) { | 976 if (el) { |
954 chrome.send('reopenTab', [String(el.sessionId)]); | 977 chrome.send('reopenTab', [String(el.sessionId)]); |
955 e.preventDefault(); | 978 e.preventDefault(); |
956 | 979 |
957 setWindowTooltipTimeout(); | 980 setWindowTooltipTimeout(); |
958 } | 981 } |
959 } | 982 } |
960 | 983 |
961 function maybeReopenSession(e) { | 984 // Note that the openForeignSession calls can fail, resulting this method to |
| 985 // not have any action (hence the maybe). |
| 986 function maybeOpenForeignSession(e) { |
962 var el = findAncestor(e.target, function(el) { | 987 var el = findAncestor(e.target, function(el) { |
963 return el.sessionId; | 988 return el.sessionTag !== undefined; |
964 }); | 989 }); |
965 if (el) { | 990 if (el) { |
966 chrome.send('reopenForeignSession', [String(el.sessionTag)]); | 991 chrome.send('openForeignSession', [String(el.sessionTag)]); |
| 992 e.stopPropagation(); |
| 993 e.preventDefault(); |
| 994 setWindowTooltipTimeout(); |
| 995 } |
| 996 } |
967 | 997 |
| 998 function maybeOpenForeignWindow(e) { |
| 999 var el = findAncestor(e.target, function(el) { |
| 1000 return el.winNum !== undefined; |
| 1001 }); |
| 1002 if (el) { |
| 1003 chrome.send('openForeignSession', [String(el.sessionTag), |
| 1004 String(el.winNum)]); |
| 1005 e.stopPropagation(); |
| 1006 e.preventDefault(); |
| 1007 setWindowTooltipTimeout(); |
| 1008 } |
| 1009 } |
| 1010 |
| 1011 function maybeOpenForeignTab(e) { |
| 1012 var el = findAncestor(e.target, function(el) { |
| 1013 return el.sessionId !== undefined; |
| 1014 }); |
| 1015 if (el) { |
| 1016 chrome.send('openForeignSession', [String(el.sessionTag), String(el.winNum), |
| 1017 String(el.sessionId)]); |
| 1018 e.stopPropagation(); |
| 1019 e.preventDefault(); |
968 setWindowTooltipTimeout(); | 1020 setWindowTooltipTimeout(); |
969 } | 1021 } |
970 } | 1022 } |
971 | 1023 |
972 // HACK(arv): After the window onblur event happens we get a mouseover event | 1024 // HACK(arv): After the window onblur event happens we get a mouseover event |
973 // on the next item and we want to make sure that we do not show a tooltip | 1025 // on the next item and we want to make sure that we do not show a tooltip |
974 // for that. | 1026 // for that. |
975 function setWindowTooltipTimeout(e) { | 1027 function setWindowTooltipTimeout(e) { |
976 window.setTimeout(function() { | 1028 window.setTimeout(function() { |
977 windowTooltip.hide(); | 1029 windowTooltip.hide(); |
(...skipping 16 matching lines...) Expand all Loading... |
994 | 1046 |
995 recentlyClosedElement.addEventListener('click', maybeReopenTab); | 1047 recentlyClosedElement.addEventListener('click', maybeReopenTab); |
996 recentlyClosedElement.addEventListener('keydown', | 1048 recentlyClosedElement.addEventListener('keydown', |
997 handleIfEnterKey(maybeReopenTab)); | 1049 handleIfEnterKey(maybeReopenTab)); |
998 | 1050 |
999 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); | 1051 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); |
1000 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); | 1052 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); |
1001 | 1053 |
1002 var foreignSessionElement = $('foreign-sessions'); | 1054 var foreignSessionElement = $('foreign-sessions'); |
1003 | 1055 |
1004 foreignSessionElement.addEventListener('click', maybeReopenSession); | 1056 foreignSessionElement.addEventListener('click', maybeOpenForeignSession); |
1005 foreignSessionElement.addEventListener('keydown', | 1057 foreignSessionElement.addEventListener('keydown', |
1006 handleIfEnterKey(maybeReopenSession)); | 1058 handleIfEnterKey( |
| 1059 maybeOpenForeignSession)); |
1007 | 1060 |
1008 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); | 1061 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); |
1009 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); | 1062 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); |
1010 | 1063 |
1011 /** | 1064 /** |
1012 * This object represents a tooltip representing a closed window. It is | 1065 * This object represents a tooltip representing a closed window. It is |
1013 * shown when hovering over a closed window item or when the item is focused. It | 1066 * shown when hovering over a closed window item or when the item is focused. It |
1014 * gets hidden when blurred or when mousing out of the menu or the item. | 1067 * gets hidden when blurred or when mousing out of the menu or the item. |
1015 * @param {Element} tooltipEl The element to use as the tooltip. | 1068 * @param {Element} tooltipEl The element to use as the tooltip. |
1016 * @constructor | 1069 * @constructor |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 var promoLink = promoText1.querySelector('a'); | 1303 var promoLink = promoText1.querySelector('a'); |
1251 promoLink.id = 'apps-promo-link'; | 1304 promoLink.id = 'apps-promo-link'; |
1252 promoLink.href = localStrings.getString('web_store_url'); | 1305 promoLink.href = localStrings.getString('web_store_url'); |
1253 | 1306 |
1254 $('apps-promo-hide').addEventListener('click', function() { | 1307 $('apps-promo-hide').addEventListener('click', function() { |
1255 chrome.send('hideAppsPromo', []); | 1308 chrome.send('hideAppsPromo', []); |
1256 document.documentElement.classList.remove('apps-promo-visible'); | 1309 document.documentElement.classList.remove('apps-promo-visible'); |
1257 layoutSections(); | 1310 layoutSections(); |
1258 }); | 1311 }); |
1259 }); | 1312 }); |
OLD | NEW |