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/screen/public/screen_manager.h" | 9 #include "athena/screen/public/screen_manager.h" |
10 #include "athena/util/container_priorities.h" | 10 #include "athena/util/container_priorities.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } else { | 94 } else { |
95 window->SetBounds(gfx::Rect(work_area)); | 95 window->SetBounds(gfx::Rect(work_area)); |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 100 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
101 aura::Window::Windows list = instance->window_list_provider_->GetWindowList(); | 101 aura::Window::Windows list = instance->window_list_provider_->GetWindowList(); |
102 if (std::find(list.begin(), list.end(), child) == list.end()) | 102 if (std::find(list.begin(), list.end(), child) == list.end()) |
103 return; | 103 return; |
104 if (instance->split_view_controller_->IsSplitViewModeActive()) { | 104 |
| 105 if (instance->split_view_controller_->IsSplitViewModeActive() && |
| 106 !instance->IsOverviewModeActive()) { |
105 instance->split_view_controller_->ReplaceWindow( | 107 instance->split_view_controller_->ReplaceWindow( |
106 instance->split_view_controller_->left_window(), child); | 108 instance->split_view_controller_->left_window(), child); |
107 } else { | 109 } else { |
108 gfx::Size size = | 110 gfx::Size size = |
109 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 111 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
110 child->SetBounds(gfx::Rect(size)); | 112 child->SetBounds(gfx::Rect(size)); |
111 } | 113 } |
| 114 |
| 115 if (instance->IsOverviewModeActive()) { |
| 116 // TODO(pkotwicz|oshima). Creating a new window should only exit overview |
| 117 // mode if the new window is activated. crbug.com/415266 |
| 118 instance->OnSelectWindow(child); |
| 119 } |
112 } | 120 } |
113 | 121 |
114 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( | 122 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( |
115 aura::Window* child) { | 123 aura::Window* child) { |
116 } | 124 } |
117 | 125 |
118 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( | 126 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( |
119 aura::Window* child) { | 127 aura::Window* child) { |
120 } | 128 } |
121 | 129 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 container_->RemoveObserver(this); | 168 container_->RemoveObserver(this); |
161 container_->RemovePreTargetHandler(bezel_controller_.get()); | 169 container_->RemovePreTargetHandler(bezel_controller_.get()); |
162 } | 170 } |
163 // |title_drag_controller_| needs to be reset before |container_|. | 171 // |title_drag_controller_| needs to be reset before |container_|. |
164 title_drag_controller_.reset(); | 172 title_drag_controller_.reset(); |
165 container_.reset(); | 173 container_.reset(); |
166 instance = NULL; | 174 instance = NULL; |
167 } | 175 } |
168 | 176 |
169 void WindowManagerImpl::ToggleOverview() { | 177 void WindowManagerImpl::ToggleOverview() { |
170 SetInOverview(overview_.get() == NULL); | 178 if (IsOverviewModeActive()) { |
| 179 SetInOverview(false); |
| 180 |
| 181 // Activate the window which was active prior to entering overview. |
| 182 const aura::Window::Windows windows = |
| 183 window_list_provider_->GetWindowList(); |
| 184 if (!windows.empty()) { |
| 185 aura::Window* window = windows.back(); |
| 186 // Show the window in case the exit overview animation has finished and |
| 187 // |window| was hidden. |
| 188 window->Show(); |
| 189 wm::ActivateWindow(window); |
| 190 } |
| 191 } else { |
| 192 SetInOverview(true); |
| 193 } |
171 } | 194 } |
172 | 195 |
173 bool WindowManagerImpl::IsOverviewModeActive() { | 196 bool WindowManagerImpl::IsOverviewModeActive() { |
174 return overview_; | 197 return overview_; |
175 } | 198 } |
176 | 199 |
177 void WindowManagerImpl::SetInOverview(bool active) { | 200 void WindowManagerImpl::SetInOverview(bool active) { |
178 bool in_overview = !!overview_; | 201 bool in_overview = !!overview_; |
179 if (active == in_overview) | 202 if (active == in_overview) |
180 return; | 203 return; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 239 |
217 void WindowManagerImpl::ToggleSplitViewForTest() { | 240 void WindowManagerImpl::ToggleSplitViewForTest() { |
218 ToggleSplitview(); | 241 ToggleSplitview(); |
219 } | 242 } |
220 | 243 |
221 WindowListProvider* WindowManagerImpl::GetWindowListProvider() { | 244 WindowListProvider* WindowManagerImpl::GetWindowListProvider() { |
222 return window_list_provider_.get(); | 245 return window_list_provider_.get(); |
223 } | 246 } |
224 | 247 |
225 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { | 248 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { |
| 249 SetInOverview(false); |
| 250 |
| 251 // Show the window in case the exit overview animation has finished and |
| 252 // |window| was hidden. |
| 253 window->Show(); |
| 254 |
| 255 wm::ActivateWindow(window); |
| 256 |
226 if (split_view_controller_->IsSplitViewModeActive()) { | 257 if (split_view_controller_->IsSplitViewModeActive()) { |
227 split_view_controller_->DeactivateSplitMode(); | 258 split_view_controller_->DeactivateSplitMode(); |
228 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); | 259 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); |
229 } | 260 } |
230 wm::ActivateWindow(window); | |
231 SetInOverview(false); | |
232 // If |window| does not have the size of the work-area, then make sure it is | 261 // If |window| does not have the size of the work-area, then make sure it is |
233 // resized. | 262 // resized. |
234 const gfx::Size work_area = | 263 const gfx::Size work_area = |
235 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 264 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
236 if (window->GetTargetBounds().size() != work_area) { | 265 if (window->GetTargetBounds().size() != work_area) { |
237 const gfx::Rect& window_bounds = window->bounds(); | 266 const gfx::Rect& window_bounds = window->bounds(); |
238 const gfx::Rect desired_bounds(work_area); | 267 const gfx::Rect desired_bounds(work_area); |
239 gfx::Transform transform; | 268 gfx::Transform transform; |
240 transform.Translate(desired_bounds.x() - window_bounds.x(), | 269 transform.Translate(desired_bounds.x() - window_bounds.x(), |
241 desired_bounds.y() - window_bounds.y()); | 270 desired_bounds.y() - window_bounds.y()); |
242 transform.Scale(desired_bounds.width() / window_bounds.width(), | 271 transform.Scale(desired_bounds.width() / window_bounds.width(), |
243 desired_bounds.height() / window_bounds.height()); | 272 desired_bounds.height() / window_bounds.height()); |
244 window->layer()->GetAnimator()->AbortAllAnimations(); | |
245 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 273 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
246 settings.SetPreemptionStrategy( | 274 settings.SetPreemptionStrategy( |
247 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 275 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
248 settings.AddObserver( | 276 settings.AddObserver( |
249 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, | 277 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, |
250 base::Unretained(window), | 278 base::Unretained(window), |
251 desired_bounds, | 279 desired_bounds, |
252 gfx::Transform()))); | 280 gfx::Transform()))); |
253 window->SetTransform(transform); | 281 window->SetTransform(transform); |
254 } | 282 } |
255 } | 283 } |
256 | 284 |
257 void WindowManagerImpl::OnSplitViewMode(aura::Window* left, | 285 void WindowManagerImpl::OnSelectSplitViewWindow(aura::Window* left, |
258 aura::Window* right) { | 286 aura::Window* right, |
| 287 aura::Window* to_activate) { |
259 SetInOverview(false); | 288 SetInOverview(false); |
260 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); | 289 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); |
261 split_view_controller_->ActivateSplitMode(left, right); | 290 split_view_controller_->ActivateSplitMode(left, right); |
262 } | 291 wm::ActivateWindow(to_activate); |
263 | |
264 void WindowManagerImpl::OnWindowAdded(aura::Window* new_window) { | |
265 // TODO(oshima): Creating a new window should updates the ovewview mode | |
266 // instead of exitting. | |
267 if (new_window->type() == ui::wm::WINDOW_TYPE_NORMAL) | |
268 SetInOverview(false); | |
269 } | 292 } |
270 | 293 |
271 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { | 294 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
272 if (window == container_) | 295 if (window == container_) |
273 container_.reset(); | 296 container_.reset(); |
274 } | 297 } |
275 | 298 |
276 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { | 299 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { |
277 return true; | 300 return true; |
278 } | 301 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 DCHECK(!instance); | 425 DCHECK(!instance); |
403 } | 426 } |
404 | 427 |
405 // static | 428 // static |
406 WindowManager* WindowManager::GetInstance() { | 429 WindowManager* WindowManager::GetInstance() { |
407 DCHECK(instance); | 430 DCHECK(instance); |
408 return instance; | 431 return instance; |
409 } | 432 } |
410 | 433 |
411 } // namespace athena | 434 } // namespace athena |
OLD | NEW |