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
ash / system / update / quick_settings_notice_view.cc [blame]
// 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 "ash/system/update/quick_settings_notice_view.h"
#include "ash/public/cpp/ash_view_ids.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/style/ash_color_id.h"
#include "ash/style/typography.h"
#include "ash/system/unified/quick_settings_metrics_util.h"
#include "base/functional/bind.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/border.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/layout/box_layout.h"
namespace ash {
namespace {
constexpr int kButtonHeight = 32;
constexpr int kImageLabelSpacing = 8;
constexpr int kIconSize = 20;
constexpr int kRoundedCornerRadius = 16;
constexpr float kButtonStrokeWidth = 1.0f;
// Wrapper function that records the quick settings button being pressed,
// then runs the provided callback.
void PressedCallbackWrapper(views::Button::PressedCallback::Callback callback,
QsButtonCatalogName catalog_name,
const ui::Event& event) {
quick_settings_metrics_util::RecordQsButtonActivated(catalog_name);
callback.Run(event);
}
} // namespace
QuickSettingsNoticeView::QuickSettingsNoticeView(
ash::ViewID view_id,
QsButtonCatalogName catalog_name,
int text_id,
const gfx::VectorIcon& icon,
views::Button::PressedCallback::Callback callback)
: views::LabelButton(
base::BindRepeating(&PressedCallbackWrapper, callback, catalog_name),
l10n_util::GetStringUTF16(text_id)),
text_id_(text_id) {
SetID(view_id);
SetMinSize(gfx::Size(0, kButtonHeight));
SetImageLabelSpacing(kImageLabelSpacing);
views::InkDrop::Get(this)->SetMode(views::InkDropHost::InkDropMode::ON);
views::InkDrop::Get(this)->SetBaseColorId(kColorAshInkDropOpaqueColor);
SetImageModel(views::Button::STATE_NORMAL,
ui::ImageModel::FromVectorIcon(
icon, cros_tokens::kCrosSysOnSurfaceVariant, kIconSize));
SetEnabledTextColorIds(cros_tokens::kCrosSysOnSurfaceVariant);
TypographyProvider::Get()->StyleLabel(TypographyToken::kCrosBody2, *label());
SetHorizontalAlignment(gfx::ALIGN_CENTER);
views::InstallRoundRectHighlightPathGenerator(this, gfx::Insets(0),
kRoundedCornerRadius);
SetInstallFocusRingOnFocus(true);
views::FocusRing::Get(this)->SetColorId(
static_cast<ui::ColorId>(cros_tokens::kCrosSysFocusRing));
}
QuickSettingsNoticeView::~QuickSettingsNoticeView() = default;
void QuickSettingsNoticeView::PaintButtonContents(gfx::Canvas* canvas) {
cc::PaintFlags flags;
gfx::RectF bounds(GetLocalBounds());
flags.setColor(GetColorProvider()->GetColor(cros_tokens::kCrosSysSeparator));
flags.setStyle(cc::PaintFlags::kStroke_Style);
flags.setStrokeWidth(kButtonStrokeWidth);
bounds.Inset(kButtonStrokeWidth / 2.0f);
flags.setAntiAlias(true);
canvas->DrawPath(
SkPath().addRoundRect(gfx::RectFToSkRect(bounds), kRoundedCornerRadius,
kRoundedCornerRadius),
flags);
}
void QuickSettingsNoticeView::SetNarrowLayout(bool narrow) {
label()->SetText(
l10n_util::GetStringUTF16(narrow ? GetShortTextId() : text_id_));
}
int QuickSettingsNoticeView::GetShortTextId() const {
return text_id_;
}
BEGIN_METADATA(QuickSettingsNoticeView)
END_METADATA
} // namespace ash