This source file includes following definitions.
- GetScrollerConfig
- scroller_
- StartFling
- CancelFling
- apply
- CreateAndroidGestureCurve
#include "content/child/fling_animator_impl_android.h"
#include "base/logging.h"
#include "third_party/WebKit/public/platform/WebFloatSize.h"
#include "third_party/WebKit/public/platform/WebGestureCurveTarget.h"
#include "ui/gfx/android/view_configuration.h"
#include "ui/gfx/frame_time.h"
#include "ui/gfx/vector2d.h"
namespace content {
namespace {
gfx::Scroller::Config GetScrollerConfig() {
gfx::Scroller::Config config;
config.flywheel_enabled = false;
config.fling_friction = gfx::ViewConfiguration::GetScrollFriction();
return config;
}
}
FlingAnimatorImpl::FlingAnimatorImpl()
: is_active_(false),
scroller_(GetScrollerConfig()) {}
FlingAnimatorImpl::~FlingAnimatorImpl() {}
void FlingAnimatorImpl::StartFling(const gfx::PointF& velocity) {
DCHECK(velocity.x() || velocity.y());
if (is_active_)
CancelFling();
is_active_ = true;
scroller_.Fling(0,
0,
velocity.x(),
velocity.y(),
INT_MIN,
INT_MAX,
INT_MIN,
INT_MAX,
gfx::FrameTime::Now());
}
void FlingAnimatorImpl::CancelFling() {
if (!is_active_)
return;
is_active_ = false;
scroller_.AbortAnimation();
}
bool FlingAnimatorImpl::apply(double ,
blink::WebGestureCurveTarget* target) {
if (!scroller_.ComputeScrollOffset(gfx::FrameTime::Now())) {
is_active_ = false;
return false;
}
gfx::PointF current_position(scroller_.GetCurrX(), scroller_.GetCurrY());
gfx::Vector2dF scroll_amount(current_position - last_position_);
last_position_ = current_position;
return target->scrollBy(blink::WebFloatSize(scroll_amount),
blink::WebFloatSize(scroller_.GetCurrVelocityX(),
scroller_.GetCurrVelocityY()));
}
FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve(
const blink::WebFloatPoint& velocity,
const blink::WebSize&) {
FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl();
gesture_curve->StartFling(velocity);
return gesture_curve;
}
}