| 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_new.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" |
| 11 #include "content/public/browser/render_widget_host.h" | 11 #include "content/public/browser/render_widget_host.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 SyntheticGestureControllerNew::SyntheticGestureControllerNew( | 15 SyntheticGestureController::SyntheticGestureController( |
| 16 scoped_ptr<SyntheticGestureTarget> gesture_target) | 16 scoped_ptr<SyntheticGestureTarget> gesture_target) |
| 17 : gesture_target_(gesture_target.Pass()) {} | 17 : gesture_target_(gesture_target.Pass()) {} |
| 18 | 18 |
| 19 SyntheticGestureControllerNew::~SyntheticGestureControllerNew() {} | 19 SyntheticGestureController::~SyntheticGestureController() {} |
| 20 | 20 |
| 21 void SyntheticGestureControllerNew::QueueSyntheticGesture( | 21 void SyntheticGestureController::QueueSyntheticGesture( |
| 22 scoped_ptr<SyntheticGestureNew> synthetic_gesture) { | 22 scoped_ptr<SyntheticGesture> synthetic_gesture) { |
| 23 DCHECK(synthetic_gesture); | 23 DCHECK(synthetic_gesture); |
| 24 | 24 |
| 25 pending_gesture_queue_.push_back(synthetic_gesture.release()); | 25 pending_gesture_queue_.push_back(synthetic_gesture.release()); |
| 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 SyntheticGestureControllerNew::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()) { | 36 if (last_tick_time_.is_null()) { |
| 37 last_tick_time_ = timestamp; | 37 last_tick_time_ = timestamp; |
| 38 gesture_target_->SetNeedsFlush(); | 38 gesture_target_->SetNeedsFlush(); |
| 39 return; | 39 return; |
| 40 } | 40 } |
| 41 | 41 |
| 42 base::TimeDelta interval = timestamp - last_tick_time_; | 42 base::TimeDelta interval = timestamp - last_tick_time_; |
| 43 last_tick_time_ = timestamp; | 43 last_tick_time_ = timestamp; |
| 44 SyntheticGestureNew::Result result = | 44 SyntheticGesture::Result result = |
| 45 pending_gesture_queue_.front()->ForwardInputEvents(interval, | 45 pending_gesture_queue_.front()->ForwardInputEvents(interval, |
| 46 gesture_target_.get()); | 46 gesture_target_.get()); |
| 47 | 47 |
| 48 if (result == SyntheticGestureNew::GESTURE_RUNNING) { | 48 if (result == SyntheticGesture::GESTURE_RUNNING) { |
| 49 gesture_target_->SetNeedsFlush(); | 49 gesture_target_->SetNeedsFlush(); |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 | 52 |
| 53 StopGesture(*pending_gesture_queue_.front(), result); | 53 StopGesture(*pending_gesture_queue_.front(), result); |
| 54 pending_gesture_queue_.erase(pending_gesture_queue_.begin()); | 54 pending_gesture_queue_.erase(pending_gesture_queue_.begin()); |
| 55 | 55 |
| 56 if (!pending_gesture_queue_.empty()) { | 56 if (!pending_gesture_queue_.empty()) { |
| 57 StartGesture(*pending_gesture_queue_.front()); | 57 StartGesture(*pending_gesture_queue_.front()); |
| 58 } else { | 58 } else { |
| 59 // Reset last_tick_time_ so that we don't use an old value when a new | 59 // Reset last_tick_time_ so that we don't use an old value when a new |
| 60 // gestures is queued. | 60 // gestures is queued. |
| 61 last_tick_time_ = base::TimeTicks(); | 61 last_tick_time_ = base::TimeTicks(); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void SyntheticGestureControllerNew::StartGesture( | 65 void SyntheticGestureController::StartGesture(const SyntheticGesture& gesture) { |
| 66 const SyntheticGestureNew& gesture) { | |
| 67 TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running", | 66 TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running", |
| 68 &gesture); | 67 &gesture); |
| 69 gesture_target_->SetNeedsFlush(); | 68 gesture_target_->SetNeedsFlush(); |
| 70 } | 69 } |
| 71 | 70 |
| 72 void SyntheticGestureControllerNew::StopGesture( | 71 void SyntheticGestureController::StopGesture( |
| 73 const SyntheticGestureNew& gesture, SyntheticGestureNew::Result result) { | 72 const SyntheticGesture& gesture, SyntheticGesture::Result result) { |
| 74 DCHECK_NE(result, SyntheticGestureNew::GESTURE_RUNNING); | 73 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); |
| 75 TRACE_EVENT_ASYNC_END0("benchmark", "SyntheticGestureController::running", | 74 TRACE_EVENT_ASYNC_END0("benchmark", "SyntheticGestureController::running", |
| 76 &gesture); | 75 &gesture); |
| 77 | 76 |
| 78 gesture_target_->OnSyntheticGestureCompleted(result); | 77 gesture_target_->OnSyntheticGestureCompleted(result); |
| 79 } | 78 } |
| 80 | 79 |
| 81 } // namespace content | 80 } // namespace content |
| OLD | NEW |