Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / smooth_scroll_gesture_controller.cc
blob6583bc8c17a1c21b19e153114937e45a99a509ea
1 // Copyright (c) 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.
5 #include "content/browser/renderer_host/smooth_scroll_gesture_controller.h"
7 #include "base/debug/trace_event.h"
8 #include "base/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/smooth_scroll_gesture.h"
12 #include "content/public/browser/render_widget_host.h"
14 namespace content {
16 namespace {
18 // How many milliseconds apart synthetic scroll messages should be sent.
19 const int kSyntheticScrollMessageIntervalMs = 7;
21 } // namespace
23 SmoothScrollGestureController::SmoothScrollGestureController()
24 : rwh_(NULL) {
27 SmoothScrollGestureController::~SmoothScrollGestureController() {
30 void SmoothScrollGestureController::BeginSmoothScroll(
31 RenderWidgetHostViewPort* view,
32 const ViewHostMsg_BeginSmoothScroll_Params& params) {
33 if (pending_smooth_scroll_gesture_.get())
34 return;
36 rwh_ = view->GetRenderWidgetHost();
37 pending_smooth_scroll_gesture_ = view->CreateSmoothScrollGesture(
38 params.scroll_down,
39 params.pixels_to_scroll,
40 params.mouse_event_x,
41 params.mouse_event_y);
43 timer_.Start(FROM_HERE, GetSyntheticScrollMessageInterval(), this,
44 &SmoothScrollGestureController::OnTimer);
47 base::TimeDelta
48 SmoothScrollGestureController::GetSyntheticScrollMessageInterval() const {
49 return base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs);
52 void SmoothScrollGestureController::OnTimer() {
53 base::TimeTicks now = base::TimeTicks::Now();
54 if (!pending_smooth_scroll_gesture_->ForwardInputEvents(now, rwh_)) {
55 timer_.Stop();
56 pending_smooth_scroll_gesture_ = NULL;
57 rwh_->Send(new ViewMsg_SmoothScrollCompleted(rwh_->GetRoutingID()));
61 } // namespace content