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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 $(id).classList.remove('hidden'); | 105 $(id).classList.remove('hidden'); |
106 if (maxiview) | 106 if (maxiview) |
107 maxiview.classList.remove('hidden'); | 107 maxiview.classList.remove('hidden'); |
108 } else { | 108 } else { |
109 $(id).classList.add('hidden'); | 109 $(id).classList.add('hidden'); |
110 if (maxiview) | 110 if (maxiview) |
111 maxiview.classList.add('hidden'); | 111 maxiview.classList.add('hidden'); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
| 115 var sessionItems = []; |
| 116 |
| 117 function foreignSessions(data) { |
| 118 logEvent('received foreign sessions'); |
| 119 // We need to store the foreign sessions so we can update the layout on a |
| 120 // resize. |
| 121 sessionItems = data; |
| 122 renderForeignSessions(); |
| 123 layoutSections(); |
| 124 } |
| 125 |
| 126 function renderForeignSessions() { |
| 127 // Remove all existing items and create new items. |
| 128 var sessionElement = $('foreign-sessions'); |
| 129 var parentSessionElement = sessionElement.lastElementChild; |
| 130 parentSessionElement.textContent = ''; |
| 131 |
| 132 // For each client, create entries and append the lists together. |
| 133 sessionItems.forEach(function(item, i) { |
| 134 // TODO(zea): Get real client names. See issue 59672 |
| 135 var name = 'Client ' + i; |
| 136 parentSessionElement.appendChild(createForeignSession(item, name)); |
| 137 }); |
| 138 |
| 139 layoutForeignSessions(); |
| 140 } |
| 141 |
| 142 function layoutForeignSessions() { |
| 143 var sessionElement = $('foreign-sessions'); |
| 144 // We cannot use clientWidth here since the width has a transition. |
| 145 var availWidth = useSmallGrid() ? 692 : 920; |
| 146 var parentSessEl = sessionElement.lastElementChild; |
| 147 |
| 148 if (parentSessEl.hasChildNodes()) { |
| 149 sessionElement.classList.remove('disabled'); |
| 150 } else { |
| 151 sessionElement.classList.add('disabled'); |
| 152 } |
| 153 } |
| 154 |
| 155 function createForeignSession(client, name) { |
| 156 // Vertically stack the windows in a client. |
| 157 var stack = document.createElement('div'); |
| 158 stack.className = 'foreign-session-client'; |
| 159 stack.textContent = name; |
| 160 |
| 161 client.forEach(function(win) { |
| 162 // We know these are lists of multiple tabs, don't need the special case for |
| 163 // single url + favicon. |
| 164 var el = document.createElement('p'); |
| 165 el.className = 'item link window'; |
| 166 el.tabItems = win.tabs; |
| 167 el.tabIndex = 0; |
| 168 el.textContent = formatTabsText(win.tabs.length); |
| 169 |
| 170 el.sessionId = win.sessionId; |
| 171 el.xtitle = win.title; |
| 172 el.sessionTag = win.sessionTag; |
| 173 |
| 174 // Add the actual tab listing. |
| 175 stack.appendChild(el); |
| 176 |
| 177 // TODO(zea): Should there be a clickHandler as well? We appear to be |
| 178 // breaking windowTooltip's hide: removeEventListener(onMouseOver) when we |
| 179 // click. |
| 180 }); |
| 181 return stack; |
| 182 } |
| 183 |
| 184 var recentItems = []; |
| 185 |
115 function recentlyClosedTabs(data) { | 186 function recentlyClosedTabs(data) { |
116 logEvent('received recently closed tabs'); | 187 logEvent('received recently closed tabs'); |
117 // We need to store the recent items so we can update the layout on a resize. | 188 // We need to store the recent items so we can update the layout on a resize. |
118 recentItems = data; | 189 recentItems = data; |
119 renderRecentlyClosed(); | 190 renderRecentlyClosed(); |
120 layoutSections(); | 191 layoutSections(); |
121 } | 192 } |
122 | 193 |
123 var recentItems = []; | |
124 | |
125 function renderRecentlyClosed() { | 194 function renderRecentlyClosed() { |
126 // Remove all existing items and create new items. | 195 // Remove all existing items and create new items. |
127 var recentElement = $('recently-closed'); | 196 var recentElement = $('recently-closed'); |
128 var parentEl = recentElement.lastElementChild; | 197 var parentEl = recentElement.lastElementChild; |
129 parentEl.textContent = ''; | 198 parentEl.textContent = ''; |
130 var recentMenu = $('recently-closed-menu'); | 199 var recentMenu = $('recently-closed-menu'); |
131 clearClosedMenu(recentMenu); | 200 clearClosedMenu(recentMenu); |
132 | 201 |
133 recentItems.forEach(function(item) { | 202 recentItems.forEach(function(item) { |
134 parentEl.appendChild(createRecentItem(item)); | 203 parentEl.appendChild(createRecentItem(item)); |
(...skipping 16 matching lines...) Expand all Loading... |
151 } else { | 220 } else { |
152 el = document.createElement('a'); | 221 el = document.createElement('a'); |
153 el.className = 'item'; | 222 el.className = 'item'; |
154 el.href = data.url; | 223 el.href = data.url; |
155 el.style.backgroundImage = url('chrome://favicon/' + data.url); | 224 el.style.backgroundImage = url('chrome://favicon/' + data.url); |
156 el.dir = data.direction; | 225 el.dir = data.direction; |
157 el.textContent = data.title; | 226 el.textContent = data.title; |
158 } | 227 } |
159 el.sessionId = data.sessionId; | 228 el.sessionId = data.sessionId; |
160 el.xtitle = data.title; | 229 el.xtitle = data.title; |
| 230 el.sessionTag = data.sessionTag; |
161 var wrapperEl = document.createElement('span'); | 231 var wrapperEl = document.createElement('span'); |
162 wrapperEl.appendChild(el); | 232 wrapperEl.appendChild(el); |
163 return wrapperEl; | 233 return wrapperEl; |
164 } | 234 } |
165 | 235 |
166 function addRecentMenuItem(menu, data) { | 236 function addRecentMenuItem(menu, data) { |
167 var isWindow = data.type == 'window'; | 237 var isWindow = data.type == 'window'; |
168 var a = document.createElement('a'); | 238 var a = document.createElement('a'); |
169 if (isWindow) { | 239 if (isWindow) { |
170 a.textContent = formatTabsText(data.tabs.length); | 240 a.textContent = formatTabsText(data.tabs.length); |
(...skipping 30 matching lines...) Expand all Loading... |
201 } | 271 } |
202 | 272 |
203 var oldLayoutMode = layoutMode; | 273 var oldLayoutMode = layoutMode; |
204 var b = useSmallGrid(); | 274 var b = useSmallGrid(); |
205 layoutMode = b ? LayoutMode.SMALL : LayoutMode.NORMAL | 275 layoutMode = b ? LayoutMode.SMALL : LayoutMode.NORMAL |
206 | 276 |
207 if (layoutMode != oldLayoutMode){ | 277 if (layoutMode != oldLayoutMode){ |
208 mostVisited.useSmallGrid = b; | 278 mostVisited.useSmallGrid = b; |
209 mostVisited.layout(); | 279 mostVisited.layout(); |
210 renderRecentlyClosed(); | 280 renderRecentlyClosed(); |
| 281 renderForeignSessions(); |
211 updateAllMiniviewClippings(); | 282 updateAllMiniviewClippings(); |
212 } | 283 } |
213 | 284 |
214 layoutSections(); | 285 layoutSections(); |
215 } | 286 } |
216 | 287 |
217 // Stores some information about each section necessary to layout. A new | 288 // Stores some information about each section necessary to layout. A new |
218 // instance is constructed for each section on each layout. | 289 // instance is constructed for each section on each layout. |
219 function SectionLayoutInfo(section) { | 290 function SectionLayoutInfo(section) { |
220 this.section = section; | 291 this.section = section; |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 } | 909 } |
839 | 910 |
840 function maybeReopenTab(e) { | 911 function maybeReopenTab(e) { |
841 var el = findAncestor(e.target, function(el) { | 912 var el = findAncestor(e.target, function(el) { |
842 return el.sessionId !== undefined; | 913 return el.sessionId !== undefined; |
843 }); | 914 }); |
844 if (el) { | 915 if (el) { |
845 chrome.send('reopenTab', [String(el.sessionId)]); | 916 chrome.send('reopenTab', [String(el.sessionId)]); |
846 e.preventDefault(); | 917 e.preventDefault(); |
847 | 918 |
848 // HACK(arv): After the window onblur event happens we get a mouseover event | 919 setWindowTooltipTimeout(); |
849 // on the next item and we want to make sure that we do not show a tooltip | |
850 // for that. | |
851 window.setTimeout(function() { | |
852 windowTooltip.hide(); | |
853 }, 2 * WindowTooltip.DELAY); | |
854 } | 920 } |
855 } | 921 } |
856 | 922 |
| 923 function maybeReopenSession(e) { |
| 924 var el = findAncestor(e.target, function(el) { |
| 925 return el.sessionId; |
| 926 }); |
| 927 if (el) { |
| 928 chrome.send('reopenForeignSession', [String(el.sessionTag)]); |
| 929 |
| 930 setWindowTooltipTimeout(); |
| 931 } |
| 932 } |
| 933 |
| 934 // HACK(arv): After the window onblur event happens we get a mouseover event |
| 935 // on the next item and we want to make sure that we do not show a tooltip |
| 936 // for that. |
| 937 function setWindowTooltipTimeout(e) { |
| 938 window.setTimeout(function() { |
| 939 windowTooltip.hide(); |
| 940 }, 2 * WindowTooltip.DELAY); |
| 941 } |
| 942 |
857 function maybeShowWindowTooltip(e) { | 943 function maybeShowWindowTooltip(e) { |
858 var f = function(el) { | 944 var f = function(el) { |
859 return el.tabItems !== undefined; | 945 return el.tabItems !== undefined; |
860 }; | 946 }; |
861 var el = findAncestor(e.target, f); | 947 var el = findAncestor(e.target, f); |
862 var relatedEl = findAncestor(e.relatedTarget, f); | 948 var relatedEl = findAncestor(e.relatedTarget, f); |
863 if (el && el != relatedEl) { | 949 if (el && el != relatedEl) { |
864 windowTooltip.handleMouseOver(e, el, el.tabItems); | 950 windowTooltip.handleMouseOver(e, el, el.tabItems); |
865 } | 951 } |
866 } | 952 } |
867 | 953 |
868 | 954 |
869 var recentlyClosedElement = $('recently-closed'); | 955 var recentlyClosedElement = $('recently-closed'); |
870 | 956 |
871 recentlyClosedElement.addEventListener('click', maybeReopenTab); | 957 recentlyClosedElement.addEventListener('click', maybeReopenTab); |
872 recentlyClosedElement.addEventListener('keydown', | 958 recentlyClosedElement.addEventListener('keydown', |
873 handleIfEnterKey(maybeReopenTab)); | 959 handleIfEnterKey(maybeReopenTab)); |
874 | 960 |
875 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); | 961 recentlyClosedElement.addEventListener('mouseover', maybeShowWindowTooltip); |
876 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); | 962 recentlyClosedElement.addEventListener('focus', maybeShowWindowTooltip, true); |
877 | 963 |
| 964 var foreignSessionElement = $('foreign-sessions'); |
| 965 |
| 966 foreignSessionElement.addEventListener('click', maybeReopenSession); |
| 967 foreignSessionElement.addEventListener('keydown', |
| 968 handleIfEnterKey(maybeReopenSession)); |
| 969 |
| 970 foreignSessionElement.addEventListener('mouseover', maybeShowWindowTooltip); |
| 971 foreignSessionElement.addEventListener('focus', maybeShowWindowTooltip, true); |
| 972 |
878 /** | 973 /** |
879 * This object represents a tooltip representing a closed window. It is | 974 * This object represents a tooltip representing a closed window. It is |
880 * shown when hovering over a closed window item or when the item is focused. It | 975 * shown when hovering over a closed window item or when the item is focused. It |
881 * gets hidden when blurred or when mousing out of the menu or the item. | 976 * gets hidden when blurred or when mousing out of the menu or the item. |
882 * @param {Element} tooltipEl The element to use as the tooltip. | 977 * @param {Element} tooltipEl The element to use as the tooltip. |
883 * @constructor | 978 * @constructor |
884 */ | 979 */ |
885 function WindowTooltip(tooltipEl) { | 980 function WindowTooltip(tooltipEl) { |
886 this.tooltipEl = tooltipEl; | 981 this.tooltipEl = tooltipEl; |
887 this.boundHide_ = this.hide.bind(this); | 982 this.boundHide_ = this.hide.bind(this); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 var promoText1 = $('apps-promo-text1'); | 1209 var promoText1 = $('apps-promo-text1'); |
1115 promoText1.innerHTML = promoText1.textContent; | 1210 promoText1.innerHTML = promoText1.textContent; |
1116 promoText1.querySelector('a').href = localStrings.getString('web_store_url'); | 1211 promoText1.querySelector('a').href = localStrings.getString('web_store_url'); |
1117 | 1212 |
1118 $('apps-promo-hide').addEventListener('click', function() { | 1213 $('apps-promo-hide').addEventListener('click', function() { |
1119 chrome.send('hideAppsPromo', []); | 1214 chrome.send('hideAppsPromo', []); |
1120 document.documentElement.classList.remove('apps-promo-visible'); | 1215 document.documentElement.classList.remove('apps-promo-visible'); |
1121 layoutSections(); | 1216 layoutSections(); |
1122 }); | 1217 }); |
1123 }); | 1218 }); |
OLD | NEW |