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

Side by Side Diff: chrome/browser/resources/downloads/focus_row.js

Issue 1018543005: downloads: fix Resume/Pause focus regression. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests Created 5 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/resources/downloads/manager.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('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
26 FocusRow.prototype = { 45 FocusRow.prototype = {
27 __proto__: cr.ui.FocusRow.prototype, 46 __proto__: cr.ui.FocusRow.prototype,
28 47
29 /** @override */ 48 /** @override */
30 getEquivalentElement: function(element) { 49 getEquivalentElement: function(element) {
31 if (this.focusableElements.indexOf(element) > -1) 50 if (this.focusableElements.indexOf(element) > -1)
32 return assert(element); 51 return assert(element);
33 52
34 // All elements default to another element with the same type. 53 // All elements default to another element with the same type.
35 var columnType = element.getAttribute('column-type'); 54 var columnType = element.getAttribute('column-type');
(...skipping 13 matching lines...) Expand all
49 68
50 // Return the first focusable element if no equivalent element is found. 69 // Return the first focusable element if no equivalent element is found.
51 return assert(equivalent || this.focusableElements[0]); 70 return assert(equivalent || this.focusableElements[0]);
52 }, 71 },
53 72
54 /** @private */ 73 /** @private */
55 addFocusableElements_: function() { 74 addFocusableElements_: function() {
56 var possiblyFocusableElements = this.querySelectorAll('[column-type]'); 75 var possiblyFocusableElements = this.querySelectorAll('[column-type]');
57 for (var i = 0; i < possiblyFocusableElements.length; ++i) { 76 for (var i = 0; i < possiblyFocusableElements.length; ++i) {
58 var possiblyFocusableElement = possiblyFocusableElements[i]; 77 var possiblyFocusableElement = possiblyFocusableElements[i];
59 if (this.shouldFocus_(possiblyFocusableElement)) 78 if (FocusRow.shouldFocus(possiblyFocusableElement))
60 this.addFocusableElement(possiblyFocusableElement); 79 this.addFocusableElement(possiblyFocusableElement);
61 } 80 }
62 }, 81 },
63
64 /**
65 * Determines if element should be focusable.
66 * @param {Element} element
67 * @return {boolean}
68 * @private
69 */
70 shouldFocus_: function(element) {
71 if (!element)
72 return false;
73
74 // Hidden elements are not focusable.
75 var style = window.getComputedStyle(element);
76 if (style.visibility == 'hidden' || style.display == 'none')
77 return false;
78
79 // Verify all ancestors are focusable.
80 return !element.parentElement || this.shouldFocus_(element.parentElement);
81 },
82 }; 82 };
83 83
84 return {FocusRow: FocusRow}; 84 return {FocusRow: FocusRow};
85 }); 85 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/downloads/manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698