Chromium Code Reviews| 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_view_md.h" | 5 #include "ui/message_center/views/notification_view_md.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "ui/base/cursor/cursor.h" | 10 #include "ui/base/cursor/cursor.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/gfx/image/image_skia_operations.h" | 14 #include "ui/gfx/image/image_skia_operations.h" |
| 15 #include "ui/gfx/paint_vector_icon.h" | 15 #include "ui/gfx/paint_vector_icon.h" |
| 16 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 17 #include "ui/gfx/text_elider.h" | 17 #include "ui/gfx/text_elider.h" |
| 18 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
| 19 #include "ui/message_center/message_center_style.h" | 19 #include "ui/message_center/message_center_style.h" |
| 20 #include "ui/message_center/notification.h" | 20 #include "ui/message_center/notification.h" |
| 21 #include "ui/message_center/notification_types.h" | 21 #include "ui/message_center/notification_types.h" |
| 22 #include "ui/message_center/vector_icons.h" | 22 #include "ui/message_center/vector_icons.h" |
| 23 #include "ui/message_center/views/bounded_label.h" | 23 #include "ui/message_center/views/bounded_label.h" |
| 24 #include "ui/message_center/views/constants.h" | 24 #include "ui/message_center/views/constants.h" |
| 25 #include "ui/message_center/views/message_center_controller.h" | 25 #include "ui/message_center/views/message_center_controller.h" |
| 26 #include "ui/message_center/views/notification_header_view.h" | 26 #include "ui/message_center/views/notification_header_view.h" |
| 27 #include "ui/message_center/views/padded_button.h" | 27 #include "ui/message_center/views/padded_button.h" |
| 28 #include "ui/message_center/views/proportional_image_view.h" | 28 #include "ui/message_center/views/proportional_image_view.h" |
| 29 #include "ui/strings/grit/ui_strings.h" | 29 #include "ui/strings/grit/ui_strings.h" |
| 30 #include "ui/views/animation/ink_drop_highlight.h" | |
| 30 #include "ui/views/background.h" | 31 #include "ui/views/background.h" |
| 31 #include "ui/views/border.h" | 32 #include "ui/views/border.h" |
| 32 #include "ui/views/controls/button/label_button.h" | 33 #include "ui/views/controls/button/label_button.h" |
| 33 #include "ui/views/controls/image_view.h" | 34 #include "ui/views/controls/image_view.h" |
| 34 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
| 35 #include "ui/views/controls/progress_bar.h" | 36 #include "ui/views/controls/progress_bar.h" |
| 36 #include "ui/views/focus/focus_manager.h" | 37 #include "ui/views/focus/focus_manager.h" |
| 37 #include "ui/views/layout/box_layout.h" | 38 #include "ui/views/layout/box_layout.h" |
| 38 #include "ui/views/layout/fill_layout.h" | 39 #include "ui/views/layout/fill_layout.h" |
| 39 #include "ui/views/native_cursor.h" | 40 #include "ui/views/native_cursor.h" |
| 40 #include "ui/views/view_targeter.h" | 41 #include "ui/views/view_targeter.h" |
| 41 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
| 42 | 43 |
| 43 namespace message_center { | 44 namespace message_center { |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 // Dimensions. | 48 // Dimensions. |
| 48 constexpr gfx::Insets kContentRowPadding(4, 12, 12, 12); | 49 constexpr gfx::Insets kContentRowPadding(4, 12, 12, 12); |
| 49 constexpr gfx::Insets kActionsRowPadding(8, 8, 8, 8); | 50 constexpr gfx::Insets kActionsRowPadding(8, 8, 8, 8); |
| 50 constexpr int kActionsRowHorizontalSpacing = 8; | 51 constexpr int kActionsRowHorizontalSpacing = 8; |
| 51 constexpr gfx::Insets kImageContainerPadding(0, 12, 12, 12); | 52 constexpr gfx::Insets kImageContainerPadding(0, 12, 12, 12); |
| 53 constexpr gfx::Insets kActionButtonPadding(0, 12, 0, 12); | |
| 54 constexpr gfx::Size kActionButtonMinSize(88, 32); | |
| 52 | 55 |
| 53 // Foreground of small icon image. | 56 // Foreground of small icon image. |
| 54 constexpr SkColor kSmallImageBackgroundColor = SK_ColorWHITE; | 57 constexpr SkColor kSmallImageBackgroundColor = SK_ColorWHITE; |
| 55 // Background of small icon image. | 58 // Background of small icon image. |
| 56 const SkColor kSmallImageColor = SkColorSetRGB(0x43, 0x43, 0x43); | 59 const SkColor kSmallImageColor = SkColorSetRGB(0x43, 0x43, 0x43); |
| 57 // Background of inline actions area. | 60 // Background of inline actions area. |
| 58 const SkColor kActionsRowBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); | 61 const SkColor kActionsRowBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); |
| 62 // Base ink drop color of action buttons. | |
| 63 const SkColor kActionButtonInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0); | |
| 64 // Ripple ink drop opacity of action buttons. | |
| 65 const float kActionButtonInkDropRippleVisibleOpacity = 0.08f; | |
| 66 // Highlight (hover) ink drop opacity of action buttons. | |
| 67 const float kActionButtonInkDropHighlightVisibleOpacity = 0.08f; | |
| 68 // Text color of action button. | |
| 69 const SkColor kActionButtonTextColor = SkColorSetRGB(0x33, 0x67, 0xD6); | |
| 59 | 70 |
| 60 // Max number of lines for message_view_. | 71 // Max number of lines for message_view_. |
| 61 constexpr int kMaxLinesForMessageView = 1; | 72 constexpr int kMaxLinesForMessageView = 1; |
| 62 constexpr int kMaxLinesForExpandedMessageView = 4; | 73 constexpr int kMaxLinesForExpandedMessageView = 4; |
| 63 | 74 |
| 64 constexpr int kListNotificationOverflowIndicatorSpacing = 4; | 75 constexpr int kListNotificationOverflowIndicatorSpacing = 4; |
| 65 constexpr int kCompactTitleMessageViewSpacing = 12; | 76 constexpr int kCompactTitleMessageViewSpacing = 12; |
| 66 | 77 |
| 67 constexpr int kProgressBarHeight = 4; | 78 constexpr int kProgressBarHeight = 4; |
| 68 | 79 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 const int message_width = | 265 const int message_width = |
| 255 std::max(0, width() - title_width - kCompactTitleMessageViewSpacing); | 266 std::max(0, width() - title_width - kCompactTitleMessageViewSpacing); |
| 256 message = gfx::ElideText(message, font_list, message_width, gfx::ELIDE_TAIL); | 267 message = gfx::ElideText(message, font_list, message_width, gfx::ELIDE_TAIL); |
| 257 | 268 |
| 258 title_view_->SetText(title); | 269 title_view_->SetText(title); |
| 259 message_view_->SetText(message); | 270 message_view_->SetText(message); |
| 260 | 271 |
| 261 views::View::OnPaint(canvas); | 272 views::View::OnPaint(canvas); |
| 262 } | 273 } |
| 263 | 274 |
| 275 // NotificationButtonMD //////////////////////////////////////////////////////// | |
| 276 | |
| 277 // This class is needed in addition to LabelButton mainly becuase we want to set | |
| 278 // visible_opacity of InkDropHighlight. | |
| 279 class NotificationButtonMD : public views::LabelButton { | |
| 280 public: | |
| 281 NotificationButtonMD(views::ButtonListener* listener, | |
| 282 const base::string16& text); | |
| 283 ~NotificationButtonMD() override; | |
| 284 | |
| 285 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | |
| 286 const override; | |
| 287 | |
| 288 private: | |
| 289 DISALLOW_COPY_AND_ASSIGN(NotificationButtonMD); | |
| 290 }; | |
| 291 | |
| 292 NotificationButtonMD::NotificationButtonMD(views::ButtonListener* listener, | |
| 293 const base::string16& text) | |
| 294 : views::LabelButton(listener, text, views::style::CONTEXT_BUTTON_MD) { | |
| 295 SetInkDropMode(views::LabelButton::InkDropMode::ON); | |
| 296 set_has_ink_drop_action_on_click(true); | |
| 297 set_ink_drop_base_color(kActionButtonInkDropBaseColor); | |
| 298 set_ink_drop_visible_opacity(kActionButtonInkDropRippleVisibleOpacity); | |
| 299 SetEnabledTextColors(kActionButtonTextColor); | |
| 300 SetBorder(views::CreateEmptyBorder(kActionButtonPadding)); | |
| 301 SetMinSize(kActionButtonMinSize); | |
| 302 SetFocusForPlatform(); | |
| 303 } | |
| 304 | |
| 305 std::unique_ptr<views::InkDropHighlight> | |
| 306 NotificationButtonMD::CreateInkDropHighlight() const { | |
|
yoshiki
2017/06/29 04:35:03
Please move this below the dtor to match the order
tetsui
2017/06/29 04:39:33
Done.
| |
| 307 std::unique_ptr<views::InkDropHighlight> highlight = | |
| 308 views::LabelButton::CreateInkDropHighlight(); | |
| 309 highlight->set_visible_opacity(kActionButtonInkDropHighlightVisibleOpacity); | |
| 310 return highlight; | |
| 311 } | |
| 312 | |
| 313 NotificationButtonMD::~NotificationButtonMD() {} | |
|
yoshiki
2017/06/29 04:35:04
please specify the default destructor: "~Notificat
tetsui
2017/06/29 04:39:33
Done.
| |
| 314 | |
| 264 } // anonymous namespace | 315 } // anonymous namespace |
| 265 | 316 |
| 266 // //////////////////////////////////////////////////////////// | 317 // //////////////////////////////////////////////////////////// |
| 267 // NotificationViewMD | 318 // NotificationViewMD |
| 268 // //////////////////////////////////////////////////////////// | 319 // //////////////////////////////////////////////////////////// |
| 269 | 320 |
| 270 views::View* NotificationViewMD::TargetForRect(views::View* root, | 321 views::View* NotificationViewMD::TargetForRect(views::View* root, |
| 271 const gfx::Rect& rect) { | 322 const gfx::Rect& rect) { |
| 272 CHECK_EQ(root, this); | 323 CHECK_EQ(root, this); |
| 273 | 324 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 for (auto* item : action_buttons_) | 721 for (auto* item : action_buttons_) |
| 671 delete item; | 722 delete item; |
| 672 action_buttons_.clear(); | 723 action_buttons_.clear(); |
| 673 } | 724 } |
| 674 | 725 |
| 675 DCHECK_EQ(this, actions_row_->parent()); | 726 DCHECK_EQ(this, actions_row_->parent()); |
| 676 | 727 |
| 677 for (size_t i = 0; i < buttons.size(); ++i) { | 728 for (size_t i = 0; i < buttons.size(); ++i) { |
| 678 ButtonInfo button_info = buttons[i]; | 729 ButtonInfo button_info = buttons[i]; |
| 679 if (new_buttons) { | 730 if (new_buttons) { |
| 680 views::LabelButton* button = new views::LabelButton( | 731 NotificationButtonMD* button = |
| 681 this, button_info.title, views::style::CONTEXT_BUTTON_MD); | 732 new NotificationButtonMD(this, button_info.title); |
| 682 button->SetFocusForPlatform(); | |
| 683 action_buttons_.push_back(button); | 733 action_buttons_.push_back(button); |
| 684 actions_row_->AddChildView(button); | 734 actions_row_->AddChildView(button); |
| 685 } else { | 735 } else { |
| 686 action_buttons_[i]->SetText(button_info.title); | 736 action_buttons_[i]->SetText(button_info.title); |
| 687 action_buttons_[i]->SchedulePaint(); | 737 action_buttons_[i]->SchedulePaint(); |
| 688 action_buttons_[i]->Layout(); | 738 action_buttons_[i]->Layout(); |
| 689 } | 739 } |
| 690 } | 740 } |
| 691 | 741 |
| 692 if (new_buttons) { | 742 if (new_buttons) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 header_row_->expand_button()->HasFocus()) || | 823 header_row_->expand_button()->HasFocus()) || |
| 774 (header_row_->IsCloseButtonEnabled() && | 824 (header_row_->IsCloseButtonEnabled() && |
| 775 header_row_->close_button()->HasFocus()) || | 825 header_row_->close_button()->HasFocus()) || |
| 776 (header_row_->IsSettingsButtonEnabled() && | 826 (header_row_->IsSettingsButtonEnabled() && |
| 777 header_row_->settings_button()->HasFocus()); | 827 header_row_->settings_button()->HasFocus()); |
| 778 | 828 |
| 779 header_row_->SetControlButtonsVisible(target_visibility); | 829 header_row_->SetControlButtonsVisible(target_visibility); |
| 780 } | 830 } |
| 781 | 831 |
| 782 } // namespace message_center | 832 } // namespace message_center |
| OLD | NEW |