| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 Polymer({ | |
| 6 is: 'history-list-container', | |
| 7 | |
| 8 properties: { | |
| 9 canDeleteHistory_: { | |
| 10 type: Boolean, | |
| 11 value: loadTimeData.getBoolean('allowDeletingHistory'), | |
| 12 }, | |
| 13 | |
| 14 /** @type {!QueryState} */ | |
| 15 queryState: Object, | |
| 16 | |
| 17 /** @type {!QueryResult} */ | |
| 18 queryResult: Object, | |
| 19 | |
| 20 /** | |
| 21 * @private {?{ | |
| 22 * index: number, | |
| 23 * item: !HistoryEntry, | |
| 24 * path: string, | |
| 25 * target: !HTMLElement | |
| 26 * }} | |
| 27 */ | |
| 28 actionMenuModel_: Object, | |
| 29 }, | |
| 30 | |
| 31 listeners: { | |
| 32 'open-menu': 'openMenu_', | |
| 33 }, | |
| 34 | |
| 35 /** | |
| 36 * @param {HistoryQuery} info An object containing information about the | |
| 37 * query. | |
| 38 * @param {!Array<!HistoryEntry>} results A list of results. | |
| 39 */ | |
| 40 historyResult: function(info, results) { | |
| 41 this.initializeResults_(info, results); | |
| 42 this.closeMenu_(); | |
| 43 | |
| 44 if (info.term && !this.queryState.incremental) { | |
| 45 Polymer.IronA11yAnnouncer.requestAvailability(); | |
| 46 this.fire('iron-announce', { | |
| 47 text: | |
| 48 md_history.HistoryItem.searchResultsTitle(results.length, info.term) | |
| 49 }); | |
| 50 } | |
| 51 | |
| 52 var list = /** @type {HistoryListBehavior} */ this.getSelectedList_(); | |
| 53 list.addNewResults(results, this.queryState.incremental, info.finished); | |
| 54 }, | |
| 55 | |
| 56 historyDeleted: function() { | |
| 57 // Do not reload the list when there are items checked. | |
| 58 if (this.getSelectedItemCount() > 0) | |
| 59 return; | |
| 60 | |
| 61 // Reload the list with current search state. | |
| 62 this.fire('query-history', false); | |
| 63 }, | |
| 64 | |
| 65 /** @return {Element} */ | |
| 66 getContentScrollTarget: function() { | |
| 67 return this.getSelectedList_(); | |
| 68 }, | |
| 69 | |
| 70 /** @return {number} */ | |
| 71 getSelectedItemCount: function() { | |
| 72 return this.getSelectedList_().selectedPaths.size; | |
| 73 }, | |
| 74 | |
| 75 unselectAllItems: function(count) { | |
| 76 var selectedList = this.getSelectedList_(); | |
| 77 if (selectedList) | |
| 78 selectedList.unselectAllItems(count); | |
| 79 }, | |
| 80 | |
| 81 /** | |
| 82 * Delete all the currently selected history items. Will prompt the user with | |
| 83 * a dialog to confirm that the deletion should be performed. | |
| 84 */ | |
| 85 deleteSelectedWithPrompt: function() { | |
| 86 if (!loadTimeData.getBoolean('allowDeletingHistory')) | |
| 87 return; | |
| 88 | |
| 89 var browserService = md_history.BrowserService.getInstance(); | |
| 90 browserService.recordAction('RemoveSelected'); | |
| 91 if (this.queryState.searchTerm != '') | |
| 92 browserService.recordAction('SearchResultRemove'); | |
| 93 this.$.dialog.get().showModal(); | |
| 94 | |
| 95 // TODO(dbeam): remove focus flicker caused by showModal() + focus(). | |
| 96 this.$$('.action-button').focus(); | |
| 97 }, | |
| 98 | |
| 99 /** | |
| 100 * @param {HistoryQuery} info | |
| 101 * @param {!Array<HistoryEntry>} results | |
| 102 * @private | |
| 103 */ | |
| 104 initializeResults_: function(info, results) { | |
| 105 if (results.length == 0) | |
| 106 return; | |
| 107 | |
| 108 var currentDate = results[0].dateRelativeDay; | |
| 109 | |
| 110 for (var i = 0; i < results.length; i++) { | |
| 111 // Sets the default values for these fields to prevent undefined types. | |
| 112 results[i].selected = false; | |
| 113 results[i].readableTimestamp = | |
| 114 info.term == '' ? results[i].dateTimeOfDay : results[i].dateShort; | |
| 115 | |
| 116 if (results[i].dateRelativeDay != currentDate) { | |
| 117 currentDate = results[i].dateRelativeDay; | |
| 118 } | |
| 119 } | |
| 120 }, | |
| 121 | |
| 122 /** @private */ | |
| 123 onDialogConfirmTap_: function() { | |
| 124 md_history.BrowserService.getInstance().recordAction( | |
| 125 'ConfirmRemoveSelected'); | |
| 126 | |
| 127 this.getSelectedList_().deleteSelected(); | |
| 128 var dialog = assert(this.$.dialog.getIfExists()); | |
| 129 dialog.close(); | |
| 130 }, | |
| 131 | |
| 132 /** @private */ | |
| 133 onDialogCancelTap_: function() { | |
| 134 md_history.BrowserService.getInstance().recordAction( | |
| 135 'CancelRemoveSelected'); | |
| 136 | |
| 137 var dialog = assert(this.$.dialog.getIfExists()); | |
| 138 dialog.close(); | |
| 139 }, | |
| 140 | |
| 141 /** | |
| 142 * Closes the overflow menu. | |
| 143 * @private | |
| 144 */ | |
| 145 closeMenu_: function() { | |
| 146 var menu = this.$.sharedMenu.getIfExists(); | |
| 147 if (menu && menu.open) { | |
| 148 this.actionMenuModel_ = null; | |
| 149 menu.close(); | |
| 150 } | |
| 151 }, | |
| 152 | |
| 153 /** | |
| 154 * Opens the overflow menu. | |
| 155 * @param {{detail: { | |
| 156 * index: number, item: !HistoryEntry, | |
| 157 * path: string, target: !HTMLElement | |
| 158 * }}} e | |
| 159 * @private | |
| 160 */ | |
| 161 openMenu_: function(e) { | |
| 162 var target = e.detail.target; | |
| 163 this.actionMenuModel_ = e.detail; | |
| 164 var menu = /** @type {CrSharedMenuElement} */ this.$.sharedMenu.get(); | |
| 165 menu.showAt(target); | |
| 166 }, | |
| 167 | |
| 168 /** @private */ | |
| 169 onMoreFromSiteTap_: function() { | |
| 170 md_history.BrowserService.getInstance().recordAction( | |
| 171 'EntryMenuShowMoreFromSite'); | |
| 172 | |
| 173 var menu = assert(this.$.sharedMenu.getIfExists()); | |
| 174 this.fire('change-query', {search: this.actionMenuModel_.item.domain}); | |
| 175 this.actionMenuModel_ = null; | |
| 176 this.closeMenu_(); | |
| 177 }, | |
| 178 | |
| 179 /** @private */ | |
| 180 onRemoveFromHistoryTap_: function() { | |
| 181 var browserService = md_history.BrowserService.getInstance(); | |
| 182 browserService.recordAction('EntryMenuRemoveFromHistory'); | |
| 183 var menu = assert(this.$.sharedMenu.getIfExists()); | |
| 184 var itemData = this.actionMenuModel_; | |
| 185 browserService.deleteItems([itemData.item]).then(function(items) { | |
| 186 // This unselect-all resets the toolbar when deleting a selected item | |
| 187 // and clears selection state which can be invalid if items move | |
| 188 // around during deletion. | |
| 189 // TODO(tsergeant): Make this automatic based on observing list | |
| 190 // modifications. | |
| 191 this.fire('unselect-all'); | |
| 192 this.getSelectedList_().removeItemsByPath([itemData.path]); | |
| 193 | |
| 194 var index = itemData.index; | |
| 195 if (index == undefined) | |
| 196 return; | |
| 197 | |
| 198 var browserService = md_history.BrowserService.getInstance(); | |
| 199 browserService.recordHistogram( | |
| 200 'HistoryPage.RemoveEntryPosition', | |
| 201 Math.min(index, UMA_MAX_BUCKET_VALUE), UMA_MAX_BUCKET_VALUE); | |
| 202 if (index <= UMA_MAX_SUBSET_BUCKET_VALUE) { | |
| 203 browserService.recordHistogram( | |
| 204 'HistoryPage.RemoveEntryPositionSubset', index, | |
| 205 UMA_MAX_SUBSET_BUCKET_VALUE); | |
| 206 } | |
| 207 }.bind(this)); | |
| 208 this.closeMenu_(); | |
| 209 }, | |
| 210 | |
| 211 /** | |
| 212 * @return {Element} | |
| 213 * @private | |
| 214 */ | |
| 215 getSelectedList_: function() { | |
| 216 return this.$['infinite-list']; | |
| 217 }, | |
| 218 }); | |
| OLD | NEW |