author Botond Ballo <>
Fri, 20 Apr 2018 18:42:08 -0400
changeset 472036 f6f3318816787873baf0a0c83c90a42bec1f389c
child 472039 8c7c5f3460062a19cc709a772c7586977af3d32b
permissions -rw-r--r--
Bug 1448439 - Add an AndroidFlingPhysics class containing an implementation of Chrome's fling physics on Android. r=kats MozReview-Commit-ID: 509Cl04rozm

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef mozilla_layers_AndroidFlingPhysics_h_
#define mozilla_layers_AndroidFlingPhysics_h_

#include "AsyncPanZoomController.h"
#include "Units.h"
#include "gfxPrefs.h"
#include "mozilla/Assertions.h"

namespace mozilla {
namespace layers {

class AndroidFlingPhysics {
  void Init(const ParentLayerPoint& aVelocity);
  void Sample(const TimeDuration& aDelta,
              ParentLayerPoint* aOutVelocity,
              ParentLayerPoint* aOutOffset);

  static void InitializeGlobalState();
  // Returns false if the animation should end.
  bool SampleImpl(const TimeDuration& aDelta, float* aOutVelocity);

  // Information pertaining to the current fling.
  // This is initialized on each call to Init().
  ParentLayerCoord mVelocity;  // diagonal velocity (length of velocity vector)
  TimeDuration mTargetDuration;
  TimeDuration mDurationSoFar;
  ParentLayerPoint mLastPos;
  ParentLayerPoint mCurrentPos;
  ParentLayerCoord mTargetDistance;  // diagonal distance
  ParentLayerPoint mTargetPos;  // really a target *offset* relative to the
                                // start position, which we don't track
  ParentLayerPoint mDeltaNorm;  // mTargetPos with length normalized to 1

} // namespace layers
} // namespace mozilla

#endif // mozilla_layers_AndroidFlingPhysics_h_