File: tab_alert_icon.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 4,662 bytes parent folder | download | duplicates (3)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/tabs/alert/tab_alert_icon.h"

#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/tabs/alert/tab_alert.h"
#include "chrome/common/chrome_features.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/models/image_model.h"

#if BUILDFLAG(ENABLE_GLIC)
#include "chrome/browser/glic/browser_ui/glic_vector_icon_manager.h"
#endif

namespace tabs {

ui::ColorId GetAlertIndicatorColor(TabAlert state,
                                   bool is_tab_active,
                                   bool is_frame_active) {
  int group = 0;
  switch (state) {
    case tabs::TabAlert::MEDIA_RECORDING:
    case tabs::TabAlert::AUDIO_RECORDING:
    case tabs::TabAlert::VIDEO_RECORDING:
    case tabs::TabAlert::DESKTOP_CAPTURING:
      group = 0;
      break;
    case tabs::TabAlert::TAB_CAPTURING:
    case tabs::TabAlert::PIP_PLAYING:
    case tabs::TabAlert::GLIC_ACCESSING:
    case tabs::TabAlert::GLIC_SHARING:
      group = 1;
      break;
    case tabs::TabAlert::AUDIO_PLAYING:
    case tabs::TabAlert::AUDIO_MUTING:
    case tabs::TabAlert::BLUETOOTH_CONNECTED:
    case tabs::TabAlert::BLUETOOTH_SCAN_ACTIVE:
    case tabs::TabAlert::USB_CONNECTED:
    case tabs::TabAlert::HID_CONNECTED:
    case tabs::TabAlert::SERIAL_CONNECTED:
    case tabs::TabAlert::VR_PRESENTING_IN_HEADSET:
      group = 2;
      break;
    default:
      NOTREACHED() << "Unknown tab alert state";
  }

  static constexpr std::array<std::array<std::array<ui::ColorId, 2>, 2>, 3>
      color_ids{{{{{kColorTabAlertMediaRecordingInactiveFrameInactive,
                    kColorTabAlertMediaRecordingInactiveFrameActive},
                   {kColorTabAlertMediaRecordingActiveFrameInactive,
                    kColorTabAlertMediaRecordingActiveFrameActive}}},
                 {{{kColorTabAlertPipPlayingInactiveFrameInactive,
                    kColorTabAlertPipPlayingInactiveFrameActive},
                   {kColorTabAlertPipPlayingActiveFrameInactive,
                    kColorTabAlertPipPlayingActiveFrameActive}}},
                 {{{kColorTabAlertAudioPlayingInactiveFrameInactive,
                    kColorTabAlertAudioPlayingInactiveFrameActive},
                   {kColorTabAlertAudioPlayingActiveFrameInactive,
                    kColorTabAlertAudioPlayingActiveFrameActive}}}}};
  return color_ids[group][is_tab_active][is_frame_active];
}

const gfx::VectorIcon& GetAlertIcon(TabAlert alert_state) {
  switch (alert_state) {
    case TabAlert::AUDIO_PLAYING:
      return vector_icons::kVolumeUpChromeRefreshIcon;
    case TabAlert::AUDIO_MUTING:
      return vector_icons::kVolumeOffChromeRefreshIcon;
    case TabAlert::MEDIA_RECORDING:
    case TabAlert::AUDIO_RECORDING:
    case TabAlert::VIDEO_RECORDING:
    case TabAlert::DESKTOP_CAPTURING:
      return vector_icons::kRadioButtonCheckedIcon;
    case TabAlert::TAB_CAPTURING:
      return vector_icons::kCaptureIcon;
    case TabAlert::BLUETOOTH_CONNECTED:
      return vector_icons::kBluetoothConnectedIcon;
    case TabAlert::BLUETOOTH_SCAN_ACTIVE:
      return vector_icons::kBluetoothScanningChromeRefreshIcon;
    case TabAlert::USB_CONNECTED:
      return vector_icons::kUsbChromeRefreshIcon;
    case TabAlert::HID_CONNECTED:
      return vector_icons::kVideogameAssetChromeRefreshIcon;
    case TabAlert::SERIAL_CONNECTED:
      return vector_icons::kSerialPortChromeRefreshIcon;
    case TabAlert::PIP_PLAYING:
      return vector_icons::kPictureInPictureAltIcon;
    case TabAlert::VR_PRESENTING_IN_HEADSET:
      return vector_icons::kCardboardIcon;
    case TabAlert::GLIC_ACCESSING:
    case TabAlert::GLIC_SHARING:
#if BUILDFLAG(ENABLE_GLIC)
      return glic::GlicVectorIconManager::GetVectorIcon(
          IDR_GLIC_ACCESSING_ICON);
#else
      return kTvIcon;
#endif
  }
}

ui::ImageModel GetAlertImageModel(TabAlert alert_state,
                                  ui::ColorId icon_color) {
  // Tab capturing icon uses a different width compared to
  // the other tab alert indicator icons.
  const int image_width =
      GetLayoutConstant(alert_state == tabs::TabAlert::TAB_CAPTURING
                            ? TAB_ALERT_INDICATOR_CAPTURE_ICON_WIDTH
                            : TAB_ALERT_INDICATOR_ICON_WIDTH);

  return ui::ImageModel::FromVectorIcon(GetAlertIcon(alert_state), icon_color,
                                        image_width);
}

}  // namespace tabs