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

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

Issue 2112803002: MD History: Trim long item titles to reduce effect on performance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test Created 4 years, 5 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 cr.define('md_history', function() { 5 cr.define('md_history', function() {
6 var HistoryItem = Polymer({ 6 var HistoryItem = Polymer({
7 is: 'history-item', 7 is: 'history-item',
8 8
9 properties: { 9 properties: {
10 // Underlying HistoryEntry data for this item. Contains read-only fields 10 // Underlying HistoryEntry data for this item. Contains read-only fields
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 * @param {string} search The search term associated with these results. 74 * @param {string} search The search term associated with these results.
75 * @private 75 * @private
76 */ 76 */
77 cardTitle_: function(numberOfItems, historyDate, search) { 77 cardTitle_: function(numberOfItems, historyDate, search) {
78 if (!search) 78 if (!search)
79 return this.item.dateRelativeDay; 79 return this.item.dateRelativeDay;
80 80
81 var resultId = numberOfItems == 1 ? 'searchResult' : 'searchResults'; 81 var resultId = numberOfItems == 1 ? 'searchResult' : 'searchResults';
82 return loadTimeData.getStringF('foundSearchResults', numberOfItems, 82 return loadTimeData.getStringF('foundSearchResults', numberOfItems,
83 loadTimeData.getString(resultId), search); 83 loadTimeData.getString(resultId), search);
84 },
85
86 /**
87 * Crop long item titles to reduce their effect on layout performance. See
88 * crbug.com/621347.
89 * @param {string} title
90 * @return {string}
91 */
92 cropItemTitle_: function(title) {
93 return (title.length > TITLE_MAX_LENGTH) ?
94 title.substr(0, TITLE_MAX_LENGTH) :
95 title;
84 } 96 }
85 }); 97 });
86 98
87 /** 99 /**
88 * Check whether the time difference between the given history item and the 100 * Check whether the time difference between the given history item and the
89 * next one is large enough for a spacer to be required. 101 * next one is large enough for a spacer to be required.
90 * @param {Array<HistoryEntry>} visits 102 * @param {Array<HistoryEntry>} visits
91 * @param {number} currentIndex 103 * @param {number} currentIndex
92 * @param {string} searchedTerm 104 * @param {string} searchedTerm
93 * @return {boolean} Whether or not time gap separator is required. 105 * @return {boolean} Whether or not time gap separator is required.
94 * @private 106 * @private
95 */ 107 */
96 HistoryItem.needsTimeGap = function(visits, currentIndex, searchedTerm) { 108 HistoryItem.needsTimeGap = function(visits, currentIndex, searchedTerm) {
97 if (currentIndex >= visits.length - 1 || visits.length == 0) 109 if (currentIndex >= visits.length - 1 || visits.length == 0)
98 return false; 110 return false;
99 111
100 var currentItem = visits[currentIndex]; 112 var currentItem = visits[currentIndex];
101 var nextItem = visits[currentIndex + 1]; 113 var nextItem = visits[currentIndex + 1];
102 114
103 if (searchedTerm) 115 if (searchedTerm)
104 return currentItem.dateShort != nextItem.dateShort; 116 return currentItem.dateShort != nextItem.dateShort;
105 117
106 return currentItem.time - nextItem.time > BROWSING_GAP_TIME && 118 return currentItem.time - nextItem.time > BROWSING_GAP_TIME &&
107 currentItem.dateRelativeDay == nextItem.dateRelativeDay; 119 currentItem.dateRelativeDay == nextItem.dateRelativeDay;
108 }; 120 };
109 121
110 return { HistoryItem: HistoryItem }; 122 return { HistoryItem: HistoryItem };
111 }); 123 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_history/history_item.html ('k') | chrome/test/data/webui/md_history/history_item_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698