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_manager_impl.h" | 5 #include "athena/wm/window_manager_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "athena/common/container_priorities.h" | 9 #include "athena/common/container_priorities.h" |
10 #include "athena/screen/public/screen_manager.h" | 10 #include "athena/screen/public/screen_manager.h" |
11 #include "athena/wm/bezel_controller.h" | 11 #include "athena/wm/bezel_controller.h" |
12 #include "athena/wm/public/window_manager_observer.h" | 12 #include "athena/wm/public/window_manager_observer.h" |
13 #include "athena/wm/split_view_controller.h" | 13 #include "athena/wm/split_view_controller.h" |
14 #include "athena/wm/title_drag_controller.h" | 14 #include "athena/wm/title_drag_controller.h" |
15 #include "athena/wm/window_list_provider_impl.h" | 15 #include "athena/wm/window_list_provider_impl.h" |
16 #include "athena/wm/window_overview_mode.h" | 16 #include "athena/wm/window_overview_mode.h" |
| 17 #include "base/bind.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "ui/aura/layout_manager.h" | 19 #include "ui/aura/layout_manager.h" |
19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 21 #include "ui/compositor/closure_animation_observer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
20 #include "ui/gfx/display.h" | 23 #include "ui/gfx/display.h" |
21 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
22 #include "ui/wm/core/shadow_controller.h" | 25 #include "ui/wm/core/shadow_controller.h" |
23 #include "ui/wm/core/window_util.h" | 26 #include "ui/wm/core/window_util.h" |
24 #include "ui/wm/core/wm_state.h" | 27 #include "ui/wm/core/wm_state.h" |
25 #include "ui/wm/public/activation_client.h" | 28 #include "ui/wm/public/activation_client.h" |
26 #include "ui/wm/public/window_types.h" | 29 #include "ui/wm/public/window_types.h" |
27 | 30 |
28 namespace athena { | 31 namespace athena { |
29 namespace { | 32 namespace { |
30 class WindowManagerImpl* instance = NULL; | 33 class WindowManagerImpl* instance = NULL; |
| 34 |
| 35 void SetWindowState(aura::Window* window, |
| 36 const gfx::Rect& bounds, |
| 37 const gfx::Transform& transform) { |
| 38 window->SetBounds(bounds); |
| 39 window->SetTransform(transform); |
| 40 } |
| 41 |
31 } // namespace | 42 } // namespace |
32 | 43 |
33 class AthenaContainerLayoutManager : public aura::LayoutManager { | 44 class AthenaContainerLayoutManager : public aura::LayoutManager { |
34 public: | 45 public: |
35 AthenaContainerLayoutManager(); | 46 AthenaContainerLayoutManager(); |
36 virtual ~AthenaContainerLayoutManager(); | 47 virtual ~AthenaContainerLayoutManager(); |
37 | 48 |
38 private: | 49 private: |
39 // aura::LayoutManager: | 50 // aura::LayoutManager: |
40 virtual void OnWindowResized() OVERRIDE; | 51 virtual void OnWindowResized() OVERRIDE; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 175 |
165 void WindowManagerImpl::SetInOverview(bool active) { | 176 void WindowManagerImpl::SetInOverview(bool active) { |
166 bool in_overview = !!overview_; | 177 bool in_overview = !!overview_; |
167 if (active == in_overview) | 178 if (active == in_overview) |
168 return; | 179 return; |
169 | 180 |
170 bezel_controller_->set_left_right_delegate( | 181 bezel_controller_->set_left_right_delegate( |
171 active ? NULL : split_view_controller_.get()); | 182 active ? NULL : split_view_controller_.get()); |
172 if (active) { | 183 if (active) { |
173 split_view_controller_->DeactivateSplitMode(); | 184 split_view_controller_->DeactivateSplitMode(); |
174 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 185 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeEnter()); |
175 OnOverviewModeEnter()); | 186 |
176 // Re-stack all windows in the order defined by window_list_provider_. | 187 // Re-stack all windows in the order defined by window_list_provider_. |
177 aura::Window::Windows window_list = window_list_provider_->GetWindowList(); | 188 aura::Window::Windows window_list = window_list_provider_->GetWindowList(); |
178 aura::Window::Windows::iterator it; | 189 aura::Window::Windows::iterator it; |
179 for (it = window_list.begin(); it != window_list.end(); ++it) | 190 for (it = window_list.begin(); it != window_list.end(); ++it) |
180 container_->StackChildAtTop(*it); | 191 container_->StackChildAtTop(*it); |
181 overview_ = WindowOverviewMode::Create( | 192 overview_ = WindowOverviewMode::Create( |
182 container_.get(), window_list_provider_.get(), this); | 193 container_.get(), window_list_provider_.get(), this); |
183 } else { | 194 } else { |
184 CHECK(!split_view_controller_->IsSplitViewModeActive()); | 195 CHECK(!split_view_controller_->IsSplitViewModeActive()); |
185 overview_.reset(); | 196 overview_.reset(); |
186 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 197 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeExit()); |
187 OnOverviewModeExit()); | |
188 } | 198 } |
189 } | 199 } |
190 | 200 |
191 void WindowManagerImpl::InstallAccelerators() { | 201 void WindowManagerImpl::InstallAccelerators() { |
192 const AcceleratorData accelerator_data[] = { | 202 const AcceleratorData accelerator_data[] = { |
193 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW, | 203 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW, |
194 AF_NONE}, | 204 AF_NONE}, |
195 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_CONTROL_DOWN, | 205 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_CONTROL_DOWN, |
196 CMD_TOGGLE_SPLIT_VIEW, AF_NONE}, | 206 CMD_TOGGLE_SPLIT_VIEW, AF_NONE}, |
197 }; | 207 }; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 behind = (iter == windows.rend()) ? NULL : *iter; | 289 behind = (iter == windows.rend()) ? NULL : *iter; |
280 } | 290 } |
281 | 291 |
282 return behind; | 292 return behind; |
283 } | 293 } |
284 | 294 |
285 void WindowManagerImpl::OnTitleDragStarted(aura::Window* window) { | 295 void WindowManagerImpl::OnTitleDragStarted(aura::Window* window) { |
286 aura::Window* next_window = GetWindowBehind(window); | 296 aura::Window* next_window = GetWindowBehind(window); |
287 if (!next_window) | 297 if (!next_window) |
288 return; | 298 return; |
289 // Make sure |window| is active. Also make sure that |next_window| is visible, | 299 // Make sure |window| is active. |
290 // and positioned to match the top-left edge of |window|. | |
291 wm::ActivateWindow(window); | 300 wm::ActivateWindow(window); |
| 301 |
| 302 // Make sure |next_window| is visibile. |
292 next_window->Show(); | 303 next_window->Show(); |
| 304 |
| 305 // Position |next_window| correctly (left aligned if it's larger than |
| 306 // |window|, and center aligned otherwise). |
293 int dx = window->bounds().x() - next_window->bounds().x(); | 307 int dx = window->bounds().x() - next_window->bounds().x(); |
| 308 if (next_window->bounds().width() < window->bounds().width()) |
| 309 dx -= (next_window->bounds().width() - window->bounds().width()) / 2; |
| 310 |
294 if (dx) { | 311 if (dx) { |
295 gfx::Transform transform; | 312 gfx::Transform transform; |
296 transform.Translate(dx, 0); | 313 transform.Translate(dx, 0); |
297 next_window->SetTransform(transform); | 314 next_window->SetTransform(transform); |
298 } | 315 } |
299 } | 316 } |
300 | 317 |
301 void WindowManagerImpl::OnTitleDragCompleted(aura::Window* window) { | 318 void WindowManagerImpl::OnTitleDragCompleted(aura::Window* window) { |
302 aura::Window* next_window = GetWindowBehind(window); | 319 aura::Window* next_window = GetWindowBehind(window); |
303 if (!next_window) | 320 if (!next_window) |
304 return; | 321 return; |
305 if (split_view_controller_->IsSplitViewModeActive()) | 322 if (split_view_controller_->IsSplitViewModeActive()) { |
306 split_view_controller_->ReplaceWindow(window, next_window); | 323 split_view_controller_->ReplaceWindow(window, next_window); |
307 else | 324 wm::ActivateWindow(next_window); |
| 325 } else { |
| 326 ui::ScopedLayerAnimationSettings |
| 327 settings(next_window->layer()->GetAnimator()); |
| 328 settings.AddObserver(new ui::ClosureAnimationObserver( |
| 329 base::Bind(&SetWindowState, |
| 330 base::Unretained(next_window), |
| 331 window->bounds(), |
| 332 gfx::Transform()))); |
| 333 |
| 334 gfx::Transform transform; |
| 335 transform.Scale(window->bounds().width() / next_window->bounds().width(), |
| 336 window->bounds().height() / next_window->bounds().height()); |
| 337 transform.Translate(window->bounds().x() - next_window->bounds().x(), 0); |
| 338 next_window->SetTransform(transform); |
| 339 |
308 OnSelectWindow(next_window); | 340 OnSelectWindow(next_window); |
309 wm::ActivateWindow(next_window); | 341 } |
| 342 window->Hide(); |
310 } | 343 } |
311 | 344 |
312 void WindowManagerImpl::OnTitleDragCanceled(aura::Window* window) { | 345 void WindowManagerImpl::OnTitleDragCanceled(aura::Window* window) { |
313 aura::Window* next_window = GetWindowBehind(window); | 346 aura::Window* next_window = GetWindowBehind(window); |
314 if (!next_window) | 347 if (!next_window) |
315 return; | 348 return; |
316 next_window->SetTransform(gfx::Transform()); | 349 next_window->SetTransform(gfx::Transform()); |
| 350 next_window->Hide(); |
317 } | 351 } |
318 | 352 |
319 // static | 353 // static |
320 WindowManager* WindowManager::Create() { | 354 WindowManager* WindowManager::Create() { |
321 DCHECK(!instance); | 355 DCHECK(!instance); |
322 new WindowManagerImpl; | 356 new WindowManagerImpl; |
323 DCHECK(instance); | 357 DCHECK(instance); |
324 return instance; | 358 return instance; |
325 } | 359 } |
326 | 360 |
327 // static | 361 // static |
328 void WindowManager::Shutdown() { | 362 void WindowManager::Shutdown() { |
329 DCHECK(instance); | 363 DCHECK(instance); |
330 delete instance; | 364 delete instance; |
331 DCHECK(!instance); | 365 DCHECK(!instance); |
332 } | 366 } |
333 | 367 |
334 // static | 368 // static |
335 WindowManager* WindowManager::GetInstance() { | 369 WindowManager* WindowManager::GetInstance() { |
336 DCHECK(instance); | 370 DCHECK(instance); |
337 return instance; | 371 return instance; |
338 } | 372 } |
339 | 373 |
340 } // namespace athena | 374 } // namespace athena |
OLD | NEW |