Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <include src="../uber/uber_utils.js"> | 5 <include src="../uber/uber_utils.js"> |
| 6 <include src="history_focus_manager.js"> | 6 <include src="history_focus_manager.js"> |
| 7 | 7 |
| 8 /////////////////////////////////////////////////////////////////////////////// | 8 /////////////////////////////////////////////////////////////////////////////// |
| 9 // Globals: | 9 // Globals: |
| 10 /** @const */ var RESULTS_PER_PAGE = 150; | 10 /** @const */ var RESULTS_PER_PAGE = 150; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 chrome.send('removeBookmark', [self.url_]); | 243 chrome.send('removeBookmark', [self.url_]); |
| 244 | 244 |
| 245 this.model_.getView().onBeforeUnstarred(this); | 245 this.model_.getView().onBeforeUnstarred(this); |
| 246 bookmarkSection.classList.remove('starred'); | 246 bookmarkSection.classList.remove('starred'); |
| 247 this.model_.getView().onAfterUnstarred(this); | 247 this.model_.getView().onAfterUnstarred(this); |
| 248 | 248 |
| 249 bookmarkSection.removeEventListener('click', f); | 249 bookmarkSection.removeEventListener('click', f); |
| 250 e.preventDefault(); | 250 e.preventDefault(); |
| 251 }.bind(this)); | 251 }.bind(this)); |
| 252 } | 252 } |
| 253 if (focusless) | |
| 254 bookmarkSection.tabIndex = -1; | |
| 253 entryBox.appendChild(bookmarkSection); | 255 entryBox.appendChild(bookmarkSection); |
| 254 | 256 |
| 255 var visitEntryWrapper = /** @type {HTMLElement} */( | 257 var visitEntryWrapper = /** @type {HTMLElement} */( |
| 256 entryBox.appendChild(document.createElement('div'))); | 258 entryBox.appendChild(document.createElement('div'))); |
| 257 if (addTitleFavicon || this.blockedVisit) | 259 if (addTitleFavicon || this.blockedVisit) |
| 258 visitEntryWrapper.classList.add('visit-entry'); | 260 visitEntryWrapper.classList.add('visit-entry'); |
| 259 if (this.blockedVisit) { | 261 if (this.blockedVisit) { |
| 260 visitEntryWrapper.classList.add('blocked-indicator'); | 262 visitEntryWrapper.classList.add('blocked-indicator'); |
| 261 visitEntryWrapper.appendChild(this.getVisitAttemptDOM_()); | 263 visitEntryWrapper.appendChild(this.getVisitAttemptDOM_()); |
| 262 } else { | 264 } else { |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 | 890 |
| 889 /** | 891 /** |
| 890 * @constructor | 892 * @constructor |
| 891 * @implements {cr.ui.FocusRow.Observer} | 893 * @implements {cr.ui.FocusRow.Observer} |
| 892 */ | 894 */ |
| 893 function HistoryFocusObserver() {} | 895 function HistoryFocusObserver() {} |
| 894 | 896 |
| 895 HistoryFocusObserver.prototype = { | 897 HistoryFocusObserver.prototype = { |
| 896 /** @override */ | 898 /** @override */ |
| 897 onActivate: function(row) { | 899 onActivate: function(row) { |
| 898 this.getActiveRowElement_(row).classList.add('active'); | 900 row.getRowElement().classList.add('active'); |
| 899 }, | 901 }, |
| 900 | 902 |
| 901 /** @override */ | 903 /** @override */ |
| 902 onDeactivate: function(row) { | 904 onDeactivate: function(row) { |
| 903 this.getActiveRowElement_(row).classList.remove('active'); | 905 row.getRowElement().classList.remove('active'); |
| 904 }, | 906 }, |
| 905 | 907 |
| 906 /** | 908 /** |
| 907 * @param {cr.ui.FocusRow} row The row to find an element for. | 909 * @param {Element} item The row item to find a a row element for. |
| 908 * @return {Element} |row|'s "active" element. | 910 * @return {Element} |row|'s "active" element. |
| 909 * @private | 911 * @override |
| 910 */ | 912 */ |
| 911 getActiveRowElement_: function(row) { | 913 getRowElement: function(item) { |
| 912 return findAncestorByClass(row.items[0], 'entry') || | 914 return findAncestorByClass(item, 'entry') || |
| 913 findAncestorByClass(row.items[0], 'site-domain-wrapper'); | 915 findAncestorByClass(item, 'site-domain-wrapper'); |
| 916 }, | |
| 917 | |
| 918 /** @override */ | |
| 919 onElementIdMiss: function(row, expectedId) { | |
| 920 // Clickable titles. | |
| 921 if (expectedId == 'domain') | |
| 922 return 'title'; | |
| 923 if (expectedId == 'title') | |
| 924 return 'domain'; | |
| 925 | |
| 926 // Select the title or the domain if there is no bookmarked star. | |
| 927 if (expectedId == 'star') { | |
| 928 if (row.elementIds.indexOf('title') != -1) | |
| 929 return 'title'; | |
| 930 return 'domain'; | |
| 931 } | |
| 932 | |
| 933 if (expectedId == 'menu') | |
| 934 return row.elementIds[row.elementIds.length - 1]; | |
| 935 | |
| 936 return null; | |
| 914 }, | 937 }, |
| 915 }; | 938 }; |
| 916 | 939 |
| 917 /////////////////////////////////////////////////////////////////////////////// | 940 /////////////////////////////////////////////////////////////////////////////// |
| 918 // HistoryFocusGrid: | 941 // HistoryFocusGrid: |
| 919 | 942 |
| 920 /** | 943 /** |
| 921 * @param {Node=} opt_boundary | 944 * @param {Node=} opt_boundary |
| 922 * @param {cr.ui.FocusRow.Observer=} opt_observer | 945 * @param {cr.ui.FocusRow.Observer=} opt_observer |
| 923 * @constructor | 946 * @constructor |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 HistoryView.prototype.onBeforeRemove = function(visit) { | 1220 HistoryView.prototype.onBeforeRemove = function(visit) { |
| 1198 assert(this.currentVisits_.indexOf(visit) >= 0); | 1221 assert(this.currentVisits_.indexOf(visit) >= 0); |
| 1199 | 1222 |
| 1200 var pos = this.focusGrid_.getPositionForTarget(document.activeElement); | 1223 var pos = this.focusGrid_.getPositionForTarget(document.activeElement); |
| 1201 if (!pos) | 1224 if (!pos) |
| 1202 return; | 1225 return; |
| 1203 | 1226 |
| 1204 var row = this.focusGrid_.rows[pos.row + 1] || | 1227 var row = this.focusGrid_.rows[pos.row + 1] || |
| 1205 this.focusGrid_.rows[pos.row - 1]; | 1228 this.focusGrid_.rows[pos.row - 1]; |
| 1206 if (row) | 1229 if (row) |
| 1207 row.focusIndex(Math.min(pos.col, row.items.length - 1)); | 1230 row.setFocusId(pos.elementId); |
| 1208 }; | 1231 }; |
| 1209 | 1232 |
| 1210 /** @param {Visit} visit The visit about to be unstarred. */ | 1233 /** @param {Visit} visit The visit about to be unstarred. */ |
| 1211 HistoryView.prototype.onBeforeUnstarred = function(visit) { | 1234 HistoryView.prototype.onBeforeUnstarred = function(visit) { |
| 1212 assert(this.currentVisits_.indexOf(visit) >= 0); | 1235 assert(this.currentVisits_.indexOf(visit) >= 0); |
| 1213 assert(visit.bookmarkStar == document.activeElement); | 1236 assert(visit.bookmarkStar == document.activeElement); |
| 1214 | 1237 |
| 1215 var pos = this.focusGrid_.getPositionForTarget(document.activeElement); | 1238 var pos = this.focusGrid_.getPositionForTarget(document.activeElement); |
| 1216 var row = this.focusGrid_.rows[pos.row]; | 1239 var row = this.focusGrid_.rows[pos.row]; |
| 1217 row.focusIndex(Math.min(pos.col + 1, row.items.length - 1)); | 1240 row.setFocusId(pos.elementId); |
| 1218 }; | 1241 }; |
| 1219 | 1242 |
| 1220 /** @param {Visit} visit The visit that was just unstarred. */ | 1243 /** @param {Visit} visit The visit that was just unstarred. */ |
| 1221 HistoryView.prototype.onAfterUnstarred = function(visit) { | 1244 HistoryView.prototype.onAfterUnstarred = function(visit) { |
| 1222 this.updateFocusGrid_(); | 1245 this.updateFocusGrid_(); |
| 1223 }; | 1246 }; |
| 1224 | 1247 |
| 1225 /** | 1248 /** |
| 1226 * Removes a single entry from the view. Also removes gaps before and after | 1249 * Removes a single entry from the view. Also removes gaps before and after |
| 1227 * entry if necessary. | 1250 * entry if necessary. |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1667 // time column. | 1690 // time column. |
| 1668 this.setTimeColumnWidth_(); | 1691 this.setTimeColumnWidth_(); |
| 1669 }; | 1692 }; |
| 1670 | 1693 |
| 1671 var focusGridRowSelector = [ | 1694 var focusGridRowSelector = [ |
| 1672 ':-webkit-any(.day-results, .search-results) > .entry:not(.fade-out)', | 1695 ':-webkit-any(.day-results, .search-results) > .entry:not(.fade-out)', |
| 1673 '.expand .grouped .entry:not(.fade-out)', | 1696 '.expand .grouped .entry:not(.fade-out)', |
| 1674 '.site-domain-wrapper' | 1697 '.site-domain-wrapper' |
| 1675 ].join(', '); | 1698 ].join(', '); |
| 1676 | 1699 |
| 1677 var focusGridColumnSelector = [ | 1700 /** |
| 1678 '.entry-box input', | 1701 * Add a column to |focusRow| if it exists in |row|. |
| 1679 '.bookmark-section.starred', | 1702 * @param {Element} row The row that should contain the element. |
| 1680 '.title a', | 1703 * @param {cr.ui.FocusRow} focusRow The focus row to add the element to. |
| 1681 '.drop-down', | 1704 * @param {string} query A query to select the appropriate element in |row|. |
| 1682 '.domain-checkbox', | 1705 * @param {string} elementId The elementId to use in |focusRow|. |
| 1683 '[is="action-link"]', | 1706 * @private |
| 1684 ].join(', '); | 1707 */ |
| 1708 HistoryView.prototype.addFocusRow_ = function(row, focusRow, query, elementId) { | |
| 1709 var element = row.querySelectorAll(query); | |
| 1710 | |
| 1711 // There should only be 0 or 1 matches. | |
| 1712 if (element.length == 1) | |
| 1713 focusRow.setFocusableElementId(element[0], elementId); | |
| 1714 else | |
| 1715 assert(element.length == 0); | |
| 1716 }; | |
| 1685 | 1717 |
| 1686 /** @private */ | 1718 /** @private */ |
| 1687 HistoryView.prototype.updateFocusGrid_ = function() { | 1719 HistoryView.prototype.updateFocusGrid_ = function() { |
| 1688 var rows = this.resultDiv_.querySelectorAll(focusGridRowSelector); | 1720 var rows = this.resultDiv_.querySelectorAll(focusGridRowSelector); |
| 1689 var grid = []; | 1721 this.focusGrid_.destroy(); |
| 1690 | 1722 |
| 1691 for (var i = 0; i < rows.length; ++i) { | 1723 for (var i = 0; i < rows.length; ++i) { |
| 1692 assert(rows[i].parentNode); | 1724 assert(rows[i].parentNode); |
| 1693 grid.push(rows[i].querySelectorAll(focusGridColumnSelector)); | 1725 var focusRow = this.focusGrid_.createRow(); |
| 1726 | |
| 1727 // These 2 buttons are mutually exclusive, but visually the same. | |
|
dmazzoni
2015/01/15 19:38:19
I don't quite understand this comment.
hcarmona
2015/01/16 21:39:06
Done.
| |
| 1728 this.addFocusRow_(rows[i], focusRow, '.entry-box input', 'checkbox'); | |
| 1729 this.addFocusRow_(rows[i], focusRow, '.domain-checkbox', 'checkbox'); | |
| 1730 | |
| 1731 this.addFocusRow_(rows[i], focusRow, '.bookmark-section.starred', 'star'); | |
| 1732 this.addFocusRow_(rows[i], focusRow, '[is="action-link"]', 'domain'); | |
| 1733 this.addFocusRow_(rows[i], focusRow, '.title a', 'title'); | |
| 1734 this.addFocusRow_(rows[i], focusRow, '.drop-down', 'menu'); | |
| 1735 | |
| 1736 this.focusGrid_.addRow(focusRow); | |
| 1694 } | 1737 } |
| 1695 | |
| 1696 this.focusGrid_.setGrid(grid); | |
| 1697 }; | 1738 }; |
| 1698 | 1739 |
| 1699 /** | 1740 /** |
| 1700 * Update the visibility of the page navigation buttons. | 1741 * Update the visibility of the page navigation buttons. |
| 1701 * @private | 1742 * @private |
| 1702 */ | 1743 */ |
| 1703 HistoryView.prototype.updateNavBar_ = function() { | 1744 HistoryView.prototype.updateNavBar_ = function() { |
| 1704 this.updateRangeButtons_(); | 1745 this.updateRangeButtons_(); |
| 1705 | 1746 |
| 1706 // If grouping by domain is enabled, there's a control bar on top, don't show | 1747 // If grouping by domain is enabled, there's a control bar on top, don't show |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2381 historyView.reload(); | 2422 historyView.reload(); |
| 2382 } | 2423 } |
| 2383 | 2424 |
| 2384 // Add handlers to HTML elements. | 2425 // Add handlers to HTML elements. |
| 2385 document.addEventListener('DOMContentLoaded', load); | 2426 document.addEventListener('DOMContentLoaded', load); |
| 2386 | 2427 |
| 2387 // This event lets us enable and disable menu items before the menu is shown. | 2428 // This event lets us enable and disable menu items before the menu is shown. |
| 2388 document.addEventListener('canExecute', function(e) { | 2429 document.addEventListener('canExecute', function(e) { |
| 2389 e.canExecute = true; | 2430 e.canExecute = true; |
| 2390 }); | 2431 }); |
| OLD | NEW |