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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 this.domain_)); | 205 this.domain_)); |
206 checkbox.addEventListener('click', checkboxClicked); | 206 checkbox.addEventListener('click', checkboxClicked); |
207 entryBox.appendChild(checkbox); | 207 entryBox.appendChild(checkbox); |
208 | 208 |
209 if (focusless) | 209 if (focusless) |
210 checkbox.tabIndex = -1; | 210 checkbox.tabIndex = -1; |
211 | 211 |
212 if (!isMobileVersion()) { | 212 if (!isMobileVersion()) { |
213 // Clicking anywhere in the entryBox will check/uncheck the checkbox. | 213 // Clicking anywhere in the entryBox will check/uncheck the checkbox. |
214 entryBox.setAttribute('for', checkbox.id); | 214 entryBox.setAttribute('for', checkbox.id); |
215 entryBox.addEventListener('mousedown', entryBoxMousedown); | 215 entryBox.addEventListener('mousedown', this.handleMousedown_.bind(this)); |
216 entryBox.addEventListener('click', entryBoxClick); | 216 entryBox.addEventListener('click', entryBoxClick); |
217 entryBox.addEventListener('keydown', this.handleKeydown_.bind(this)); | 217 entryBox.addEventListener('keydown', this.handleKeydown_.bind(this)); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 // Keep track of the drop down that triggered the menu, so we know | 221 // Keep track of the drop down that triggered the menu, so we know |
222 // which element to apply the command to. | 222 // which element to apply the command to. |
223 // TODO(dubroy): Ideally we'd use 'activate', but MenuButton swallows it. | 223 // TODO(dubroy): Ideally we'd use 'activate', but MenuButton swallows it. |
224 var setActiveVisit = function(e) { | 224 var setActiveVisit = function(e) { |
225 activeVisit = self; | 225 activeVisit = self; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 * @param {Event} e A keydown event to handle. | 492 * @param {Event} e A keydown event to handle. |
493 * @private | 493 * @private |
494 */ | 494 */ |
495 Visit.prototype.handleKeydown_ = function(e) { | 495 Visit.prototype.handleKeydown_ = function(e) { |
496 // Delete or Backspace should delete the entry if allowed. | 496 // Delete or Backspace should delete the entry if allowed. |
497 if (e.keyIdentifier == 'U+0008' || e.keyIdentifier == 'U+007F') | 497 if (e.keyIdentifier == 'U+0008' || e.keyIdentifier == 'U+007F') |
498 this.removeEntryFromHistory_(e); | 498 this.removeEntryFromHistory_(e); |
499 }; | 499 }; |
500 | 500 |
501 /** | 501 /** |
| 502 * @param {Event} event A mousedown event. |
| 503 * @private |
| 504 */ |
| 505 Visit.prototype.handleMousedown_ = function(event) { |
| 506 // Prevent text selection when shift-clicking to select multiple entries. |
| 507 if (event.shiftKey) { |
| 508 event.preventDefault(); |
| 509 |
| 510 if (this.model_.getView().isInFocusGrid(event.target)) |
| 511 event.target.focus(); |
| 512 } |
| 513 }; |
| 514 |
| 515 /** |
502 * Removes a history entry on click or keydown and finds a new entry to focus. | 516 * Removes a history entry on click or keydown and finds a new entry to focus. |
503 * @param {Event} e A click or keydown event. | 517 * @param {Event} e A click or keydown event. |
504 * @private | 518 * @private |
505 */ | 519 */ |
506 Visit.prototype.removeEntryFromHistory_ = function(e) { | 520 Visit.prototype.removeEntryFromHistory_ = function(e) { |
507 if (!this.model_.deletingHistoryAllowed || this.model_.isDeletingVisits() || | 521 if (!this.model_.deletingHistoryAllowed || this.model_.isDeletingVisits() || |
508 this.domNode_.classList.contains('fade-out')) { | 522 this.domNode_.classList.contains('fade-out')) { |
509 return; | 523 return; |
510 } | 524 } |
511 | 525 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 * @return {Element} |row|'s "active" element. | 905 * @return {Element} |row|'s "active" element. |
892 * @private | 906 * @private |
893 */ | 907 */ |
894 getActiveRowElement_: function(row) { | 908 getActiveRowElement_: function(row) { |
895 return findAncestorByClass(row.items[0], 'entry') || | 909 return findAncestorByClass(row.items[0], 'entry') || |
896 findAncestorByClass(row.items[0], 'site-domain-wrapper'); | 910 findAncestorByClass(row.items[0], 'site-domain-wrapper'); |
897 }, | 911 }, |
898 }; | 912 }; |
899 | 913 |
900 /////////////////////////////////////////////////////////////////////////////// | 914 /////////////////////////////////////////////////////////////////////////////// |
| 915 // HistoryFocusGrid: |
| 916 |
| 917 /** |
| 918 * @param {Node=} opt_boundary |
| 919 * @param {cr.ui.FocusRow.Observer=} opt_observer |
| 920 * @constructor |
| 921 * @extends {cr.ui.FocusGrid} |
| 922 */ |
| 923 function HistoryFocusGrid(opt_boundary, opt_observer) { |
| 924 cr.ui.FocusGrid.apply(this, arguments); |
| 925 } |
| 926 |
| 927 HistoryFocusGrid.prototype = { |
| 928 __proto__: cr.ui.FocusGrid.prototype, |
| 929 |
| 930 /** @override */ |
| 931 onMousedown: function(row, e) { |
| 932 return !!findAncestorByClass(e.target, 'menu-button'); |
| 933 }, |
| 934 }; |
| 935 |
| 936 /////////////////////////////////////////////////////////////////////////////// |
901 // HistoryView: | 937 // HistoryView: |
902 | 938 |
903 /** | 939 /** |
904 * Functions and state for populating the page with HTML. This should one-day | 940 * Functions and state for populating the page with HTML. This should one-day |
905 * contain the view and use event handlers, rather than pushing HTML out and | 941 * contain the view and use event handlers, rather than pushing HTML out and |
906 * getting called externally. | 942 * getting called externally. |
907 * @param {HistoryModel} model The model backing this view. | 943 * @param {HistoryModel} model The model backing this view. |
908 * @constructor | 944 * @constructor |
909 */ | 945 */ |
910 function HistoryView(model) { | 946 function HistoryView(model) { |
911 this.editButtonTd_ = $('edit-button'); | 947 this.editButtonTd_ = $('edit-button'); |
912 this.editingControlsDiv_ = $('editing-controls'); | 948 this.editingControlsDiv_ = $('editing-controls'); |
913 this.resultDiv_ = $('results-display'); | 949 this.resultDiv_ = $('results-display'); |
914 this.focusGrid_ = new cr.ui.FocusGrid(this.resultDiv_, | 950 this.focusGrid_ = new HistoryFocusGrid(this.resultDiv_, |
915 new HistoryFocusObserver); | 951 new HistoryFocusObserver); |
916 this.pageDiv_ = $('results-pagination'); | 952 this.pageDiv_ = $('results-pagination'); |
917 this.model_ = model; | 953 this.model_ = model; |
918 this.pageIndex_ = 0; | 954 this.pageIndex_ = 0; |
919 this.lastDisplayed_ = []; | 955 this.lastDisplayed_ = []; |
920 | 956 |
921 this.model_.setView(this); | 957 this.model_.setView(this); |
922 | 958 |
923 this.currentVisits_ = []; | 959 this.currentVisits_ = []; |
924 | 960 |
925 // If there is no search button, use the search button label as placeholder | 961 // If there is no search button, use the search button label as placeholder |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 // If the bar does not fit beside the editing controls, put it into the | 1283 // If the bar does not fit beside the editing controls, put it into the |
1248 // overflow state. | 1284 // overflow state. |
1249 if (bar.getBoundingClientRect().top >= | 1285 if (bar.getBoundingClientRect().top >= |
1250 $('editing-controls').getBoundingClientRect().bottom) { | 1286 $('editing-controls').getBoundingClientRect().bottom) { |
1251 bar.classList.add('alone'); | 1287 bar.classList.add('alone'); |
1252 } else { | 1288 } else { |
1253 bar.classList.remove('alone'); | 1289 bar.classList.remove('alone'); |
1254 } | 1290 } |
1255 }; | 1291 }; |
1256 | 1292 |
| 1293 /** |
| 1294 * @param {Element} el An element to look for. |
| 1295 * @return {boolean} Whether |el| is in |this.focusGrid_|. |
| 1296 */ |
| 1297 HistoryView.prototype.isInFocusGrid = function(el) { |
| 1298 return !!this.focusGrid_.getPositionForTarget(el); |
| 1299 }; |
| 1300 |
1257 // HistoryView, private: ------------------------------------------------------ | 1301 // HistoryView, private: ------------------------------------------------------ |
1258 | 1302 |
1259 /** | 1303 /** |
1260 * Clear the results in the view. Since we add results piecemeal, we need | 1304 * Clear the results in the view. Since we add results piecemeal, we need |
1261 * to clear them out when we switch to a new page or reload. | 1305 * to clear them out when we switch to a new page or reload. |
1262 * @private | 1306 * @private |
1263 */ | 1307 */ |
1264 HistoryView.prototype.clear_ = function() { | 1308 HistoryView.prototype.clear_ = function() { |
1265 var alertOverlay = $('alertOverlay'); | 1309 var alertOverlay = $('alertOverlay'); |
1266 if (alertOverlay && alertOverlay.classList.contains('showing')) | 1310 if (alertOverlay && alertOverlay.classList.contains('showing')) |
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 | 2200 |
2157 var entry = findAncestorByClass(checkbox, 'site-entry'); | 2201 var entry = findAncestorByClass(checkbox, 'site-entry'); |
2158 if (!entry) | 2202 if (!entry) |
2159 return; | 2203 return; |
2160 | 2204 |
2161 var groupCheckbox = entry.querySelector('.site-domain-wrapper input'); | 2205 var groupCheckbox = entry.querySelector('.site-domain-wrapper input'); |
2162 if (groupCheckbox) | 2206 if (groupCheckbox) |
2163 groupCheckbox.checked = false; | 2207 groupCheckbox.checked = false; |
2164 } | 2208 } |
2165 | 2209 |
2166 function entryBoxMousedown(event) { | |
2167 // Prevent text selection when shift-clicking to select multiple entries. | |
2168 if (event.shiftKey) | |
2169 event.preventDefault(); | |
2170 } | |
2171 | |
2172 /** | 2210 /** |
2173 * Handle click event for entryBoxes. | 2211 * Handle click event for entryBoxes. |
2174 * @param {!Event} event A click event. | 2212 * @param {!Event} event A click event. |
2175 */ | 2213 */ |
2176 function entryBoxClick(event) { | 2214 function entryBoxClick(event) { |
2177 event = /** @type {!MouseEvent} */(event); | 2215 event = /** @type {!MouseEvent} */(event); |
2178 // Do nothing if a bookmark star is clicked. | 2216 // Do nothing if a bookmark star is clicked. |
2179 if (event.defaultPrevented) | 2217 if (event.defaultPrevented) |
2180 return; | 2218 return; |
2181 var element = event.target; | 2219 var element = event.target; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 historyView.reload(); | 2320 historyView.reload(); |
2283 } | 2321 } |
2284 | 2322 |
2285 // Add handlers to HTML elements. | 2323 // Add handlers to HTML elements. |
2286 document.addEventListener('DOMContentLoaded', load); | 2324 document.addEventListener('DOMContentLoaded', load); |
2287 | 2325 |
2288 // This event lets us enable and disable menu items before the menu is shown. | 2326 // This event lets us enable and disable menu items before the menu is shown. |
2289 document.addEventListener('canExecute', function(e) { | 2327 document.addEventListener('canExecute', function(e) { |
2290 e.canExecute = true; | 2328 e.canExecute = true; |
2291 }); | 2329 }); |
OLD | NEW |