Index: content/browser/renderer_host/input/synthetic_gesture_controller.cc |
diff --git a/content/browser/renderer_host/input/synthetic_gesture_controller.cc b/content/browser/renderer_host/input/synthetic_gesture_controller.cc |
index 9e5bc84403eb18e01f09e43b26b9db51fbd20211..51c28aa406042f57fed6562efd9c550582f7a982 100644 |
--- a/content/browser/renderer_host/input/synthetic_gesture_controller.cc |
+++ b/content/browser/renderer_host/input/synthetic_gesture_controller.cc |
@@ -6,6 +6,7 @@ |
#include <utility> |
+#include "base/threading/thread_task_runner_handle.h" |
#include "base/trace_event/trace_event.h" |
#include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
#include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
@@ -15,8 +16,11 @@ |
namespace content { |
SyntheticGestureController::SyntheticGestureController( |
- std::unique_ptr<SyntheticGestureTarget> gesture_target) |
- : gesture_target_(std::move(gesture_target)) {} |
+ std::unique_ptr<SyntheticGestureTarget> gesture_target, |
+ BeginFrameRequestCallback begin_frame_callback) |
+ : gesture_target_(std::move(gesture_target)), |
+ begin_frame_callback_(std::move(begin_frame_callback)), |
+ weak_ptr_factory_(this) {} |
SyntheticGestureController::~SyntheticGestureController() {} |
@@ -34,51 +38,44 @@ void SyntheticGestureController::QueueSyntheticGesture( |
StartGesture(*pending_gesture_queue_.FrontGesture()); |
} |
-void SyntheticGestureController::Flush(base::TimeTicks timestamp) { |
+void SyntheticGestureController::OnBeginFrame() { |
+ // TODO(sad): Instead of dispatching the events immediately, dispatch after an |
+ // offset. |
+ DispatchNextEvent(); |
+} |
+ |
+bool SyntheticGestureController::DispatchNextEvent(base::TimeTicks timestamp) { |
TRACE_EVENT0("input", "SyntheticGestureController::Flush"); |
if (pending_gesture_queue_.IsEmpty()) |
- return; |
- |
- if (pending_gesture_result_) |
- return; |
+ return false; |
- SyntheticGesture* gesture = pending_gesture_queue_.FrontGesture(); |
SyntheticGesture::Result result = |
- gesture->ForwardInputEvents(timestamp, gesture_target_.get()); |
+ pending_gesture_queue_.FrontGesture()->ForwardInputEvents( |
+ timestamp, gesture_target_.get()); |
if (result == SyntheticGesture::GESTURE_RUNNING) { |
- gesture_target_->SetNeedsFlush(); |
- return; |
+ begin_frame_callback_.Run( |
+ base::BindOnce(&SyntheticGestureController::OnBeginFrame, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ return true; |
} |
- // It's possible that all events generated by the gesture have been fully |
- // dispatched at this point, in which case |OnDidFlushInput()| was called |
- // before |pending_gesture_result_| was initialized. Requesting another flush |
- // will trigger the necessary gesture-ending call to |OnDidFlushInput()|. |
- pending_gesture_result_.reset(new SyntheticGesture::Result(result)); |
- gesture_target_->SetNeedsFlush(); |
-} |
- |
-void SyntheticGestureController::OnDidFlushInput() { |
- if (!pending_gesture_result_) |
- return; |
- |
- DCHECK(!pending_gesture_queue_.IsEmpty()); |
- auto pending_gesture_result = std::move(pending_gesture_result_); |
StopGesture(*pending_gesture_queue_.FrontGesture(), |
- pending_gesture_queue_.FrontCallback(), |
- *pending_gesture_result); |
+ pending_gesture_queue_.FrontCallback(), result); |
pending_gesture_queue_.Pop(); |
- |
- if (!pending_gesture_queue_.IsEmpty()) |
- StartGesture(*pending_gesture_queue_.FrontGesture()); |
+ if (pending_gesture_queue_.IsEmpty()) |
+ return false; |
+ StartGesture(*pending_gesture_queue_.FrontGesture()); |
+ return true; |
} |
void SyntheticGestureController::StartGesture(const SyntheticGesture& gesture) { |
TRACE_EVENT_ASYNC_BEGIN0("input,benchmark", |
"SyntheticGestureController::running", |
&gesture); |
- gesture_target_->SetNeedsFlush(); |
+ begin_frame_callback_.Run( |
+ base::BindOnce(&SyntheticGestureController::OnBeginFrame, |
+ weak_ptr_factory_.GetWeakPtr())); |
} |
void SyntheticGestureController::StopGesture( |