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/input/public/accelerator_manager.h" | 7 #include "athena/input/public/accelerator_manager.h" |
8 #include "athena/screen/public/screen_manager.h" | 8 #include "athena/screen/public/screen_manager.h" |
9 #include "athena/wm/public/window_manager_observer.h" | 9 #include "athena/wm/public/window_manager_observer.h" |
10 #include "athena/wm/window_overview_mode.h" | 10 #include "athena/wm/window_overview_mode.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 public WindowOverviewModeDelegate, | 22 public WindowOverviewModeDelegate, |
23 public aura::WindowObserver, | 23 public aura::WindowObserver, |
24 public AcceleratorHandler { | 24 public AcceleratorHandler { |
25 public: | 25 public: |
26 WindowManagerImpl(); | 26 WindowManagerImpl(); |
27 virtual ~WindowManagerImpl(); | 27 virtual ~WindowManagerImpl(); |
28 | 28 |
29 void Layout(); | 29 void Layout(); |
30 | 30 |
31 // WindowManager: | 31 // WindowManager: |
32 virtual void ToggleOverview() OVERRIDE { | 32 virtual void ToggleOverview() OVERRIDE; |
33 if (overview_) { | |
34 overview_.reset(); | |
35 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | |
36 OnOverviewModeExit()); | |
37 } else { | |
38 overview_ = WindowOverviewMode::Create(container_.get(), this); | |
39 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | |
40 OnOverviewModeEnter()); | |
41 } | |
42 } | |
43 | 33 |
44 private: | 34 private: |
45 enum Command { | 35 enum Command { |
46 COMMAND_TOGGLE_OVERVIEW, | 36 COMMAND_TOGGLE_OVERVIEW, |
47 }; | 37 }; |
48 | 38 |
49 void InstallAccelerators() { | 39 void InstallAccelerators(); |
50 const AcceleratorData accelerator_data[] = { | |
51 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, COMMAND_TOGGLE_OVERVIEW, | |
52 AF_NONE}, | |
53 }; | |
54 AcceleratorManager::Get()->RegisterAccelerators( | |
55 accelerator_data, arraysize(accelerator_data), this); | |
56 } | |
57 | 40 |
58 // WindowManager: | 41 // WindowManager: |
59 virtual void AddObserver(WindowManagerObserver* observer) OVERRIDE { | 42 virtual void AddObserver(WindowManagerObserver* observer) OVERRIDE; |
60 observers_.AddObserver(observer); | 43 virtual void RemoveObserver(WindowManagerObserver* observer) OVERRIDE; |
61 } | |
62 | |
63 virtual void RemoveObserver(WindowManagerObserver* observer) OVERRIDE { | |
64 observers_.RemoveObserver(observer); | |
65 } | |
66 | 44 |
67 // WindowOverviewModeDelegate: | 45 // WindowOverviewModeDelegate: |
68 virtual void OnSelectWindow(aura::Window* window) OVERRIDE { | 46 virtual void OnSelectWindow(aura::Window* window) OVERRIDE; |
69 CHECK_EQ(container_.get(), window->parent()); | |
70 container_->StackChildAtTop(window); | |
71 wm::ActivateWindow(window); | |
72 overview_.reset(); | |
73 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | |
74 OnOverviewModeExit()); | |
75 } | |
76 | 47 |
77 // aura::WindowObserver | 48 // aura::WindowObserver |
78 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | 49 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
79 if (window == container_) | |
80 container_.reset(); | |
81 } | |
82 | 50 |
83 // AcceleratorHandler: | 51 // AcceleratorHandler: |
84 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } | 52 virtual bool IsCommandEnabled(int command_id) const OVERRIDE; |
85 virtual bool OnAcceleratorFired(int command_id, | 53 virtual bool OnAcceleratorFired(int command_id, |
86 const ui::Accelerator& accelerator) OVERRIDE { | 54 const ui::Accelerator& accelerator) OVERRIDE; |
87 switch (command_id) { | |
88 case COMMAND_TOGGLE_OVERVIEW: | |
89 ToggleOverview(); | |
90 break; | |
91 } | |
92 return true; | |
93 } | |
94 | 55 |
95 scoped_ptr<aura::Window> container_; | 56 scoped_ptr<aura::Window> container_; |
96 scoped_ptr<WindowOverviewMode> overview_; | 57 scoped_ptr<WindowOverviewMode> overview_; |
97 ObserverList<WindowManagerObserver> observers_; | 58 ObserverList<WindowManagerObserver> observers_; |
98 | 59 |
99 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); | 60 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); |
100 }; | 61 }; |
101 | 62 |
| 63 class AthenaContainerLayoutManager : public aura::LayoutManager { |
| 64 public: |
| 65 AthenaContainerLayoutManager(); |
| 66 virtual ~AthenaContainerLayoutManager(); |
| 67 |
| 68 private: |
| 69 // aura::LayoutManager: |
| 70 virtual void OnWindowResized() OVERRIDE; |
| 71 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; |
| 72 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; |
| 73 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; |
| 74 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 75 bool visible) OVERRIDE; |
| 76 virtual void SetChildBounds(aura::Window* child, |
| 77 const gfx::Rect& requested_bounds) OVERRIDE; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); |
| 80 }; |
| 81 |
102 class WindowManagerImpl* instance = NULL; | 82 class WindowManagerImpl* instance = NULL; |
103 | 83 |
104 class AthenaContainerLayoutManager : public aura::LayoutManager { | |
105 public: | |
106 AthenaContainerLayoutManager() {} | |
107 virtual ~AthenaContainerLayoutManager() {} | |
108 | |
109 private: | |
110 // aura::LayoutManager: | |
111 virtual void OnWindowResized() OVERRIDE { instance->Layout(); } | |
112 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | |
113 instance->Layout(); | |
114 } | |
115 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | |
116 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { | |
117 instance->Layout(); | |
118 } | |
119 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | |
120 bool visible) OVERRIDE { | |
121 instance->Layout(); | |
122 } | |
123 virtual void SetChildBounds(aura::Window* child, | |
124 const gfx::Rect& requested_bounds) OVERRIDE { | |
125 if (!requested_bounds.IsEmpty()) | |
126 SetChildBoundsDirect(child, requested_bounds); | |
127 } | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); | |
130 }; | |
131 | |
132 WindowManagerImpl::WindowManagerImpl() { | 84 WindowManagerImpl::WindowManagerImpl() { |
133 ScreenManager::ContainerParams params("DefaultContainer"); | 85 ScreenManager::ContainerParams params("DefaultContainer"); |
134 params.can_activate_children = true; | 86 params.can_activate_children = true; |
135 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 87 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
136 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 88 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
137 container_->AddObserver(this); | 89 container_->AddObserver(this); |
138 instance = this; | 90 instance = this; |
139 InstallAccelerators(); | 91 InstallAccelerators(); |
140 } | 92 } |
141 | 93 |
(...skipping 11 matching lines...) Expand all Loading... |
153 const aura::Window::Windows& children = container_->children(); | 105 const aura::Window::Windows& children = container_->children(); |
154 for (aura::Window::Windows::const_iterator iter = children.begin(); | 106 for (aura::Window::Windows::const_iterator iter = children.begin(); |
155 iter != children.end(); | 107 iter != children.end(); |
156 ++iter) { | 108 ++iter) { |
157 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL || | 109 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL || |
158 (*iter)->type() == ui::wm::WINDOW_TYPE_POPUP) | 110 (*iter)->type() == ui::wm::WINDOW_TYPE_POPUP) |
159 (*iter)->SetBounds(bounds); | 111 (*iter)->SetBounds(bounds); |
160 } | 112 } |
161 } | 113 } |
162 | 114 |
| 115 void WindowManagerImpl::ToggleOverview() { |
| 116 if (overview_) { |
| 117 overview_.reset(); |
| 118 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 119 OnOverviewModeExit()); |
| 120 } else { |
| 121 overview_ = WindowOverviewMode::Create(container_.get(), this); |
| 122 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 123 OnOverviewModeEnter()); |
| 124 } |
| 125 } |
| 126 |
| 127 void WindowManagerImpl::InstallAccelerators() { |
| 128 const AcceleratorData accelerator_data[] = { |
| 129 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, COMMAND_TOGGLE_OVERVIEW, |
| 130 AF_NONE}, |
| 131 }; |
| 132 AcceleratorManager::Get()->RegisterAccelerators( |
| 133 accelerator_data, arraysize(accelerator_data), this); |
| 134 } |
| 135 |
| 136 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { |
| 137 observers_.AddObserver(observer); |
| 138 } |
| 139 |
| 140 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { |
| 141 observers_.RemoveObserver(observer); |
| 142 } |
| 143 |
| 144 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { |
| 145 CHECK_EQ(container_.get(), window->parent()); |
| 146 container_->StackChildAtTop(window); |
| 147 wm::ActivateWindow(window); |
| 148 overview_.reset(); |
| 149 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 150 OnOverviewModeExit()); |
| 151 } |
| 152 |
| 153 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
| 154 if (window == container_) |
| 155 container_.reset(); |
| 156 } |
| 157 |
| 158 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { |
| 159 return true; |
| 160 } |
| 161 |
| 162 bool WindowManagerImpl::OnAcceleratorFired(int command_id, |
| 163 const ui::Accelerator& accelerator) { |
| 164 switch (command_id) { |
| 165 case COMMAND_TOGGLE_OVERVIEW: |
| 166 ToggleOverview(); |
| 167 break; |
| 168 } |
| 169 return true; |
| 170 } |
| 171 |
| 172 AthenaContainerLayoutManager::AthenaContainerLayoutManager() { |
| 173 } |
| 174 |
| 175 AthenaContainerLayoutManager::~AthenaContainerLayoutManager() { |
| 176 } |
| 177 |
| 178 void AthenaContainerLayoutManager::OnWindowResized() { |
| 179 instance->Layout(); |
| 180 } |
| 181 |
| 182 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 183 instance->Layout(); |
| 184 } |
| 185 |
| 186 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( |
| 187 aura::Window* child) { |
| 188 } |
| 189 |
| 190 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( |
| 191 aura::Window* child) { |
| 192 instance->Layout(); |
| 193 } |
| 194 |
| 195 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( |
| 196 aura::Window* child, |
| 197 bool visible) { |
| 198 instance->Layout(); |
| 199 } |
| 200 |
| 201 void AthenaContainerLayoutManager::SetChildBounds( |
| 202 aura::Window* child, |
| 203 const gfx::Rect& requested_bounds) { |
| 204 if (!requested_bounds.IsEmpty()) |
| 205 SetChildBoundsDirect(child, requested_bounds); |
| 206 } |
| 207 |
163 } // namespace | 208 } // namespace |
164 | 209 |
165 // static | 210 // static |
166 WindowManager* WindowManager::Create() { | 211 WindowManager* WindowManager::Create() { |
167 DCHECK(!instance); | 212 DCHECK(!instance); |
168 new WindowManagerImpl; | 213 new WindowManagerImpl; |
169 DCHECK(instance); | 214 DCHECK(instance); |
170 return instance; | 215 return instance; |
171 } | 216 } |
172 | 217 |
173 // static | 218 // static |
174 void WindowManager::Shutdown() { | 219 void WindowManager::Shutdown() { |
175 DCHECK(instance); | 220 DCHECK(instance); |
176 delete instance; | 221 delete instance; |
177 DCHECK(!instance); | 222 DCHECK(!instance); |
178 } | 223 } |
179 | 224 |
180 // static | 225 // static |
181 WindowManager* WindowManager::GetInstance() { | 226 WindowManager* WindowManager::GetInstance() { |
182 DCHECK(instance); | 227 DCHECK(instance); |
183 return instance; | 228 return instance; |
184 } | 229 } |
185 | 230 |
186 } // namespace athena | 231 } // namespace athena |
OLD | NEW |