summaryrefslogtreecommitdiffstats
path: root/webkit/glue/fling_curve_configuration.cc
blob: 1b0a63a53de03a3514e9f04e746426f5bd08cbdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/glue/fling_curve_configuration.h"

#include "base/logging.h"
#include "third_party/WebKit/public/platform/WebGestureCurve.h"
#include "webkit/glue/touch_fling_gesture_curve.h"

namespace webkit_glue {

FlingCurveConfiguration::FlingCurveConfiguration() { }

FlingCurveConfiguration::~FlingCurveConfiguration() { }

void FlingCurveConfiguration::SetCurveParameters(
    const std::vector<float>& new_touchpad,
    const std::vector<float>& new_touchscreen) {
  DCHECK(new_touchpad.size() >= 3);
  DCHECK(new_touchscreen.size() >= 3);
  base::AutoLock scoped_lock(lock_);
  touchpad_coefs_ = new_touchpad;
  touchscreen_coefs_ = new_touchscreen;
}

WebKit::WebGestureCurve* FlingCurveConfiguration::CreateCore(
    const std::vector<float>& coefs,
    const WebKit::WebFloatPoint& velocity,
    const WebKit::WebSize& cumulativeScroll) {
  float p0, p1, p2;

  {
    base::AutoLock scoped_lock(lock_);
    p0 = coefs[0];
    p1 = coefs[1];
    p2 = coefs[2];
  }

  return TouchFlingGestureCurve::Create(velocity, p0, p1, p2, cumulativeScroll);
}

WebKit::WebGestureCurve* FlingCurveConfiguration::CreateForTouchPad(
    const WebKit::WebFloatPoint& velocity,
    const WebKit::WebSize& cumulativeScroll) {
  return CreateCore(touchpad_coefs_, velocity, cumulativeScroll);
}

WebKit::WebGestureCurve* FlingCurveConfiguration::CreateForTouchScreen(
    const WebKit::WebFloatPoint& velocity,
    const WebKit::WebSize& cumulativeScroll) {
  return CreateCore(touchscreen_coefs_, velocity, cumulativeScroll);
}

} // namespace webkit_glue