stacked_notification_bar.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2019 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_STACKED_NOTIFICATION_BAR_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_STACKED_NOTIFICATION_BAR_H_
  6. #include "ash/system/message_center/unified_message_center_view.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "ui/message_center/message_center_observer.h"
  9. #include "ui/views/view.h"
  10. namespace message_center {
  11. class Notification;
  12. } // namespace message_center
  13. namespace views {
  14. class BoxLayout;
  15. class Label;
  16. } // namespace views
  17. namespace ash {
  18. // The header shown above the notification list displaying the number of hidden
  19. // notifications. Has a dynamic list of icons which hide/show as notifications
  20. // are scrolled.
  21. class StackedNotificationBar : public views::View,
  22. public message_center::MessageCenterObserver {
  23. public:
  24. explicit StackedNotificationBar(
  25. UnifiedMessageCenterView* message_center_view);
  26. StackedNotificationBar(const StackedNotificationBar&) = delete;
  27. StackedNotificationBar& operator=(const StackedNotificationBar&) = delete;
  28. ~StackedNotificationBar() override;
  29. // Sets the icons and overflow count for hidden notifications as well as the
  30. // total/pinned notifications count. Returns true if the state of the bar
  31. // has changed.
  32. bool Update(int total_notification_count,
  33. int pinned_notification_count,
  34. std::vector<message_center::Notification*> stacked_notifications);
  35. // Sets the current animation state.
  36. void SetAnimationState(UnifiedMessageCenterAnimationState animation_state);
  37. // Set notification bar state to collapsed.
  38. void SetCollapsed();
  39. // Set notification bar state to expanded.
  40. void SetExpanded();
  41. // views::View:
  42. void OnPaint(gfx::Canvas* canvas) override;
  43. const char* GetClassName() const override;
  44. // message_center::MessageCenterObserver:
  45. void OnNotificationAdded(const std::string& id) override;
  46. void OnNotificationRemoved(const std::string& id, bool by_user) override;
  47. void OnNotificationUpdated(const std::string& id) override;
  48. private:
  49. class StackedNotificationBarIcon;
  50. friend class UnifiedMessageCenterViewTest;
  51. // Clean up icon view after it's removal animation is complete, adds an icon
  52. // for `notification` if needed. Called from a callback registered in
  53. // `ShiftIconsLeft()`.
  54. void OnIconAnimatedOut(std::string notification_id, views::View* icon);
  55. // Get the first icon which is `animating_out`.
  56. StackedNotificationBarIcon* GetFrontIcon(bool animating_out);
  57. // Search for a icon view in the stacked notification bar based on a provided
  58. // notification id.
  59. const StackedNotificationBarIcon* GetIconFromId(const std::string& id) const;
  60. // Set visibility based on number of stacked notifications or animation state.
  61. void UpdateVisibility();
  62. // Add a stacked notification icon to the front or back of the row.
  63. void AddNotificationIcon(message_center::Notification* notification,
  64. bool at_front);
  65. // Move all icons left when notifications are scrolled up.
  66. void ShiftIconsLeft(
  67. std::vector<message_center::Notification*> stacked_notifications);
  68. // Move icons right to make space for additional icons when notifications are
  69. // scrolled down.
  70. void ShiftIconsRight(
  71. std::vector<message_center::Notification*> stacked_notifications);
  72. // Update state for stacked notification icons and move them as necessary.
  73. void UpdateStackedNotifications(
  74. std::vector<message_center::Notification*> stacked_notifications);
  75. int total_notification_count_ = 0;
  76. int pinned_notification_count_ = 0;
  77. int stacked_notification_count_ = 0;
  78. UnifiedMessageCenterAnimationState animation_state_ =
  79. UnifiedMessageCenterAnimationState::IDLE;
  80. UnifiedMessageCenterView* const message_center_view_;
  81. views::View* notification_icons_container_;
  82. views::Label* const count_label_;
  83. views::View* const spacer_;
  84. views::Button* const clear_all_button_;
  85. views::Button* const expand_all_button_;
  86. views::BoxLayout* const layout_manager_;
  87. base::WeakPtrFactory<StackedNotificationBar> weak_ptr_factory_{this};
  88. };
  89. } // namespace ash
  90. #endif // ASH_SYSTEM_MESSAGE_CENTER_STACKED_NOTIFICATION_BAR_H_