| OLD | NEW |
| 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('downloads', function() { | 5 cr.define('downloads', function() { |
| 6 /** | 6 /** |
| 7 * Provides an implementation for a single column grid. | 7 * Provides an implementation for a single column grid. |
| 8 * @constructor | 8 * @constructor |
| 9 * @extends {cr.ui.FocusRow} | 9 * @extends {cr.ui.FocusRow} |
| 10 */ | 10 */ |
| 11 function FocusRow() {} | 11 function FocusRow() {} |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Decorates |focusRow| so that it can be treated as a FocusRow. | 14 * Decorates |focusRow| so that it can be treated as a FocusRow. |
| 15 * @param {Element} focusRow The element that has all the columns represented | 15 * @param {Element} focusRow The element that has all the columns represented |
| 16 * by |itemView|. | 16 * by |itemView|. |
| 17 * @param {!downloads.ItemView} itemView The item view this row cares about. | 17 * @param {!downloads.ItemView} itemView The item view this row cares about. |
| 18 * @param {Node} boundary Focus events are ignored outside of this node. | 18 * @param {Node} boundary Focus events are ignored outside of this node. |
| 19 */ | 19 */ |
| 20 FocusRow.decorate = function(focusRow, itemView, boundary) { | 20 FocusRow.decorate = function(focusRow, itemView, boundary) { |
| 21 focusRow.__proto__ = FocusRow.prototype; | 21 focusRow.__proto__ = FocusRow.prototype; |
| 22 focusRow.decorate(boundary); | 22 focusRow.decorate(boundary); |
| 23 focusRow.addFocusableElements_(); | 23 focusRow.addFocusableElements_(); |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 /** | |
| 27 * Determines if element should be focusable. | |
| 28 * @param {Element} element | |
| 29 * @return {boolean} | |
| 30 */ | |
| 31 FocusRow.shouldFocus = function(element) { | |
| 32 if (!element) | |
| 33 return false; | |
| 34 | |
| 35 // Hidden elements are not focusable. | |
| 36 var style = window.getComputedStyle(element); | |
| 37 if (style.visibility == 'hidden' || style.display == 'none') | |
| 38 return false; | |
| 39 | |
| 40 // Verify all ancestors are focusable. | |
| 41 return !element.parentElement || | |
| 42 FocusRow.shouldFocus(element.parentElement); | |
| 43 }; | |
| 44 | |
| 45 FocusRow.prototype = { | 26 FocusRow.prototype = { |
| 46 __proto__: cr.ui.FocusRow.prototype, | 27 __proto__: cr.ui.FocusRow.prototype, |
| 47 | 28 |
| 48 /** @override */ | 29 /** @override */ |
| 49 getEquivalentElement: function(element) { | 30 getEquivalentElement: function(element) { |
| 50 if (this.focusableElements.indexOf(element) > -1) | 31 if (this.focusableElements.indexOf(element) > -1) |
| 51 return assert(element); | 32 return assert(element); |
| 52 | 33 |
| 53 // All elements default to another element with the same type. | 34 // All elements default to another element with the same type. |
| 54 var columnType = element.getAttribute('focus-type'); | 35 var columnType = element.getAttribute('focus-type'); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 | 49 |
| 69 // Return the first focusable element if no equivalent element is found. | 50 // Return the first focusable element if no equivalent element is found. |
| 70 return assert(equivalent || this.focusableElements[0]); | 51 return assert(equivalent || this.focusableElements[0]); |
| 71 }, | 52 }, |
| 72 | 53 |
| 73 /** @private */ | 54 /** @private */ |
| 74 addFocusableElements_: function() { | 55 addFocusableElements_: function() { |
| 75 var possiblyFocusableElements = this.querySelectorAll('[focus-type]'); | 56 var possiblyFocusableElements = this.querySelectorAll('[focus-type]'); |
| 76 for (var i = 0; i < possiblyFocusableElements.length; ++i) { | 57 for (var i = 0; i < possiblyFocusableElements.length; ++i) { |
| 77 var possiblyFocusableElement = possiblyFocusableElements[i]; | 58 var possiblyFocusableElement = possiblyFocusableElements[i]; |
| 78 if (FocusRow.shouldFocus(possiblyFocusableElement)) | 59 if (cr.ui.FocusRow.isFocusable(possiblyFocusableElement)) |
| 79 this.addFocusableElement(possiblyFocusableElement); | 60 this.addFocusableElement(possiblyFocusableElement); |
| 80 } | 61 } |
| 81 }, | 62 }, |
| 82 }; | 63 }; |
| 83 | 64 |
| 84 return {FocusRow: FocusRow}; | 65 return {FocusRow: FocusRow}; |
| 85 }); | 66 }); |
| OLD | NEW |