OLD | NEW |
---|---|
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 the network state for a specific | 6 * @fileoverview Polymer element for displaying the network state for a specific |
7 * type and a list of networks for that type. | 7 * type and a list of networks for that type. |
8 */ | 8 */ |
9 | 9 |
10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ | 10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ |
11 var DeviceStateProperties; | 11 var DeviceStateProperties; |
12 | 12 |
13 Polymer({ | 13 Polymer({ |
14 is: 'network-summary-item', | 14 is: 'network-summary-item', |
15 | 15 |
16 behaviors: [Polymer.IronA11yKeysBehavior], | |
17 | |
16 properties: { | 18 properties: { |
17 /** | 19 /** |
18 * Device state for the network type. | 20 * Device state for the network type. |
19 * @type {DeviceStateProperties|undefined} | 21 * @type {DeviceStateProperties|undefined} |
20 */ | 22 */ |
21 deviceState: { | 23 deviceState: { |
22 type: Object, | 24 type: Object, |
23 observer: 'deviceStateChanged_', | 25 observer: 'deviceStateChanged_', |
24 }, | 26 }, |
25 | 27 |
26 /** | 28 /** |
27 * Network state for the active network. | 29 * Network state for the active network. |
28 * @type {!CrOnc.NetworkStateProperties|undefined} | 30 * @type {!CrOnc.NetworkStateProperties|undefined} |
29 */ | 31 */ |
30 activeNetworkState: { | 32 activeNetworkState: Object, |
31 type: Object, | |
32 observer: 'activeNetworkStateChanged_', | |
33 }, | |
34 | 33 |
35 /** | 34 /** |
36 * List of all network state data for the network type. | 35 * List of all network state data for the network type. |
37 * @type {!Array<!CrOnc.NetworkStateProperties>} | 36 * @type {!Array<!CrOnc.NetworkStateProperties>} |
38 */ | 37 */ |
39 networkStateList: { | 38 networkStateList: { |
40 type: Array, | 39 type: Array, |
41 value: function() { | 40 value: function() { |
42 return []; | 41 return []; |
43 }, | 42 }, |
44 observer: 'networkStateListChanged_', | |
45 }, | 43 }, |
46 | 44 |
47 /** The maximum height in pixels for the list of networks. */ | 45 /** The maximum height in pixels for the list of networks. */ |
48 maxHeight: { | 46 maxHeight: { |
49 type: Number, | 47 type: Number, |
50 value: 200, | 48 value: 200, |
51 }, | 49 }, |
52 | 50 |
53 /** | 51 /** |
52 * Interface for networkingPrivate calls, passed from internet_page. | |
53 * @type {NetworkingPrivate} | |
54 */ | |
55 networkingPrivate: Object, | |
56 | |
57 /** | |
54 * The expanded state of the list of networks. | 58 * The expanded state of the list of networks. |
55 * @private | 59 * @private |
56 */ | 60 */ |
57 expanded_: { | 61 expanded_: { |
58 type: Boolean, | 62 type: Boolean, |
59 value: false, | 63 value: false, |
60 observer: 'expandedChanged_', | 64 observer: 'expandedChanged_', |
61 }, | 65 }, |
62 | 66 |
63 /** | 67 /** |
64 * Whether the list has been expanded. This is used to ensure the | 68 * Whether the list has been expanded. This is used to ensure the |
65 * iron-collapse section animates correctly. | 69 * iron-collapse section animates correctly. |
66 * @private | 70 * @private |
67 */ | 71 */ |
68 wasExpanded_: { | 72 wasExpanded_: { |
69 type: Boolean, | 73 type: Boolean, |
70 value: false, | 74 value: false, |
71 }, | 75 }, |
72 }, | 76 }, |
73 | 77 |
78 keyBindings: { | |
79 'enter': 'onDetailsTap_', | |
80 }, | |
81 | |
74 /** @private */ | 82 /** @private */ |
75 expandedChanged_: function() { | 83 expandedChanged_: function() { |
76 var type = this.deviceState ? this.deviceState.Type : ''; | 84 var type = this.deviceState ? this.deviceState.Type : ''; |
77 this.fire('expanded', {expanded: this.expanded_, type: type}); | 85 this.fire('expanded', {expanded: this.expanded_, type: type}); |
78 }, | 86 }, |
79 | 87 |
80 /** @private */ | 88 /** @private */ |
81 deviceStateChanged_: function() { | 89 deviceStateChanged_: function() { |
82 this.updateSelectable_(); | |
83 if (this.expanded_ && !this.deviceIsEnabled_()) | 90 if (this.expanded_ && !this.deviceIsEnabled_()) |
84 this.expanded_ = false; | 91 this.expanded_ = false; |
85 }, | 92 }, |
86 | 93 |
87 /** @private */ | |
88 activeNetworkStateChanged_: function() { | |
89 this.updateSelectable_(); | |
90 }, | |
91 | |
92 /** @private */ | |
93 networkStateListChanged_: function() { | |
94 this.updateSelectable_(); | |
95 }, | |
96 | |
97 /** | 94 /** |
98 * @return {boolean} Whether or not the scanning spinner should be shown. | 95 * @return {boolean} Whether or not the scanning spinner should be shown. |
99 * @private | 96 * @private |
100 */ | 97 */ |
101 showScanning_: function() { | 98 showScanning_: function() { |
102 return !!this.expanded_ && !!this.deviceState.Scanning; | 99 return !!this.expanded_ && !!this.deviceState.Scanning; |
103 }, | 100 }, |
104 | 101 |
105 /** | 102 /** |
103 * Show the <network-siminfo> element if this is a disabled and locked | |
104 * cellular device. | |
105 * @return {boolean} | |
106 * @private | |
107 */ | |
108 showSimInfo_: function() { | |
109 let device = this.deviceState; | |
110 if (device.Type != CrOnc.Type.CELLULAR || this.deviceIsEnabled_()) | |
111 return false; | |
112 return device.SimPresent === false || | |
113 device.SimLockType == CrOnc.LockType.PIN || | |
114 device.SimLockType == CrOnc.LockType.PUK; | |
115 }, | |
116 | |
117 /** | |
118 * Returns a NetworkProperties object for <network-siminfo> built from | |
119 * the device properties (since there will be no active network). | |
120 * @return {!CrOnc.NetworkProperties} | |
121 * @private | |
122 */ | |
123 getCellularState_: function() { | |
124 let device = this.deviceState; | |
125 return { | |
126 GUID: '', | |
127 Type: CrOnc.Type.CELLULAR, | |
128 Cellular: { | |
129 SIMLockStatus: { | |
130 LockType: device.SimLockType || '', | |
131 LockEnabled: device.SimLockType != CrOnc.LockType.NONE | |
132 }, | |
133 SIMPresent: device.SimPresent, | |
134 }, | |
135 }; | |
136 }, | |
137 | |
138 /** | |
106 * @return {boolean} Whether or not the device state is enabled. | 139 * @return {boolean} Whether or not the device state is enabled. |
107 * @private | 140 * @private |
108 */ | 141 */ |
109 deviceIsEnabled_: function() { | 142 deviceIsEnabled_: function() { |
110 return !!this.deviceState && | 143 return !!this.deviceState && |
111 this.deviceState.State == | 144 this.deviceState.State == |
112 chrome.networkingPrivate.DeviceStateType.ENABLED; | 145 chrome.networkingPrivate.DeviceStateType.ENABLED; |
113 }, | 146 }, |
114 | 147 |
115 /** | 148 /** |
(...skipping 21 matching lines...) Expand all Loading... | |
137 */ | 170 */ |
138 networksIronCollapseIsOpened_() { | 171 networksIronCollapseIsOpened_() { |
139 return this.expanded_ && this.wasExpanded_; | 172 return this.expanded_ && this.wasExpanded_; |
140 }, | 173 }, |
141 | 174 |
142 /** | 175 /** |
143 * @return {boolean} | 176 * @return {boolean} |
144 * @private | 177 * @private |
145 */ | 178 */ |
146 enableIsVisible_: function() { | 179 enableIsVisible_: function() { |
147 return !!this.deviceState && this.deviceState.Type != CrOnc.Type.ETHERNET && | 180 return this.deviceState.Type != CrOnc.Type.ETHERNET && |
148 this.deviceState.Type != CrOnc.Type.VPN; | 181 this.deviceState.Type != CrOnc.Type.VPN; |
149 }, | 182 }, |
150 | 183 |
151 /** | 184 /** |
185 * @return {boolean} | |
186 * @private | |
187 */ | |
188 showDetailsIsVisible_: function() { | |
189 return this.deviceState.Type == CrOnc.Type.CELLULAR && | |
190 this.networkStateList.length == 1; | |
191 }, | |
192 | |
193 /** | |
152 * @return {boolean} Whether or not to show the UI to expand the list. | 194 * @return {boolean} Whether or not to show the UI to expand the list. |
153 * @private | 195 * @private |
154 */ | 196 */ |
155 expandIsVisible_: function() { | 197 expandIsVisible_: function() { |
156 if (!this.deviceIsEnabled_()) | 198 if (!this.deviceIsEnabled_()) |
157 return false; | 199 return false; |
158 let type = this.deviceState.Type; | 200 let type = this.deviceState.Type; |
159 var minLength = | 201 var minLength = |
160 (type == CrOnc.Type.WI_FI || type == CrOnc.Type.VPN) ? 1 : 2; | 202 (type == CrOnc.Type.WI_FI || type == CrOnc.Type.VPN) ? 1 : 2; |
161 return this.networkStateList.length >= minLength; | 203 return this.networkStateList.length >= minLength; |
162 }, | 204 }, |
163 | 205 |
164 /** | 206 /** |
165 * @return {boolean} True if the known networks button should be shown. | 207 * @return {boolean} True if the known networks button should be shown. |
166 * @private | 208 * @private |
167 */ | 209 */ |
168 knownNetworksIsVisible_: function() { | 210 knownNetworksIsVisible_: function() { |
169 return !!this.activeNetworkState && | 211 return !!this.activeNetworkState && |
170 this.activeNetworkState.Type == CrOnc.Type.WI_FI; | 212 this.activeNetworkState.Type == CrOnc.Type.WI_FI; |
171 }, | 213 }, |
172 | 214 |
173 /** | 215 /** |
174 * Event triggered when the details div is tapped. | 216 * Event triggered when the details div is tapped. |
michaelpg
2016/09/06 21:10:38
document that <Enter> on this element triggers thi
stevenjb
2016/09/12 19:46:42
Done.
| |
175 * @param {Event} event The enable button event. | 217 * @param {Event} event The enable button event. |
michaelpg
2016/09/06 21:10:38
!Event while you're here
stevenjb
2016/09/12 19:46:42
Done.
| |
176 * @private | 218 * @private |
177 */ | 219 */ |
178 onDetailsTap_: function(event) { | 220 onDetailsTap_: function(event) { |
179 if ((event.target.id == 'expandListButton') || | 221 if ((event.target && event.target.id == 'expandListButton') || |
180 (this.deviceState && !this.deviceIsEnabled_())) { | 222 (this.deviceState && !this.deviceIsEnabled_())) { |
181 // Already handled or disabled, do nothing. | 223 // Already handled or disabled, do nothing. |
182 return; | 224 return; |
183 } | 225 } |
184 if (this.expandIsVisible_()) { | 226 if (this.expandIsVisible_()) { |
185 // Expandable, toggle expand. | 227 // Expandable, toggle expand. |
186 this.expanded_ = !this.expanded_; | 228 this.expanded_ = !this.expanded_; |
187 return; | 229 return; |
188 } | 230 } |
189 // Not expandable, fire 'selected' with |activeNetworkState|. | 231 // Not expandable, fire 'selected' with |activeNetworkState|. |
190 this.fire('selected', this.activeNetworkState); | 232 this.fire('selected', this.activeNetworkState); |
191 }, | 233 }, |
192 | 234 |
193 /** | 235 /** |
236 * @param {Event} event The enable button event. | |
michaelpg
2016/09/06 21:10:38
!Event
stevenjb
2016/09/12 19:46:42
Done.
| |
237 * @private | |
238 */ | |
239 onShowDetailsTap_: function(event) { | |
240 if (this.activeNetworkState.GUID != '') { | |
241 this.fire('show-detail', this.activeNetworkState); | |
michaelpg
2016/09/06 21:10:38
optional: early return?
stevenjb
2016/09/12 19:46:42
Done.
| |
242 event.stopPropagation(); | |
243 } | |
244 }, | |
245 | |
246 /** | |
194 * Event triggered when the known networks button is tapped. | 247 * Event triggered when the known networks button is tapped. |
195 * @private | 248 * @private |
196 */ | 249 */ |
197 onKnownNetworksTap_: function() { | 250 onKnownNetworksTap_: function() { |
198 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); | 251 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); |
199 }, | 252 }, |
200 | 253 |
201 /** | 254 /** |
202 * Event triggered when the enable button is toggled. | 255 * Event triggered when the enable button is toggled. |
203 * @param {!Event} event | 256 * @param {!Event} event |
204 * @private | 257 * @private |
205 */ | 258 */ |
206 onDeviceEnabledTap_: function(event) { | 259 onDeviceEnabledTap_: function(event) { |
207 var deviceIsEnabled = this.deviceIsEnabled_(); | 260 var deviceIsEnabled = this.deviceIsEnabled_(); |
208 var type = this.deviceState ? this.deviceState.Type : ''; | 261 var type = this.deviceState ? this.deviceState.Type : ''; |
209 this.fire( | 262 this.fire( |
210 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); | 263 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
211 // Make sure this does not propagate to onDetailsTap_. | 264 // Make sure this does not propagate to onDetailsTap_. |
212 event.stopPropagation(); | 265 event.stopPropagation(); |
213 }, | 266 }, |
214 | 267 |
215 /** | 268 /** |
216 * Called whenever the 'selectable' state might change. | 269 * @return {string} |
217 * @private | 270 * @private |
218 */ | 271 */ |
219 updateSelectable_: function() { | 272 getTabIndex_: function() { |
220 var selectable = this.deviceIsEnabled_(); | 273 return this.deviceIsEnabled_() ? '0' : '-1'; |
221 this.$.details.classList.toggle('selectable', selectable); | |
222 }, | 274 }, |
223 }); | 275 }); |
OLD | NEW |