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

Side by Side Diff: trunk/src/content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.cc

Issue 79143002: Revert 236254 "Replace old with new synthetic gesture framework." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
6
7 #include <cmath>
8
9 #include "content/common/input/input_event.h"
10 #include "ui/events/latency_info.h"
11
12 namespace content {
13
14 SyntheticSmoothScrollGesture::SyntheticSmoothScrollGesture(
15 const SyntheticSmoothScrollGestureParams& params)
16 : params_(params), current_y_(params_.anchor.y()) {}
17
18 SyntheticSmoothScrollGesture::~SyntheticSmoothScrollGesture() {}
19
20 SyntheticGesture::Result SyntheticSmoothScrollGesture::ForwardInputEvents(
21 const base::TimeDelta& interval, SyntheticGestureTarget* target) {
22
23 SyntheticGestureParams::GestureSourceType source =
24 params_.gesture_source_type;
25 if (source == SyntheticGestureParams::DEFAULT_INPUT)
26 source = target->GetDefaultSyntheticGestureSourceType();
27
28 if (!target->SupportsSyntheticGestureSourceType(source))
29 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_SUPPORTED_BY_PLATFORM;
30
31 if (source == SyntheticGestureParams::TOUCH_INPUT)
32 return ForwardTouchInputEvents(interval, target);
33 else if (source == SyntheticGestureParams::MOUSE_INPUT)
34 return ForwardMouseInputEvents(interval, target);
35 else
36 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED;
37 }
38
39 SyntheticGesture::Result SyntheticSmoothScrollGesture::ForwardTouchInputEvents(
40 const base::TimeDelta& interval, SyntheticGestureTarget* target) {
41 if (HasFinished())
42 return SyntheticGesture::GESTURE_FINISHED;
43
44 if (current_y_ == params_.anchor.y()) {
45 touch_event_.PressPoint(params_.anchor.x(), current_y_);
46 ForwardTouchEvent(target);
47 }
48
49 current_y_ += GetPositionDelta(interval);
50 touch_event_.MovePoint(0, params_.anchor.x(), current_y_);
51 ForwardTouchEvent(target);
52
53 if (HasFinished()) {
54 touch_event_.ReleasePoint(0);
55 ForwardTouchEvent(target);
56 return SyntheticGesture::GESTURE_FINISHED;
57 }
58
59 return SyntheticGesture::GESTURE_RUNNING;
60 }
61
62 SyntheticGesture::Result SyntheticSmoothScrollGesture::ForwardMouseInputEvents(
63 const base::TimeDelta& interval, SyntheticGestureTarget* target) {
64 if (HasFinished())
65 return SyntheticGesture::GESTURE_FINISHED;
66
67 float delta = GetPositionDelta(interval);
68 current_y_ += delta;
69 ForwardMouseWheelEvent(target, delta);
70
71 if (HasFinished())
72 return SyntheticGesture::GESTURE_FINISHED;
73
74 return SyntheticGesture::GESTURE_RUNNING;
75 }
76
77 void SyntheticSmoothScrollGesture::ForwardTouchEvent(
78 SyntheticGestureTarget* target) {
79 target->DispatchInputEventToPlatform(
80 InputEvent(touch_event_, ui::LatencyInfo(), false));
81 }
82
83 void SyntheticSmoothScrollGesture::ForwardMouseWheelEvent(
84 SyntheticGestureTarget* target, float delta) {
85 blink::WebMouseWheelEvent mouse_wheel_event =
86 SyntheticWebMouseWheelEventBuilder::Build(0, delta, 0, false);
87
88 mouse_wheel_event.x = params_.anchor.x();
89 mouse_wheel_event.y = params_.anchor.y();
90
91 target->DispatchInputEventToPlatform(
92 InputEvent(mouse_wheel_event, ui::LatencyInfo(), false));
93 }
94
95 float SyntheticSmoothScrollGesture::GetPositionDelta(
96 const base::TimeDelta& interval) {
97 float delta = params_.speed_in_pixels_s * interval.InSecondsF();
98 // A positive value indicates scrolling down, which means the touch pointer
99 // moves up or the scroll wheel moves down. In either case, the delta is
100 // negative when scrolling down and positive when scrolling up.
101 return (params_.distance > 0) ? -delta : delta;
102 }
103
104 bool SyntheticSmoothScrollGesture::HasFinished() {
105 return abs(current_y_ - params_.anchor.y()) >= abs(params_.distance);
106 }
107
108 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698