Chromium Code Reviews| Index: ash/wm/compact_layout_manager.cc |
| diff --git a/ash/wm/compact_layout_manager.cc b/ash/wm/compact_layout_manager.cc |
| index 9cbff21af0a8d24e27034f22c801d347fd644196..05ea35572352c8a76f925f5ce81e1be88ab4983f 100644 |
| --- a/ash/wm/compact_layout_manager.cc |
| +++ b/ash/wm/compact_layout_manager.cc |
| @@ -10,6 +10,7 @@ |
| #include "ash/shell_delegate.h" |
| #include "ash/shell_window_ids.h" |
| #include "ash/wm/window_util.h" |
| +#include "base/memory/scoped_vector.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/window.h" |
| #include "ui/gfx/compositor/scoped_layer_animation_settings.h" |
| @@ -39,14 +40,6 @@ bool ShouldAnimateOnEntrance(aura::Window* window) { |
| window_util::IsWindowMaximized(window); |
| } |
| -// Adjust layer bounds to grow or shrink in |delta_width|. |
| -void AdjustContainerLayerWidth(int delta_width) { |
| - gfx::Rect bounds(GetDefaultContainerLayer()->bounds()); |
| - bounds.set_width(bounds.width() + delta_width); |
| - GetDefaultContainerLayer()->SetBounds(bounds); |
| - GetDefaultContainerLayer()->GetCompositor()->WidgetSizeChanged( |
| - GetDefaultContainerLayer()->bounds().size()); |
| -} |
| } // namespace |
| ///////////////////////////////////////////////////////////////////////////// |
| @@ -69,20 +62,11 @@ void CompactLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| child->SetProperty(aura::client::kAnimationsDisabledKey, true); |
| BaseLayoutManager::OnWindowAddedToLayout(child); |
| UpdateStatusAreaVisibility(); |
| - if (windows().size() > 1 && |
| - child->type() == aura::client::WINDOW_TYPE_NORMAL) { |
| - // The first window is already contained in the current layer, |
| - // add subsequent windows to layer bounds calculation. |
| - AdjustContainerLayerWidth(child->bounds().width()); |
| - } |
| } |
| void CompactLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
| BaseLayoutManager::OnWillRemoveWindowFromLayout(child); |
| UpdateStatusAreaVisibility(); |
| - if (windows().size() > 1 && ShouldAnimateOnEntrance(child)) |
| - AdjustContainerLayerWidth(-child->bounds().width()); |
| - |
| if (child == current_window_) { |
| LayoutWindows(current_window_); |
| SwitchToReplacementWindow(); |
| @@ -154,8 +138,9 @@ void CompactLayoutManager::OnWindowStackingChanged(aura::Window* window) { |
| // CompactLayoutManager, AnimationDelegate overrides: |
| void CompactLayoutManager::OnImplicitAnimationsCompleted() { |
| - if (!GetDefaultContainerLayer()->GetAnimator()->is_animating()) |
| - HideWindows(); |
| + if (AreWindowsAnimating()) |
| + return; |
| + HideWindows(); |
| } |
| ////////////////////////////////////////////////////////////////////////////// |
| @@ -174,13 +159,40 @@ void CompactLayoutManager::UpdateStatusAreaVisibility() { |
| } |
| void CompactLayoutManager::AnimateSlideTo(int offset_x) { |
| - GetDefaultContainerLayer()->GetAnimator()->RemoveObserver(this); |
| - ui::ScopedLayerAnimationSettings settings( |
| - GetDefaultContainerLayer()->GetAnimator()); |
| - settings.AddObserver(this); |
| - ui::Transform transform; |
| - transform.ConcatTranslate(-offset_x, 0); |
| - GetDefaultContainerLayer()->SetTransform(transform); // Will be animated! |
| + // If we were waiting for another implicit animation to complete, forget |
| + // about it since we're about to start observing a new animation. |
| + StopObservingImplicitAnimations(); |
| + ScopedVector<ui::ScopedLayerAnimationSettings> settings; |
| + ShellDelegate* shell_delegate = ash::Shell::GetInstance()->delegate(); |
| + const WindowList& windows_list = shell_delegate->GetCycleWindowList( |
| + ShellDelegate::SOURCE_KEYBOARD, |
| + ShellDelegate::ORDER_LINEAR); |
| + for (WindowListConstIter const_it = windows_list.begin(); |
| + const_it != windows_list.end(); |
| + ++const_it) { |
| + settings.push_back(new ui::ScopedLayerAnimationSettings( |
| + (*const_it)->layer()->GetAnimator())); |
| + settings[settings.size() - 1]->AddObserver(this); |
|
alicet1
2012/02/14 16:04:39
settings.back()?
|
| + settings[settings.size() - 1]->SetPreemptionStrategy( |
| + ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| + gfx::Rect bounds = (*const_it)->layer()->bounds(); |
|
alicet1
2012/02/14 16:04:39
should this be GetTargetBounds() ?
|
| + bounds.Offset(-offset_x, 0); |
| + (*const_it)->layer()->SetBounds(bounds); |
| + } |
| +} |
| + |
| +bool CompactLayoutManager::AreWindowsAnimating() const { |
| + ShellDelegate* shell_delegate = ash::Shell::GetInstance()->delegate(); |
| + const WindowList& windows_list = shell_delegate->GetCycleWindowList( |
| + ShellDelegate::SOURCE_KEYBOARD, |
| + ShellDelegate::ORDER_LINEAR); |
| + for (WindowListConstIter const_it = windows_list.begin(); |
| + const_it != windows_list.end(); |
| + ++const_it) { |
| + if ((*const_it)->layer()->GetAnimator()->is_animating()) |
| + return true; |
| + } |
| + return false; |
| } |
| void CompactLayoutManager::LayoutWindows(aura::Window* skip) { |
| @@ -188,13 +200,18 @@ void CompactLayoutManager::LayoutWindows(aura::Window* skip) { |
| const WindowList& windows_list = shell_delegate->GetCycleWindowList( |
| ShellDelegate::SOURCE_KEYBOARD, |
| ShellDelegate::ORDER_LINEAR); |
| + bool first_window = true; |
| int new_x = 0; |
| for (WindowListConstIter const_it = windows_list.begin(); |
| const_it != windows_list.end(); |
| ++const_it) { |
| if (*const_it != skip) { |
| gfx::Rect new_bounds((*const_it)->bounds()); |
| - new_bounds.set_x(new_x); |
| + if (first_window) { |
| + new_x = new_bounds.x(); |
| + first_window = false; |
| + } else |
| + new_bounds.set_x(new_x); |
| SetChildBoundsDirect(*const_it, new_bounds); |
| (*const_it)->layer()->SetVisible(true); |
| new_x += (*const_it)->bounds().width(); |
| @@ -219,7 +236,8 @@ void CompactLayoutManager::HideWindows() { |
| for (WindowListConstIter const_it = windows_list.begin(); |
| const_it != windows_list.end(); |
| ++const_it) { |
| - if (*const_it != current_window_) |
| + if (*const_it != current_window_ && |
| + (*const_it)->layer()->GetTargetVisibility()) |
| (*const_it)->layer()->SetVisible(false); |
| } |
| } |