| Index: chrome/browser/resources/md_history/history_list.js
|
| diff --git a/chrome/browser/resources/md_history/history_list.js b/chrome/browser/resources/md_history/history_list.js
|
| index fe3926f570966f8d3f2f5125da96bfeac3d83016..9803295b4dada421ad00687ef4743f9fb99b4617 100644
|
| --- a/chrome/browser/resources/md_history/history_list.js
|
| +++ b/chrome/browser/resources/md_history/history_list.js
|
| @@ -24,9 +24,20 @@ Polymer({
|
| reflectToAttribute: true
|
| },
|
|
|
| + searchTerm: {
|
| + type: String,
|
| + value: ''
|
| + },
|
| +
|
| menuIdentifier: {
|
| type: Number,
|
| value: 0
|
| + },
|
| +
|
| + // Page waits until results have finished loading before displaying message.
|
| + loading_: {
|
| + type: Boolean,
|
| + value: true
|
| }
|
| },
|
|
|
| @@ -46,6 +57,16 @@ Polymer({
|
| },
|
|
|
| /**
|
| + * Clear the page completely so the page can display new results (search).
|
| + */
|
| + resetHistoryResults: function() {
|
| + // TODO(hsampson): make it so the old results aren't replaced immediately,
|
| + // only replaced when new results come in.
|
| + this.loading_ = true;
|
| + this.splice('historyData', 0, this.historyData.length);
|
| + },
|
| +
|
| + /**
|
| * Opens the overflow menu unless the menu is already open and the same button
|
| * is pressed.
|
| * @param {Event} e The event with details of the menu item that was clicked.
|
| @@ -73,9 +94,13 @@ Polymer({
|
| * for each result.
|
| * @param {!Array<!HistoryEntry>} historyResults The new history results.
|
| */
|
| - addNewResults: function(historyResults) {
|
| - if (historyResults.length == 0)
|
| + addNewResults: function(historyResults, search) {
|
| + this.searchTerm = search;
|
| +
|
| + if (historyResults.length == 0) {
|
| + this.loading_ = false;
|
| return;
|
| + }
|
|
|
| // Creates a copy of historyResults to prevent accidentally modifying this
|
| // field.
|
| @@ -97,15 +122,20 @@ Polymer({
|
| results[i].selected = false;
|
| results[i].isLastItem = false;
|
| results[i].isFirstItem = false;
|
| + results[i].visibleTimestamp =
|
| + search == '' ? results[i].dateTimeOfDay : results[i].dateShort;
|
|
|
| if (results[i].dateRelativeDay != currentDate) {
|
| results[i - 1].isLastItem = true;
|
| results[i].isFirstItem = true;
|
| currentDate = results[i].dateRelativeDay;
|
| }
|
| - results[i].needsTimeGap = this.needsTimeGap_(results, i);
|
| + if (i != 0) {
|
| + results[i - 1].needsTimeGap = this.needsTimeGap_(results, i - 1);
|
| + }
|
| }
|
| results[i - 1].isLastItem = true;
|
| + results[i - 1].needsTimeGap = false;
|
|
|
| // If it's the first time we get data, the first item will always be the
|
| // first card.
|
| @@ -117,6 +147,7 @@ Polymer({
|
| this.push.apply(this, results);
|
|
|
| this.lastVisitedTime = this.historyData[this.historyData.length - 1].time;
|
| + this.loading_ = false;
|
| },
|
|
|
| /**
|
| @@ -198,6 +229,7 @@ Polymer({
|
| return toBeRemoved;
|
| }
|
| }
|
| + return toBeRemoved;
|
| },
|
|
|
| /**
|
| @@ -213,10 +245,10 @@ Polymer({
|
| var scrollOffset = 10;
|
| var scrollElem = this.$['infinite-list'];
|
|
|
| - if (scrollElem.scrollHeight <=
|
| + if (!this.loading_ && scrollElem.scrollHeight <=
|
| scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
|
| chrome.send('queryHistory',
|
| - ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
|
| + [this.searchTerm, 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
|
| }
|
| },
|
|
|
| @@ -232,10 +264,33 @@ Polymer({
|
| var currentItem = results[index];
|
| var nextItem = results[index + 1];
|
|
|
| - if (index + 1 >= results.length)
|
| - return false;
|
| + if (this.searchTerm)
|
| + return currentItem.visibleTimestamp != nextItem.visibleTimestamp;
|
| + else
|
| + return currentItem.time - nextItem.time > BROWSING_GAP_TIME &&
|
| + currentItem.dateRelativeDay == nextItem.dateRelativeDay;
|
| + },
|
| +
|
| + /**
|
| + * True if there are no results available and the page has finished loading.
|
| + * @param {number} numberOfResults The length of historyDataByDay_.
|
| + * @param {boolean} loading Whether the page has finished loading results.
|
| + * @return {boolean} Whether there are results to show.
|
| + * @private
|
| + */
|
| + noResultsAvailable_: function(numberOfResults, loading) {
|
| + return numberOfResults == 0 && !loading;
|
| + },
|
|
|
| - return currentItem.time - nextItem.time > BROWSING_GAP_TIME &&
|
| - currentItem.dateRelativeDay == nextItem.dateRelativeDay;
|
| + /**
|
| + * Return the message to be displayed if there are no results based on whether
|
| + * the empty results were for a search or normal history results.
|
| + * @param {string} search The search term for these results.
|
| + * @return {string} The displayed message.
|
| + * @private
|
| + */
|
| + noResultsMessage_: function(search) {
|
| + var messageId = search != '' ? 'noSearchResults' : 'noResults';
|
| + return loadTimeData.getString(messageId);
|
| }
|
| });
|
|
|