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
|
// 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.
#include "content/browser/renderer_host/synthetic_gesture_controller.h"
#include "base/debug/trace_event.h"
#include "base/message_loop/message_loop.h"
#include "content/common/view_messages.h"
#include "content/port/browser/render_widget_host_view_port.h"
#include "content/port/browser/synthetic_gesture.h"
#include "content/public/browser/render_widget_host.h"
namespace content {
namespace {
// How many milliseconds apart synthetic scroll messages should be sent.
const int kSyntheticGestureMessageIntervalMs = 7;
} // namespace
SyntheticGestureController::SyntheticGestureController()
: rwh_(NULL) {
}
SyntheticGestureController::~SyntheticGestureController() {
}
void SyntheticGestureController::BeginSmoothScroll(
RenderWidgetHostViewPort* view,
const ViewHostMsg_BeginSmoothScroll_Params& params) {
if (pending_synthetic_gesture_.get())
return;
rwh_ = view->GetRenderWidgetHost();
pending_synthetic_gesture_ = view->CreateSmoothScrollGesture(
params.scroll_down,
params.pixels_to_scroll,
params.mouse_event_x,
params.mouse_event_y);
TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running",
pending_synthetic_gesture_);
timer_.Start(FROM_HERE, GetSyntheticGestureMessageInterval(), this,
&SyntheticGestureController::OnTimer);
}
void SyntheticGestureController::BeginPinch(
RenderWidgetHostViewPort* view,
const ViewHostMsg_BeginPinch_Params& params) {
if (pending_synthetic_gesture_.get())
return;
rwh_ = view->GetRenderWidgetHost();
pending_synthetic_gesture_ = view->CreatePinchGesture(
params.zoom_in,
params.pixels_to_move,
params.anchor_x,
params.anchor_y);
TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running",
pending_synthetic_gesture_);
timer_.Start(FROM_HERE, GetSyntheticGestureMessageInterval(), this,
&SyntheticGestureController::OnTimer);
}
base::TimeDelta
SyntheticGestureController::GetSyntheticGestureMessageInterval() const {
return base::TimeDelta::FromMilliseconds(kSyntheticGestureMessageIntervalMs);
}
void SyntheticGestureController::OnTimer() {
base::TimeTicks now = base::TimeTicks::Now();
if (!pending_synthetic_gesture_->ForwardInputEvents(now, rwh_)) {
timer_.Stop();
TRACE_EVENT_ASYNC_END0("benchmark", "SyntheticGestureController::running",
pending_synthetic_gesture_);
pending_synthetic_gesture_ = NULL;
rwh_->Send(new ViewMsg_SyntheticGestureCompleted(rwh_->GetRoutingID()));
}
}
} // namespace content
|