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/move_loop.h" | 7 #include "components/mus/example/wm/move_loop.h" |
| 8 #include "components/mus/example/wm/non_client_frame_controller.h" |
8 #include "components/mus/example/wm/property_util.h" | 9 #include "components/mus/example/wm/property_util.h" |
9 #include "components/mus/example/wm/public/interfaces/container.mojom.h" | 10 #include "components/mus/example/wm/public/interfaces/container.mojom.h" |
10 #include "components/mus/example/wm/window_manager_application.h" | 11 #include "components/mus/example/wm/window_manager_application.h" |
11 #include "components/mus/public/cpp/property_type_converters.h" | 12 #include "components/mus/public/cpp/property_type_converters.h" |
12 #include "components/mus/public/cpp/types.h" | 13 #include "components/mus/public/cpp/types.h" |
13 #include "components/mus/public/cpp/window.h" | 14 #include "components/mus/public/cpp/window.h" |
14 #include "components/mus/public/cpp/window_property.h" | 15 #include "components/mus/public/cpp/window_property.h" |
15 #include "components/mus/public/cpp/window_tree_connection.h" | 16 #include "components/mus/public/cpp/window_tree_connection.h" |
16 #include "components/mus/public/interfaces/input_events.mojom.h" | 17 #include "components/mus/public/interfaces/input_events.mojom.h" |
| 18 #include "mojo/application/public/cpp/application_impl.h" |
17 #include "mojo/converters/geometry/geometry_type_converters.h" | 19 #include "mojo/converters/geometry/geometry_type_converters.h" |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 bool IsPointerEvent(const mus::mojom::Event& event) { | 23 bool IsPointerEvent(const mus::mojom::Event& event) { |
22 return event.action == mus::mojom::EVENT_TYPE_POINTER_CANCEL || | 24 return event.action == mus::mojom::EVENT_TYPE_POINTER_CANCEL || |
23 event.action == mus::mojom::EVENT_TYPE_POINTER_DOWN || | 25 event.action == mus::mojom::EVENT_TYPE_POINTER_DOWN || |
24 event.action == mus::mojom::EVENT_TYPE_POINTER_MOVE || | 26 event.action == mus::mojom::EVENT_TYPE_POINTER_MOVE || |
25 event.action == mus::mojom::EVENT_TYPE_POINTER_UP; | 27 event.action == mus::mojom::EVENT_TYPE_POINTER_UP; |
26 } | 28 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 for (auto prop : properties) | 68 for (auto prop : properties) |
67 child_window->SetSharedProperty(prop.GetKey(), prop.GetValue()); | 69 child_window->SetSharedProperty(prop.GetKey(), prop.GetValue()); |
68 | 70 |
69 gfx::Rect bounds(40 + (state_->window_count() % 4) * 40, | 71 gfx::Rect bounds(40 + (state_->window_count() % 4) * 40, |
70 40 + (state_->window_count() % 4) * 40, width, height); | 72 40 + (state_->window_count() % 4) * 40, width, height); |
71 child_window->SetBounds(bounds); | 73 child_window->SetBounds(bounds); |
72 GetContainerForChild(child_window)->AddChild(child_window); | 74 GetContainerForChild(child_window)->AddChild(child_window); |
73 child_window->Embed(client.Pass()); | 75 child_window->Embed(client.Pass()); |
74 child_window->AddObserver(this); | 76 child_window->AddObserver(this); |
75 | 77 |
| 78 // NonClientFrameController deletes itself when the window is destroyed. |
| 79 new NonClientFrameController(state_->app()->shell(), child_window); |
| 80 |
76 state_->IncrementWindowCount(); | 81 state_->IncrementWindowCount(); |
77 } | 82 } |
78 | 83 |
79 void WindowManagerImpl::SetPreferredSize( | 84 void WindowManagerImpl::SetPreferredSize( |
80 mus::Id window_id, | 85 mus::Id window_id, |
81 mojo::SizePtr size, | 86 mojo::SizePtr size, |
82 const WindowManagerErrorCodeCallback& callback) { | 87 const WindowManagerErrorCodeCallback& callback) { |
83 SetWindowPreferredSize(state_->GetWindowById(window_id), | 88 SetWindowPreferredSize(state_->GetWindowById(window_id), |
84 size.To<gfx::Size>()); | 89 size.To<gfx::Size>()); |
85 | 90 |
(...skipping 12 matching lines...) Expand all Loading... |
98 void WindowManagerImpl::SetShowState( | 103 void WindowManagerImpl::SetShowState( |
99 mus::Id window_id, | 104 mus::Id window_id, |
100 mus::mojom::ShowState show_state, | 105 mus::mojom::ShowState show_state, |
101 const WindowManagerErrorCodeCallback& callback){ | 106 const WindowManagerErrorCodeCallback& callback){ |
102 mus::Window* window = state_->GetWindowById(window_id); | 107 mus::Window* window = state_->GetWindowById(window_id); |
103 window->SetSharedProperty<int32_t>( | 108 window->SetSharedProperty<int32_t>( |
104 mus::mojom::WindowManager::kShowState_Property, show_state); | 109 mus::mojom::WindowManager::kShowState_Property, show_state); |
105 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_SUCCESS); | 110 callback.Run(mus::mojom::WINDOW_MANAGER_ERROR_CODE_SUCCESS); |
106 } | 111 } |
107 | 112 |
108 void WindowManagerImpl::GetDisplays(const GetDisplaysCallback& callback) { | 113 void WindowManagerImpl::GetConfig(const GetConfigCallback& callback) { |
109 mojo::Array<mus::mojom::DisplayPtr> displays(1); | 114 mus::mojom::WindowManagerConfigPtr config( |
110 displays[0] = mus::mojom::Display::New(); | 115 mus::mojom::WindowManagerConfig::New()); |
111 displays[0]->id = 2001; | 116 config->displays = mojo::Array<mus::mojom::DisplayPtr>::New(1); |
112 displays[0]->bounds = mojo::Rect::New(); | 117 config->displays[0] = mus::mojom::Display::New(); |
113 displays[0]->bounds->y = 0; | 118 config->displays[0]->id = 2001; |
114 displays[0]->bounds->width = state_->root()->bounds().width(); | 119 config->displays[0]->bounds = mojo::Rect::New(); |
115 displays[0]->bounds->height = state_->root()->bounds().width(); | 120 config->displays[0]->bounds->y = 0; |
116 displays[0]->work_area = displays[0]->bounds.Clone(); | 121 config->displays[0]->bounds->width = state_->root()->bounds().width(); |
117 displays[0]->device_pixel_ratio = | 122 config->displays[0]->bounds->height = state_->root()->bounds().width(); |
| 123 config->displays[0]->work_area = config->displays[0]->bounds.Clone(); |
| 124 config->displays[0]->device_pixel_ratio = |
118 state_->root()->viewport_metrics().device_pixel_ratio; | 125 state_->root()->viewport_metrics().device_pixel_ratio; |
119 callback.Run(displays.Pass()); | 126 |
| 127 // The insets are roughly what is needed by CustomFrameView. The expectation |
| 128 // is at some point we'll write our own NonClientFrameView and get the insets |
| 129 // from it. |
| 130 config->normal_client_area_insets = mojo::Insets::New(); |
| 131 config->normal_client_area_insets->top = 23; |
| 132 config->normal_client_area_insets->left = 5; |
| 133 config->normal_client_area_insets->right = 5; |
| 134 config->normal_client_area_insets->bottom = 5; |
| 135 |
| 136 config->maximized_client_area_insets = mojo::Insets::New(); |
| 137 config->maximized_client_area_insets->top = 21; |
| 138 config->maximized_client_area_insets->left = 0; |
| 139 config->maximized_client_area_insets->right = 0; |
| 140 config->maximized_client_area_insets->bottom = 0; |
| 141 |
| 142 callback.Run(config.Pass()); |
120 } | 143 } |
121 | 144 |
122 void WindowManagerImpl::OnWindowDestroyed(mus::Window* window) { | 145 void WindowManagerImpl::OnWindowDestroyed(mus::Window* window) { |
123 window->RemoveObserver(this); | 146 window->RemoveObserver(this); |
124 } | 147 } |
125 | 148 |
126 void WindowManagerImpl::OnWindowInputEvent(mus::Window* window, | 149 void WindowManagerImpl::OnWindowInputEvent(mus::Window* window, |
127 const mus::mojom::EventPtr& event) { | 150 const mus::mojom::EventPtr& event) { |
128 if (move_loop_ && IsPointerEvent(*event)) { | 151 if (move_loop_ && IsPointerEvent(*event)) { |
129 if (move_loop_->Move(*event) == MoveLoop::DONE) | 152 if (move_loop_->Move(*event) == MoveLoop::DONE) |
130 move_loop_.reset(); | 153 move_loop_.reset(); |
131 return; | 154 return; |
132 } | 155 } |
133 if (!move_loop_ && event->action == mus::mojom::EVENT_TYPE_POINTER_DOWN) | 156 if (!move_loop_ && event->action == mus::mojom::EVENT_TYPE_POINTER_DOWN) |
134 move_loop_ = MoveLoop::Create(window, *event); | 157 move_loop_ = MoveLoop::Create(window, *event); |
135 } | 158 } |
136 | 159 |
137 mus::Window* WindowManagerImpl::GetContainerForChild(mus::Window* child) { | 160 mus::Window* WindowManagerImpl::GetContainerForChild(mus::Window* child) { |
138 ash::mojom::Container container = GetRequestedContainer(child); | 161 ash::mojom::Container container = GetRequestedContainer(child); |
139 return state_->GetWindowForContainer(container); | 162 return state_->GetWindowForContainer(container); |
140 } | 163 } |
OLD | NEW |