ash_message_popup_collection.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2014 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_MESSAGE_POPUP_COLLECTION_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_ASH_MESSAGE_POPUP_COLLECTION_H_
  6. #include <stdint.h>
  7. #include "ash/ash_export.h"
  8. #include "ash/public/cpp/shelf_types.h"
  9. #include "ash/shelf/shelf_observer.h"
  10. #include "ash/shell_observer.h"
  11. #include "ui/compositor/throughput_tracker.h"
  12. #include "ui/display/display_observer.h"
  13. #include "ui/gfx/geometry/rect.h"
  14. #include "ui/message_center/views/message_popup_collection.h"
  15. #include "ui/message_center/views/message_view.h"
  16. #include "ui/views/widget/widget_observer.h"
  17. namespace display {
  18. class Screen;
  19. }
  20. namespace ash {
  21. class AshMessagePopupCollectionTest;
  22. class Shelf;
  23. // The MessagePopupCollection subclass for Ash. It needs to handle alignment of
  24. // the shelf and its autohide state.
  25. class ASH_EXPORT AshMessagePopupCollection
  26. : public message_center::MessagePopupCollection,
  27. public ShelfObserver,
  28. public display::DisplayObserver,
  29. public views::WidgetObserver,
  30. public message_center::MessageView::Observer {
  31. public:
  32. // The name that will set for the message popup widget in
  33. // ConfigureWidgetInitParamsForContainer(), and that can be used to identify a
  34. // message popup widget.
  35. static const char kMessagePopupWidgetName[];
  36. explicit AshMessagePopupCollection(Shelf* shelf);
  37. AshMessagePopupCollection(const AshMessagePopupCollection&) = delete;
  38. AshMessagePopupCollection& operator=(const AshMessagePopupCollection&) =
  39. delete;
  40. ~AshMessagePopupCollection() override;
  41. // Start observing the system.
  42. void StartObserving(display::Screen* screen, const display::Display& display);
  43. // Sets the current height of the system tray bubble (or legacy notification
  44. // bubble) so that notification toasts can avoid it.
  45. void SetTrayBubbleHeight(int height);
  46. // message_center::MessagePopupCollection:
  47. int GetToastOriginX(const gfx::Rect& toast_bounds) const override;
  48. int GetBaseline() const override;
  49. gfx::Rect GetWorkArea() const override;
  50. bool IsTopDown() const override;
  51. bool IsFromLeft() const override;
  52. bool RecomputeAlignment(const display::Display& display) override;
  53. void ConfigureWidgetInitParamsForContainer(
  54. views::Widget* widget,
  55. views::Widget::InitParams* init_params) override;
  56. bool IsPrimaryDisplayForNotification() const override;
  57. bool BlockForMixedFullscreen(
  58. const message_center::Notification& notification) const override;
  59. void NotifyPopupAdded(message_center::MessagePopupView* popup) override;
  60. void NotifyPopupClosed(message_center::MessagePopupView* popup) override;
  61. void AnimationStarted() override;
  62. void AnimationFinished() override;
  63. message_center::MessagePopupView* CreatePopup(
  64. const message_center::Notification& notification) override;
  65. // Returns the current tray bubble height or 0 if there is no bubble.
  66. int tray_bubble_height_for_test() const { return tray_bubble_height_; }
  67. private:
  68. friend class AshMessagePopupCollectionTest;
  69. friend class NotificationGroupingControllerTest;
  70. // message_center::MessageView::Observer:
  71. void OnSlideOut(const std::string& notification_id) override;
  72. void OnCloseButtonPressed(const std::string& notification_id) override;
  73. void OnSettingsButtonPressed(const std::string& notification_id) override;
  74. void OnSnoozeButtonPressed(const std::string& notification_id) override;
  75. // Get the current alignment of the shelf.
  76. ShelfAlignment GetAlignment() const;
  77. // Utility function to get the display which should be care about.
  78. display::Display GetCurrentDisplay() const;
  79. // Compute the new work area.
  80. void UpdateWorkArea();
  81. // ShelfObserver:
  82. void OnShelfWorkAreaInsetsChanged() override;
  83. void OnHotseatStateChanged(HotseatState old_state,
  84. HotseatState new_state) override;
  85. // display::DisplayObserver:
  86. void OnDisplayMetricsChanged(const display::Display& display,
  87. uint32_t metrics) override;
  88. // views::WidgetObserver:
  89. void OnWidgetClosing(views::Widget* widget) override;
  90. void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
  91. absl::optional<display::ScopedDisplayObserver> display_observer_;
  92. display::Screen* screen_;
  93. gfx::Rect work_area_;
  94. Shelf* shelf_;
  95. int tray_bubble_height_;
  96. std::set<views::Widget*> tracked_widgets_;
  97. // Tracks the smoothness of popup animation.
  98. absl::optional<ui::ThroughputTracker> animation_tracker_;
  99. // Keeps track of number of items that are animating. This is used when we
  100. // have more than one popup appear in the screen and different animations are
  101. // performed at the same time (fade in, move up, etc.), making sure that we
  102. // stop the throughput tracker only when all of these animations are finished.
  103. int popups_animating_ = 0;
  104. // Keeps track the last pop up added, used by throughout tracker. We only
  105. // record smoothness when this variable is in scope.
  106. message_center::MessagePopupView* last_pop_up_added_ = nullptr;
  107. };
  108. } // namespace ash
  109. #endif // ASH_SYSTEM_MESSAGE_CENTER_ASH_MESSAGE_POPUP_COLLECTION_H_