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 <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" | 10 #include "athena/input/public/accelerator_manager.h" |
11 #include "athena/screen/public/screen_manager.h" | 11 #include "athena/screen/public/screen_manager.h" |
12 #include "athena/wm/bezel_controller.h" | 12 #include "athena/wm/bezel_controller.h" |
| 13 #include "athena/wm/mru_window_tracker.h" |
13 #include "athena/wm/public/window_manager_observer.h" | 14 #include "athena/wm/public/window_manager_observer.h" |
14 #include "athena/wm/split_view_controller.h" | 15 #include "athena/wm/split_view_controller.h" |
15 #include "athena/wm/title_drag_controller.h" | 16 #include "athena/wm/title_drag_controller.h" |
16 #include "athena/wm/window_overview_mode.h" | 17 #include "athena/wm/window_overview_mode.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
19 #include "ui/aura/layout_manager.h" | 20 #include "ui/aura/layout_manager.h" |
20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
21 #include "ui/wm/core/shadow_controller.h" | 22 #include "ui/wm/core/shadow_controller.h" |
22 #include "ui/wm/core/window_util.h" | 23 #include "ui/wm/core/window_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
34 public TitleDragControllerDelegate { | 35 public TitleDragControllerDelegate { |
35 public: | 36 public: |
36 WindowManagerImpl(); | 37 WindowManagerImpl(); |
37 virtual ~WindowManagerImpl(); | 38 virtual ~WindowManagerImpl(); |
38 | 39 |
39 void Layout(); | 40 void Layout(); |
40 | 41 |
41 // WindowManager: | 42 // WindowManager: |
42 virtual void ToggleOverview() OVERRIDE; | 43 virtual void ToggleOverview() OVERRIDE; |
43 | 44 |
| 45 virtual bool IsOverviewModeActive() OVERRIDE; |
| 46 |
44 private: | 47 private: |
45 enum Command { | 48 enum Command { |
46 CMD_TOGGLE_OVERVIEW, | 49 CMD_TOGGLE_OVERVIEW, |
47 }; | 50 }; |
48 | 51 |
49 // Sets whether overview mode is active. | 52 // Sets whether overview mode is active. |
50 void SetInOverview(bool active); | 53 void SetInOverview(bool active); |
51 | 54 |
52 void InstallAccelerators(); | 55 void InstallAccelerators(); |
53 | 56 |
(...skipping 13 matching lines...) Expand all Loading... |
67 virtual bool OnAcceleratorFired(int command_id, | 70 virtual bool OnAcceleratorFired(int command_id, |
68 const ui::Accelerator& accelerator) OVERRIDE; | 71 const ui::Accelerator& accelerator) OVERRIDE; |
69 | 72 |
70 // TitleDragControllerDelegate: | 73 // TitleDragControllerDelegate: |
71 virtual aura::Window* GetWindowBehind(aura::Window* window) OVERRIDE; | 74 virtual aura::Window* GetWindowBehind(aura::Window* window) OVERRIDE; |
72 virtual void OnTitleDragStarted(aura::Window* window) OVERRIDE; | 75 virtual void OnTitleDragStarted(aura::Window* window) OVERRIDE; |
73 virtual void OnTitleDragCompleted(aura::Window* window) OVERRIDE; | 76 virtual void OnTitleDragCompleted(aura::Window* window) OVERRIDE; |
74 virtual void OnTitleDragCanceled(aura::Window* window) OVERRIDE; | 77 virtual void OnTitleDragCanceled(aura::Window* window) OVERRIDE; |
75 | 78 |
76 scoped_ptr<aura::Window> container_; | 79 scoped_ptr<aura::Window> container_; |
| 80 scoped_ptr<MruWindowTracker> mru_window_tracker_; |
77 scoped_ptr<WindowOverviewMode> overview_; | 81 scoped_ptr<WindowOverviewMode> overview_; |
78 scoped_ptr<BezelController> bezel_controller_; | 82 scoped_ptr<BezelController> bezel_controller_; |
79 scoped_ptr<SplitViewController> split_view_controller_; | 83 scoped_ptr<SplitViewController> split_view_controller_; |
80 scoped_ptr<wm::WMState> wm_state_; | 84 scoped_ptr<wm::WMState> wm_state_; |
81 scoped_ptr<TitleDragController> title_drag_controller_; | 85 scoped_ptr<TitleDragController> title_drag_controller_; |
82 scoped_ptr<wm::ShadowController> shadow_controller_; | 86 scoped_ptr<wm::ShadowController> shadow_controller_; |
83 ObserverList<WindowManagerObserver> observers_; | 87 ObserverList<WindowManagerObserver> observers_; |
84 | 88 |
85 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); | 89 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); |
86 }; | 90 }; |
(...skipping 18 matching lines...) Expand all Loading... |
105 }; | 109 }; |
106 | 110 |
107 class WindowManagerImpl* instance = NULL; | 111 class WindowManagerImpl* instance = NULL; |
108 | 112 |
109 WindowManagerImpl::WindowManagerImpl() { | 113 WindowManagerImpl::WindowManagerImpl() { |
110 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); | 114 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); |
111 params.can_activate_children = true; | 115 params.can_activate_children = true; |
112 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 116 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
113 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 117 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
114 container_->AddObserver(this); | 118 container_->AddObserver(this); |
| 119 mru_window_tracker_.reset(new MruWindowTracker(container_.get())); |
115 bezel_controller_.reset(new BezelController(container_.get())); | 120 bezel_controller_.reset(new BezelController(container_.get())); |
116 split_view_controller_.reset(new SplitViewController()); | 121 split_view_controller_.reset(new SplitViewController( |
| 122 container_.get(), mru_window_tracker_.get(), this)); |
117 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); | 123 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); |
118 container_->AddPreTargetHandler(bezel_controller_.get()); | 124 container_->AddPreTargetHandler(bezel_controller_.get()); |
119 title_drag_controller_.reset(new TitleDragController(container_.get(), this)); | 125 title_drag_controller_.reset(new TitleDragController(container_.get(), this)); |
120 wm_state_.reset(new wm::WMState()); | 126 wm_state_.reset(new wm::WMState()); |
121 aura::client::ActivationClient* activation_client = | 127 aura::client::ActivationClient* activation_client = |
122 aura::client::GetActivationClient(container_->GetRootWindow()); | 128 aura::client::GetActivationClient(container_->GetRootWindow()); |
123 shadow_controller_.reset(new wm::ShadowController(activation_client)); | 129 shadow_controller_.reset(new wm::ShadowController(activation_client)); |
124 instance = this; | 130 instance = this; |
125 InstallAccelerators(); | 131 InstallAccelerators(); |
126 } | 132 } |
127 | 133 |
128 WindowManagerImpl::~WindowManagerImpl() { | 134 WindowManagerImpl::~WindowManagerImpl() { |
129 overview_.reset(); | 135 overview_.reset(); |
| 136 mru_window_tracker_.reset(); |
130 if (container_) { | 137 if (container_) { |
131 container_->RemoveObserver(this); | 138 container_->RemoveObserver(this); |
132 container_->RemovePreTargetHandler(bezel_controller_.get()); | 139 container_->RemovePreTargetHandler(bezel_controller_.get()); |
133 } | 140 } |
134 // |title_drag_controller_| needs to be reset before |container_|. | 141 // |title_drag_controller_| needs to be reset before |container_|. |
135 title_drag_controller_.reset(); | 142 title_drag_controller_.reset(); |
136 container_.reset(); | 143 container_.reset(); |
137 instance = NULL; | 144 instance = NULL; |
138 } | 145 } |
139 | 146 |
140 void WindowManagerImpl::Layout() { | 147 void WindowManagerImpl::Layout() { |
141 if (!container_) | 148 if (!container_) |
142 return; | 149 return; |
143 gfx::Rect bounds = gfx::Rect(container_->bounds().size()); | 150 gfx::Rect bounds = gfx::Rect(container_->bounds().size()); |
144 const aura::Window::Windows& children = container_->children(); | 151 const aura::Window::Windows& children = container_->children(); |
145 for (aura::Window::Windows::const_iterator iter = children.begin(); | 152 for (aura::Window::Windows::const_iterator iter = children.begin(); |
146 iter != children.end(); | 153 iter != children.end(); |
147 ++iter) { | 154 ++iter) { |
148 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL) | 155 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL) |
149 (*iter)->SetBounds(bounds); | 156 (*iter)->SetBounds(bounds); |
150 } | 157 } |
151 } | 158 } |
152 | 159 |
153 void WindowManagerImpl::ToggleOverview() { | 160 void WindowManagerImpl::ToggleOverview() { |
154 SetInOverview(overview_.get() == NULL); | 161 SetInOverview(overview_.get() == NULL); |
155 } | 162 } |
156 | 163 |
| 164 bool WindowManagerImpl::IsOverviewModeActive() { |
| 165 return overview_; |
| 166 } |
| 167 |
157 void WindowManagerImpl::SetInOverview(bool active) { | 168 void WindowManagerImpl::SetInOverview(bool active) { |
158 bool in_overview = !!overview_; | 169 bool in_overview = !!overview_; |
159 if (active == in_overview) | 170 if (active == in_overview) |
160 return; | 171 return; |
161 | 172 |
162 if (active) { | 173 if (active) { |
163 overview_ = WindowOverviewMode::Create(container_.get(), this); | |
164 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 174 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
165 OnOverviewModeEnter()); | 175 OnOverviewModeEnter()); |
| 176 // Re-stack all windows in the order defined by mru_window_tracker_. |
| 177 aura::Window::Windows window_list = mru_window_tracker_->GetWindowList(); |
| 178 aura::Window::Windows::iterator it; |
| 179 for (it = window_list.begin(); it != window_list.end(); ++it) |
| 180 container_->StackChildAtTop(*it); |
| 181 overview_ = WindowOverviewMode::Create(container_.get(), |
| 182 mru_window_tracker_.get(), |
| 183 this); |
166 } else { | 184 } else { |
167 overview_.reset(); | 185 overview_.reset(); |
168 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 186 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
169 OnOverviewModeExit()); | 187 OnOverviewModeExit()); |
170 } | 188 } |
171 } | 189 } |
172 | 190 |
173 void WindowManagerImpl::InstallAccelerators() { | 191 void WindowManagerImpl::InstallAccelerators() { |
174 const AcceleratorData accelerator_data[] = { | 192 const AcceleratorData accelerator_data[] = { |
175 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW, | 193 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW, |
176 AF_NONE}, | 194 AF_NONE}, |
177 }; | 195 }; |
178 AcceleratorManager::Get()->RegisterAccelerators( | 196 AcceleratorManager::Get()->RegisterAccelerators( |
179 accelerator_data, arraysize(accelerator_data), this); | 197 accelerator_data, arraysize(accelerator_data), this); |
180 } | 198 } |
181 | 199 |
182 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { | 200 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { |
183 observers_.AddObserver(observer); | 201 observers_.AddObserver(observer); |
184 } | 202 } |
185 | 203 |
186 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { | 204 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { |
187 observers_.RemoveObserver(observer); | 205 observers_.RemoveObserver(observer); |
188 } | 206 } |
189 | 207 |
190 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { | 208 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { |
191 CHECK_EQ(container_.get(), window->parent()); | 209 mru_window_tracker_->MoveToFront(window); |
192 container_->StackChildAtTop(window); | |
193 wm::ActivateWindow(window); | 210 wm::ActivateWindow(window); |
194 SetInOverview(false); | 211 SetInOverview(false); |
195 } | 212 } |
196 | 213 |
197 void WindowManagerImpl::OnWindowAdded(aura::Window* new_window) { | 214 void WindowManagerImpl::OnWindowAdded(aura::Window* new_window) { |
198 if (new_window->type() == ui::wm::WINDOW_TYPE_NORMAL) | 215 if (new_window->type() == ui::wm::WINDOW_TYPE_NORMAL) |
199 SetInOverview(false); | 216 SetInOverview(false); |
200 } | 217 } |
201 | 218 |
202 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { | 219 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 DCHECK(!instance); | 308 DCHECK(!instance); |
292 } | 309 } |
293 | 310 |
294 // static | 311 // static |
295 WindowManager* WindowManager::GetInstance() { | 312 WindowManager* WindowManager::GetInstance() { |
296 DCHECK(instance); | 313 DCHECK(instance); |
297 return instance; | 314 return instance; |
298 } | 315 } |
299 | 316 |
300 } // namespace athena | 317 } // namespace athena |
OLD | NEW |