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. | |
sadrul
2014/09/17 18:04:44
Or the window should position itself correctly in
pkotwicz
2014/09/17 20:14:37
Done.
| |
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); | |
oshima
2014/09/17 22:07:30
It's probably cleaner if we can have two methods
pkotwicz
2014/09/17 22:24:16
It is doable. There are several ways of doing what
oshima
2014/09/17 22:32:40
Great, thanks!
| |
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 windows.back()->Show(); | |
sadrul
2014/09/17 18:04:44
Why do we need to explicitly Show() here?
pkotwicz
2014/09/17 20:14:37
During unit tests, SetInOverview(false) immediatel
| |
186 wm::ActivateWindow(windows.back()); | |
187 } | |
188 } else { | |
189 SetInOverview(true); | |
190 } | |
171 } | 191 } |
172 | 192 |
173 bool WindowManagerImpl::IsOverviewModeActive() { | 193 bool WindowManagerImpl::IsOverviewModeActive() { |
174 return overview_; | 194 return overview_; |
175 } | 195 } |
176 | 196 |
177 void WindowManagerImpl::SetInOverview(bool active) { | 197 void WindowManagerImpl::SetInOverview(bool active) { |
178 bool in_overview = !!overview_; | 198 bool in_overview = !!overview_; |
179 if (active == in_overview) | 199 if (active == in_overview) |
180 return; | 200 return; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 236 |
217 void WindowManagerImpl::ToggleSplitViewForTest() { | 237 void WindowManagerImpl::ToggleSplitViewForTest() { |
218 ToggleSplitview(); | 238 ToggleSplitview(); |
219 } | 239 } |
220 | 240 |
221 WindowListProvider* WindowManagerImpl::GetWindowListProvider() { | 241 WindowListProvider* WindowManagerImpl::GetWindowListProvider() { |
222 return window_list_provider_.get(); | 242 return window_list_provider_.get(); |
223 } | 243 } |
224 | 244 |
225 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { | 245 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { |
246 SetInOverview(false); | |
247 | |
248 window->Show(); | |
249 wm::ActivateWindow(window); | |
sadrul
2014/09/17 18:04:44
ditto
| |
250 | |
226 if (split_view_controller_->IsSplitViewModeActive()) { | 251 if (split_view_controller_->IsSplitViewModeActive()) { |
227 split_view_controller_->DeactivateSplitMode(); | 252 split_view_controller_->DeactivateSplitMode(); |
228 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); | 253 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); |
229 } | 254 } |
230 wm::ActivateWindow(window); | |
231 SetInOverview(false); | |
232 // If |window| does not have the size of the work-area, then make sure it is | 255 // If |window| does not have the size of the work-area, then make sure it is |
233 // resized. | 256 // resized. |
234 const gfx::Size work_area = | 257 const gfx::Size work_area = |
235 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 258 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
236 if (window->GetTargetBounds().size() != work_area) { | 259 if (window->GetTargetBounds().size() != work_area) { |
237 const gfx::Rect& window_bounds = window->bounds(); | 260 const gfx::Rect& window_bounds = window->bounds(); |
238 const gfx::Rect desired_bounds(work_area); | 261 const gfx::Rect desired_bounds(work_area); |
239 gfx::Transform transform; | 262 gfx::Transform transform; |
240 transform.Translate(desired_bounds.x() - window_bounds.x(), | 263 transform.Translate(desired_bounds.x() - window_bounds.x(), |
241 desired_bounds.y() - window_bounds.y()); | 264 desired_bounds.y() - window_bounds.y()); |
242 transform.Scale(desired_bounds.width() / window_bounds.width(), | 265 transform.Scale(desired_bounds.width() / window_bounds.width(), |
243 desired_bounds.height() / window_bounds.height()); | 266 desired_bounds.height() / window_bounds.height()); |
244 window->layer()->GetAnimator()->AbortAllAnimations(); | |
245 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 267 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
246 settings.SetPreemptionStrategy( | 268 settings.SetPreemptionStrategy( |
247 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 269 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
248 settings.AddObserver( | 270 settings.AddObserver( |
249 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, | 271 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, |
250 base::Unretained(window), | 272 base::Unretained(window), |
251 desired_bounds, | 273 desired_bounds, |
252 gfx::Transform()))); | 274 gfx::Transform()))); |
253 window->SetTransform(transform); | 275 window->SetTransform(transform); |
254 } | 276 } |
255 } | 277 } |
256 | 278 |
257 void WindowManagerImpl::OnSplitViewMode(aura::Window* left, | 279 void WindowManagerImpl::OnSelectSplitViewWindow(aura::Window* left, |
258 aura::Window* right) { | 280 aura::Window* right, |
281 aura::Window* to_activate) { | |
259 SetInOverview(false); | 282 SetInOverview(false); |
260 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); | 283 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); |
261 split_view_controller_->ActivateSplitMode(left, right); | 284 split_view_controller_->ActivateSplitMode(left, right); |
262 } | 285 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 } | 286 } |
270 | 287 |
271 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { | 288 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
272 if (window == container_) | 289 if (window == container_) |
273 container_.reset(); | 290 container_.reset(); |
274 } | 291 } |
275 | 292 |
276 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { | 293 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { |
277 return true; | 294 return true; |
278 } | 295 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 DCHECK(!instance); | 419 DCHECK(!instance); |
403 } | 420 } |
404 | 421 |
405 // static | 422 // static |
406 WindowManager* WindowManager::GetInstance() { | 423 WindowManager* WindowManager::GetInstance() { |
407 DCHECK(instance); | 424 DCHECK(instance); |
408 return instance; | 425 return instance; |
409 } | 426 } |
410 | 427 |
411 } // namespace athena | 428 } // namespace athena |
OLD | NEW |