Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(971)

Side by Side Diff: content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h

Issue 929333002: Adding synthetic touch/mouse drag [Part1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_SCROLL_GESTURE_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_SCROLL_GESTURE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_SCROLL_GESTURE_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_SCROLL_GESTURE_H_
7 7
8 #include "base/time/time.h" 8 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h"
9 #include "content/browser/renderer_host/input/synthetic_gesture.h" 9
10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
11 #include "content/common/content_export.h"
12 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" 10 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
13 #include "content/common/input/synthetic_web_input_event_builders.h"
14 #include "third_party/WebKit/public/web/WebInputEvent.h"
15 #include "ui/gfx/geometry/vector2d.h"
16 #include "ui/gfx/geometry/vector2d_f.h"
17 11
18 namespace content { 12 namespace content {
19
20 // Simulates scrolling given a sequence of scroll distances as a continuous
21 // gestures (i.e. when synthesizing touch events, the touch pointer is not
22 // lifted when changing scroll direction).
23 // If no distance is provided or the first one is 0, no touch events are
24 // generated.
25 // When synthesizing touch events, the first distance is extended to compensate
26 // for the touch slop.
27 class CONTENT_EXPORT SyntheticSmoothScrollGesture : public SyntheticGesture { 13 class CONTENT_EXPORT SyntheticSmoothScrollGesture : public SyntheticGesture {
28 public: 14 public:
29 explicit SyntheticSmoothScrollGesture( 15 explicit SyntheticSmoothScrollGesture(
30 const SyntheticSmoothScrollGestureParams& params); 16 const SyntheticSmoothScrollGestureParams& params);
31 ~SyntheticSmoothScrollGesture() override; 17 ~SyntheticSmoothScrollGesture() override;
32 18
19 // SyntheticGesture implementation:
33 SyntheticGesture::Result ForwardInputEvents( 20 SyntheticGesture::Result ForwardInputEvents(
34 const base::TimeTicks& timestamp, 21 const base::TimeTicks& timestamp,
35 SyntheticGestureTarget* target) override; 22 SyntheticGestureTarget* target) override;
36 23
37 private: 24 private:
38 enum GestureState { 25 static SyntheticSmoothMoveGestureParams::InputType GetInputSourceType(
39 SETUP, 26 SyntheticGestureParams::GestureSourceType gesture_source_type);
40 STARTED,
41 MOVING,
42 STOPPING,
43 DONE
44 };
45 27
46 void ForwardTouchInputEvents( 28 bool InitializeMoveGesture(
47 const base::TimeTicks& timestamp, SyntheticGestureTarget* target); 29 SyntheticGestureParams::GestureSourceType gesture_type,
48 void ForwardMouseInputEvents( 30 SyntheticGestureTarget* target);
49 const base::TimeTicks& timestamp, SyntheticGestureTarget* target);
50 31
51 void ForwardTouchEvent(SyntheticGestureTarget* target, 32 scoped_ptr<SyntheticSmoothMoveGesture> move_gesture_;
52 const base::TimeTicks& timestamp);
53 void ForwardMouseWheelEvent(SyntheticGestureTarget* target,
54 const gfx::Vector2dF& delta,
55 const base::TimeTicks& timestamp) const;
56
57 void PressTouchPoint(SyntheticGestureTarget* target,
58 const base::TimeTicks& timestamp);
59 void MoveTouchPoint(SyntheticGestureTarget* target,
60 const gfx::Vector2dF& delta,
61 const base::TimeTicks& timestamp);
62 void ReleaseTouchPoint(SyntheticGestureTarget* target,
63 const base::TimeTicks& timestamp);
64
65 void AddTouchSlopToFirstDistance(SyntheticGestureTarget* target);
66 gfx::Vector2dF GetPositionDeltaAtTime(const base::TimeTicks& timestamp)
67 const;
68 void ComputeNextScrollSegment();
69 base::TimeTicks ClampTimestamp(const base::TimeTicks& timestamp) const;
70 bool FinishedCurrentScrollSegment(const base::TimeTicks& timestamp) const;
71 bool IsLastScrollSegment() const;
72 bool ScrollIsNoOp() const;
73
74 SyntheticSmoothScrollGestureParams params_; 33 SyntheticSmoothScrollGestureParams params_;
75 // Used for mouse input.
76 gfx::Vector2d current_scroll_segment_total_delta_discrete_;
77 // Used for touch input.
78 gfx::Point current_scroll_segment_start_position_;
79 SyntheticWebTouchEvent touch_event_;
80 SyntheticGestureParams::GestureSourceType gesture_source_type_;
81 GestureState state_;
82 int current_scroll_segment_;
83 base::TimeTicks current_scroll_segment_start_time_;
84 base::TimeTicks current_scroll_segment_stop_time_;
85
86 DISALLOW_COPY_AND_ASSIGN(SyntheticSmoothScrollGesture);
87 }; 34 };
88 35
89 } // namespace content 36 } // namespace content
90 37
91 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_SCROLL_GESTURE_H _ 38 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_SCROLL_GESTURE_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698