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

Side by Side Diff: chrome/browser/resources/md_history/list_container.js

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

Powered by Google App Engine
This is Rietveld 408576698