Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Side by Side Diff: chrome/browser/resources/md_history/synced_device_manager.js

Issue 2394433002: [MD History] Make synced devices keyboard navigation consistent. (Closed)
Patch Set: rebase/address comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 * @typedef {{device: string, 6 * @typedef {{device: string,
7 * lastUpdateTime: string, 7 * lastUpdateTime: string,
8 * opened: boolean, 8 * opened: boolean,
9 * separatorIndexes: !Array<number>, 9 * separatorIndexes: !Array<number>,
10 * timestamp: number, 10 * timestamp: number,
11 * tabs: !Array<!ForeignSessionTab>, 11 * tabs: !Array<!ForeignSessionTab>,
12 * tag: string}} 12 * tag: string}}
13 */ 13 */
14 var ForeignDeviceInternal; 14 var ForeignDeviceInternal;
15 15
16 Polymer({ 16 Polymer({
17 is: 'history-synced-device-manager', 17 is: 'history-synced-device-manager',
18 18
19 properties: { 19 properties: {
20 /** 20 /**
21 * @type {?Array<!ForeignSession>} 21 * @type {?Array<!ForeignSession>}
22 */ 22 */
23 sessionList: { 23 sessionList: {type: Array, observer: 'updateSyncedDevices'},
24 type: Array,
25 observer: 'updateSyncedDevices'
26 },
27 24
28 searchTerm: { 25 searchTerm: {type: String, observer: 'searchTermChanged'},
29 type: String,
30 observer: 'searchTermChanged'
31 },
32 26
33 /** 27 /**
34 * An array of synced devices with synced tab data. 28 * An array of synced devices with synced tab data.
35 * @type {!Array<!ForeignDeviceInternal>} 29 * @type {!Array<!ForeignDeviceInternal>}
36 */ 30 */
37 syncedDevices_: { 31 syncedDevices_: {type: Array, value: function() { return []; }},
38 type: Array,
39 value: function() { return []; }
40 },
41 32
42 /** @private */ 33 /** @private */
43 signInState: { 34 signInState: {
44 type: Boolean, 35 type: Boolean,
45 observer: 'signInStateChanged_', 36 observer: 'signInStateChanged_',
46 }, 37 },
47 38
48 /** @private */ 39 /** @private */
49 guestSession_: { 40 guestSession_: {
50 type: Boolean, 41 type: Boolean,
51 value: loadTimeData.getBoolean('isGuestSession'), 42 value: loadTimeData.getBoolean('isGuestSession'),
52 }, 43 },
53 44
54 /** @private */ 45 /** @private */
55 fetchingSyncedTabs_: { 46 fetchingSyncedTabs_: {
56 type: Boolean, 47 type: Boolean,
57 value: false, 48 value: false,
58 }, 49 },
59 50
60 hasSeenForeignData_: Boolean, 51 hasSeenForeignData_: Boolean,
61 }, 52 },
62 53
63 listeners: { 54 listeners: {
64 'toggle-menu': 'onToggleMenu_', 55 'toggle-menu': 'onToggleMenu_',
65 'scroll': 'onListScroll_' 56 'scroll': 'onListScroll_',
57 'update-focus-grid': 'updateFocusGrid_',
66 }, 58 },
67 59
60 /** @type {?cr.ui.FocusGrid} */
61 focusGrid_: null,
62
68 /** @override */ 63 /** @override */
69 attached: function() { 64 attached: function() {
65 this.focusGrid_ = new cr.ui.FocusGrid();
66
70 // Update the sign in state. 67 // Update the sign in state.
71 chrome.send('otherDevicesInitialized'); 68 chrome.send('otherDevicesInitialized');
72 md_history.BrowserService.getInstance().recordHistogram( 69 md_history.BrowserService.getInstance().recordHistogram(
73 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.INITIALIZED, 70 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.INITIALIZED,
74 SyncedTabsHistogram.LIMIT); 71 SyncedTabsHistogram.LIMIT);
75 }, 72 },
76 73
74 /** @override */
75 detached: function() { this.focusGrid_.destroy(); },
76
77 /** @return {HTMLElement} */ 77 /** @return {HTMLElement} */
78 getContentScrollTarget: function() { return this; }, 78 getContentScrollTarget: function() { return this; },
79 79
80 /** 80 /**
81 * @param {!ForeignSession} session 81 * @param {!ForeignSession} session
82 * @return {!ForeignDeviceInternal} 82 * @return {!ForeignDeviceInternal}
83 * @private
83 */ 84 */
84 createInternalDevice_: function(session) { 85 createInternalDevice_: function(session) {
85 var tabs = []; 86 var tabs = [];
86 var separatorIndexes = []; 87 var separatorIndexes = [];
87 for (var i = 0; i < session.windows.length; i++) { 88 for (var i = 0; i < session.windows.length; i++) {
88 var windowId = session.windows[i].sessionId; 89 var windowId = session.windows[i].sessionId;
89 var newTabs = session.windows[i].tabs; 90 var newTabs = session.windows[i].tabs;
90 if (newTabs.length == 0) 91 if (newTabs.length == 0)
91 continue; 92 continue;
92 93
(...skipping 23 matching lines...) Expand all
116 device: session.name, 117 device: session.name,
117 lastUpdateTime: '– ' + session.modifiedTime, 118 lastUpdateTime: '– ' + session.modifiedTime,
118 opened: true, 119 opened: true,
119 separatorIndexes: separatorIndexes, 120 separatorIndexes: separatorIndexes,
120 timestamp: session.timestamp, 121 timestamp: session.timestamp,
121 tabs: tabs, 122 tabs: tabs,
122 tag: session.tag, 123 tag: session.tag,
123 }; 124 };
124 }, 125 },
125 126
126 onSignInTap_: function() { 127 /** @private */
127 chrome.send('startSignInFlow'); 128 onSignInTap_: function() { chrome.send('startSignInFlow'); },
128 },
129 129
130 /** @private */
130 onListScroll_: function() { 131 onListScroll_: function() {
131 var menu = this.$.menu.getIfExists(); 132 var menu = this.$.menu.getIfExists();
132 if (menu) 133 if (menu)
133 menu.closeMenu(); 134 menu.closeMenu();
134 }, 135 },
135 136
137 /** @private */
136 onToggleMenu_: function(e) { 138 onToggleMenu_: function(e) {
137 var menu = /** @type {CrSharedMenuElement} */ this.$.menu.get(); 139 var menu = /** @type {CrSharedMenuElement} */ this.$.menu.get();
138 menu.toggleMenu(e.detail.target, e.detail.tag); 140 menu.toggleMenu(e.detail.target, e.detail.tag);
139 if (menu.menuOpen) { 141 if (menu.menuOpen) {
140 md_history.BrowserService.getInstance().recordHistogram( 142 md_history.BrowserService.getInstance().recordHistogram(
141 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.SHOW_SESSION_MENU, 143 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.SHOW_SESSION_MENU,
142 SyncedTabsHistogram.LIMIT); 144 SyncedTabsHistogram.LIMIT);
143 } 145 }
144 }, 146 },
145 147
148 /** @private */
146 onOpenAllTap_: function() { 149 onOpenAllTap_: function() {
147 var menu = assert(this.$.menu.getIfExists()); 150 var menu = assert(this.$.menu.getIfExists());
148 var browserService = md_history.BrowserService.getInstance(); 151 var browserService = md_history.BrowserService.getInstance();
149 browserService.recordHistogram( 152 browserService.recordHistogram(
150 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.OPEN_ALL, 153 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.OPEN_ALL,
151 SyncedTabsHistogram.LIMIT); 154 SyncedTabsHistogram.LIMIT);
152 browserService.openForeignSessionAllTabs( 155 browserService.openForeignSessionAllTabs(
153 menu.itemData); 156 menu.itemData);
154 menu.closeMenu(); 157 menu.closeMenu();
155 }, 158 },
156 159
160 /** @private */
161 updateFocusGrid_: function() {
162 if (!this.focusGrid_)
163 return;
164
165 this.focusGrid_.destroy();
166
167 this.debounce('updateFocusGrid', function() {
168 Polymer.dom(this.root)
169 .querySelectorAll('history-synced-device-card')
170 .reduce(
171 function(prev, cur) {
172 return prev.concat(cur.createFocusRows());
173 },
174 [])
175 .forEach(function(row) { this.focusGrid_.addRow(row); }.bind(this));
176 this.focusGrid_.ensureRowActive();
177 });
178 },
179
180 /** @private */
157 onDeleteSessionTap_: function() { 181 onDeleteSessionTap_: function() {
158 var menu = assert(this.$.menu.getIfExists()); 182 var menu = assert(this.$.menu.getIfExists());
159 var browserService = md_history.BrowserService.getInstance(); 183 var browserService = md_history.BrowserService.getInstance();
160 browserService.recordHistogram( 184 browserService.recordHistogram(
161 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HIDE_FOR_NOW, 185 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HIDE_FOR_NOW,
162 SyncedTabsHistogram.LIMIT); 186 SyncedTabsHistogram.LIMIT);
163 browserService.deleteForeignSession(menu.itemData); 187 browserService.deleteForeignSession(menu.itemData);
164 menu.closeMenu(); 188 menu.closeMenu();
165 }, 189 },
166 190
167 /** @private */ 191 /** @private */
168 clearDisplayedSyncedDevices_: function() { 192 clearDisplayedSyncedDevices_: function() { this.syncedDevices_ = []; },
169 this.syncedDevices_ = [];
170 },
171 193
172 /** 194 /**
173 * Decide whether or not should display no synced tabs message. 195 * Decide whether or not should display no synced tabs message.
174 * @param {boolean} signInState 196 * @param {boolean} signInState
175 * @param {number} syncedDevicesLength 197 * @param {number} syncedDevicesLength
176 * @param {boolean} guestSession 198 * @param {boolean} guestSession
177 * @return {boolean} 199 * @return {boolean}
178 */ 200 */
179 showNoSyncedMessage: function( 201 showNoSyncedMessage: function(
180 signInState, syncedDevicesLength, guestSession) { 202 signInState, syncedDevicesLength, guestSession) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (!sessionList) 249 if (!sessionList)
228 return; 250 return;
229 251
230 if (sessionList.length > 0 && !this.hasSeenForeignData_) { 252 if (sessionList.length > 0 && !this.hasSeenForeignData_) {
231 this.hasSeenForeignData_ = true; 253 this.hasSeenForeignData_ = true;
232 md_history.BrowserService.getInstance().recordHistogram( 254 md_history.BrowserService.getInstance().recordHistogram(
233 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HAS_FOREIGN_DATA, 255 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HAS_FOREIGN_DATA,
234 SyncedTabsHistogram.LIMIT); 256 SyncedTabsHistogram.LIMIT);
235 } 257 }
236 258
237 // First, update any existing devices that have changed. 259 var devices = [];
238 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); 260 sessionList.forEach(function(session) {
239 for (var i = 0; i < updateCount; i++) { 261 var device = this.createInternalDevice_(session);
240 var oldDevice = this.syncedDevices_[i]; 262 if (device.tabs.length != 0)
241 if (oldDevice.tag != sessionList[i].tag || 263 devices.push(device);
242 oldDevice.timestamp != sessionList[i].timestamp) { 264 }.bind(this));
243 var device = this.createInternalDevice_(sessionList[i]);
244 if (device.tabs.length != 0)
245 this.splice('syncedDevices_', i, 1, device);
246 }
247 }
248 265
249 if (sessionList.length >= this.syncedDevices_.length) { 266 this.syncedDevices_ = devices;
250 // The list grew; append new items.
251 for (var i = updateCount; i < sessionList.length; i++) {
252 var device = this.createInternalDevice_(sessionList[i]);
253 if (device.tabs.length != 0)
254 this.push('syncedDevices_', device);
255 }
256 } else {
257 // The list shrank; remove deleted items.
258 this.splice(
259 'syncedDevices_', updateCount,
260 this.syncedDevices_.length - updateCount);
261 }
calamity 2016/10/05 04:20:25 We took this code from the old history page and it
tsergeant 2016/10/05 04:39:59 The intention was that it would encourage Polymer
262 }, 267 },
263 268
264 /** 269 /**
265 * End fetching synced tabs when sync is disabled. 270 * End fetching synced tabs when sync is disabled.
266 */ 271 */
267 tabSyncDisabled: function() { 272 tabSyncDisabled: function() {
268 this.fetchingSyncedTabs_ = false; 273 this.fetchingSyncedTabs_ = false;
269 this.clearDisplayedSyncedDevices_(); 274 this.clearDisplayedSyncedDevices_();
270 }, 275 },
271 276
(...skipping 13 matching lines...) Expand all
285 // User signed in, show the loading message when querying for synced 290 // User signed in, show the loading message when querying for synced
286 // devices. 291 // devices.
287 this.fetchingSyncedTabs_ = true; 292 this.fetchingSyncedTabs_ = true;
288 }, 293 },
289 294
290 searchTermChanged: function(searchTerm) { 295 searchTermChanged: function(searchTerm) {
291 this.clearDisplayedSyncedDevices_(); 296 this.clearDisplayedSyncedDevices_();
292 this.updateSyncedDevices(this.sessionList); 297 this.updateSyncedDevices(this.sessionList);
293 } 298 }
294 }); 299 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698