unified_message_center_bubble.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_UNIFIED_MESSAGE_CENTER_BUBBLE_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_UNIFIED_MESSAGE_CENTER_BUBBLE_H_
  6. #include "ash/system/screen_layout_observer.h"
  7. #include "ash/system/tray/time_to_click_recorder.h"
  8. #include "ash/system/tray/tray_bubble_base.h"
  9. #include "ash/system/tray/tray_bubble_view.h"
  10. #include "ui/views/view_observer.h"
  11. #include "ui/views/widget/widget_observer.h"
  12. namespace views {
  13. class Widget;
  14. } // namespace views
  15. namespace ash {
  16. class UnifiedSystemTray;
  17. class UnifiedMessageCenterView;
  18. class SystemShadow;
  19. // Manages the bubble that contains UnifiedMessageCenterView.
  20. // Shows the bubble on `ShowBubble()`, and closes the bubble on the destructor.
  21. class ASH_EXPORT UnifiedMessageCenterBubble
  22. : public ScreenLayoutObserver,
  23. public TrayBubbleBase,
  24. public TrayBubbleView::Delegate,
  25. public TimeToClickRecorder::Delegate,
  26. public views::ViewObserver {
  27. public:
  28. explicit UnifiedMessageCenterBubble(UnifiedSystemTray* tray);
  29. UnifiedMessageCenterBubble(const UnifiedMessageCenterBubble&) = delete;
  30. UnifiedMessageCenterBubble& operator=(const UnifiedMessageCenterBubble&) =
  31. delete;
  32. ~UnifiedMessageCenterBubble() override;
  33. // Return the bounds of the bubble in the screen.
  34. gfx::Rect GetBoundsInScreen() const;
  35. // We need the code to show the bubble explicitly separated from the
  36. // contructor. This is to prevent trigerring the TrayEventFilter from within
  37. // the constructor. Doing so can cause a crash when the TrayEventFilter tries
  38. // to reference the message center bubble before it is fully instantiated.
  39. void ShowBubble();
  40. // Collapse the bubble to only have the notification bar visible.
  41. void CollapseMessageCenter();
  42. // Expand the bubble to show all notifications.
  43. void ExpandMessageCenter();
  44. // Move the message center bubble to keep it on top of the quick settings
  45. // widget whenever the quick settings widget is resized.
  46. void UpdatePosition();
  47. // Inform `UnifiedMessageCenterView` of focus being acquired. The oldest
  48. // notification should be focused if `reverse` is `true`. Otherwise, if
  49. // `reverse` is `false`, the newest notification should be focused.
  50. void FocusEntered(bool reverse);
  51. // Relinquish focus and transfer it to the quick settings widget.
  52. bool FocusOut(bool reverse);
  53. // Activate quick settings bubble. Used when the message center is going
  54. // invisible.
  55. void ActivateQuickSettingsBubble();
  56. // Returns true if notifications are shown.
  57. bool IsMessageCenterVisible();
  58. // Returns true if only StackedNotificationBar is visible.
  59. bool IsMessageCenterCollapsed();
  60. // TrayBubbleBase:
  61. TrayBackgroundView* GetTray() const override;
  62. TrayBubbleView* GetBubbleView() const override;
  63. views::Widget* GetBubbleWidget() const override;
  64. // TrayBubbleView::Delegate:
  65. std::u16string GetAccessibleNameForBubble() override;
  66. bool ShouldEnableExtraKeyboardAccessibility() override;
  67. // views::ViewObserver:
  68. void OnViewPreferredSizeChanged(views::View* observed_view) override;
  69. void OnViewVisibilityChanged(views::View* observed_view,
  70. views::View* starting_view) override;
  71. // views::WidgetObserver:
  72. void OnWidgetDestroying(views::Widget* widget) override;
  73. void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
  74. // ScreenLayoutObserver:
  75. void OnDisplayConfigurationChanged() override;
  76. UnifiedMessageCenterView* message_center_view() {
  77. return message_center_view_;
  78. }
  79. private:
  80. class Border;
  81. // Check if the message center bubble should be collapsed or expanded.
  82. void UpdateBubbleState();
  83. // Calculate the height usable for the bubble.
  84. int CalculateAvailableHeight();
  85. // TimeToClickRecorder::Delegate:
  86. void RecordTimeToClick() override;
  87. UnifiedSystemTray* const tray_;
  88. std::unique_ptr<Border> border_;
  89. std::unique_ptr<SystemShadow> shadow_;
  90. views::Widget* bubble_widget_ = nullptr;
  91. TrayBubbleView* bubble_view_ = nullptr;
  92. UnifiedMessageCenterView* message_center_view_ = nullptr;
  93. std::unique_ptr<TimeToClickRecorder> time_to_click_recorder_;
  94. };
  95. } // namespace ash
  96. #endif // ASH_SYSTEM_MESSAGE_CENTER_UNIFIED_MESSAGE_CENTER_BUBBLE_H_