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

Unified Diff: chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js

Issue 1877233006: [Media Router WebUI] Fix escape bug in filter menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename focus update function Created 4 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/resources/media_router/media_router_data.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js
diff --git a/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js b/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js
index 46bf89b7c61ead3901efe3bf7d707724ebf34007..5cdbb30e01befe872da983eea59d5ae454176c99 100644
--- a/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js
+++ b/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js
@@ -382,7 +382,7 @@ Polymer({
if (!cr.isMac)
this.$$('#focus-placeholder').remove();
- document.addEventListener('keydown', this.onKeydown_.bind(this));
+ document.addEventListener('keydown', this.onKeydown_.bind(this), true);
this.setSearchFocusHandlers_();
this.showSinkList_();
},
@@ -1119,6 +1119,35 @@ Polymer({
},
/**
+ * If an element in the search results list has keyboard focus when we are
+ * transitioning from the filter view to the sink list view, give focus to the
+ * same sink in the sink list. Otherwise we leave the keyboard focus where it
+ * is.
+ * @private
+ */
+ maybeUpdateFocusOnFilterViewExit_: function() {
+ var searchSinks = this.$$('#search-results').querySelectorAll('paper-item');
+ var focusedElem = Array.prototype.find.call(searchSinks, function(sink) {
+ return sink.focused;
+ });
+ if (!focusedElem) {
+ return;
+ }
+ var focusedSink =
+ this.$$('#searchResults').itemForElement(focusedElem).sinkItem;
+ setTimeout(function() {
+ var sinkList = this.$$('#sinkList');
+ var sinks = this.$['sink-list-view'].querySelectorAll('paper-item');
+ Array.prototype.some.call(sinks, function(sink) {
+ if (sinkList.itemForElement(sink).id == focusedSink.id) {
+ sink.focus();
+ return true;
+ }
+ });
+ }.bind(this));
+ },
+
+ /**
* May update |populatedSinkListSeenTimeMs_| depending on |currentView| and
* |sinksToShow|.
* Called when |currentView_| or |sinksToShow_| is updated.
@@ -1272,10 +1301,15 @@ Polymer({
// handled on the C++ side instead of the JS side on non-mac platforms,
// which uses toolkit-views. Handle the expected behavior on all platforms
// here.
- if (e.keyCode == media_router.KEYCODE_ESC && !e.shiftKey &&
+ if (e.key == media_router.KEY_ESC && !e.shiftKey &&
!e.ctrlKey && !e.altKey && !e.metaKey) {
// When searching, allow ESC as a mechanism to leave the filter view.
if (this.isUserSearching_) {
+ // If the user tabbed to an item in the search results, or otherwise has
+ // an item in the list focused, focus will seem to vanish when we
+ // transition back to the sink list. Instead we should move focus to the
+ // appropriate item in the sink list.
+ this.maybeUpdateFocusOnFilterViewExit_();
this.showSinkList_();
e.preventDefault();
} else {
« no previous file with comments | « no previous file | chrome/browser/resources/media_router/media_router_data.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698