summaryrefslogtreecommitdiff
path: root/chromium/ui/webui/resources/cr_components/chromeos/bluetooth/bluetooth_icon.js
blob: 66b69a54834a7c714fe9664df6fbb10c58a08a06 (plain)
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
82
83
84
85
86
87
88
89
// 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
 * UI element used to display Bluetooth device icon.
 */

import './bluetooth_icons.js';

import {html, PolymerElement} from '//resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {hasDefaultImage} from './bluetooth_utils.js';

/** @polymer */
export class SettingsBluetoothIconElement extends PolymerElement {
  static get is() {
    return 'bluetooth-icon';
  }

  static get template() {
    return html`{__html_template__}`;
  }

  static get properties() {
    return {
      /**
       * @type {!chromeos.bluetoothConfig.mojom.BluetoothDeviceProperties}
       */
      device: {
        type: Object,
      },
    };
  }

  /**
   * @return {string}
   * @private
   */
  getIcon_() {
    if (!this.device) {
      return 'default';
    }

    const deviceType = chromeos.bluetoothConfig.mojom.DeviceType;
    switch (this.device.deviceType) {
      case deviceType.kComputer:
        return 'computer';
      case deviceType.kPhone:
        return 'phone';
      case deviceType.kHeadset:
        return 'headset';
      case deviceType.kVideoCamera:
        return 'video-camera';
      case deviceType.kGameController:
        return 'game-controller';
      case deviceType.kKeyboard:
      case deviceType.kKeyboardMouseCombo:
        return 'keyboard';
      case deviceType.kMouse:
        return 'mouse';
      case deviceType.kTablet:
        return 'tablet';
      default:
        return 'default';
    }
  }

  /**
   * @return {boolean}
   * @private
   */
  hasDefaultImage_() {
    return hasDefaultImage(this.device);
  }

  /**
   * @return {string}
   * @private
   */
  getDefaultImageSrc_() {
    if (!this.hasDefaultImage_()) {
      return '';
    }
    return this.device.imageInfo.defaultImageUrl.url;
  }
}
customElements.define(
    SettingsBluetoothIconElement.is, SettingsBluetoothIconElement);