Commit 369336a1 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

Overview: Animation refactoring.

No functionality is changed in this CL.

Bug: None
Change-Id: Ib9a935b7a2b15254f21e79f996c28c5ff5e17895
Reviewed-on: https://chromium-review.googlesource.com/1149611
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577981}
parent 709d7c0b
......@@ -254,7 +254,7 @@ void ScopedTransformOverviewWindow::BeginScopedAnimation(
// ScopedOverviewAnimationSettings in order to monitor the complete of its
// exiting animation.
if (window == GetOverviewWindow() &&
selector_item_->ShouldBeObservedWhenExiting()) {
selector_item_->should_be_observed_when_exiting()) {
auto window_animation_observer_weak_ptr =
selector_item_->window_grid()->window_animation_observer();
if (window_animation_observer_weak_ptr)
......@@ -405,7 +405,7 @@ void ScopedTransformOverviewWindow::SetTransform(
// If current |window_| should not animate during exiting process, we defer
// set transfrom on the window by adding the layer and transform information
// to the |window_animation_observer|.
if (!selector_item_->ShouldAnimateWhenExiting() &&
if (!selector_item_->should_animate_when_exiting() &&
window_animation_observer_weak_ptr) {
window_animation_observer_weak_ptr->AddLayerTransformPair(window->layer(),
new_transform);
......
......@@ -345,10 +345,13 @@ void WindowGrid::PrepareForOverview() {
prepared_for_overview_ = true;
}
void WindowGrid::PositionWindows(bool animate,
WindowSelectorItem* ignored_item) {
void WindowGrid::PositionWindows(
bool animate,
WindowSelectorItem* ignored_item,
WindowSelector::OverviewTransition transition) {
if (window_selector_->IsShuttingDown())
return;
DCHECK_NE(transition, WindowSelector::OverviewTransition::kExit);
DCHECK(shield_widget_.get());
// Keep the background shield widget covering the whole screen. A grid without
......@@ -368,15 +371,26 @@ void WindowGrid::PositionWindows(bool animate,
// position |ignored_item| if it is not nullptr and matches a item in
// |window_list_|.
for (size_t i = 0; i < window_list_.size(); ++i) {
if (window_list_[i]->animating_to_close() ||
(ignored_item != nullptr && window_list_[i].get() == ignored_item)) {
WindowSelectorItem* window_item = window_list_[i].get();
if (window_item->animating_to_close() ||
(ignored_item != nullptr && window_item == ignored_item)) {
continue;
}
const bool should_animate = window_list_[i]->ShouldAnimateWhenEntering();
window_list_[i]->SetBounds(
// Calculate if each window item needs animation.
bool should_animate_item = animate;
// If we're in entering overview process, not all window items in the grid
// might need animation even if the grid needs animation.
if (animate && transition == WindowSelector::OverviewTransition::kEnter)
should_animate_item = window_item->should_animate_when_entering();
// Do not do the bounds animation for the new selector item. We'll do the
// opacity animation by ourselves.
if (IsNewSelectorItemWindow(window_item->GetWindow()))
should_animate_item = false;
window_item->SetBounds(
rects[i],
animate && should_animate
should_animate_item
? OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS
: OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
}
......@@ -471,13 +485,6 @@ void WindowGrid::AddItem(aura::Window* window, bool reposition) {
std::make_unique<WindowSelectorItem>(window, window_selector_, this));
window_list_.back()->PrepareForOverview();
if (IsNewSelectorItemWindow(window)) {
// If we're adding the new selector item, don't do the layout animation.
// We'll do opacity animation by ourselves.
window_list_.back()->set_should_animate_when_entering(false);
window_list_.back()->set_should_animate_when_exiting(false);
}
if (reposition)
PositionWindows(/*animate=*/true);
}
......@@ -835,11 +842,6 @@ void WindowGrid::SetWindowListNotAnimatedWhenExiting() {
}
}
void WindowGrid::ResetWindowListAnimationStates() {
for (const auto& selector_item : window_list_)
selector_item->ResetAnimationStates();
}
void WindowGrid::StartNudge(WindowSelectorItem* item) {
// When there is one window left, there is no need to nudge.
if (window_list_.size() <= 1) {
......
......@@ -70,8 +70,11 @@ class ASH_EXPORT WindowGrid : public aura::WindowObserver,
// fit that height. Optionally animates the windows to their targets when
// |animate| is true. If |ignored_item| is not null and is an item in
// |window_list_|, that item is not positioned. This is for split screen.
// |transition| specifies the overview state when this function is called.
void PositionWindows(bool animate,
WindowSelectorItem* ignored_item = nullptr);
WindowSelectorItem* ignored_item = nullptr,
WindowSelector::OverviewTransition transition =
WindowSelector::OverviewTransition::kInOverview);
// Updates |selected_index_| according to the specified |direction| and calls
// MoveSelectionWidget(). Returns |true| if the new selection index is out of
......@@ -206,10 +209,6 @@ class ASH_EXPORT WindowGrid : public aura::WindowObserver,
// directly when the animation is completed.
void SetWindowListNotAnimatedWhenExiting();
// Reset |selector_item|'s |should_animate_when_entering_|,
// |should_animate_when_exiting_| and |should_be_observed_when_exiting_|.
void ResetWindowListAnimationStates();
// Starts a nudge, with |item| being the item that may be deleted. This method
// calculates which items in |window_list_| are to be updated, and their
// destination bounds and fills |nudge_data_| accordingly.
......
......@@ -290,13 +290,11 @@ void WindowSelector::Init(const WindowList& windows,
// as we don't want to cause any window updates until all windows in
// overview are observed. See http://crbug.com/384495.
for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) {
window_grid->SetWindowListAnimationStates(/*selected_item=*/nullptr,
OverviewTransition::kEnter);
window_grid->SetWindowListAnimationStates(/*selected_item=*/nullptr,
OverviewTransition::kEnter);
window_grid->PrepareForOverview();
window_grid->PositionWindows(/*animate=*/true);
// Reset |should_animate_when_entering_| in order to animate during
// overview mode, such as dragging animations.
window_grid->ResetWindowListAnimationStates();
window_grid->PositionWindows(/*animate=*/true, /*ignore_item=*/nullptr,
OverviewTransition::kEnter);
}
// Image used for text filter textfield.
......
......@@ -57,8 +57,9 @@ class ASH_EXPORT WindowSelector : public display::DisplayObserver,
enum Direction { LEFT, UP, RIGHT, DOWN };
enum class OverviewTransition {
kEnter, // In the entering process of overview.
kExit // In the exiting process of overview.
kEnter, // In the entering process of overview.
kInOverview, // Already in overview.
kExit // In the exiting process of overview.
};
using WindowList = std::vector<aura::Window*>;
......
......@@ -1139,32 +1139,14 @@ float WindowSelectorItem::GetOpacity() {
return item_widget_->GetNativeWindow()->layer()->opacity();
}
bool WindowSelectorItem::ShouldAnimateWhenEntering() const {
return should_animate_when_entering_;
}
bool WindowSelectorItem::ShouldAnimateWhenExiting() const {
return should_animate_when_exiting_;
}
bool WindowSelectorItem::ShouldBeObservedWhenExiting() const {
return should_be_observed_when_exiting_;
}
void WindowSelectorItem::ResetAnimationStates() {
should_animate_when_entering_ = true;
should_animate_when_exiting_ = true;
should_be_observed_when_exiting_ = false;
}
OverviewAnimationType WindowSelectorItem::GetExitOverviewAnimationType() {
return ShouldAnimateWhenExiting()
return should_animate_when_exiting_
? OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS
: OverviewAnimationType::OVERVIEW_ANIMATION_NONE;
}
OverviewAnimationType WindowSelectorItem::GetExitTransformAnimationType() {
return ShouldAnimateWhenExiting()
return should_animate_when_exiting_
? OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW
: OverviewAnimationType::OVERVIEW_ANIMATION_NONE;
}
......
......@@ -223,19 +223,23 @@ class ASH_EXPORT WindowSelectorItem : public views::ButtonListener,
void set_should_animate_when_entering(bool should_animate) {
should_animate_when_entering_ = should_animate;
}
bool ShouldAnimateWhenEntering() const;
bool should_animate_when_entering() const {
return should_animate_when_entering_;
}
void set_should_animate_when_exiting(bool should_animate) {
should_animate_when_exiting_ = should_animate;
}
bool ShouldAnimateWhenExiting() const;
bool should_animate_when_exiting() const {
return should_animate_when_exiting_;
}
void set_should_be_observed_when_exiting(bool should_be_observed) {
should_be_observed_when_exiting_ = should_be_observed;
}
bool ShouldBeObservedWhenExiting() const;
void ResetAnimationStates();
bool should_be_observed_when_exiting() const {
return should_be_observed_when_exiting_;
}
OverviewAnimationType GetExitOverviewAnimationType();
OverviewAnimationType GetExitTransformAnimationType();
......
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