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

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

Issue 1641543002: MD History: Refactored design for displaying history information (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@second_patch
Patch Set: removed dodgy fix for end of history query: Created 4 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
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-card-manager', 6 is: 'history-list',
7 7
8 properties: { 8 properties: {
9 // An array of objects sorted in reverse chronological order. 9 // The time in seconds of the last history item in historyData.
10 // Each object has a date and the history items belonging to that date.
11 historyDataByDay_: {
12 type: Array,
13 value: function() { return []; }
14 },
15
16 // The time of access of the last element of historyDataByDay_.
17 lastVisitedTime: { 10 lastVisitedTime: {
18 type: Number, 11 type: Number,
19 value: 0 12 value: 0
20 }, 13 },
21 14
22 menuOpen: { 15 menuOpen: {
23 type: Boolean, 16 type: Boolean,
24 value: false, 17 value: false,
25 reflectToAttribute: true 18 reflectToAttribute: true
26 }, 19 },
27 20
28 menuIdentifier: { 21 menuIdentifier: {
29 type: Number, 22 type: Number,
30 value: 0 23 value: 0
24 },
25 // An array of history entries in reverse chronological order.
26 historyData: {
tsergeant 2016/02/02 05:58:00 Minor nit: Maybe move this to the top of propertie
yingran 2016/02/02 06:49:11 Done.
27 type: Array,
28 value: function() { return []; }
31 } 29 }
32 }, 30 },
33 31
34 /** @const @private */ 32 /** @const @private */
35 X_OFFSET_: 30, 33 X_OFFSET_: 30,
36 34
37 listeners: { 35 listeners: {
38 'tap': 'closeMenu', 36 'tap': 'closeMenu',
39 'toggle-menu': 'toggleMenu_' 37 'toggle-menu': 'toggleMenu_'
40 }, 38 },
(...skipping 22 matching lines...) Expand all
63 this.menuIdentifier = e.detail.accessTime; 61 this.menuIdentifier = e.detail.accessTime;
64 62
65 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu, 63 cr.ui.positionPopupAtPoint(e.detail.x + this.X_OFFSET_, e.detail.y, menu,
66 cr.ui.AnchorType.BEFORE); 64 cr.ui.AnchorType.BEFORE);
67 65
68 menu.focus(); 66 menu.focus();
69 } 67 }
70 }, 68 },
71 69
72 /** 70 /**
73 * Split the newly updated history results into history items sorted via day 71 * Adds the newly updated history results into historyData. Adds new fields
74 * accessed. 72 * for each result. Preserves the scroll position of the window when new data
73 * is loaded.
75 * @param {!Array<!HistoryEntry>} results The new history results. 74 * @param {!Array<!HistoryEntry>} results The new history results.
76 */ 75 */
77 addNewResults: function(results) { 76 addNewResults: function(results) {
78 if (results.length == 0) 77 if (results.length == 0)
79 return; 78 return;
80 79
81 var dateSortedData = []; 80 var scrollPosition = this.$['infinite-list'].scrollTop;
82 var historyItems = []; 81 // If it's the first time we get data, the first item will always be the
82 // first card.
83 if (this.historyData.length == 0) {
84 results[0].isFirstItem = true;
85 }
86
83 var currentDate = results[0].dateRelativeDay; 87 var currentDate = results[0].dateRelativeDay;
84 88
85 for (var i = 0; i < results.length; i++) { 89 for (var i = 0; i < results.length; i++) {
86 if (!currentDate)
87 continue;
88
89 results[i].selected = false; 90 results[i].selected = false;
90 if (results[i].dateRelativeDay != currentDate) { 91 if (results[i].dateRelativeDay != currentDate) {
91 this.appendHistoryData_(currentDate, historyItems); 92 results[i - 1].isLastItem = true;
tsergeant 2016/02/02 05:58:00 Just like what you changed in the C++ layer last w
yingran 2016/02/02 06:49:11 Done.
93 results[i].isFirstItem = true;
92 currentDate = results[i].dateRelativeDay; 94 currentDate = results[i].dateRelativeDay;
93 historyItems = [];
94 } 95 }
95 historyItems.push(results[i]); 96 results[i].needsTimeGap = this.needsTimeGap_(results, i);
96 } 97 }
97 98
98 if (currentDate) 99 this.set('historyData', this.historyData.concat(results));
99 this.appendHistoryData_(currentDate, historyItems); 100 this.lastVisitedTime = this.historyData[this.historyData.length - 1].time;
100 101 this.$['infinite-list'].scrollTop = scrollPosition;
101 this.lastVisitedTime = historyItems[historyItems.length - 1].time;
102 }, 102 },
103 103
104 /** 104 /**
105 * Cycle through each entry in historyDataByDay_ and set all items to be 105 * Cycle through each entry in historyData and set all items to be
106 * unselected. 106 * unselected.
107 * @param {number} overallItemCount The number of checkboxes selected.
107 */ 108 */
108 unselectAllItems: function(overallItemCount) { 109 unselectAllItems: function(overallItemCount) {
109 var historyCardData = this.historyDataByDay_; 110 for (var i = 0; i < this.historyData.length; i++) {
110 111 if (this.historyData[i].selected) {
111 for (var i = 0; i < historyCardData.length; i++) { 112 this.set('historyData.' + i + '.selected', false);
112 var items = historyCardData[i].historyItems; 113 overallItemCount--;
113 for (var j = 0; j < items.length; j++) { 114 if (overallItemCount == 0)
114 if (items[j].selected) { 115 break;
115 this.set('historyDataByDay_.' + i + '.historyItems.' + j +
116 '.selected', false);
117 overallItemCount--;
118 if (overallItemCount == 0)
119 break;
120 }
121 } 116 }
122 } 117 }
123 }, 118 },
124 119
125 /** 120 /**
126 * Adds the given items into historyDataByDay_. Adds items to the last
127 * existing day if the date matches, creates a new element otherwise.
128 * @param {string} date The date of the history items.
129 * @param {!Array<!HistoryEntry>} historyItems The list of history items for
130 * the current date.
131 * @private
132 */
133 appendHistoryData_: function(date, historyItems) {
134 var lastDay = this.historyDataByDay_.length - 1;
135 if (lastDay > 0 && date == this.historyDataByDay_[lastDay].date) {
136 this.set('historyDataByDay_.' + lastDay + '.historyItems',
137 this.historyDataByDay_[lastDay].historyItems.concat(historyItems));
138 } else {
139 this.push('historyDataByDay_', {
140 date: date,
141 historyItems: historyItems
142 });
143 }
144 },
145
146 /**
147 * Called when the card manager is scrolled. 121 * Called when the card manager is scrolled.
148 * @private 122 * @private
149 */ 123 */
150 scrollHandler_: function() { 124 scrollHandler_: function() {
151 // Close overflow menu on scroll. 125 // Close overflow menu on scroll.
152 this.closeMenu(); 126 this.closeMenu();
153 127
154 // Requests the next list of results when the scrollbar is near the bottom 128 // Requests the next list of results when the scrollbar is near the bottom
155 // of the window. 129 // of the window.
156 var scrollOffset = 10; 130 var scrollOffset = 10;
157 var scrollElem = this.$['infinite-list']; 131 var scrollElem = this.$['infinite-list'];
158 132
159 if (scrollElem.scrollHeight <= 133 if (scrollElem.scrollHeight <=
160 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) { 134 scrollElem.scrollTop + scrollElem.clientHeight + scrollOffset) {
161 chrome.send('queryHistory', 135 chrome.send('queryHistory',
162 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]); 136 ['', 0, 0, this.lastVisitedTime, RESULTS_PER_PAGE]);
163 } 137 }
138 },
139
140 /**
141 * Check whether the time difference between the given history item and the
142 * next one is large enough for a spacer to be required.
143 * @param {number} index The index number of the first item being compared.
144 * @return {boolean} Whether or not time gap separator is required.
145 * @private
146 */
147 needsTimeGap_: function(results, index) {
148 var items = results;
149 return index + 1 < items.length &&
150 items[index].time - items[index + 1].time > BROWSING_GAP_TIME &&
151 items[index].dateRelativeDay == items[index + 1].dateRelativeDay;
164 } 152 }
165 }); 153 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698