autozoom_toast_controller.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2022 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_CAMERA_AUTOZOOM_TOAST_CONTROLLER_H_
  5. #define ASH_SYSTEM_CAMERA_AUTOZOOM_TOAST_CONTROLLER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/system/camera/autozoom_observer.h"
  8. #include "ash/system/camera/autozoom_toast_view.h"
  9. #include "ash/system/tray/tray_bubble_view.h"
  10. #include "base/timer/timer.h"
  11. namespace ash {
  12. class UnifiedSystemTray;
  13. // Controller class for the autozoom toast, which is shown when the autozoom is
  14. // on and camera is opened.
  15. class ASH_EXPORT AutozoomToastController : public TrayBubbleView::Delegate,
  16. public AutozoomObserver {
  17. public:
  18. // The Delegate interface handles adding and removing observers on behalf of
  19. // AutozoomToastController. This is used for unit tests.
  20. class ASH_EXPORT Delegate {
  21. public:
  22. Delegate();
  23. Delegate(const Delegate&) = delete;
  24. Delegate& operator=(const Delegate&) = delete;
  25. virtual ~Delegate() = default;
  26. virtual void AddAutozoomObserver(AutozoomObserver* observer);
  27. virtual void RemoveAutozoomObserver(AutozoomObserver* observer);
  28. virtual bool IsAutozoomEnabled();
  29. virtual bool IsAutozoomControlEnabled();
  30. };
  31. AutozoomToastController(UnifiedSystemTray* tray,
  32. std::unique_ptr<Delegate> delegate);
  33. AutozoomToastController(AutozoomToastController&) = delete;
  34. AutozoomToastController operator=(AutozoomToastController&) = delete;
  35. ~AutozoomToastController() override;
  36. // Shows the toast explicitly. Normally this is shown when there's a new
  37. // active camera client and autozoom is enabled.
  38. void ShowToast();
  39. // Hides the toast if it is shown. Normally, it times out and automatically
  40. // closes.
  41. void HideToast();
  42. // Stops the timer to autoclose the toast.
  43. void StopAutocloseTimer();
  44. // Triggers a timer to automatically close the toast.
  45. void StartAutoCloseTimer();
  46. protected:
  47. views::Widget* bubble_widget_for_test() { return bubble_widget_; }
  48. private:
  49. friend class AutozoomToastControllerTest;
  50. // AutozoomObserver:
  51. void OnAutozoomStateChanged(
  52. cros::mojom::CameraAutoFramingState state) override;
  53. void OnAutozoomControlEnabledChanged(bool enabled) override;
  54. // Updates the toast UI with the current privacy screen state.
  55. void UpdateToastView();
  56. // TrayBubbleView::Delegate:
  57. void BubbleViewDestroyed() override;
  58. void OnMouseEnteredView() override;
  59. void OnMouseExitedView() override;
  60. std::u16string GetAccessibleNameForBubble() override;
  61. UnifiedSystemTray* const tray_;
  62. TrayBubbleView* bubble_view_ = nullptr;
  63. views::Widget* bubble_widget_ = nullptr;
  64. AutozoomToastView* toast_view_ = nullptr;
  65. bool mouse_hovered_ = false;
  66. base::OneShotTimer close_timer_;
  67. const std::unique_ptr<Delegate> delegate_;
  68. };
  69. } // namespace ash
  70. #endif // ASH_SYSTEM_CAMERA_AUTOZOOM_TOAST_CONTROLLER_H_