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

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: hook to dom-change 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 focusGrid_: null,
tsergeant 2016/10/04 06:09:02 /** @type {?cr.ui.FocusGrid} */
calamity 2016/10/05 04:20:25 Done.
61
68 /** @override */ 62 /** @override */
69 attached: function() { 63 attached: function() {
64 this.focusGrid_ = new cr.ui.FocusGrid();
65
70 // Update the sign in state. 66 // Update the sign in state.
71 chrome.send('otherDevicesInitialized'); 67 chrome.send('otherDevicesInitialized');
72 md_history.BrowserService.getInstance().recordHistogram( 68 md_history.BrowserService.getInstance().recordHistogram(
73 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.INITIALIZED, 69 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.INITIALIZED,
74 SyncedTabsHistogram.LIMIT); 70 SyncedTabsHistogram.LIMIT);
75 }, 71 },
76 72
73 /** @override */
74 detached: function() { this.focusGrid_.destroy(); },
75
77 /** @return {HTMLElement} */ 76 /** @return {HTMLElement} */
78 getContentScrollTarget: function() { return this; }, 77 getContentScrollTarget: function() { return this; },
79 78
80 /** 79 /**
81 * @param {!ForeignSession} session 80 * @param {!ForeignSession} session
82 * @return {!ForeignDeviceInternal} 81 * @return {!ForeignDeviceInternal}
83 */ 82 */
84 createInternalDevice_: function(session) { 83 createInternalDevice_: function(session) {
85 var tabs = []; 84 var tabs = [];
86 var separatorIndexes = []; 85 var separatorIndexes = [];
(...skipping 29 matching lines...) Expand all
116 device: session.name, 115 device: session.name,
117 lastUpdateTime: '– ' + session.modifiedTime, 116 lastUpdateTime: '– ' + session.modifiedTime,
118 opened: true, 117 opened: true,
119 separatorIndexes: separatorIndexes, 118 separatorIndexes: separatorIndexes,
120 timestamp: session.timestamp, 119 timestamp: session.timestamp,
121 tabs: tabs, 120 tabs: tabs,
122 tag: session.tag, 121 tag: session.tag,
123 }; 122 };
124 }, 123 },
125 124
126 onSignInTap_: function() { 125 onSignInTap_: function() { chrome.send('startSignInFlow'); },
127 chrome.send('startSignInFlow');
128 },
129 126
130 onListScroll_: function() { 127 onListScroll_: function() {
131 var menu = this.$.menu.getIfExists(); 128 var menu = this.$.menu.getIfExists();
132 if (menu) 129 if (menu)
133 menu.closeMenu(); 130 menu.closeMenu();
134 }, 131 },
135 132
136 onToggleMenu_: function(e) { 133 onToggleMenu_: function(e) {
137 var menu = /** @type {CrSharedMenuElement} */ this.$.menu.get(); 134 var menu = /** @type {CrSharedMenuElement} */ this.$.menu.get();
138 menu.toggleMenu(e.detail.target, e.detail.tag); 135 menu.toggleMenu(e.detail.target, e.detail.tag);
139 if (menu.menuOpen) { 136 if (menu.menuOpen) {
140 md_history.BrowserService.getInstance().recordHistogram( 137 md_history.BrowserService.getInstance().recordHistogram(
141 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.SHOW_SESSION_MENU, 138 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.SHOW_SESSION_MENU,
142 SyncedTabsHistogram.LIMIT); 139 SyncedTabsHistogram.LIMIT);
143 } 140 }
144 }, 141 },
145 142
146 onOpenAllTap_: function() { 143 onOpenAllTap_: function() {
147 var menu = assert(this.$.menu.getIfExists()); 144 var menu = assert(this.$.menu.getIfExists());
148 var browserService = md_history.BrowserService.getInstance(); 145 var browserService = md_history.BrowserService.getInstance();
149 browserService.recordHistogram( 146 browserService.recordHistogram(
150 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.OPEN_ALL, 147 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.OPEN_ALL,
151 SyncedTabsHistogram.LIMIT); 148 SyncedTabsHistogram.LIMIT);
152 browserService.openForeignSessionAllTabs( 149 browserService.openForeignSessionAllTabs(
153 menu.itemData); 150 menu.itemData);
154 menu.closeMenu(); 151 menu.closeMenu();
155 }, 152 },
156 153
154 updateFocusGrid_: function() {
tsergeant 2016/10/04 06:09:02 /** @private */
calamity 2016/10/05 04:20:25 Privated the rest of this file too.
155 this.focusGrid_.destroy();
156
157 this.debounce('updateFocusGrid', function() {
158 Polymer.dom(this.root)
159 .querySelectorAll('history-synced-device-card')
160 .reduce(
161 function(prev, cur) {
162 return prev.concat(cur.createFocusRows());
163 },
164 [])
165 .forEach(function(row) { this.focusGrid_.addRow(row); }.bind(this));
166 this.focusGrid_.ensureRowActive();
167 });
168 },
169
157 onDeleteSessionTap_: function() { 170 onDeleteSessionTap_: function() {
158 var menu = assert(this.$.menu.getIfExists()); 171 var menu = assert(this.$.menu.getIfExists());
159 var browserService = md_history.BrowserService.getInstance(); 172 var browserService = md_history.BrowserService.getInstance();
160 browserService.recordHistogram( 173 browserService.recordHistogram(
161 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HIDE_FOR_NOW, 174 SYNCED_TABS_HISTOGRAM_NAME, SyncedTabsHistogram.HIDE_FOR_NOW,
162 SyncedTabsHistogram.LIMIT); 175 SyncedTabsHistogram.LIMIT);
163 browserService.deleteForeignSession(menu.itemData); 176 browserService.deleteForeignSession(menu.itemData);
164 menu.closeMenu(); 177 menu.closeMenu();
165 }, 178 },
166 179
167 /** @private */ 180 /** @private */
168 clearDisplayedSyncedDevices_: function() { 181 clearDisplayedSyncedDevices_: function() { this.syncedDevices_ = []; },
169 this.syncedDevices_ = [];
170 },
171 182
172 /** 183 /**
173 * Decide whether or not should display no synced tabs message. 184 * Decide whether or not should display no synced tabs message.
174 * @param {boolean} signInState 185 * @param {boolean} signInState
175 * @param {number} syncedDevicesLength 186 * @param {number} syncedDevicesLength
176 * @param {boolean} guestSession 187 * @param {boolean} guestSession
177 * @return {boolean} 188 * @return {boolean}
178 */ 189 */
179 showNoSyncedMessage: function( 190 showNoSyncedMessage: function(
180 signInState, syncedDevicesLength, guestSession) { 191 signInState, syncedDevicesLength, guestSession) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // User signed in, show the loading message when querying for synced 296 // User signed in, show the loading message when querying for synced
286 // devices. 297 // devices.
287 this.fetchingSyncedTabs_ = true; 298 this.fetchingSyncedTabs_ = true;
288 }, 299 },
289 300
290 searchTermChanged: function(searchTerm) { 301 searchTermChanged: function(searchTerm) {
291 this.clearDisplayedSyncedDevices_(); 302 this.clearDisplayedSyncedDevices_();
292 this.updateSyncedDevices(this.sessionList); 303 this.updateSyncedDevices(this.sessionList);
293 } 304 }
294 }); 305 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698