Commit 51ce0e2a authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

applist: Translate and fade launcher when swipe up to minimize.

Refactor the launcher overview animation to share some code.

Test: manual
Bug: 873394
Change-Id: I6c94719a559eea04e354d2bc131efc4cf14650df
Reviewed-on: https://chromium-review.googlesource.com/1196910Reviewed-by: default avatarWeidong Guo <weidongg@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587794}
parent f86476e7
...@@ -75,7 +75,7 @@ AppListControllerImpl::AppListControllerImpl(ws::WindowService* window_service) ...@@ -75,7 +75,7 @@ AppListControllerImpl::AppListControllerImpl(ws::WindowService* window_service)
if (is_home_launcher_enabled_ && if (is_home_launcher_enabled_ &&
app_list::features::IsHomeLauncherGesturesEnabled()) { app_list::features::IsHomeLauncherGesturesEnabled()) {
home_launcher_gesture_handler_ = home_launcher_gesture_handler_ =
std::make_unique<HomeLauncherGestureHandler>(); std::make_unique<HomeLauncherGestureHandler>(this);
} }
mojom::VoiceInteractionObserverPtr ptr; mojom::VoiceInteractionObserverPtr ptr;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/app_list/home_launcher_gesture_handler.h" #include "ash/app_list/home_launcher_gesture_handler.h"
#include "ash/app_list/app_list_controller_impl.h" #include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/model/app_list_view_state.h"
#include "ash/screen_util.h" #include "ash/screen_util.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/mru_window_tracker.h" #include "ash/wm/mru_window_tracker.h"
...@@ -84,6 +85,13 @@ double GetHeightInWorkAreaAsRatio(int y, aura::Window* window) { ...@@ -84,6 +85,13 @@ double GetHeightInWorkAreaAsRatio(int y, aura::Window* window) {
return 1.0 - ratio; return 1.0 - ratio;
} }
void UpdateSettings(ui::ScopedLayerAnimationSettings* settings) {
settings->SetTransitionDuration(kAnimationDurationMs);
settings->SetTweenType(gfx::Tween::LINEAR);
settings->SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
}
// Helper class to perform window state changes without animations. Used to hide // Helper class to perform window state changes without animations. Used to hide
// and minimize windows without having their animation interfere with the ones // and minimize windows without having their animation interfere with the ones
// this class is in charge of. // this class is in charge of.
...@@ -109,7 +117,9 @@ class ScopedAnimationDisabler { ...@@ -109,7 +117,9 @@ class ScopedAnimationDisabler {
} // namespace } // namespace
HomeLauncherGestureHandler::HomeLauncherGestureHandler() { HomeLauncherGestureHandler::HomeLauncherGestureHandler(
AppListControllerImpl* app_list_controller)
: app_list_controller_(app_list_controller) {
tablet_mode_observer_.Add(Shell::Get()->tablet_mode_controller()); tablet_mode_observer_.Add(Shell::Get()->tablet_mode_controller());
} }
...@@ -257,6 +267,11 @@ void HomeLauncherGestureHandler::OnImplicitAnimationsCompleted() { ...@@ -257,6 +267,11 @@ void HomeLauncherGestureHandler::OnImplicitAnimationsCompleted() {
} }
} }
// Return the app list to its original opacity and transform without
// animation.
app_list_controller_->presenter()->UpdateYPositionAndOpacityForHomeLauncher(
screen_util::GetDisplayWorkAreaBoundsInParent(window_).y(), 1.f,
base::NullCallback());
last_event_location_ = base::nullopt; last_event_location_ = base::nullopt;
RemoveObserversAndStopTracking(); RemoveObserversAndStopTracking();
} }
...@@ -264,10 +279,14 @@ void HomeLauncherGestureHandler::OnImplicitAnimationsCompleted() { ...@@ -264,10 +279,14 @@ void HomeLauncherGestureHandler::OnImplicitAnimationsCompleted() {
bool HomeLauncherGestureHandler::CanHideWindow(aura::Window* window) { bool HomeLauncherGestureHandler::CanHideWindow(aura::Window* window) {
DCHECK(window); DCHECK(window);
// Window should not be fullscreen as we do not allow swiping up when auto
// hide for shelf.
DCHECK(!wm::GetWindowState(window)->IsFullscreen());
if (!window->IsVisible()) if (!window->IsVisible())
return false; return false;
if (!Shell::Get()->app_list_controller()->IsHomeLauncherEnabledInTabletMode()) if (!app_list_controller_->IsHomeLauncherEnabledInTabletMode())
return false; return false;
if (Shell::Get()->split_view_controller()->IsSplitViewModeActive()) if (Shell::Get()->split_view_controller()->IsSplitViewModeActive())
...@@ -301,10 +320,7 @@ void HomeLauncherGestureHandler::UpdateWindows(double progress, bool animate) { ...@@ -301,10 +320,7 @@ void HomeLauncherGestureHandler::UpdateWindows(double progress, bool animate) {
if (animate) { if (animate) {
settings = std::make_unique<ui::ScopedLayerAnimationSettings>( settings = std::make_unique<ui::ScopedLayerAnimationSettings>(
window->layer()->GetAnimator()); window->layer()->GetAnimator());
settings->SetTransitionDuration(kAnimationDurationMs); UpdateSettings(settings.get());
settings->SetTweenType(gfx::Tween::LINEAR);
settings->SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
if (window == this->window()) if (window == this->window())
settings->AddObserver(this); settings->AddObserver(this);
} }
...@@ -317,6 +333,22 @@ void HomeLauncherGestureHandler::UpdateWindows(double progress, bool animate) { ...@@ -317,6 +333,22 @@ void HomeLauncherGestureHandler::UpdateWindows(double progress, bool animate) {
descendant.second); descendant.second);
} }
update_windows_helper(progress, animate, window_, window_values_); update_windows_helper(progress, animate, window_, window_values_);
// Update full screen applist. On tests, |window_| may be null because
// OnImplicitAnimationsCompleted runs right away, which invalidates |window_|,
// so just skip this section.
if (!window_)
return;
const gfx::Rect work_area =
screen_util::GetDisplayWorkAreaBoundsInParent(window_);
const int y_position =
gfx::Tween::IntValueBetween(progress, work_area.bottom(), work_area.y());
app_list_controller_->presenter()->UpdateYPositionAndOpacityForHomeLauncher(
y_position,
gfx::Tween::FloatValueBetween(progress, window_values_.target_opacity,
window_values_.initial_opacity),
animate ? base::BindRepeating(&UpdateSettings) : base::NullCallback());
} }
void HomeLauncherGestureHandler::RemoveObserversAndStopTracking() { void HomeLauncherGestureHandler::RemoveObserversAndStopTracking() {
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
namespace ash { namespace ash {
class AppListControllerImpl;
// HomeLauncherGestureHandler makes modifications to a window's transform and // HomeLauncherGestureHandler makes modifications to a window's transform and
// opacity when gesture drag events are received and forwarded to it. // opacity when gesture drag events are received and forwarded to it.
// Additionally hides windows which may block the home launcher. All // Additionally hides windows which may block the home launcher. All
...@@ -31,7 +33,8 @@ class ASH_EXPORT HomeLauncherGestureHandler : aura::WindowObserver, ...@@ -31,7 +33,8 @@ class ASH_EXPORT HomeLauncherGestureHandler : aura::WindowObserver,
TabletModeObserver, TabletModeObserver,
ui::ImplicitAnimationObserver { ui::ImplicitAnimationObserver {
public: public:
HomeLauncherGestureHandler(); explicit HomeLauncherGestureHandler(
AppListControllerImpl* app_list_controller);
~HomeLauncherGestureHandler() override; ~HomeLauncherGestureHandler() override;
// Called by owner of this object when a gesture event is received. |location| // Called by owner of this object when a gesture event is received. |location|
...@@ -96,6 +99,9 @@ class ASH_EXPORT HomeLauncherGestureHandler : aura::WindowObserver, ...@@ -96,6 +99,9 @@ class ASH_EXPORT HomeLauncherGestureHandler : aura::WindowObserver,
ScopedObserver<TabletModeController, TabletModeObserver> ScopedObserver<TabletModeController, TabletModeObserver>
tablet_mode_observer_{this}; tablet_mode_observer_{this};
// Unowned and guaranteed to be non null for the lifetime of this.
AppListControllerImpl* app_list_controller_;
DISALLOW_COPY_AND_ASSIGN(HomeLauncherGestureHandler); DISALLOW_COPY_AND_ASSIGN(HomeLauncherGestureHandler);
}; };
......
...@@ -32,21 +32,40 @@ namespace app_list { ...@@ -32,21 +32,40 @@ namespace app_list {
namespace { namespace {
// The y offset for app list animation when overview mode toggles. // The y offset for app list animation when overview mode toggles.
constexpr int kOverViewAnimationYOffset = 100; constexpr int kOverviewAnimationYOffset = 100;
// The delay in milliseconds for app list animation when overview mode ends // The delay in milliseconds for app list animation when overview mode ends
constexpr base::TimeDelta kOverViewEndAnimationDelay = constexpr base::TimeDelta kOverviewEndAnimationDelay =
base::TimeDelta::FromMilliseconds(250); base::TimeDelta::FromMilliseconds(250);
// The duration in milliseconds for app list animation when overview mode // The duration in milliseconds for app list animation when overview mode
// toggles. // toggles.
constexpr base::TimeDelta kOverViewAnimationDuration = constexpr base::TimeDelta kOverviewAnimationDuration =
base::TimeDelta::FromMilliseconds(250); base::TimeDelta::FromMilliseconds(250);
inline ui::Layer* GetLayer(views::Widget* widget) { inline ui::Layer* GetLayer(views::Widget* widget) {
return widget->GetNativeView()->layer(); return widget->GetNativeView()->layer();
} }
void UpdateOverviewSettings(bool end_overview,
ui::AnimationMetricsReporter* reporter,
ui::ScopedLayerAnimationSettings* settings) {
settings->SetTransitionDuration(kOverviewAnimationDuration);
settings->SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN);
settings->SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
DCHECK(reporter);
settings->SetAnimationMetricsReporter(reporter);
if (end_overview) {
settings->GetAnimator()->SchedulePauseForProperties(
kOverviewEndAnimationDelay,
ui::LayerAnimationElement::AnimatableProperty::OPACITY |
ui::LayerAnimationElement::AnimatableProperty::TRANSFORM);
}
}
class StateAnimationMetricsReporter : public ui::AnimationMetricsReporter { class StateAnimationMetricsReporter : public ui::AnimationMetricsReporter {
public: public:
StateAnimationMetricsReporter() = default; StateAnimationMetricsReporter() = default;
...@@ -213,71 +232,46 @@ void AppListPresenterImpl::ProcessMouseWheelOffset(int y_scroll_offset) { ...@@ -213,71 +232,46 @@ void AppListPresenterImpl::ProcessMouseWheelOffset(int y_scroll_offset) {
view_->HandleScroll(y_scroll_offset, ui::ET_MOUSEWHEEL); view_->HandleScroll(y_scroll_offset, ui::ET_MOUSEWHEEL);
} }
void AppListPresenterImpl::ScheduleOverviewModeAnimation(bool start, void AppListPresenterImpl::UpdateYPositionAndOpacityForHomeLauncher(
bool animate) { int y_position_in_screen,
if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == float opacity,
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION) { UpdateHomeLauncherAnimationSettingsCallback callback) {
// Start animation immediately in test.
StartOverviewModeAnimation(start, false);
return;
}
start_animation_timer_.Stop();
start_animation_timer_.Start(
FROM_HERE, start ? base::TimeDelta() : kOverViewEndAnimationDelay,
base::BindOnce(&AppListPresenterImpl::StartOverviewModeAnimation,
base::Unretained(this), start, animate));
}
void AppListPresenterImpl::StartOverviewModeAnimation(bool start,
bool animate) {
if (!GetTargetVisibility()) if (!GetTargetVisibility())
return; return;
// Calculate the source and target parameters used in the animation. const gfx::Transform translation(1.f, 0.f, 0.f, 1.f, 0.f,
gfx::Transform transform; static_cast<float>(y_position_in_screen));
transform.Translate(0, kOverViewAnimationYOffset); // We want to animate the expand arrow, suggestion chips and apps grid in
const base::TimeDelta duration = // app_list_main_view, and the search box.
animate ? kOverViewAnimationDuration : base::TimeDelta(); std::vector<ui::Layer*> animation_layers = {
const gfx::Transform source_transform = start ? gfx::Transform() : transform; view_->app_list_main_view()->layer(),
const gfx::Transform target_transform = start ? transform : gfx::Transform(); view_->search_box_widget()->GetNativeWindow()->layer()};
const float source_opacity = start ? 1.0f : 0.0f; for (auto* layer : animation_layers) {
const float target_opacity = start ? 0.0f : 1.0f; layer->GetAnimator()->StopAnimating();
std::unique_ptr<ui::ScopedLayerAnimationSettings> settings;
// Start animation to change the opacity and y position of expand arrow, if (!callback.is_null()) {
// suggestion chips and apps grid. settings = std::make_unique<ui::ScopedLayerAnimationSettings>(
AppListMainView* app_list_main_view = view_->app_list_main_view(); layer->GetAnimator());
ui::Layer* layer = app_list_main_view->layer(); callback.Run(settings.get());
layer->GetAnimator()->StopAnimating(); }
layer->SetTransform(source_transform); layer->SetOpacity(opacity);
layer->SetOpacity(source_opacity); layer->SetTransform(translation);
{
ui::ScopedLayerAnimationSettings animation(layer->GetAnimator());
animation.SetTransitionDuration(duration);
animation.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN);
animation.SetAnimationMetricsReporter(
state_animation_metrics_reporter_.get());
layer->SetTransform(target_transform);
layer->SetOpacity(target_opacity);
} }
}
// Start animation to change the opacity and y position of search box. void AppListPresenterImpl::ScheduleOverviewModeAnimation(bool start,
views::Widget* search_box_widget = view_->search_box_widget(); bool animate) {
ui::Layer* search_box_layer = search_box_widget->GetNativeView()->layer(); // If animating, set the source parameters.
search_box_layer->GetAnimator()->StopAnimating(); if (animate) {
search_box_layer->SetTransform(source_transform); UpdateYPositionAndOpacityForHomeLauncher(
search_box_layer->SetOpacity(source_opacity); start ? 0 : kOverviewAnimationYOffset, start ? 1.f : 0.f,
base::NullCallback());
{
ui::ScopedLayerAnimationSettings animation(search_box_layer->GetAnimator());
animation.SetTransitionDuration(duration);
animation.SetTweenType(gfx::Tween::FAST_OUT_SLOW_IN);
animation.SetAnimationMetricsReporter(
state_animation_metrics_reporter_.get());
search_box_layer->SetTransform(target_transform);
search_box_layer->SetOpacity(target_opacity);
} }
UpdateYPositionAndOpacityForHomeLauncher(
start ? kOverviewAnimationYOffset : 0, start ? 0.f : 1.f,
animate ? base::BindRepeating(&UpdateOverviewSettings, start,
state_animation_metrics_reporter_.get())
: base::NullCallback());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#include "ash/app_list/pagination_model_observer.h" #include "ash/app_list/pagination_model_observer.h"
#include "ash/app_list/presenter/app_list_presenter_delegate.h" #include "ash/app_list/presenter/app_list_presenter_delegate.h"
#include "ash/app_list/presenter/app_list_presenter_export.h" #include "ash/app_list/presenter/app_list_presenter_export.h"
#include "base/callback.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/timer/timer.h"
#include "ui/aura/client/focus_change_observer.h" #include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
...@@ -39,6 +39,12 @@ class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl ...@@ -39,6 +39,12 @@ class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl
public views::WidgetObserver, public views::WidgetObserver,
public PaginationModelObserver { public PaginationModelObserver {
public: public:
// Callback which fills out the passed settings object. Used by
// UpdateYPositionAndOpacityForHomeLauncher so different callers can do
// similar animations with different settings.
using UpdateHomeLauncherAnimationSettingsCallback =
base::RepeatingCallback<void(ui::ScopedLayerAnimationSettings* settings)>;
explicit AppListPresenterImpl( explicit AppListPresenterImpl(
std::unique_ptr<AppListPresenterDelegate> delegate); std::unique_ptr<AppListPresenterDelegate> delegate);
~AppListPresenterImpl() override; ~AppListPresenterImpl() override;
...@@ -85,13 +91,16 @@ class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl ...@@ -85,13 +91,16 @@ class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl
// Passes a MouseWheelEvent from the shelf to the AppListView. // Passes a MouseWheelEvent from the shelf to the AppListView.
void ProcessMouseWheelOffset(int y_scroll_offset); void ProcessMouseWheelOffset(int y_scroll_offset);
// Schedules animation for app list when overview mode starts or ends. The // Updates the y position and opacity of the full screen app list. The changes
// animation duration will be set to 0 if |animate| is false. // are slightly different than UpdateYPositionAndOpacity. If |callback| is non
void ScheduleOverviewModeAnimation(bool start, bool animate); // null the this will animate using the animation settings in |callback|.
void UpdateYPositionAndOpacityForHomeLauncher(
int y_position_in_screen,
float opacity,
UpdateHomeLauncherAnimationSettingsCallback callback);
// Immediately start animation for app list when overview mode starts or ends. // Schedules animation for app list when overview mode starts or ends.
// The animation duration will be set to 0 if |animate| is false. void ScheduleOverviewModeAnimation(bool start, bool animate);
void StartOverviewModeAnimation(bool start, bool animate);
private: private:
// Sets the app list view and attempts to show it. // Sets the app list view and attempts to show it.
...@@ -160,9 +169,6 @@ class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl ...@@ -160,9 +169,6 @@ class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl
bool last_visible_ = false; bool last_visible_ = false;
int64_t last_display_id_ = display::kInvalidDisplayId; int64_t last_display_id_ = display::kInvalidDisplayId;
// The timer used to delay the start time of an animation.
base::OneShotTimer start_animation_timer_;
DISALLOW_COPY_AND_ASSIGN(AppListPresenterImpl); DISALLOW_COPY_AND_ASSIGN(AppListPresenterImpl);
}; };
......
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