File: swipe_home_to_overview_controller.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (95 lines) | stat: -rw-r--r-- 3,599 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SHELF_SWIPE_HOME_TO_OVERVIEW_CONTROLLER_H_
#define ASH_SHELF_SWIPE_HOME_TO_OVERVIEW_CONTROLLER_H_

#include <optional>

#include "ash/ash_export.h"
#include "base/functional/callback_helpers.h"
#include "base/timer/timer.h"
#include "ui/gfx/geometry/point_f.h"

namespace ash {

// Used by ShelfLayoutManager to handle gesture drag events while the
// handler is in kSwipeHomeToOverview mode. The controller handles swipe gesture
// from hot seat on the home screen. The gesture, if detected, transitions the
// home screen to the overview UI.
class ASH_EXPORT SwipeHomeToOverviewController {
 public:
  // The minimum vertical distance between gesture location and the bottom of
  // work area for the gesture to trigger transition to overview.
  static constexpr int kVerticalThresholdForOverviewTransition = 56;

  // The max pointer velocity at which home transitions to overview.
  static constexpr int kMovementVelocityThreshold = 10;

  // The constructor that uses default tick clock for
  // |overview_transition_timer_|. Should be preferred outside of test
  // environment.
  explicit SwipeHomeToOverviewController(int64_t display_id);

  // |display_id| - the ID of display on which the gesture started.
  // |tick_clock| - the tick clock that should be used by
  // |overview_transition_timer_|.
  SwipeHomeToOverviewController(int64_t display_id,
                                const base::TickClock* tick_clock);

  SwipeHomeToOverviewController(const SwipeHomeToOverviewController&) = delete;
  SwipeHomeToOverviewController& operator=(
      const SwipeHomeToOverviewController&) = delete;

  ~SwipeHomeToOverviewController();

  // Called during swiping up on the shelf.
  void Drag(const gfx::PointF& location_in_screen,
            float scroll_x,
            float scroll_y);
  void EndDrag(const gfx::PointF& location_in_screen,
               std::optional<float> velocity_y);
  void CancelDrag();

  base::OneShotTimer* overview_transition_timer_for_testing() {
    return &overview_transition_timer_;
  }

 private:
  enum class State { kInitial, kTrackingDrag, kFinished };

  // Starts |overview_transition_timer_|. No-op if the timer is already running.
  void ScheduleFinalizeDragAndShowOverview();

  // Finalizes the drag sequence, and starts overview session.
  // Note that the controller might keep getting drag updates as the user keeps
  // moving the pointer - those events will be ignored.
  void FinalizeDragAndShowOverview();

  // Finalizes the drag sequence by staying on the home screen.
  // |go_back| - if the gesture should invoke home screen back action.
  void FinalizeDragAndStayOnHomeScreen(bool go_back);

  const int64_t display_id_;

  State state_ = State::kInitial;

  // The y in-screen coordinate at which drag, when stopped, will cause
  // transition to overview. Overview session will be started iff the drag stops
  // above this line.
  // The value is set when the controller transitions to kStarted state.
  int overview_transition_threshold_y_ = 0;

  // Home screen is scaled down depending on gesture vertical distance from the
  // shelf - this is the target gesture vertical location at which home screen
  // should be scaled by the target scale factor.
  int scaling_threshold_y_ = 0;

  // The timer to run FinalizeDragAndShowOverview().
  base::OneShotTimer overview_transition_timer_;
};

}  // namespace ash

#endif  // ASH_SHELF_SWIPE_HOME_TO_OVERVIEW_CONTROLLER_H_