home_to_overview_nudge_controller.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2020 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_SHELF_HOME_TO_OVERVIEW_NUDGE_CONTROLLER_H_
  5. #define ASH_SHELF_HOME_TO_OVERVIEW_NUDGE_CONTROLLER_H_
  6. #include "ash/ash_export.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "base/scoped_multi_source_observation.h"
  9. #include "base/timer/timer.h"
  10. #include "ui/views/widget/widget.h"
  11. #include "ui/views/widget/widget_observer.h"
  12. namespace ash {
  13. class ContextualNudge;
  14. class HotseatWidget;
  15. class ASH_EXPORT HomeToOverviewNudgeController : views::WidgetObserver {
  16. public:
  17. // Indicates the reason the nudge is being hidden. Used to determine the exact
  18. // transition to use when hiding the nudge.
  19. enum class HideTransition { kShelfStateChange, kUserTap, kNudgeTimeout };
  20. explicit HomeToOverviewNudgeController(HotseatWidget* hotseat_widget);
  21. HomeToOverviewNudgeController(const HomeToOverviewNudgeController& other) =
  22. delete;
  23. ~HomeToOverviewNudgeController() override;
  24. HomeToOverviewNudgeController& operator=(
  25. const HomeToOverviewNudgeController& other) = delete;
  26. // Sets whether the home to overview nudge can be shown for the current shelf
  27. // state. If nudge is allowed, controller may show the nudge (if required). If
  28. // the nudge is not allowed, the nudge will be hidden if currently shown.
  29. void SetNudgeAllowedForCurrentShelf(bool allowed);
  30. // views::WidgetObserver:
  31. void OnWidgetDestroying(views::Widget* widget) override;
  32. void OnWidgetBoundsChanged(views::Widget* widget,
  33. const gfx::Rect& new_bounds) override;
  34. ContextualNudge* nudge_for_testing() { return nudge_; }
  35. bool HasShowTimerForTesting() const;
  36. void FireShowTimerForTesting();
  37. bool HasHideTimerForTesting() const;
  38. void FireHideTimerForTesting();
  39. private:
  40. // Creates and shows the nudge bubble, schedules showing animation for the
  41. // nudge and hotseat widgets, and schedules nudge hide timer as needed.
  42. void ShowNudge();
  43. // Sets up hotseat and nudge wdget animation for hiding the nudge, and closes
  44. // the nudge widget when the animation finishes.
  45. void HideNudge(HideTransition transition);
  46. // Updates the nudge anchor bounds for the current hotseat and shelf bounds.
  47. void UpdateNudgeAnchorBounds();
  48. // Passed to |nudge_| as its tap gesture handler.
  49. void HandleNudgeTap();
  50. bool nudge_allowed_for_shelf_state_ = false;
  51. HotseatWidget* const hotseat_widget_;
  52. ContextualNudge* nudge_ = nullptr;
  53. base::OneShotTimer nudge_show_timer_;
  54. base::OneShotTimer nudge_hide_timer_;
  55. // Observes hotseat widget to detect the hotseat bounds changes, and the
  56. // nudge widget to detect that the widget is being destroyed.
  57. base::ScopedMultiSourceObservation<views::Widget, views::WidgetObserver>
  58. widget_observations_{this};
  59. base::WeakPtrFactory<HomeToOverviewNudgeController> weak_factory_{this};
  60. };
  61. } // namespace ash
  62. #endif // ASH_SHELF_HOME_TO_OVERVIEW_NUDGE_CONTROLLER_H_