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

Side by Side Diff: chrome/browser/resources/settings/settings_page/settings_animated_pages.js

Issue 2805363002: MD Settings: Add mechanism to restore focus after subpage exiting. (Closed)
Patch Set: Use tag name Created 3 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 unified diff | Download patch
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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 'settings-animated-pages' is a container for a page and animated subpages. 7 * 'settings-animated-pages' is a container for a page and animated subpages.
8 * It provides a set of common behaviors and animations. 8 * It provides a set of common behaviors and animations.
9 * 9 *
10 * Example: 10 * Example:
11 * 11 *
12 * <settings-animated-pages section="privacy"> 12 * <settings-animated-pages section="privacy">
13 * <!-- Insert your section controls here --> 13 * <!-- Insert your section controls here -->
14 * </settings-animated-pages> 14 * </settings-animated-pages>
15 */ 15 */
16
17 /**
18 */
19 var FocusConfig;
20
16 Polymer({ 21 Polymer({
17 is: 'settings-animated-pages', 22 is: 'settings-animated-pages',
18 23
19 behaviors: [settings.RouteObserverBehavior], 24 behaviors: [settings.RouteObserverBehavior],
20 25
21 properties: { 26 properties: {
22 /** 27 /**
23 * Routes with this section activate this element. For instance, if this 28 * Routes with this section activate this element. For instance, if this
24 * property is 'search', and currentRoute.section is also set to 'search', 29 * property is 'search', and currentRoute.section is also set to 'search',
25 * this element will display the subpage in currentRoute.subpage. 30 * this element will display the subpage in currentRoute.subpage.
26 * 31 *
27 * The section name must match the name specified in route.js. 32 * The section name must match the name specified in route.js.
28 */ 33 */
29 section: { 34 section: String,
30 type: String, 35
31 }, 36 /**
37 * A Map specifying which element should be focused when exiting a subpage.
38 * The key of the map holds a settings.Route path, and the value holds a
39 * query selector that identifies the desired element.
40 * @type {?Map<string, string>}
41 */
42 focusConfig: Object,
32 }, 43 },
33 44
45 /**
46 * The last "previous" route reported by the router.
47 * @private {?settings.Route}
48 */
49 lastOldRoute_: null,
50
34 /** @override */ 51 /** @override */
35 created: function() { 52 created: function() {
36 // Observe the light DOM so we know when it's ready. 53 // Observe the light DOM so we know when it's ready.
37 this.lightDomObserver_ = Polymer.dom(this).observeNodes( 54 this.lightDomObserver_ = Polymer.dom(this).observeNodes(
38 this.lightDomChanged_.bind(this)); 55 this.lightDomChanged_.bind(this));
39 }, 56 },
40 57
41 /** 58 /**
59 * @param {!Event} e
60 * @private
61 */
62 onIronSelect_: function(e) {
63 if (!this.focusConfig || !this.lastOldRoute_)
64 return;
65
66 if (e.detail.item.tagName != 'NEON-ANIMATABLE')
Dan Beam 2017/04/11 00:06:07 nit: combine with above if
dpapad 2017/04/11 00:18:32 Done.
67 return;
68
69 var querySelector = this.focusConfig.get(this.lastOldRoute_.path);
Dan Beam 2017/04/11 00:06:07 nit: the argument passed to querySelector is just
70 if (querySelector) {
71 // neon-animatable has "display: none" until the animation finishes, so
72 // calling focus() on any of its children has no effect until
73 // "display: none" is removed. Therefore can't call focus() from within
74 // the currentRouteChanged callback. Using 'iron-select' listener which
75 // fires after the animation has finished allows focus() to work as
76 // expected.
77 var trigger = assert(this.querySelector(querySelector));
Dan Beam 2017/04/11 00:06:07 nit: this.querySelector(selector).focus(); (no as
dpapad 2017/04/11 00:18:32 Done. Agreed. An assert() is more useful when it i
78 trigger.focus();
79 }
80 },
81
82 /**
42 * Called initially once the effective children are ready. 83 * Called initially once the effective children are ready.
43 * @private 84 * @private
44 */ 85 */
45 lightDomChanged_: function() { 86 lightDomChanged_: function() {
46 if (this.lightDomReady_) 87 if (this.lightDomReady_)
47 return; 88 return;
48 89
49 this.lightDomReady_ = true; 90 this.lightDomReady_ = true;
50 Polymer.dom(this).unobserveNodes(this.lightDomObserver_); 91 Polymer.dom(this).unobserveNodes(this.lightDomObserver_);
51 this.runQueuedRouteChange_(); 92 this.runQueuedRouteChange_();
52 }, 93 },
53 94
54 /** 95 /**
55 * Calls currentRouteChanged with the deferred route change info. 96 * Calls currentRouteChanged with the deferred route change info.
56 * @private 97 * @private
57 */ 98 */
58 runQueuedRouteChange_: function() { 99 runQueuedRouteChange_: function() {
59 if (!this.queuedRouteChange_) 100 if (!this.queuedRouteChange_)
60 return; 101 return;
61 this.async(this.currentRouteChanged.bind( 102 this.async(this.currentRouteChanged.bind(
62 this, 103 this,
63 this.queuedRouteChange_.newRoute, 104 this.queuedRouteChange_.newRoute,
64 this.queuedRouteChange_.oldRoute)); 105 this.queuedRouteChange_.oldRoute));
65 }, 106 },
66 107
67 /** @protected */ 108 /** @protected */
68 currentRouteChanged: function(newRoute, oldRoute) { 109 currentRouteChanged: function(newRoute, oldRoute) {
110 this.lastOldRoute_ = oldRoute;
111
69 if (newRoute.section == this.section && newRoute.isSubpage()) { 112 if (newRoute.section == this.section && newRoute.isSubpage()) {
70 this.switchToSubpage_(newRoute, oldRoute); 113 this.switchToSubpage_(newRoute, oldRoute);
71 } else { 114 } else {
72 this.$.animatedPages.exitAnimation = 'fade-out-animation'; 115 this.$.animatedPages.exitAnimation = 'fade-out-animation';
73 this.$.animatedPages.entryAnimation = 'fade-in-animation'; 116 this.$.animatedPages.entryAnimation = 'fade-in-animation';
74 this.$.animatedPages.selected = 'default'; 117 this.$.animatedPages.selected = 'default';
75 } 118 }
76 }, 119 },
77 120
78 /** 121 /**
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // instance, such that the stamped instance will also be ignored by the 187 // instance, such that the stamped instance will also be ignored by the
145 // searching algorithm. 188 // searching algorithm.
146 if (template.hasAttribute('no-search')) 189 if (template.hasAttribute('no-search'))
147 subpage.setAttribute('no-search', ''); 190 subpage.setAttribute('no-search', '');
148 191
149 // Render synchronously so neon-animated-pages can select the subpage. 192 // Render synchronously so neon-animated-pages can select the subpage.
150 template.if = true; 193 template.if = true;
151 template.render(); 194 template.render();
152 }, 195 },
153 }); 196 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698