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/public/window_manager.h" |
6 | 6 |
7 #include "athena/screen/public/screen_manager.h" | 7 #include "athena/screen/public/screen_manager.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
11 | 11 |
12 namespace athena { | 12 namespace athena { |
13 namespace { | 13 namespace { |
14 | 14 |
15 class WindowManagerImpl : public WindowManager { | 15 class WindowManagerImpl : public WindowManager, public aura::WindowObserver { |
16 public: | 16 public: |
17 WindowManagerImpl(); | 17 WindowManagerImpl(); |
18 virtual ~WindowManagerImpl(); | 18 virtual ~WindowManagerImpl(); |
19 | 19 |
20 void Layout(); | 20 void Layout(); |
21 | 21 |
22 private: | 22 private: |
23 aura::Window* container_; | 23 // aura::WindowObserver |
| 24 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
| 25 if (window == container_) |
| 26 container_.reset(); |
| 27 } |
| 28 |
| 29 scoped_ptr<aura::Window> container_; |
24 | 30 |
25 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); | 31 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); |
26 }; | 32 }; |
27 | 33 |
28 class WindowManagerImpl* instance = NULL; | 34 class WindowManagerImpl* instance = NULL; |
29 | 35 |
30 class AthenaContainerLayoutManager : public aura::LayoutManager { | 36 class AthenaContainerLayoutManager : public aura::LayoutManager { |
31 public: | 37 public: |
32 AthenaContainerLayoutManager() {} | 38 AthenaContainerLayoutManager() {} |
33 virtual ~AthenaContainerLayoutManager() {} | 39 virtual ~AthenaContainerLayoutManager() {} |
(...skipping 15 matching lines...) Expand all Loading... |
49 virtual void SetChildBounds(aura::Window* child, | 55 virtual void SetChildBounds(aura::Window* child, |
50 const gfx::Rect& requested_bounds) OVERRIDE { | 56 const gfx::Rect& requested_bounds) OVERRIDE { |
51 if (!requested_bounds.IsEmpty()) | 57 if (!requested_bounds.IsEmpty()) |
52 SetChildBoundsDirect(child, requested_bounds); | 58 SetChildBoundsDirect(child, requested_bounds); |
53 } | 59 } |
54 | 60 |
55 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); | 61 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); |
56 }; | 62 }; |
57 | 63 |
58 WindowManagerImpl::WindowManagerImpl() | 64 WindowManagerImpl::WindowManagerImpl() |
59 : container_(ScreenManager::Get()->GetContainerWindow()) { | 65 : container_( |
| 66 ScreenManager::Get()->CreateDefaultContainer("MainContainer")) { |
60 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 67 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
| 68 container_->AddObserver(this); |
61 instance = this; | 69 instance = this; |
62 } | 70 } |
63 | 71 |
64 WindowManagerImpl::~WindowManagerImpl() { | 72 WindowManagerImpl::~WindowManagerImpl() { |
| 73 if (container_) |
| 74 container_->RemoveObserver(this); |
| 75 container_.reset(); |
65 instance = NULL; | 76 instance = NULL; |
66 } | 77 } |
67 | 78 |
68 void WindowManagerImpl::Layout() { | 79 void WindowManagerImpl::Layout() { |
| 80 if (!container_) |
| 81 return; |
69 gfx::Rect bounds = gfx::Rect(container_->bounds().size()); | 82 gfx::Rect bounds = gfx::Rect(container_->bounds().size()); |
70 // Just make it small a bit so that the background is visible. | 83 // Just make it small a bit so that the background is visible. |
71 bounds.Inset(10, 10, 10, 10); | 84 bounds.Inset(10, 10, 10, 10); |
72 const aura::Window::Windows& children = container_->children(); | 85 const aura::Window::Windows& children = container_->children(); |
73 for (aura::Window::Windows::const_iterator iter = children.begin(); | 86 for (aura::Window::Windows::const_iterator iter = children.begin(); |
74 iter != children.end(); | 87 iter != children.end(); |
75 ++iter) { | 88 ++iter) { |
76 (*iter)->SetBounds(bounds); | 89 (*iter)->SetBounds(bounds); |
77 } | 90 } |
78 } | 91 } |
79 | 92 |
80 } // namespace | 93 } // namespace |
81 | 94 |
82 // static | 95 // static |
83 WindowManager* WindowManager::Create() { | 96 WindowManager* WindowManager::Create() { |
84 DCHECK(!instance); | 97 DCHECK(!instance); |
85 new WindowManagerImpl; | 98 new WindowManagerImpl; |
86 DCHECK(instance); | 99 DCHECK(instance); |
87 return instance; | 100 return instance; |
88 } | 101 } |
89 | 102 |
90 // static | 103 // static |
91 void WindowManager::Shutdown() { | 104 void WindowManager::Shutdown() { |
92 DCHECK(instance); | 105 DCHECK(instance); |
93 delete instance; | 106 delete instance; |
94 DCHECK(!instance); | 107 DCHECK(!instance); |
95 } | 108 } |
96 | 109 |
97 } // namespace athena | 110 } // namespace athena |
OLD | NEW |