Commit 967a10cb authored by Danton Vu's avatar Danton Vu Committed by Commit Bot

overview: Implement inertial scrolling for new tablet overview mode.

The overview grid should scroll by itself when flung.

Tests: 
Bug: 991599
Change-Id: If3534f841f56202389d3c96d2aeac5de84e3c9e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1752917
Commit-Queue: Danton Vu <dantonvu@google.com>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687358}
parent a94a4e87
......@@ -11,7 +11,9 @@
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_grid.h"
#include "ash/wm/overview/overview_utils.h"
#include "ui/compositor/compositor.h"
#include "ui/events/event.h"
#include "ui/events/gestures/fling_curve.h"
namespace ash {
......@@ -39,6 +41,7 @@ OverviewGridPreEventHandler::~OverviewGridPreEventHandler() {
auto* wallpaper_view = GetWallpaperViewForRoot(grid_->root_window());
if (wallpaper_view)
wallpaper_view->RemovePreTargetHandler(this);
EndFling();
}
void OverviewGridPreEventHandler::OnMouseEvent(ui::MouseEvent* event) {
......@@ -48,12 +51,21 @@ void OverviewGridPreEventHandler::OnMouseEvent(ui::MouseEvent* event) {
void OverviewGridPreEventHandler::OnGestureEvent(ui::GestureEvent* event) {
switch (event->type()) {
case ui::ET_GESTURE_TAP:
case ui::ET_GESTURE_TAP: {
HandleClickOrTap(event);
break;
}
case ui::ET_SCROLL_FLING_START: {
if (!ShouldUseTabletModeGridLayout())
return;
HandleFlingScroll(event);
event->SetHandled();
break;
}
case ui::ET_GESTURE_SCROLL_BEGIN: {
if (!ShouldUseTabletModeGridLayout())
return;
EndFling();
grid_->StartScroll();
event->SetHandled();
break;
......@@ -77,6 +89,29 @@ void OverviewGridPreEventHandler::OnGestureEvent(ui::GestureEvent* event) {
}
}
void OverviewGridPreEventHandler::OnAnimationStep(base::TimeTicks timestamp) {
// Updates |grid_| based on |offset| when |observed_compositor_| begins a new
// frame.
DCHECK(observed_compositor_);
gfx::Vector2dF offset;
// As a fling progresses, the velocity degenerates, and the difference in
// offset is passed into |grid_| as an updated scroll value.
bool fling =
fling_curve_->ComputeScrollOffset(timestamp, &offset, &fling_velocity_);
grid_->UpdateScrollOffset(offset.x() - fling_last_offset_.x());
fling_last_offset_ = offset;
if (!fling)
EndFling();
}
void OverviewGridPreEventHandler::OnCompositingShuttingDown(
ui::Compositor* compositor) {
DCHECK_EQ(compositor, observed_compositor_);
EndFling();
}
void OverviewGridPreEventHandler::HandleClickOrTap(ui::Event* event) {
CHECK_EQ(ui::EP_PRETARGET, event->phase());
// Events that happen while app list is sliding out during overview should
......@@ -86,4 +121,23 @@ void OverviewGridPreEventHandler::HandleClickOrTap(ui::Event* event) {
event->StopPropagation();
}
void OverviewGridPreEventHandler::HandleFlingScroll(ui::GestureEvent* event) {
fling_velocity_ = gfx::Vector2dF(event->details().velocity_x(),
event->details().velocity_y());
fling_curve_ =
std::make_unique<ui::FlingCurve>(fling_velocity_, base::TimeTicks::Now());
observed_compositor_ = const_cast<ui::Compositor*>(
grid_->root_window()->layer()->GetCompositor());
observed_compositor_->AddAnimationObserver(this);
}
void OverviewGridPreEventHandler::EndFling() {
if (!observed_compositor_)
return;
observed_compositor_->RemoveAnimationObserver(this);
observed_compositor_ = nullptr;
fling_curve_.reset();
grid_->EndScroll();
}
} // namespace ash
......@@ -6,11 +6,14 @@
#define ASH_WM_OVERVIEW_OVERVIEW_GRID_PRE_EVENT_HANDLER_H_
#include "base/macros.h"
#include "ui/compositor/compositor_animation_observer.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/geometry/point.h"
namespace ui {
class Compositor;
class Event;
class FlingCurve;
class GestureEvent;
class MouseEvent;
} // namespace ui
......@@ -23,7 +26,9 @@ class OverviewGrid;
// - Disabling overview mode on touch release.
// - Disabling overview mode on mouse release.
// - Scrolling through tablet overview mode on scrolling.
class OverviewGridPreEventHandler : public ui::EventHandler {
// - Scrolling through tablet overview mode on flinging.
class OverviewGridPreEventHandler : public ui::EventHandler,
public ui::CompositorAnimationObserver {
public:
explicit OverviewGridPreEventHandler(OverviewGrid* grid);
~OverviewGridPreEventHandler() override;
......@@ -33,12 +38,34 @@ class OverviewGridPreEventHandler : public ui::EventHandler {
void OnGestureEvent(ui::GestureEvent* event) override;
private:
// ui::CompositorAnimationObserver:
void OnAnimationStep(base::TimeTicks timestamp) override;
void OnCompositingShuttingDown(ui::Compositor* compositor) override;
void HandleClickOrTap(ui::Event* event);
void HandleFlingScroll(ui::GestureEvent* event);
void EndFling();
// Cached value of the OverviewGrid that handles a series of gesture scroll
// events. Guaranteed to be alive during the lifetime of |this|.
OverviewGrid* grid_;
// Gesture curve of the current active fling. nullptr while a fling is not
// active.
std::unique_ptr<ui::FlingCurve> fling_curve_;
// Velocity of the fling that will gradually decrease during a fling.
gfx::Vector2dF fling_velocity_;
// Cached value of an earlier offset that determines values to scroll through
// overview mode by being compared to an updated offset.
gfx::Vector2dF fling_last_offset_;
// The compositor we are observing when a fling is underway.
ui::Compositor* observed_compositor_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(OverviewGridPreEventHandler);
};
......
......@@ -2800,7 +2800,7 @@ class OverviewSessionNewLayoutTest : public OverviewSessionTest {
void GenerateScrollSequence(const gfx::Point& start, const gfx::Point& end) {
GetEventGenerator()->GestureScrollSequence(
start, end, base::TimeDelta::FromMilliseconds(10), 10);
start, end, base::TimeDelta::FromMilliseconds(100), 1000);
}
protected:
......@@ -2813,6 +2813,9 @@ class OverviewSessionNewLayoutTest : public OverviewSessionTest {
GetEventGenerator()->Dispatch(&long_press);
}
// TODO(sammiequon): Investigate simulating fling event for testing inertial
// scrolling.
private:
base::test::ScopedFeatureList scoped_feature_list_;
......
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