| 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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 9 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 9 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 10 #include "content/common/input_messages.h" | 10 #include "content/common/input_messages.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 // Start forwarding input events if the queue was previously empty. | 27 // Start forwarding input events if the queue was previously empty. |
| 28 if (pending_gesture_queue_.size() == 1) | 28 if (pending_gesture_queue_.size() == 1) |
| 29 StartGesture(*pending_gesture_queue_.front()); | 29 StartGesture(*pending_gesture_queue_.front()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void SyntheticGestureController::Flush(base::TimeTicks timestamp) { | 32 void SyntheticGestureController::Flush(base::TimeTicks timestamp) { |
| 33 if (pending_gesture_queue_.empty()) | 33 if (pending_gesture_queue_.empty()) |
| 34 return; | 34 return; |
| 35 | 35 |
| 36 if (last_tick_time_.is_null()) { | |
| 37 last_tick_time_ = timestamp; | |
| 38 gesture_target_->SetNeedsFlush(); | |
| 39 return; | |
| 40 } | |
| 41 | |
| 42 base::TimeDelta interval = timestamp - last_tick_time_; | |
| 43 last_tick_time_ = timestamp; | |
| 44 SyntheticGesture::Result result = | 36 SyntheticGesture::Result result = |
| 45 pending_gesture_queue_.front()->ForwardInputEvents(interval, | 37 pending_gesture_queue_.front()->ForwardInputEvents(timestamp, |
| 46 gesture_target_.get()); | 38 gesture_target_.get()); |
| 47 | 39 |
| 48 if (result == SyntheticGesture::GESTURE_RUNNING) { | 40 if (result == SyntheticGesture::GESTURE_RUNNING) { |
| 49 gesture_target_->SetNeedsFlush(); | 41 gesture_target_->SetNeedsFlush(); |
| 50 return; | 42 return; |
| 51 } | 43 } |
| 52 | 44 |
| 53 StopGesture(*pending_gesture_queue_.front(), result); | 45 StopGesture(*pending_gesture_queue_.front(), result); |
| 54 pending_gesture_queue_.erase(pending_gesture_queue_.begin()); | 46 pending_gesture_queue_.erase(pending_gesture_queue_.begin()); |
| 55 | 47 |
| 56 if (!pending_gesture_queue_.empty()) { | 48 if (!pending_gesture_queue_.empty()) |
| 57 StartGesture(*pending_gesture_queue_.front()); | 49 StartGesture(*pending_gesture_queue_.front()); |
| 58 } else { | |
| 59 // Reset last_tick_time_ so that we don't use an old value when a new | |
| 60 // gestures is queued. | |
| 61 last_tick_time_ = base::TimeTicks(); | |
| 62 } | |
| 63 } | 50 } |
| 64 | 51 |
| 65 void SyntheticGestureController::StartGesture(const SyntheticGesture& gesture) { | 52 void SyntheticGestureController::StartGesture(const SyntheticGesture& gesture) { |
| 66 TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running", | 53 TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running", |
| 67 &gesture); | 54 &gesture); |
| 68 gesture_target_->SetNeedsFlush(); | 55 gesture_target_->SetNeedsFlush(); |
| 69 } | 56 } |
| 70 | 57 |
| 71 void SyntheticGestureController::StopGesture( | 58 void SyntheticGestureController::StopGesture( |
| 72 const SyntheticGesture& gesture, SyntheticGesture::Result result) { | 59 const SyntheticGesture& gesture, SyntheticGesture::Result result) { |
| 73 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); | 60 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); |
| 74 TRACE_EVENT_ASYNC_END0("benchmark", "SyntheticGestureController::running", | 61 TRACE_EVENT_ASYNC_END0("benchmark", "SyntheticGestureController::running", |
| 75 &gesture); | 62 &gesture); |
| 76 | 63 |
| 77 gesture_target_->OnSyntheticGestureCompleted(result); | 64 gesture_target_->OnSyntheticGestureCompleted(result); |
| 78 } | 65 } |
| 79 | 66 |
| 80 } // namespace content | 67 } // namespace content |
| OLD | NEW |