Commit 6c944694 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Use MobileScroller instead of cloning it.

Chromecast wants to scroll exactly like Android and for that
the code cloned the mobile scrolling code, but simpler and
easier and with less code and fewer jumbo compilation errors
is to just use the existing code directly.

Only a minor code difference existed and that is controlled with
a conditional statement instead now.

Bug: 813911
Change-Id: I9d037da9b58c1ad0916dc22ee194328c113075cd
Reviewed-on: https://chromium-review.googlesource.com/1136541Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarKevin Schoedel <kpschoedel@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#576035}
parent ec63e94d
......@@ -151,13 +151,6 @@ component("events_base") {
"Carbon.framework",
]
}
if (is_chromecast && !is_android) {
sources += [
"chromecast/scroller.cc",
"chromecast/scroller.h",
]
}
}
component("events") {
......
This diff is collapsed.
// Copyright 2018 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.
#ifndef UI_EVENTS_CHROMECAST_SCROLLER_H_
#define UI_EVENTS_CHROMECAST_SCROLLER_H_
#include "base/time/time.h"
#include "ui/events/events_base_export.h"
#include "ui/events/gesture_curve.h"
#include "ui/gfx/geometry/vector2d_f.h"
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 {
public:
struct Config {
Config();
// Controls fling deceleration. Defaults to 0.015f.
float fling_friction;
// Controls fling accumulation. Defaults to disabled.
bool flywheel_enabled;
};
explicit Scroller(const Config& config);
~Scroller() override;
// GestureCurve implementation.
bool ComputeScrollOffset(base::TimeTicks time,
gfx::Vector2dF* offset,
gfx::Vector2dF* velocity) override;
// Start scrolling by providing a starting point and the distance to travel.
// The default value of 250 milliseconds will be used for the duration.
void StartScroll(float start_x,
float start_y,
float dx,
float dy,
base::TimeTicks start_time);
// Start scrolling by providing a starting point, the distance to travel,
// and the duration of the scroll.
void StartScroll(float start_x,
float start_y,
float dx,
float dy,
base::TimeTicks start_time,
base::TimeDelta duration);
// Start scrolling based on a fling gesture. The distance travelled will
// depend on the initial velocity of the fling.
void 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);
// Extend the scroll animation by |extend|. This allows a running animation
// to scroll further and longer when used with |SetFinalX()| or |SetFinalY()|.
void ExtendDuration(base::TimeDelta extend);
void SetFinalX(float new_x);
void SetFinalY(float new_y);
// Stops the animation. Contrary to |ForceFinished()|, aborting the animation
// causes the scroller to move to the final x and y position.
void AbortAnimation();
// Terminate the scroll without affecting the current x and y positions.
void ForceFinished(bool finished);
// Returns whether the scroller has finished scrolling.
bool IsFinished() const;
// Returns the time elapsed since the beginning of the scrolling.
base::TimeDelta GetTimePassed() const;
// Returns how long the scroll event will take.
base::TimeDelta GetDuration() const;
float GetStartX() const;
float GetStartY() const;
float GetCurrX() const;
float GetCurrY() const;
float GetCurrVelocity() const;
float GetCurrVelocityX() const;
float GetCurrVelocityY() const;
float GetFinalX() const;
float GetFinalY() const;
bool IsScrollingInDirection(float xvel, float yvel) const;
private:
enum Mode {
UNDEFINED,
SCROLL_MODE,
FLING_MODE,
};
bool ComputeScrollOffsetInternal(base::TimeTicks time);
void RecomputeDeltas();
double GetSplineDeceleration(float velocity) const;
base::TimeDelta GetSplineFlingDuration(float velocity) const;
double GetSplineFlingDistance(float velocity) const;
Mode mode_;
float start_x_;
float start_y_;
float final_x_;
float final_y_;
float min_x_;
float max_x_;
float min_y_;
float max_y_;
float curr_x_;
float curr_y_;
base::TimeTicks start_time_;
base::TimeTicks curr_time_;
base::TimeDelta duration_;
double duration_seconds_reciprocal_;
float delta_x_;
float delta_x_norm_;
float delta_y_;
float delta_y_norm_;
bool finished_;
bool flywheel_enabled_;
float velocity_;
float curr_velocity_;
float distance_;
float fling_friction_;
float deceleration_;
float tuning_coeff_;
};
} // namespace ui
#endif // UI_EVENTS_CHROMECAST_SCROLLER_H_
......@@ -6,7 +6,7 @@
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/chromecast/scroller.h"
#include "ui/events/mobile_scroller.h"
namespace ui {
namespace {
......@@ -19,8 +19,8 @@ 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
......@@ -28,7 +28,7 @@ Scroller::Config DefaultConfig() {
class ScrollerTest : public testing::Test {};
TEST_F(ScrollerTest, Scroll) {
Scroller scroller(DefaultConfig());
MobileScroller scroller(DefaultConfig());
base::TimeTicks start_time = base::TimeTicks::Now();
// Start a scroll and verify initialized values.
......@@ -99,7 +99,7 @@ TEST_F(ScrollerTest, Scroll) {
}
TEST_F(ScrollerTest, Fling) {
Scroller scroller(DefaultConfig());
MobileScroller scroller(DefaultConfig());
base::TimeTicks start_time = base::TimeTicks::Now();
// Start a fling and verify initialized values.
......
......@@ -2,12 +2,18 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/chromecast_build.gni")
source_set("blink") {
sources = [
"web_gesture_curve_impl.cc",
"web_gesture_curve_impl.h",
]
if (is_chromecast && !is_android) {
defines = [ "USE_MOBILE_FLING_CURVE" ]
}
deps = [
"//base",
"//third_party/blink/public:blink_headers",
......
......@@ -19,10 +19,6 @@
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
#if !defined(OS_ANDROID) && defined(CHROMECAST_BUILD)
#include "ui/events/chromecast/scroller.h"
#endif
using blink::WebGestureCurve;
namespace ui {
......@@ -37,21 +33,22 @@ std::unique_ptr<GestureCurve> CreateDefaultPlatformCurve(
base::TimeTicks());
}
#if !defined(OS_ANDROID) && 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());
return std::move(scroller);
#else
#ifdef USE_MOBILE_FLING_CURVE
use_mobile_fling_curve = true;
#endif
if (use_mobile_fling_curve) {
auto scroller = std::make_unique<MobileScroller>(MobileScroller::Config());
MobileScroller::Config config;
#ifdef USE_MOBILE_FLING_CURVE
config.chromecast_optimized = true;
#endif
auto scroller = std::make_unique<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
}
} // namespace
......
......@@ -159,7 +159,9 @@ base::LazyInstance<SplineConstants>::Leaky g_spline_constants =
} // namespace
MobileScroller::Config::Config()
: fling_friction(kDefaultFriction), flywheel_enabled(false) {}
: fling_friction(kDefaultFriction),
flywheel_enabled(false),
chromecast_optimized(false) {}
MobileScroller::MobileScroller(const Config& config)
: mode_(UNDEFINED),
......@@ -185,7 +187,8 @@ MobileScroller::MobileScroller(const Config& config)
distance_(0),
fling_friction_(config.fling_friction),
deceleration_(ComputeDeceleration(fling_friction_)),
tuning_coeff_(ComputeDeceleration(0.84f)) {}
tuning_coeff_(
ComputeDeceleration(config.chromecast_optimized ? 0.9f : 0.84f)) {}
MobileScroller::~MobileScroller() {}
......
......@@ -25,6 +25,10 @@ class EVENTS_BASE_EXPORT MobileScroller : public GestureCurve {
// Controls fling accumulation. Defaults to disabled.
bool flywheel_enabled;
// Controls whether to use chromecast optimized
// scrolling. Defaults to false, mimic normal Android scrolling.
bool chromecast_optimized;
};
explicit MobileScroller(const Config& config);
......
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