| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/message_center/views/notification_header_view.h" | 5 #include "ui/message_center/views/notification_header_view.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/gfx/color_palette.h" | 10 #include "ui/gfx/color_palette.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // Bullet character. The divider symbol between different parts of the header. | 36 // Bullet character. The divider symbol between different parts of the header. |
| 37 constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022; | 37 constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022; |
| 38 | 38 |
| 39 // Base ink drop color of action buttons. | 39 // Base ink drop color of action buttons. |
| 40 const SkColor kInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0); | 40 const SkColor kInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0); |
| 41 // Ripple ink drop opacity of action buttons. | 41 // Ripple ink drop opacity of action buttons. |
| 42 constexpr float kInkDropRippleVisibleOpacity = 0.08f; | 42 constexpr float kInkDropRippleVisibleOpacity = 0.08f; |
| 43 // Highlight (hover) ink drop opacity of action buttons. | 43 // Highlight (hover) ink drop opacity of action buttons. |
| 44 constexpr float kInkDropHighlightVisibleOpacity = 0.08f; | 44 constexpr float kInkDropHighlightVisibleOpacity = 0.08f; |
| 45 | 45 |
| 46 // ExpandButtton forwards all mouse and key events to NotificationHeaderView, |
| 47 // but takes tab focus for accessibility purpose. |
| 48 class ExpandButton : public views::ImageView { |
| 49 public: |
| 50 ExpandButton(); |
| 51 ~ExpandButton() override; |
| 52 |
| 53 void OnPaint(gfx::Canvas* canvas) override; |
| 54 void OnFocus() override; |
| 55 void OnBlur() override; |
| 56 |
| 57 private: |
| 58 std::unique_ptr<views::Painter> focus_painter_; |
| 59 }; |
| 60 |
| 61 ExpandButton::ExpandButton() { |
| 62 SetImage(gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize, |
| 63 gfx::kChromeIconGrey)); |
| 64 focus_painter_ = views::Painter::CreateSolidFocusPainter( |
| 65 kFocusBorderColor, gfx::Insets(1, 2, 2, 2)); |
| 66 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 67 } |
| 68 |
| 69 ExpandButton::~ExpandButton() = default; |
| 70 |
| 71 void ExpandButton::OnPaint(gfx::Canvas* canvas) { |
| 72 views::ImageView::OnPaint(canvas); |
| 73 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| 74 } |
| 75 |
| 76 void ExpandButton::OnFocus() { |
| 77 views::ImageView::OnFocus(); |
| 78 SchedulePaint(); |
| 79 } |
| 80 |
| 81 void ExpandButton::OnBlur() { |
| 82 views::ImageView::OnBlur(); |
| 83 SchedulePaint(); |
| 84 } |
| 85 |
| 46 } // namespace | 86 } // namespace |
| 47 | 87 |
| 48 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) | 88 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) |
| 49 : views::CustomButton(listener) { | 89 : views::CustomButton(listener) { |
| 50 SetInkDropMode(InkDropMode::ON); | 90 SetInkDropMode(InkDropMode::ON); |
| 51 set_has_ink_drop_action_on_click(true); | 91 set_has_ink_drop_action_on_click(true); |
| 52 set_animate_on_state_change(true); | 92 set_animate_on_state_change(true); |
| 53 set_notify_enter_exit_on_child(true); | 93 set_notify_enter_exit_on_child(true); |
| 54 set_ink_drop_base_color(kInkDropBaseColor); | 94 set_ink_drop_base_color(kInkDropBaseColor); |
| 55 set_ink_drop_visible_opacity(kInkDropRippleVisibleOpacity); | 95 set_ink_drop_visible_opacity(kInkDropRippleVisibleOpacity); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 app_info_container->AddChildView(summary_text_divider_); | 134 app_info_container->AddChildView(summary_text_divider_); |
| 95 | 135 |
| 96 // Summary text view | 136 // Summary text view |
| 97 summary_text_view_ = new views::Label(base::string16()); | 137 summary_text_view_ = new views::Label(base::string16()); |
| 98 summary_text_view_->SetFontList(font_list); | 138 summary_text_view_->SetFontList(font_list); |
| 99 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 139 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 100 summary_text_view_->SetVisible(false); | 140 summary_text_view_->SetVisible(false); |
| 101 app_info_container->AddChildView(summary_text_view_); | 141 app_info_container->AddChildView(summary_text_view_); |
| 102 | 142 |
| 103 // Expand button view | 143 // Expand button view |
| 104 expand_button_ = new views::ImageButton(listener); | 144 expand_button_ = new ExpandButton(); |
| 105 expand_button_->SetImage( | |
| 106 views::Button::STATE_NORMAL, | |
| 107 gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize, | |
| 108 gfx::kChromeIconGrey)); | |
| 109 expand_button_->SetFocusForPlatform(); | |
| 110 expand_button_->SetFocusPainter(views::Painter::CreateSolidFocusPainter( | |
| 111 kFocusBorderColor, gfx::Insets(1, 2, 2, 2))); | |
| 112 app_info_container->AddChildView(expand_button_); | 145 app_info_container->AddChildView(expand_button_); |
| 113 | 146 |
| 114 // Spacer between left-aligned views and right-aligned views | 147 // Spacer between left-aligned views and right-aligned views |
| 115 views::View* spacer = new views::View; | 148 views::View* spacer = new views::View; |
| 116 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight)); | 149 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight)); |
| 117 AddChildView(spacer); | 150 AddChildView(spacer); |
| 118 layout->SetFlexForView(spacer, 1); | 151 layout->SetFlexForView(spacer, 1); |
| 119 | 152 |
| 120 // Settings button view | 153 // Settings button view |
| 121 settings_button_ = new PaddedButton(listener); | 154 settings_button_ = new PaddedButton(listener); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 199 } |
| 167 UpdateSummaryTextVisibility(); | 200 UpdateSummaryTextVisibility(); |
| 168 } | 201 } |
| 169 | 202 |
| 170 void NotificationHeaderView::ClearOverflowIndicator() { | 203 void NotificationHeaderView::ClearOverflowIndicator() { |
| 171 has_overflow_indicator_ = false; | 204 has_overflow_indicator_ = false; |
| 172 UpdateSummaryTextVisibility(); | 205 UpdateSummaryTextVisibility(); |
| 173 } | 206 } |
| 174 | 207 |
| 175 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { | 208 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { |
| 209 // SetInkDropMode iff. the visibility changed. |
| 210 // Otherwise, the ink drop animation cannot finish. |
| 211 if (expand_button_->visible() != enabled) |
| 212 SetInkDropMode(enabled ? InkDropMode::ON : InkDropMode::OFF); |
| 213 |
| 176 expand_button_->SetVisible(enabled); | 214 expand_button_->SetVisible(enabled); |
| 177 } | 215 } |
| 178 | 216 |
| 179 void NotificationHeaderView::SetExpanded(bool expanded) { | 217 void NotificationHeaderView::SetExpanded(bool expanded) { |
| 180 expand_button_->SetImage( | 218 expand_button_->SetImage( |
| 181 views::Button::STATE_NORMAL, | |
| 182 gfx::CreateVectorIcon( | 219 gfx::CreateVectorIcon( |
| 183 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon, | 220 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon, |
| 184 kExpandIconSize, gfx::kChromeIconGrey)); | 221 kExpandIconSize, gfx::kChromeIconGrey)); |
| 185 } | 222 } |
| 186 | 223 |
| 187 void NotificationHeaderView::SetSettingsButtonEnabled(bool enabled) { | 224 void NotificationHeaderView::SetSettingsButtonEnabled(bool enabled) { |
| 188 if (settings_button_enabled_ != enabled) { | 225 if (settings_button_enabled_ != enabled) { |
| 189 settings_button_enabled_ = enabled; | 226 settings_button_enabled_ = enabled; |
| 190 UpdateControlButtonsVisibility(); | 227 UpdateControlButtonsVisibility(); |
| 191 } | 228 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 287 } |
| 251 | 288 |
| 252 void NotificationHeaderView::UpdateSummaryTextVisibility() { | 289 void NotificationHeaderView::UpdateSummaryTextVisibility() { |
| 253 const bool visible = has_progress_ || has_overflow_indicator_; | 290 const bool visible = has_progress_ || has_overflow_indicator_; |
| 254 summary_text_divider_->SetVisible(visible); | 291 summary_text_divider_->SetVisible(visible); |
| 255 summary_text_view_->SetVisible(visible); | 292 summary_text_view_->SetVisible(visible); |
| 256 Layout(); | 293 Layout(); |
| 257 } | 294 } |
| 258 | 295 |
| 259 } // namespace message_center | 296 } // namespace message_center |
| OLD | NEW |