| 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_impl.h" | 5 #include "ash/mus/wm/window_manager_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/mus/wm/non_client_frame_controller.h" |
| 11 #include "ash/mus/wm/window_manager_application.h" |
| 10 #include "components/mus/common/types.h" | 12 #include "components/mus/common/types.h" |
| 11 #include "components/mus/public/cpp/window.h" | 13 #include "components/mus/public/cpp/window.h" |
| 12 #include "components/mus/public/cpp/window_property.h" | 14 #include "components/mus/public/cpp/window_property.h" |
| 13 #include "components/mus/public/cpp/window_tree_connection.h" | 15 #include "components/mus/public/cpp/window_tree_connection.h" |
| 14 #include "components/mus/public/interfaces/input_events.mojom.h" | 16 #include "components/mus/public/interfaces/input_events.mojom.h" |
| 15 #include "components/mus/public/interfaces/mus_constants.mojom.h" | 17 #include "components/mus/public/interfaces/mus_constants.mojom.h" |
| 16 #include "components/mus/public/interfaces/window_manager.mojom.h" | 18 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 17 #include "mash/wm/non_client_frame_controller.h" | |
| 18 #include "mash/wm/property_util.h" | |
| 19 #include "mash/wm/public/interfaces/container.mojom.h" | |
| 20 #include "mash/wm/window_manager_application.h" | |
| 21 #include "mojo/converters/geometry/geometry_type_converters.h" | 19 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 22 #include "mojo/shell/public/cpp/application_impl.h" | 20 #include "mojo/shell/public/cpp/application_impl.h" |
| 23 | 21 |
| 24 namespace mash { | 22 namespace ash { |
| 25 namespace wm { | 23 namespace muswm { |
| 26 | 24 |
| 27 WindowManagerImpl::WindowManagerImpl() | 25 WindowManagerImpl::WindowManagerImpl() |
| 28 : state_(nullptr), window_manager_client_(nullptr) {} | 26 : state_(nullptr), window_manager_client_(nullptr) {} |
| 29 | 27 |
| 30 WindowManagerImpl::~WindowManagerImpl() { | 28 WindowManagerImpl::~WindowManagerImpl() { |
| 31 if (!state_) | 29 if (!state_) |
| 32 return; | 30 return; |
| 33 for (auto container : state_->root()->children()) { | 31 for (auto container : state_->root()->children()) { |
| 34 container->RemoveObserver(this); | 32 container->RemoveObserver(this); |
| 35 for (auto child : container->children()) | 33 for (auto child : container->children()) |
| 36 child->RemoveObserver(this); | 34 child->RemoveObserver(this); |
| 37 } | 35 } |
| 38 } | 36 } |
| 39 | 37 |
| 40 void WindowManagerImpl::Initialize(WindowManagerApplication* state) { | 38 void WindowManagerImpl::Initialize(WindowManagerApplication* state) { |
| 41 DCHECK(state); | 39 DCHECK(state); |
| 42 DCHECK(!state_); | 40 DCHECK(!state_); |
| 43 state_ = state; | 41 state_ = state; |
| 44 // The children of the root are considered containers. | 42 // The children of the root are considered containers. |
| 45 for (auto container : state_->root()->children()) { | 43 for (auto container : state_->root()->children()) { |
| 46 container->AddObserver(this); | 44 container->AddObserver(this); |
| 47 for (auto child : container->children()) | 45 for (auto child : container->children()) |
| 48 child->AddObserver(this); | 46 child->AddObserver(this); |
| 49 } | 47 } |
| 50 | 48 |
| 51 // The insets are roughly what is needed by CustomFrameView. The expectation | 49 // XXX(sad): satiate the WS |
| 52 // is at some point we'll write our own NonClientFrameView and get the insets | |
| 53 // from it. | |
| 54 mus::mojom::FrameDecorationValuesPtr frame_decoration_values = | 50 mus::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 55 mus::mojom::FrameDecorationValues::New(); | 51 mus::mojom::FrameDecorationValues::New(); |
| 56 const gfx::Insets client_area_insets = | 52 frame_decoration_values->normal_client_area_insets = mojo::Insets::New(); |
| 57 NonClientFrameController::GetPreferredClientAreaInsets(); | 53 frame_decoration_values->maximized_client_area_insets = mojo::Insets::New(); |
| 58 frame_decoration_values->normal_client_area_insets = | 54 frame_decoration_values->max_title_bar_button_width = 0u; |
| 59 mojo::Insets::From(client_area_insets); | |
| 60 frame_decoration_values->maximized_client_area_insets = | |
| 61 mojo::Insets::From(client_area_insets); | |
| 62 frame_decoration_values->max_title_bar_button_width = | |
| 63 NonClientFrameController::GetMaxTitleBarButtonWidth(); | |
| 64 window_manager_client_->SetFrameDecorationValues( | 55 window_manager_client_->SetFrameDecorationValues( |
| 65 std::move(frame_decoration_values)); | 56 std::move(frame_decoration_values)); |
| 66 } | 57 } |
| 67 | 58 |
| 68 gfx::Rect WindowManagerImpl::CalculateDefaultBounds(mus::Window* window) const { | 59 gfx::Rect WindowManagerImpl::CalculateDefaultBounds(mus::Window* window) const { |
| 69 DCHECK(state_); | 60 DCHECK(state_); |
| 70 int width, height; | 61 int width, height; |
| 71 const gfx::Size pref = GetWindowPreferredSize(window); | 62 const gfx::Size pref = gfx::Size(); |
| 72 const mus::Window* root = state_->root(); | 63 const mus::Window* root = state_->root(); |
| 73 if (pref.IsEmpty()) { | 64 if (pref.IsEmpty()) { |
| 74 width = root->bounds().width() - 240; | 65 width = root->bounds().width() - 240; |
| 75 height = root->bounds().height() - 240; | 66 height = root->bounds().height() - 240; |
| 76 } else { | 67 } else { |
| 77 // TODO(sky): likely want to constrain more than root size. | 68 // TODO(sky): likely want to constrain more than root size. |
| 78 const gfx::Size max_size = GetMaximizedWindowBounds().size(); | 69 const gfx::Size max_size = GetMaximizedWindowBounds().size(); |
| 79 width = std::max(0, std::min(max_size.width(), pref.width())); | 70 width = std::max(0, std::min(max_size.width(), pref.width())); |
| 80 height = std::max(0, std::min(max_size.height(), pref.height())); | 71 height = std::max(0, std::min(max_size.height(), pref.height())); |
| 81 } | 72 } |
| 82 return gfx::Rect(40 + (state_->window_count() % 4) * 40, | 73 return gfx::Rect(40 + (state_->window_count() % 4) * 40, |
| 83 40 + (state_->window_count() % 4) * 40, width, height); | 74 40 + (state_->window_count() % 4) * 40, width, height); |
| 84 } | 75 } |
| 85 | 76 |
| 86 gfx::Rect WindowManagerImpl::GetMaximizedWindowBounds() const { | 77 gfx::Rect WindowManagerImpl::GetMaximizedWindowBounds() const { |
| 87 DCHECK(state_); | 78 DCHECK(state_); |
| 88 return gfx::Rect(state_->root()->bounds().size()); | 79 return gfx::Rect(state_->root()->bounds().size()); |
| 89 } | 80 } |
| 90 | 81 |
| 91 mus::Window* WindowManagerImpl::NewTopLevelWindow( | 82 mus::Window* WindowManagerImpl::NewTopLevelWindow( |
| 92 std::map<std::string, std::vector<uint8_t>>* properties, | 83 std::map<std::string, std::vector<uint8_t>>* properties, |
| 93 mus::mojom::WindowTreeClientPtr client) { | 84 mus::mojom::WindowTreeClientPtr client) { |
| 94 DCHECK(state_); | 85 DCHECK(state_); |
| 95 mus::Window* root = state_->root(); | 86 mus::Window* root = state_->root(); |
| 96 DCHECK(root); | 87 DCHECK(root); |
| 97 | 88 |
| 98 const bool provide_non_client_frame = | 89 const bool provide_non_client_frame = true; // XXX(sad): |
| 99 GetWindowType(*properties) == mus::mojom::WindowType::WINDOW; | |
| 100 if (provide_non_client_frame) | 90 if (provide_non_client_frame) |
| 101 (*properties)[mus::mojom::kWaitForUnderlay_Property].clear(); | 91 (*properties)[mus::mojom::kWaitForUnderlay_Property].clear(); |
| 102 | 92 |
| 103 // TODO(sky): constrain and validate properties before passing to server. | 93 // TODO(sky): constrain and validate properties before passing to server. |
| 104 mus::Window* window = root->connection()->NewWindow(properties); | 94 mus::Window* window = root->connection()->NewWindow(properties); |
| 105 window->SetBounds(CalculateDefaultBounds(window)); | 95 window->SetBounds(CalculateDefaultBounds(window)); |
| 106 | 96 |
| 107 mojom::Container container = GetRequestedContainer(window); | 97 state_->root()->AddChild(window); |
| 108 state_->GetWindowForContainer(container)->AddChild(window); | |
| 109 | 98 |
| 110 if (client) | 99 if (client) |
| 111 window->Embed(std::move(client)); | 100 window->Embed(std::move(client)); |
| 112 | |
| 113 if (provide_non_client_frame) { | 101 if (provide_non_client_frame) { |
| 114 // NonClientFrameController deletes itself when |window| is destroyed. | 102 // NonClientFrameController deletes itself when |window| is destroyed. |
| 115 new NonClientFrameController(state_->app()->shell(), window, | 103 new NonClientFrameController(state_->app()->shell(), window, |
| 116 state_->window_tree_host()); | 104 state_->window_tree_host(), |
| 105 state_->aura_root()); |
| 117 } | 106 } |
| 118 | 107 |
| 119 state_->IncrementWindowCount(); | 108 state_->IncrementWindowCount(); |
| 120 | 109 |
| 121 return window; | 110 return window; |
| 122 } | 111 } |
| 123 | 112 |
| 124 void WindowManagerImpl::OnTreeChanging(const TreeChangeParams& params) { | 113 void WindowManagerImpl::OnTreeChanging(const TreeChangeParams& params) { |
| 125 DCHECK(state_); | 114 DCHECK(state_); |
| 115 #if 0 |
| 126 if (state_->WindowIsContainer(params.old_parent)) | 116 if (state_->WindowIsContainer(params.old_parent)) |
| 127 params.target->RemoveObserver(this); | 117 params.target->RemoveObserver(this); |
| 128 else if (state_->WindowIsContainer(params.new_parent)) | 118 else if (state_->WindowIsContainer(params.new_parent)) |
| 129 params.target->AddObserver(this); | 119 params.target->AddObserver(this); |
| 120 #endif |
| 130 } | 121 } |
| 131 | 122 |
| 132 void WindowManagerImpl::OnWindowEmbeddedAppDisconnected(mus::Window* window) { | 123 void WindowManagerImpl::OnWindowEmbeddedAppDisconnected(mus::Window* window) { |
| 133 window->Destroy(); | 124 window->Destroy(); |
| 134 } | 125 } |
| 135 | 126 |
| 136 void WindowManagerImpl::OpenWindow( | 127 void WindowManagerImpl::OpenWindow( |
| 137 mus::mojom::WindowTreeClientPtr client, | 128 mus::mojom::WindowTreeClientPtr client, |
| 138 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 129 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
| 139 mus::Window::SharedProperties properties = | 130 mus::Window::SharedProperties properties = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 161 name == mus::mojom::WindowManager::kPreferredSize_Property || | 152 name == mus::mojom::WindowManager::kPreferredSize_Property || |
| 162 name == mus::mojom::WindowManager::kResizeBehavior_Property || | 153 name == mus::mojom::WindowManager::kResizeBehavior_Property || |
| 163 name == mus::mojom::WindowManager::kWindowTitle_Property; | 154 name == mus::mojom::WindowManager::kWindowTitle_Property; |
| 164 } | 155 } |
| 165 | 156 |
| 166 mus::Window* WindowManagerImpl::OnWmCreateTopLevelWindow( | 157 mus::Window* WindowManagerImpl::OnWmCreateTopLevelWindow( |
| 167 std::map<std::string, std::vector<uint8_t>>* properties) { | 158 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 168 return NewTopLevelWindow(properties, nullptr); | 159 return NewTopLevelWindow(properties, nullptr); |
| 169 } | 160 } |
| 170 | 161 |
| 171 } // namespace wm | 162 } // namespace muswm |
| 172 } // namespace mash | 163 } // namespace ash |
| OLD | NEW |