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