File: cast_device_footer_view.cc

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; 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 (113 lines) | stat: -rw-r--r-- 4,546 bytes parent folder | download | duplicates (5)
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
// Copyright 2024 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/views/global_media_controls/cast_device_footer_view.h"

#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/views/global_media_controls/media_item_ui_helper.h"
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/layout/box_layout.h"

namespace {

constexpr int kBackgroundBorderThickness = 1;
constexpr int kBackgroundCornerRadius = 8;
constexpr int kStopCastingButtonCornerRadius = 10;
constexpr int kBackgroundSeparator = 8;
constexpr int kStopCastingButtonSeparator = 4;
constexpr int kDeviceIconSize = 20;
constexpr int kStopCastingButtonIconSize = 12;

constexpr gfx::Insets kBackgroundInsets = gfx::Insets::VH(13, 15);
constexpr gfx::Insets kStopCastingButtonInsets = gfx::Insets::TLBR(2, 6, 2, 8);

}  // namespace

CastDeviceFooterView::CastDeviceFooterView(
    std::optional<std::string> device_name,
    base::RepeatingClosure stop_casting_callback,
    media_message_center::MediaColorTheme media_color_theme)
    : stop_casting_callback_(std::move(stop_casting_callback)) {
  SetBorder(views::CreateRoundedRectBorder(
      kBackgroundBorderThickness, kBackgroundCornerRadius,
      media_color_theme.device_selector_border_color_id));
  SetBackground(views::CreateRoundedRectBackground(
      media_color_theme.device_selector_background_color_id,
      kBackgroundCornerRadius));
  auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
      views::BoxLayout::Orientation::kHorizontal, kBackgroundInsets,
      kBackgroundSeparator));

  // Add the device icon.
  device_icon_ = AddChildView(
      std::make_unique<views::ImageView>(ui::ImageModel::FromVectorIcon(
          vector_icons::kCastIcon,
          media_color_theme.device_selector_foreground_color_id,
          kDeviceIconSize)));

  // Add the device name.
  device_name_ =
      AddChildView(std::make_unique<views::Label>(l10n_util::GetStringUTF16(
          IDS_GLOBAL_MEDIA_CONTROLS_UNKNOWN_DEVICE_TEXT)));
  if (device_name.has_value()) {
    device_name_->SetText(base::UTF8ToUTF16(device_name.value()));
  }
  device_name_->SetTextStyle(views::style::STYLE_BODY_2_MEDIUM);
  device_name_->SetEnabledColor(
      media_color_theme.device_selector_foreground_color_id);
  device_name_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  layout->SetFlexForView(device_name_, 1);

  // Add the stop casting button.
  stop_casting_button_ = AddChildView(std::make_unique<views::LabelButton>(
      base::BindRepeating(&CastDeviceFooterView::StopCasting,
                          base::Unretained(this)),
      l10n_util::GetStringUTF16(
          IDS_MEDIA_MESSAGE_CENTER_MEDIA_NOTIFICATION_ACTION_STOP_CASTING)));
  stop_casting_button_->SetImageModel(
      views::Button::STATE_NORMAL,
      ui::ImageModel::FromVectorIcon(
          vector_icons::kStopCircleIcon,
          media_color_theme.error_foreground_color_id,
          kStopCastingButtonIconSize));
  stop_casting_button_->SetBorder(
      views::CreateEmptyBorder(kStopCastingButtonInsets));
  stop_casting_button_->SetLabelStyle(views::style::STYLE_BODY_5);
  stop_casting_button_->SetEnabledTextColors(
      media_color_theme.error_foreground_color_id);
  stop_casting_button_->SetImageLabelSpacing(kStopCastingButtonSeparator);
  stop_casting_button_->SetBackground(views::CreateRoundedRectBackground(
      media_color_theme.error_container_color_id,
      kStopCastingButtonCornerRadius));

  // Set the focus behavior for stop casting button.
  stop_casting_button_->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
  stop_casting_button_->SetFocusRingCornerRadius(
      kStopCastingButtonCornerRadius);
  views::FocusRing::Get(stop_casting_button_)
      ->SetColorId(media_color_theme.focus_ring_color_id);
}

CastDeviceFooterView::~CastDeviceFooterView() = default;

views::Label* CastDeviceFooterView::GetDeviceNameForTesting() {
  return device_name_;
}

views::Button* CastDeviceFooterView::GetStopCastingButtonForTesting() {
  return stop_casting_button_;
}

void CastDeviceFooterView::StopCasting() {
  stop_casting_button_->SetEnabled(false);
  stop_casting_callback_.Run();
}

BEGIN_METADATA(CastDeviceFooterView)
END_METADATA