notification_menu_view.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright 2018 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_APP_MENU_NOTIFICATION_MENU_VIEW_H_
  5. #define ASH_APP_MENU_NOTIFICATION_MENU_VIEW_H_
  6. #include <deque>
  7. #include <string>
  8. #include "ash/app_menu/app_menu_export.h"
  9. #include "ui/views/view.h"
  10. namespace message_center {
  11. class Notification;
  12. }
  13. namespace views {
  14. class MenuSeparator;
  15. class SlideOutControllerDelegate;
  16. }
  17. namespace ash {
  18. class NotificationMenuHeaderView;
  19. class NotificationOverflowView;
  20. class NotificationItemView;
  21. // A view inserted into a container MenuItemView which shows a
  22. // NotificationItemView and a NotificationMenuHeaderView.
  23. class APP_MENU_EXPORT NotificationMenuView : public views::View {
  24. public:
  25. // API for child views to interact with the NotificationMenuController.
  26. class Delegate {
  27. public:
  28. virtual ~Delegate() = default;
  29. // Activates the notification corresponding with |notification_id| and
  30. // closes the menu.
  31. virtual void ActivateNotificationAndClose(
  32. const std::string& notification_id) = 0;
  33. // Called when an overflow view is added or remove.
  34. virtual void OnOverflowAddedOrRemoved() = 0;
  35. };
  36. NotificationMenuView(
  37. Delegate* notification_item_view_delegate,
  38. views::SlideOutControllerDelegate* slide_out_controller_delegate,
  39. const std::string& app_id);
  40. NotificationMenuView(const NotificationMenuView&) = delete;
  41. NotificationMenuView& operator=(const NotificationMenuView&) = delete;
  42. ~NotificationMenuView() override;
  43. // views::View:
  44. gfx::Size CalculatePreferredSize() const override;
  45. void Layout() override;
  46. // Whether |notifications_for_this_app_| is empty.
  47. bool IsEmpty() const;
  48. // Adds |notification| as a NotificationItemView, displacing the currently
  49. // displayed NotificationItemView, if it exists.
  50. void AddNotificationItemView(
  51. const message_center::Notification& notification);
  52. // Updates the NotificationItemView corresponding to |notification|, replacing
  53. // the contents if they have changed.
  54. void UpdateNotificationItemView(
  55. const message_center::Notification& notification);
  56. // Removes the NotificationItemView associated with |notification_id| and
  57. // if it is the currently displayed NotificationItemView, replaces it with
  58. // the next one if available. Also removes the notification from
  59. // |overflow_view_| if it exists there.
  60. void OnNotificationRemoved(const std::string& notification_id);
  61. // Gets the slide out layer, used to move the displayed NotificationItemView.
  62. ui::Layer* GetSlideOutLayer();
  63. // Returns the currently-visible notification, or null if none.
  64. const NotificationItemView* GetDisplayedNotificationItemView() const;
  65. NotificationItemView* GetDisplayedNotificationItemView() {
  66. return const_cast<NotificationItemView*>(
  67. static_cast<const NotificationMenuView*>(this)
  68. ->GetDisplayedNotificationItemView());
  69. }
  70. // Gets the notification id of the displayed NotificationItemView.
  71. const std::string& GetDisplayedNotificationID() const;
  72. private:
  73. friend class NotificationMenuViewTestAPI;
  74. using NotificationItemViews = std::deque<NotificationItemView*>;
  75. // Returns an iterator to the notification matching the supplied ID, or
  76. // notification_item_views_.end() if none.
  77. NotificationItemViews::iterator NotificationIterForId(const std::string& id);
  78. // Identifies the app for this menu.
  79. const std::string app_id_;
  80. // Owned by AppMenuModelAdapter.
  81. NotificationMenuView::Delegate* const notification_item_view_delegate_;
  82. // Owned by AppMenuModelAdapter.
  83. views::SlideOutControllerDelegate* const slide_out_controller_delegate_;
  84. // The deque of NotificationItemViews. The front item in the deque is the view
  85. // which is shown.
  86. NotificationItemViews notification_item_views_;
  87. // A double separator used to distinguish notifications from context menu
  88. // options. Owned by views hierarchy.
  89. views::MenuSeparator* double_separator_;
  90. // Holds the header and counter texts. Owned by views hierarchy.
  91. NotificationMenuHeaderView* header_view_;
  92. // A view that shows icons of notifications for this app that are not being
  93. // shown.
  94. NotificationOverflowView* overflow_view_ = nullptr;
  95. };
  96. } // namespace ash
  97. #endif // ASH_APP_MENU_NOTIFICATION_MENU_VIEW_H_