Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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', | 6 is: 'history-list', |
| 7 | 7 |
| 8 behaviors: [HistoryListBehavior], | 8 behaviors: [HistoryListBehavior], |
| 9 | 9 |
| 10 properties: { | 10 properties: { |
| 11 // The search term for the current query. Set when the query returns. | 11 // The search term for the current query. Set when the query returns. |
| 12 searchedTerm: { | 12 searchedTerm: { |
| 13 type: String, | 13 type: String, |
| 14 value: '', | 14 value: '', |
| 15 }, | 15 }, |
| 16 | 16 |
| 17 lastSearchedTerm_: String, | 17 lastSearchedTerm_: String, |
|
tsergeant
2016/08/17 06:58:28
This is no longer used and can be removed.
lshang
2016/08/18 08:41:54
Done. Good catch!
| |
| 18 | 18 |
| 19 querying: Boolean, | 19 querying: Boolean, |
| 20 | 20 |
| 21 clearingHistory_: { | |
| 22 type: Boolean, | |
| 23 value: false, | |
| 24 }, | |
| 25 | |
| 21 // An array of history entries in reverse chronological order. | 26 // An array of history entries in reverse chronological order. |
| 22 historyData_: Array, | 27 historyData_: Array, |
| 23 | 28 |
| 24 resultLoadingDisabled_: { | 29 resultLoadingDisabled_: { |
| 25 type: Boolean, | 30 type: Boolean, |
| 26 value: false, | 31 value: false, |
| 27 }, | 32 }, |
| 28 }, | 33 }, |
| 29 | 34 |
| 30 listeners: { | 35 listeners: { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 * Disables history result loading when there are no more history results. | 68 * Disables history result loading when there are no more history results. |
| 64 */ | 69 */ |
| 65 disableResultLoading: function() { | 70 disableResultLoading: function() { |
| 66 this.resultLoadingDisabled_ = true; | 71 this.resultLoadingDisabled_ = true; |
| 67 }, | 72 }, |
| 68 | 73 |
| 69 /** | 74 /** |
| 70 * Adds the newly updated history results into historyData_. Adds new fields | 75 * Adds the newly updated history results into historyData_. Adds new fields |
| 71 * for each result. | 76 * for each result. |
| 72 * @param {!Array<!HistoryEntry>} historyResults The new history results. | 77 * @param {!Array<!HistoryEntry>} historyResults The new history results. |
| 78 * @param {boolean} incremental Whether the result is from loading more | |
| 79 * history, or a new search/list reload. | |
| 80 * @param {number} selectedCount Number of selected items. | |
| 73 */ | 81 */ |
| 74 addNewResults: function(historyResults) { | 82 addNewResults: function(historyResults, incremental, selectedCount) { |
| 75 var results = historyResults.slice(); | 83 var results = historyResults.slice(); |
| 76 /** @type {IronScrollThresholdElement} */(this.$['scroll-threshold']) | 84 /** @type {IronScrollThresholdElement} */(this.$['scroll-threshold']) |
| 77 .clearTriggers(); | 85 .clearTriggers(); |
| 78 | 86 |
| 79 if (this.lastSearchedTerm_ != this.searchedTerm) { | 87 // Do not reload the list when clearing browsing data and there are items |
| 88 // checked. | |
| 89 if (this.clearingHistory_) { | |
| 90 this.clearingHistory_ = false; | |
| 91 if (selectedCount > 0) | |
| 92 return; | |
| 93 } | |
| 94 | |
| 95 if (!incremental) { | |
| 80 this.resultLoadingDisabled_ = false; | 96 this.resultLoadingDisabled_ = false; |
| 81 if (this.historyData_) | 97 if (this.historyData_) |
| 82 this.splice('historyData_', 0, this.historyData_.length); | 98 this.splice('historyData_', 0, this.historyData_.length); |
| 83 this.fire('unselect-all'); | 99 this.fire('unselect-all'); |
| 84 this.lastSearchedTerm_ = this.searchedTerm; | 100 this.lastSearchedTerm_ = this.searchedTerm; |
| 85 } | 101 } |
| 86 | 102 |
| 87 if (this.historyData_) { | 103 if (this.historyData_) { |
| 88 // If we have previously received data, push the new items onto the | 104 // If we have previously received data, push the new items onto the |
| 89 // existing array. | 105 // existing array. |
| 90 results.unshift('historyData_'); | 106 results.unshift('historyData_'); |
| 91 this.push.apply(this, results); | 107 this.push.apply(this, results); |
| 92 } else { | 108 } else { |
| 93 // The first time we receive data, use set() to ensure the iron-list is | 109 // The first time we receive data, use set() to ensure the iron-list is |
| 94 // initialized correctly. | 110 // initialized correctly. |
| 95 this.set('historyData_', results); | 111 this.set('historyData_', results); |
| 96 } | 112 } |
| 97 }, | 113 }, |
| 98 | 114 |
| 115 clearingHistory: function() { | |
| 116 this.clearingHistory_ = true; | |
| 117 }, | |
| 118 | |
| 99 /** | 119 /** |
| 100 * Called when the page is scrolled to near the bottom of the list. | 120 * Called when the page is scrolled to near the bottom of the list. |
| 101 * @private | 121 * @private |
| 102 */ | 122 */ |
| 103 loadMoreData_: function() { | 123 loadMoreData_: function() { |
| 104 if (this.resultLoadingDisabled_ || this.querying) | 124 if (this.resultLoadingDisabled_ || this.querying) |
| 105 return; | 125 return; |
| 106 | 126 |
| 107 this.fire('load-more-history'); | 127 this.fire('load-more-history'); |
| 108 }, | 128 }, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 | 191 |
| 172 /** | 192 /** |
| 173 * @param {number} index | 193 * @param {number} index |
| 174 * @return {string} | 194 * @return {string} |
| 175 * @private | 195 * @private |
| 176 */ | 196 */ |
| 177 pathForItem_: function(index) { | 197 pathForItem_: function(index) { |
| 178 return 'historyData_.' + index; | 198 return 'historyData_.' + index; |
| 179 }, | 199 }, |
| 180 }); | 200 }); |
| OLD | NEW |