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