system_nudge_controller.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_SYSTEM_TRAY_SYSTEM_NUDGE_CONTROLLER_H_
  5. #define ASH_SYSTEM_TRAY_SYSTEM_NUDGE_CONTROLLER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/timer/timer.h"
  10. #include "ui/compositor/layer_animation_observer.h"
  11. namespace ash {
  12. class SystemNudge;
  13. // An abstract class which displays a contextual system nudge and fades it in
  14. // and out after a short period of time. While nudge behavior is covered by this
  15. // abstract class, Subclasses must implement CreateSystemNudge() in order to
  16. // create a custom label and icon for their nudge's UI.
  17. // TODO(crbug.com/1232525): Duration and positioning should be configurable.
  18. class ASH_EXPORT SystemNudgeController {
  19. public:
  20. SystemNudgeController();
  21. SystemNudgeController(const SystemNudgeController&) = delete;
  22. SystemNudgeController& operator=(const SystemNudgeController&) = delete;
  23. virtual ~SystemNudgeController();
  24. // Shows the nudge widget.
  25. void ShowNudge();
  26. // Ensure the destruction of a nudge that is animating.
  27. void ForceCloseAnimatingNudge();
  28. // Test method for triggering the nudge timer to hide.
  29. void FireHideNudgeTimerForTesting();
  30. // Get the system nudge for testing purpose.
  31. SystemNudge* GetSystemNudgeForTesting() { return nudge_.get(); }
  32. protected:
  33. // Concrete subclasses must implement this method to return a
  34. // SystemNudge that creates a label and specifies an icon specific
  35. // to the nudge.
  36. virtual std::unique_ptr<SystemNudge> CreateSystemNudge() = 0;
  37. // Hides the nudge widget.
  38. void HideNudge();
  39. private:
  40. // Begins the animation for fading in or fading out the nudge.
  41. void StartFadeAnimation(bool show);
  42. // Contextual nudge which shows a view.
  43. std::unique_ptr<SystemNudge> nudge_;
  44. // Timer to hide the nudge.
  45. base::OneShotTimer hide_nudge_timer_;
  46. std::unique_ptr<ui::ImplicitAnimationObserver> hide_nudge_animation_observer_;
  47. base::WeakPtrFactory<SystemNudgeController> weak_ptr_factory_{this};
  48. };
  49. } // namespace ash
  50. #endif // ASH_SYSTEM_TRAY_SYSTEM_NUDGE_CONTROLLER_H_