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" |
(...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. | |
118 instance->ExitOverview(child, WindowOverviewModeDelegate::SPLIT_NONE); | |
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 ExitOverview(); | |
180 else | |
181 EnterOverview(); | |
171 } | 182 } |
172 | 183 |
173 bool WindowManagerImpl::IsOverviewModeActive() { | 184 bool WindowManagerImpl::IsOverviewModeActive() { |
174 return overview_; | 185 return overview_; |
175 } | 186 } |
176 | 187 |
177 void WindowManagerImpl::SetInOverview(bool active) { | 188 void WindowManagerImpl::EnterOverview() { |
178 bool in_overview = !!overview_; | 189 if (overview_) |
179 if (active == in_overview) | |
180 return; | 190 return; |
181 | 191 |
182 bezel_controller_->set_left_right_delegate( | 192 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeEnter()); |
183 active ? NULL : split_view_controller_.get()); | |
184 if (active) { | |
185 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeEnter()); | |
186 | 193 |
187 // Re-stack all windows in the order defined by window_list_provider_. | 194 bezel_controller_->set_left_right_delegate(NULL); |
188 aura::Window::Windows window_list = window_list_provider_->GetWindowList(); | 195 |
189 aura::Window::Windows::iterator it; | 196 // Re-stack all windows in the order defined by window_list_provider_. |
190 for (it = window_list.begin(); it != window_list.end(); ++it) | 197 aura::Window::Windows window_list = window_list_provider_->GetWindowList(); |
191 container_->StackChildAtTop(*it); | 198 aura::Window::Windows::iterator it; |
192 overview_ = WindowOverviewMode::Create( | 199 for (it = window_list.begin(); it != window_list.end(); ++it) |
193 container_.get(), window_list_provider_.get(), | 200 container_->StackChildAtTop(*it); |
194 split_view_controller_.get(), this); | 201 overview_ = WindowOverviewMode::Create( |
195 } else { | 202 container_.get(), window_list_provider_.get(), |
196 overview_.reset(); | 203 split_view_controller_.get(), this); |
197 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeExit()); | |
198 } | |
199 } | 204 } |
200 | 205 |
201 void WindowManagerImpl::InstallAccelerators() { | 206 void WindowManagerImpl::ExitOverview(aura::Window* window, |
202 const AcceleratorData accelerator_data[] = { | 207 SplitType split_type) { |
203 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW, | 208 if (!overview_) |
204 AF_NONE}, | 209 return; |
205 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_CONTROL_DOWN, | |
206 CMD_TOGGLE_SPLIT_VIEW, AF_NONE}, | |
207 }; | |
208 AcceleratorManager::Get()->RegisterAccelerators( | |
209 accelerator_data, arraysize(accelerator_data), this); | |
210 } | |
211 | 210 |
212 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { | 211 overview_.reset(); |
213 observers_.AddObserver(observer); | 212 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeExit()); |
214 } | |
215 | 213 |
216 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { | 214 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); |
217 observers_.RemoveObserver(observer); | |
218 } | |
219 | 215 |
220 void WindowManagerImpl::ToggleSplitViewForTest() { | 216 if (!window) |
221 ToggleSplitview(); | 217 return; |
222 } | |
223 | 218 |
224 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { | 219 window->layer()->SetOpacity(1.0f); |
220 window->Show(); | |
221 wm::ActivateWindow(window); | |
222 | |
223 if (split_type != SPLIT_NONE) { | |
224 FOR_EACH_OBSERVER(WindowManagerObserver, | |
225 observers_, | |
226 OnSplitViewModeEnter()); | |
227 if (split_type == SPLIT_LEFT) | |
228 split_view_controller_->ActivateSplitMode(window, NULL); | |
229 else | |
230 split_view_controller_->ActivateSplitMode(NULL, window); | |
231 return; | |
232 } | |
233 | |
225 if (split_view_controller_->IsSplitViewModeActive()) { | 234 if (split_view_controller_->IsSplitViewModeActive()) { |
226 split_view_controller_->DeactivateSplitMode(); | 235 split_view_controller_->DeactivateSplitMode(); |
227 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); | 236 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); |
228 } | 237 } |
229 wm::ActivateWindow(window); | 238 |
230 SetInOverview(false); | |
231 // If |window| does not have the size of the work-area, then make sure it is | 239 // If |window| does not have the size of the work-area, then make sure it is |
232 // resized. | 240 // resized. |
233 const gfx::Size work_area = | 241 const gfx::Size work_area = |
234 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 242 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
235 if (window->GetTargetBounds().size() != work_area) { | 243 if (window->GetTargetBounds().size() != work_area) { |
236 const gfx::Rect& window_bounds = window->bounds(); | 244 const gfx::Rect& window_bounds = window->bounds(); |
237 const gfx::Rect desired_bounds(work_area); | 245 const gfx::Rect desired_bounds(work_area); |
238 gfx::Transform transform; | 246 gfx::Transform transform; |
239 transform.Translate(desired_bounds.x() - window_bounds.x(), | 247 transform.Translate(desired_bounds.x() - window_bounds.x(), |
240 desired_bounds.y() - window_bounds.y()); | 248 desired_bounds.y() - window_bounds.y()); |
241 transform.Scale(desired_bounds.width() / window_bounds.width(), | 249 transform.Scale(desired_bounds.width() / window_bounds.width(), |
242 desired_bounds.height() / window_bounds.height()); | 250 desired_bounds.height() / window_bounds.height()); |
243 window->layer()->GetAnimator()->AbortAllAnimations(); | |
244 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 251 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
245 settings.SetPreemptionStrategy( | 252 settings.SetPreemptionStrategy( |
246 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 253 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
247 settings.AddObserver( | 254 settings.AddObserver( |
248 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, | 255 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, |
249 base::Unretained(window), | 256 base::Unretained(window), |
250 desired_bounds, | 257 desired_bounds, |
251 gfx::Transform()))); | 258 gfx::Transform()))); |
252 window->SetTransform(transform); | 259 window->SetTransform(transform); |
253 } | 260 } |
254 } | 261 } |
255 | 262 |
256 void WindowManagerImpl::OnSplitViewMode(aura::Window* left, | 263 void WindowManagerImpl::ExitOverview() { |
257 aura::Window* right) { | 264 if (overview_) |
258 SetInOverview(false); | 265 overview_->SelectDefaultWindow(); |
sadrul
2014/09/07 05:26:49
If the WOM did not explicitly request a selection
pkotwicz
2014/09/08 19:39:23
WOM is best positioned to select the default windo
sadrul
2014/09/11 05:43:37
If the user dismisses the overview mode without ac
| |
259 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); | |
260 split_view_controller_->ActivateSplitMode(left, right); | |
261 } | 266 } |
262 | 267 |
263 void WindowManagerImpl::OnWindowAdded(aura::Window* new_window) { | 268 void WindowManagerImpl::InstallAccelerators() { |
264 // TODO(oshima): Creating a new window should updates the ovewview mode | 269 const AcceleratorData accelerator_data[] = { |
265 // instead of exitting. | 270 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW, |
266 if (new_window->type() == ui::wm::WINDOW_TYPE_NORMAL) | 271 AF_NONE}, |
267 SetInOverview(false); | 272 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_CONTROL_DOWN, |
273 CMD_TOGGLE_SPLIT_VIEW, AF_NONE}, | |
274 }; | |
275 AcceleratorManager::Get()->RegisterAccelerators( | |
276 accelerator_data, arraysize(accelerator_data), this); | |
277 } | |
278 | |
279 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { | |
280 observers_.AddObserver(observer); | |
281 } | |
282 | |
283 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { | |
284 observers_.RemoveObserver(observer); | |
285 } | |
286 | |
287 void WindowManagerImpl::ToggleSplitViewForTest() { | |
288 ToggleSplitview(); | |
289 } | |
290 | |
291 void WindowManagerImpl::OnSelectWindow(aura::Window* window, | |
292 SplitType split_type) { | |
293 ExitOverview(window, split_type); | |
268 } | 294 } |
269 | 295 |
270 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { | 296 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
271 if (window == container_) | 297 if (window == container_) |
272 container_.reset(); | 298 container_.reset(); |
273 } | 299 } |
274 | 300 |
275 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { | 301 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { |
276 return true; | 302 return true; |
277 } | 303 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 DCHECK(!instance); | 427 DCHECK(!instance); |
402 } | 428 } |
403 | 429 |
404 // static | 430 // static |
405 WindowManager* WindowManager::GetInstance() { | 431 WindowManager* WindowManager::GetInstance() { |
406 DCHECK(instance); | 432 DCHECK(instance); |
407 return instance; | 433 return instance; |
408 } | 434 } |
409 | 435 |
410 } // namespace athena | 436 } // namespace athena |
OLD | NEW |