Commit e6a2c644 authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Use mobile-like flingging in tablet mode

When a Chromebook is flipped into tablet mode, scrolling
and gesture fling events should follow the same curve
used by android in order to have a smoother and more
fluid experience.

BUG=813911,822455

Change-Id: I39b42bdda08a3c20e1b7fab4d8f7e41c2a69b61a
Reviewed-on: https://chromium-review.googlesource.com/1087641Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarSahel Sharifymoghaddam <sahel@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568704}
parent bd4386f5
......@@ -249,6 +249,10 @@ void AwContentBrowserClient::RenderProcessWillLaunch(
host->AddFilter(new AwPrintingMessageFilter(host->GetID()));
}
bool AwContentBrowserClient::ShouldUseMobileFlingCurve() const {
return true;
}
bool AwContentBrowserClient::IsHandledURL(const GURL& url) {
if (!url.is_valid()) {
// We handle error cases.
......
......@@ -53,6 +53,7 @@ class AwContentBrowserClient : public content::ContentBrowserClient {
void RenderProcessWillLaunch(
content::RenderProcessHost* host,
service_manager::mojom::ServiceRequest* service_request) override;
bool ShouldUseMobileFlingCurve() const override;
bool IsHandledURL(const GURL& url) override;
bool ForceSniffingFileUrlsForHtml() override;
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
......
......@@ -316,6 +316,7 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
#include "chrome/browser/ui/ash/tablet_mode_client.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chromeos/chromeos_constants.h"
#include "chromeos/chromeos_features.h"
......@@ -1327,6 +1328,17 @@ GURL ChromeContentBrowserClient::GetEffectiveURL(
#endif
}
bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() const {
#if defined(OS_ANDROID)
return true;
#elif defined(OS_CHROMEOS)
return TabletModeClient::Get() &&
TabletModeClient::Get()->tablet_mode_enabled();
#else
return false;
#endif // defined(OS_ANDROID)
}
bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
content::BrowserContext* browser_context, const GURL& effective_url) {
// Non-extension, non-Instant URLs should generally use
......
......@@ -108,6 +108,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
bool AllowGpuLaunchRetryOnIOThread() override;
GURL GetEffectiveURL(content::BrowserContext* browser_context,
const GURL& url) override;
bool ShouldUseMobileFlingCurve() const override;
bool ShouldUseProcessPerSite(content::BrowserContext* browser_context,
const GURL& effective_url) override;
bool ShouldUseSpareRenderProcessHost(content::BrowserContext* browser_context,
......
......@@ -6,6 +6,8 @@
#include "base/trace_event/trace_event.h"
#include "content/browser/renderer_host/input/gesture_event_queue.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/blink/fling_booster.h"
......@@ -420,7 +422,8 @@ bool FlingController::UpdateCurrentFlingState(
ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
current_fling_parameters_.source_device,
current_fling_parameters_.velocity,
gfx::Vector2dF() /*initial_offset*/, false /*on_main_thread*/));
gfx::Vector2dF() /*initial_offset*/, false /*on_main_thread*/,
GetContentClient()->browser()->ShouldUseMobileFlingCurve()));
return true;
}
......
......@@ -672,7 +672,7 @@ BlinkPlatformImpl::CreateFlingAnimationCurve(
return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
device_source, gfx::Vector2dF(velocity.x, velocity.y),
gfx::Vector2dF(cumulative_scroll.width, cumulative_scroll.height),
IsMainThread());
IsMainThread(), false /*use_mobile_fling_curve*/);
}
bool BlinkPlatformImpl::AllowScriptExtensionForServiceWorker(
......
......@@ -80,6 +80,10 @@ GURL ContentBrowserClient::GetEffectiveURL(BrowserContext* browser_context,
return url;
}
bool ContentBrowserClient::ShouldUseMobileFlingCurve() const {
return false;
}
bool ContentBrowserClient::ShouldUseProcessPerSite(
BrowserContext* browser_context, const GURL& effective_url) {
return false;
......
......@@ -242,6 +242,10 @@ class CONTENT_EXPORT ContentBrowserClient {
virtual GURL GetEffectiveURL(BrowserContext* browser_context,
const GURL& url);
// Returns whether gesture fling events should use the mobile-behavior gesture
// curve for scrolling.
virtual bool ShouldUseMobileFlingCurve() const;
// Returns whether all instances of the specified effective URL should be
// rendered by the same process, rather than using process-per-site-instance.
virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context,
......
......@@ -92,8 +92,6 @@ source_set("platform_event") {
component("events_base") {
sources = [
"android/scroller.cc",
"android/scroller.h",
"base_event_utils.cc",
"base_event_utils.h",
"event_switches.cc",
......@@ -118,6 +116,8 @@ component("events_base") {
"keycodes/keyboard_code_conversion_win.cc",
"keycodes/keyboard_code_conversion_win.h",
"keycodes/keyboard_codes.h",
"mobile_scroller.cc",
"mobile_scroller.h",
]
defines = [ "EVENTS_BASE_IMPLEMENTATION" ]
......@@ -441,7 +441,6 @@ static_library("test_support") {
if (!is_ios) {
test("events_unittests") {
sources = [
"android/scroller_unittest.cc",
"blink/blink_event_util_unittest.cc",
"blink/fling_booster_unittest.cc",
"blink/input_handler_proxy_unittest.cc",
......@@ -474,6 +473,7 @@ if (!is_ios) {
"keycodes/dom/keycode_converter_unittest.cc",
"keycodes/keyboard_code_conversion_unittest.cc",
"keycodes/platform_key_map_win_unittest.cc",
"mobile_scroller_unittest.cc",
"mojo/struct_traits_unittest.cc",
"platform/platform_event_source_unittest.cc",
"scoped_target_handler_unittest.cc",
......
......@@ -15,14 +15,11 @@
#include "third_party/blink/public/platform/web_gesture_curve_target.h"
#include "ui/events/gestures/fixed_velocity_curve.h"
#include "ui/events/gestures/fling_curve.h"
#include "ui/events/mobile_scroller.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
#if defined(OS_ANDROID)
#include "ui/events/android/scroller.h"
#endif
#if !defined(OS_ANDROID) && defined(CHROMECAST_BUILD)
#include "ui/events/chromecast/scroller.h"
#endif
......@@ -34,25 +31,26 @@ namespace {
std::unique_ptr<GestureCurve> CreateDefaultPlatformCurve(
blink::WebGestureDevice device_source,
const gfx::Vector2dF& initial_velocity) {
const gfx::Vector2dF& initial_velocity,
bool use_mobile_fling_curve) {
if (device_source == blink::kWebGestureDeviceSyntheticAutoscroll) {
return std::make_unique<FixedVelocityCurve>(initial_velocity,
base::TimeTicks());
}
#if defined(OS_ANDROID) || defined(CHROMECAST_BUILD)
#if defined(CHROMECAST_BUILD)
auto scroller = std::make_unique<Scroller>(Scroller::Config());
scroller->Fling(0,
0,
initial_velocity.x(),
initial_velocity.y(),
INT_MIN,
INT_MAX,
INT_MIN,
INT_MAX,
base::TimeTicks());
scroller->Fling(0, 0, initial_velocity.x(), initial_velocity.y(), INT_MIN,
INT_MAX, INT_MIN, INT_MAX, base::TimeTicks());
return std::move(scroller);
#else
if (use_mobile_fling_curve) {
auto scroller = std::make_unique<MobileScroller>(MobileScroller::Config());
scroller->Fling(0, 0, initial_velocity.x(), initial_velocity.y(), INT_MIN,
INT_MAX, INT_MIN, INT_MAX, base::TimeTicks());
return std::move(scroller);
}
return std::make_unique<FlingCurve>(initial_velocity, base::TimeTicks());
#endif
}
......@@ -65,9 +63,11 @@ WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
blink::WebGestureDevice device_source,
const gfx::Vector2dF& initial_velocity,
const gfx::Vector2dF& initial_offset,
bool on_main_thread) {
bool on_main_thread,
bool use_mobile_fling_curve) {
return std::unique_ptr<WebGestureCurve>(new WebGestureCurveImpl(
CreateDefaultPlatformCurve(device_source, initial_velocity),
CreateDefaultPlatformCurve(device_source, initial_velocity,
use_mobile_fling_curve),
initial_offset, on_main_thread ? ThreadType::MAIN : ThreadType::IMPL));
}
......
......@@ -24,7 +24,8 @@ class WebGestureCurveImpl : public blink::WebGestureCurve {
blink::WebGestureDevice device_source,
const gfx::Vector2dF& initial_velocity,
const gfx::Vector2dF& initial_offset,
bool on_main_thread);
bool on_main_thread,
bool use_mobile_fling_curve);
static std::unique_ptr<blink::WebGestureCurve> CreateFromUICurveForTesting(
std::unique_ptr<GestureCurve> curve,
const gfx::Vector2dF& initial_offset);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/events/android/scroller.h"
#include "ui/events/mobile_scroller.h"
#include <cmath>
......@@ -158,11 +158,10 @@ base::LazyInstance<SplineConstants>::Leaky g_spline_constants =
} // namespace
Scroller::Config::Config()
: fling_friction(kDefaultFriction), flywheel_enabled(false) {
}
MobileScroller::Config::Config()
: fling_friction(kDefaultFriction), flywheel_enabled(false) {}
Scroller::Scroller(const Config& config)
MobileScroller::MobileScroller(const Config& config)
: mode_(UNDEFINED),
start_x_(0),
start_y_(0),
......@@ -186,15 +185,13 @@ Scroller::Scroller(const Config& config)
distance_(0),
fling_friction_(config.fling_friction),
deceleration_(ComputeDeceleration(fling_friction_)),
tuning_coeff_(ComputeDeceleration(0.84f)) {
}
tuning_coeff_(ComputeDeceleration(0.84f)) {}
Scroller::~Scroller() {
}
MobileScroller::~MobileScroller() {}
bool Scroller::ComputeScrollOffset(base::TimeTicks time,
gfx::Vector2dF* offset,
gfx::Vector2dF* velocity) {
bool MobileScroller::ComputeScrollOffset(base::TimeTicks time,
gfx::Vector2dF* offset,
gfx::Vector2dF* velocity) {
DCHECK(offset);
DCHECK(velocity);
if (!ComputeScrollOffsetInternal(time)) {
......@@ -208,25 +205,21 @@ bool Scroller::ComputeScrollOffset(base::TimeTicks time,
return true;
}
void Scroller::StartScroll(float start_x,
float start_y,
float dx,
float dy,
base::TimeTicks start_time) {
StartScroll(start_x,
start_y,
dx,
dy,
start_time,
void MobileScroller::StartScroll(float start_x,
float start_y,
float dx,
float dy,
base::TimeTicks start_time) {
StartScroll(start_x, start_y, dx, dy, start_time,
base::TimeDelta::FromMilliseconds(kDefaultDurationMs));
}
void Scroller::StartScroll(float start_x,
float start_y,
float dx,
float dy,
base::TimeTicks start_time,
base::TimeDelta duration) {
void MobileScroller::StartScroll(float start_x,
float start_y,
float dx,
float dy,
base::TimeTicks start_time,
base::TimeDelta duration) {
DCHECK_GT(duration, base::TimeDelta());
mode_ = SCROLL_MODE;
finished_ = false;
......@@ -241,15 +234,15 @@ void Scroller::StartScroll(float start_x,
curr_time_ = start_time_;
}
void Scroller::Fling(float start_x,
float start_y,
float velocity_x,
float velocity_y,
float min_x,
float max_x,
float min_y,
float max_y,
base::TimeTicks start_time) {
void MobileScroller::Fling(float start_x,
float start_y,
float velocity_x,
float velocity_y,
float min_x,
float max_x,
float min_y,
float max_y,
base::TimeTicks start_time) {
DCHECK(velocity_x || velocity_y);
// Continue a scroll or fling in progress.
......@@ -297,26 +290,26 @@ void Scroller::Fling(float start_x,
RecomputeDeltas();
}
void Scroller::ExtendDuration(base::TimeDelta extend) {
void MobileScroller::ExtendDuration(base::TimeDelta extend) {
base::TimeDelta passed = GetTimePassed();
duration_ = passed + extend;
duration_seconds_reciprocal_ = 1.0 / duration_.InSecondsF();
finished_ = false;
}
void Scroller::SetFinalX(float new_x) {
void MobileScroller::SetFinalX(float new_x) {
final_x_ = new_x;
finished_ = false;
RecomputeDeltas();
}
void Scroller::SetFinalY(float new_y) {
void MobileScroller::SetFinalY(float new_y) {
final_y_ = new_y;
finished_ = false;
RecomputeDeltas();
}
void Scroller::AbortAnimation() {
void MobileScroller::AbortAnimation() {
curr_x_ = final_x_;
curr_y_ = final_y_;
curr_velocity_ = 0;
......@@ -324,31 +317,31 @@ void Scroller::AbortAnimation() {
finished_ = true;
}
void Scroller::ForceFinished(bool finished) {
void MobileScroller::ForceFinished(bool finished) {
finished_ = finished;
}
bool Scroller::IsFinished() const {
bool MobileScroller::IsFinished() const {
return finished_;
}
base::TimeDelta Scroller::GetTimePassed() const {
base::TimeDelta MobileScroller::GetTimePassed() const {
return curr_time_ - start_time_;
}
base::TimeDelta Scroller::GetDuration() const {
base::TimeDelta MobileScroller::GetDuration() const {
return duration_;
}
float Scroller::GetCurrX() const {
float MobileScroller::GetCurrX() const {
return curr_x_;
}
float Scroller::GetCurrY() const {
float MobileScroller::GetCurrY() const {
return curr_y_;
}
float Scroller::GetCurrVelocity() const {
float MobileScroller::GetCurrVelocity() const {
if (finished_)
return 0;
if (mode_ == FLING_MODE)
......@@ -356,36 +349,36 @@ float Scroller::GetCurrVelocity() const {
return velocity_ - deceleration_ * GetTimePassed().InSecondsF() * 0.5f;
}
float Scroller::GetCurrVelocityX() const {
float MobileScroller::GetCurrVelocityX() const {
return delta_x_norm_ * GetCurrVelocity();
}
float Scroller::GetCurrVelocityY() const {
float MobileScroller::GetCurrVelocityY() const {
return delta_y_norm_ * GetCurrVelocity();
}
float Scroller::GetStartX() const {
float MobileScroller::GetStartX() const {
return start_x_;
}
float Scroller::GetStartY() const {
float MobileScroller::GetStartY() const {
return start_y_;
}
float Scroller::GetFinalX() const {
float MobileScroller::GetFinalX() const {
return final_x_;
}
float Scroller::GetFinalY() const {
float MobileScroller::GetFinalY() const {
return final_y_;
}
bool Scroller::IsScrollingInDirection(float xvel, float yvel) const {
bool MobileScroller::IsScrollingInDirection(float xvel, float yvel) const {
return !finished_ && Signum(xvel) == Signum(delta_x_) &&
Signum(yvel) == Signum(delta_y_);
}
bool Scroller::ComputeScrollOffsetInternal(base::TimeTicks time) {
bool MobileScroller::ComputeScrollOffsetInternal(base::TimeTicks time) {
if (finished_)
return false;
......@@ -420,8 +413,8 @@ bool Scroller::ComputeScrollOffsetInternal(base::TimeTicks time) {
case FLING_MODE: {
float distance_coef = 1.f;
float velocity_coef = 0.f;
g_spline_constants.Get().CalculateCoefficients(
u, &distance_coef, &velocity_coef);
g_spline_constants.Get().CalculateCoefficients(u, &distance_coef,
&velocity_coef);
curr_velocity_ = velocity_coef * distance_ * duration_seconds_reciprocal_;
......@@ -441,7 +434,7 @@ bool Scroller::ComputeScrollOffsetInternal(base::TimeTicks time) {
return !finished_;
}
void Scroller::RecomputeDeltas() {
void MobileScroller::RecomputeDeltas() {
delta_x_ = final_x_ - start_x_;
delta_y_ = final_y_ - start_y_;
......@@ -454,12 +447,12 @@ void Scroller::RecomputeDeltas() {
}
}
double Scroller::GetSplineDeceleration(float velocity) const {
double MobileScroller::GetSplineDeceleration(float velocity) const {
return std::log(kInflexion * std::abs(velocity) /
(fling_friction_ * tuning_coeff_));
}
base::TimeDelta Scroller::GetSplineFlingDuration(float velocity) const {
base::TimeDelta MobileScroller::GetSplineFlingDuration(float velocity) const {
const double l = GetSplineDeceleration(velocity);
const double decel_minus_one = kDecelerationRate - 1.0;
const double time_seconds = std::exp(l / decel_minus_one);
......@@ -467,7 +460,7 @@ base::TimeDelta Scroller::GetSplineFlingDuration(float velocity) const {
base::Time::kMicrosecondsPerSecond);
}
double Scroller::GetSplineFlingDistance(float velocity) const {
double MobileScroller::GetSplineFlingDistance(float velocity) const {
const double l = GetSplineDeceleration(velocity);
const double decel_minus_one = kDecelerationRate - 1.0;
return fling_friction_ * tuning_coeff_ *
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_EVENTS_ANDROID_SCROLLER_H_
#define UI_EVENTS_ANDROID_SCROLLER_H_
#ifndef UI_EVENTS_MOBILE_SCROLLER_H_
#define UI_EVENTS_MOBILE_SCROLLER_H_
#include "base/time/time.h"
#include "ui/events/events_base_export.h"
......@@ -15,9 +15,9 @@ namespace ui {
// Native port of android.widget.Scroller.
// * Change-Id: I4365946f890a76fcfa78ca9d69f2a8e0848095a9
// * Please update the Change-Id as upstream Android changes are pulled.
class EVENTS_BASE_EXPORT Scroller : public GestureCurve {
class EVENTS_BASE_EXPORT MobileScroller : public GestureCurve {
public:
struct Config {
struct EVENTS_BASE_EXPORT Config {
Config();
// Controls fling deceleration. Defaults to 0.015f.
......@@ -27,8 +27,8 @@ class EVENTS_BASE_EXPORT Scroller : public GestureCurve {
bool flywheel_enabled;
};
explicit Scroller(const Config& config);
~Scroller() override;
explicit MobileScroller(const Config& config);
~MobileScroller() override;
// GestureCurve implementation.
bool ComputeScrollOffset(base::TimeTicks time,
......@@ -148,4 +148,4 @@ class EVENTS_BASE_EXPORT Scroller : public GestureCurve {
} // namespace ui
#endif // UI_EVENTS_ANDROID_SCROLLER_H_
#endif // UI_EVENTS_MOBILE_SCROLLER_H_
......@@ -6,7 +6,7 @@
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/android/scroller.h"
#include "ui/events/mobile_scroller.h"
namespace ui {
namespace {
......@@ -19,24 +19,21 @@ const float kDefaultVelocityX = -350.f;
const float kDefaultVelocityY = 220.f;
const float kEpsilon = 1e-3f;
Scroller::Config DefaultConfig() {
return Scroller::Config();
MobileScroller::Config DefaultConfig() {
return MobileScroller::Config();
}
} // namespace
class ScrollerTest : public testing::Test {};
using MobileScrollerTest = testing::Test;
TEST_F(ScrollerTest, Scroll) {
Scroller scroller(DefaultConfig());
TEST_F(MobileScrollerTest, Scroll) {
MobileScroller scroller(DefaultConfig());
base::TimeTicks start_time = base::TimeTicks::Now();
// Start a scroll and verify initialized values.
scroller.StartScroll(kDefaultStartX,
kDefaultStartY,
kDefaultDeltaX,
kDefaultDeltaY,
start_time);
scroller.StartScroll(kDefaultStartX, kDefaultStartY, kDefaultDeltaX,
kDefaultDeltaY, start_time);
EXPECT_EQ(kDefaultStartX, scroller.GetStartX());
EXPECT_EQ(kDefaultStartY, scroller.GetStartY());
......@@ -50,8 +47,8 @@ TEST_F(ScrollerTest, Scroll) {
// Advance halfway through the scroll.
const base::TimeDelta scroll_duration = scroller.GetDuration();
gfx::Vector2dF offset, velocity;
EXPECT_TRUE(scroller.ComputeScrollOffset(
start_time + scroll_duration / 2, &offset, &velocity));
EXPECT_TRUE(scroller.ComputeScrollOffset(start_time + scroll_duration / 2,
&offset, &velocity));
// Ensure we've moved in the direction of the delta, but have yet to reach
// the target.
......@@ -72,16 +69,16 @@ TEST_F(ScrollerTest, Scroll) {
float curr_y = offset.y();
float curr_velocity_x = velocity.x();
float curr_velocity_y = velocity.y();
EXPECT_TRUE(scroller.ComputeScrollOffset(
start_time + scroll_duration / 2, &offset, &velocity));
EXPECT_TRUE(scroller.ComputeScrollOffset(start_time + scroll_duration / 2,
&offset, &velocity));
EXPECT_EQ(curr_x, offset.x());
EXPECT_EQ(curr_y, offset.y());
EXPECT_EQ(curr_velocity_x, velocity.x());
EXPECT_EQ(curr_velocity_y, velocity.y());
// Advance to the end.
EXPECT_FALSE(scroller.ComputeScrollOffset(
start_time + scroll_duration, &offset, &velocity));
EXPECT_FALSE(scroller.ComputeScrollOffset(start_time + scroll_duration,
&offset, &velocity));
EXPECT_EQ(scroller.GetFinalX(), offset.x());
EXPECT_EQ(scroller.GetFinalY(), offset.y());
EXPECT_TRUE(scroller.IsFinished());
......@@ -90,27 +87,21 @@ TEST_F(ScrollerTest, Scroll) {
EXPECT_NEAR(0.f, velocity.y(), kEpsilon);
// Try to advance further; nothing should change.
EXPECT_FALSE(scroller.ComputeScrollOffset(
start_time + scroll_duration * 2, &offset, &velocity));
EXPECT_FALSE(scroller.ComputeScrollOffset(start_time + scroll_duration * 2,
&offset, &velocity));
EXPECT_EQ(scroller.GetFinalX(), offset.x());
EXPECT_EQ(scroller.GetFinalY(), offset.y());
EXPECT_TRUE(scroller.IsFinished());
EXPECT_EQ(scroll_duration, scroller.GetTimePassed());
}
TEST_F(ScrollerTest, Fling) {
Scroller scroller(DefaultConfig());
TEST_F(MobileScrollerTest, Fling) {
MobileScroller scroller(DefaultConfig());
base::TimeTicks start_time = base::TimeTicks::Now();
// Start a fling and verify initialized values.
scroller.Fling(kDefaultStartX,
kDefaultStartY,
kDefaultVelocityX,
kDefaultVelocityY,
INT_MIN,
INT_MAX,
INT_MIN,
INT_MAX,
scroller.Fling(kDefaultStartX, kDefaultStartY, kDefaultVelocityX,
kDefaultVelocityY, INT_MIN, INT_MAX, INT_MIN, INT_MAX,
start_time);
EXPECT_EQ(kDefaultStartX, scroller.GetStartX());
......@@ -125,8 +116,8 @@ TEST_F(ScrollerTest, Fling) {
// Advance halfway through the fling.
const base::TimeDelta scroll_duration = scroller.GetDuration();
gfx::Vector2dF offset, velocity;
scroller.ComputeScrollOffset(
start_time + scroll_duration / 2, &offset, &velocity);
scroller.ComputeScrollOffset(start_time + scroll_duration / 2, &offset,
&velocity);
// Ensure we've moved in the direction of the velocity, but have yet to reach
// the target.
......@@ -149,16 +140,16 @@ TEST_F(ScrollerTest, Fling) {
float curr_y = offset.y();
float curr_velocity_x = velocity.x();
float curr_velocity_y = velocity.y();
EXPECT_TRUE(scroller.ComputeScrollOffset(
start_time + scroll_duration / 2, &offset, &velocity));
EXPECT_TRUE(scroller.ComputeScrollOffset(start_time + scroll_duration / 2,
&offset, &velocity));
EXPECT_EQ(curr_x, offset.x());
EXPECT_EQ(curr_y, offset.y());
EXPECT_EQ(curr_velocity_x, velocity.x());
EXPECT_EQ(curr_velocity_y, velocity.y());
// Advance to the end.
EXPECT_FALSE(scroller.ComputeScrollOffset(
start_time + scroll_duration, &offset, &velocity));
EXPECT_FALSE(scroller.ComputeScrollOffset(start_time + scroll_duration,
&offset, &velocity));
EXPECT_EQ(scroller.GetFinalX(), offset.x());
EXPECT_EQ(scroller.GetFinalY(), offset.y());
EXPECT_TRUE(scroller.IsFinished());
......@@ -167,8 +158,8 @@ TEST_F(ScrollerTest, Fling) {
EXPECT_NEAR(0.f, velocity.y(), kEpsilon);
// Try to advance further; nothing should change.
EXPECT_FALSE(scroller.ComputeScrollOffset(
start_time + scroll_duration * 2, &offset, &velocity));
EXPECT_FALSE(scroller.ComputeScrollOffset(start_time + scroll_duration * 2,
&offset, &velocity));
EXPECT_EQ(scroller.GetFinalX(), offset.x());
EXPECT_EQ(scroller.GetFinalY(), offset.y());
EXPECT_TRUE(scroller.IsFinished());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment