1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/wm/public/window_manager.h"
#include <algorithm>
#include "athena/common/container_priorities.h"
#include "athena/input/public/accelerator_manager.h"
#include "athena/screen/public/screen_manager.h"
#include "athena/wm/bezel_controller.h"
#include "athena/wm/mru_window_tracker.h"
#include "athena/wm/public/window_manager_observer.h"
#include "athena/wm/split_view_controller.h"
#include "athena/wm/title_drag_controller.h"
#include "athena/wm/window_overview_mode.h"
#include "base/logging.h"
#include "base/observer_list.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
#include "ui/wm/core/shadow_controller.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/core/wm_state.h"
#include "ui/wm/public/activation_client.h"
#include "ui/wm/public/window_types.h"
namespace athena {
namespace {
class WindowManagerImpl : public WindowManager,
public WindowOverviewModeDelegate,
public aura::WindowObserver,
public AcceleratorHandler,
public TitleDragControllerDelegate {
public:
WindowManagerImpl();
virtual ~WindowManagerImpl();
void Layout();
// WindowManager:
virtual void ToggleOverview() OVERRIDE;
virtual bool IsOverviewModeActive() OVERRIDE;
private:
enum Command {
CMD_TOGGLE_OVERVIEW,
};
// Sets whether overview mode is active.
void SetInOverview(bool active);
void InstallAccelerators();
// WindowManager:
virtual void AddObserver(WindowManagerObserver* observer) OVERRIDE;
virtual void RemoveObserver(WindowManagerObserver* observer) OVERRIDE;
// WindowOverviewModeDelegate:
virtual void OnSelectWindow(aura::Window* window) OVERRIDE;
virtual void OnSplitViewMode(aura::Window* left,
aura::Window* right) OVERRIDE;
// aura::WindowObserver
virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE;
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
// AcceleratorHandler:
virtual bool IsCommandEnabled(int command_id) const OVERRIDE;
virtual bool OnAcceleratorFired(int command_id,
const ui::Accelerator& accelerator) OVERRIDE;
// TitleDragControllerDelegate:
virtual aura::Window* GetWindowBehind(aura::Window* window) OVERRIDE;
virtual void OnTitleDragStarted(aura::Window* window) OVERRIDE;
virtual void OnTitleDragCompleted(aura::Window* window) OVERRIDE;
virtual void OnTitleDragCanceled(aura::Window* window) OVERRIDE;
scoped_ptr<aura::Window> container_;
scoped_ptr<MruWindowTracker> mru_window_tracker_;
scoped_ptr<WindowOverviewMode> overview_;
scoped_ptr<BezelController> bezel_controller_;
scoped_ptr<SplitViewController> split_view_controller_;
scoped_ptr<wm::WMState> wm_state_;
scoped_ptr<TitleDragController> title_drag_controller_;
scoped_ptr<wm::ShadowController> shadow_controller_;
ObserverList<WindowManagerObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl);
};
class AthenaContainerLayoutManager : public aura::LayoutManager {
public:
AthenaContainerLayoutManager();
virtual ~AthenaContainerLayoutManager();
private:
// aura::LayoutManager:
virtual void OnWindowResized() OVERRIDE;
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE;
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) OVERRIDE;
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager);
};
class WindowManagerImpl* instance = NULL;
WindowManagerImpl::WindowManagerImpl() {
ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT);
params.can_activate_children = true;
container_.reset(ScreenManager::Get()->CreateDefaultContainer(params));
container_->SetLayoutManager(new AthenaContainerLayoutManager);
container_->AddObserver(this);
mru_window_tracker_.reset(new MruWindowTracker(container_.get()));
bezel_controller_.reset(new BezelController(container_.get()));
split_view_controller_.reset(new SplitViewController(
container_.get(), mru_window_tracker_.get(), this));
bezel_controller_->set_left_right_delegate(split_view_controller_.get());
container_->AddPreTargetHandler(bezel_controller_.get());
title_drag_controller_.reset(new TitleDragController(container_.get(), this));
wm_state_.reset(new wm::WMState());
aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(container_->GetRootWindow());
shadow_controller_.reset(new wm::ShadowController(activation_client));
instance = this;
InstallAccelerators();
}
WindowManagerImpl::~WindowManagerImpl() {
overview_.reset();
mru_window_tracker_.reset();
if (container_) {
container_->RemoveObserver(this);
container_->RemovePreTargetHandler(bezel_controller_.get());
}
// |title_drag_controller_| needs to be reset before |container_|.
title_drag_controller_.reset();
container_.reset();
instance = NULL;
}
void WindowManagerImpl::Layout() {
if (!container_)
return;
gfx::Rect bounds = gfx::Rect(container_->bounds().size());
const aura::Window::Windows& children = container_->children();
for (aura::Window::Windows::const_iterator iter = children.begin();
iter != children.end();
++iter) {
if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL)
(*iter)->SetBounds(bounds);
}
}
void WindowManagerImpl::ToggleOverview() {
SetInOverview(overview_.get() == NULL);
}
bool WindowManagerImpl::IsOverviewModeActive() {
return overview_;
}
void WindowManagerImpl::SetInOverview(bool active) {
bool in_overview = !!overview_;
if (active == in_overview)
return;
if (active) {
FOR_EACH_OBSERVER(WindowManagerObserver, observers_,
OnOverviewModeEnter());
// Re-stack all windows in the order defined by mru_window_tracker_.
aura::Window::Windows window_list = mru_window_tracker_->GetWindowList();
aura::Window::Windows::iterator it;
for (it = window_list.begin(); it != window_list.end(); ++it)
container_->StackChildAtTop(*it);
overview_ = WindowOverviewMode::Create(container_.get(),
mru_window_tracker_.get(),
this);
} else {
overview_.reset();
FOR_EACH_OBSERVER(WindowManagerObserver, observers_,
OnOverviewModeExit());
}
}
void WindowManagerImpl::InstallAccelerators() {
const AcceleratorData accelerator_data[] = {
{TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW,
AF_NONE},
};
AcceleratorManager::Get()->RegisterAccelerators(
accelerator_data, arraysize(accelerator_data), this);
}
void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) {
observers_.AddObserver(observer);
}
void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) {
observers_.RemoveObserver(observer);
}
void WindowManagerImpl::OnSelectWindow(aura::Window* window) {
mru_window_tracker_->MoveToFront(window);
wm::ActivateWindow(window);
SetInOverview(false);
}
void WindowManagerImpl::OnSplitViewMode(aura::Window* left,
aura::Window* right) {
SetInOverview(false);
split_view_controller_->ActivateSplitMode(left, right);
}
void WindowManagerImpl::OnWindowAdded(aura::Window* new_window) {
if (new_window->type() == ui::wm::WINDOW_TYPE_NORMAL)
SetInOverview(false);
}
void WindowManagerImpl::OnWindowDestroying(aura::Window* window) {
if (window == container_)
container_.reset();
}
bool WindowManagerImpl::IsCommandEnabled(int command_id) const {
return true;
}
bool WindowManagerImpl::OnAcceleratorFired(int command_id,
const ui::Accelerator& accelerator) {
switch (command_id) {
case CMD_TOGGLE_OVERVIEW:
ToggleOverview();
break;
}
return true;
}
aura::Window* WindowManagerImpl::GetWindowBehind(aura::Window* window) {
const aura::Window::Windows& windows = container_->children();
aura::Window::Windows::const_iterator iter =
std::find(windows.begin(), windows.end(), window);
CHECK(iter != windows.end());
return (iter == windows.begin()) ? NULL : *(iter - 1);
}
void WindowManagerImpl::OnTitleDragStarted(aura::Window* window) {
}
void WindowManagerImpl::OnTitleDragCompleted(aura::Window* window) {
aura::Window* next_window = GetWindowBehind(window);
if (next_window)
OnSelectWindow(next_window);
}
void WindowManagerImpl::OnTitleDragCanceled(aura::Window* window) {
}
AthenaContainerLayoutManager::AthenaContainerLayoutManager() {
}
AthenaContainerLayoutManager::~AthenaContainerLayoutManager() {
}
void AthenaContainerLayoutManager::OnWindowResized() {
instance->Layout();
}
void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
instance->Layout();
}
void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout(
aura::Window* child) {
}
void AthenaContainerLayoutManager::OnWindowRemovedFromLayout(
aura::Window* child) {
instance->Layout();
}
void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged(
aura::Window* child,
bool visible) {
instance->Layout();
}
void AthenaContainerLayoutManager::SetChildBounds(
aura::Window* child,
const gfx::Rect& requested_bounds) {
if (!requested_bounds.IsEmpty())
SetChildBoundsDirect(child, requested_bounds);
}
} // namespace
// static
WindowManager* WindowManager::Create() {
DCHECK(!instance);
new WindowManagerImpl;
DCHECK(instance);
return instance;
}
// static
void WindowManager::Shutdown() {
DCHECK(instance);
delete instance;
DCHECK(!instance);
}
// static
WindowManager* WindowManager::GetInstance() {
DCHECK(instance);
return instance;
}
} // namespace athena
|