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
|
// Copyright (c) 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.
#include "content/browser/renderer_host/touch_smooth_scroll_gesture_aura.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
namespace {
WebKit::WebTouchEvent CreateWebTouchPointAt(const gfx::Point& location,
WebKit::WebInputEvent::Type type) {
WebKit::WebTouchEvent touch;
touch.type = type;
touch.touchesLength = 1;
touch.changedTouchesLength = 1;
WebKit::WebTouchPoint point;
switch (type) {
case WebKit::WebInputEvent::TouchStart:
point.state = WebKit::WebTouchPoint::StatePressed;
break;
case WebKit::WebInputEvent::TouchMove:
point.state = WebKit::WebTouchPoint::StateMoved;
break;
case WebKit::WebInputEvent::TouchEnd:
point.state = WebKit::WebTouchPoint::StateReleased;
break;
case WebKit::WebInputEvent::TouchCancel:
point.state = WebKit::WebTouchPoint::StateCancelled;
break;
default:
NOTREACHED();
}
point.position.x = location.x();
point.position.y = location.y();
point.screenPosition = point.position;
touch.touches[0] = touch.changedTouches[0] = point;
return touch;
}
} // namespace
namespace content {
TouchSmoothScrollGestureAura::TouchSmoothScrollGestureAura(bool scroll_down,
int pixels_to_scroll,
int mouse_event_x,
int mouse_event_y)
: scroll_down_(scroll_down),
pixels_to_scroll_(pixels_to_scroll),
pixels_scrolled_(0),
location_(mouse_event_x, mouse_event_y) {
}
TouchSmoothScrollGestureAura::~TouchSmoothScrollGestureAura() {}
bool TouchSmoothScrollGestureAura::ForwardInputEvents(
base::TimeTicks now,
RenderWidgetHost* host) {
if (pixels_scrolled_ >= pixels_to_scroll_)
return false;
RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From(host);
double position_delta = smooth_scroll_calculator_.GetScrollDelta(now,
host_impl->GetSyntheticScrollMessageInterval());
if (pixels_scrolled_ == 0) {
host_impl->ForwardTouchEvent(CreateWebTouchPointAt(location_,
WebKit::WebInputEvent::TouchStart));
}
location_.Offset(0, scroll_down_ ? -position_delta : position_delta);
host_impl->ForwardTouchEvent(CreateWebTouchPointAt(location_,
WebKit::WebInputEvent::TouchMove));
pixels_scrolled_ += abs(position_delta);
if (pixels_scrolled_ >= pixels_to_scroll_) {
host_impl->ForwardTouchEvent(CreateWebTouchPointAt(location_,
WebKit::WebInputEvent::TouchEnd));
}
return true;
}
} // namespace content
|