[go: nahoru, domu]

blob: 5f88e3db9f56354e263eecb34a0e5de901bbaf0c [file] [log] [blame]
Alex Newcomer9099fd92018-06-19 03:54:201// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ash/app_menu/notification_menu_header_view.h"
6
7#include "ash/public/cpp/app_menu_constants.h"
8#include "base/strings/string_number_conversions.h"
9#include "ui/base/l10n/l10n_util.h"
10#include "ui/strings/grit/ui_strings.h"
11#include "ui/views/border.h"
12#include "ui/views/controls/label.h"
13#include "ui/views/controls/menu/menu_config.h"
14
15namespace ash {
16
17namespace {
18
19// Color of text in NotificationMenuHeaderView.
20constexpr SkColor kNotificationHeaderTextColor =
21 SkColorSetRGB(0X1A, 0x73, 0xE8);
22
23// Line height of all text in the NotificationMenuHeaderView in dips.
24constexpr int kNotificationHeaderLineHeight = 20;
25
26} // namespace
27
28NotificationMenuHeaderView::NotificationMenuHeaderView() {
29 SetBorder(views::CreateEmptyBorder(gfx::Insets(
30 kNotificationVerticalPadding, kNotificationHorizontalPadding)));
31
32 notification_title_ = new views::Label(
Jan Wilken Dörrie85285b02021-03-11 23:38:4733 std::u16string(l10n_util::GetStringUTF16(
Alex Newcomer9099fd92018-06-19 03:54:2034 IDS_MESSAGE_CENTER_NOTIFICATION_ACCESSIBLE_NAME_PLURAL)),
35 {views::Label::GetDefaultFontList().DeriveWithSizeDelta(1)});
36 notification_title_->SetEnabledColor(kNotificationHeaderTextColor);
37 notification_title_->SetLineHeight(kNotificationHeaderLineHeight);
38 AddChildView(notification_title_);
39
40 counter_ = new views::Label(
Jan Wilken Dörrie85285b02021-03-11 23:38:4741 std::u16string(),
Alex Newcomer9099fd92018-06-19 03:54:2042 {views::Label::GetDefaultFontList().DeriveWithSizeDelta(1)});
43 counter_->SetEnabledColor(kNotificationHeaderTextColor);
44 counter_->SetLineHeight(kNotificationHeaderLineHeight);
45 AddChildView(counter_);
46}
47
48NotificationMenuHeaderView::~NotificationMenuHeaderView() = default;
49
50void NotificationMenuHeaderView::UpdateCounter(int number_of_notifications) {
51 if (number_of_notifications_ == number_of_notifications)
52 return;
53
54 number_of_notifications_ = number_of_notifications;
55
Raul Tambre73f906942019-02-11 16:47:2156 counter_->SetText(base::NumberToString16(number_of_notifications_));
Alex Newcomer9099fd92018-06-19 03:54:2057}
58
59gfx::Size NotificationMenuHeaderView::CalculatePreferredSize() const {
60 return gfx::Size(
Matthew Mourgosd0a505f2021-02-11 02:29:1061 views::MenuConfig::instance().touchable_menu_min_width,
Alex Newcomer9099fd92018-06-19 03:54:2062 GetInsets().height() + notification_title_->GetPreferredSize().height());
63}
64
65void NotificationMenuHeaderView::Layout() {
66 const gfx::Insets insets = GetInsets();
67
68 const gfx::Size notification_title_preferred_size =
69 notification_title_->GetPreferredSize();
70 notification_title_->SetBounds(insets.left(), insets.top(),
71 notification_title_preferred_size.width(),
72 notification_title_preferred_size.height());
73
74 const gfx::Size counter_preferred_size = counter_->GetPreferredSize();
75 counter_->SetBounds(width() - counter_preferred_size.width() - insets.right(),
76 insets.top(), counter_preferred_size.width(),
77 counter_preferred_size.height());
78}
79
80} // namespace ash