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.
5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
7 #include "base/debug/trace_event.h"
8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
9 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
10 #include "content/common/input_messages.h"
11 #include "content/public/browser/render_widget_host.h"
15 SyntheticGestureController::SyntheticGestureController(
16 scoped_ptr
<SyntheticGestureTarget
> gesture_target
)
17 : gesture_target_(gesture_target
.Pass()) {}
19 SyntheticGestureController::~SyntheticGestureController() {}
21 void SyntheticGestureController::QueueSyntheticGesture(
22 scoped_ptr
<SyntheticGesture
> synthetic_gesture
) {
23 DCHECK(synthetic_gesture
);
25 pending_gesture_queue_
.push_back(synthetic_gesture
.release());
27 // Start forwarding input events if the queue was previously empty.
28 if (pending_gesture_queue_
.size() == 1)
29 StartGesture(*pending_gesture_queue_
.front());
32 void SyntheticGestureController::Flush(base::TimeTicks timestamp
) {
33 if (pending_gesture_queue_
.empty())
36 SyntheticGesture::Result result
=
37 pending_gesture_queue_
.front()->ForwardInputEvents(timestamp
,
38 gesture_target_
.get());
40 if (result
== SyntheticGesture::GESTURE_RUNNING
) {
41 gesture_target_
->SetNeedsFlush();
45 StopGesture(*pending_gesture_queue_
.front(), result
);
46 pending_gesture_queue_
.erase(pending_gesture_queue_
.begin());
48 if (!pending_gesture_queue_
.empty())
49 StartGesture(*pending_gesture_queue_
.front());
52 void SyntheticGestureController::StartGesture(const SyntheticGesture
& gesture
) {
53 TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running",
55 gesture_target_
->SetNeedsFlush();
58 void SyntheticGestureController::StopGesture(
59 const SyntheticGesture
& gesture
, SyntheticGesture::Result result
) {
60 DCHECK_NE(result
, SyntheticGesture::GESTURE_RUNNING
);
61 TRACE_EVENT_ASYNC_END0("benchmark", "SyntheticGestureController::running",
64 gesture_target_
->OnSyntheticGestureCompleted(result
);
67 } // namespace content