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

Overview: Use the spawn animation for desks removal only

https://crrev.com/c/1832477 previously added the spawn animation
and made it being used for all add-item-to-overview while overview
is active. This animation should not be used for dragging a window
to overview, or removing it from splitscreen, and should only be
limited to appending an item to overview as a result of desk removal.

BUG=1011981
TEST=Manual

Change-Id: I5a55b7bb7e49fb0fa9e5c7eb856ef7499675f698
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847947Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703938}
parent b2d00427
...@@ -19,6 +19,9 @@ enum OverviewAnimationType { ...@@ -19,6 +19,9 @@ enum OverviewAnimationType {
OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_ON_ENTER, OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_ON_ENTER,
OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW, OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW,
OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_ON_EXIT, OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_ON_EXIT,
// Used to add an item to an active overview session using the spawn
// animation.
OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW,
// Used to restore windows to their original position when exiting overview // Used to restore windows to their original position when exiting overview
// mode. // mode.
OVERVIEW_ANIMATION_RESTORE_WINDOW, OVERVIEW_ANIMATION_RESTORE_WINDOW,
......
...@@ -556,6 +556,9 @@ void OverviewGrid::PositionWindows( ...@@ -556,6 +556,9 @@ void OverviewGrid::PositionWindows(
bool has_non_cover_animating = false; bool has_non_cover_animating = false;
std::vector<OverviewAnimationType> animation_types(rects.size()); std::vector<OverviewAnimationType> animation_types(rects.size());
const bool can_do_spawn_animation =
animate && transition == OverviewSession::OverviewTransition::kInOverview;
for (size_t i = 0; i < window_list_.size(); ++i) { for (size_t i = 0; i < window_list_.size(); ++i) {
OverviewItem* window_item = window_list_[i].get(); OverviewItem* window_item = window_list_[i].get();
if (window_item->animating_to_close() || if (window_item->animating_to_close() ||
...@@ -582,6 +585,10 @@ void OverviewGrid::PositionWindows( ...@@ -582,6 +585,10 @@ void OverviewGrid::PositionWindows(
++animate_count; ++animate_count;
} }
} }
if (can_do_spawn_animation && window_item->should_use_spawn_animation())
animation_type = OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW;
animation_types[i] = animation_types[i] =
should_animate_item ? animation_type : OVERVIEW_ANIMATION_NONE; should_animate_item ? animation_type : OVERVIEW_ANIMATION_NONE;
} }
...@@ -622,22 +629,26 @@ void OverviewGrid::AddItem(aura::Window* window, ...@@ -622,22 +629,26 @@ void OverviewGrid::AddItem(aura::Window* window,
bool reposition, bool reposition,
bool animate, bool animate,
const base::flat_set<OverviewItem*>& ignored_items, const base::flat_set<OverviewItem*>& ignored_items,
size_t index) { size_t index,
bool use_spawn_animation) {
DCHECK(!GetOverviewItemContaining(window)); DCHECK(!GetOverviewItemContaining(window));
DCHECK_LE(index, window_list_.size()); DCHECK_LE(index, window_list_.size());
window_list_.insert( window_list_.insert(
window_list_.begin() + index, window_list_.begin() + index,
std::make_unique<OverviewItem>(window, overview_session_, this)); std::make_unique<OverviewItem>(window, overview_session_, this));
window_list_[index]->PrepareForOverview(); auto* item = window_list_[index].get();
item->PrepareForOverview();
if (!animate) { if (animate && use_spawn_animation && reposition) {
item->set_should_use_spawn_animation(true);
} else {
// The item is added after overview enter animation is complete, so // The item is added after overview enter animation is complete, so
// just call OnStartingAnimationComplete() only if we won't animate it, // just call OnStartingAnimationComplete() only if we won't animate it with
// otherwise, OnStartingAnimationComplete() will be called when the // with the spawn animation. Otherwise, OnStartingAnimationComplete() will
// add-item-to-overview animation completes // be called when the spawn-item-animation completes (See
// (See OverviewItem::OnItemAddedAnimationCompleted()). // OverviewItem::OnItemSpawnedAnimationCompleted()).
window_list_[index]->OnStartingAnimationComplete(); item->OnStartingAnimationComplete();
} }
if (reposition) if (reposition)
...@@ -646,9 +657,10 @@ void OverviewGrid::AddItem(aura::Window* window, ...@@ -646,9 +657,10 @@ void OverviewGrid::AddItem(aura::Window* window,
void OverviewGrid::AppendItem(aura::Window* window, void OverviewGrid::AppendItem(aura::Window* window,
bool reposition, bool reposition,
bool animate) { bool animate,
bool use_spawn_animation) {
AddItem(window, reposition, animate, /*ignored_items=*/{}, AddItem(window, reposition, animate, /*ignored_items=*/{},
window_list_.size()); window_list_.size(), use_spawn_animation);
} }
void OverviewGrid::RemoveItem(OverviewItem* overview_item, void OverviewGrid::RemoveItem(OverviewItem* overview_item,
......
...@@ -88,6 +88,10 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver, ...@@ -88,6 +88,10 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
// grid. If |reposition| is true, repositions all items except those in // grid. If |reposition| is true, repositions all items except those in
// |ignored_items|. If |animate| is true, animates the repositioning. // |ignored_items|. If |animate| is true, animates the repositioning.
// |animate| has no effect if |reposition| is false. // |animate| has no effect if |reposition| is false.
// If |use_spawn_animation| is true, and this item is being added *while*
// overview is already active, it will use a special spawn animation on its
// first position in the grid. |use_spawn_animation| has no effect if either
// |animate| or |reposition| are false.
// //
// Note: This function should only be called by |OverviewSession::AddItem|. // Note: This function should only be called by |OverviewSession::AddItem|.
// |overview_session_| keeps count of all overview items, but this function // |overview_session_| keeps count of all overview items, but this function
...@@ -96,10 +100,14 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver, ...@@ -96,10 +100,14 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
bool reposition, bool reposition,
bool animate, bool animate,
const base::flat_set<OverviewItem*>& ignored_items, const base::flat_set<OverviewItem*>& ignored_items,
size_t index); size_t index,
bool use_spawn_animation = false);
// Similar to the above function, but adds the window to the end of the grid. // Similar to the above function, but adds the window to the end of the grid.
void AppendItem(aura::Window* window, bool reposition, bool animate); void AppendItem(aura::Window* window,
bool reposition,
bool animate,
bool use_spawn_animation = false);
// Removes |overview_item| from the grid. |overview_item| cannot already be // Removes |overview_item| from the grid. |overview_item| cannot already be
// absent from the grid. No items are repositioned. // absent from the grid. No items are repositioned.
......
...@@ -161,8 +161,12 @@ void SetWidgetBoundsAndMaybeAnimateTransform( ...@@ -161,8 +161,12 @@ void SetWidgetBoundsAndMaybeAnimateTransform(
window->SetBoundsInScreen( window->SetBoundsInScreen(
new_bounds_in_screen, new_bounds_in_screen,
display::Screen::GetScreen()->GetDisplayNearestWindow(window)); display::Screen::GetScreen()->GetDisplayNearestWindow(window));
if (animation_type == OVERVIEW_ANIMATION_NONE) if (animation_type == OVERVIEW_ANIMATION_NONE) {
// Make sure that |observer|, which could be a self-deleting object, will
// not be leaked.
DCHECK(!observer);
return; return;
}
// For animations, compute the transform needed to place the widget at its // For animations, compute the transform needed to place the widget at its
// new bounds back to the old bounds, and then apply the idenity // new bounds back to the old bounds, and then apply the idenity
...@@ -438,10 +442,9 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds, ...@@ -438,10 +442,9 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds,
if (!should_animate_when_entering_) { if (!should_animate_when_entering_) {
item_widget_->GetNativeWindow()->layer()->SetOpacity(1.f); item_widget_->GetNativeWindow()->layer()->SetOpacity(1.f);
} else { } else {
if (new_animation_type == if (new_animation_type == OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW) {
OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW) { PerformItemSpawnedAnimation(item_widget_->GetNativeWindow(),
PerformItemAddedAnimation(item_widget_->GetNativeWindow(), gfx::Transform{});
gfx::Transform{});
} else { } else {
FadeInWidgetAndMaybeSlideOnEnter( FadeInWidgetAndMaybeSlideOnEnter(
item_widget_.get(), item_widget_.get(),
...@@ -1070,7 +1073,7 @@ void OverviewItem::OnWindowCloseAnimationCompleted() { ...@@ -1070,7 +1073,7 @@ void OverviewItem::OnWindowCloseAnimationCompleted() {
transform_window_.Close(); transform_window_.Close();
} }
void OverviewItem::OnItemAddedAnimationCompleted() { void OverviewItem::OnItemSpawnedAnimationCompleted() {
UpdateRoundedCornersAndShadow(); UpdateRoundedCornersAndShadow();
OnDragAnimationCompleted(); OnDragAnimationCompleted();
OnStartingAnimationComplete(); OnStartingAnimationComplete();
...@@ -1089,9 +1092,12 @@ void OverviewItem::OnItemBoundsAnimationEnded() { ...@@ -1089,9 +1092,12 @@ void OverviewItem::OnItemBoundsAnimationEnded() {
OnDragAnimationCompleted(); OnDragAnimationCompleted();
} }
void OverviewItem::PerformItemAddedAnimation( void OverviewItem::PerformItemSpawnedAnimation(
aura::Window* window, aura::Window* window,
const gfx::Transform& target_transform) { const gfx::Transform& target_transform) {
DCHECK(should_use_spawn_animation_);
should_use_spawn_animation_ = false;
constexpr float kInitialScaler = 0.1f; constexpr float kInitialScaler = 0.1f;
constexpr float kTargetScaler = 1.0f; constexpr float kTargetScaler = 1.0f;
...@@ -1105,14 +1111,14 @@ void OverviewItem::PerformItemAddedAnimation( ...@@ -1105,14 +1111,14 @@ void OverviewItem::PerformItemAddedAnimation(
ScopedOverviewTransformWindow::ScopedAnimationSettings animation_settings; ScopedOverviewTransformWindow::ScopedAnimationSettings animation_settings;
for (auto* window_iter : GetVisibleTransientTreeIterator(window)) { for (auto* window_iter : GetVisibleTransientTreeIterator(window)) {
auto settings = std::make_unique<ScopedOverviewAnimationSettings>( auto settings = std::make_unique<ScopedOverviewAnimationSettings>(
OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW, window_iter); OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW, window_iter);
settings->DeferPaint(); settings->DeferPaint();
animation_settings.push_back(std::move(settings)); animation_settings.push_back(std::move(settings));
} }
if (!animation_settings.empty()) { if (!animation_settings.empty()) {
animation_settings.front()->AddObserver(new AnimationObserver{ animation_settings.front()->AddObserver(new AnimationObserver{
base::BindOnce(&OverviewItem::OnItemAddedAnimationCompleted, base::BindOnce(&OverviewItem::OnItemSpawnedAnimationCompleted,
weak_ptr_factory_.GetWeakPtr())}); weak_ptr_factory_.GetWeakPtr())});
} }
SetTransform(window, target_transform); SetTransform(window, target_transform);
...@@ -1122,8 +1128,7 @@ void OverviewItem::PerformItemAddedAnimation( ...@@ -1122,8 +1128,7 @@ void OverviewItem::PerformItemAddedAnimation(
aura::Window* cannot_snap_window = cannot_snap_widget_->GetNativeWindow(); aura::Window* cannot_snap_window = cannot_snap_widget_->GetNativeWindow();
cannot_snap_window->layer()->SetOpacity(kInitialScaler); cannot_snap_window->layer()->SetOpacity(kInitialScaler);
ScopedOverviewAnimationSettings label_animation_settings( ScopedOverviewAnimationSettings label_animation_settings(
OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW, OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW, cannot_snap_window);
cannot_snap_window);
cannot_snap_window->layer()->SetOpacity(kTargetScaler); cannot_snap_window->layer()->SetOpacity(kTargetScaler);
} }
} }
...@@ -1156,8 +1161,8 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds, ...@@ -1156,8 +1161,8 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds,
gfx::TransformBetweenRects(screen_rect, overview_item_bounds); gfx::TransformBetweenRects(screen_rect, overview_item_bounds);
if (is_first_update && if (is_first_update &&
animation_type == OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW) { animation_type == OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW) {
PerformItemAddedAnimation(window, transform); PerformItemSpawnedAnimation(window, transform);
return; return;
} }
......
...@@ -221,6 +221,13 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate, ...@@ -221,6 +221,13 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate,
OverviewGrid* overview_grid() { return overview_grid_; } OverviewGrid* overview_grid() { return overview_grid_; }
bool should_use_spawn_animation() const {
return should_use_spawn_animation_;
}
void set_should_use_spawn_animation(bool value) {
should_use_spawn_animation_ = value;
}
void set_should_animate_when_entering(bool should_animate) { void set_should_animate_when_entering(bool should_animate) {
should_animate_when_entering_ = should_animate; should_animate_when_entering_ = should_animate;
} }
...@@ -264,18 +271,18 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate, ...@@ -264,18 +271,18 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate,
// Functions to be called back when their associated animations complete. // Functions to be called back when their associated animations complete.
void OnWindowCloseAnimationCompleted(); void OnWindowCloseAnimationCompleted();
void OnItemAddedAnimationCompleted(); void OnItemSpawnedAnimationCompleted();
void OnItemBoundsAnimationStarted(); void OnItemBoundsAnimationStarted();
void OnItemBoundsAnimationEnded(); void OnItemBoundsAnimationEnded();
// Performs the add-item-to-overview animation (which is a fade-in plus // Performs the spawn-item-in-overview animation (which is a fade-in plus
// scale-up animation), on the given |window|. |target_transform| is the final // scale-up animation), on the given |window|. |target_transform| is the final
// transform that should be applied to |window| at the end of the animation. // transform that should be applied to |window| at the end of the animation.
// |window| is either the real window associated with this item (from // |window| is either the real window associated with this item (from
// GetWindow()), or the `item_widget_->GetNativeWindow()` if the associated // GetWindow()), or the `item_widget_->GetNativeWindow()` if the associated
// window is minimized. // window is minimized.
void PerformItemAddedAnimation(aura::Window* window, void PerformItemSpawnedAnimation(aura::Window* window,
const gfx::Transform& target_transform); const gfx::Transform& target_transform);
// Sets the bounds of this overview item to |target_bounds| in |root_window_|. // Sets the bounds of this overview item to |target_bounds| in |root_window_|.
// The bounds change will be animated as specified by |animation_type|. // The bounds change will be animated as specified by |animation_type|.
...@@ -363,6 +370,12 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate, ...@@ -363,6 +370,12 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate,
// for the lifetime of |this|. // for the lifetime of |this|.
OverviewGrid* overview_grid_; OverviewGrid* overview_grid_;
// True if this item should be added to an active overview session using the
// spawn animation on its first update. This implies an animation type of
// OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW. This value will be reset to
// false once the spawn animation is performed.
bool should_use_spawn_animation_ = false;
// True if the contained window should animate during the entering animation. // True if the contained window should animate during the entering animation.
bool should_animate_when_entering_ = true; bool should_animate_when_entering_ = true;
......
...@@ -364,7 +364,7 @@ void OverviewSession::AppendItem(aura::Window* window, ...@@ -364,7 +364,7 @@ void OverviewSession::AppendItem(aura::Window* window,
if (!grid || grid->GetOverviewItemContaining(window)) if (!grid || grid->GetOverviewItemContaining(window))
return; return;
grid->AppendItem(window, reposition, animate); grid->AppendItem(window, reposition, animate, /*use_spawn_animation=*/true);
++num_items_; ++num_items_;
UpdateNoWindowsWidget(); UpdateNoWindowsWidget();
......
...@@ -147,6 +147,8 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver, ...@@ -147,6 +147,8 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver,
size_t index = 0); size_t index = 0);
// Similar to the above function, but adds the window at the end of the grid. // Similar to the above function, but adds the window at the end of the grid.
// This will use the spawn-item animation.
// TODO(afakhry): Expose |use_spawn_animation| if needed.
void AppendItem(aura::Window* window, bool reposition, bool animate); void AppendItem(aura::Window* window, bool reposition, bool animate);
// Removes |overview_item| from the corresponding grid. No items are // Removes |overview_item| from the corresponding grid. No items are
......
...@@ -60,6 +60,7 @@ base::TimeDelta GetAnimationDuration(OverviewAnimationType animation_type) { ...@@ -60,6 +60,7 @@ base::TimeDelta GetAnimationDuration(OverviewAnimationType animation_type) {
case OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_ON_EXIT: case OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_ON_EXIT:
case OVERVIEW_ANIMATION_RESTORE_WINDOW: case OVERVIEW_ANIMATION_RESTORE_WINDOW:
case OVERVIEW_ANIMATION_RESTORE_WINDOW_ZERO: case OVERVIEW_ANIMATION_RESTORE_WINDOW_ZERO:
case OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW:
return kTransition; return kTransition;
case OVERVIEW_ANIMATION_CLOSING_OVERVIEW_ITEM: case OVERVIEW_ANIMATION_CLOSING_OVERVIEW_ITEM:
return kCloseScale; return kCloseScale;
...@@ -132,6 +133,7 @@ ScopedOverviewAnimationSettings::ScopedOverviewAnimationSettings( ...@@ -132,6 +133,7 @@ ScopedOverviewAnimationSettings::ScopedOverviewAnimationSettings(
case OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW: case OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_IN_OVERVIEW:
case OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_ON_EXIT: case OVERVIEW_ANIMATION_LAYOUT_OVERVIEW_ITEMS_ON_EXIT:
case OVERVIEW_ANIMATION_RESTORE_WINDOW: case OVERVIEW_ANIMATION_RESTORE_WINDOW:
case OVERVIEW_ANIMATION_SPAWN_ITEM_IN_OVERVIEW:
animation_settings_->SetTweenType(gfx::Tween::EASE_OUT); animation_settings_->SetTweenType(gfx::Tween::EASE_OUT);
animation_settings_->SetPreemptionStrategy( animation_settings_->SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
......
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