ash_notification_expand_button.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2021 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. #ifndef ASH_SYSTEM_MESSAGE_CENTER_ASH_NOTIFICATION_EXPAND_BUTTON_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_ASH_NOTIFICATION_EXPAND_BUTTON_H_
  6. #include "base/memory/weak_ptr.h"
  7. #include "ui/views/controls/button/button.h"
  8. #include "ui/views/metadata/view_factory.h"
  9. namespace views {
  10. class Label;
  11. class ImageView;
  12. } // namespace views
  13. namespace ash {
  14. // Customized expand button for ash notification view. Used for grouped as
  15. // well as singular notifications.
  16. class AshNotificationExpandButton : public views::Button {
  17. public:
  18. METADATA_HEADER(AshNotificationExpandButton);
  19. explicit AshNotificationExpandButton(
  20. PressedCallback callback = PressedCallback());
  21. AshNotificationExpandButton(const AshNotificationExpandButton&) = delete;
  22. AshNotificationExpandButton& operator=(const AshNotificationExpandButton&) =
  23. delete;
  24. ~AshNotificationExpandButton() override;
  25. // Change the expanded state. The icon will change.
  26. void SetExpanded(bool expanded);
  27. // Whether the label displaying the number of notifications in a grouped
  28. // notification needs to be displayed.
  29. bool ShouldShowLabel() const;
  30. // Update the count of total grouped notifications in the parent view and
  31. // update the text for the label accordingly.
  32. void UpdateGroupedNotificationsCount(int count);
  33. // Generate the icons used for chevron in the expanded and collapsed state.
  34. void UpdateIcons();
  35. // Perform expand/collapse and converting from single to group notification
  36. // animation. Both of these include bounds change and fade in/out `label_`.
  37. void AnimateExpandCollapse();
  38. void AnimateSingleToGroupNotification();
  39. // views::Button:
  40. void OnThemeChanged() override;
  41. gfx::Size CalculatePreferredSize() const override;
  42. void set_label_fading_out(bool label_fading_out) {
  43. label_fading_out_ = label_fading_out;
  44. }
  45. void set_previous_bounds(gfx::Rect previous_bounds) {
  46. previous_bounds_ = previous_bounds;
  47. }
  48. views::Label* label_for_test() { return label_; }
  49. private:
  50. // Bounds change animation happens during expand/collapse and converting from
  51. // single to group animation.
  52. void AnimateBoundsChange(int duration_in_ms,
  53. gfx::Tween::Type tween_type,
  54. const std::string& animation_histogram_name);
  55. // Owned by views hierarchy.
  56. views::Label* label_;
  57. views::ImageView* image_;
  58. // Cached icons used to display the chevron in the button.
  59. gfx::ImageSkia expanded_image_;
  60. gfx::ImageSkia collapsed_image_;
  61. // Used in layer bounds animation.
  62. gfx::Rect previous_bounds_;
  63. // Total number of grouped child notifications in this button's parent view.
  64. int total_grouped_notifications_ = 0;
  65. // The expand state of the button.
  66. bool expanded_ = false;
  67. // True if `label_` is in its fade out animation.
  68. bool label_fading_out_ = false;
  69. base::WeakPtrFactory<AshNotificationExpandButton> weak_factory_{this};
  70. };
  71. BEGIN_VIEW_BUILDER(/*no export*/, AshNotificationExpandButton, views::Button)
  72. END_VIEW_BUILDER
  73. } // namespace ash
  74. DEFINE_VIEW_BUILDER(/* no export */, ash::AshNotificationExpandButton)
  75. #endif // ASH_SYSTEM_MESSAGE_CENTER_ASH_NOTIFICATION_EXPAND_BUTTON_H_