Alex Newcomer | 9099fd9 | 2018-06-19 03:54:20 | [diff] [blame] | 1 | // 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 | |
| 15 | namespace ash { |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | // Color of text in NotificationMenuHeaderView. |
| 20 | constexpr SkColor kNotificationHeaderTextColor = |
| 21 | SkColorSetRGB(0X1A, 0x73, 0xE8); |
| 22 | |
| 23 | // Line height of all text in the NotificationMenuHeaderView in dips. |
| 24 | constexpr int kNotificationHeaderLineHeight = 20; |
| 25 | |
| 26 | } // namespace |
| 27 | |
| 28 | NotificationMenuHeaderView::NotificationMenuHeaderView() { |
| 29 | SetBorder(views::CreateEmptyBorder(gfx::Insets( |
| 30 | kNotificationVerticalPadding, kNotificationHorizontalPadding))); |
| 31 | |
| 32 | notification_title_ = new views::Label( |
Jan Wilken Dörrie | 85285b0 | 2021-03-11 23:38:47 | [diff] [blame^] | 33 | std::u16string(l10n_util::GetStringUTF16( |
Alex Newcomer | 9099fd9 | 2018-06-19 03:54:20 | [diff] [blame] | 34 | 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örrie | 85285b0 | 2021-03-11 23:38:47 | [diff] [blame^] | 41 | std::u16string(), |
Alex Newcomer | 9099fd9 | 2018-06-19 03:54:20 | [diff] [blame] | 42 | {views::Label::GetDefaultFontList().DeriveWithSizeDelta(1)}); |
| 43 | counter_->SetEnabledColor(kNotificationHeaderTextColor); |
| 44 | counter_->SetLineHeight(kNotificationHeaderLineHeight); |
| 45 | AddChildView(counter_); |
| 46 | } |
| 47 | |
| 48 | NotificationMenuHeaderView::~NotificationMenuHeaderView() = default; |
| 49 | |
| 50 | void 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 Tambre | 73f90694 | 2019-02-11 16:47:21 | [diff] [blame] | 56 | counter_->SetText(base::NumberToString16(number_of_notifications_)); |
Alex Newcomer | 9099fd9 | 2018-06-19 03:54:20 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | gfx::Size NotificationMenuHeaderView::CalculatePreferredSize() const { |
| 60 | return gfx::Size( |
Matthew Mourgos | d0a505f | 2021-02-11 02:29:10 | [diff] [blame] | 61 | views::MenuConfig::instance().touchable_menu_min_width, |
Alex Newcomer | 9099fd9 | 2018-06-19 03:54:20 | [diff] [blame] | 62 | GetInsets().height() + notification_title_->GetPreferredSize().height()); |
| 63 | } |
| 64 | |
| 65 | void 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 |