| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/browser/renderer_host/synthetic_gesture_controller.h" | |
| 6 | |
| 7 #include "base/debug/trace_event.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "content/common/view_messages.h" | |
| 10 #include "content/port/browser/render_widget_host_view_port.h" | |
| 11 #include "content/port/browser/synthetic_gesture.h" | |
| 12 #include "content/public/browser/render_widget_host.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // How many milliseconds apart synthetic scroll messages should be sent. | |
| 19 const int kSyntheticGestureMessageIntervalMs = 7; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 SyntheticGestureController::SyntheticGestureController() | |
| 24 : rwh_(NULL) { | |
| 25 } | |
| 26 | |
| 27 SyntheticGestureController::~SyntheticGestureController() { | |
| 28 } | |
| 29 | |
| 30 void SyntheticGestureController::BeginSmoothScroll( | |
| 31 RenderWidgetHostViewPort* view, | |
| 32 const ViewHostMsg_BeginSmoothScroll_Params& params) { | |
| 33 if (pending_synthetic_gesture_.get()) | |
| 34 return; | |
| 35 | |
| 36 rwh_ = view->GetRenderWidgetHost(); | |
| 37 pending_synthetic_gesture_ = view->CreateSmoothScrollGesture( | |
| 38 params.scroll_down, | |
| 39 params.pixels_to_scroll, | |
| 40 params.mouse_event_x, | |
| 41 params.mouse_event_y); | |
| 42 | |
| 43 TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running", | |
| 44 pending_synthetic_gesture_); | |
| 45 timer_.Start(FROM_HERE, GetSyntheticGestureMessageInterval(), this, | |
| 46 &SyntheticGestureController::OnTimer); | |
| 47 } | |
| 48 | |
| 49 void SyntheticGestureController::BeginPinch( | |
| 50 RenderWidgetHostViewPort* view, | |
| 51 const ViewHostMsg_BeginPinch_Params& params) { | |
| 52 if (pending_synthetic_gesture_.get()) | |
| 53 return; | |
| 54 | |
| 55 rwh_ = view->GetRenderWidgetHost(); | |
| 56 pending_synthetic_gesture_ = view->CreatePinchGesture( | |
| 57 params.zoom_in, | |
| 58 params.pixels_to_move, | |
| 59 params.anchor_x, | |
| 60 params.anchor_y); | |
| 61 | |
| 62 TRACE_EVENT_ASYNC_BEGIN0("benchmark", "SyntheticGestureController::running", | |
| 63 pending_synthetic_gesture_); | |
| 64 timer_.Start(FROM_HERE, GetSyntheticGestureMessageInterval(), this, | |
| 65 &SyntheticGestureController::OnTimer); | |
| 66 } | |
| 67 | |
| 68 base::TimeDelta | |
| 69 SyntheticGestureController::GetSyntheticGestureMessageInterval() const { | |
| 70 return base::TimeDelta::FromMilliseconds(kSyntheticGestureMessageIntervalMs); | |
| 71 } | |
| 72 | |
| 73 void SyntheticGestureController::OnTimer() { | |
| 74 base::TimeTicks now = base::TimeTicks::Now(); | |
| 75 if (!pending_synthetic_gesture_->ForwardInputEvents(now, rwh_)) { | |
| 76 timer_.Stop(); | |
| 77 TRACE_EVENT_ASYNC_END0("benchmark", "SyntheticGestureController::running", | |
| 78 pending_synthetic_gesture_); | |
| 79 pending_synthetic_gesture_ = NULL; | |
| 80 rwh_->Send(new ViewMsg_SyntheticGestureCompleted(rwh_->GetRoutingID())); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 } // namespace content | |
| OLD | NEW |