File: synthetic_smooth_move_gesture.h

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (121 lines) | stat: -rw-r--r-- 4,659 bytes parent folder | download | duplicates (2)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_MOVE_GESTURE_H_
#define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_MOVE_GESTURE_H_

#include <vector>

#include "base/macros.h"
#include "base/time/time.h"
#include "content/browser/renderer_host/input/synthetic_gesture.h"
#include "content/browser/renderer_host/input/synthetic_gesture_target.h"
#include "content/browser/renderer_host/input/synthetic_pointer_driver.h"
#include "content/common/content_export.h"
#include "content/common/input/synthetic_smooth_drag_gesture_params.h"
#include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
#include "third_party/blink/public/platform/web_input_event.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"

namespace content {

class CONTENT_EXPORT SyntheticSmoothMoveGestureParams {
 public:
  SyntheticSmoothMoveGestureParams();
  SyntheticSmoothMoveGestureParams(
      const SyntheticSmoothMoveGestureParams& other);
  ~SyntheticSmoothMoveGestureParams();

  enum InputType { MOUSE_DRAG_INPUT, MOUSE_WHEEL_INPUT, TOUCH_INPUT };

  InputType input_type;
  gfx::PointF start_point;
  std::vector<gfx::Vector2dF> distances;
  int speed_in_pixels_s;
  int fling_velocity_x;
  int fling_velocity_y;
  bool prevent_fling;
  bool add_slop;
  bool precise_scrolling_deltas;
  bool scroll_by_page;
};

// This class is used as helper class for simulation of scroll and drag.
// Simulates scrolling/dragging given a sequence of distances as a continuous
// gestures (i.e. when synthesizing touch or mouse drag events, the pointer is
// not lifted when changing scroll direction).
// If no distance is provided or the first one is 0, no touch events are
// generated.
// When synthesizing touch events for scrolling, the first distance is extended
// to compensate for the touch slop.
class CONTENT_EXPORT SyntheticSmoothMoveGesture : public SyntheticGesture {
 public:
  explicit SyntheticSmoothMoveGesture(SyntheticSmoothMoveGestureParams params);
  ~SyntheticSmoothMoveGesture() override;

  // SyntheticGesture implementation:
  SyntheticGesture::Result ForwardInputEvents(
      const base::TimeTicks& timestamp,
      SyntheticGestureTarget* target) override;

 private:
  enum GestureState {
    SETUP,
    STARTED,
    MOVING,
    STOPPING,
    DONE
  };

  void ForwardTouchInputEvents(
      const base::TimeTicks& timestamp, SyntheticGestureTarget* target);
  void ForwardMouseWheelInputEvents(
      const base::TimeTicks& timestamp, SyntheticGestureTarget* target);
  void ForwardMouseClickInputEvents(
      const base::TimeTicks& timestamp, SyntheticGestureTarget* target);

  void ForwardMouseWheelEvent(SyntheticGestureTarget* target,
                              const gfx::Vector2dF& delta,
                              const blink::WebMouseWheelEvent::Phase phase,
                              const base::TimeTicks& timestamp) const;

  void ForwardFlingGestureEvent(SyntheticGestureTarget* target,
                                const blink::WebInputEvent::Type type) const;

  void PressPoint(SyntheticGestureTarget* target,
                  const base::TimeTicks& timestamp);
  void MovePoint(SyntheticGestureTarget* target,
                 const gfx::Vector2dF& delta,
                 const base::TimeTicks& timestamp);
  void ReleasePoint(SyntheticGestureTarget* target,
                    const base::TimeTicks& timestamp);

  void AddTouchSlopToFirstDistance(SyntheticGestureTarget* target);
  gfx::Vector2dF GetPositionDeltaAtTime(const base::TimeTicks& timestamp) const;
  void ComputeNextMoveSegment();
  base::TimeTicks ClampTimestamp(const base::TimeTicks& timestamp) const;
  bool FinishedCurrentMoveSegment(const base::TimeTicks& timestamp) const;
  bool IsLastMoveSegment() const;
  bool MoveIsNoOp() const;

  SyntheticSmoothMoveGestureParams params_;
  std::unique_ptr<SyntheticPointerDriver> synthetic_pointer_driver_;
  // Used for mouse input.
  gfx::Vector2dF current_move_segment_total_delta_;
  // Used for touch input.
  gfx::PointF current_move_segment_start_position_;
  GestureState state_;
  int current_move_segment_;
  base::TimeTicks current_move_segment_start_time_;
  base::TimeTicks current_move_segment_stop_time_;
  // Used to set phase information for synthetic wheel events.
  bool needs_scroll_begin_;

  DISALLOW_COPY_AND_ASSIGN(SyntheticSmoothMoveGesture);
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_MOVE_GESTURE_H_