| 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 "mash/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 "components/mus/common/types.h" | 10 #include "components/mus/common/types.h" |
| 11 #include "components/mus/public/cpp/property_type_converters.h" | |
| 12 #include "components/mus/public/cpp/window.h" | 11 #include "components/mus/public/cpp/window.h" |
| 13 #include "components/mus/public/cpp/window_property.h" | 12 #include "components/mus/public/cpp/window_property.h" |
| 14 #include "components/mus/public/cpp/window_tree_connection.h" | 13 #include "components/mus/public/cpp/window_tree_connection.h" |
| 15 #include "components/mus/public/interfaces/input_events.mojom.h" | 14 #include "components/mus/public/interfaces/input_events.mojom.h" |
| 16 #include "components/mus/public/interfaces/mus_constants.mojom.h" | 15 #include "components/mus/public/interfaces/mus_constants.mojom.h" |
| 17 #include "components/mus/public/interfaces/window_manager.mojom.h" | 16 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 18 #include "mash/wm/non_client_frame_controller.h" | 17 #include "mash/wm/non_client_frame_controller.h" |
| 19 #include "mash/wm/property_util.h" | 18 #include "mash/wm/property_util.h" |
| 20 #include "mash/wm/public/interfaces/container.mojom.h" | 19 #include "mash/wm/public/interfaces/container.mojom.h" |
| 21 #include "mash/wm/window_manager_application.h" | 20 #include "mash/wm/window_manager_application.h" |
| 22 #include "mojo/converters/geometry/geometry_type_converters.h" | 21 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 23 #include "mojo/shell/public/cpp/application_impl.h" | 22 #include "mojo/shell/public/cpp/application_impl.h" |
| 24 | 23 |
| 25 namespace mojo { | |
| 26 | |
| 27 template <> | |
| 28 struct TypeConverter<const std::vector<uint8_t>, Array<uint8_t>> { | |
| 29 static const std::vector<uint8_t> Convert(const Array<uint8_t>& input) { | |
| 30 return input.storage(); | |
| 31 } | |
| 32 }; | |
| 33 | |
| 34 } // namespace mojo | |
| 35 | |
| 36 namespace mash { | 24 namespace mash { |
| 37 namespace wm { | 25 namespace wm { |
| 38 | 26 |
| 39 WindowManagerImpl::WindowManagerImpl() | 27 WindowManagerImpl::WindowManagerImpl() |
| 40 : state_(nullptr) {} | 28 : state_(nullptr), window_manager_client_(nullptr) {} |
| 41 | 29 |
| 42 WindowManagerImpl::~WindowManagerImpl() { | 30 WindowManagerImpl::~WindowManagerImpl() { |
| 43 if (!state_) | 31 if (!state_) |
| 44 return; | 32 return; |
| 45 for (auto container : state_->root()->children()) { | 33 for (auto container : state_->root()->children()) { |
| 46 container->RemoveObserver(this); | 34 container->RemoveObserver(this); |
| 47 for (auto child : container->children()) | 35 for (auto child : container->children()) |
| 48 child->RemoveObserver(this); | 36 child->RemoveObserver(this); |
| 49 } | 37 } |
| 50 } | 38 } |
| 51 | 39 |
| 52 void WindowManagerImpl::Initialize(WindowManagerApplication* state) { | 40 void WindowManagerImpl::Initialize(WindowManagerApplication* state) { |
| 53 DCHECK(state); | 41 DCHECK(state); |
| 54 DCHECK(!state_); | 42 DCHECK(!state_); |
| 55 state_ = state; | 43 state_ = state; |
| 56 // The children of the root are considered containers. | 44 // The children of the root are considered containers. |
| 57 for (auto container : state_->root()->children()) { | 45 for (auto container : state_->root()->children()) { |
| 58 container->AddObserver(this); | 46 container->AddObserver(this); |
| 59 for (auto child : container->children()) | 47 for (auto child : container->children()) |
| 60 child->AddObserver(this); | 48 child->AddObserver(this); |
| 61 } | 49 } |
| 50 |
| 51 // The insets are roughly what is needed by CustomFrameView. The expectation |
| 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 = |
| 55 mus::mojom::FrameDecorationValues::New(); |
| 56 const gfx::Insets client_area_insets = |
| 57 NonClientFrameController::GetPreferredClientAreaInsets(); |
| 58 frame_decoration_values->normal_client_area_insets = |
| 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( |
| 65 std::move(frame_decoration_values)); |
| 62 } | 66 } |
| 63 | 67 |
| 64 gfx::Rect WindowManagerImpl::CalculateDefaultBounds(mus::Window* window) const { | 68 gfx::Rect WindowManagerImpl::CalculateDefaultBounds(mus::Window* window) const { |
| 65 DCHECK(state_); | 69 DCHECK(state_); |
| 66 int width, height; | 70 int width, height; |
| 67 const gfx::Size pref = GetWindowPreferredSize(window); | 71 const gfx::Size pref = GetWindowPreferredSize(window); |
| 68 const mus::Window* root = state_->root(); | 72 const mus::Window* root = state_->root(); |
| 69 if (pref.IsEmpty()) { | 73 if (pref.IsEmpty()) { |
| 70 width = root->bounds().width() - 240; | 74 width = root->bounds().width() - 240; |
| 71 height = root->bounds().height() - 240; | 75 height = root->bounds().height() - 240; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 134 } |
| 131 | 135 |
| 132 void WindowManagerImpl::OpenWindow( | 136 void WindowManagerImpl::OpenWindow( |
| 133 mus::mojom::WindowTreeClientPtr client, | 137 mus::mojom::WindowTreeClientPtr client, |
| 134 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 138 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
| 135 mus::Window::SharedProperties properties = | 139 mus::Window::SharedProperties properties = |
| 136 transport_properties.To<mus::Window::SharedProperties>(); | 140 transport_properties.To<mus::Window::SharedProperties>(); |
| 137 NewTopLevelWindow(&properties, std::move(client)); | 141 NewTopLevelWindow(&properties, std::move(client)); |
| 138 } | 142 } |
| 139 | 143 |
| 140 void WindowManagerImpl::GetConfig(const GetConfigCallback& callback) { | 144 void WindowManagerImpl::SetWindowManagerClient( |
| 141 DCHECK(state_); | 145 mus::WindowManagerClient* client) { |
| 142 mus::mojom::WindowManagerConfigPtr config( | 146 window_manager_client_ = client; |
| 143 mus::mojom::WindowManagerConfig::New()); | |
| 144 config->displays = mojo::Array<mus::mojom::DisplayPtr>::New(1); | |
| 145 config->displays[0] = mus::mojom::Display::New(); | |
| 146 config->displays[0]->id = 2001; | |
| 147 config->displays[0]->bounds = mojo::Rect::New(); | |
| 148 config->displays[0]->bounds->y = 0; | |
| 149 config->displays[0]->bounds->width = state_->root()->bounds().width(); | |
| 150 config->displays[0]->bounds->height = state_->root()->bounds().width(); | |
| 151 config->displays[0]->work_area = config->displays[0]->bounds.Clone(); | |
| 152 config->displays[0]->device_pixel_ratio = | |
| 153 state_->root()->viewport_metrics().device_pixel_ratio; | |
| 154 | |
| 155 // The insets are roughly what is needed by CustomFrameView. The expectation | |
| 156 // is at some point we'll write our own NonClientFrameView and get the insets | |
| 157 // from it. | |
| 158 const gfx::Insets client_area_insets = | |
| 159 NonClientFrameController::GetPreferredClientAreaInsets(); | |
| 160 config->normal_client_area_insets = mojo::Insets::From(client_area_insets); | |
| 161 | |
| 162 config->maximized_client_area_insets = mojo::Insets::From(client_area_insets); | |
| 163 | |
| 164 config->max_title_bar_button_width = | |
| 165 NonClientFrameController::GetMaxTitleBarButtonWidth(); | |
| 166 | |
| 167 callback.Run(std::move(config)); | |
| 168 } | 147 } |
| 169 | 148 |
| 170 bool WindowManagerImpl::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { | 149 bool WindowManagerImpl::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { |
| 171 // By returning true the bounds of |window| is updated. | 150 // By returning true the bounds of |window| is updated. |
| 172 return true; | 151 return true; |
| 173 } | 152 } |
| 174 | 153 |
| 175 bool WindowManagerImpl::OnWmSetProperty( | 154 bool WindowManagerImpl::OnWmSetProperty( |
| 176 mus::Window* window, | 155 mus::Window* window, |
| 177 const std::string& name, | 156 const std::string& name, |
| 178 scoped_ptr<std::vector<uint8_t>>* new_data) { | 157 scoped_ptr<std::vector<uint8_t>>* new_data) { |
| 179 // TODO(sky): constrain this to set of keys we know about, and allowed | 158 // TODO(sky): constrain this to set of keys we know about, and allowed |
| 180 // values. | 159 // values. |
| 181 return name == mus::mojom::WindowManager::kShowState_Property || | 160 return name == mus::mojom::WindowManager::kShowState_Property || |
| 182 name == mus::mojom::WindowManager::kPreferredSize_Property || | 161 name == mus::mojom::WindowManager::kPreferredSize_Property || |
| 183 name == mus::mojom::WindowManager::kResizeBehavior_Property || | 162 name == mus::mojom::WindowManager::kResizeBehavior_Property || |
| 184 name == mus::mojom::WindowManager::kWindowTitle_Property; | 163 name == mus::mojom::WindowManager::kWindowTitle_Property; |
| 185 } | 164 } |
| 186 | 165 |
| 187 mus::Window* WindowManagerImpl::OnWmCreateTopLevelWindow( | 166 mus::Window* WindowManagerImpl::OnWmCreateTopLevelWindow( |
| 188 std::map<std::string, std::vector<uint8_t>>* properties) { | 167 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 189 return NewTopLevelWindow(properties, nullptr); | 168 return NewTopLevelWindow(properties, nullptr); |
| 190 } | 169 } |
| 191 | 170 |
| 192 } // namespace wm | 171 } // namespace wm |
| 193 } // namespace mash | 172 } // namespace mash |
| OLD | NEW |