fullscreen_notification_bubble.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_SESSION_FULLSCREEN_NOTIFICATION_BUBBLE_H_
  5. #define ASH_SESSION_FULLSCREEN_NOTIFICATION_BUBBLE_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/wm/window_state.h"
  9. #include "ash/wm/window_state_observer.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/scoped_observation.h"
  12. #include "ui/aura/window.h"
  13. #include "ui/aura/window_observer.h"
  14. class SubtleNotificationView;
  15. namespace base {
  16. class OneShotTimer;
  17. }
  18. namespace gfx {
  19. class Rect;
  20. }
  21. namespace views {
  22. class Widget;
  23. }
  24. namespace ash {
  25. // A notification bubble shown when the device returns from sleep, low
  26. // brightness or the lock screen to remind the user that full screen mode is
  27. // active.
  28. class ASH_EXPORT FullscreenNotificationBubble : public aura::WindowObserver,
  29. public WindowStateObserver {
  30. public:
  31. FullscreenNotificationBubble();
  32. FullscreenNotificationBubble(const FullscreenNotificationBubble&) = delete;
  33. FullscreenNotificationBubble& operator=(const FullscreenNotificationBubble&) =
  34. delete;
  35. ~FullscreenNotificationBubble() override;
  36. void ShowForWindowState(WindowState* window_state);
  37. // Returns the underlying widget for testing purposes.
  38. views::Widget* widget_for_test() { return widget_; }
  39. private:
  40. // aura::WindowObserver:
  41. void OnWindowDestroying(aura::Window* window) override;
  42. // WindowStateObserver:
  43. void OnPreWindowStateTypeChange(WindowState* window_state,
  44. chromeos::WindowStateType old_type) override;
  45. void Show();
  46. void Hide();
  47. gfx::Rect GetBubbleBounds();
  48. // The contents of the widget.
  49. SubtleNotificationView* view_ = nullptr;
  50. // The widget containing the bubble.
  51. views::Widget* widget_ = nullptr;
  52. // A timer to auto-dismiss the bubble after a short period of time.
  53. std::unique_ptr<base::OneShotTimer> timer_;
  54. base::ScopedObservation<aura::Window, aura::WindowObserver>
  55. window_observation_{this};
  56. base::ScopedObservation<ash::WindowState, ash::WindowStateObserver>
  57. window_state_observation_{this};
  58. base::WeakPtrFactory<FullscreenNotificationBubble> weak_ptr_factory_{this};
  59. };
  60. } // namespace ash
  61. #endif // ASH_SESSION_FULLSCREEN_NOTIFICATION_BUBBLE_H_