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/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" |
| 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 instance->split_view_controller_->ReplaceWindow( | 108 instance->split_view_controller_->ReplaceWindow( |
| 106 instance->split_view_controller_->left_window(), child); | 109 instance->split_view_controller_->left_window(), child); |
| 107 } else { | 110 } else { |
| 108 gfx::Size size = | 111 gfx::Size size = |
| 109 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 112 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
| 110 child->SetBounds(gfx::Rect(size)); | 113 child->SetBounds(gfx::Rect(size)); |
| 111 } | 114 } |
| 115 | |
| 116 if (instance->IsOverviewModeActive()) { | |
| 117 // TODO(pkotwicz|oshima). Creating a new window should only exit overview | |
| 118 // mode if the new window is activated. | |
| 119 instance->OnSelectWindow(child); | |
| 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 |
| 122 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( | 131 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( |
| 123 aura::Window* child, | 132 aura::Window* child, |
| 124 bool visible) { | 133 bool visible) { |
| 125 } | 134 } |
| 126 | 135 |
| 127 void AthenaContainerLayoutManager::SetChildBounds( | 136 void AthenaContainerLayoutManager::SetChildBounds( |
| 128 aura::Window* child, | 137 aura::Window* child, |
| 129 const gfx::Rect& requested_bounds) { | 138 const gfx::Rect& requested_bounds) { |
| 130 if (!requested_bounds.IsEmpty()) | 139 if (!requested_bounds.IsEmpty()) |
| 131 SetChildBoundsDirect(child, requested_bounds); | 140 SetChildBoundsDirect(child, requested_bounds); |
| 132 } | 141 } |
| 133 | 142 |
| 134 WindowManagerImpl::WindowManagerImpl() { | 143 WindowManagerImpl::WindowManagerImpl() : selecting_window_(false) { |
| 135 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); | 144 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); |
| 136 params.can_activate_children = true; | 145 params.can_activate_children = true; |
| 137 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 146 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
| 138 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 147 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
| 139 container_->AddObserver(this); | 148 container_->AddObserver(this); |
| 140 window_list_provider_.reset(new WindowListProviderImpl(container_.get())); | 149 window_list_provider_.reset(new WindowListProviderImpl(container_.get())); |
| 141 bezel_controller_.reset(new BezelController(container_.get())); | 150 bezel_controller_.reset(new BezelController(container_.get())); |
| 142 split_view_controller_.reset( | 151 split_view_controller_.reset( |
| 143 new SplitViewController(container_.get(), window_list_provider_.get())); | 152 new SplitViewController(container_.get(), window_list_provider_.get())); |
| 144 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); | 153 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 172 | 181 |
| 173 bool WindowManagerImpl::IsOverviewModeActive() { | 182 bool WindowManagerImpl::IsOverviewModeActive() { |
| 174 return overview_; | 183 return overview_; |
| 175 } | 184 } |
| 176 | 185 |
| 177 void WindowManagerImpl::SetInOverview(bool active) { | 186 void WindowManagerImpl::SetInOverview(bool active) { |
| 178 bool in_overview = !!overview_; | 187 bool in_overview = !!overview_; |
| 179 if (active == in_overview) | 188 if (active == in_overview) |
| 180 return; | 189 return; |
| 181 | 190 |
| 191 if (!active && !selecting_window_) { | |
| 192 const aura::Window::Windows& windows = | |
| 193 window_list_provider_->GetWindowList(); | |
|
sadrul
2014/09/12 04:42:06
Just const Windows windows = ...;
| |
| 194 if (!windows.empty()) { | |
| 195 if (split_view_controller_->IsSplitViewModeActive()) { | |
| 196 DCHECK(windows.back() == split_view_controller_->left_window() || | |
| 197 windows.back() == split_view_controller_->right_window()); | |
| 198 OnSelectSplitViewWindow(split_view_controller_->left_window(), | |
| 199 split_view_controller_->right_window(), | |
| 200 windows.back()); | |
| 201 } else { | |
| 202 OnSelectWindow(windows.back()); | |
| 203 } | |
| 204 return; | |
|
sadrul
2014/09/12 04:42:06
I think |overview_|, bezel-controller's delegate e
| |
| 205 } | |
| 206 } | |
| 207 | |
| 182 bezel_controller_->set_left_right_delegate( | 208 bezel_controller_->set_left_right_delegate( |
| 183 active ? NULL : split_view_controller_.get()); | 209 active ? NULL : split_view_controller_.get()); |
| 184 if (active) { | 210 if (active) { |
| 185 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeEnter()); | 211 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnOverviewModeEnter()); |
| 186 | 212 |
| 187 // Note: The window_list_provider_ resembles the exact window list of the | 213 // Note: The window_list_provider_ resembles the exact window list of the |
| 188 // container, so no re-stacking is required before showing the OverviewMode. | 214 // container, so no re-stacking is required before showing the OverviewMode. |
| 189 overview_ = WindowOverviewMode::Create( | 215 overview_ = WindowOverviewMode::Create( |
| 190 container_.get(), window_list_provider_.get(), | 216 container_.get(), window_list_provider_.get(), |
| 191 split_view_controller_.get(), this); | 217 split_view_controller_.get(), this); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 216 | 242 |
| 217 void WindowManagerImpl::ToggleSplitViewForTest() { | 243 void WindowManagerImpl::ToggleSplitViewForTest() { |
| 218 ToggleSplitview(); | 244 ToggleSplitview(); |
| 219 } | 245 } |
| 220 | 246 |
| 221 WindowListProvider* WindowManagerImpl::GetWindowListProvider() { | 247 WindowListProvider* WindowManagerImpl::GetWindowListProvider() { |
| 222 return window_list_provider_.get(); | 248 return window_list_provider_.get(); |
| 223 } | 249 } |
| 224 | 250 |
| 225 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { | 251 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { |
| 252 base::AutoReset<bool> selecting_window(&selecting_window_, true); | |
| 253 SetInOverview(false); | |
| 254 | |
| 255 window->Show(); | |
| 256 wm::ActivateWindow(window); | |
| 257 | |
| 226 if (split_view_controller_->IsSplitViewModeActive()) { | 258 if (split_view_controller_->IsSplitViewModeActive()) { |
| 227 split_view_controller_->DeactivateSplitMode(); | 259 split_view_controller_->DeactivateSplitMode(); |
| 228 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); | 260 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); |
| 229 } | 261 } |
| 230 wm::ActivateWindow(window); | |
| 231 SetInOverview(false); | |
| 232 // If |window| does not have the size of the work-area, then make sure it is | 262 // If |window| does not have the size of the work-area, then make sure it is |
| 233 // resized. | 263 // resized. |
| 234 const gfx::Size work_area = | 264 const gfx::Size work_area = |
| 235 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 265 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
| 236 if (window->GetTargetBounds().size() != work_area) { | 266 if (window->GetTargetBounds().size() != work_area) { |
| 237 const gfx::Rect& window_bounds = window->bounds(); | 267 const gfx::Rect& window_bounds = window->bounds(); |
| 238 const gfx::Rect desired_bounds(work_area); | 268 const gfx::Rect desired_bounds(work_area); |
| 239 gfx::Transform transform; | 269 gfx::Transform transform; |
| 240 transform.Translate(desired_bounds.x() - window_bounds.x(), | 270 transform.Translate(desired_bounds.x() - window_bounds.x(), |
| 241 desired_bounds.y() - window_bounds.y()); | 271 desired_bounds.y() - window_bounds.y()); |
| 242 transform.Scale(desired_bounds.width() / window_bounds.width(), | 272 transform.Scale(desired_bounds.width() / window_bounds.width(), |
| 243 desired_bounds.height() / window_bounds.height()); | 273 desired_bounds.height() / window_bounds.height()); |
| 244 window->layer()->GetAnimator()->AbortAllAnimations(); | |
| 245 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 274 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 246 settings.SetPreemptionStrategy( | 275 settings.SetPreemptionStrategy( |
| 247 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 276 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 248 settings.AddObserver( | 277 settings.AddObserver( |
| 249 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, | 278 new ui::ClosureAnimationObserver(base::Bind(&SetWindowState, |
| 250 base::Unretained(window), | 279 base::Unretained(window), |
| 251 desired_bounds, | 280 desired_bounds, |
| 252 gfx::Transform()))); | 281 gfx::Transform()))); |
| 253 window->SetTransform(transform); | 282 window->SetTransform(transform); |
| 254 } | 283 } |
| 255 } | 284 } |
| 256 | 285 |
| 257 void WindowManagerImpl::OnSplitViewMode(aura::Window* left, | 286 void WindowManagerImpl::OnSelectSplitViewWindow(aura::Window* left, |
| 258 aura::Window* right) { | 287 aura::Window* right, |
| 288 aura::Window* to_activate) { | |
| 289 base::AutoReset<bool> selecting_window(&selecting_window_, true); | |
| 259 SetInOverview(false); | 290 SetInOverview(false); |
| 260 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); | 291 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeEnter()); |
| 261 split_view_controller_->ActivateSplitMode(left, right); | 292 split_view_controller_->ActivateSplitMode(left, right); |
| 262 } | 293 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 } | 294 } |
| 270 | 295 |
| 271 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { | 296 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
| 272 if (window == container_) | 297 if (window == container_) |
| 273 container_.reset(); | 298 container_.reset(); |
| 274 } | 299 } |
| 275 | 300 |
| 276 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { | 301 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { |
| 277 return true; | 302 return true; |
| 278 } | 303 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 DCHECK(!instance); | 427 DCHECK(!instance); |
| 403 } | 428 } |
| 404 | 429 |
| 405 // static | 430 // static |
| 406 WindowManager* WindowManager::GetInstance() { | 431 WindowManager* WindowManager::GetInstance() { |
| 407 DCHECK(instance); | 432 DCHECK(instance); |
| 408 return instance; | 433 return instance; |
| 409 } | 434 } |
| 410 | 435 |
| 411 } // namespace athena | 436 } // namespace athena |
| OLD | NEW |