OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "athena/wm/window_overview_mode.h" | 5 #include "athena/wm/window_overview_mode.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "athena/common/closure_animation_observer.h" | 11 #include "athena/common/closure_animation_observer.h" |
12 #include "athena/wm/public/window_list_provider.h" | 12 #include "athena/wm/public/window_list_provider.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "ui/aura/scoped_window_targeter.h" | 15 #include "ui/aura/scoped_window_targeter.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/aura/window_delegate.h" | 17 #include "ui/aura/window_delegate.h" |
18 #include "ui/aura/window_property.h" | 18 #include "ui/aura/window_property.h" |
19 #include "ui/aura/window_targeter.h" | 19 #include "ui/aura/window_targeter.h" |
20 #include "ui/aura/window_tree_host.h" | 20 #include "ui/aura/window_tree_host.h" |
21 #include "ui/compositor/compositor.h" | 21 #include "ui/compositor/compositor.h" |
22 #include "ui/compositor/compositor_animation_observer.h" | 22 #include "ui/compositor/compositor_animation_observer.h" |
23 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
24 #include "ui/events/event_handler.h" | 24 #include "ui/events/event_handler.h" |
25 #include "ui/events/gestures/fling_curve.h" | 25 #include "ui/events/gestures/fling_curve.h" |
26 #include "ui/gfx/frame_time.h" | 26 #include "ui/gfx/frame_time.h" |
27 #include "ui/gfx/transform.h" | 27 #include "ui/gfx/transform.h" |
28 #include "ui/wm/core/shadow.h" | 28 #include "ui/wm/core/shadow_types.h" |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 struct WindowOverviewState { | 32 struct WindowOverviewState { |
33 // The transform for when the window is at the topmost position. | 33 // The transform for when the window is at the topmost position. |
34 gfx::Transform top; | 34 gfx::Transform top; |
35 | 35 |
36 // The transform for when the window is at the bottom-most position. | 36 // The transform for when the window is at the bottom-most position. |
37 gfx::Transform bottom; | 37 gfx::Transform bottom; |
38 | 38 |
39 // The current overview state of the window. 0.f means the window is at the | 39 // The current overview state of the window. 0.f means the window is at the |
40 // topmost position. 1.f means the window is at the bottom-most position. | 40 // topmost position. 1.f means the window is at the bottom-most position. |
41 float progress; | 41 float progress; |
42 | |
43 scoped_ptr<wm::Shadow> shadow; | |
44 }; | 42 }; |
45 | 43 |
46 } // namespace | 44 } // namespace |
47 | 45 |
48 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*) | 46 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*) |
49 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, | 47 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, |
50 kWindowOverviewState, | 48 kWindowOverviewState, |
51 NULL) | 49 NULL) |
52 namespace athena { | 50 namespace athena { |
53 | 51 |
(...skipping 15 matching lines...) Expand all Loading... |
69 | 67 |
70 // Resets the overview-related state for |window|. | 68 // Resets the overview-related state for |window|. |
71 void RestoreWindowState(aura::Window* window) { | 69 void RestoreWindowState(aura::Window* window) { |
72 window->ClearProperty(kWindowOverviewState); | 70 window->ClearProperty(kWindowOverviewState); |
73 | 71 |
74 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 72 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
75 settings.SetPreemptionStrategy( | 73 settings.SetPreemptionStrategy( |
76 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 74 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
77 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | 75 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); |
78 window->SetTransform(gfx::Transform()); | 76 window->SetTransform(gfx::Transform()); |
| 77 wm::SetShadowType(window, wm::SHADOW_TYPE_NONE); |
79 } | 78 } |
80 | 79 |
81 // Always returns the same target. | 80 // Always returns the same target. |
82 class StaticWindowTargeter : public aura::WindowTargeter { | 81 class StaticWindowTargeter : public aura::WindowTargeter { |
83 public: | 82 public: |
84 explicit StaticWindowTargeter(aura::Window* target) : target_(target) {} | 83 explicit StaticWindowTargeter(aura::Window* target) : target_(target) {} |
85 virtual ~StaticWindowTargeter() {} | 84 virtual ~StaticWindowTargeter() {} |
86 | 85 |
87 private: | 86 private: |
88 // aura::WindowTargeter: | 87 // aura::WindowTargeter: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 gfx::Transform bottom_transform; | 159 gfx::Transform bottom_transform; |
161 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); | 160 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); |
162 x_translate = container_size.width() * (1 - kMaxScale) / 2.; | 161 x_translate = container_size.width() * (1 - kMaxScale) / 2.; |
163 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); | 162 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); |
164 bottom_transform.Scale(kMaxScale, kMaxScale); | 163 bottom_transform.Scale(kMaxScale, kMaxScale); |
165 | 164 |
166 WindowOverviewState* state = new WindowOverviewState; | 165 WindowOverviewState* state = new WindowOverviewState; |
167 state->top = top_transform; | 166 state->top = top_transform; |
168 state->bottom = bottom_transform; | 167 state->bottom = bottom_transform; |
169 state->progress = 0.f; | 168 state->progress = 0.f; |
170 state->shadow = CreateShadowForWindow(window); | |
171 window->SetProperty(kWindowOverviewState, state); | 169 window->SetProperty(kWindowOverviewState, state); |
| 170 wm::SetShadowType(window, wm::SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE); |
172 } | 171 } |
173 } | 172 } |
174 | 173 |
175 // Sets the initial position for the windows for the overview mode. | 174 // Sets the initial position for the windows for the overview mode. |
176 void SetInitialWindowStates() { | 175 void SetInitialWindowStates() { |
177 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 176 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
178 size_t window_count = windows.size(); | 177 size_t window_count = windows.size(); |
179 // The initial overview state of the topmost three windows. | 178 // The initial overview state of the topmost three windows. |
180 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; | 179 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; |
181 for (size_t i = 0; i < window_count; ++i) { | 180 for (size_t i = 0; i < window_count; ++i) { |
(...skipping 17 matching lines...) Expand all Loading... |
199 { | 198 { |
200 ui::ScopedLayerAnimationSettings settings(animator); | 199 ui::ScopedLayerAnimationSettings settings(animator); |
201 settings.SetPreemptionStrategy( | 200 settings.SetPreemptionStrategy( |
202 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 201 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
203 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | 202 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); |
204 SetWindowProgress(window, progress); | 203 SetWindowProgress(window, progress); |
205 } | 204 } |
206 } | 205 } |
207 } | 206 } |
208 | 207 |
209 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) { | |
210 scoped_ptr<wm::Shadow> shadow(new wm::Shadow()); | |
211 shadow->Init(wm::Shadow::STYLE_ACTIVE); | |
212 shadow->SetContentBounds(gfx::Rect(container_->bounds().size())); | |
213 shadow->layer()->SetVisible(true); | |
214 window->layer()->Add(shadow->layer()); | |
215 return shadow.Pass(); | |
216 } | |
217 | |
218 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { | 208 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { |
219 CHECK_EQ(container_, event->target()); | 209 CHECK_EQ(container_, event->target()); |
220 // Find the old targeter to find the target of the event. | 210 // Find the old targeter to find the target of the event. |
221 ui::EventTarget* window = container_; | 211 ui::EventTarget* window = container_; |
222 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); | 212 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); |
223 while (!targeter && window->GetParentTarget()) { | 213 while (!targeter && window->GetParentTarget()) { |
224 window = window->GetParentTarget(); | 214 window = window->GetParentTarget(); |
225 targeter = window->GetEventTargeter(); | 215 targeter = window->GetEventTargeter(); |
226 } | 216 } |
227 if (!targeter) | 217 if (!targeter) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 // static | 486 // static |
497 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( | 487 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( |
498 aura::Window* container, | 488 aura::Window* container, |
499 const WindowListProvider* window_list_provider, | 489 const WindowListProvider* window_list_provider, |
500 WindowOverviewModeDelegate* delegate) { | 490 WindowOverviewModeDelegate* delegate) { |
501 return scoped_ptr<WindowOverviewMode>( | 491 return scoped_ptr<WindowOverviewMode>( |
502 new WindowOverviewModeImpl(container, window_list_provider, delegate)); | 492 new WindowOverviewModeImpl(container, window_list_provider, delegate)); |
503 } | 493 } |
504 | 494 |
505 } // namespace athena | 495 } // namespace athena |
OLD | NEW |