Chromium Code Reviews| 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 function maybeOpenForeignSession(e) { |
|
tim (not reviewing)
2010/12/15 21:14:00
comment what 'maybe' means
Nicolas Zea
2010/12/16 18:09:18
Done.
| |
| 958 var el = findAncestor(e.target, function(el) { | 981 var el = findAncestor(e.target, function(el) { |
| 959 return el.sessionId; | 982 return el.sessionTag !== undefined; |
| 960 }); | 983 }); |
| 961 if (el) { | 984 if (el) { |
| 962 chrome.send('reopenForeignSession', [String(el.sessionTag)]); | 985 chrome.send('openForeignSession', [String(el.sessionTag)]); |
| 986 e.stopPropagation(); | |
| 987 e.preventDefault(); | |
| 988 setWindowTooltipTimeout(); | |
| 989 } | |
| 990 } | |
| 963 | 991 |
| 992 function maybeOpenForeignWindow(e) { | |
| 993 var el = findAncestor(e.target, function(el) { | |
| 994 return el.winNum !== undefined; | |
| 995 }); | |
| 996 if (el) { | |
| 997 chrome.send('openForeignSession', [String(el.sessionTag), | |
| 998 String(el.winNum)]); | |
| 999 e.stopPropagation(); | |
| 1000 e.preventDefault(); | |
| 1001 setWindowTooltipTimeout(); | |
| 1002 } | |
| 1003 } | |
| 1004 | |
| 1005 function maybeOpenForeignTab(e) { | |
| 1006 var el = findAncestor(e.target, function(el) { | |
| 1007 return el.sessionId !== undefined; | |
| 1008 }); | |
| 1009 if (el) { | |
| 1010 chrome.send('openForeignSession', [String(el.sessionTag), String(el.winNum), | |
| 1011 String(el.sessionId)]); | |
| 1012 e.stopPropagation(); | |
| 1013 e.preventDefault(); | |
| 964 setWindowTooltipTimeout(); | 1014 setWindowTooltipTimeout(); |
| 965 } | 1015 } |
| 966 } | 1016 } |
| 967 | 1017 |
| 968 // HACK(arv): After the window onblur event happens we get a mouseover event | 1018 // 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 | 1019 // on the next item and we want to make sure that we do not show a tooltip |
| 970 // for that. | 1020 // for that. |
| 971 function setWindowTooltipTimeout(e) { | 1021 function setWindowTooltipTimeout(e) { |
| 972 window.setTimeout(function() { | 1022 window.setTimeout(function() { |
| 973 windowTooltip.hide(); | 1023 windowTooltip.hide(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 990 | 1040 |
| 991 recentlyClosedElement.addEventListener('click', maybeReopenTab); | 1041 recentlyClosedElement.addEventListener('click', maybeReopenTab); |
| 992 recentlyClosedElement.addEventListener('keydown', | 1042 recentlyClosedElement.addEventListener('keydown', |
| 993 handleIfEnterKey(maybeReopenTab)); | 1043 handleIfEnterKey(maybeReopenTab)); |
| 994 | 1044 |
| 995 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); | 1045 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); |
| 996 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); | 1046 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); |
| 997 | 1047 |
| 998 var foreignSessionElement = $('foreign-sessions'); | 1048 var foreignSessionElement = $('foreign-sessions'); |
| 999 | 1049 |
| 1000 foreignSessionElement.addEventListener('click', maybeReopenSession); | 1050 foreignSessionElement.addEventListener('click', maybeOpenForeignSession); |
| 1001 foreignSessionElement.addEventListener('keydown', | 1051 foreignSessionElement.addEventListener('keydown', |
| 1002 handleIfEnterKey(maybeReopenSession)); | 1052 handleIfEnterKey( |
| 1053 maybeOpenForeignSession)); | |
| 1003 | 1054 |
| 1004 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); | 1055 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); |
| 1005 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); | 1056 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); |
| 1006 | 1057 |
| 1007 /** | 1058 /** |
| 1008 * This object represents a tooltip representing a closed window. It is | 1059 * 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 | 1060 * 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. | 1061 * 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. | 1062 * @param {Element} tooltipEl The element to use as the tooltip. |
| 1012 * @constructor | 1063 * @constructor |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1246 var promoLink = promoText1.querySelector('a'); | 1297 var promoLink = promoText1.querySelector('a'); |
| 1247 promoLink.id = 'apps-promo-link'; | 1298 promoLink.id = 'apps-promo-link'; |
| 1248 promoLink.href = localStrings.getString('web_store_url'); | 1299 promoLink.href = localStrings.getString('web_store_url'); |
| 1249 | 1300 |
| 1250 $('apps-promo-hide').addEventListener('click', function() { | 1301 $('apps-promo-hide').addEventListener('click', function() { |
| 1251 chrome.send('hideAppsPromo', []); | 1302 chrome.send('hideAppsPromo', []); |
| 1252 document.documentElement.classList.remove('apps-promo-visible'); | 1303 document.documentElement.classList.remove('apps-promo-visible'); |
| 1253 layoutSections(); | 1304 layoutSections(); |
| 1254 }); | 1305 }); |
| 1255 }); | 1306 }); |
| OLD | NEW |