Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Polymer({ | 5 Polymer({ |
| 6 is: 'history-list-container', | 6 is: 'history-list-container', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** @type {HistoryRange} */ | 9 /** @type {HistoryRange} */ |
| 10 groupedRange: { | 10 groupedRange: { |
| 11 type: Number, | 11 type: Number, |
| 12 observer: 'groupedRangeChanged_', | 12 observer: 'groupedRangeChanged_', |
| 13 }, | 13 }, |
| 14 | 14 |
| 15 // The path of the currently selected page. | 15 // The path of the currently selected page. |
| 16 selectedPage_: String, | 16 selectedPage_: String, |
| 17 | 17 |
| 18 // Whether domain-grouped history is enabled. | 18 // Whether domain-grouped history is enabled. |
| 19 grouped: Boolean, | 19 grouped: Boolean, |
| 20 | 20 |
| 21 /** @type {!QueryState} */ | 21 /** @type {!QueryState} */ |
| 22 queryState: Object, | 22 queryState: Object, |
| 23 | 23 |
| 24 /** @type {!QueryResult} */ | 24 /** @type {!QueryResult} */ |
| 25 queryResult: Object, | 25 queryResult: Object, |
| 26 | |
| 27 /** | |
| 28 * @private {?{ | |
| 29 * index: number, item: !HistoryEntry, | |
| 30 * path: string, target: !HTMLElement | |
|
Dan Beam
2016/12/21 22:06:38
indent off, why are you wrapping like this?
dpapad
2016/12/21 22:41:09
Done. If only there was a linter to tell me how to
| |
| 31 * }} | |
| 32 */ | |
| 33 actionMenuModel_: Object, | |
| 26 }, | 34 }, |
| 27 | 35 |
| 28 observers: [ | 36 observers: [ |
| 29 'searchTermChanged_(queryState.searchTerm)', | 37 'searchTermChanged_(queryState.searchTerm)', |
| 30 'groupedOffsetChanged_(queryState.groupedOffset)', | 38 'groupedOffsetChanged_(queryState.groupedOffset)', |
| 31 ], | 39 ], |
| 32 | 40 |
| 33 listeners: { | 41 listeners: { |
| 34 'history-list-scrolled': 'closeMenu_', | |
| 35 'load-more-history': 'loadMoreHistory_', | 42 'load-more-history': 'loadMoreHistory_', |
| 36 'toggle-menu': 'toggleMenu_', | 43 'open-menu': 'openMenu_', |
| 37 }, | 44 }, |
| 38 | 45 |
| 39 /** | 46 /** |
| 40 * @param {HistoryQuery} info An object containing information about the | 47 * @param {HistoryQuery} info An object containing information about the |
| 41 * query. | 48 * query. |
| 42 * @param {!Array<!HistoryEntry>} results A list of results. | 49 * @param {!Array<!HistoryEntry>} results A list of results. |
| 43 */ | 50 */ |
| 44 historyResult: function(info, results) { | 51 historyResult: function(info, results) { |
| 45 this.initializeResults_(info, results); | 52 this.initializeResults_(info, results); |
| 46 this.closeMenu_(); | 53 this.closeMenu_(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 var dialog = assert(this.$.dialog.getIfExists()); | 222 var dialog = assert(this.$.dialog.getIfExists()); |
| 216 dialog.close(); | 223 dialog.close(); |
| 217 }, | 224 }, |
| 218 | 225 |
| 219 /** | 226 /** |
| 220 * Closes the overflow menu. | 227 * Closes the overflow menu. |
| 221 * @private | 228 * @private |
| 222 */ | 229 */ |
| 223 closeMenu_: function() { | 230 closeMenu_: function() { |
| 224 var menu = this.$.sharedMenu.getIfExists(); | 231 var menu = this.$.sharedMenu.getIfExists(); |
| 225 if (menu) | 232 if (menu && menu.open) { |
| 226 menu.closeMenu(); | 233 this.actionMenuModel_ = null; |
| 234 menu.close(); | |
| 235 } | |
| 227 }, | 236 }, |
| 228 | 237 |
| 229 /** | 238 /** |
| 230 * Opens the overflow menu unless the menu is already open and the same button | 239 * Opens the overflow menu. |
| 231 * is pressed. | 240 * @param {{detail: { |
| 232 * @param {{detail: {item: !HistoryEntry, target: !HTMLElement}}} e | 241 * index: number, item: !HistoryEntry, |
| 242 * path: string, target: !HTMLElement | |
| 243 * }}} e | |
| 233 * @private | 244 * @private |
| 234 */ | 245 */ |
| 235 toggleMenu_: function(e) { | 246 openMenu_: function(e) { |
| 236 var target = e.detail.target; | 247 var target = e.detail.target; |
| 248 this.actionMenuModel_ = e.detail; | |
| 237 var menu = /** @type {CrSharedMenuElement} */ this.$.sharedMenu.get(); | 249 var menu = /** @type {CrSharedMenuElement} */ this.$.sharedMenu.get(); |
| 238 menu.toggleMenu(target, e.detail); | 250 menu.showAt(target); |
| 239 }, | 251 }, |
| 240 | 252 |
| 241 /** @private */ | 253 /** @private */ |
| 242 onMoreFromSiteTap_: function() { | 254 onMoreFromSiteTap_: function() { |
| 243 md_history.BrowserService.getInstance().recordAction( | 255 md_history.BrowserService.getInstance().recordAction( |
| 244 'EntryMenuShowMoreFromSite'); | 256 'EntryMenuShowMoreFromSite'); |
| 245 | 257 |
| 246 var menu = assert(this.$.sharedMenu.getIfExists()); | 258 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 247 this.set('queryState.searchTerm', menu.itemData.item.domain); | 259 this.set('queryState.searchTerm', this.actionMenuModel_.item.domain); |
| 248 menu.closeMenu(); | 260 this.actionMenuModel_ = null; |
| 261 this.closeMenu_(); | |
| 249 }, | 262 }, |
| 250 | 263 |
| 251 /** @private */ | 264 /** @private */ |
| 252 onRemoveFromHistoryTap_: function() { | 265 onRemoveFromHistoryTap_: function() { |
| 253 var browserService = md_history.BrowserService.getInstance(); | 266 var browserService = md_history.BrowserService.getInstance(); |
| 254 browserService.recordAction('EntryMenuRemoveFromHistory'); | 267 browserService.recordAction('EntryMenuRemoveFromHistory'); |
| 255 var menu = assert(this.$.sharedMenu.getIfExists()); | 268 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 256 var itemData = menu.itemData; | 269 var itemData = this.actionMenuModel_; |
| 257 browserService.deleteItems([itemData.item]).then(function(items) { | 270 browserService.deleteItems([itemData.item]).then(function(items) { |
| 258 // This unselect-all resets the toolbar when deleting a selected item | 271 // This unselect-all resets the toolbar when deleting a selected item |
| 259 // and clears selection state which can be invalid if items move | 272 // and clears selection state which can be invalid if items move |
| 260 // around during deletion. | 273 // around during deletion. |
| 261 // TODO(tsergeant): Make this automatic based on observing list | 274 // TODO(tsergeant): Make this automatic based on observing list |
| 262 // modifications. | 275 // modifications. |
| 263 this.fire('unselect-all'); | 276 this.fire('unselect-all'); |
| 264 this.getSelectedList_().removeItemsByPath([itemData.path]); | 277 this.getSelectedList_().removeItemsByPath([itemData.path]); |
| 265 | 278 |
| 266 var index = itemData.index; | 279 var index = itemData.index; |
| 267 if (index == undefined) | 280 if (index == undefined) |
| 268 return; | 281 return; |
| 269 | 282 |
| 270 var browserService = md_history.BrowserService.getInstance(); | 283 var browserService = md_history.BrowserService.getInstance(); |
| 271 browserService.recordHistogram( | 284 browserService.recordHistogram( |
| 272 'HistoryPage.RemoveEntryPosition', | 285 'HistoryPage.RemoveEntryPosition', |
| 273 Math.min(index, UMA_MAX_BUCKET_VALUE), UMA_MAX_BUCKET_VALUE); | 286 Math.min(index, UMA_MAX_BUCKET_VALUE), UMA_MAX_BUCKET_VALUE); |
| 274 if (index <= UMA_MAX_SUBSET_BUCKET_VALUE) { | 287 if (index <= UMA_MAX_SUBSET_BUCKET_VALUE) { |
| 275 browserService.recordHistogram( | 288 browserService.recordHistogram( |
| 276 'HistoryPage.RemoveEntryPositionSubset', index, | 289 'HistoryPage.RemoveEntryPositionSubset', index, |
| 277 UMA_MAX_SUBSET_BUCKET_VALUE); | 290 UMA_MAX_SUBSET_BUCKET_VALUE); |
| 278 } | 291 } |
| 279 }.bind(this)); | 292 }.bind(this)); |
| 280 menu.closeMenu(); | 293 this.closeMenu_(); |
| 281 }, | 294 }, |
| 282 | 295 |
| 283 /** | 296 /** |
| 284 * @return {Element} | 297 * @return {Element} |
| 285 * @private | 298 * @private |
| 286 */ | 299 */ |
| 287 getSelectedList_: function() { return this.$$('#' + this.selectedPage_); }, | 300 getSelectedList_: function() { return this.$$('#' + this.selectedPage_); }, |
| 288 | 301 |
| 289 /** @private */ | 302 /** @private */ |
| 290 canDeleteHistory_: function() { | 303 canDeleteHistory_: function() { |
| 291 return loadTimeData.getBoolean('allowDeletingHistory'); | 304 return loadTimeData.getBoolean('allowDeletingHistory'); |
| 292 } | 305 } |
| 293 }); | 306 }); |
| OLD | NEW |