Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / synthetic_gesture_controller.cc
blob536426b71db2eed3f0df1476de222bc7b89d1a35
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/trace_event/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"
13 namespace content {
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 const OnGestureCompleteCallback& completion_callback) {
24 DCHECK(synthetic_gesture);
26 bool was_empty = pending_gesture_queue_.IsEmpty();
28 pending_gesture_queue_.Push(synthetic_gesture.Pass(), completion_callback);
30 if (was_empty)
31 StartGesture(*pending_gesture_queue_.FrontGesture());
34 void SyntheticGestureController::Flush(base::TimeTicks timestamp) {
35 TRACE_EVENT0("input", "SyntheticGestureController::Flush");
36 if (pending_gesture_queue_.IsEmpty())
37 return;
39 if (pending_gesture_result_)
40 return;
42 SyntheticGesture* gesture = pending_gesture_queue_.FrontGesture();
43 SyntheticGesture::Result result =
44 gesture->ForwardInputEvents(timestamp, gesture_target_.get());
46 if (result == SyntheticGesture::GESTURE_RUNNING) {
47 gesture_target_->SetNeedsFlush();
48 return;
51 // It's possible that all events generated by the gesture have been fully
52 // dispatched at this point, in which case |OnDidFlushInput()| was called
53 // before |pending_gesture_result_| was initialized. Requesting another flush
54 // will trigger the necessary gesture-ending call to |OnDidFlushInput()|.
55 pending_gesture_result_.reset(new SyntheticGesture::Result(result));
56 gesture_target_->SetNeedsFlush();
59 void SyntheticGestureController::OnDidFlushInput() {
60 if (!pending_gesture_result_)
61 return;
63 DCHECK(!pending_gesture_queue_.IsEmpty());
64 auto pending_gesture_result = pending_gesture_result_.Pass();
65 StopGesture(*pending_gesture_queue_.FrontGesture(),
66 pending_gesture_queue_.FrontCallback(),
67 *pending_gesture_result);
68 pending_gesture_queue_.Pop();
70 if (!pending_gesture_queue_.IsEmpty())
71 StartGesture(*pending_gesture_queue_.FrontGesture());
74 void SyntheticGestureController::StartGesture(const SyntheticGesture& gesture) {
75 TRACE_EVENT_ASYNC_BEGIN0("input,benchmark",
76 "SyntheticGestureController::running",
77 &gesture);
78 gesture_target_->SetNeedsFlush();
81 void SyntheticGestureController::StopGesture(
82 const SyntheticGesture& gesture,
83 const OnGestureCompleteCallback& completion_callback,
84 SyntheticGesture::Result result) {
85 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING);
86 TRACE_EVENT_ASYNC_END0("input,benchmark",
87 "SyntheticGestureController::running",
88 &gesture);
90 completion_callback.Run(result);
93 SyntheticGestureController::GestureAndCallbackQueue::GestureAndCallbackQueue() {
96 SyntheticGestureController::GestureAndCallbackQueue::
97 ~GestureAndCallbackQueue() {
100 } // namespace content