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