1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "content/test/web_gesture_curve_mock.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "content/test/weburl_loader_mock_factory.h"
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebFloatSize.h"
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebGestureCurveTarget.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)WebGestureCurveMock::WebGestureCurveMock(const blink::WebFloatPoint& velocity,
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const blink::WebSize& cumulative_scroll)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : velocity_(velocity),
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cumulative_scroll_(cumulative_scroll) {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebGestureCurveMock::~WebGestureCurveMock() {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebGestureCurveMock::apply(double time,
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                blink::WebGestureCurveTarget* target) {
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebSize displacement(velocity_.x * time, velocity_.y * time);
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebFloatSize increment(displacement.width - cumulative_scroll_.width,
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      displacement.height - cumulative_scroll_.height);
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  cumulative_scroll_ = displacement;
26e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  blink::WebFloatSize velocity(velocity_.x, velocity_.y);
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // scrollBy() could delete this curve if the animation is over, so don't
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // touch any member variables after making that call.
29e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  target->scrollBy(increment, velocity);
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
32