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

Side by Side Diff: chrome/browser/resources/bluetooth_internals/characteristic_list.js

Issue 2622393002: bluetooth: Add characteristic list to DeviceDetailsPage in internals page. (Closed)
Patch Set: Fix comments, simplify onExpand Created 3 years, 11 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Javascript for CharacteristicList and CharacteristicListItem, served from
7 * chrome://bluetooth-internals/.
8 */
9
10 cr.define('characteristic_list', function() {
11 /** @const */ var ExpandableList = expandable_list.ExpandableList;
12 /** @const */ var ExpandableListItem = expandable_list.ExpandableListItem;
13
14 /** Property names for the CharacteristicInfo fieldset */
15 var INFO_PROPERTY_NAMES = {
16 id: 'ID',
17 'uuid.uuid': 'UUID',
18 };
19
20 /** Property names for the Properties fieldset. */
21 var PROPERTIES_PROPERTY_NAMES = {
22 broadcast: 'Broadcast',
23 read: 'Read',
24 write_without_response: 'Write Without Response',
25 write: 'Write',
26 notify: 'Notify',
27 indicate: 'Indicate',
28 authenticated_signed_writes: 'Authenticated Signed Writes',
29 extended_properties: 'Extended Properties',
30 reliable_write: 'Reliable Write',
31 writable_auxiliaries: 'Writable Auxiliaries',
32 read_encrypted: 'Read Encrypted',
33 write_encrypted: 'Write Encrypted',
34 read_encrypted_authenticated: 'Read Encrypted Authenticated',
35 write_encrypted_authenticated: 'Write Encrypted Authenticated',
36 };
37
38 /**
39 * A list item that displays the properties of a CharacteristicInfo object.
40 * Two fieldsets are created within the element: one for the primitive
41 * properties, 'id' and 'uuid', and one for the 'properties' object within the
42 * CharacteristicInfo object.
43 * @constructor
44 * @param {!interfaces.BluetoothDevice.CharacteristicInfo} characteristicInfo
45 */
46 function CharacteristicListItem(characteristicInfo) {
47 var listItem = new ExpandableListItem();
48 listItem.__proto__ = CharacteristicListItem.prototype;
49
50 listItem.info = characteristicInfo;
51 listItem.decorate();
52
53 return listItem;
54 }
55
56 CharacteristicListItem.prototype = {
57 __proto__: ExpandableListItem.prototype,
58
59 /**
60 * Decorates the element as a characteristic list item. Creates and caches
61 * two fieldsets for displaying property values.
62 * @override
63 */
64 decorate: function() {
65 this.classList.add('characteristic-list-item');
66
67 /** @private {!object_fieldset.ObjectFieldSet} */
68 this.characteristicFieldSet_ = object_fieldset.ObjectFieldSet();
69 this.characteristicFieldSet_.setPropertyDisplayNames(INFO_PROPERTY_NAMES);
70 var characteristicViewObj = {
71 id: this.info.id,
72 'uuid.uuid': this.info.uuid.uuid,
73 };
74 this.characteristicFieldSet_.setObject(characteristicViewObj);
75
76 /** @private {!object_fieldset.ObjectFieldSet} */
77 this.propertiesFieldSet_ = new object_fieldset.ObjectFieldSet();
78 this.propertiesFieldSet_.setPropertyDisplayNames(
79 PROPERTIES_PROPERTY_NAMES);
80 this.propertiesFieldSet_.setObject(this.info.properties);
81
82 // Create content for display in brief content container.
83 var characteristicHeaderText = document.createElement('div');
84 characteristicHeaderText.textContent = 'Characteristic:';
85
86 var characteristicHeaderValue = document.createElement('div');
87 characteristicHeaderValue.textContent = this.info.uuid.uuid;
88
89 var characteristicHeader = document.createElement('div');
90 characteristicHeader.appendChild(characteristicHeaderText);
91 characteristicHeader.appendChild(characteristicHeaderValue);
92 this.briefContent_.appendChild(characteristicHeader);
93
94 // Create content for display in expanded content container.
95 var characteristicInfoHeader = document.createElement('h4');
96 characteristicInfoHeader.textContent = 'Characteristic Info';
97
98 var characteristicDiv = document.createElement('div');
99 characteristicDiv.classList.add('flex');
100 characteristicDiv.appendChild(this.characteristicFieldSet_);
101
102 var propertiesHeader = document.createElement('h4');
103 propertiesHeader.textContent = 'Properties';
104
105
106 var propertiesDiv = document.createElement('div');
107 propertiesDiv.classList.add('flex');
108 propertiesDiv.appendChild(this.propertiesFieldSet_);
109
110 var infoDiv = document.createElement('div');
111 infoDiv.classList.add('info-container');
112 infoDiv.appendChild(characteristicInfoHeader);
113 infoDiv.appendChild(characteristicDiv);
114 infoDiv.appendChild(propertiesHeader);
115 infoDiv.appendChild(propertiesDiv);
116
117 this.expandedContent_.appendChild(infoDiv);
118 },
119 };
120
121 /**
122 * A list that displays CharacteristicListItems.
123 * @constructor
124 */
125 var CharacteristicList = cr.ui.define('list');
126
127 CharacteristicList.prototype = {
128 __proto__: ExpandableList.prototype,
129
130 /** @override */
131 decorate: function() {
132 ExpandableList.prototype.decorate.call(this);
133 this.classList.add('characteristic-list');
134 this.setEmptyMessage('No Characteristics Found');
135 },
136
137 /** @override */
138 createItem: function(data) {
139 return new CharacteristicListItem(data);
140 },
141 };
142
143 return {
144 CharacteristicList: CharacteristicList,
145 CharacteristicListItem: CharacteristicListItem,
146 };
147 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698