| 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" |
| 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/logging.h" | 17 #include "base/logging.h" |
| 18 #include "ui/aura/layout_manager.h" | 18 #include "ui/aura/layout_manager.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/wm/core/shadow_controller.h" | 20 #include "ui/wm/core/shadow_controller.h" |
| 21 #include "ui/wm/core/window_util.h" | 21 #include "ui/wm/core/window_util.h" |
| 22 #include "ui/wm/core/wm_state.h" | 22 #include "ui/wm/core/wm_state.h" |
| 23 #include "ui/wm/public/activation_client.h" | 23 #include "ui/wm/public/activation_client.h" |
| 24 #include "ui/wm/public/window_types.h" | 24 #include "ui/wm/public/window_types.h" |
| 25 | 25 |
| 26 namespace athena { | 26 namespace athena { |
| 27 namespace { | 27 namespace { |
| 28 | |
| 29 class WindowManagerImpl* instance = NULL; | 28 class WindowManagerImpl* instance = NULL; |
| 29 } // namespace |
| 30 | 30 |
| 31 class AthenaContainerLayoutManager : public aura::LayoutManager { | 31 class AthenaContainerLayoutManager : public aura::LayoutManager { |
| 32 public: | 32 public: |
| 33 AthenaContainerLayoutManager(); | 33 AthenaContainerLayoutManager(); |
| 34 virtual ~AthenaContainerLayoutManager(); | 34 virtual ~AthenaContainerLayoutManager(); |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 // aura::LayoutManager: | 37 // aura::LayoutManager: |
| 38 virtual void OnWindowResized() OVERRIDE; | 38 virtual void OnWindowResized() OVERRIDE; |
| 39 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; | 39 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; |
| 40 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; | 40 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; |
| 41 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; | 41 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE; |
| 42 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 42 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 43 bool visible) OVERRIDE; | 43 bool visible) OVERRIDE; |
| 44 virtual void SetChildBounds(aura::Window* child, | 44 virtual void SetChildBounds(aura::Window* child, |
| 45 const gfx::Rect& requested_bounds) OVERRIDE; | 45 const gfx::Rect& requested_bounds) OVERRIDE; |
| 46 | 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); | 47 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 AthenaContainerLayoutManager::AthenaContainerLayoutManager() { | 50 AthenaContainerLayoutManager::AthenaContainerLayoutManager() { |
| 51 } | 51 } |
| 52 | 52 |
| 53 AthenaContainerLayoutManager::~AthenaContainerLayoutManager() { | 53 AthenaContainerLayoutManager::~AthenaContainerLayoutManager() { |
| 54 } | 54 } |
| 55 | 55 |
| 56 void AthenaContainerLayoutManager::OnWindowResized() { | 56 void AthenaContainerLayoutManager::OnWindowResized() { |
| 57 instance->Layout(); | 57 // Resize all the existing windows. |
| 58 const aura::Window::Windows& list = instance->container_->children(); |
| 59 const gfx::Size container_size = instance->container_->bounds().size(); |
| 60 bool is_splitview = instance->split_view_controller_->IsSplitViewModeActive(); |
| 61 gfx::Size split_size; |
| 62 if (is_splitview) { |
| 63 CHECK(instance->split_view_controller_->left_window()); |
| 64 split_size = |
| 65 instance->split_view_controller_->left_window()->bounds().size(); |
| 66 } |
| 67 |
| 68 for (aura::Window::Windows::const_iterator iter = list.begin(); |
| 69 iter != list.end(); |
| 70 ++iter) { |
| 71 aura::Window* window = *iter; |
| 72 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) |
| 73 return; |
| 74 if (is_splitview) { |
| 75 if (window == instance->split_view_controller_->left_window()) |
| 76 window->SetBounds(gfx::Rect(split_size)); |
| 77 else if (window == instance->split_view_controller_->right_window()) |
| 78 window->SetBounds( |
| 79 gfx::Rect(gfx::Point(split_size.width(), 0), split_size)); |
| 80 else |
| 81 window->SetBounds(gfx::Rect(container_size)); |
| 82 } else { |
| 83 window->SetBounds(gfx::Rect(container_size)); |
| 84 } |
| 85 } |
| 58 } | 86 } |
| 59 | 87 |
| 60 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 88 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 61 instance->Layout(); | 89 if (child->type() != ui::wm::WINDOW_TYPE_NORMAL) |
| 90 return; |
| 91 aura::Window* window = NULL; |
| 92 if (instance->split_view_controller_->IsSplitViewModeActive()) |
| 93 window = instance->split_view_controller_->left_window(); |
| 94 else |
| 95 window = instance->container_.get(); |
| 96 CHECK(window); |
| 97 child->SetBounds(gfx::Rect(window->bounds().size())); |
| 62 } | 98 } |
| 63 | 99 |
| 64 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( | 100 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( |
| 65 aura::Window* child) { | 101 aura::Window* child) { |
| 66 } | 102 } |
| 67 | 103 |
| 68 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( | 104 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( |
| 69 aura::Window* child) { | 105 aura::Window* child) { |
| 70 instance->Layout(); | |
| 71 } | 106 } |
| 72 | 107 |
| 73 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( | 108 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( |
| 74 aura::Window* child, | 109 aura::Window* child, |
| 75 bool visible) { | 110 bool visible) { |
| 76 instance->Layout(); | |
| 77 } | 111 } |
| 78 | 112 |
| 79 void AthenaContainerLayoutManager::SetChildBounds( | 113 void AthenaContainerLayoutManager::SetChildBounds( |
| 80 aura::Window* child, | 114 aura::Window* child, |
| 81 const gfx::Rect& requested_bounds) { | 115 const gfx::Rect& requested_bounds) { |
| 82 if (!requested_bounds.IsEmpty()) | 116 if (!requested_bounds.IsEmpty()) |
| 83 SetChildBoundsDirect(child, requested_bounds); | 117 SetChildBoundsDirect(child, requested_bounds); |
| 84 } | 118 } |
| 85 | 119 |
| 86 } // namespace | |
| 87 | |
| 88 WindowManagerImpl::WindowManagerImpl() { | 120 WindowManagerImpl::WindowManagerImpl() { |
| 89 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); | 121 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); |
| 90 params.can_activate_children = true; | 122 params.can_activate_children = true; |
| 91 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 123 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
| 92 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 124 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
| 93 container_->AddObserver(this); | 125 container_->AddObserver(this); |
| 94 window_list_provider_.reset(new WindowListProviderImpl(container_.get())); | 126 window_list_provider_.reset(new WindowListProviderImpl(container_.get())); |
| 95 bezel_controller_.reset(new BezelController(container_.get())); | 127 bezel_controller_.reset(new BezelController(container_.get())); |
| 96 split_view_controller_.reset( | 128 split_view_controller_.reset( |
| 97 new SplitViewController(container_.get(), window_list_provider_.get())); | 129 new SplitViewController(container_.get(), window_list_provider_.get())); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 113 if (container_) { | 145 if (container_) { |
| 114 container_->RemoveObserver(this); | 146 container_->RemoveObserver(this); |
| 115 container_->RemovePreTargetHandler(bezel_controller_.get()); | 147 container_->RemovePreTargetHandler(bezel_controller_.get()); |
| 116 } | 148 } |
| 117 // |title_drag_controller_| needs to be reset before |container_|. | 149 // |title_drag_controller_| needs to be reset before |container_|. |
| 118 title_drag_controller_.reset(); | 150 title_drag_controller_.reset(); |
| 119 container_.reset(); | 151 container_.reset(); |
| 120 instance = NULL; | 152 instance = NULL; |
| 121 } | 153 } |
| 122 | 154 |
| 123 void WindowManagerImpl::Layout() { | |
| 124 if (!container_) | |
| 125 return; | |
| 126 gfx::Rect bounds = gfx::Rect(container_->bounds().size()); | |
| 127 const aura::Window::Windows& children = container_->children(); | |
| 128 for (aura::Window::Windows::const_iterator iter = children.begin(); | |
| 129 iter != children.end(); | |
| 130 ++iter) { | |
| 131 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL) | |
| 132 (*iter)->SetBounds(bounds); | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 void WindowManagerImpl::ToggleOverview() { | 155 void WindowManagerImpl::ToggleOverview() { |
| 137 SetInOverview(overview_.get() == NULL); | 156 SetInOverview(overview_.get() == NULL); |
| 138 } | 157 } |
| 139 | 158 |
| 140 bool WindowManagerImpl::IsOverviewModeActive() { | 159 bool WindowManagerImpl::IsOverviewModeActive() { |
| 141 return overview_; | 160 return overview_; |
| 142 } | 161 } |
| 143 | 162 |
| 144 void WindowManagerImpl::SetInOverview(bool active) { | 163 void WindowManagerImpl::SetInOverview(bool active) { |
| 145 bool in_overview = !!overview_; | 164 bool in_overview = !!overview_; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 DCHECK(!instance); | 308 DCHECK(!instance); |
| 290 } | 309 } |
| 291 | 310 |
| 292 // static | 311 // static |
| 293 WindowManager* WindowManager::GetInstance() { | 312 WindowManager* WindowManager::GetInstance() { |
| 294 DCHECK(instance); | 313 DCHECK(instance); |
| 295 return instance; | 314 return instance; |
| 296 } | 315 } |
| 297 | 316 |
| 298 } // namespace athena | 317 } // namespace athena |
| OLD | NEW |