| 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 "components/mus/example/wm/window_manager_impl.h" | 5 #include "components/mus/example/wm/window_manager_impl.h" |
| 6 | 6 |
| 7 #include "components/mus/example/wm/container.h" | 7 #include "components/mus/example/wm/container.h" |
| 8 #include "components/mus/example/wm/window_manager_application.h" | 8 #include "components/mus/example/wm/window_manager_application.h" |
| 9 #include "components/mus/public/cpp/property_type_converters.h" | 9 #include "components/mus/public/cpp/property_type_converters.h" |
| 10 #include "components/mus/public/cpp/types.h" | 10 #include "components/mus/public/cpp/types.h" |
| 11 #include "components/mus/public/cpp/window.h" | 11 #include "components/mus/public/cpp/window.h" |
| 12 #include "components/mus/public/cpp/window_property.h" | 12 #include "components/mus/public/cpp/window_property.h" |
| 13 #include "components/mus/public/cpp/window_tree_connection.h" | 13 #include "components/mus/public/cpp/window_tree_connection.h" |
| 14 | 14 |
| 15 WindowManagerImpl::WindowManagerImpl( | 15 WindowManagerImpl::WindowManagerImpl(WindowManagerApplication* state) |
| 16 WindowManagerApplication* state, | 16 : state_(state) {} |
| 17 mojo::InterfaceRequest<mus::mojom::WindowManager> request) | |
| 18 : state_(state), | |
| 19 binding_(this, request.Pass()) { | |
| 20 } | |
| 21 | 17 |
| 22 WindowManagerImpl::~WindowManagerImpl() {} | 18 WindowManagerImpl::~WindowManagerImpl() {} |
| 23 | 19 |
| 24 void WindowManagerImpl::OpenWindow(mus::mojom::WindowTreeClientPtr client) { | 20 void WindowManagerImpl::OpenWindow(mus::mojom::WindowTreeClientPtr client) { |
| 25 mus::Window* root = state_->root(); | 21 mus::Window* root = state_->root(); |
| 26 DCHECK(root); | 22 DCHECK(root); |
| 27 | 23 |
| 28 const int width = (root->bounds().width - 240); | 24 const int width = (root->bounds().width - 240); |
| 29 const int height = (root->bounds().height - 240); | 25 const int height = (root->bounds().height - 240); |
| 30 | 26 |
| 31 mus::Window* child_window = root->connection()->NewWindow(); | 27 mus::Window* child_window = root->connection()->NewWindow(); |
| 32 windows_.insert(child_window->id()); | |
| 33 mojo::Rect bounds; | 28 mojo::Rect bounds; |
| 34 bounds.x = 40 + (state_->window_count() % 4) * 40; | 29 bounds.x = 40 + (state_->window_count() % 4) * 40; |
| 35 bounds.y = 40 + (state_->window_count() % 4) * 40; | 30 bounds.y = 40 + (state_->window_count() % 4) * 40; |
| 36 bounds.width = width; | 31 bounds.width = width; |
| 37 bounds.height = height; | 32 bounds.height = height; |
| 38 child_window->SetBounds(bounds); | 33 child_window->SetBounds(bounds); |
| 39 state_->GetWindowForContainer(Container::USER_WINDOWS) | 34 state_->GetWindowForContainer(Container::USER_WINDOWS) |
| 40 ->AddChild(child_window); | 35 ->AddChild(child_window); |
| 41 child_window->Embed(client.Pass()); | 36 child_window->Embed(client.Pass()); |
| 42 | 37 |
| 43 state_->IncrementWindowCount(); | 38 state_->IncrementWindowCount(); |
| 44 } | 39 } |
| 45 | 40 |
| 46 void WindowManagerImpl::SetPreferredSize( | 41 void WindowManagerImpl::SetPreferredSize( |
| 47 mus::Id window_id, | 42 mus::Id window_id, |
| 48 mojo::SizePtr size, | 43 mojo::SizePtr size, |
| 49 const WindowManagerErrorCodeCallback& callback) { | 44 const WindowManagerErrorCodeCallback& callback) { |
| 50 if (windows_.count(window_id) == 0) { | |
| 51 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_ERROR_ACCESS_DENIED); | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 mus::Window* window = state_->GetWindowById(window_id); | 45 mus::Window* window = state_->GetWindowById(window_id); |
| 56 window->SetSharedProperty<mojo::Size>( | 46 window->SetSharedProperty<mojo::Size>( |
| 57 mus::mojom::WindowManager::kPreferredSize_Property, *size); | 47 mus::mojom::WindowManager::kPreferredSize_Property, *size); |
| 58 | 48 |
| 59 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_SUCCESS); | 49 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_SUCCESS); |
| 60 } | 50 } |
| 61 | 51 |
| 62 void WindowManagerImpl::SetBounds( | 52 void WindowManagerImpl::SetBounds( |
| 63 mus::Id window_id, | 53 mus::Id window_id, |
| 64 mojo::RectPtr bounds, | 54 mojo::RectPtr bounds, |
| 65 const WindowManagerErrorCodeCallback& callback) { | 55 const WindowManagerErrorCodeCallback& callback) { |
| 66 if (windows_.count(window_id) == 0) { | |
| 67 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_ERROR_ACCESS_DENIED); | |
| 68 return; | |
| 69 } | |
| 70 | |
| 71 mus::Window* window = state_->root()->GetChildById(window_id); | 56 mus::Window* window = state_->root()->GetChildById(window_id); |
| 72 window->SetBounds(*bounds); | 57 window->SetBounds(*bounds); |
| 73 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_SUCCESS); | 58 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_SUCCESS); |
| 74 } | 59 } |
| 75 | 60 |
| 76 void WindowManagerImpl::SetShowState( | 61 void WindowManagerImpl::SetShowState( |
| 77 mus::Id window_id, | 62 mus::Id window_id, |
| 78 mus::mojom::ShowState show_state, | 63 mus::mojom::ShowState show_state, |
| 79 const WindowManagerErrorCodeCallback& callback){ | 64 const WindowManagerErrorCodeCallback& callback){ |
| 80 if (windows_.count(window_id) == 0) { | |
| 81 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_ERROR_ACCESS_DENIED); | |
| 82 return; | |
| 83 } | |
| 84 | |
| 85 mus::Window* window = state_->GetWindowById(window_id); | 65 mus::Window* window = state_->GetWindowById(window_id); |
| 86 window->SetSharedProperty<int32_t>( | 66 window->SetSharedProperty<int32_t>( |
| 87 mus::mojom::WindowManager::kShowState_Property, show_state); | 67 mus::mojom::WindowManager::kShowState_Property, show_state); |
| 88 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_SUCCESS); | 68 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_SUCCESS); |
| 89 } | 69 } |
| 90 | 70 |
| 91 void WindowManagerImpl::GetDisplays(const GetDisplaysCallback& callback) { | 71 void WindowManagerImpl::GetDisplays(const GetDisplaysCallback& callback) { |
| 92 mojo::Array<mus::mojom::DisplayPtr> displays(1); | 72 mojo::Array<mus::mojom::DisplayPtr> displays(1); |
| 93 displays[0] = mus::mojom::Display::New(); | 73 displays[0] = mus::mojom::Display::New(); |
| 94 displays[0]->id = 2001; | 74 displays[0]->id = 2001; |
| 95 displays[0]->bounds = mojo::Rect::New(); | 75 displays[0]->bounds = mojo::Rect::New(); |
| 96 displays[0]->bounds->y = 0; | 76 displays[0]->bounds->y = 0; |
| 97 displays[0]->bounds->width = state_->root()->bounds().width; | 77 displays[0]->bounds->width = state_->root()->bounds().width; |
| 98 displays[0]->bounds->height = state_->root()->bounds().width; | 78 displays[0]->bounds->height = state_->root()->bounds().width; |
| 99 displays[0]->work_area = displays[0]->bounds.Clone(); | 79 displays[0]->work_area = displays[0]->bounds.Clone(); |
| 100 displays[0]->device_pixel_ratio = | 80 displays[0]->device_pixel_ratio = |
| 101 state_->root()->viewport_metrics().device_pixel_ratio; | 81 state_->root()->viewport_metrics().device_pixel_ratio; |
| 102 callback.Run(displays.Pass()); | 82 callback.Run(displays.Pass()); |
| 103 } | 83 } |
| 104 | |
| 105 void WindowManagerImpl::OnWindowDestroyed(mus::Window* window) { | |
| 106 auto it = std::find(windows_.begin(), windows_.end(), window->id()); | |
| 107 DCHECK(it != windows_.end()); | |
| 108 windows_.erase(it); | |
| 109 } | |
| OLD | NEW |