| 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/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "ui/aura/client/aura_constants.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" |
| 22 #include "ui/aura/window_delegate.h" |
| 21 #include "ui/compositor/closure_animation_observer.h" | 23 #include "ui/compositor/closure_animation_observer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/gfx/display.h" | 25 #include "ui/gfx/display.h" |
| 24 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
| 25 #include "ui/wm/core/shadow_controller.h" | 27 #include "ui/wm/core/shadow_controller.h" |
| 26 #include "ui/wm/core/transient_window_manager.h" | 28 #include "ui/wm/core/transient_window_manager.h" |
| 27 #include "ui/wm/core/window_util.h" | 29 #include "ui/wm/core/window_util.h" |
| 28 #include "ui/wm/core/wm_state.h" | 30 #include "ui/wm/core/wm_state.h" |
| 29 #include "ui/wm/public/activation_client.h" | 31 #include "ui/wm/public/activation_client.h" |
| 30 #include "ui/wm/public/window_types.h" | 32 #include "ui/wm/public/window_types.h" |
| 31 | 33 |
| 32 namespace athena { | 34 namespace athena { |
| 33 namespace { | 35 namespace { |
| 34 class WindowManagerImpl* instance = nullptr; | 36 class WindowManagerImpl* instance = nullptr; |
| 35 | 37 |
| 36 void SetWindowState(aura::Window* window, | 38 void SetWindowState(aura::Window* window, |
| 37 const gfx::Rect& bounds, | 39 const gfx::Rect& bounds, |
| 38 const gfx::Transform& transform) { | 40 const gfx::Transform& transform) { |
| 39 window->SetBounds(bounds); | 41 window->SetBounds(bounds); |
| 40 window->SetTransform(transform); | 42 window->SetTransform(transform); |
| 41 } | 43 } |
| 42 | 44 |
| 45 // Tests whether the given window can be maximized |
| 46 bool CanWindowMaximize(const aura::Window* const window) { |
| 47 const aura::WindowDelegate* delegate = window->delegate(); |
| 48 const bool no_max_size = |
| 49 !delegate || delegate->GetMaximumSize().IsEmpty(); |
| 50 return no_max_size && |
| 51 window->GetProperty(aura::client::kCanMaximizeKey) && |
| 52 window->GetProperty(aura::client::kCanResizeKey); |
| 53 } |
| 54 |
| 43 } // namespace | 55 } // namespace |
| 44 | 56 |
| 45 class AthenaContainerLayoutManager : public aura::LayoutManager { | 57 class AthenaContainerLayoutManager : public aura::LayoutManager { |
| 46 public: | 58 public: |
| 47 AthenaContainerLayoutManager(); | 59 AthenaContainerLayoutManager(); |
| 48 ~AthenaContainerLayoutManager() override; | 60 ~AthenaContainerLayoutManager() override; |
| 49 | 61 |
| 50 private: | 62 private: |
| 51 // aura::LayoutManager: | 63 // aura::LayoutManager: |
| 52 void OnWindowResized() override; | 64 void OnWindowResized() override; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 for (aura::Window::Windows::const_iterator iter = list.begin(); | 96 for (aura::Window::Windows::const_iterator iter = list.begin(); |
| 85 iter != list.end(); | 97 iter != list.end(); |
| 86 ++iter) { | 98 ++iter) { |
| 87 aura::Window* window = *iter; | 99 aura::Window* window = *iter; |
| 88 if (is_splitview) { | 100 if (is_splitview) { |
| 89 if (window == instance->split_view_controller_->left_window()) | 101 if (window == instance->split_view_controller_->left_window()) |
| 90 window->SetBounds(gfx::Rect(split_size)); | 102 window->SetBounds(gfx::Rect(split_size)); |
| 91 else if (window == instance->split_view_controller_->right_window()) | 103 else if (window == instance->split_view_controller_->right_window()) |
| 92 window->SetBounds( | 104 window->SetBounds( |
| 93 gfx::Rect(gfx::Point(split_size.width(), 0), split_size)); | 105 gfx::Rect(gfx::Point(split_size.width(), 0), split_size)); |
| 94 else | 106 else if (CanWindowMaximize(window)) |
| 107 window->SetBounds(gfx::Rect(work_area)); |
| 108 } else if (CanWindowMaximize(window)) |
| 95 window->SetBounds(gfx::Rect(work_area)); | 109 window->SetBounds(gfx::Rect(work_area)); |
| 96 } else { | |
| 97 window->SetBounds(gfx::Rect(work_area)); | |
| 98 } | |
| 99 } | 110 } |
| 100 } | 111 } |
| 101 | 112 |
| 102 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 113 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 103 // TODO(oshima): Split view modes needs to take the transient window into | 114 // TODO(oshima): Split view modes needs to take the transient window into |
| 104 // account. | 115 // account. |
| 105 if (wm::GetTransientParent(child)) { | 116 if (wm::GetTransientParent(child)) { |
| 106 wm::TransientWindowManager::Get(child) | 117 wm::TransientWindowManager::Get(child) |
| 107 ->set_parent_controls_visibility(true); | 118 ->set_parent_controls_visibility(true); |
| 108 } | 119 } |
| 109 } | 120 } |
| 110 | 121 |
| 111 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( | 122 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( |
| 112 aura::Window* child) { | 123 aura::Window* child) { |
| 113 } | 124 } |
| 114 | 125 |
| 115 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( | 126 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( |
| 116 aura::Window* child) { | 127 aura::Window* child) { |
| 117 } | 128 } |
| 118 | 129 |
| 119 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( | 130 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( |
| 120 aura::Window* child, | 131 aura::Window* child, |
| 121 bool visible) { | 132 bool visible) { |
| 133 if (visible && CanWindowMaximize(child)) { |
| 134 // Make sure we're resizing a window that actually exists in the window list |
| 135 // to avoid resizing the divider in the split mode. |
| 136 if(instance->window_list_provider_->IsWindowInList(child)) { |
| 137 child->SetBounds( |
| 138 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area()); |
| 139 } |
| 140 } |
| 122 } | 141 } |
| 123 | 142 |
| 124 void AthenaContainerLayoutManager::SetChildBounds( | 143 void AthenaContainerLayoutManager::SetChildBounds( |
| 125 aura::Window* child, | 144 aura::Window* child, |
| 126 const gfx::Rect& requested_bounds) { | 145 const gfx::Rect& requested_bounds) { |
| 127 if (!requested_bounds.IsEmpty()) | 146 if (!requested_bounds.IsEmpty()) |
| 128 SetChildBoundsDirect(child, requested_bounds); | 147 SetChildBoundsDirect(child, requested_bounds); |
| 129 } | 148 } |
| 130 | 149 |
| 131 WindowManagerImpl::WindowManagerImpl() { | 150 WindowManagerImpl::WindowManagerImpl() { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 wm::ActivateWindow(window); | 303 wm::ActivateWindow(window); |
| 285 | 304 |
| 286 if (split_view_controller_->IsSplitViewModeActive()) { | 305 if (split_view_controller_->IsSplitViewModeActive()) { |
| 287 split_view_controller_->DeactivateSplitMode(); | 306 split_view_controller_->DeactivateSplitMode(); |
| 288 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); | 307 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); |
| 289 } | 308 } |
| 290 // If |window| does not have the size of the work-area, then make sure it is | 309 // If |window| does not have the size of the work-area, then make sure it is |
| 291 // resized. | 310 // resized. |
| 292 const gfx::Size work_area = | 311 const gfx::Size work_area = |
| 293 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 312 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
| 294 if (window->GetTargetBounds().size() != work_area) { | 313 |
| 314 // Resize to the screen bounds only if the window is maximize-able, and |
| 315 // is not already maximized |
| 316 if (window->GetTargetBounds().size() != work_area && |
| 317 CanWindowMaximize(window)) { |
| 295 const gfx::Rect& window_bounds = window->bounds(); | 318 const gfx::Rect& window_bounds = window->bounds(); |
| 296 const gfx::Rect desired_bounds(work_area); | 319 const gfx::Rect desired_bounds(work_area); |
| 297 gfx::Transform transform; | 320 gfx::Transform transform; |
| 298 transform.Translate(desired_bounds.x() - window_bounds.x(), | 321 transform.Translate(desired_bounds.x() - window_bounds.x(), |
| 299 desired_bounds.y() - window_bounds.y()); | 322 desired_bounds.y() - window_bounds.y()); |
| 300 transform.Scale(desired_bounds.width() / window_bounds.width(), | 323 transform.Scale(desired_bounds.width() / window_bounds.width(), |
| 301 desired_bounds.height() / window_bounds.height()); | 324 desired_bounds.height() / window_bounds.height()); |
| 302 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 325 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 303 settings.SetPreemptionStrategy( | 326 settings.SetPreemptionStrategy( |
| 304 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 327 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 DCHECK(!instance); | 488 DCHECK(!instance); |
| 466 } | 489 } |
| 467 | 490 |
| 468 // static | 491 // static |
| 469 WindowManager* WindowManager::Get() { | 492 WindowManager* WindowManager::Get() { |
| 470 DCHECK(instance); | 493 DCHECK(instance); |
| 471 return instance; | 494 return instance; |
| 472 } | 495 } |
| 473 | 496 |
| 474 } // namespace athena | 497 } // namespace athena |
| OLD | NEW |