| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mash/wm/window_manager.h" | 5 #include "mash/wm/window_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace mash { | 24 namespace mash { |
| 25 namespace wm { | 25 namespace wm { |
| 26 | 26 |
| 27 WindowManager::WindowManager() | 27 WindowManager::WindowManager() |
| 28 : root_controller_(nullptr), | 28 : root_controller_(nullptr), |
| 29 window_manager_client_(nullptr), | 29 window_manager_client_(nullptr), |
| 30 binding_(this) {} | 30 binding_(this) {} |
| 31 | 31 |
| 32 WindowManager::~WindowManager() { | 32 WindowManager::~WindowManager() { |
| 33 if (!root_controller_) | |
| 34 return; | |
| 35 for (auto container : root_controller_->root()->children()) { | |
| 36 container->RemoveObserver(this); | |
| 37 for (auto child : container->children()) | |
| 38 child->RemoveObserver(this); | |
| 39 } | |
| 40 } | 33 } |
| 41 | 34 |
| 42 void WindowManager::Initialize(RootWindowController* root_controller, | 35 void WindowManager::Initialize(RootWindowController* root_controller, |
| 43 session::mojom::Session* session) { | 36 session::mojom::Session* session) { |
| 44 DCHECK(root_controller); | 37 DCHECK(root_controller); |
| 45 DCHECK(!root_controller_); | 38 DCHECK(!root_controller_); |
| 46 root_controller_ = root_controller; | 39 root_controller_ = root_controller; |
| 47 // The children of the root are considered containers. | 40 |
| 48 for (auto container : root_controller_->root()->children()) { | 41 // Observe all the containers so that windows can be added to/removed from the |
| 49 container->AddObserver(this); | 42 // |disconnected_app_handler_|. |
| 50 for (auto child : container->children()) | 43 int count = static_cast<int>(mojom::Container::COUNT); |
| 51 child->AddObserver(this); | 44 for (int id = static_cast<int>(mojom::Container::ROOT) + 1; id < count; |
| 45 ++id) { |
| 46 mus::Window* container = root_controller_->GetWindowForContainer( |
| 47 static_cast<mojom::Container>(id)); |
| 48 Add(container); |
| 49 |
| 50 // Add any pre-existing windows in the container to |
| 51 // |disconnected_app_handler_|. |
| 52 for (auto child : container->children()) { |
| 53 if (!root_controller_->WindowIsContainer(child)) |
| 54 disconnected_app_handler_.Add(child); |
| 55 } |
| 52 } | 56 } |
| 53 | 57 |
| 54 // The insets are roughly what is needed by CustomFrameView. The expectation | 58 // The insets are roughly what is needed by CustomFrameView. The expectation |
| 55 // is at some point we'll write our own NonClientFrameView and get the insets | 59 // is at some point we'll write our own NonClientFrameView and get the insets |
| 56 // from it. | 60 // from it. |
| 57 mus::mojom::FrameDecorationValuesPtr frame_decoration_values = | 61 mus::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 58 mus::mojom::FrameDecorationValues::New(); | 62 mus::mojom::FrameDecorationValues::New(); |
| 59 const gfx::Insets client_area_insets = | 63 const gfx::Insets client_area_insets = |
| 60 NonClientFrameController::GetPreferredClientAreaInsets(); | 64 NonClientFrameController::GetPreferredClientAreaInsets(); |
| 61 frame_decoration_values->normal_client_area_insets = | 65 frame_decoration_values->normal_client_area_insets = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const bool provide_non_client_frame = | 108 const bool provide_non_client_frame = |
| 105 GetWindowType(*properties) == mus::mojom::WindowType::WINDOW; | 109 GetWindowType(*properties) == mus::mojom::WindowType::WINDOW; |
| 106 if (provide_non_client_frame) | 110 if (provide_non_client_frame) |
| 107 (*properties)[mus::mojom::kWaitForUnderlay_Property].clear(); | 111 (*properties)[mus::mojom::kWaitForUnderlay_Property].clear(); |
| 108 | 112 |
| 109 // TODO(sky): constrain and validate properties before passing to server. | 113 // TODO(sky): constrain and validate properties before passing to server. |
| 110 mus::Window* window = root->connection()->NewWindow(properties); | 114 mus::Window* window = root->connection()->NewWindow(properties); |
| 111 window->SetBounds(CalculateDefaultBounds(window)); | 115 window->SetBounds(CalculateDefaultBounds(window)); |
| 112 | 116 |
| 113 mojom::Container container = GetRequestedContainer(window); | 117 mojom::Container container = GetRequestedContainer(window); |
| 114 root_controller_->GetWindowForContainer(container)->AddChild(window); | 118 mus::Window* container_window = |
| 119 root_controller_->GetWindowForContainer(container); |
| 120 DCHECK(root_controller_->WindowIsContainer(container_window)); |
| 121 container_window->AddChild(window); |
| 115 | 122 |
| 116 if (provide_non_client_frame) { | 123 if (provide_non_client_frame) { |
| 117 NonClientFrameController::Create(root_controller_->GetConnector(), window, | 124 NonClientFrameController::Create(root_controller_->GetConnector(), window, |
| 118 root_controller_->window_manager_client()); | 125 root_controller_->window_manager_client()); |
| 119 } | 126 } |
| 120 | 127 |
| 121 root_controller_->IncrementWindowCount(); | 128 root_controller_->IncrementWindowCount(); |
| 122 | 129 |
| 123 return window; | 130 return window; |
| 124 } | 131 } |
| 125 | 132 |
| 126 void WindowManager::OnTreeChanging(const TreeChangeParams& params) { | 133 void WindowManager::OnTreeChanging(const TreeChangeParams& params) { |
| 127 DCHECK(root_controller_); | 134 DCHECK(root_controller_); |
| 128 if (root_controller_->WindowIsContainer(params.old_parent)) | 135 if (params.old_parent == params.receiver && |
| 129 params.target->RemoveObserver(this); | 136 root_controller_->WindowIsContainer(params.old_parent)) |
| 130 else if (root_controller_->WindowIsContainer(params.new_parent)) | 137 disconnected_app_handler_.Remove(params.target); |
| 131 params.target->AddObserver(this); | |
| 132 } | |
| 133 | 138 |
| 134 void WindowManager::OnWindowEmbeddedAppDisconnected(mus::Window* window) { | 139 if (params.new_parent == params.receiver && |
| 135 window->Destroy(); | 140 root_controller_->WindowIsContainer(params.new_parent)) |
| 141 disconnected_app_handler_.Add(params.target); |
| 142 |
| 143 mus::WindowTracker::OnTreeChanging(params); |
| 136 } | 144 } |
| 137 | 145 |
| 138 void WindowManager::SetWindowManagerClient(mus::WindowManagerClient* client) { | 146 void WindowManager::SetWindowManagerClient(mus::WindowManagerClient* client) { |
| 139 window_manager_client_ = client; | 147 window_manager_client_ = client; |
| 140 } | 148 } |
| 141 | 149 |
| 142 bool WindowManager::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { | 150 bool WindowManager::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { |
| 143 // By returning true the bounds of |window| is updated. | 151 // By returning true the bounds of |window| is updated. |
| 144 return true; | 152 return true; |
| 145 } | 153 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 168 | 176 |
| 169 void WindowManager::ScreenlockStateChanged(bool locked) { | 177 void WindowManager::ScreenlockStateChanged(bool locked) { |
| 170 // Hide USER_PRIVATE windows when the screen is locked. | 178 // Hide USER_PRIVATE windows when the screen is locked. |
| 171 mus::Window* window = root_controller_->GetWindowForContainer( | 179 mus::Window* window = root_controller_->GetWindowForContainer( |
| 172 mash::wm::mojom::Container::USER_PRIVATE); | 180 mash::wm::mojom::Container::USER_PRIVATE); |
| 173 window->SetVisible(!locked); | 181 window->SetVisible(!locked); |
| 174 } | 182 } |
| 175 | 183 |
| 176 } // namespace wm | 184 } // namespace wm |
| 177 } // namespace mash | 185 } // namespace mash |
| OLD | NEW |