| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 bool was_empty = pending_gesture_queue_.IsEmpty(); | 32 bool was_empty = pending_gesture_queue_.IsEmpty(); |
| 33 | 33 |
| 34 pending_gesture_queue_.Push(std::move(synthetic_gesture), | 34 pending_gesture_queue_.Push(std::move(synthetic_gesture), |
| 35 completion_callback); | 35 completion_callback); |
| 36 | 36 |
| 37 if (was_empty) | 37 if (was_empty) |
| 38 StartGesture(*pending_gesture_queue_.FrontGesture()); | 38 StartGesture(*pending_gesture_queue_.FrontGesture()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SyntheticGestureController::OnBeginFrame() { | 41 void SyntheticGestureController::OnBeginFrame() { |
| 42 // TODO(sad): Instead of dispatching the events immediately, dispatch after an | 42 constexpr base::TimeDelta kSynthesizedDispatchDelay = |
| 43 // offset. | 43 base::TimeDelta::FromMilliseconds(2); |
| 44 DispatchNextEvent(); | 44 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 45 FROM_HERE, |
| 46 base::BindOnce( |
| 47 [](base::WeakPtr<SyntheticGestureController> weak_ptr) { |
| 48 if (weak_ptr) |
| 49 weak_ptr->DispatchNextEvent(base::TimeTicks::Now()); |
| 50 }, |
| 51 weak_ptr_factory_.GetWeakPtr()), |
| 52 kSynthesizedDispatchDelay); |
| 45 } | 53 } |
| 46 | 54 |
| 47 bool SyntheticGestureController::DispatchNextEvent(base::TimeTicks timestamp) { | 55 bool SyntheticGestureController::DispatchNextEvent(base::TimeTicks timestamp) { |
| 48 TRACE_EVENT0("input", "SyntheticGestureController::Flush"); | 56 TRACE_EVENT0("input", "SyntheticGestureController::Flush"); |
| 49 if (pending_gesture_queue_.IsEmpty()) | 57 if (pending_gesture_queue_.IsEmpty()) |
| 50 return false; | 58 return false; |
| 51 | 59 |
| 52 SyntheticGesture::Result result = | 60 SyntheticGesture::Result result = |
| 53 pending_gesture_queue_.FrontGesture()->ForwardInputEvents( | 61 pending_gesture_queue_.FrontGesture()->ForwardInputEvents( |
| 54 timestamp, gesture_target_.get()); | 62 timestamp, gesture_target_.get()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 99 } |
| 92 | 100 |
| 93 SyntheticGestureController::GestureAndCallbackQueue::GestureAndCallbackQueue() { | 101 SyntheticGestureController::GestureAndCallbackQueue::GestureAndCallbackQueue() { |
| 94 } | 102 } |
| 95 | 103 |
| 96 SyntheticGestureController::GestureAndCallbackQueue:: | 104 SyntheticGestureController::GestureAndCallbackQueue:: |
| 97 ~GestureAndCallbackQueue() { | 105 ~GestureAndCallbackQueue() { |
| 98 } | 106 } |
| 99 | 107 |
| 100 } // namespace content | 108 } // namespace content |
| OLD | NEW |