| OLD | NEW |
| 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_MOVE_GESTURE_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_SCROLL_GESTURE_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_MOVE_GESTURE_H_ |
| 7 |
| 8 #include <vector> |
| 7 | 9 |
| 8 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 9 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 11 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
| 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 12 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 11 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
| 12 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 15 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 13 #include "content/common/input/synthetic_web_input_event_builders.h" | 16 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 14 #include "third_party/WebKit/public/web/WebInputEvent.h" | 17 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 15 #include "ui/gfx/geometry/vector2d.h" | 18 #include "ui/gfx/geometry/vector2d.h" |
| 16 #include "ui/gfx/geometry/vector2d_f.h" | 19 #include "ui/gfx/geometry/vector2d_f.h" |
| 17 | 20 |
| 18 namespace content { | 21 namespace content { |
| 19 | 22 |
| 20 // Simulates scrolling given a sequence of scroll distances as a continuous | 23 class CONTENT_EXPORT SyntheticSmoothMoveGestureParams { |
| 21 // gestures (i.e. when synthesizing touch events, the touch pointer is not | 24 public: |
| 22 // lifted when changing scroll direction). | 25 SyntheticSmoothMoveGestureParams(); |
| 26 ~SyntheticSmoothMoveGestureParams(); |
| 27 |
| 28 enum InputType { MOUSE_DRAG_INPUT, MOUSE_WHEEL_INPUT, TOUCH_INPUT }; |
| 29 |
| 30 InputType input_type; |
| 31 gfx::PointF start_point; |
| 32 std::vector<gfx::Vector2dF> distances; |
| 33 int speed_in_pixels_s; |
| 34 bool prevent_fling; |
| 35 bool add_slop; |
| 36 }; |
| 37 |
| 38 // This class is used as helper class for simulation of scroll and drag. |
| 39 // Simulates scrolling/dragging given a sequence of distances as a continuous |
| 40 // gestures (i.e. when synthesizing touch or mouse drag events, the pointer is |
| 41 // not lifted when changing scroll direction). |
| 23 // If no distance is provided or the first one is 0, no touch events are | 42 // If no distance is provided or the first one is 0, no touch events are |
| 24 // generated. | 43 // generated. |
| 25 // When synthesizing touch events, the first distance is extended to compensate | 44 // When synthesizing touch events for scrolling, the first distance is extended |
| 26 // for the touch slop. | 45 // to compensate for the touch slop. |
| 27 class CONTENT_EXPORT SyntheticSmoothScrollGesture : public SyntheticGesture { | 46 class CONTENT_EXPORT SyntheticSmoothMoveGesture : public SyntheticGesture { |
| 28 public: | 47 public: |
| 29 explicit SyntheticSmoothScrollGesture( | 48 SyntheticSmoothMoveGesture(SyntheticSmoothMoveGestureParams params); |
| 30 const SyntheticSmoothScrollGestureParams& params); | 49 ~SyntheticSmoothMoveGesture() override; |
| 31 ~SyntheticSmoothScrollGesture() override; | |
| 32 | 50 |
| 51 // SyntheticGesture implementation: |
| 33 SyntheticGesture::Result ForwardInputEvents( | 52 SyntheticGesture::Result ForwardInputEvents( |
| 34 const base::TimeTicks& timestamp, | 53 const base::TimeTicks& timestamp, |
| 35 SyntheticGestureTarget* target) override; | 54 SyntheticGestureTarget* target) override; |
| 36 | 55 |
| 37 private: | 56 private: |
| 38 enum GestureState { | 57 enum GestureState { |
| 39 SETUP, | 58 SETUP, |
| 40 STARTED, | 59 STARTED, |
| 41 MOVING, | 60 MOVING, |
| 42 STOPPING, | 61 STOPPING, |
| 43 DONE | 62 DONE |
| 44 }; | 63 }; |
| 45 | 64 |
| 46 void ForwardTouchInputEvents( | 65 void ForwardTouchInputEvents( |
| 47 const base::TimeTicks& timestamp, SyntheticGestureTarget* target); | 66 const base::TimeTicks& timestamp, SyntheticGestureTarget* target); |
| 48 void ForwardMouseInputEvents( | 67 void ForwardMouseWheelInputEvents( |
| 68 const base::TimeTicks& timestamp, SyntheticGestureTarget* target); |
| 69 void ForwardMouseClickInputEvents( |
| 49 const base::TimeTicks& timestamp, SyntheticGestureTarget* target); | 70 const base::TimeTicks& timestamp, SyntheticGestureTarget* target); |
| 50 | 71 |
| 51 void ForwardTouchEvent(SyntheticGestureTarget* target, | 72 void ForwardTouchEvent(SyntheticGestureTarget* target, |
| 52 const base::TimeTicks& timestamp); | 73 const base::TimeTicks& timestamp); |
| 53 void ForwardMouseWheelEvent(SyntheticGestureTarget* target, | 74 void ForwardMouseWheelEvent(SyntheticGestureTarget* target, |
| 54 const gfx::Vector2dF& delta, | 75 const gfx::Vector2dF& delta, |
| 55 const base::TimeTicks& timestamp) const; | 76 const base::TimeTicks& timestamp) const; |
| 56 | 77 |
| 57 void PressTouchPoint(SyntheticGestureTarget* target, | 78 void PressTouchPoint(SyntheticGestureTarget* target, |
| 58 const base::TimeTicks& timestamp); | 79 const base::TimeTicks& timestamp); |
| 59 void MoveTouchPoint(SyntheticGestureTarget* target, | 80 void MoveTouchPoint(SyntheticGestureTarget* target, |
| 60 const gfx::Vector2dF& delta, | 81 const gfx::Vector2dF& delta, |
| 61 const base::TimeTicks& timestamp); | 82 const base::TimeTicks& timestamp); |
| 62 void ReleaseTouchPoint(SyntheticGestureTarget* target, | 83 void ReleaseTouchPoint(SyntheticGestureTarget* target, |
| 63 const base::TimeTicks& timestamp); | 84 const base::TimeTicks& timestamp); |
| 64 | 85 |
| 86 void PressMousePoint(SyntheticGestureTarget* target, |
| 87 const base::TimeTicks& timestamp); |
| 88 void ReleaseMousePoint(SyntheticGestureTarget* target, |
| 89 const base::TimeTicks& timestamp); |
| 90 void MoveMousePoint(SyntheticGestureTarget* target, |
| 91 const gfx::Vector2dF& delta, |
| 92 const base::TimeTicks& timestamp); |
| 93 |
| 65 void AddTouchSlopToFirstDistance(SyntheticGestureTarget* target); | 94 void AddTouchSlopToFirstDistance(SyntheticGestureTarget* target); |
| 66 gfx::Vector2dF GetPositionDeltaAtTime(const base::TimeTicks& timestamp) | 95 gfx::Vector2dF GetPositionDeltaAtTime(const base::TimeTicks& timestamp) const; |
| 67 const; | 96 void ComputeNextMoveSegment(); |
| 68 void ComputeNextScrollSegment(); | |
| 69 base::TimeTicks ClampTimestamp(const base::TimeTicks& timestamp) const; | 97 base::TimeTicks ClampTimestamp(const base::TimeTicks& timestamp) const; |
| 70 bool FinishedCurrentScrollSegment(const base::TimeTicks& timestamp) const; | 98 bool FinishedCurrentMoveSegment(const base::TimeTicks& timestamp) const; |
| 71 bool IsLastScrollSegment() const; | 99 bool IsLastMoveSegment() const; |
| 72 bool ScrollIsNoOp() const; | 100 bool MoveIsNoOp() const; |
| 73 | 101 |
| 74 SyntheticSmoothScrollGestureParams params_; | 102 SyntheticSmoothMoveGestureParams params_; |
| 75 // Used for mouse input. | 103 // Used for mouse input. |
| 76 gfx::Vector2d current_scroll_segment_total_delta_discrete_; | 104 gfx::Vector2d current_move_segment_total_delta_discrete_; |
| 77 // Used for touch input. | 105 // Used for touch input. |
| 78 gfx::Point current_scroll_segment_start_position_; | 106 gfx::PointF current_move_segment_start_position_; |
| 79 SyntheticWebTouchEvent touch_event_; | 107 SyntheticWebTouchEvent touch_event_; |
| 80 SyntheticGestureParams::GestureSourceType gesture_source_type_; | |
| 81 GestureState state_; | 108 GestureState state_; |
| 82 int current_scroll_segment_; | 109 int current_move_segment_; |
| 83 base::TimeTicks current_scroll_segment_start_time_; | 110 base::TimeTicks current_move_segment_start_time_; |
| 84 base::TimeTicks current_scroll_segment_stop_time_; | 111 base::TimeTicks current_move_segment_stop_time_; |
| 85 | 112 |
| 86 DISALLOW_COPY_AND_ASSIGN(SyntheticSmoothScrollGesture); | 113 DISALLOW_COPY_AND_ASSIGN(SyntheticSmoothMoveGesture); |
| 87 }; | 114 }; |
| 88 | 115 |
| 89 } // namespace content | 116 } // namespace content |
| 90 | 117 |
| 91 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_SCROLL_GESTURE_H
_ | 118 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SYNTHETIC_SMOOTH_MOVE_GESTURE_H_ |
| OLD | NEW |