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

Unified Diff: chrome/browser/resources/md_downloads/manager.js

Issue 1313453002: Make cr.ui.Focus* play nice with Shadow DOM and MD chrome://downloads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_downloads/manager.js
diff --git a/chrome/browser/resources/md_downloads/manager.js b/chrome/browser/resources/md_downloads/manager.js
index 186cadcf28664bf0520a615dac8c1a23f426c5b7..563cd1b6daba5c34d43a4ff37ce3f9bbae0e9e52 100644
--- a/chrome/browser/resources/md_downloads/manager.js
+++ b/chrome/browser/resources/md_downloads/manager.js
@@ -82,6 +82,33 @@ cr.define('downloads', function() {
});
},
+ /** @private */
+ rebuildFocusGrid_: function() {
+ var activeElement = this.shadowRoot.activeElement;
+
+ var activeItem;
+ if (activeElement && activeElement.tagName == 'download-item')
+ activeItem = activeElement;
+
+ var activeControl = activeItem && activeItem.shadowRoot.activeElement;
+
+ /** @private {!cr.ui.FocusGrid} */
+ this.focusGrid_ = this.focusGrid_ || new cr.ui.FocusGrid;
+ this.focusGrid_.destroy();
+
+ var boundary = this.$['downloads-list'];
+
+ this.items_.forEach(function(item) {
+ var focusRow = new downloads.FocusRow(item.content, boundary);
+ this.focusGrid_.addRow(focusRow);
+
+ if (item == activeItem && !cr.ui.FocusRow.isFocusable(activeControl))
hcarmona 2015/08/24 21:00:37 When would you get an active control that isn't fo
Dan Beam 2015/08/24 22:59:30 enter on "Pause" hides and "Resume" is shown
hcarmona 2015/08/24 23:49:19 Acknowledged.
+ focusRow.getEquivalentElement(activeControl).focus();
+ }, this);
+
+ this.focusGrid_.ensureRowActive();
+ },
+
/**
* @return {number} The number of downloads shown on the page.
* @private
@@ -161,6 +188,9 @@ cr.define('downloads', function() {
this.onResize_();
this.$.panel.classList.remove('loading');
+
+ var allReady = this.items_.map(function(i) { return i.readyPromise; });
+ Promise.all(allReady).then(this.rebuildFocusGrid_.bind(this));
hcarmona 2015/08/24 21:00:37 Is it possible to update the row rather than rebui
Dan Beam 2015/08/24 22:59:30 yes, but until there's a reason to, it just compli
hcarmona 2015/08/24 23:49:19 One problem from the extensions page was that focu
Dan Beam 2015/08/25 03:22:29 I know, I fixed these issues recently ;)
},
/**
@@ -168,7 +198,18 @@ cr.define('downloads', function() {
* @private
*/
updateItem_: function(data) {
- this.idMap_[data.id].update(data);
+ var item = this.idMap_[data.id];
+
+ var activeControl = this.shadowRoot.activeElement == item ?
+ item.shadowRoot.activeElement : null;
+
+ item.update(data);
+
+ if (activeControl && !cr.ui.FocusRow.isFocusable(activeControl)) {
+ var focusRow = this.focusGrid_.getRowForRoot(item.content);
+ focusRow.getEquivalentElement(activeControl).focus();
+ }
+
this.onResize_();
},
});

Powered by Google App Engine
This is Rietveld 408576698