swipe_home_to_overview_controller.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_SHELF_SWIPE_HOME_TO_OVERVIEW_CONTROLLER_H_
  5. #define ASH_SHELF_SWIPE_HOME_TO_OVERVIEW_CONTROLLER_H_
  6. #include "ash/ash_export.h"
  7. #include "base/callback_helpers.h"
  8. #include "base/timer/timer.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. #include "ui/gfx/geometry/point_f.h"
  11. namespace ash {
  12. // Used by ShelfLayoutManager to handle gesture drag events while the
  13. // handler is in kSwipeHomeToOverview mode. The controller handles swipe gesture
  14. // from hot seat on the home screen. The gesture, if detected, transitions the
  15. // home screen to the overview UI.
  16. class ASH_EXPORT SwipeHomeToOverviewController {
  17. public:
  18. // The minimum vertical distance between gesture location and the bottom of
  19. // work area for the gesture to trigger transition to overview.
  20. static constexpr int kVerticalThresholdForOverviewTransition = 56;
  21. // The max pointer velocity at which home transitions to overview.
  22. static constexpr int kMovementVelocityThreshold = 10;
  23. // The constructor that uses default tick clock for
  24. // |overview_transition_timer_|. Should be preferred outside of test
  25. // environment.
  26. explicit SwipeHomeToOverviewController(int64_t display_id);
  27. // |display_id| - the ID of display on which the gesture started.
  28. // |tick_clock| - the tick clock that should be used by
  29. // |overview_transition_timer_|.
  30. SwipeHomeToOverviewController(int64_t display_id,
  31. const base::TickClock* tick_clock);
  32. SwipeHomeToOverviewController(const SwipeHomeToOverviewController&) = delete;
  33. SwipeHomeToOverviewController& operator=(
  34. const SwipeHomeToOverviewController&) = delete;
  35. ~SwipeHomeToOverviewController();
  36. // Called during swiping up on the shelf.
  37. void Drag(const gfx::PointF& location_in_screen,
  38. float scroll_x,
  39. float scroll_y);
  40. void EndDrag(const gfx::PointF& location_in_screen,
  41. absl::optional<float> velocity_y);
  42. void CancelDrag();
  43. base::OneShotTimer* overview_transition_timer_for_testing() {
  44. return &overview_transition_timer_;
  45. }
  46. private:
  47. enum class State { kInitial, kTrackingDrag, kFinished };
  48. // Starts |overview_transition_timer_|. No-op if the timer is already running.
  49. void ScheduleFinalizeDragAndShowOverview();
  50. // Finalizes the drag sequence, and starts overview session.
  51. // Note that the controller might keep getting drag updates as the user keeps
  52. // moving the pointer - those events will be ignored.
  53. void FinalizeDragAndShowOverview();
  54. // Finalizes the drag sequence by staying on the home screen.
  55. // |go_back| - if the gesture should invoke home screen back action.
  56. void FinalizeDragAndStayOnHomeScreen(bool go_back);
  57. const int64_t display_id_;
  58. State state_ = State::kInitial;
  59. // The y in-screen coordinate at which drag, when stopped, will cause
  60. // transition to overview. Overview session will be started iff the drag stops
  61. // above this line.
  62. // The value is set when the controller transitions to kStarted state.
  63. int overview_transition_threshold_y_ = 0;
  64. // Home screen is scaled down depending on gesture vertical distance from the
  65. // shelf - this is the target gesture vertical location at which home screen
  66. // should be scaled by the target scale factor.
  67. int scaling_threshold_y_ = 0;
  68. // The timer to run FinalizeDragAndShowOverview().
  69. base::OneShotTimer overview_transition_timer_;
  70. // ScopedClosureRunner that while in scope disables background blur in home
  71. // screen. It will be set during home screen drag with a goal of improving
  72. // overall drag performance.
  73. absl::optional<base::ScopedClosureRunner> home_screen_blur_disabler_;
  74. };
  75. } // namespace ash
  76. #endif // ASH_SHELF_SWIPE_HOME_TO_OVERVIEW_CONTROLLER_H_