Chromium Code Reviews| Index: athena/wm/window_overview_mode.cc |
| diff --git a/athena/wm/window_overview_mode.cc b/athena/wm/window_overview_mode.cc |
| index e04858a3253a2d63354bfd9045cf3d50a8da6011..330380c6ad7c64bc2421ffd6f4a466cb39e6ac36 100644 |
| --- a/athena/wm/window_overview_mode.cc |
| +++ b/athena/wm/window_overview_mode.cc |
| @@ -8,6 +8,7 @@ |
| #include <functional> |
| #include <vector> |
| +#include "athena/wm/public/window_list_provider.h" |
| #include "base/bind.h" |
| #include "base/macros.h" |
| #include "ui/aura/scoped_window_targeter.h" |
| @@ -74,17 +75,12 @@ namespace athena { |
| namespace { |
| -bool ShouldShowWindowInOverviewMode(aura::Window* window) { |
| - return window->type() == ui::wm::WINDOW_TYPE_NORMAL; |
| -} |
| - |
| // Gets the transform for the window in its current state. |
| gfx::Transform GetTransformForState(WindowOverviewState* state) { |
| return gfx::Tween::TransformValueBetween(state->progress, |
| state->top, |
| state->bottom); |
| } |
| - |
|
sadrul
2014/08/09 13:32:40
Keep the blank line between the functions here.
mfomitchev
2014/08/09 18:29:56
Done.
|
| // Sets the progress-state for the window in the overview mode. |
| void SetWindowProgress(aura::Window* window, float progress) { |
| WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
| @@ -131,8 +127,10 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| public ui::CompositorAnimationObserver { |
| public: |
| WindowOverviewModeImpl(aura::Window* container, |
| + const WindowListProvider* window_list_provider, |
| WindowOverviewModeDelegate* delegate) |
| : container_(container), |
| + window_list_provider_(window_list_provider), |
| delegate_(delegate), |
| scoped_targeter_(new aura::ScopedWindowTargeter( |
| container, |
| @@ -150,13 +148,10 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| virtual ~WindowOverviewModeImpl() { |
| container_->set_target_handler(container_->delegate()); |
| RemoveAnimationObserver(); |
| - const aura::Window::Windows& windows = container_->children(); |
| - for (aura::Window::Windows::const_iterator iter = windows.begin(); |
| - iter != windows.end(); |
| - ++iter) { |
| - if ((*iter)->GetProperty(kWindowOverviewState)) |
| - RestoreWindowState(*iter); |
| - } |
| + aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| + if (windows.empty()) |
| + return; |
| + std::for_each(windows.begin(), windows.end(), &RestoreWindowState); |
| } |
| private: |
| @@ -164,10 +159,8 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| // positions. The transforms are set in the |kWindowOverviewState| property of |
| // the windows. |
| void ComputeTerminalStatesForAllWindows() { |
| - const aura::Window::Windows& windows = container_->children(); |
| - size_t window_count = std::count_if(windows.begin(), windows.end(), |
| - ShouldShowWindowInOverviewMode); |
| - |
| + aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| + size_t window_count = windows.size(); |
| size_t index = 0; |
| const gfx::Size container_size = container_->bounds().size(); |
| @@ -176,10 +169,8 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| iter != windows.rend(); |
| - ++iter) { |
| + ++iter, ++index) { |
| aura::Window* window = (*iter); |
| - if (!ShouldShowWindowInOverviewMode(window)) |
| - continue; |
| gfx::Transform top_transform; |
| int top = (window_count - index - 1) * kGapBetweenWindowsTop; |
| @@ -199,27 +190,20 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| state->progress = 0.f; |
| state->shadow = CreateShadowForWindow(window); |
| window->SetProperty(kWindowOverviewState, state); |
| - |
| - index++; |
| } |
| } |
| // Sets the initial position for the windows for the overview mode. |
| void SetInitialWindowStates() { |
| + aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| + size_t window_count = windows.size(); |
| // The initial overview state of the topmost three windows. |
| const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; |
| - size_t index = 0; |
| - const aura::Window::Windows& windows = container_->children(); |
| - for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| - iter != windows.rend(); |
| - ++iter) { |
| - aura::Window* window = (*iter); |
| - if (!window->GetProperty(kWindowOverviewState)) |
| - continue; |
| - |
| + for (size_t i = 0; i < window_count; ++i) { |
| float progress = 0.f; |
| - if (index < arraysize(kInitialProgress)) |
| - progress = kInitialProgress[index]; |
| + aura::Window* window = windows[window_count - 1 - i]; |
| + if (i < arraysize(kInitialProgress)) |
| + progress = kInitialProgress[i]; |
| scoped_refptr<ui::LayerAnimator> animator = |
| window->layer()->GetAnimator(); |
| @@ -240,14 +224,13 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); |
| SetWindowProgress(window, progress); |
| } |
| - index++; |
| } |
| } |
| scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) { |
| scoped_ptr<wm::Shadow> shadow(new wm::Shadow()); |
| shadow->Init(wm::Shadow::STYLE_ACTIVE); |
| - shadow->SetContentBounds(gfx::Rect(window->bounds().size())); |
| + shadow->SetContentBounds(gfx::Rect(container_->bounds().size())); |
| shadow->layer()->SetVisible(true); |
| window->layer()->Add(shadow->layer()); |
| return shadow.Pass(); |
| @@ -276,7 +259,7 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| void DoScroll(float delta_y) { |
| const float kEpsilon = 1e-3f; |
| float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); |
| - const aura::Window::Windows& windows = container_->children(); |
| + aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
| if (delta_y < 0) { |
| // Scroll up. Start with the top-most (i.e. behind-most in terms of |
| // z-index) window, and try to scroll them up. |
| @@ -285,8 +268,6 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| ++iter) { |
| aura::Window* window = (*iter); |
| WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
| - if (!state) |
| - continue; |
| if (state->progress > kEpsilon) { |
| // It is possible to scroll |window| up. Scroll it up, and update |
| // |delta_y_p| for the next window. |
| @@ -298,14 +279,12 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| } else { |
| // Scroll down. Start with the bottom-most (i.e. front-most in terms of |
| // z-index) window, and try to scroll them down. |
| - for (aura::Window::Windows::const_reverse_iterator iter = |
| - windows.rbegin(); |
| + aura::Window::Windows::const_reverse_iterator iter; |
| + for (iter = windows.rbegin(); |
| delta_y_p > kEpsilon && iter != windows.rend(); |
| ++iter) { |
| aura::Window* window = (*iter); |
| WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
| - if (!state) |
| - continue; |
| if (1.f - state->progress > kEpsilon) { |
| // It is possible to scroll |window| down. Scroll it down, and update |
| // |delta_y_p| for the next window. |
| @@ -521,6 +500,8 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| const float kMinOpacity = 0.2f; |
| aura::Window* container_; |
| + // Provider of the stack of windows to show in the overview mode. Not owned. |
| + const WindowListProvider* window_list_provider_; |
| WindowOverviewModeDelegate* delegate_; |
| scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; |
| scoped_ptr<ui::FlingCurve> fling_; |
| @@ -536,9 +517,10 @@ class WindowOverviewModeImpl : public WindowOverviewMode, |
| // static |
| scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( |
| aura::Window* container, |
| + const WindowListProvider* window_list_provider, |
| WindowOverviewModeDelegate* delegate) { |
| return scoped_ptr<WindowOverviewMode>( |
| - new WindowOverviewModeImpl(container, delegate)); |
| + new WindowOverviewModeImpl(container, window_list_provider, delegate)); |
| } |
| } // namespace athena |