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 }, | 23 }, |
24 | 24 |
25 observers: [ | 25 observers: [ |
26 'searchTermChanged_(queryState.searchTerm)', | 26 'searchTermChanged_(queryState.searchTerm)', |
| 27 'groupedOffsetChanged_(queryState.groupedOffset)', |
27 ], | 28 ], |
28 | 29 |
29 listeners: { | 30 listeners: { |
30 'history-list-scrolled': 'closeMenu_', | 31 'history-list-scrolled': 'closeMenu_', |
31 'load-more-history': 'loadMoreHistory_', | 32 'load-more-history': 'loadMoreHistory_', |
32 'toggle-menu': 'toggleMenu_', | 33 'toggle-menu': 'toggleMenu_', |
33 }, | 34 }, |
34 | 35 |
35 /** | 36 /** |
36 * @param {HistoryQuery} info An object containing information about the | 37 * @param {HistoryQuery} info An object containing information about the |
37 * query. | 38 * query. |
38 * @param {!Array<HistoryEntry>} results A list of results. | 39 * @param {!Array<!HistoryEntry>} results A list of results. |
39 */ | 40 */ |
40 historyResult: function(info, results) { | 41 historyResult: function(info, results) { |
41 this.initializeResults_(info, results); | 42 this.initializeResults_(info, results); |
42 this.closeMenu_(); | 43 this.closeMenu_(); |
43 | 44 |
44 if (info.term && !this.queryState.incremental) { | 45 if (info.term && !this.queryState.incremental) { |
45 Polymer.IronA11yAnnouncer.requestAvailability(); | 46 Polymer.IronA11yAnnouncer.requestAvailability(); |
46 this.fire('iron-announce', { | 47 this.fire('iron-announce', { |
47 text: | 48 text: |
48 md_history.HistoryItem.searchResultsTitle(results.length, info.term) | 49 md_history.HistoryItem.searchResultsTitle(results.length, info.term) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 * @param {HistoryRange} range | 143 * @param {HistoryRange} range |
143 * @private | 144 * @private |
144 */ | 145 */ |
145 groupedRangeChanged_: function(range, oldRange) { | 146 groupedRangeChanged_: function(range, oldRange) { |
146 this.selectedPage_ = range == HistoryRange.ALL_TIME ? | 147 this.selectedPage_ = range == HistoryRange.ALL_TIME ? |
147 'infinite-list' : 'grouped-list'; | 148 'infinite-list' : 'grouped-list'; |
148 | 149 |
149 if (oldRange == undefined) | 150 if (oldRange == undefined) |
150 return; | 151 return; |
151 | 152 |
| 153 this.set('queryState.groupedOffset', 0); |
| 154 |
| 155 // Reset the results on range change to prevent stale results from being |
| 156 // processed into the incoming range's UI. |
| 157 if (this.queryResult.info) { |
| 158 this.set('queryResult.results', []); |
| 159 this.historyResult(this.queryResult.info, []); |
| 160 } |
| 161 |
152 this.queryHistory(false); | 162 this.queryHistory(false); |
153 this.fire('history-view-changed'); | 163 this.fire('history-view-changed'); |
154 }, | 164 }, |
155 | 165 |
156 /** @private */ | 166 /** @private */ |
157 searchTermChanged_: function() { | 167 searchTermChanged_: function() { |
158 this.queryHistory(false); | 168 this.queryHistory(false); |
159 // TODO(tsergeant): Ignore incremental searches in this metric. | 169 // TODO(tsergeant): Ignore incremental searches in this metric. |
160 if (this.queryState.searchTerm) | 170 if (this.queryState.searchTerm) |
161 md_history.BrowserService.getInstance().recordAction('Search'); | 171 md_history.BrowserService.getInstance().recordAction('Search'); |
162 }, | 172 }, |
163 | 173 |
164 /** @private */ | 174 /** @private */ |
| 175 groupedOffsetChanged_: function() { |
| 176 this.queryHistory(false); |
| 177 }, |
| 178 |
| 179 /** @private */ |
165 loadMoreHistory_: function() { this.queryHistory(true); }, | 180 loadMoreHistory_: function() { this.queryHistory(true); }, |
166 | 181 |
167 /** | 182 /** |
168 * @param {HistoryQuery} info | 183 * @param {HistoryQuery} info |
169 * @param {!Array<HistoryEntry>} results | 184 * @param {!Array<HistoryEntry>} results |
170 * @private | 185 * @private |
171 */ | 186 */ |
172 initializeResults_: function(info, results) { | 187 initializeResults_: function(info, results) { |
173 if (results.length == 0) | 188 if (results.length == 0) |
174 return; | 189 return; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 }.bind(this)); | 285 }.bind(this)); |
271 menu.closeMenu(); | 286 menu.closeMenu(); |
272 }, | 287 }, |
273 | 288 |
274 /** | 289 /** |
275 * @return {HTMLElement} | 290 * @return {HTMLElement} |
276 * @private | 291 * @private |
277 */ | 292 */ |
278 getSelectedList_: function() { return this.$.content.selectedItem; }, | 293 getSelectedList_: function() { return this.$.content.selectedItem; }, |
279 }); | 294 }); |
OLD | NEW |