Commit da082e7e authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

Introduce ScopedBoundsChangeAnimation to temporarily change animation type.

Refactoring CL. No functional change.

Bug: None
Change-Id: I6e6027b5994e48d3ebafb7ec09062600763b0d28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1726665Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683641}
parent 37260227
...@@ -584,11 +584,9 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state, ...@@ -584,11 +584,9 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state,
if (IsMinimizedWindowStateType(previous_state_type) || if (IsMinimizedWindowStateType(previous_state_type) ||
window_state->IsFullscreen() || window_state->IsPinned() || window_state->IsFullscreen() || window_state->IsPinned() ||
enter_animation_type() == IMMEDIATE) { window_state->bounds_animation_type() ==
WindowState::BoundsChangeAnimationType::IMMEDIATE) {
window_state->SetBoundsDirect(bounds_in_parent); window_state->SetBoundsDirect(bounds_in_parent);
// Reset the |enter_animation_type_| to DEFAULT if it is IMMEDIATE, which is
// set for non-top windows when entering clamshell mode.
set_enter_animation_type(DEFAULT);
} else if (window_state->IsMaximized() || } else if (window_state->IsMaximized() ||
IsMaximizedOrFullscreenOrPinnedWindowStateType( IsMaximizedOrFullscreenOrPinnedWindowStateType(
previous_state_type)) { previous_state_type)) {
......
...@@ -195,8 +195,10 @@ TabletModeWindowState::TabletModeWindowState(aura::Window* window, ...@@ -195,8 +195,10 @@ TabletModeWindowState::TabletModeWindowState(aura::Window* window,
state_type_on_attach_ = state_type_on_attach_ =
snap ? current_state_type_ : GetMaximizedOrCenteredWindowType(state); snap ? current_state_type_ : GetMaximizedOrCenteredWindowType(state);
// TODO(oshima|sammiequon): consider SplitView scenario. // TODO(oshima|sammiequon): consider SplitView scenario.
if (entering_tablet_mode) WindowState::ScopedBoundsChangeAnimation bounds_animation(
set_enter_animation_type(IsTopWindow(window) ? DEFAULT : STEP_END); window, entering_tablet_mode && !IsTopWindow(window)
? WindowState::BoundsChangeAnimationType::STEP_END
: WindowState::BoundsChangeAnimationType::DEFAULT);
old_state_.reset( old_state_.reset(
state->SetStateObject(std::unique_ptr<State>(this)).release()); state->SetStateObject(std::unique_ptr<State>(this)).release());
} }
...@@ -211,17 +213,19 @@ void TabletModeWindowState::LeaveTabletMode(WindowState* window_state, ...@@ -211,17 +213,19 @@ void TabletModeWindowState::LeaveTabletMode(WindowState* window_state,
// or the top window or a window showing in splitview before leaving tablet // or the top window or a window showing in splitview before leaving tablet
// mode, and the window has changed its state. Otherwise, restore its bounds // mode, and the window has changed its state. Otherwise, restore its bounds
// immediately. // immediately.
EnterAnimationType animation_type = WindowState::BoundsChangeAnimationType animation_type =
was_in_overview || window_state->IsSnapped() || was_in_overview || window_state->IsSnapped() ||
IsTopWindow(window_state->window()) IsTopWindow(window_state->window())
? DEFAULT ? WindowState::BoundsChangeAnimationType::DEFAULT
: IMMEDIATE; : WindowState::BoundsChangeAnimationType::IMMEDIATE;
if (old_state_->GetType() == window_state->GetStateType() && if (old_state_->GetType() == window_state->GetStateType() &&
!window_state->IsNormalStateType()) { !window_state->IsNormalStateType()) {
animation_type = IMMEDIATE; animation_type = WindowState::BoundsChangeAnimationType::IMMEDIATE;
} }
old_state_->set_enter_animation_type(animation_type);
// Note: When we return we will destroy ourselves with the |our_reference|. // Note: When we return we will destroy ourselves with the |our_reference|.
WindowState::ScopedBoundsChangeAnimation bounds_animation(
window_state->window(), animation_type);
std::unique_ptr<WindowState::State> our_reference = std::unique_ptr<WindowState::State> our_reference =
window_state->SetStateObject(std::move(old_state_)); window_state->SetStateObject(std::move(old_state_));
} }
...@@ -480,16 +484,14 @@ void TabletModeWindowState::UpdateBounds(WindowState* window_state, ...@@ -480,16 +484,14 @@ void TabletModeWindowState::UpdateBounds(WindowState* window_state,
if (!window_state->window()->IsVisible() || !animated) { if (!window_state->window()->IsVisible() || !animated) {
window_state->SetBoundsDirect(bounds_in_parent); window_state->SetBoundsDirect(bounds_in_parent);
} else { } else {
if (enter_animation_type() == STEP_END) { if (window_state->bounds_animation_type() ==
WindowState::BoundsChangeAnimationType::STEP_END) {
// Just use the normal bounds animation with ZERO tween with long enough // Just use the normal bounds animation with ZERO tween with long enough
// duration for STEP_END. The animation will be stopped when the to // duration for STEP_END. The animation will be stopped when the to
// window's animation ends. // window's animation ends.
window_state->SetBoundsDirectAnimated(bounds_in_parent, window_state->SetBoundsDirectAnimated(bounds_in_parent,
base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(1),
gfx::Tween::ZERO); gfx::Tween::ZERO);
// Reset the |enter_animation_type_| to DEFAULT it if is STEP_END, which
// is set for non-top windows when entering tablet mode.
set_enter_animation_type(DEFAULT);
return; return;
} }
// If we animate (to) tablet mode, we want to use the cross fade to // If we animate (to) tablet mode, we want to use the cross fade to
......
...@@ -178,6 +178,31 @@ void CollectPipEnterExitMetrics(aura::Window* window, bool enter) { ...@@ -178,6 +178,31 @@ void CollectPipEnterExitMetrics(aura::Window* window, bool enter) {
constexpr base::TimeDelta WindowState::kBoundsChangeSlideDuration; constexpr base::TimeDelta WindowState::kBoundsChangeSlideDuration;
WindowState::ScopedBoundsChangeAnimation::ScopedBoundsChangeAnimation(
aura::Window* window,
BoundsChangeAnimationType bounds_animation_type)
: window_(window) {
window_->AddObserver(this);
previous_bounds_animation_type_ =
WindowState::Get(window_)->bounds_animation_type_;
WindowState::Get(window_)->bounds_animation_type_ = bounds_animation_type;
}
WindowState::ScopedBoundsChangeAnimation::~ScopedBoundsChangeAnimation() {
if (window_) {
WindowState::Get(window_)->bounds_animation_type_ =
previous_bounds_animation_type_;
window_->RemoveObserver(this);
window_ = nullptr;
}
}
void WindowState::ScopedBoundsChangeAnimation::OnWindowDestroying(
aura::Window* window) {
window_->RemoveObserver(this);
window_ = nullptr;
}
WindowState::~WindowState() { WindowState::~WindowState() {
// WindowState is registered as an owned property of |window_|, and window // WindowState is registered as an owned property of |window_|, and window
// unregisters all of its observers in its d'tor before destroying its // unregisters all of its observers in its d'tor before destroying its
......
...@@ -58,11 +58,6 @@ class ASH_EXPORT WindowState : public aura::WindowObserver { ...@@ -58,11 +58,6 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
// Each subclass defines its own behavior and transition for each WMEvent. // Each subclass defines its own behavior and transition for each WMEvent.
class State { class State {
public: public:
// Animation type of updating window bounds for entering current state.
// "IMMEDIATE" means update bounds directly without animation. "STEP_END"
// means update bounds at the end of the animation.
enum EnterAnimationType { DEFAULT, IMMEDIATE, STEP_END };
State() {} State() {}
virtual ~State() {} virtual ~State() {}
...@@ -87,16 +82,7 @@ class ASH_EXPORT WindowState : public aura::WindowObserver { ...@@ -87,16 +82,7 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
// Called when the window is being destroyed. // Called when the window is being destroyed.
virtual void OnWindowDestroying(WindowState* window_state) {} virtual void OnWindowDestroying(WindowState* window_state) {}
EnterAnimationType enter_animation_type() const {
return enter_animation_type_;
}
void set_enter_animation_type(EnterAnimationType type) {
enter_animation_type_ = type;
}
private: private:
EnterAnimationType enter_animation_type_ = DEFAULT;
DISALLOW_COPY_AND_ASSIGN(State); DISALLOW_COPY_AND_ASSIGN(State);
}; };
...@@ -359,15 +345,41 @@ class ASH_EXPORT WindowState : public aura::WindowObserver { ...@@ -359,15 +345,41 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
friend class DefaultState; friend class DefaultState;
friend class LockWindowState; friend class LockWindowState;
friend class TabletModeWindowState; friend class TabletModeWindowState;
friend class ScopedBoundsChangeAnimation;
FRIEND_TEST_ALL_PREFIXES(WindowAnimationsTest, CrossFadeToBounds); FRIEND_TEST_ALL_PREFIXES(WindowAnimationsTest, CrossFadeToBounds);
FRIEND_TEST_ALL_PREFIXES(WindowAnimationsTest, FRIEND_TEST_ALL_PREFIXES(WindowAnimationsTest,
CrossFadeToBoundsFromTransform); CrossFadeToBoundsFromTransform);
FRIEND_TEST_ALL_PREFIXES(WindowStateTest, PipWindowMaskRecreated); FRIEND_TEST_ALL_PREFIXES(WindowStateTest, PipWindowMaskRecreated);
FRIEND_TEST_ALL_PREFIXES(WindowStateTest, PipWindowHasMaskLayer); FRIEND_TEST_ALL_PREFIXES(WindowStateTest, PipWindowHasMaskLayer);
// Animation type of updating window bounds. "IMMEDIATE" means update bounds
// directly without animation. "STEP_END" means update bounds at the end of
// the animation.
enum class BoundsChangeAnimationType { DEFAULT, IMMEDIATE, STEP_END };
// A class can temporarily change the window bounds change animation type.
class ScopedBoundsChangeAnimation : public aura::WindowObserver {
public:
ScopedBoundsChangeAnimation(aura::Window* window,
BoundsChangeAnimationType animation_type);
~ScopedBoundsChangeAnimation() override;
// aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override;
private:
aura::Window* window_;
BoundsChangeAnimationType previous_bounds_animation_type_;
DISALLOW_COPY_AND_ASSIGN(ScopedBoundsChangeAnimation);
};
explicit WindowState(aura::Window* window); explicit WindowState(aura::Window* window);
WindowStateDelegate* delegate() { return delegate_.get(); } WindowStateDelegate* delegate() { return delegate_.get(); }
BoundsChangeAnimationType bounds_animation_type() {
return bounds_animation_type_;
}
bool HasMaximumWidthOrHeight() const; bool HasMaximumWidthOrHeight() const;
...@@ -476,6 +488,10 @@ class ASH_EXPORT WindowState : public aura::WindowObserver { ...@@ -476,6 +488,10 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
std::unique_ptr<State> current_state_; std::unique_ptr<State> current_state_;
// The animation type for the bounds change.
BoundsChangeAnimationType bounds_animation_type_ =
BoundsChangeAnimationType::DEFAULT;
DISALLOW_COPY_AND_ASSIGN(WindowState); DISALLOW_COPY_AND_ASSIGN(WindowState);
}; };
......
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