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

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: tests 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 /**
6 * @fileoverview
7 * 'settings-bluetooth-pair-device-dialog' is the settings dialog for pairing
8 * a bluetooth device.
9 */
10
11 (function() { 5 (function() {
12 6
13 var PairingEventType = chrome.bluetoothPrivate.PairingEventType; 7 var PairingEventType = chrome.bluetoothPrivate.PairingEventType;
14 8
15 Polymer({ 9 Polymer({
16 is: 'settings-bluetooth-pair-device-dialog', 10 is: 'bluetooth-device-dialog',
17 11
18 behaviors: [I18nBehavior], 12 behaviors: [I18nBehavior],
19 13
20 properties: { 14 properties: {
15 /** Which version of this dialog to show (adding or pairing). */
16 dialog: String,
stevenjb 2016/05/09 16:58:10 I was confused by |dialog| in the html, maybe dial
Dan Beam 2016/05/10 23:55:22 Done.
17
18 // ================================== Add ======================================
stevenjb 2016/05/09 16:58:10 The necessity of these comments for readability su
Dan Beam 2016/05/10 23:55:22 Done.
19 /**
20 * The cached bluetooth adapter state.
21 * @type {!chrome.bluetooth.AdapterState|undefined}
22 */
23 adapterState: {
24 type: Object,
25 observer: 'adapterStateChanged_',
26 },
27
28 /**
29 * The ordered list of bluetooth devices.
30 * @type {!Array<!chrome.bluetooth.Device>}
31 */
32 deviceList: {
33 type: Array,
34 value: function() { return []; },
35 },
36
37 // ================================= Pair ======================================
21 /** 38 /**
22 * Current Pairing device. 39 * Current Pairing device.
23 * @type {?chrome.bluetooth.Device|undefined} 40 * @type {?chrome.bluetooth.Device|undefined}
24 */ 41 */
25 pairingDevice: Object, 42 pairingDevice: Object,
26 43
27 /** 44 /**
28 * Current Pairing event. 45 * Current Pairing event.
29 * @type {?chrome.bluetoothPrivate.PairingEvent|undefined} 46 * @type {?chrome.bluetoothPrivate.PairingEvent|undefined}
30 */ 47 */
31 pairingEvent: Object, 48 pairingEvent: Object,
32 49
33 /** 50 /**
34 * @const 51 * @const
35 * @type {!Array<number>} 52 * @type {!Array<number>}
36 */ 53 */
37 digits: { 54 digits: {
38 type: Array, 55 type: Array,
39 readOnly: true, 56 readOnly: true,
40 value: [0, 1, 2, 3, 4, 5], 57 value: [0, 1, 2, 3, 4, 5],
41 }, 58 },
42 }, 59 },
43 60
44 observers: [ 61 observers: [
45 'pairingChanged_(pairingDevice, pairingEvent)', 62 'pairingChanged_(pairingDevice, pairingEvent)',
46 ], 63 ],
64 // =============================================================================
47 65
48 /** 66 /**
67 * @return {boolean}
68 * @private
69 */
70 isDialog_: function(currentDialog, wantedDialog) {
stevenjb 2016/05/09 16:58:10 Types for num-member args?
Dan Beam 2016/05/10 23:55:22 Done.
71 return currentDialog == wantedDialog;
72 },
73
74 open: function() {
75 this.$.dialog.open();
76 },
77
78 close: function() {
79 this.$.dialog.close();
80 },
81
82 // ================================== Add ======================================
83 /** @private */
84 adapterStateChanged_: function() {
85 if (!this.adapterState.powered)
86 this.fire('close-dialog');
87 },
88
89 /**
90 * @param {!chrome.bluetooth.Device} device
91 * @return {boolean}
92 * @private
93 */
94 deviceNotPaired_: function(device) {
95 return !device.paired;
96 },
97
98 /**
99 * @param {!Array<!chrome.bluetooth.Device>} deviceList
100 * @return {boolean} True if deviceList contains any unpaired devices.
101 * @private
102 */
103 haveDevices_: function(deviceList) {
104 return this.deviceList.findIndex(function(d) { return !d.paired; }) != -1;
105 },
106
107 /**
108 * @param {!{detail: {action: string, device: !chrome.bluetooth.Device}}} e
109 * @private
110 */
111 onDeviceEvent_: function(e) {
112 this.fire('device-event', e.detail);
113 /** @type {Event} */(e).stopPropagation();
114 },
115
116 /** @private */
117 onAddCancelTap_: function() { this.fire('close-dialog'); },
118
119 // ================================= Pair ======================================
120 /**
49 * @param {?chrome.bluetooth.Device} pairingDevice 121 * @param {?chrome.bluetooth.Device} pairingDevice
50 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent 122 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
51 * @private 123 * @private
52 */ 124 */
53 pairingChanged_: function(pairingDevice, pairingEvent) { 125 pairingChanged_: function(pairingDevice, pairingEvent) {
54 // Auto-close the dialog when pairing completes. 126 // Auto-close the dialog when pairing completes.
55 if (pairingDevice && pairingDevice.connected) { 127 if (pairingDevice && pairingDevice.connected) {
56 this.fire('close-dialog', ''); 128 this.fire('close-dialog', '');
57 return; 129 return;
58 } 130 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 onConnectTap_: function() { 232 onConnectTap_: function() {
161 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM); 233 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM);
162 }, 234 },
163 235
164 /** @private */ 236 /** @private */
165 onRejectTap_: function() { 237 onRejectTap_: function() {
166 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.REJECT); 238 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.REJECT);
167 }, 239 },
168 240
169 /** @private */ 241 /** @private */
170 onCancelTap_: function() { 242 onPairCancelTap_: function() {
171 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); 243 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL);
172 // Close the dialog immediately. 244 // Close the dialog immediately.
173 this.fire('close-dialog', ''); 245 this.fire('close-dialog', '');
174 }, 246 },
175 247
176 /** @private */ 248 /** @private */
177 onDismissTap_: function() { this.fire('close-dialog', ''); }, 249 onDismissTap_: function() { this.fire('close-dialog', ''); },
178 250
179 /** @private */ 251 /** @private */
180 sendResponse_: function(response) { 252 sendResponse_: function(response) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 var enteredKey = pairingEvent.enteredKey; // 1-7 330 var enteredKey = pairingEvent.enteredKey; // 1-7
259 var lastKey = this.digits.length; // 6 331 var lastKey = this.digits.length; // 6
260 if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey)) 332 if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey))
261 cssClass += ' next'; 333 cssClass += ' next';
262 else if (index > enteredKey) 334 else if (index > enteredKey)
263 cssClass += ' untyped'; 335 cssClass += ' untyped';
264 } 336 }
265 return cssClass; 337 return cssClass;
266 }, 338 },
267 }); 339 });
340
268 })(); 341 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698