OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 /** | 5 /** |
6 * @fileoverview The section of the history page that shows tabs from sessions | 6 * @fileoverview The section of the history page that shows tabs from sessions |
7 on other devices. | 7 on other devices. |
8 */ | 8 */ |
9 | 9 |
10 /////////////////////////////////////////////////////////////////////////////// | 10 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 // Device, Public: ------------------------------------------------------------ | 160 // Device, Public: ------------------------------------------------------------ |
161 | 161 |
162 /** | 162 /** |
163 * Get the DOM node to display this device. | 163 * Get the DOM node to display this device. |
164 * @param {int} maxNumTabs The maximum number of tabs to display. | 164 * @param {int} maxNumTabs The maximum number of tabs to display. |
165 * @param {int} row The row in which this device is displayed. | 165 * @param {int} row The row in which this device is displayed. |
166 * @return {Object} A DOM node to draw the device. | 166 * @return {Object} A DOM node to draw the device. |
167 */ | 167 */ |
168 Device.prototype.getDOMNode = function(maxNumTabs, row) { | 168 Device.prototype.getDOMNode = function(maxNumTabs, row) { |
169 var deviceDiv = createElementWithClassName('div', 'device'); | 169 var deviceDiv = createElementWithClassName('div', 'device'); |
170 this.focusGrid_ = new cr.ui.FocusGrid(); | |
170 this.row_ = row; | 171 this.row_ = row; |
171 if (!this.session_) | 172 if (!this.session_) |
172 return deviceDiv; | 173 return deviceDiv; |
173 | 174 |
174 // Name heading | 175 // Name heading |
175 var heading = document.createElement('h3'); | 176 var heading = document.createElement('h3'); |
176 var name = heading.appendChild( | 177 var name = heading.appendChild( |
177 createElementWithClassName('span', 'device-name')); | 178 createElementWithClassName('span', 'device-name')); |
178 name.textContent = this.session_.name; | 179 name.textContent = this.session_.name; |
179 heading.sessionData_ = this.session_; | 180 heading.sessionData_ = this.session_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 | 238 |
238 // Device, Private ------------------------------------------------------------ | 239 // Device, Private ------------------------------------------------------------ |
239 | 240 |
240 /** | 241 /** |
241 * Create the DOM tree representing the tabs and windows of this device. | 242 * Create the DOM tree representing the tabs and windows of this device. |
242 * @param {int} maxNumTabs The maximum number of tabs to display. | 243 * @param {int} maxNumTabs The maximum number of tabs to display. |
243 * @return {Element} A single div containing the list of tabs & windows. | 244 * @return {Element} A single div containing the list of tabs & windows. |
244 * @private | 245 * @private |
245 */ | 246 */ |
246 Device.prototype.createSessionContents_ = function(maxNumTabs) { | 247 Device.prototype.createSessionContents_ = function(maxNumTabs) { |
247 var contents = createElementWithClassName('ol', 'device-contents'); | 248 var contents = createElementWithClassName('div', ''); |
249 | |
250 // |list| will be used as the boundary for the DevicesViewFocusRows. | |
251 var list = createElementWithClassName('ol', 'device-contents'); | |
252 contents.appendChild(list); | |
248 | 253 |
249 var sessionTag = this.session_.tag; | 254 var sessionTag = this.session_.tag; |
250 var numTabsShown = 0; | 255 var numTabsShown = 0; |
251 var numTabsHidden = 0; | 256 var numTabsHidden = 0; |
252 for (var i = 0; i < this.session_.windows.length; i++) { | 257 for (var i = 0; i < this.session_.windows.length; i++) { |
253 var win = this.session_.windows[i]; | 258 var win = this.session_.windows[i]; |
254 if (win.hidden) | 259 if (win.hidden) |
255 continue; | 260 continue; |
256 | 261 |
257 // Show a separator between multiple windows in the same session. | 262 // Show a separator between multiple windows in the same session. |
258 if (i > 0 && numTabsShown < maxNumTabs) | 263 if (i > 0 && numTabsShown < maxNumTabs) |
259 contents.appendChild(document.createElement('hr')); | 264 list.appendChild(document.createElement('hr')); |
260 | 265 |
261 for (var j = 0; j < win.tabs.length; j++) { | 266 for (var j = 0; j < win.tabs.length; j++) { |
262 var tab = win.tabs[j]; | 267 var tab = win.tabs[j]; |
263 if (tab.hidden) | 268 if (tab.hidden) |
264 continue; | 269 continue; |
265 | 270 |
266 if (numTabsShown < maxNumTabs) { | 271 if (numTabsShown < maxNumTabs) { |
267 numTabsShown++; | 272 numTabsShown++; |
268 var a = createElementWithClassName('a', 'device-tab-entry'); | 273 var a = createElementWithClassName('a', 'device-tab-entry'); |
269 a.href = tab.url; | 274 a.href = tab.url; |
(...skipping 10 matching lines...) Expand all Loading... | |
280 return function(e) { | 285 return function(e) { |
281 recordUmaEvent_(HISTOGRAM_EVENT.LINK_CLICKED); | 286 recordUmaEvent_(HISTOGRAM_EVENT.LINK_CLICKED); |
282 chrome.send('openForeignSession', [sessionTag, windowId, tabId, | 287 chrome.send('openForeignSession', [sessionTag, windowId, tabId, |
283 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); | 288 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); |
284 e.preventDefault(); | 289 e.preventDefault(); |
285 }; | 290 }; |
286 }; | 291 }; |
287 a.addEventListener('click', makeClickHandler(sessionTag, | 292 a.addEventListener('click', makeClickHandler(sessionTag, |
288 String(win.sessionId), | 293 String(win.sessionId), |
289 String(tab.sessionId))); | 294 String(tab.sessionId))); |
290 contents.appendChild(a); | 295 list.appendChild(a); |
296 DevicesViewFocusRow.decorate(a, list); | |
297 this.focusGrid_.addRow(a); | |
291 } else { | 298 } else { |
292 numTabsHidden++; | 299 numTabsHidden++; |
293 } | 300 } |
294 } | 301 } |
295 } | 302 } |
296 | 303 |
297 if (numTabsHidden > 0) { | 304 if (numTabsHidden > 0) { |
298 var moreLink = document.createElement('a', 'action-link'); | 305 var moreLink = document.createElement('a', 'action-link'); |
299 moreLink.classList.add('device-show-more-tabs'); | 306 moreLink.classList.add('device-show-more-tabs'); |
300 moreLink.addEventListener('click', this.view_.increaseRowHeight.bind( | 307 moreLink.addEventListener('click', this.view_.increaseRowHeight.bind( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 | 352 |
346 /** | 353 /** |
347 * Functions and state for populating the page with HTML. | 354 * Functions and state for populating the page with HTML. |
348 * @constructor | 355 * @constructor |
349 */ | 356 */ |
350 function DevicesView() { | 357 function DevicesView() { |
351 this.devices_ = []; // List of individual devices. | 358 this.devices_ = []; // List of individual devices. |
352 this.resultDiv_ = $('other-devices'); | 359 this.resultDiv_ = $('other-devices'); |
353 this.searchText_ = ''; | 360 this.searchText_ = ''; |
354 this.rowHeights_ = [NB_ENTRIES_FIRST_ROW_COLUMN]; | 361 this.rowHeights_ = [NB_ENTRIES_FIRST_ROW_COLUMN]; |
355 this.focusGrids_ = []; | |
356 this.updateSignInState(loadTimeData.getBoolean('isUserSignedIn')); | 362 this.updateSignInState(loadTimeData.getBoolean('isUserSignedIn')); |
357 recordUmaEvent_(HISTOGRAM_EVENT.INITIALIZED); | 363 recordUmaEvent_(HISTOGRAM_EVENT.INITIALIZED); |
358 } | 364 } |
359 | 365 |
360 // DevicesView, public: ------------------------------------------------------- | 366 // DevicesView, public: ------------------------------------------------------- |
361 | 367 |
362 /** | 368 /** |
363 * Updates our sign in state by clearing the view is not signed in or sending | 369 * Updates our sign in state by clearing the view is not signed in or sending |
364 * a request to get the data to display otherwise. | 370 * a request to get the data to display otherwise. |
365 * @param {boolean} signedIn Whether the user is signed in or not. | 371 * @param {boolean} signedIn Whether the user is signed in or not. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 // width, and the nodeValue could contain sub nodes for highlighting, which | 501 // width, and the nodeValue could contain sub nodes for highlighting, which |
496 // makes it harder to extract the text data here. | 502 // makes it harder to extract the text data here. |
497 tabs = document.getElementsByClassName('device-tab-entry'); | 503 tabs = document.getElementsByClassName('device-tab-entry'); |
498 for (var i = 0; i < tabs.length; i++) { | 504 for (var i = 0; i < tabs.length; i++) { |
499 if (tabs[i].scrollWidth <= tabs[i].clientWidth) | 505 if (tabs[i].scrollWidth <= tabs[i].clientWidth) |
500 tabs[i].title = ''; | 506 tabs[i].title = ''; |
501 } | 507 } |
502 | 508 |
503 this.resultDiv_.appendChild( | 509 this.resultDiv_.appendChild( |
504 createElementWithClassName('div', 'other-devices-bottom')); | 510 createElementWithClassName('div', 'other-devices-bottom')); |
505 | |
506 this.focusGrids_.forEach(function(grid) { grid.destroy(); }); | |
507 this.focusGrids_.length = 0; | |
508 | |
509 var devices = this.resultDiv_.querySelectorAll('.device-contents'); | |
510 for (var i = 0; i < devices.length; ++i) { | |
511 var rows = devices[i].querySelectorAll('.device-tab-entry, button'); | |
512 if (!rows.length) | |
513 continue; | |
514 | |
515 var grid = new cr.ui.FocusGrid(); | |
516 for (var i = 0; i < rows.length; ++i) { | |
Dan Beam
2015/03/05 02:25:56
oh, this is the problem? i'd just change i -> j h
| |
517 DevicesViewFocusRow.decorate(rows[i], devices[i]); | |
518 grid.addRow(rows[i]); | |
519 } | |
520 this.focusGrids_.push(grid); | |
521 } | |
522 }; | 511 }; |
523 | 512 |
524 /** | 513 /** |
525 * Sets the menu model data. An empty list means that either there are no | 514 * Sets the menu model data. An empty list means that either there are no |
526 * foreign sessions, or tab sync is disabled for this profile. | 515 * foreign sessions, or tab sync is disabled for this profile. |
527 * |isTabSyncEnabled| makes it possible to distinguish between the cases. | 516 * |isTabSyncEnabled| makes it possible to distinguish between the cases. |
528 * | 517 * |
529 * @param {Array} sessionList Array of objects describing the sessions | 518 * @param {Array} sessionList Array of objects describing the sessions |
530 * from other devices. | 519 * from other devices. |
531 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? | 520 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 | 567 |
579 var doSearch = function(e) { | 568 var doSearch = function(e) { |
580 devicesView.setSearchText($('search-field').value); | 569 devicesView.setSearchText($('search-field').value); |
581 }; | 570 }; |
582 $('search-field').addEventListener('search', doSearch); | 571 $('search-field').addEventListener('search', doSearch); |
583 $('search-button').addEventListener('click', doSearch); | 572 $('search-button').addEventListener('click', doSearch); |
584 } | 573 } |
585 | 574 |
586 // Add handlers to HTML elements. | 575 // Add handlers to HTML elements. |
587 document.addEventListener('DOMContentLoaded', load); | 576 document.addEventListener('DOMContentLoaded', load); |
OLD | NEW |