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