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

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

Issue 2578013002: [MD History] clang-format all javascript. (Closed)
Patch Set: rebase Created 3 years, 12 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
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} */
10 groupedRange: {
11 type: Number,
12 observer: 'groupedRangeChanged_',
13 },
14
9 // The path of the currently selected page. 15 // The path of the currently selected page.
10 selectedPage_: String, 16 selectedPage_: String,
11 17
12 // Whether domain-grouped history is enabled. 18 // Whether domain-grouped history is enabled.
13 grouped: Boolean, 19 grouped: Boolean,
14 20
15 /** @type {HistoryRange} */
16 groupedRange: {type: Number, observer: 'groupedRangeChanged_'},
17
18 /** @type {!QueryState} */ 21 /** @type {!QueryState} */
19 queryState: Object, 22 queryState: Object,
20 23
21 /** @type {!QueryResult} */ 24 /** @type {!QueryResult} */
22 queryResult: Object, 25 queryResult: Object,
23 }, 26 },
24 27
25 observers: [ 28 observers: [
26 'searchTermChanged_(queryState.searchTerm)', 29 'searchTermChanged_(queryState.searchTerm)',
27 'groupedOffsetChanged_(queryState.groupedOffset)', 30 'groupedOffsetChanged_(queryState.groupedOffset)',
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 this.set('queryState.querying', true); 81 this.set('queryState.querying', true);
79 this.set('queryState.incremental', incremental); 82 this.set('queryState.incremental', incremental);
80 83
81 var lastVisitTime = 0; 84 var lastVisitTime = 0;
82 if (incremental) { 85 if (incremental) {
83 var lastVisit = this.queryResult.results.slice(-1)[0]; 86 var lastVisit = this.queryResult.results.slice(-1)[0];
84 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0; 87 lastVisitTime = lastVisit ? Math.floor(lastVisit.time) : 0;
85 } 88 }
86 89
87 var maxResults = 90 var maxResults =
88 this.groupedRange == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; 91 this.groupedRange == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0;
89 chrome.send('queryHistory', [ 92 chrome.send('queryHistory', [
90 queryState.searchTerm, queryState.groupedOffset, queryState.range, 93 queryState.searchTerm, queryState.groupedOffset, queryState.range,
91 lastVisitTime, maxResults 94 lastVisitTime, maxResults
92 ]); 95 ]);
93 }, 96 },
94 97
95 historyDeleted: function() { 98 historyDeleted: function() {
96 // Do not reload the list when there are items checked. 99 // Do not reload the list when there are items checked.
97 if (this.getSelectedItemCount() > 0) 100 if (this.getSelectedItemCount() > 0)
98 return; 101 return;
99 102
100 // Reload the list with current search state. 103 // Reload the list with current search state.
101 this.queryHistory(false); 104 this.queryHistory(false);
102 }, 105 },
103 106
104 /** @return {Element} */ 107 /** @return {Element} */
105 getContentScrollTarget: function() { 108 getContentScrollTarget: function() { return this.getSelectedList_(); },
106 return this.getSelectedList_();
107 },
108 109
109 /** @return {number} */ 110 /** @return {number} */
110 getSelectedItemCount: function() { 111 getSelectedItemCount: function() {
111 return this.getSelectedList_().selectedPaths.size; 112 return this.getSelectedList_().selectedPaths.size;
112 }, 113 },
113 114
114 unselectAllItems: function(count) { 115 unselectAllItems: function(count) {
115 var selectedList = this.getSelectedList_(); 116 var selectedList = this.getSelectedList_();
116 if (selectedList) 117 if (selectedList)
117 selectedList.unselectAllItems(count); 118 selectedList.unselectAllItems(count);
(...skipping 15 matching lines...) Expand all
133 134
134 // TODO(dbeam): remove focus flicker caused by showModal() + focus(). 135 // TODO(dbeam): remove focus flicker caused by showModal() + focus().
135 this.$$('.action-button').focus(); 136 this.$$('.action-button').focus();
136 }, 137 },
137 138
138 /** 139 /**
139 * @param {HistoryRange} range 140 * @param {HistoryRange} range
140 * @private 141 * @private
141 */ 142 */
142 groupedRangeChanged_: function(range, oldRange) { 143 groupedRangeChanged_: function(range, oldRange) {
143 this.selectedPage_ = range == HistoryRange.ALL_TIME ? 144 this.selectedPage_ =
144 'infinite-list' : 'grouped-list'; 145 range == HistoryRange.ALL_TIME ? 'infinite-list' : 'grouped-list';
145 146
146 if (oldRange == undefined) 147 if (oldRange == undefined)
147 return; 148 return;
148 149
149 this.set('queryState.groupedOffset', 0); 150 this.set('queryState.groupedOffset', 0);
150 151
151 // Reset the results on range change to prevent stale results from being 152 // Reset the results on range change to prevent stale results from being
152 // processed into the incoming range's UI. 153 // processed into the incoming range's UI.
153 if (this.queryResult.info) { 154 if (this.queryResult.info) {
154 this.set('queryResult.results', []); 155 this.set('queryResult.results', []);
155 this.historyResult(this.queryResult.info, []); 156 this.historyResult(this.queryResult.info, []);
156 } 157 }
157 158
158 this.queryHistory(false); 159 this.queryHistory(false);
159 this.fire('history-view-changed'); 160 this.fire('history-view-changed');
160 }, 161 },
161 162
162 /** @private */ 163 /** @private */
163 searchTermChanged_: function() { 164 searchTermChanged_: function() {
164 this.queryHistory(false); 165 this.queryHistory(false);
165 // TODO(tsergeant): Ignore incremental searches in this metric. 166 // TODO(tsergeant): Ignore incremental searches in this metric.
166 if (this.queryState.searchTerm) 167 if (this.queryState.searchTerm)
167 md_history.BrowserService.getInstance().recordAction('Search'); 168 md_history.BrowserService.getInstance().recordAction('Search');
168 }, 169 },
169 170
170 /** @private */ 171 /** @private */
171 groupedOffsetChanged_: function() { 172 groupedOffsetChanged_: function() { this.queryHistory(false); },
172 this.queryHistory(false);
173 },
174 173
175 /** @private */ 174 /** @private */
176 loadMoreHistory_: function() { this.queryHistory(true); }, 175 loadMoreHistory_: function() { this.queryHistory(true); },
177 176
178 /** 177 /**
179 * @param {HistoryQuery} info 178 * @param {HistoryQuery} info
180 * @param {!Array<HistoryEntry>} results 179 * @param {!Array<HistoryEntry>} results
181 * @private 180 * @private
182 */ 181 */
183 initializeResults_: function(info, results) { 182 initializeResults_: function(info, results) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 }, 227 },
229 228
230 /** 229 /**
231 * Opens the overflow menu unless the menu is already open and the same button 230 * Opens the overflow menu unless the menu is already open and the same button
232 * is pressed. 231 * is pressed.
233 * @param {{detail: {item: !HistoryEntry, target: !HTMLElement}}} e 232 * @param {{detail: {item: !HistoryEntry, target: !HTMLElement}}} e
234 * @private 233 * @private
235 */ 234 */
236 toggleMenu_: function(e) { 235 toggleMenu_: function(e) {
237 var target = e.detail.target; 236 var target = e.detail.target;
238 var menu = /** @type {CrSharedMenuElement} */this.$.sharedMenu.get(); 237 var menu = /** @type {CrSharedMenuElement} */ this.$.sharedMenu.get();
239 menu.toggleMenu(target, e.detail); 238 menu.toggleMenu(target, e.detail);
240 }, 239 },
241 240
242 /** @private */ 241 /** @private */
243 onMoreFromSiteTap_: function() { 242 onMoreFromSiteTap_: function() {
244 md_history.BrowserService.getInstance().recordAction( 243 md_history.BrowserService.getInstance().recordAction(
245 'EntryMenuShowMoreFromSite'); 244 'EntryMenuShowMoreFromSite');
246 245
247 var menu = assert(this.$.sharedMenu.getIfExists()); 246 var menu = assert(this.$.sharedMenu.getIfExists());
248 this.set('queryState.searchTerm', menu.itemData.item.domain); 247 this.set('queryState.searchTerm', menu.itemData.item.domain);
249 menu.closeMenu(); 248 menu.closeMenu();
250 }, 249 },
251 250
252 /** @private */ 251 /** @private */
253 onRemoveFromHistoryTap_: function() { 252 onRemoveFromHistoryTap_: function() {
254 var browserService = md_history.BrowserService.getInstance(); 253 var browserService = md_history.BrowserService.getInstance();
255 browserService.recordAction('EntryMenuRemoveFromHistory'); 254 browserService.recordAction('EntryMenuRemoveFromHistory');
256 var menu = assert(this.$.sharedMenu.getIfExists()); 255 var menu = assert(this.$.sharedMenu.getIfExists());
257 var itemData = menu.itemData; 256 var itemData = menu.itemData;
258 browserService.deleteItems([itemData.item]) 257 browserService.deleteItems([itemData.item]).then(function(items) {
259 .then(function(items) { 258 // This unselect-all resets the toolbar when deleting a selected item
260 // This unselect-all resets the toolbar when deleting a selected item 259 // and clears selection state which can be invalid if items move
261 // and clears selection state which can be invalid if items move 260 // around during deletion.
262 // around during deletion. 261 // TODO(tsergeant): Make this automatic based on observing list
263 // TODO(tsergeant): Make this automatic based on observing list 262 // modifications.
264 // modifications. 263 this.fire('unselect-all');
265 this.fire('unselect-all'); 264 this.getSelectedList_().removeItemsByPath([itemData.path]);
266 this.getSelectedList_().removeItemsByPath([itemData.path]);
267 265
268 var index = itemData.index; 266 var index = itemData.index;
269 if (index == undefined) 267 if (index == undefined)
270 return; 268 return;
271 269
272 var browserService = md_history.BrowserService.getInstance(); 270 var browserService = md_history.BrowserService.getInstance();
273 browserService.recordHistogram( 271 browserService.recordHistogram(
274 'HistoryPage.RemoveEntryPosition', 272 'HistoryPage.RemoveEntryPosition',
275 Math.min(index, UMA_MAX_BUCKET_VALUE), UMA_MAX_BUCKET_VALUE); 273 Math.min(index, UMA_MAX_BUCKET_VALUE), UMA_MAX_BUCKET_VALUE);
276 if (index <= UMA_MAX_SUBSET_BUCKET_VALUE) { 274 if (index <= UMA_MAX_SUBSET_BUCKET_VALUE) {
277 browserService.recordHistogram( 275 browserService.recordHistogram(
278 'HistoryPage.RemoveEntryPositionSubset', index, 276 'HistoryPage.RemoveEntryPositionSubset', index,
279 UMA_MAX_SUBSET_BUCKET_VALUE); 277 UMA_MAX_SUBSET_BUCKET_VALUE);
280 } 278 }
281 }.bind(this)); 279 }.bind(this));
282 menu.closeMenu(); 280 menu.closeMenu();
283 }, 281 },
284 282
285 /** 283 /**
286 * @return {Element} 284 * @return {Element}
287 * @private 285 * @private
288 */ 286 */
289 getSelectedList_: function() { return this.$$('#' + this.selectedPage_); }, 287 getSelectedList_: function() { return this.$$('#' + this.selectedPage_); },
290 288
291 /** @private */ 289 /** @private */
292 canDeleteHistory_: function() { 290 canDeleteHistory_: function() {
293 return loadTimeData.getBoolean('allowDeletingHistory'); 291 return loadTimeData.getBoolean('allowDeletingHistory');
294 } 292 }
295 }); 293 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_history/lazy_load.vulcanized.html ('k') | chrome/browser/resources/md_history/router.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698