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/window_manager_impl.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/screen/public/screen_manager.h" | 10 #include "athena/screen/public/screen_manager.h" |
11 #include "athena/wm/bezel_controller.h" | 11 #include "athena/wm/bezel_controller.h" |
12 #include "athena/wm/public/window_manager_observer.h" | 12 #include "athena/wm/public/window_manager_observer.h" |
13 #include "athena/wm/split_view_controller.h" | 13 #include "athena/wm/split_view_controller.h" |
14 #include "athena/wm/title_drag_controller.h" | 14 #include "athena/wm/title_drag_controller.h" |
15 #include "athena/wm/window_list_provider_impl.h" | 15 #include "athena/wm/window_list_provider_impl.h" |
16 #include "athena/wm/window_overview_mode.h" | 16 #include "athena/wm/window_overview_mode.h" |
17 #include "base/auto_reset.h" | |
17 #include "base/bind.h" | 18 #include "base/bind.h" |
18 #include "base/logging.h" | 19 #include "base/logging.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/compositor/closure_animation_observer.h" | 22 #include "ui/compositor/closure_animation_observer.h" |
22 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
23 #include "ui/gfx/display.h" | 24 #include "ui/gfx/display.h" |
24 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
25 #include "ui/wm/core/shadow_controller.h" | 26 #include "ui/wm/core/shadow_controller.h" |
26 #include "ui/wm/core/window_util.h" | 27 #include "ui/wm/core/window_util.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 } else { | 95 } else { |
95 window->SetBounds(gfx::Rect(work_area)); | 96 window->SetBounds(gfx::Rect(work_area)); |
96 } | 97 } |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
100 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 101 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
101 aura::Window::Windows list = instance->window_list_provider_->GetWindowList(); | 102 aura::Window::Windows list = instance->window_list_provider_->GetWindowList(); |
102 if (std::find(list.begin(), list.end(), child) == list.end()) | 103 if (std::find(list.begin(), list.end(), child) == list.end()) |
103 return; | 104 return; |
104 if (instance->split_view_controller_->IsSplitViewModeActive()) { | 105 |
106 if (instance->split_view_controller_->IsSplitViewModeActive() && | |
107 !instance->IsOverviewModeActive()) { | |
105 child->Show(); | 108 child->Show(); |
106 wm::ActivateWindow(child); | 109 wm::ActivateWindow(child); |
107 instance->split_view_controller_->ReplaceWindow( | 110 instance->split_view_controller_->ReplaceWindow( |
108 instance->split_view_controller_->left_window(), child); | 111 instance->split_view_controller_->left_window(), child); |
109 } else { | 112 } else { |
110 gfx::Size size = | 113 gfx::Size size = |
111 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 114 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
112 child->SetBounds(gfx::Rect(size)); | 115 child->SetBounds(gfx::Rect(size)); |
113 } | 116 } |
117 | |
118 if (instance->IsOverviewModeActive()) { | |
119 // TODO(pkotwicz|oshima). Creating a new window should only exit overview | |
120 // mode if the new window is activated. | |
121 instance->OnSelectWindow(child); | |
122 } | |
114 } | 123 } |
115 | 124 |
116 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( | 125 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( |
117 aura::Window* child) { | 126 aura::Window* child) { |
118 } | 127 } |
119 | 128 |
120 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( | 129 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( |
121 aura::Window* child) { | 130 aura::Window* child) { |
122 } | 131 } |
123 | 132 |
124 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( | 133 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( |
125 aura::Window* child, | 134 aura::Window* child, |
126 bool visible) { | 135 bool visible) { |
127 } | 136 } |
128 | 137 |
129 void AthenaContainerLayoutManager::SetChildBounds( | 138 void AthenaContainerLayoutManager::SetChildBounds( |
130 aura::Window* child, | 139 aura::Window* child, |
131 const gfx::Rect& requested_bounds) { | 140 const gfx::Rect& requested_bounds) { |
132 if (!requested_bounds.IsEmpty()) | 141 if (!requested_bounds.IsEmpty()) |
133 SetChildBoundsDirect(child, requested_bounds); | 142 SetChildBoundsDirect(child, requested_bounds); |
134 } | 143 } |
135 | 144 |
136 WindowManagerImpl::WindowManagerImpl() { | 145 WindowManagerImpl::WindowManagerImpl() : selecting_window_(false) { |
137 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); | 146 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); |
138 params.can_activate_children = true; | 147 params.can_activate_children = true; |
139 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 148 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
140 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 149 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
141 container_->AddObserver(this); | 150 container_->AddObserver(this); |
142 window_list_provider_.reset(new WindowListProviderImpl(container_.get())); | 151 window_list_provider_.reset(new WindowListProviderImpl(container_.get())); |
143 bezel_controller_.reset(new BezelController(container_.get())); | 152 bezel_controller_.reset(new BezelController(container_.get())); |
144 split_view_controller_.reset( | 153 split_view_controller_.reset( |
145 new SplitViewController(container_.get(), window_list_provider_.get())); | 154 new SplitViewController(container_.get(), window_list_provider_.get())); |
146 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); | 155 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 wm::ActivateWindow(active_window); | 204 wm::ActivateWindow(active_window); |
196 split_view_controller_->ActivateSplitMode(active_window, NULL); | 205 split_view_controller_->ActivateSplitMode(active_window, NULL); |
197 } | 206 } |
198 } | 207 } |
199 | 208 |
200 void WindowManagerImpl::SetInOverview(bool active) { | 209 void WindowManagerImpl::SetInOverview(bool active) { |
201 bool in_overview = !!overview_; | 210 bool in_overview = !!overview_; |
202 if (active == in_overview) | 211 if (active == in_overview) |
203 return; | 212 return; |
204 | 213 |
214 if (!active && !selecting_window_) { | |
215 overview_->SelectDefaultWindow(); | |
216 // If SelectDefaultWindow() did not select a window (e.g. there are no | |
217 // windows open), it should not be possible to exit overview. | |
218 return; | |
219 } | |
220 | |
205 bezel_controller_->set_left_right_delegate( | 221 bezel_controller_->set_left_right_delegate( |
206 active ? NULL : split_view_controller_.get()); | 222 active ? NULL : split_view_controller_.get()); |
207 if (active) { | 223 if (active) { |
208 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeEnter()); | 224 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeEnter()); |
209 | 225 |
210 // Re-stack all windows in the order defined by window_list_provider_. | 226 // Re-stack all windows in the order defined by window_list_provider_. |
211 aura::Window::Windows window_list = window_list_provider_->GetWindowList(); | 227 aura::Window::Windows window_list = window_list_provider_->GetWindowList(); |
212 aura::Window::Windows::iterator it; | 228 aura::Window::Windows::iterator it; |
213 for (it = window_list.begin(); it != window_list.end(); ++it) | 229 for (it = window_list.begin(); it != window_list.end(); ++it) |
214 container_->StackChildAtTop(*it); | 230 container_->StackChildAtTop(*it); |
(...skipping 23 matching lines...) Expand all Loading... | |
238 | 254 |
239 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { | 255 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { |
240 observers_.RemoveObserver(observer); | 256 observers_.RemoveObserver(observer); |
241 } | 257 } |
242 | 258 |
243 void WindowManagerImpl::ToggleSplitViewForTest() { | 259 void WindowManagerImpl::ToggleSplitViewForTest() { |
244 ToggleSplitView(); | 260 ToggleSplitView(); |
245 } | 261 } |
246 | 262 |
247 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { | 263 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { |
264 base::AutoReset<bool> selecting_window(&selecting_window_, true); | |
265 SetInOverview(false); | |
266 | |
267 window->Show(); | |
268 wm::ActivateWindow(window); | |
269 | |
248 if (split_view_controller_->IsSplitViewModeActive()) { | 270 if (split_view_controller_->IsSplitViewModeActive()) { |
249 split_view_controller_->DeactivateSplitMode(); | 271 split_view_controller_->DeactivateSplitMode(); |
250 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); | 272 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); |
251 } | 273 } |
252 wm::ActivateWindow(window); | |
253 SetInOverview(false); | |
254 // If |window| does not have the size of the work-area, then make sure it is | 274 // If |window| does not have the size of the work-area, then make sure it is |
255 // resized. | 275 // resized. |
256 const gfx::Size work_area = | 276 const gfx::Size work_area = |
257 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 277 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
258 if (window->GetTargetBounds().size() != work_area) { | 278 if (window->GetTargetBounds().size() != work_area) { |
259 const gfx::Rect& window_bounds = window->bounds(); | 279 const gfx::Rect& window_bounds = window->bounds(); |
260 const gfx::Rect desired_bounds(work_area); | 280 const gfx::Rect desired_bounds(work_area); |
261 gfx::Transform transform; | 281 gfx::Transform transform; |
262 transform.Translate(desired_bounds.x() - window_bounds.x(), | 282 transform.Translate(desired_bounds.x() - window_bounds.x(), |
263 desired_bounds.y() - window_bounds.y()); | 283 desired_bounds.y() - window_bounds.y()); |
264 transform.Scale(desired_bounds.width() / window_bounds.width(), | 284 transform.Scale(desired_bounds.width() / window_bounds.width(), |
265 desired_bounds.height() / window_bounds.height()); | 285 desired_bounds.height() / window_bounds.height()); |
266 window->layer()->GetAnimator()->AbortAllAnimations(); | |
pkotwicz
2014/09/08 19:39:24
We do not want to abort the opacity animation star
| |
267 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 286 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
268 settings.SetPreemptionStrategy( | 287 settings.SetPreemptionStrategy( |
269 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 288 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
270 settings.AddObserver( | 289 settings.AddObserver( |
271 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, | 290 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, |
272 base::Unretained(window), | 291 base::Unretained(window), |
273 desired_bounds, | 292 desired_bounds, |
274 gfx::Transform()))); | 293 gfx::Transform()))); |
275 window->SetTransform(transform); | 294 window->SetTransform(transform); |
276 } | 295 } |
277 } | 296 } |
278 | 297 |
279 void WindowManagerImpl::OnSplitViewMode(aura::Window* left, | 298 void WindowManagerImpl::OnSelectSplitViewWindow(aura::Window* left, |
280 aura::Window* right) { | 299 aura::Window* right, |
300 aura::Window* to_activate) { | |
301 base::AutoReset<bool> selecting_window(&selecting_window_, true); | |
281 SetInOverview(false); | 302 SetInOverview(false); |
303 | |
304 to_activate->Show(); | |
305 wm::ActivateWindow(to_activate); | |
282 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); | 306 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); |
283 if (right) | |
284 wm::ActivateWindow(right); | |
285 else | |
286 wm::ActivateWindow(left); | |
287 split_view_controller_->ActivateSplitMode(left, right); | 307 split_view_controller_->ActivateSplitMode(left, right); |
288 } | 308 } |
289 | 309 |
290 void WindowManagerImpl::OnWindowAdded(aura::Window* new_window) { | |
291 // TODO(oshima): Creating a new window should updates the ovewview mode | |
292 // instead of exitting. | |
293 if (new_window->type() == ui::wm::WINDOW_TYPE_NORMAL) | |
294 SetInOverview(false); | |
295 } | |
296 | |
297 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { | 310 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
298 if (window == container_) | 311 if (window == container_) |
299 container_.reset(); | 312 container_.reset(); |
300 } | 313 } |
301 | 314 |
302 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { | 315 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { |
303 return true; | 316 return true; |
304 } | 317 } |
305 | 318 |
306 bool WindowManagerImpl::OnAcceleratorFired(int command_id, | 319 bool WindowManagerImpl::OnAcceleratorFired(int command_id, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 DCHECK(!instance); | 423 DCHECK(!instance); |
411 } | 424 } |
412 | 425 |
413 // static | 426 // static |
414 WindowManager* WindowManager::GetInstance() { | 427 WindowManager* WindowManager::GetInstance() { |
415 DCHECK(instance); | 428 DCHECK(instance); |
416 return instance; | 429 return instance; |
417 } | 430 } |
418 | 431 |
419 } // namespace athena | 432 } // namespace athena |
OLD | NEW |