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

Side by Side Diff: ui/webui/resources/cr_elements/network/cr_network_list.js

Issue 2705793002: cr-network-select: implement focus() (Closed)
Patch Set: Created 3 years, 10 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 | ui/webui/resources/cr_elements/network/cr_network_select.html » ('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 /** 5 /**
6 * @fileoverview Polymer element for displaying a collapsable list of networks. 6 * @fileoverview Polymer element for displaying a collapsable list of networks.
7 */ 7 */
8 8
9 /** 9 /**
10 * Polymer class definition for 'cr-network-list'. 10 * Polymer class definition for 'cr-network-list'.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 value: function() { 60 value: function() {
61 return []; 61 return [];
62 }, 62 },
63 }, 63 },
64 }, 64 },
65 65
66 behaviors: [CrScrollableBehavior], 66 behaviors: [CrScrollableBehavior],
67 67
68 observers: ['updateListItems_(networks, customItems)'], 68 observers: ['updateListItems_(networks, customItems)'],
69 69
70 /**
71 * True if element is focused, but dom-repeat is not rendered yet.
72 * @private
73 */
74 needFocus_: false,
75
76 attached: function() {
77 var self = this;
78 var observer = new MutationObserver(function() {
79 self.checkFocus_();
80 });
81 observer.observe(this.$.networkList, { childList: true });
82 },
83
84 focus: function() {
85 this.needFocus_ = false;
86 var items = this.$.networkList.getElementsByTagName('cr-network-list-item');
87 if (items && items[0]) {
88 items[0].focus();
89 } else {
90 this.needFocus_ = true;
91 }
92 },
93
94 /**
95 * Triggers delayed focus.
96 * @private
97 */
98 checkFocus_: function() {
99 if (this.needFocus_)
100 this.focus();
101 },
102
70 /** @private */ 103 /** @private */
71 updateListItems_: function() { 104 updateListItems_: function() {
72 this.saveScroll(this.$.networkList); 105 this.saveScroll(this.$.networkList);
73 this.listItems_ = this.networks.concat(this.customItems); 106 this.listItems_ = this.networks.concat(this.customItems);
74 this.restoreScroll(this.$.networkList); 107 this.restoreScroll(this.$.networkList);
75 this.updateScrollableContents(); 108 this.updateScrollableContents();
109 this.checkFocus_();
76 }, 110 },
77 111
78 /** 112 /**
79 * Use iron-list selection (which is not the same as focus) to trigger 113 * Use iron-list selection (which is not the same as focus) to trigger
80 * tap (requires selection-enabled) or keyboard selection. 114 * tap (requires selection-enabled) or keyboard selection.
81 * @private 115 * @private
82 */ 116 */
83 selectedItemChanged_: function() { 117 selectedItemChanged_: function() {
84 if (this.selectedItem) 118 if (this.selectedItem)
85 this.onItemAction_(this.selectedItem); 119 this.onItemAction_(this.selectedItem);
86 }, 120 },
87 121
88 /** 122 /**
89 * @param {!CrNetworkList.CrNetworkListItemType} item 123 * @param {!CrNetworkList.CrNetworkListItemType} item
90 * @private 124 * @private
91 */ 125 */
92 onItemAction_: function(item) { 126 onItemAction_: function(item) {
93 if (item.hasOwnProperty('customItemName')) 127 if (item.hasOwnProperty('customItemName'))
94 this.fire('custom-item-selected', item); 128 this.fire('custom-item-selected', item);
95 else 129 else
96 this.fire('selected', item); 130 this.fire('selected', item);
97 }, 131 },
98 }); 132 });
OLDNEW
« no previous file with comments | « no previous file | ui/webui/resources/cr_elements/network/cr_network_select.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698