| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "ui/message_center/views/notification_header_view.h" |
| 6 |
| 7 #include "ui/base/l10n/l10n_util.h" |
| 8 #include "ui/gfx/color_palette.h" |
| 9 #include "ui/gfx/font_list.h" |
| 10 #include "ui/gfx/paint_vector_icon.h" |
| 11 #include "ui/message_center/message_center_style.h" |
| 12 #include "ui/message_center/vector_icons.h" |
| 13 #include "ui/message_center/views/padded_button.h" |
| 14 #include "ui/strings/grit/ui_strings.h" |
| 15 #include "ui/views/controls/button/image_button.h" |
| 16 #include "ui/views/controls/image_view.h" |
| 17 #include "ui/views/controls/label.h" |
| 18 #include "ui/views/layout/box_layout.h" |
| 19 #include "ui/views/painter.h" |
| 20 |
| 21 namespace message_center { |
| 22 |
| 23 namespace { |
| 24 |
| 25 constexpr int kHeaderHeight = 28; |
| 26 constexpr int kAppIconSize = 12; |
| 27 constexpr int kExpandIconSize = 12; |
| 28 constexpr gfx::Insets kHeaderPadding(0, 12, 0, 2); |
| 29 constexpr int kHeaderHorizontalSpacing = 2; |
| 30 constexpr int kAppInfoConatainerTopPadding = 12; |
| 31 |
| 32 } // namespace |
| 33 |
| 34 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) |
| 35 : views::CustomButton(listener) { |
| 36 views::BoxLayout* layout = new views::BoxLayout( |
| 37 views::BoxLayout::kHorizontal, kHeaderPadding, kHeaderHorizontalSpacing); |
| 38 layout->set_cross_axis_alignment( |
| 39 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 40 SetLayoutManager(layout); |
| 41 |
| 42 views::View* app_info_container = new views::View(); |
| 43 views::BoxLayout* app_info_layout = |
| 44 new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 45 gfx::Insets(kAppInfoConatainerTopPadding, 0, 0, 0), |
| 46 kHeaderHorizontalSpacing); |
| 47 app_info_layout->set_cross_axis_alignment( |
| 48 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 49 app_info_container->SetLayoutManager(app_info_layout); |
| 50 AddChildView(app_info_container); |
| 51 |
| 52 // App icon view |
| 53 app_icon_view_ = new views::ImageView(); |
| 54 app_icon_view_->SetImageSize(gfx::Size(kAppIconSize, kAppIconSize)); |
| 55 app_info_container->AddChildView(app_icon_view_); |
| 56 |
| 57 // App name view |
| 58 const gfx::FontList& font_list = views::Label().font_list().Derive( |
| 59 -2, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); |
| 60 app_name_view_ = new views::Label(base::string16()); |
| 61 app_name_view_->SetFontList(font_list); |
| 62 app_name_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 63 app_info_container->AddChildView(app_name_view_); |
| 64 |
| 65 // Expand button view |
| 66 expand_button_ = new views::ImageButton(listener); |
| 67 expand_button_->SetImage( |
| 68 views::Button::STATE_NORMAL, |
| 69 gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize, |
| 70 gfx::kChromeIconGrey)); |
| 71 expand_button_->SetFocusForPlatform(); |
| 72 expand_button_->SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
| 73 kFocusBorderColor, gfx::Insets(1, 2, 2, 2))); |
| 74 app_info_container->AddChildView(expand_button_); |
| 75 |
| 76 // Spacer between left-aligned views and right-aligned views |
| 77 views::View* spacer = new views::View; |
| 78 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight)); |
| 79 layout->SetFlexForView(spacer, 1); |
| 80 AddChildView(spacer); |
| 81 |
| 82 // Settings button view |
| 83 settings_button_ = new PaddedButton(listener); |
| 84 settings_button_->SetImage(views::Button::STATE_NORMAL, GetSettingsIcon()); |
| 85 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16( |
| 86 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
| 87 settings_button_->SetTooltipText(l10n_util::GetStringUTF16( |
| 88 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
| 89 AddChildView(settings_button_); |
| 90 |
| 91 // Close button view |
| 92 close_button_ = new PaddedButton(listener); |
| 93 close_button_->SetImage(views::Button::STATE_NORMAL, GetCloseIcon()); |
| 94 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( |
| 95 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); |
| 96 close_button_->SetTooltipText(l10n_util::GetStringUTF16( |
| 97 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); |
| 98 AddChildView(close_button_); |
| 99 } |
| 100 |
| 101 void NotificationHeaderView::SetAppIcon(const gfx::ImageSkia& img) { |
| 102 app_icon_view_->SetImage(img); |
| 103 } |
| 104 |
| 105 void NotificationHeaderView::SetAppName(const base::string16& name) { |
| 106 app_name_view_->SetText(name); |
| 107 } |
| 108 |
| 109 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { |
| 110 expand_button_->SetVisible(enabled); |
| 111 } |
| 112 |
| 113 void NotificationHeaderView::SetExpanded(bool expanded) { |
| 114 expand_button_->SetImage( |
| 115 views::Button::STATE_NORMAL, |
| 116 gfx::CreateVectorIcon( |
| 117 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon, |
| 118 kExpandIconSize, gfx::kChromeIconGrey)); |
| 119 } |
| 120 |
| 121 void NotificationHeaderView::SetSettingsButtonEnabled(bool enabled) { |
| 122 if (settings_button_enabled_ != enabled) { |
| 123 settings_button_enabled_ = enabled; |
| 124 UpdateControlButtonsVisibility(); |
| 125 } |
| 126 } |
| 127 |
| 128 void NotificationHeaderView::SetCloseButtonEnabled(bool enabled) { |
| 129 if (close_button_enabled_ != enabled) { |
| 130 close_button_enabled_ = enabled; |
| 131 UpdateControlButtonsVisibility(); |
| 132 } |
| 133 } |
| 134 |
| 135 void NotificationHeaderView::SetControlButtonsVisible(bool visible) { |
| 136 if (is_control_buttons_visible_ != visible) { |
| 137 is_control_buttons_visible_ = visible; |
| 138 UpdateControlButtonsVisibility(); |
| 139 } |
| 140 } |
| 141 |
| 142 bool NotificationHeaderView::IsExpandButtonEnabled() { |
| 143 return expand_button_->visible(); |
| 144 } |
| 145 |
| 146 bool NotificationHeaderView::IsSettingsButtonEnabled() { |
| 147 return settings_button_enabled_; |
| 148 } |
| 149 |
| 150 bool NotificationHeaderView::IsCloseButtonEnabled() { |
| 151 return close_button_enabled_; |
| 152 } |
| 153 |
| 154 void NotificationHeaderView::UpdateControlButtonsVisibility() { |
| 155 settings_button_->SetVisible(settings_button_enabled_ && |
| 156 is_control_buttons_visible_); |
| 157 close_button_->SetVisible(close_button_enabled_ && |
| 158 is_control_buttons_visible_); |
| 159 Layout(); |
| 160 } |
| 161 |
| 162 } // namespace message_center |
| OLD | NEW |