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

Side by Side Diff: chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js

Issue 1954383002: MD Settings: combine bluetooth adding and pairing dialogs into one (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: whoops, html deps Created 4 years, 7 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 2016 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 cr.exportPath('settings');
6 * @fileoverview
7 * 'settings-bluetooth-pair-device-dialog' is the settings dialog for pairing
8 * a bluetooth device.
9 */
10 6
11 (function() { 7 (function() {
12 8
13 var PairingEventType = chrome.bluetoothPrivate.PairingEventType; 9 var PairingEventType = chrome.bluetoothPrivate.PairingEventType;
14 10
15 Polymer({ 11 // NOTE(dbeam): even though these behaviors are only used privately, they must
16 is: 'settings-bluetooth-pair-device-dialog', 12 // be globally accessible for Closure's --polymer_pass to compile happily.
17 13
18 behaviors: [I18nBehavior], 14 /** @polymerBehavior */
15 settings.BluetoothAddDeviceBehavior = {
16 properties: {
17 /**
18 * The cached bluetooth adapter state.
19 * @type {!chrome.bluetooth.AdapterState|undefined}
20 */
21 adapterState: {
22 type: Object,
23 observer: 'adapterStateChanged_',
24 },
19 25
26 /**
27 * The ordered list of bluetooth devices.
28 * @type {!Array<!chrome.bluetooth.Device>}
29 */
30 deviceList: {
31 type: Array,
32 value: /** @return {Array} */ function() { return []; },
33 },
34 },
35
36 /** @private */
37 adapterStateChanged_: function() {
38 if (!this.adapterState.powered)
39 this.fire('close-dialog');
40 },
41
42 /**
43 * @param {!chrome.bluetooth.Device} device
44 * @return {boolean}
45 * @private
46 */
47 deviceNotPaired_: function(device) {
48 return !device.paired;
49 },
50
51 /**
52 * @param {!Array<!chrome.bluetooth.Device>} deviceList
53 * @return {boolean} True if deviceList contains any unpaired devices.
54 * @private
55 */
56 haveDevices_: function(deviceList) {
57 return this.deviceList.findIndex(function(d) { return !d.paired; }) != -1;
58 },
59
60 /**
61 * @param {!{detail: {action: string, device: !chrome.bluetooth.Device}}} e
62 * @private
63 */
64 onDeviceEvent_: function(e) {
65 this.fire('device-event', e.detail);
66 /** @type {Event} */(e).stopPropagation();
67 },
68
69 /** @private */
70 onAddCancelTap_: function() { this.fire('close-dialog'); },
71 };
72
73 /** @polymerBehavior */
74 settings.BluetoothPairDeviceBehavior = {
20 properties: { 75 properties: {
21 /** 76 /**
22 * Current Pairing device. 77 * Current Pairing device.
23 * @type {?chrome.bluetooth.Device|undefined} 78 * @type {?chrome.bluetooth.Device|undefined}
24 */ 79 */
25 pairingDevice: Object, 80 pairingDevice: Object,
26 81
27 /** 82 /**
28 * Current Pairing event. 83 * Current Pairing event.
29 * @type {?chrome.bluetoothPrivate.PairingEvent|undefined} 84 * @type {?chrome.bluetoothPrivate.PairingEvent|undefined}
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 onConnectTap_: function() { 215 onConnectTap_: function() {
161 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM); 216 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM);
162 }, 217 },
163 218
164 /** @private */ 219 /** @private */
165 onRejectTap_: function() { 220 onRejectTap_: function() {
166 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.REJECT); 221 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.REJECT);
167 }, 222 },
168 223
169 /** @private */ 224 /** @private */
170 onCancelTap_: function() { 225 onPairCancelTap_: function() {
171 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); 226 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL);
172 // Close the dialog immediately. 227 // Close the dialog immediately.
173 this.fire('close-dialog', ''); 228 this.fire('close-dialog', '');
174 }, 229 },
175 230
176 /** @private */ 231 /** @private */
177 onDismissTap_: function() { this.fire('close-dialog', ''); }, 232 onDismissTap_: function() { this.fire('close-dialog', ''); },
178 233
179 /** @private */ 234 /** @private */
180 sendResponse_: function(response) { 235 sendResponse_: function(response) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 pairingEvent.enteredKey) { 312 pairingEvent.enteredKey) {
258 var enteredKey = pairingEvent.enteredKey; // 1-7 313 var enteredKey = pairingEvent.enteredKey; // 1-7
259 var lastKey = this.digits.length; // 6 314 var lastKey = this.digits.length; // 6
260 if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey)) 315 if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey))
261 cssClass += ' next'; 316 cssClass += ' next';
262 else if (index > enteredKey) 317 else if (index > enteredKey)
263 cssClass += ' untyped'; 318 cssClass += ' untyped';
264 } 319 }
265 return cssClass; 320 return cssClass;
266 }, 321 },
322 };
323
324 Polymer({
325 is: 'bluetooth-device-dialog',
326
327 behaviors: [
328 I18nBehavior,
329 settings.BluetoothAddDeviceBehavior,
330 settings.BluetoothPairDeviceBehavior,
331 ],
332
333 properties: {
334 /** Which version of this dialog to show (adding or pairing). */
335 dialogType: String,
336 },
337
338 /**
339 * @param {string} currentDialogType
340 * @param {string} wantedDialogType
341 * @return {boolean}
342 * @private
343 */
344 isDialogType_: function(currentDialogType, wantedDialogType) {
345 return currentDialogType == wantedDialogType;
346 },
347
348 open: function() {
349 this.$.dialog.open();
350 },
351
352 close: function() {
353 this.$.dialog.close();
354 },
267 }); 355 });
356
268 })(); 357 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698