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/public/window_manager.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/input/public/accelerator_manager.h" | |
11 #include "athena/screen/public/screen_manager.h" | 10 #include "athena/screen/public/screen_manager.h" |
12 #include "athena/wm/bezel_controller.h" | 11 #include "athena/wm/bezel_controller.h" |
13 #include "athena/wm/public/window_manager_observer.h" | 12 #include "athena/wm/public/window_manager_observer.h" |
14 #include "athena/wm/split_view_controller.h" | 13 #include "athena/wm/split_view_controller.h" |
15 #include "athena/wm/title_drag_controller.h" | 14 #include "athena/wm/title_drag_controller.h" |
16 #include "athena/wm/window_list_provider_impl.h" | 15 #include "athena/wm/window_list_provider_impl.h" |
17 #include "athena/wm/window_overview_mode.h" | 16 #include "athena/wm/window_overview_mode.h" |
18 #include "base/logging.h" | 17 #include "base/logging.h" |
19 #include "base/observer_list.h" | |
20 #include "ui/aura/layout_manager.h" | 18 #include "ui/aura/layout_manager.h" |
21 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
22 #include "ui/wm/core/shadow_controller.h" | 20 #include "ui/wm/core/shadow_controller.h" |
23 #include "ui/wm/core/window_util.h" | 21 #include "ui/wm/core/window_util.h" |
24 #include "ui/wm/core/wm_state.h" | 22 #include "ui/wm/core/wm_state.h" |
25 #include "ui/wm/public/activation_client.h" | 23 #include "ui/wm/public/activation_client.h" |
26 #include "ui/wm/public/window_types.h" | 24 #include "ui/wm/public/window_types.h" |
27 | 25 |
28 namespace athena { | 26 namespace athena { |
29 namespace { | 27 namespace { |
30 | 28 |
31 class WindowManagerImpl : public WindowManager, | 29 class WindowManagerImpl* instance = NULL; |
32 public WindowOverviewModeDelegate, | |
33 public aura::WindowObserver, | |
34 public AcceleratorHandler, | |
35 public TitleDragControllerDelegate { | |
36 public: | |
37 WindowManagerImpl(); | |
38 virtual ~WindowManagerImpl(); | |
39 | |
40 void Layout(); | |
41 | |
42 // WindowManager: | |
43 virtual void ToggleOverview() OVERRIDE; | |
44 | |
45 virtual bool IsOverviewModeActive() OVERRIDE; | |
46 | |
47 private: | |
48 enum Command { | |
49 CMD_TOGGLE_OVERVIEW, | |
50 }; | |
51 | |
52 // Sets whether overview mode is active. | |
53 void SetInOverview(bool active); | |
54 | |
55 void InstallAccelerators(); | |
56 | |
57 // WindowManager: | |
58 virtual void AddObserver(WindowManagerObserver* observer) OVERRIDE; | |
59 virtual void RemoveObserver(WindowManagerObserver* observer) OVERRIDE; | |
60 | |
61 // WindowOverviewModeDelegate: | |
62 virtual void OnSelectWindow(aura::Window* window) OVERRIDE; | |
63 virtual void OnSplitViewMode(aura::Window* left, | |
64 aura::Window* right) OVERRIDE; | |
65 | |
66 // aura::WindowObserver | |
67 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE; | |
68 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | |
69 | |
70 // AcceleratorHandler: | |
71 virtual bool IsCommandEnabled(int command_id) const OVERRIDE; | |
72 virtual bool OnAcceleratorFired(int command_id, | |
73 const ui::Accelerator& accelerator) OVERRIDE; | |
74 | |
75 // TitleDragControllerDelegate: | |
76 virtual aura::Window* GetWindowBehind(aura::Window* window) OVERRIDE; | |
77 virtual void OnTitleDragStarted(aura::Window* window) OVERRIDE; | |
78 virtual void OnTitleDragCompleted(aura::Window* window) OVERRIDE; | |
79 virtual void OnTitleDragCanceled(aura::Window* window) OVERRIDE; | |
80 | |
81 scoped_ptr<aura::Window> container_; | |
82 scoped_ptr<WindowListProvider> window_list_provider_; | |
83 scoped_ptr<WindowOverviewMode> overview_; | |
84 scoped_ptr<BezelController> bezel_controller_; | |
85 scoped_ptr<SplitViewController> split_view_controller_; | |
86 scoped_ptr<wm::WMState> wm_state_; | |
87 scoped_ptr<TitleDragController> title_drag_controller_; | |
88 scoped_ptr<wm::ShadowController> shadow_controller_; | |
89 ObserverList<WindowManagerObserver> observers_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); | |
92 }; | |
93 | 30 |
94 class AthenaContainerLayoutManager : public aura::LayoutManager { | 31 class AthenaContainerLayoutManager : public aura::LayoutManager { |
95 public: | 32 public: |
96 AthenaContainerLayoutManager(); | 33 AthenaContainerLayoutManager(); |
97 virtual ~AthenaContainerLayoutManager(); | 34 virtual ~AthenaContainerLayoutManager(); |
98 | 35 |
99 private: | 36 private: |
100 // aura::LayoutManager: | 37 // aura::LayoutManager: |
101 virtual void OnWindowResized() OVERRIDE; | 38 virtual void OnWindowResized() OVERRIDE; |
102 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; | 39 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; |
103 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; | 40 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; |
104 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; | 41 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; |
105 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 42 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
106 bool visible) OVERRIDE; | 43 bool visible) OVERRIDE; |
107 virtual void SetChildBounds(aura::Window* child, | 44 virtual void SetChildBounds(aura::Window* child, |
108 const gfx::Rect& requested_bounds) OVERRIDE; | 45 const gfx::Rect& requested_bounds) OVERRIDE; |
109 | 46 |
110 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); | 47 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); |
111 }; | 48 }; |
112 | 49 |
113 class WindowManagerImpl* instance = NULL; | 50 AthenaContainerLayoutManager::AthenaContainerLayoutManager() { |
| 51 } |
| 52 |
| 53 AthenaContainerLayoutManager::~AthenaContainerLayoutManager() { |
| 54 } |
| 55 |
| 56 void AthenaContainerLayoutManager::OnWindowResized() { |
| 57 instance->Layout(); |
| 58 } |
| 59 |
| 60 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 61 instance->Layout(); |
| 62 } |
| 63 |
| 64 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( |
| 65 aura::Window* child) { |
| 66 } |
| 67 |
| 68 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( |
| 69 aura::Window* child) { |
| 70 instance->Layout(); |
| 71 } |
| 72 |
| 73 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( |
| 74 aura::Window* child, |
| 75 bool visible) { |
| 76 instance->Layout(); |
| 77 } |
| 78 |
| 79 void AthenaContainerLayoutManager::SetChildBounds( |
| 80 aura::Window* child, |
| 81 const gfx::Rect& requested_bounds) { |
| 82 if (!requested_bounds.IsEmpty()) |
| 83 SetChildBoundsDirect(child, requested_bounds); |
| 84 } |
| 85 |
| 86 } // namespace |
114 | 87 |
115 WindowManagerImpl::WindowManagerImpl() { | 88 WindowManagerImpl::WindowManagerImpl() { |
116 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); | 89 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); |
117 params.can_activate_children = true; | 90 params.can_activate_children = true; |
118 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 91 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
119 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 92 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
120 container_->AddObserver(this); | 93 container_->AddObserver(this); |
121 window_list_provider_.reset(new WindowListProviderImpl(container_.get())); | 94 window_list_provider_.reset(new WindowListProviderImpl(container_.get())); |
122 bezel_controller_.reset(new BezelController(container_.get())); | 95 bezel_controller_.reset(new BezelController(container_.get())); |
123 split_view_controller_.reset( | 96 split_view_controller_.reset( |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 wm::ActivateWindow(next_window); | 267 wm::ActivateWindow(next_window); |
295 } | 268 } |
296 | 269 |
297 void WindowManagerImpl::OnTitleDragCanceled(aura::Window* window) { | 270 void WindowManagerImpl::OnTitleDragCanceled(aura::Window* window) { |
298 aura::Window* next_window = GetWindowBehind(window); | 271 aura::Window* next_window = GetWindowBehind(window); |
299 if (!next_window) | 272 if (!next_window) |
300 return; | 273 return; |
301 next_window->SetTransform(gfx::Transform()); | 274 next_window->SetTransform(gfx::Transform()); |
302 } | 275 } |
303 | 276 |
304 AthenaContainerLayoutManager::AthenaContainerLayoutManager() { | |
305 } | |
306 | |
307 AthenaContainerLayoutManager::~AthenaContainerLayoutManager() { | |
308 } | |
309 | |
310 void AthenaContainerLayoutManager::OnWindowResized() { | |
311 instance->Layout(); | |
312 } | |
313 | |
314 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | |
315 instance->Layout(); | |
316 } | |
317 | |
318 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( | |
319 aura::Window* child) { | |
320 } | |
321 | |
322 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( | |
323 aura::Window* child) { | |
324 instance->Layout(); | |
325 } | |
326 | |
327 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( | |
328 aura::Window* child, | |
329 bool visible) { | |
330 instance->Layout(); | |
331 } | |
332 | |
333 void AthenaContainerLayoutManager::SetChildBounds( | |
334 aura::Window* child, | |
335 const gfx::Rect& requested_bounds) { | |
336 if (!requested_bounds.IsEmpty()) | |
337 SetChildBoundsDirect(child, requested_bounds); | |
338 } | |
339 | |
340 } // namespace | |
341 | |
342 // static | 277 // static |
343 WindowManager* WindowManager::Create() { | 278 WindowManager* WindowManager::Create() { |
344 DCHECK(!instance); | 279 DCHECK(!instance); |
345 new WindowManagerImpl; | 280 new WindowManagerImpl; |
346 DCHECK(instance); | 281 DCHECK(instance); |
347 return instance; | 282 return instance; |
348 } | 283 } |
349 | 284 |
350 // static | 285 // static |
351 void WindowManager::Shutdown() { | 286 void WindowManager::Shutdown() { |
352 DCHECK(instance); | 287 DCHECK(instance); |
353 delete instance; | 288 delete instance; |
354 DCHECK(!instance); | 289 DCHECK(!instance); |
355 } | 290 } |
356 | 291 |
357 // static | 292 // static |
358 WindowManager* WindowManager::GetInstance() { | 293 WindowManager* WindowManager::GetInstance() { |
359 DCHECK(instance); | 294 DCHECK(instance); |
360 return instance; | 295 return instance; |
361 } | 296 } |
362 | 297 |
363 } // namespace athena | 298 } // namespace athena |
OLD | NEW |