1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* View displaying Bluetooth device battery information.
*/
import '../../../cr_elements/shared_style_css.m.js';
import './bluetooth_battery_icon_percentage.js';
import {html, PolymerElement} from '//resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BluetoothDeviceProperties} from 'chrome://resources/mojo/chromeos/services/bluetooth_config/public/mojom/cros_bluetooth_config.mojom-webui.js';
import {BatteryType} from './bluetooth_types.js';
import {getBatteryPercentage, hasAnyDetailedBatteryInfo} from './bluetooth_utils.js';
/** @polymer */
export class BluetoothDeviceBatteryInfoElement extends PolymerElement {
static get is() {
return 'bluetooth-device-battery-info';
}
static get template() {
return html`{__html_template__}`;
}
static get properties() {
return {
/**
* @type {!BluetoothDeviceProperties}
*/
device: {
type: Object,
},
/**
* Enum used as an ID for specific UI elements.
* A BatteryType is passed between html and JS for
* certain UI elements to determine their state.
*
* @type {!BatteryType}
*/
BatteryType: {
type: Object,
value: BatteryType,
},
/** @protected {boolean} */
showMultipleBatteries_: {
type: Boolean,
computed: 'computeShowMultipleBatteries_(device)',
},
};
}
/**
* @param {!BluetoothDeviceProperties}
* device
* @return {boolean}
* @private
*/
computeShowMultipleBatteries_(device) {
return hasAnyDetailedBatteryInfo(device);
}
/**
* @param {!BluetoothDeviceProperties}
* device
* @param {!BatteryType} batteryType
* @return {boolean}
* @private
*/
shouldShowBattery_(device, batteryType) {
return getBatteryPercentage(device, batteryType) !== undefined;
}
}
customElements.define(
BluetoothDeviceBatteryInfoElement.is, BluetoothDeviceBatteryInfoElement);
|