| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/public/cpp/lib/window_tree_client_impl.h" | 5 #include "components/mus/public/cpp/window_tree_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "components/mus/common/util.h" | 15 #include "components/mus/common/util.h" |
| 16 #include "components/mus/public/cpp/input_event_handler.h" | 16 #include "components/mus/public/cpp/input_event_handler.h" |
| 17 #include "components/mus/public/cpp/lib/in_flight_change.h" | 17 #include "components/mus/public/cpp/lib/in_flight_change.h" |
| 18 #include "components/mus/public/cpp/lib/window_private.h" | 18 #include "components/mus/public/cpp/lib/window_private.h" |
| 19 #include "components/mus/public/cpp/window_manager_delegate.h" | 19 #include "components/mus/public/cpp/window_manager_delegate.h" |
| 20 #include "components/mus/public/cpp/window_observer.h" | 20 #include "components/mus/public/cpp/window_observer.h" |
| 21 #include "components/mus/public/cpp/window_tracker.h" | 21 #include "components/mus/public/cpp/window_tracker.h" |
| 22 #include "components/mus/public/cpp/window_tree_connection.h" | 22 #include "components/mus/public/cpp/window_tree_client_delegate.h" |
| 23 #include "components/mus/public/cpp/window_tree_connection_observer.h" | 23 #include "components/mus/public/cpp/window_tree_client_observer.h" |
| 24 #include "components/mus/public/cpp/window_tree_delegate.h" | |
| 25 #include "services/shell/public/cpp/connector.h" | 24 #include "services/shell/public/cpp/connector.h" |
| 26 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
| 27 #include "ui/events/mojo/input_events_type_converters.h" | 26 #include "ui/events/mojo/input_events_type_converters.h" |
| 28 #include "ui/gfx/geometry/insets.h" | 27 #include "ui/gfx/geometry/insets.h" |
| 29 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
| 30 | 29 |
| 31 namespace mus { | 30 namespace mus { |
| 32 | 31 |
| 33 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { | 32 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { |
| 34 return (client_id << 16) | local_id; | 33 return (client_id << 16) | local_id; |
| 35 } | 34 } |
| 36 | 35 |
| 37 Id server_id(Window* window) { | 36 Id server_id(Window* window) { |
| 38 return WindowPrivate(window).server_id(); | 37 return WindowPrivate(window).server_id(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 // Helper called to construct a local window object from transport data. | 40 // Helper called to construct a local window object from transport data. |
| 42 Window* AddWindowToClient(WindowTreeClientImpl* client, | 41 Window* AddWindowToClient(WindowTreeClient* client, |
| 43 Window* parent, | 42 Window* parent, |
| 44 const mojom::WindowDataPtr& window_data) { | 43 const mojom::WindowDataPtr& window_data) { |
| 45 // We don't use the ctor that takes a WindowTreeConnection here, since it | 44 // We don't use the ctor that takes a WindowTreeClient here, since it will |
| 46 // will call back to the service and attempt to create a new window. | 45 // call back to the service and attempt to create a new window. |
| 47 Window* window = WindowPrivate::LocalCreate(); | 46 Window* window = WindowPrivate::LocalCreate(); |
| 48 WindowPrivate private_window(window); | 47 WindowPrivate private_window(window); |
| 49 private_window.set_connection(client); | 48 private_window.set_client(client); |
| 50 private_window.set_server_id(window_data->window_id); | 49 private_window.set_server_id(window_data->window_id); |
| 51 private_window.set_visible(window_data->visible); | 50 private_window.set_visible(window_data->visible); |
| 52 private_window.set_properties( | 51 private_window.set_properties( |
| 53 window_data->properties | 52 window_data->properties |
| 54 .To<std::map<std::string, std::vector<uint8_t>>>()); | 53 .To<std::map<std::string, std::vector<uint8_t>>>()); |
| 55 client->AddWindow(window); | 54 client->AddWindow(window); |
| 56 private_window.LocalSetBounds(gfx::Rect(), window_data->bounds); | 55 private_window.LocalSetBounds(gfx::Rect(), window_data->bounds); |
| 57 if (parent) | 56 if (parent) |
| 58 WindowPrivate(parent).LocalAddChild(window); | 57 WindowPrivate(parent).LocalAddChild(window); |
| 59 return window; | 58 return window; |
| 60 } | 59 } |
| 61 | 60 |
| 62 Window* BuildWindowTree(WindowTreeClientImpl* client, | 61 Window* BuildWindowTree(WindowTreeClient* client, |
| 63 const mojo::Array<mojom::WindowDataPtr>& windows, | 62 const mojo::Array<mojom::WindowDataPtr>& windows, |
| 64 Window* initial_parent) { | 63 Window* initial_parent) { |
| 65 std::vector<Window*> parents; | 64 std::vector<Window*> parents; |
| 66 Window* root = NULL; | 65 Window* root = NULL; |
| 67 Window* last_window = NULL; | 66 Window* last_window = NULL; |
| 68 if (initial_parent) | 67 if (initial_parent) |
| 69 parents.push_back(initial_parent); | 68 parents.push_back(initial_parent); |
| 70 for (size_t i = 0; i < windows.size(); ++i) { | 69 for (size_t i = 0; i < windows.size(); ++i) { |
| 71 if (last_window && windows[i]->parent_id == server_id(last_window)) { | 70 if (last_window && windows[i]->parent_id == server_id(last_window)) { |
| 72 parents.push_back(last_window); | 71 parents.push_back(last_window); |
| 73 } else if (!parents.empty()) { | 72 } else if (!parents.empty()) { |
| 74 while (server_id(parents.back()) != windows[i]->parent_id) | 73 while (server_id(parents.back()) != windows[i]->parent_id) |
| 75 parents.pop_back(); | 74 parents.pop_back(); |
| 76 } | 75 } |
| 77 Window* window = AddWindowToClient( | 76 Window* window = AddWindowToClient( |
| 78 client, !parents.empty() ? parents.back() : NULL, windows[i]); | 77 client, !parents.empty() ? parents.back() : NULL, windows[i]); |
| 79 if (!last_window) | 78 if (!last_window) |
| 80 root = window; | 79 root = window; |
| 81 last_window = window; | 80 last_window = window; |
| 82 } | 81 } |
| 83 return root; | 82 return root; |
| 84 } | 83 } |
| 85 | 84 |
| 86 WindowTreeConnection* WindowTreeConnection::Create( | 85 WindowTreeClient::WindowTreeClient( |
| 87 WindowTreeDelegate* delegate, | 86 WindowTreeClientDelegate* delegate, |
| 88 shell::Connector* connector) { | |
| 89 WindowTreeClientImpl* client = | |
| 90 new WindowTreeClientImpl(delegate, nullptr, nullptr); | |
| 91 client->ConnectViaWindowTreeFactory(connector); | |
| 92 return client; | |
| 93 } | |
| 94 | |
| 95 WindowTreeConnection* WindowTreeConnection::Create( | |
| 96 WindowTreeDelegate* delegate, | |
| 97 mojo::InterfaceRequest<mojom::WindowTreeClient> request, | |
| 98 CreateType create_type) { | |
| 99 WindowTreeClientImpl* client = | |
| 100 new WindowTreeClientImpl(delegate, nullptr, std::move(request)); | |
| 101 if (create_type == CreateType::WAIT_FOR_EMBED) | |
| 102 client->WaitForEmbed(); | |
| 103 return client; | |
| 104 } | |
| 105 | |
| 106 WindowTreeConnection* WindowTreeConnection::CreateForWindowManager( | |
| 107 WindowTreeDelegate* delegate, | |
| 108 mojo::InterfaceRequest<mojom::WindowTreeClient> request, | |
| 109 CreateType create_type, | |
| 110 WindowManagerDelegate* window_manager_delegate) { | |
| 111 WindowTreeClientImpl* client = new WindowTreeClientImpl( | |
| 112 delegate, window_manager_delegate, std::move(request)); | |
| 113 if (create_type == CreateType::WAIT_FOR_EMBED) | |
| 114 client->WaitForEmbed(); | |
| 115 return client; | |
| 116 } | |
| 117 | |
| 118 WindowTreeClientImpl::WindowTreeClientImpl( | |
| 119 WindowTreeDelegate* delegate, | |
| 120 WindowManagerDelegate* window_manager_delegate, | 87 WindowManagerDelegate* window_manager_delegate, |
| 121 mojo::InterfaceRequest<mojom::WindowTreeClient> request) | 88 mojo::InterfaceRequest<mojom::WindowTreeClient> request) |
| 122 : client_id_(0), | 89 : client_id_(0), |
| 123 next_window_id_(1), | 90 next_window_id_(1), |
| 124 next_change_id_(1), | 91 next_change_id_(1), |
| 125 delegate_(delegate), | 92 delegate_(delegate), |
| 126 window_manager_delegate_(window_manager_delegate), | 93 window_manager_delegate_(window_manager_delegate), |
| 127 capture_window_(nullptr), | 94 capture_window_(nullptr), |
| 128 focused_window_(nullptr), | 95 focused_window_(nullptr), |
| 129 binding_(this), | 96 binding_(this), |
| 130 tree_(nullptr), | 97 tree_(nullptr), |
| 131 delete_on_no_roots_(true), | 98 delete_on_no_roots_(true), |
| 132 in_destructor_(false), | 99 in_destructor_(false), |
| 133 cursor_location_memory_(nullptr), | 100 cursor_location_memory_(nullptr), |
| 134 weak_factory_(this) { | 101 weak_factory_(this) { |
| 135 // Allow for a null request in tests. | 102 // Allow for a null request in tests. |
| 136 if (request.is_pending()) | 103 if (request.is_pending()) |
| 137 binding_.Bind(std::move(request)); | 104 binding_.Bind(std::move(request)); |
| 138 if (window_manager_delegate) | 105 if (window_manager_delegate) |
| 139 window_manager_delegate->SetWindowManagerClient(this); | 106 window_manager_delegate->SetWindowManagerClient(this); |
| 140 } | 107 } |
| 141 | 108 |
| 142 WindowTreeClientImpl::~WindowTreeClientImpl() { | 109 WindowTreeClient::~WindowTreeClient() { |
| 143 in_destructor_ = true; | 110 in_destructor_ = true; |
| 144 | 111 |
| 145 std::vector<Window*> non_owned; | 112 std::vector<Window*> non_owned; |
| 146 WindowTracker tracker; | 113 WindowTracker tracker; |
| 147 while (!windows_.empty()) { | 114 while (!windows_.empty()) { |
| 148 IdToWindowMap::iterator it = windows_.begin(); | 115 IdToWindowMap::iterator it = windows_.begin(); |
| 149 if (OwnsWindow(it->second)) { | 116 if (OwnsWindow(it->second)) { |
| 150 it->second->Destroy(); | 117 it->second->Destroy(); |
| 151 } else { | 118 } else { |
| 152 tracker.Add(it->second); | 119 tracker.Add(it->second); |
| 153 windows_.erase(it); | 120 windows_.erase(it); |
| 154 } | 121 } |
| 155 } | 122 } |
| 156 | 123 |
| 157 // Delete the non-owned windows last. In the typical case these are roots. The | 124 // Delete the non-owned windows last. In the typical case these are roots. The |
| 158 // exception is the window manager and embed roots, which may know about | 125 // exception is the window manager and embed roots, which may know about |
| 159 // other random windows that it doesn't own. | 126 // other random windows that it doesn't own. |
| 160 // NOTE: we manually delete as we're a friend. | 127 // NOTE: we manually delete as we're a friend. |
| 161 while (!tracker.windows().empty()) | 128 while (!tracker.windows().empty()) |
| 162 delete tracker.windows().front(); | 129 delete tracker.windows().front(); |
| 163 | 130 |
| 164 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, | 131 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, |
| 165 OnWillDestroyConnection(this)); | 132 OnWillDestroyClient(this)); |
| 166 | 133 |
| 167 delegate_->OnConnectionLost(this); | 134 delegate_->OnWindowTreeClientDestroyed(this); |
| 168 } | 135 } |
| 169 | 136 |
| 170 void WindowTreeClientImpl::ConnectViaWindowTreeFactory( | 137 void WindowTreeClient::ConnectViaWindowTreeFactory( |
| 171 shell::Connector* connector) { | 138 shell::Connector* connector) { |
| 172 // Clients created with no root shouldn't delete automatically. | 139 // Clients created with no root shouldn't delete automatically. |
| 173 delete_on_no_roots_ = false; | 140 delete_on_no_roots_ = false; |
| 174 | 141 |
| 175 // The client id doesn't really matter, we use 101 purely for debugging. | 142 // The client id doesn't really matter, we use 101 purely for debugging. |
| 176 client_id_ = 101; | 143 client_id_ = 101; |
| 177 | 144 |
| 178 mojom::WindowTreeFactoryPtr factory; | 145 mojom::WindowTreeFactoryPtr factory; |
| 179 connector->ConnectToInterface("mojo:mus", &factory); | 146 connector->ConnectToInterface("mojo:mus", &factory); |
| 180 factory->CreateWindowTree(GetProxy(&tree_ptr_), | 147 factory->CreateWindowTree(GetProxy(&tree_ptr_), |
| 181 binding_.CreateInterfacePtrAndBind()); | 148 binding_.CreateInterfacePtrAndBind()); |
| 182 tree_ = tree_ptr_.get(); | 149 tree_ = tree_ptr_.get(); |
| 183 | 150 |
| 184 tree_ptr_->GetCursorLocationMemory( | 151 tree_ptr_->GetCursorLocationMemory( |
| 185 base::Bind(&WindowTreeClientImpl::OnReceivedCursorLocationMemory, | 152 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, |
| 186 weak_factory_.GetWeakPtr())); | 153 weak_factory_.GetWeakPtr())); |
| 187 } | 154 } |
| 188 | 155 |
| 189 void WindowTreeClientImpl::WaitForEmbed() { | 156 void WindowTreeClient::WaitForEmbed() { |
| 190 DCHECK(roots_.empty()); | 157 DCHECK(roots_.empty()); |
| 191 // OnEmbed() is the first function called. | 158 // OnEmbed() is the first function called. |
| 192 binding_.WaitForIncomingMethodCall(); | 159 binding_.WaitForIncomingMethodCall(); |
| 193 // TODO(sky): deal with pipe being closed before we get OnEmbed(). | 160 // TODO(sky): deal with pipe being closed before we get OnEmbed(). |
| 194 } | 161 } |
| 195 | 162 |
| 196 void WindowTreeClientImpl::DestroyWindow(Window* window) { | 163 void WindowTreeClient::DestroyWindow(Window* window) { |
| 197 DCHECK(tree_); | 164 DCHECK(tree_); |
| 198 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( | 165 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( |
| 199 new CrashInFlightChange(window, ChangeType::DELETE_WINDOW))); | 166 new CrashInFlightChange(window, ChangeType::DELETE_WINDOW))); |
| 200 tree_->DeleteWindow(change_id, server_id(window)); | 167 tree_->DeleteWindow(change_id, server_id(window)); |
| 201 } | 168 } |
| 202 | 169 |
| 203 void WindowTreeClientImpl::AddChild(Window* parent, Id child_id) { | 170 void WindowTreeClient::AddChild(Window* parent, Id child_id) { |
| 204 DCHECK(tree_); | 171 DCHECK(tree_); |
| 205 const uint32_t change_id = ScheduleInFlightChange( | 172 const uint32_t change_id = ScheduleInFlightChange( |
| 206 base::WrapUnique(new CrashInFlightChange(parent, ChangeType::ADD_CHILD))); | 173 base::WrapUnique(new CrashInFlightChange(parent, ChangeType::ADD_CHILD))); |
| 207 tree_->AddWindow(change_id, parent->server_id(), child_id); | 174 tree_->AddWindow(change_id, parent->server_id(), child_id); |
| 208 } | 175 } |
| 209 | 176 |
| 210 void WindowTreeClientImpl::RemoveChild(Window* parent, Id child_id) { | 177 void WindowTreeClient::RemoveChild(Window* parent, Id child_id) { |
| 211 DCHECK(tree_); | 178 DCHECK(tree_); |
| 212 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( | 179 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( |
| 213 new CrashInFlightChange(parent, ChangeType::REMOVE_CHILD))); | 180 new CrashInFlightChange(parent, ChangeType::REMOVE_CHILD))); |
| 214 tree_->RemoveWindowFromParent(change_id, child_id); | 181 tree_->RemoveWindowFromParent(change_id, child_id); |
| 215 } | 182 } |
| 216 | 183 |
| 217 void WindowTreeClientImpl::AddTransientWindow(Window* window, | 184 void WindowTreeClient::AddTransientWindow(Window* window, |
| 218 Id transient_window_id) { | 185 Id transient_window_id) { |
| 219 DCHECK(tree_); | 186 DCHECK(tree_); |
| 220 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( | 187 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( |
| 221 new CrashInFlightChange(window, ChangeType::ADD_TRANSIENT_WINDOW))); | 188 new CrashInFlightChange(window, ChangeType::ADD_TRANSIENT_WINDOW))); |
| 222 tree_->AddTransientWindow(change_id, server_id(window), transient_window_id); | 189 tree_->AddTransientWindow(change_id, server_id(window), transient_window_id); |
| 223 } | 190 } |
| 224 | 191 |
| 225 void WindowTreeClientImpl::RemoveTransientWindowFromParent(Window* window) { | 192 void WindowTreeClient::RemoveTransientWindowFromParent(Window* window) { |
| 226 DCHECK(tree_); | 193 DCHECK(tree_); |
| 227 const uint32_t change_id = | 194 const uint32_t change_id = |
| 228 ScheduleInFlightChange(base::WrapUnique(new CrashInFlightChange( | 195 ScheduleInFlightChange(base::WrapUnique(new CrashInFlightChange( |
| 229 window, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT))); | 196 window, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT))); |
| 230 tree_->RemoveTransientWindowFromParent(change_id, server_id(window)); | 197 tree_->RemoveTransientWindowFromParent(change_id, server_id(window)); |
| 231 } | 198 } |
| 232 | 199 |
| 233 void WindowTreeClientImpl::SetModal(Window* window) { | 200 void WindowTreeClient::SetModal(Window* window) { |
| 234 DCHECK(tree_); | 201 DCHECK(tree_); |
| 235 const uint32_t change_id = ScheduleInFlightChange( | 202 const uint32_t change_id = ScheduleInFlightChange( |
| 236 base::WrapUnique(new InFlightSetModalChange(window))); | 203 base::WrapUnique(new InFlightSetModalChange(window))); |
| 237 tree_->SetModal(change_id, server_id(window)); | 204 tree_->SetModal(change_id, server_id(window)); |
| 238 } | 205 } |
| 239 | 206 |
| 240 void WindowTreeClientImpl::Reorder(Window* window, | 207 void WindowTreeClient::Reorder(Window* window, |
| 241 Id relative_window_id, | 208 Id relative_window_id, |
| 242 mojom::OrderDirection direction) { | 209 mojom::OrderDirection direction) { |
| 243 DCHECK(tree_); | 210 DCHECK(tree_); |
| 244 const uint32_t change_id = ScheduleInFlightChange( | 211 const uint32_t change_id = ScheduleInFlightChange( |
| 245 base::WrapUnique(new CrashInFlightChange(window, ChangeType::REORDER))); | 212 base::WrapUnique(new CrashInFlightChange(window, ChangeType::REORDER))); |
| 246 tree_->ReorderWindow(change_id, server_id(window), relative_window_id, | 213 tree_->ReorderWindow(change_id, server_id(window), relative_window_id, |
| 247 direction); | 214 direction); |
| 248 } | 215 } |
| 249 | 216 |
| 250 bool WindowTreeClientImpl::OwnsWindow(Window* window) const { | 217 bool WindowTreeClient::OwnsWindow(Window* window) const { |
| 251 // Windows created via CreateTopLevelWindow() are not owned by us, but have | 218 // Windows created via CreateTopLevelWindow() are not owned by us, but have |
| 252 // our client id. | 219 // our client id. |
| 253 return HiWord(server_id(window)) == client_id_ && | 220 return HiWord(server_id(window)) == client_id_ && |
| 254 roots_.count(window) == 0; | 221 roots_.count(window) == 0; |
| 255 } | 222 } |
| 256 | 223 |
| 257 void WindowTreeClientImpl::SetBounds(Window* window, | 224 void WindowTreeClient::SetBounds(Window* window, |
| 258 const gfx::Rect& old_bounds, | 225 const gfx::Rect& old_bounds, |
| 259 const gfx::Rect& bounds) { | 226 const gfx::Rect& bounds) { |
| 260 DCHECK(tree_); | 227 DCHECK(tree_); |
| 261 const uint32_t change_id = ScheduleInFlightChange( | 228 const uint32_t change_id = ScheduleInFlightChange( |
| 262 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); | 229 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); |
| 263 tree_->SetWindowBounds(change_id, server_id(window), bounds); | 230 tree_->SetWindowBounds(change_id, server_id(window), bounds); |
| 264 } | 231 } |
| 265 | 232 |
| 266 void WindowTreeClientImpl::SetCapture(Window* window) { | 233 void WindowTreeClient::SetCapture(Window* window) { |
| 267 // In order for us to get here we had to have exposed a window, which implies | 234 // In order for us to get here we had to have exposed a window, which implies |
| 268 // we got a client. | 235 // we got a client. |
| 269 DCHECK(tree_); | 236 DCHECK(tree_); |
| 270 if (capture_window_ == window) | 237 if (capture_window_ == window) |
| 271 return; | 238 return; |
| 272 const uint32_t change_id = ScheduleInFlightChange( | 239 const uint32_t change_id = ScheduleInFlightChange( |
| 273 base::WrapUnique(new InFlightCaptureChange(this, capture_window_))); | 240 base::WrapUnique(new InFlightCaptureChange(this, capture_window_))); |
| 274 tree_->SetCapture(change_id, server_id(window)); | 241 tree_->SetCapture(change_id, server_id(window)); |
| 275 LocalSetCapture(window); | 242 LocalSetCapture(window); |
| 276 } | 243 } |
| 277 | 244 |
| 278 void WindowTreeClientImpl::ReleaseCapture(Window* window) { | 245 void WindowTreeClient::ReleaseCapture(Window* window) { |
| 279 // In order for us to get here we had to have exposed a window, which implies | 246 // In order for us to get here we had to have exposed a window, which implies |
| 280 // we got a client. | 247 // we got a client. |
| 281 DCHECK(tree_); | 248 DCHECK(tree_); |
| 282 if (capture_window_ != window) | 249 if (capture_window_ != window) |
| 283 return; | 250 return; |
| 284 const uint32_t change_id = ScheduleInFlightChange( | 251 const uint32_t change_id = ScheduleInFlightChange( |
| 285 base::WrapUnique(new InFlightCaptureChange(this, window))); | 252 base::WrapUnique(new InFlightCaptureChange(this, window))); |
| 286 tree_->ReleaseCapture(change_id, server_id(window)); | 253 tree_->ReleaseCapture(change_id, server_id(window)); |
| 287 LocalSetCapture(nullptr); | 254 LocalSetCapture(nullptr); |
| 288 } | 255 } |
| 289 | 256 |
| 290 void WindowTreeClientImpl::SetClientArea( | 257 void WindowTreeClient::SetClientArea( |
| 291 Id window_id, | 258 Id window_id, |
| 292 const gfx::Insets& client_area, | 259 const gfx::Insets& client_area, |
| 293 const std::vector<gfx::Rect>& additional_client_areas) { | 260 const std::vector<gfx::Rect>& additional_client_areas) { |
| 294 DCHECK(tree_); | 261 DCHECK(tree_); |
| 295 tree_->SetClientArea(window_id, client_area, additional_client_areas); | 262 tree_->SetClientArea(window_id, client_area, additional_client_areas); |
| 296 } | 263 } |
| 297 | 264 |
| 298 void WindowTreeClientImpl::SetHitTestMask(Id window_id, const gfx::Rect& mask) { | 265 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { |
| 299 DCHECK(tree_); | 266 DCHECK(tree_); |
| 300 tree_->SetHitTestMask(window_id, mask); | 267 tree_->SetHitTestMask(window_id, mask); |
| 301 } | 268 } |
| 302 | 269 |
| 303 void WindowTreeClientImpl::ClearHitTestMask(Id window_id) { | 270 void WindowTreeClient::ClearHitTestMask(Id window_id) { |
| 304 DCHECK(tree_); | 271 DCHECK(tree_); |
| 305 tree_->SetHitTestMask(window_id, {}); | 272 tree_->SetHitTestMask(window_id, {}); |
| 306 } | 273 } |
| 307 | 274 |
| 308 void WindowTreeClientImpl::SetFocus(Window* window) { | 275 void WindowTreeClient::SetFocus(Window* window) { |
| 309 // In order for us to get here we had to have exposed a window, which implies | 276 // In order for us to get here we had to have exposed a window, which implies |
| 310 // we got a client. | 277 // we got a client. |
| 311 DCHECK(tree_); | 278 DCHECK(tree_); |
| 312 const uint32_t change_id = ScheduleInFlightChange( | 279 const uint32_t change_id = ScheduleInFlightChange( |
| 313 base::WrapUnique(new InFlightFocusChange(this, focused_window_))); | 280 base::WrapUnique(new InFlightFocusChange(this, focused_window_))); |
| 314 tree_->SetFocus(change_id, window ? server_id(window) : 0); | 281 tree_->SetFocus(change_id, window ? server_id(window) : 0); |
| 315 LocalSetFocus(window); | 282 LocalSetFocus(window); |
| 316 } | 283 } |
| 317 | 284 |
| 318 void WindowTreeClientImpl::SetCanFocus(Id window_id, bool can_focus) { | 285 void WindowTreeClient::SetCanFocus(Id window_id, bool can_focus) { |
| 319 DCHECK(tree_); | 286 DCHECK(tree_); |
| 320 tree_->SetCanFocus(window_id, can_focus); | 287 tree_->SetCanFocus(window_id, can_focus); |
| 321 } | 288 } |
| 322 | 289 |
| 323 void WindowTreeClientImpl::SetPredefinedCursor(Id window_id, | 290 void WindowTreeClient::SetPredefinedCursor(Id window_id, |
| 324 mus::mojom::Cursor cursor_id) { | 291 mus::mojom::Cursor cursor_id) { |
| 325 DCHECK(tree_); | 292 DCHECK(tree_); |
| 326 | 293 |
| 327 Window* window = GetWindowByServerId(window_id); | 294 Window* window = GetWindowByServerId(window_id); |
| 328 if (!window) | 295 if (!window) |
| 329 return; | 296 return; |
| 330 | 297 |
| 331 // We make an inflight change thing here. | 298 // We make an inflight change thing here. |
| 332 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( | 299 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( |
| 333 new InFlightPredefinedCursorChange(window, window->predefined_cursor()))); | 300 new InFlightPredefinedCursorChange(window, window->predefined_cursor()))); |
| 334 tree_->SetPredefinedCursor(change_id, window_id, cursor_id); | 301 tree_->SetPredefinedCursor(change_id, window_id, cursor_id); |
| 335 } | 302 } |
| 336 | 303 |
| 337 void WindowTreeClientImpl::SetVisible(Window* window, bool visible) { | 304 void WindowTreeClient::SetVisible(Window* window, bool visible) { |
| 338 DCHECK(tree_); | 305 DCHECK(tree_); |
| 339 const uint32_t change_id = ScheduleInFlightChange( | 306 const uint32_t change_id = ScheduleInFlightChange( |
| 340 base::WrapUnique(new InFlightVisibleChange(window, !visible))); | 307 base::WrapUnique(new InFlightVisibleChange(window, !visible))); |
| 341 tree_->SetWindowVisibility(change_id, server_id(window), visible); | 308 tree_->SetWindowVisibility(change_id, server_id(window), visible); |
| 342 } | 309 } |
| 343 | 310 |
| 344 void WindowTreeClientImpl::SetOpacity(Window* window, float opacity) { | 311 void WindowTreeClient::SetOpacity(Window* window, float opacity) { |
| 345 DCHECK(tree_); | 312 DCHECK(tree_); |
| 346 const uint32_t change_id = ScheduleInFlightChange( | 313 const uint32_t change_id = ScheduleInFlightChange( |
| 347 base::WrapUnique(new InFlightOpacityChange(window, window->opacity()))); | 314 base::WrapUnique(new InFlightOpacityChange(window, window->opacity()))); |
| 348 tree_->SetWindowOpacity(change_id, server_id(window), opacity); | 315 tree_->SetWindowOpacity(change_id, server_id(window), opacity); |
| 349 } | 316 } |
| 350 | 317 |
| 351 void WindowTreeClientImpl::SetProperty(Window* window, | 318 void WindowTreeClient::SetProperty(Window* window, |
| 352 const std::string& name, | 319 const std::string& name, |
| 353 mojo::Array<uint8_t> data) { | 320 mojo::Array<uint8_t> data) { |
| 354 DCHECK(tree_); | 321 DCHECK(tree_); |
| 355 | 322 |
| 356 mojo::Array<uint8_t> old_value(nullptr); | 323 mojo::Array<uint8_t> old_value(nullptr); |
| 357 if (window->HasSharedProperty(name)) | 324 if (window->HasSharedProperty(name)) |
| 358 old_value = mojo::Array<uint8_t>::From(window->properties_[name]); | 325 old_value = mojo::Array<uint8_t>::From(window->properties_[name]); |
| 359 | 326 |
| 360 const uint32_t change_id = ScheduleInFlightChange( | 327 const uint32_t change_id = ScheduleInFlightChange( |
| 361 base::WrapUnique(new InFlightPropertyChange(window, name, old_value))); | 328 base::WrapUnique(new InFlightPropertyChange(window, name, old_value))); |
| 362 tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name), | 329 tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name), |
| 363 std::move(data)); | 330 std::move(data)); |
| 364 } | 331 } |
| 365 | 332 |
| 366 void WindowTreeClientImpl::SetWindowTextInputState( | 333 void WindowTreeClient::SetWindowTextInputState( |
| 367 Id window_id, | 334 Id window_id, |
| 368 mojo::TextInputStatePtr state) { | 335 mojo::TextInputStatePtr state) { |
| 369 DCHECK(tree_); | 336 DCHECK(tree_); |
| 370 tree_->SetWindowTextInputState(window_id, std::move(state)); | 337 tree_->SetWindowTextInputState(window_id, std::move(state)); |
| 371 } | 338 } |
| 372 | 339 |
| 373 void WindowTreeClientImpl::SetImeVisibility(Id window_id, | 340 void WindowTreeClient::SetImeVisibility(Id window_id, |
| 374 bool visible, | 341 bool visible, |
| 375 mojo::TextInputStatePtr state) { | 342 mojo::TextInputStatePtr state) { |
| 376 DCHECK(tree_); | 343 DCHECK(tree_); |
| 377 tree_->SetImeVisibility(window_id, visible, std::move(state)); | 344 tree_->SetImeVisibility(window_id, visible, std::move(state)); |
| 378 } | 345 } |
| 379 | 346 |
| 380 void WindowTreeClientImpl::Embed( | 347 void WindowTreeClient::Embed( |
| 381 Id window_id, | 348 Id window_id, |
| 382 mojom::WindowTreeClientPtr client, | 349 mojom::WindowTreeClientPtr client, |
| 383 const mojom::WindowTree::EmbedCallback& callback) { | 350 const mojom::WindowTree::EmbedCallback& callback) { |
| 384 DCHECK(tree_); | 351 DCHECK(tree_); |
| 385 tree_->Embed(window_id, std::move(client), callback); | 352 tree_->Embed(window_id, std::move(client), callback); |
| 386 } | 353 } |
| 387 | 354 |
| 388 void WindowTreeClientImpl::RequestClose(Window* window) { | 355 void WindowTreeClient::RequestClose(Window* window) { |
| 389 if (window_manager_internal_client_) | 356 if (window_manager_internal_client_) |
| 390 window_manager_internal_client_->WmRequestClose(server_id(window)); | 357 window_manager_internal_client_->WmRequestClose(server_id(window)); |
| 391 } | 358 } |
| 392 | 359 |
| 393 void WindowTreeClientImpl::AttachSurface( | 360 void WindowTreeClient::AttachSurface( |
| 394 Id window_id, | 361 Id window_id, |
| 395 mojom::SurfaceType type, | 362 mojom::SurfaceType type, |
| 396 mojo::InterfaceRequest<mojom::Surface> surface, | 363 mojo::InterfaceRequest<mojom::Surface> surface, |
| 397 mojom::SurfaceClientPtr client) { | 364 mojom::SurfaceClientPtr client) { |
| 398 DCHECK(tree_); | 365 DCHECK(tree_); |
| 399 tree_->AttachSurface(window_id, type, std::move(surface), std::move(client)); | 366 tree_->AttachSurface(window_id, type, std::move(surface), std::move(client)); |
| 400 } | 367 } |
| 401 | 368 |
| 402 void WindowTreeClientImpl::LocalSetCapture(Window* window) { | 369 void WindowTreeClient::LocalSetCapture(Window* window) { |
| 403 if (capture_window_ == window) | 370 if (capture_window_ == window) |
| 404 return; | 371 return; |
| 405 Window* lost_capture = capture_window_; | 372 Window* lost_capture = capture_window_; |
| 406 capture_window_ = window; | 373 capture_window_ = window; |
| 407 if (lost_capture) { | 374 if (lost_capture) { |
| 408 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(lost_capture).observers(), | 375 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(lost_capture).observers(), |
| 409 OnWindowLostCapture(lost_capture)); | 376 OnWindowLostCapture(lost_capture)); |
| 410 } | 377 } |
| 411 } | 378 } |
| 412 | 379 |
| 413 void WindowTreeClientImpl::LocalSetFocus(Window* focused) { | 380 void WindowTreeClient::LocalSetFocus(Window* focused) { |
| 414 Window* blurred = focused_window_; | 381 Window* blurred = focused_window_; |
| 415 // Update |focused_window_| before calling any of the observers, so that the | 382 // Update |focused_window_| before calling any of the observers, so that the |
| 416 // observers get the correct result from calling |Window::HasFocus()|, | 383 // observers get the correct result from calling |Window::HasFocus()|, |
| 417 // |WindowTreeConnection::GetFocusedWindow()| etc. | 384 // |WindowTreeClient::GetFocusedWindow()| etc. |
| 418 focused_window_ = focused; | 385 focused_window_ = focused; |
| 419 if (blurred) { | 386 if (blurred) { |
| 420 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(blurred).observers(), | 387 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(blurred).observers(), |
| 421 OnWindowFocusChanged(focused, blurred)); | 388 OnWindowFocusChanged(focused, blurred)); |
| 422 } | 389 } |
| 423 if (focused) { | 390 if (focused) { |
| 424 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(focused).observers(), | 391 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(focused).observers(), |
| 425 OnWindowFocusChanged(focused, blurred)); | 392 OnWindowFocusChanged(focused, blurred)); |
| 426 } | 393 } |
| 427 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, | 394 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, |
| 428 OnWindowTreeFocusChanged(focused, blurred)); | 395 OnWindowTreeFocusChanged(focused, blurred)); |
| 429 } | 396 } |
| 430 | 397 |
| 431 void WindowTreeClientImpl::AddWindow(Window* window) { | 398 void WindowTreeClient::AddWindow(Window* window) { |
| 432 DCHECK(windows_.find(server_id(window)) == windows_.end()); | 399 DCHECK(windows_.find(server_id(window)) == windows_.end()); |
| 433 windows_[server_id(window)] = window; | 400 windows_[server_id(window)] = window; |
| 434 } | 401 } |
| 435 | 402 |
| 436 void WindowTreeClientImpl::OnWindowDestroying(Window* window) { | 403 void WindowTreeClient::OnWindowDestroying(Window* window) { |
| 437 // TODO(jonross): Also clear the focused window (crbug.com/611983) | 404 // TODO(jonross): Also clear the focused window (crbug.com/611983) |
| 438 if (window == capture_window_) { | 405 if (window == capture_window_) { |
| 439 InFlightCaptureChange reset_change(this, nullptr); | 406 InFlightCaptureChange reset_change(this, nullptr); |
| 440 ApplyServerChangeToExistingInFlightChange(reset_change); | 407 ApplyServerChangeToExistingInFlightChange(reset_change); |
| 441 // Normally just updating the queued changes is sufficient. However since | 408 // Normally just updating the queued changes is sufficient. However since |
| 442 // |window| is being destroyed, it will not be possible to notify its | 409 // |window| is being destroyed, it will not be possible to notify its |
| 443 // observers of the lost capture. Update local state now. | 410 // observers of the lost capture. Update local state now. |
| 444 LocalSetCapture(nullptr); | 411 LocalSetCapture(nullptr); |
| 445 } | 412 } |
| 446 } | 413 } |
| 447 | 414 |
| 448 void WindowTreeClientImpl::OnWindowDestroyed(Window* window) { | 415 void WindowTreeClient::OnWindowDestroyed(Window* window) { |
| 449 windows_.erase(server_id(window)); | 416 windows_.erase(server_id(window)); |
| 450 | 417 |
| 451 for (auto& entry : embedded_windows_) { | 418 for (auto& entry : embedded_windows_) { |
| 452 auto it = entry.second.find(window); | 419 auto it = entry.second.find(window); |
| 453 if (it != entry.second.end()) { | 420 if (it != entry.second.end()) { |
| 454 entry.second.erase(it); | 421 entry.second.erase(it); |
| 455 break; | 422 break; |
| 456 } | 423 } |
| 457 } | 424 } |
| 458 | 425 |
| 459 // Remove any InFlightChanges associated with the window. | 426 // Remove any InFlightChanges associated with the window. |
| 460 std::set<uint32_t> in_flight_change_ids_to_remove; | 427 std::set<uint32_t> in_flight_change_ids_to_remove; |
| 461 for (const auto& pair : in_flight_map_) { | 428 for (const auto& pair : in_flight_map_) { |
| 462 if (pair.second->window() == window) | 429 if (pair.second->window() == window) |
| 463 in_flight_change_ids_to_remove.insert(pair.first); | 430 in_flight_change_ids_to_remove.insert(pair.first); |
| 464 } | 431 } |
| 465 for (auto change_id : in_flight_change_ids_to_remove) | 432 for (auto change_id : in_flight_change_ids_to_remove) |
| 466 in_flight_map_.erase(change_id); | 433 in_flight_map_.erase(change_id); |
| 467 | 434 |
| 468 if (roots_.erase(window) > 0 && roots_.empty() && delete_on_no_roots_ && | 435 if (roots_.erase(window) > 0 && roots_.empty() && delete_on_no_roots_ && |
| 469 !in_destructor_) { | 436 !in_destructor_) { |
| 470 delete this; | 437 delete this; |
| 471 } | 438 } |
| 472 } | 439 } |
| 473 | 440 |
| 474 Window* WindowTreeClientImpl::GetWindowByServerId(Id id) { | 441 Window* WindowTreeClient::GetWindowByServerId(Id id) { |
| 475 IdToWindowMap::const_iterator it = windows_.find(id); | 442 IdToWindowMap::const_iterator it = windows_.find(id); |
| 476 return it != windows_.end() ? it->second : NULL; | 443 return it != windows_.end() ? it->second : NULL; |
| 477 } | 444 } |
| 478 | 445 |
| 479 InFlightChange* WindowTreeClientImpl::GetOldestInFlightChangeMatching( | 446 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( |
| 480 const InFlightChange& change) { | 447 const InFlightChange& change) { |
| 481 for (const auto& pair : in_flight_map_) { | 448 for (const auto& pair : in_flight_map_) { |
| 482 if (pair.second->window() == change.window() && | 449 if (pair.second->window() == change.window() && |
| 483 pair.second->change_type() == change.change_type() && | 450 pair.second->change_type() == change.change_type() && |
| 484 pair.second->Matches(change)) { | 451 pair.second->Matches(change)) { |
| 485 return pair.second.get(); | 452 return pair.second.get(); |
| 486 } | 453 } |
| 487 } | 454 } |
| 488 return nullptr; | 455 return nullptr; |
| 489 } | 456 } |
| 490 | 457 |
| 491 uint32_t WindowTreeClientImpl::ScheduleInFlightChange( | 458 uint32_t WindowTreeClient::ScheduleInFlightChange( |
| 492 std::unique_ptr<InFlightChange> change) { | 459 std::unique_ptr<InFlightChange> change) { |
| 493 DCHECK(!change->window() || | 460 DCHECK(!change->window() || |
| 494 windows_.count(change->window()->server_id()) > 0); | 461 windows_.count(change->window()->server_id()) > 0); |
| 495 const uint32_t change_id = next_change_id_++; | 462 const uint32_t change_id = next_change_id_++; |
| 496 in_flight_map_[change_id] = std::move(change); | 463 in_flight_map_[change_id] = std::move(change); |
| 497 return change_id; | 464 return change_id; |
| 498 } | 465 } |
| 499 | 466 |
| 500 bool WindowTreeClientImpl::ApplyServerChangeToExistingInFlightChange( | 467 bool WindowTreeClient::ApplyServerChangeToExistingInFlightChange( |
| 501 const InFlightChange& change) { | 468 const InFlightChange& change) { |
| 502 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); | 469 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); |
| 503 if (!existing_change) | 470 if (!existing_change) |
| 504 return false; | 471 return false; |
| 505 | 472 |
| 506 existing_change->SetRevertValueFrom(change); | 473 existing_change->SetRevertValueFrom(change); |
| 507 return true; | 474 return true; |
| 508 } | 475 } |
| 509 | 476 |
| 510 Window* WindowTreeClientImpl::NewWindowImpl( | 477 Window* WindowTreeClient::NewWindowImpl( |
| 511 NewWindowType type, | 478 NewWindowType type, |
| 512 const Window::SharedProperties* properties) { | 479 const Window::SharedProperties* properties) { |
| 513 DCHECK(tree_); | 480 DCHECK(tree_); |
| 514 Window* window = | 481 Window* window = |
| 515 new Window(this, MakeTransportId(client_id_, next_window_id_++)); | 482 new Window(this, MakeTransportId(client_id_, next_window_id_++)); |
| 516 if (properties) | 483 if (properties) |
| 517 window->properties_ = *properties; | 484 window->properties_ = *properties; |
| 518 AddWindow(window); | 485 AddWindow(window); |
| 519 | 486 |
| 520 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( | 487 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( |
| 521 new CrashInFlightChange(window, type == NewWindowType::CHILD | 488 new CrashInFlightChange(window, type == NewWindowType::CHILD |
| 522 ? ChangeType::NEW_WINDOW | 489 ? ChangeType::NEW_WINDOW |
| 523 : ChangeType::NEW_TOP_LEVEL_WINDOW))); | 490 : ChangeType::NEW_TOP_LEVEL_WINDOW))); |
| 524 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; | 491 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; |
| 525 if (properties) { | 492 if (properties) { |
| 526 transport_properties = | 493 transport_properties = |
| 527 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties); | 494 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties); |
| 528 } | 495 } |
| 529 if (type == NewWindowType::CHILD) { | 496 if (type == NewWindowType::CHILD) { |
| 530 tree_->NewWindow(change_id, server_id(window), | 497 tree_->NewWindow(change_id, server_id(window), |
| 531 std::move(transport_properties)); | 498 std::move(transport_properties)); |
| 532 } else { | 499 } else { |
| 533 roots_.insert(window); | 500 roots_.insert(window); |
| 534 tree_->NewTopLevelWindow(change_id, server_id(window), | 501 tree_->NewTopLevelWindow(change_id, server_id(window), |
| 535 std::move(transport_properties)); | 502 std::move(transport_properties)); |
| 536 } | 503 } |
| 537 return window; | 504 return window; |
| 538 } | 505 } |
| 539 | 506 |
| 540 void WindowTreeClientImpl::OnEmbedImpl(mojom::WindowTree* window_tree, | 507 void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree, |
| 541 ClientSpecificId client_id, | 508 ClientSpecificId client_id, |
| 542 mojom::WindowDataPtr root_data, | 509 mojom::WindowDataPtr root_data, |
| 543 int64_t display_id, | 510 int64_t display_id, |
| 544 Id focused_window_id, | 511 Id focused_window_id, |
| 545 bool drawn) { | 512 bool drawn) { |
| 546 // WARNING: this is only called if WindowTreeClientImpl was created as the | 513 // WARNING: this is only called if WindowTreeClient was created as the |
| 547 // result of an embedding. | 514 // result of an embedding. |
| 548 tree_ = window_tree; | 515 tree_ = window_tree; |
| 549 client_id_ = client_id; | 516 client_id_ = client_id; |
| 550 | 517 |
| 551 DCHECK(roots_.empty()); | 518 DCHECK(roots_.empty()); |
| 552 Window* root = AddWindowToClient(this, nullptr, root_data); | 519 Window* root = AddWindowToClient(this, nullptr, root_data); |
| 553 WindowPrivate(root).LocalSetDisplay(display_id); | 520 WindowPrivate(root).LocalSetDisplay(display_id); |
| 554 roots_.insert(root); | 521 roots_.insert(root); |
| 555 | 522 |
| 556 focused_window_ = GetWindowByServerId(focused_window_id); | 523 focused_window_ = GetWindowByServerId(focused_window_id); |
| 557 | 524 |
| 558 WindowPrivate(root).LocalSetParentDrawn(drawn); | 525 WindowPrivate(root).LocalSetParentDrawn(drawn); |
| 559 | 526 |
| 560 delegate_->OnEmbed(root); | 527 delegate_->OnEmbed(root); |
| 561 | 528 |
| 562 if (focused_window_) { | 529 if (focused_window_) { |
| 563 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, | 530 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, |
| 564 OnWindowTreeFocusChanged(focused_window_, nullptr)); | 531 OnWindowTreeFocusChanged(focused_window_, nullptr)); |
| 565 } | 532 } |
| 566 } | 533 } |
| 567 | 534 |
| 568 void WindowTreeClientImpl::OnReceivedCursorLocationMemory( | 535 void WindowTreeClient::OnReceivedCursorLocationMemory( |
| 569 mojo::ScopedSharedBufferHandle handle) { | 536 mojo::ScopedSharedBufferHandle handle) { |
| 570 cursor_location_handle_ = std::move(handle); | 537 cursor_location_handle_ = std::move(handle); |
| 571 MojoResult result = mojo::MapBuffer( | 538 MojoResult result = mojo::MapBuffer( |
| 572 cursor_location_handle_.get(), 0, | 539 cursor_location_handle_.get(), 0, |
| 573 sizeof(base::subtle::Atomic32), | 540 sizeof(base::subtle::Atomic32), |
| 574 reinterpret_cast<void**>(&cursor_location_memory_), | 541 reinterpret_cast<void**>(&cursor_location_memory_), |
| 575 MOJO_MAP_BUFFER_FLAG_NONE); | 542 MOJO_MAP_BUFFER_FLAG_NONE); |
| 576 if (result != MOJO_RESULT_OK) { | 543 if (result != MOJO_RESULT_OK) { |
| 577 NOTREACHED(); | 544 NOTREACHED(); |
| 578 return; | 545 return; |
| 579 } | 546 } |
| 580 DCHECK(cursor_location_memory_); | 547 DCHECK(cursor_location_memory_); |
| 581 } | 548 } |
| 582 | 549 |
| 583 //////////////////////////////////////////////////////////////////////////////// | 550 //////////////////////////////////////////////////////////////////////////////// |
| 584 // WindowTreeClientImpl, WindowTreeConnection implementation: | 551 // WindowTreeClient, WindowTreeClient implementation: |
| 585 | 552 |
| 586 void WindowTreeClientImpl::SetDeleteOnNoRoots(bool value) { | 553 void WindowTreeClient::SetDeleteOnNoRoots(bool value) { |
| 587 delete_on_no_roots_ = value; | 554 delete_on_no_roots_ = value; |
| 588 } | 555 } |
| 589 | 556 |
| 590 const std::set<Window*>& WindowTreeClientImpl::GetRoots() { | 557 const std::set<Window*>& WindowTreeClient::GetRoots() { |
| 591 return roots_; | 558 return roots_; |
| 592 } | 559 } |
| 593 | 560 |
| 594 Window* WindowTreeClientImpl::GetFocusedWindow() { | 561 Window* WindowTreeClient::GetFocusedWindow() { |
| 595 return focused_window_; | 562 return focused_window_; |
| 596 } | 563 } |
| 597 | 564 |
| 598 void WindowTreeClientImpl::ClearFocus() { | 565 void WindowTreeClient::ClearFocus() { |
| 599 if (!focused_window_) | 566 if (!focused_window_) |
| 600 return; | 567 return; |
| 601 | 568 |
| 602 SetFocus(nullptr); | 569 SetFocus(nullptr); |
| 603 } | 570 } |
| 604 | 571 |
| 605 gfx::Point WindowTreeClientImpl::GetCursorScreenPoint() { | 572 gfx::Point WindowTreeClient::GetCursorScreenPoint() { |
| 606 // We raced initialization. Return (0, 0). | 573 // We raced initialization. Return (0, 0). |
| 607 if (!cursor_location_memory_) | 574 if (!cursor_location_memory_) |
| 608 return gfx::Point(); | 575 return gfx::Point(); |
| 609 | 576 |
| 610 base::subtle::Atomic32 location = | 577 base::subtle::Atomic32 location = |
| 611 base::subtle::NoBarrier_Load(cursor_location_memory_); | 578 base::subtle::NoBarrier_Load(cursor_location_memory_); |
| 612 return gfx::Point(static_cast<int16_t>(location >> 16), | 579 return gfx::Point(static_cast<int16_t>(location >> 16), |
| 613 static_cast<int16_t>(location & 0xFFFF)); | 580 static_cast<int16_t>(location & 0xFFFF)); |
| 614 } | 581 } |
| 615 | 582 |
| 616 void WindowTreeClientImpl::SetEventObserver(mojom::EventMatcherPtr matcher) { | 583 void WindowTreeClient::SetEventObserver(mojom::EventMatcherPtr matcher) { |
| 617 if (matcher.is_null()) { | 584 if (matcher.is_null()) { |
| 618 has_event_observer_ = false; | 585 has_event_observer_ = false; |
| 619 tree_->SetEventObserver(nullptr, 0u); | 586 tree_->SetEventObserver(nullptr, 0u); |
| 620 } else { | 587 } else { |
| 621 has_event_observer_ = true; | 588 has_event_observer_ = true; |
| 622 event_observer_id_++; | 589 event_observer_id_++; |
| 623 tree_->SetEventObserver(std::move(matcher), event_observer_id_); | 590 tree_->SetEventObserver(std::move(matcher), event_observer_id_); |
| 624 } | 591 } |
| 625 } | 592 } |
| 626 | 593 |
| 627 Window* WindowTreeClientImpl::NewWindow( | 594 Window* WindowTreeClient::NewWindow( |
| 628 const Window::SharedProperties* properties) { | 595 const Window::SharedProperties* properties) { |
| 629 return NewWindowImpl(NewWindowType::CHILD, properties); | 596 return NewWindowImpl(NewWindowType::CHILD, properties); |
| 630 } | 597 } |
| 631 | 598 |
| 632 Window* WindowTreeClientImpl::NewTopLevelWindow( | 599 Window* WindowTreeClient::NewTopLevelWindow( |
| 633 const Window::SharedProperties* properties) { | 600 const Window::SharedProperties* properties) { |
| 634 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); | 601 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); |
| 635 // Assume newly created top level windows are drawn by default, otherwise | 602 // Assume newly created top level windows are drawn by default, otherwise |
| 636 // requests to focus will fail. We will get the real value in | 603 // requests to focus will fail. We will get the real value in |
| 637 // OnTopLevelCreated(). | 604 // OnTopLevelCreated(). |
| 638 window->LocalSetParentDrawn(true); | 605 window->LocalSetParentDrawn(true); |
| 639 return window; | 606 return window; |
| 640 } | 607 } |
| 641 | 608 |
| 642 //////////////////////////////////////////////////////////////////////////////// | 609 //////////////////////////////////////////////////////////////////////////////// |
| 643 // WindowTreeClientImpl, WindowTreeClient implementation: | 610 // WindowTreeClient, WindowTreeClient implementation: |
| 644 | 611 |
| 645 void WindowTreeClientImpl::AddObserver(WindowTreeConnectionObserver* observer) { | 612 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { |
| 646 observers_.AddObserver(observer); | 613 observers_.AddObserver(observer); |
| 647 } | 614 } |
| 648 | 615 |
| 649 void WindowTreeClientImpl::RemoveObserver( | 616 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { |
| 650 WindowTreeConnectionObserver* observer) { | |
| 651 observers_.RemoveObserver(observer); | 617 observers_.RemoveObserver(observer); |
| 652 } | 618 } |
| 653 | 619 |
| 654 void WindowTreeClientImpl::OnEmbed(ClientSpecificId client_id, | 620 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
| 655 mojom::WindowDataPtr root_data, | 621 mojom::WindowDataPtr root_data, |
| 656 mojom::WindowTreePtr tree, | 622 mojom::WindowTreePtr tree, |
| 657 int64_t display_id, | 623 int64_t display_id, |
| 658 Id focused_window_id, | 624 Id focused_window_id, |
| 659 bool drawn) { | 625 bool drawn) { |
| 660 DCHECK(!tree_ptr_); | 626 DCHECK(!tree_ptr_); |
| 661 tree_ptr_ = std::move(tree); | 627 tree_ptr_ = std::move(tree); |
| 662 tree_ptr_.set_connection_error_handler([this]() { delete this; }); | 628 tree_ptr_.set_connection_error_handler([this]() { delete this; }); |
| 663 | 629 |
| 664 if (window_manager_delegate_) { | 630 if (window_manager_delegate_) { |
| 665 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, | 631 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, |
| 666 tree_ptr_.associated_group())); | 632 tree_ptr_.associated_group())); |
| 667 } | 633 } |
| 668 | 634 |
| 669 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, | 635 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, |
| 670 focused_window_id, drawn); | 636 focused_window_id, drawn); |
| 671 } | 637 } |
| 672 | 638 |
| 673 void WindowTreeClientImpl::OnEmbeddedAppDisconnected(Id window_id) { | 639 void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) { |
| 674 Window* window = GetWindowByServerId(window_id); | 640 Window* window = GetWindowByServerId(window_id); |
| 675 if (window) { | 641 if (window) { |
| 676 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), | 642 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), |
| 677 OnWindowEmbeddedAppDisconnected(window)); | 643 OnWindowEmbeddedAppDisconnected(window)); |
| 678 } | 644 } |
| 679 } | 645 } |
| 680 | 646 |
| 681 void WindowTreeClientImpl::OnUnembed(Id window_id) { | 647 void WindowTreeClient::OnUnembed(Id window_id) { |
| 682 Window* window = GetWindowByServerId(window_id); | 648 Window* window = GetWindowByServerId(window_id); |
| 683 if (!window) | 649 if (!window) |
| 684 return; | 650 return; |
| 685 | 651 |
| 686 delegate_->OnUnembed(window); | 652 delegate_->OnUnembed(window); |
| 687 WindowPrivate(window).LocalDestroy(); | 653 WindowPrivate(window).LocalDestroy(); |
| 688 } | 654 } |
| 689 | 655 |
| 690 void WindowTreeClientImpl::OnLostCapture(Id window_id) { | 656 void WindowTreeClient::OnLostCapture(Id window_id) { |
| 691 Window* window = GetWindowByServerId(window_id); | 657 Window* window = GetWindowByServerId(window_id); |
| 692 if (!window) | 658 if (!window) |
| 693 return; | 659 return; |
| 694 | 660 |
| 695 InFlightCaptureChange reset_change(this, nullptr); | 661 InFlightCaptureChange reset_change(this, nullptr); |
| 696 if (ApplyServerChangeToExistingInFlightChange(reset_change)) | 662 if (ApplyServerChangeToExistingInFlightChange(reset_change)) |
| 697 return; | 663 return; |
| 698 | 664 |
| 699 LocalSetCapture(nullptr); | 665 LocalSetCapture(nullptr); |
| 700 } | 666 } |
| 701 | 667 |
| 702 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id, | 668 void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| 703 mojom::WindowDataPtr data, | 669 mojom::WindowDataPtr data, |
| 704 int64_t display_id, | 670 int64_t display_id, |
| 705 bool drawn) { | 671 bool drawn) { |
| 706 // The server ack'd the top level window we created and supplied the state | 672 // The server ack'd the top level window we created and supplied the state |
| 707 // of the window at the time the server created it. For properties we do not | 673 // of the window at the time the server created it. For properties we do not |
| 708 // have changes in flight for we can update them immediately. For properties | 674 // have changes in flight for we can update them immediately. For properties |
| 709 // with changes in flight we set the revert value from the server. | 675 // with changes in flight we set the revert value from the server. |
| 710 | 676 |
| 711 if (!in_flight_map_.count(change_id)) { | 677 if (!in_flight_map_.count(change_id)) { |
| 712 // The window may have been destroyed locally before the server could finish | 678 // The window may have been destroyed locally before the server could finish |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 if (current_change) | 726 if (current_change) |
| 761 current_change->SetRevertValueFrom(property_change); | 727 current_change->SetRevertValueFrom(property_change); |
| 762 else | 728 else |
| 763 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); | 729 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); |
| 764 } | 730 } |
| 765 | 731 |
| 766 // Top level windows should not have a parent. | 732 // Top level windows should not have a parent. |
| 767 DCHECK_EQ(0u, data->parent_id); | 733 DCHECK_EQ(0u, data->parent_id); |
| 768 } | 734 } |
| 769 | 735 |
| 770 void WindowTreeClientImpl::OnWindowBoundsChanged(Id window_id, | 736 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, |
| 771 const gfx::Rect& old_bounds, | 737 const gfx::Rect& old_bounds, |
| 772 const gfx::Rect& new_bounds) { | 738 const gfx::Rect& new_bounds) { |
| 773 Window* window = GetWindowByServerId(window_id); | 739 Window* window = GetWindowByServerId(window_id); |
| 774 if (!window) | 740 if (!window) |
| 775 return; | 741 return; |
| 776 | 742 |
| 777 InFlightBoundsChange new_change(window, new_bounds); | 743 InFlightBoundsChange new_change(window, new_bounds); |
| 778 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 744 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 779 return; | 745 return; |
| 780 | 746 |
| 781 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); | 747 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); |
| 782 } | 748 } |
| 783 | 749 |
| 784 void WindowTreeClientImpl::OnClientAreaChanged( | 750 void WindowTreeClient::OnClientAreaChanged( |
| 785 uint32_t window_id, | 751 uint32_t window_id, |
| 786 const gfx::Insets& new_client_area, | 752 const gfx::Insets& new_client_area, |
| 787 mojo::Array<gfx::Rect> new_additional_client_areas) { | 753 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 788 Window* window = GetWindowByServerId(window_id); | 754 Window* window = GetWindowByServerId(window_id); |
| 789 if (window) { | 755 if (window) { |
| 790 WindowPrivate(window).LocalSetClientArea( | 756 WindowPrivate(window).LocalSetClientArea( |
| 791 new_client_area, | 757 new_client_area, |
| 792 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | 758 new_additional_client_areas.To<std::vector<gfx::Rect>>()); |
| 793 } | 759 } |
| 794 } | 760 } |
| 795 | 761 |
| 796 void WindowTreeClientImpl::OnTransientWindowAdded( | 762 void WindowTreeClient::OnTransientWindowAdded( |
| 797 uint32_t window_id, | 763 uint32_t window_id, |
| 798 uint32_t transient_window_id) { | 764 uint32_t transient_window_id) { |
| 799 Window* window = GetWindowByServerId(window_id); | 765 Window* window = GetWindowByServerId(window_id); |
| 800 Window* transient_window = GetWindowByServerId(transient_window_id); | 766 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 801 // window or transient_window or both may be null if a local delete occurs | 767 // window or transient_window or both may be null if a local delete occurs |
| 802 // with an in flight add from the server. | 768 // with an in flight add from the server. |
| 803 if (window && transient_window) | 769 if (window && transient_window) |
| 804 WindowPrivate(window).LocalAddTransientWindow(transient_window); | 770 WindowPrivate(window).LocalAddTransientWindow(transient_window); |
| 805 } | 771 } |
| 806 | 772 |
| 807 void WindowTreeClientImpl::OnTransientWindowRemoved( | 773 void WindowTreeClient::OnTransientWindowRemoved( |
| 808 uint32_t window_id, | 774 uint32_t window_id, |
| 809 uint32_t transient_window_id) { | 775 uint32_t transient_window_id) { |
| 810 Window* window = GetWindowByServerId(window_id); | 776 Window* window = GetWindowByServerId(window_id); |
| 811 Window* transient_window = GetWindowByServerId(transient_window_id); | 777 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 812 // window or transient_window or both may be null if a local delete occurs | 778 // window or transient_window or both may be null if a local delete occurs |
| 813 // with an in flight delete from the server. | 779 // with an in flight delete from the server. |
| 814 if (window && transient_window) | 780 if (window && transient_window) |
| 815 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); | 781 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); |
| 816 } | 782 } |
| 817 | 783 |
| 818 void WindowTreeClientImpl::OnWindowHierarchyChanged( | 784 void WindowTreeClient::OnWindowHierarchyChanged( |
| 819 Id window_id, | 785 Id window_id, |
| 820 Id old_parent_id, | 786 Id old_parent_id, |
| 821 Id new_parent_id, | 787 Id new_parent_id, |
| 822 mojo::Array<mojom::WindowDataPtr> windows) { | 788 mojo::Array<mojom::WindowDataPtr> windows) { |
| 823 Window* initial_parent = | 789 Window* initial_parent = |
| 824 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL; | 790 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL; |
| 825 | 791 |
| 826 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; | 792 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; |
| 827 | 793 |
| 828 BuildWindowTree(this, windows, initial_parent); | 794 BuildWindowTree(this, windows, initial_parent); |
| 829 | 795 |
| 830 // If the window was not known, then BuildWindowTree() will have created it | 796 // If the window was not known, then BuildWindowTree() will have created it |
| 831 // and parented the window. | 797 // and parented the window. |
| 832 if (!was_window_known) | 798 if (!was_window_known) |
| 833 return; | 799 return; |
| 834 | 800 |
| 835 Window* new_parent = GetWindowByServerId(new_parent_id); | 801 Window* new_parent = GetWindowByServerId(new_parent_id); |
| 836 Window* old_parent = GetWindowByServerId(old_parent_id); | 802 Window* old_parent = GetWindowByServerId(old_parent_id); |
| 837 Window* window = GetWindowByServerId(window_id); | 803 Window* window = GetWindowByServerId(window_id); |
| 838 if (new_parent) | 804 if (new_parent) |
| 839 WindowPrivate(new_parent).LocalAddChild(window); | 805 WindowPrivate(new_parent).LocalAddChild(window); |
| 840 else | 806 else |
| 841 WindowPrivate(old_parent).LocalRemoveChild(window); | 807 WindowPrivate(old_parent).LocalRemoveChild(window); |
| 842 } | 808 } |
| 843 | 809 |
| 844 void WindowTreeClientImpl::OnWindowReordered(Id window_id, | 810 void WindowTreeClient::OnWindowReordered(Id window_id, |
| 845 Id relative_window_id, | 811 Id relative_window_id, |
| 846 mojom::OrderDirection direction) { | 812 mojom::OrderDirection direction) { |
| 847 Window* window = GetWindowByServerId(window_id); | 813 Window* window = GetWindowByServerId(window_id); |
| 848 Window* relative_window = GetWindowByServerId(relative_window_id); | 814 Window* relative_window = GetWindowByServerId(relative_window_id); |
| 849 if (window && relative_window) | 815 if (window && relative_window) |
| 850 WindowPrivate(window).LocalReorder(relative_window, direction); | 816 WindowPrivate(window).LocalReorder(relative_window, direction); |
| 851 } | 817 } |
| 852 | 818 |
| 853 void WindowTreeClientImpl::OnWindowDeleted(Id window_id) { | 819 void WindowTreeClient::OnWindowDeleted(Id window_id) { |
| 854 Window* window = GetWindowByServerId(window_id); | 820 Window* window = GetWindowByServerId(window_id); |
| 855 if (window) | 821 if (window) |
| 856 WindowPrivate(window).LocalDestroy(); | 822 WindowPrivate(window).LocalDestroy(); |
| 857 } | 823 } |
| 858 | 824 |
| 859 Window* WindowTreeClientImpl::GetCaptureWindow() { | 825 Window* WindowTreeClient::GetCaptureWindow() { |
| 860 return capture_window_; | 826 return capture_window_; |
| 861 } | 827 } |
| 862 | 828 |
| 863 void WindowTreeClientImpl::OnWindowVisibilityChanged(Id window_id, | 829 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, |
| 864 bool visible) { | 830 bool visible) { |
| 865 Window* window = GetWindowByServerId(window_id); | 831 Window* window = GetWindowByServerId(window_id); |
| 866 if (!window) | 832 if (!window) |
| 867 return; | 833 return; |
| 868 | 834 |
| 869 InFlightVisibleChange new_change(window, visible); | 835 InFlightVisibleChange new_change(window, visible); |
| 870 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 836 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 871 return; | 837 return; |
| 872 | 838 |
| 873 WindowPrivate(window).LocalSetVisible(visible); | 839 WindowPrivate(window).LocalSetVisible(visible); |
| 874 } | 840 } |
| 875 | 841 |
| 876 void WindowTreeClientImpl::OnWindowOpacityChanged(Id window_id, | 842 void WindowTreeClient::OnWindowOpacityChanged(Id window_id, |
| 877 float old_opacity, | 843 float old_opacity, |
| 878 float new_opacity) { | 844 float new_opacity) { |
| 879 Window* window = GetWindowByServerId(window_id); | 845 Window* window = GetWindowByServerId(window_id); |
| 880 if (!window) | 846 if (!window) |
| 881 return; | 847 return; |
| 882 | 848 |
| 883 InFlightOpacityChange new_change(window, new_opacity); | 849 InFlightOpacityChange new_change(window, new_opacity); |
| 884 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 850 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 885 return; | 851 return; |
| 886 | 852 |
| 887 WindowPrivate(window).LocalSetOpacity(new_opacity); | 853 WindowPrivate(window).LocalSetOpacity(new_opacity); |
| 888 } | 854 } |
| 889 | 855 |
| 890 void WindowTreeClientImpl::OnWindowParentDrawnStateChanged(Id window_id, | 856 void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id, |
| 891 bool drawn) { | 857 bool drawn) { |
| 892 Window* window = GetWindowByServerId(window_id); | 858 Window* window = GetWindowByServerId(window_id); |
| 893 if (window) | 859 if (window) |
| 894 WindowPrivate(window).LocalSetParentDrawn(drawn); | 860 WindowPrivate(window).LocalSetParentDrawn(drawn); |
| 895 } | 861 } |
| 896 | 862 |
| 897 void WindowTreeClientImpl::OnWindowSharedPropertyChanged( | 863 void WindowTreeClient::OnWindowSharedPropertyChanged( |
| 898 Id window_id, | 864 Id window_id, |
| 899 const mojo::String& name, | 865 const mojo::String& name, |
| 900 mojo::Array<uint8_t> new_data) { | 866 mojo::Array<uint8_t> new_data) { |
| 901 Window* window = GetWindowByServerId(window_id); | 867 Window* window = GetWindowByServerId(window_id); |
| 902 if (!window) | 868 if (!window) |
| 903 return; | 869 return; |
| 904 | 870 |
| 905 InFlightPropertyChange new_change(window, name, new_data); | 871 InFlightPropertyChange new_change(window, name, new_data); |
| 906 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 872 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 907 return; | 873 return; |
| 908 | 874 |
| 909 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); | 875 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); |
| 910 } | 876 } |
| 911 | 877 |
| 912 void WindowTreeClientImpl::OnWindowInputEvent(uint32_t event_id, | 878 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| 913 Id window_id, | 879 Id window_id, |
| 914 mojom::EventPtr event, | 880 mojom::EventPtr event, |
| 915 uint32_t event_observer_id) { | 881 uint32_t event_observer_id) { |
| 916 std::unique_ptr<ui::Event> ui_event = event.To<std::unique_ptr<ui::Event>>(); | 882 std::unique_ptr<ui::Event> ui_event = event.To<std::unique_ptr<ui::Event>>(); |
| 917 Window* window = GetWindowByServerId(window_id); // May be null. | 883 Window* window = GetWindowByServerId(window_id); // May be null. |
| 918 | 884 |
| 919 // Non-zero event_observer_id means it matched an event observer on the | 885 // Non-zero event_observer_id means it matched an event observer on the |
| 920 // server. | 886 // server. |
| 921 if (event_observer_id != 0 && has_event_observer_ && | 887 if (event_observer_id != 0 && has_event_observer_ && |
| 922 event_observer_id == event_observer_id_) | 888 event_observer_id == event_observer_id_) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 933 base::Unretained(tree_), event_id))); | 899 base::Unretained(tree_), event_id))); |
| 934 window->input_event_handler_->OnWindowInputEvent( | 900 window->input_event_handler_->OnWindowInputEvent( |
| 935 window, *event.To<std::unique_ptr<ui::Event>>().get(), &ack_callback); | 901 window, *event.To<std::unique_ptr<ui::Event>>().get(), &ack_callback); |
| 936 | 902 |
| 937 // The handler did not take ownership of the callback, so we send the ack, | 903 // The handler did not take ownership of the callback, so we send the ack, |
| 938 // marking the event as not consumed. | 904 // marking the event as not consumed. |
| 939 if (ack_callback) | 905 if (ack_callback) |
| 940 ack_callback->Run(mojom::EventResult::UNHANDLED); | 906 ack_callback->Run(mojom::EventResult::UNHANDLED); |
| 941 } | 907 } |
| 942 | 908 |
| 943 void WindowTreeClientImpl::OnEventObserved(mojom::EventPtr event, | 909 void WindowTreeClient::OnEventObserved(mojom::EventPtr event, |
| 944 uint32_t event_observer_id) { | 910 uint32_t event_observer_id) { |
| 945 if (has_event_observer_ && event_observer_id == event_observer_id_) { | 911 if (has_event_observer_ && event_observer_id == event_observer_id_) { |
| 946 std::unique_ptr<ui::Event> ui_event = | 912 std::unique_ptr<ui::Event> ui_event = |
| 947 event.To<std::unique_ptr<ui::Event>>(); | 913 event.To<std::unique_ptr<ui::Event>>(); |
| 948 delegate_->OnEventObserved(*ui_event, nullptr /* target */); | 914 delegate_->OnEventObserved(*ui_event, nullptr /* target */); |
| 949 } | 915 } |
| 950 } | 916 } |
| 951 | 917 |
| 952 void WindowTreeClientImpl::OnWindowFocused(Id focused_window_id) { | 918 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { |
| 953 Window* focused_window = GetWindowByServerId(focused_window_id); | 919 Window* focused_window = GetWindowByServerId(focused_window_id); |
| 954 InFlightFocusChange new_change(this, focused_window); | 920 InFlightFocusChange new_change(this, focused_window); |
| 955 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 921 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 956 return; | 922 return; |
| 957 | 923 |
| 958 LocalSetFocus(focused_window); | 924 LocalSetFocus(focused_window); |
| 959 } | 925 } |
| 960 | 926 |
| 961 void WindowTreeClientImpl::OnWindowPredefinedCursorChanged( | 927 void WindowTreeClient::OnWindowPredefinedCursorChanged( |
| 962 Id window_id, | 928 Id window_id, |
| 963 mojom::Cursor cursor) { | 929 mojom::Cursor cursor) { |
| 964 Window* window = GetWindowByServerId(window_id); | 930 Window* window = GetWindowByServerId(window_id); |
| 965 if (!window) | 931 if (!window) |
| 966 return; | 932 return; |
| 967 | 933 |
| 968 InFlightPredefinedCursorChange new_change(window, cursor); | 934 InFlightPredefinedCursorChange new_change(window, cursor); |
| 969 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 935 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 970 return; | 936 return; |
| 971 | 937 |
| 972 WindowPrivate(window).LocalSetPredefinedCursor(cursor); | 938 WindowPrivate(window).LocalSetPredefinedCursor(cursor); |
| 973 } | 939 } |
| 974 | 940 |
| 975 void WindowTreeClientImpl::OnChangeCompleted(uint32_t change_id, bool success) { | 941 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
| 976 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 942 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 977 in_flight_map_.erase(change_id); | 943 in_flight_map_.erase(change_id); |
| 978 if (!change) | 944 if (!change) |
| 979 return; | 945 return; |
| 980 | 946 |
| 981 if (!success) | 947 if (!success) |
| 982 change->ChangeFailed(); | 948 change->ChangeFailed(); |
| 983 | 949 |
| 984 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); | 950 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); |
| 985 if (next_change) { | 951 if (next_change) { |
| 986 if (!success) | 952 if (!success) |
| 987 next_change->SetRevertValueFrom(*change); | 953 next_change->SetRevertValueFrom(*change); |
| 988 } else if (!success) { | 954 } else if (!success) { |
| 989 change->Revert(); | 955 change->Revert(); |
| 990 } | 956 } |
| 991 } | 957 } |
| 992 | 958 |
| 993 void WindowTreeClientImpl::GetWindowManager( | 959 void WindowTreeClient::GetWindowManager( |
| 994 mojo::AssociatedInterfaceRequest<WindowManager> internal) { | 960 mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
| 995 window_manager_internal_.reset( | 961 window_manager_internal_.reset( |
| 996 new mojo::AssociatedBinding<mojom::WindowManager>(this, | 962 new mojo::AssociatedBinding<mojom::WindowManager>(this, |
| 997 std::move(internal))); | 963 std::move(internal))); |
| 998 } | 964 } |
| 999 | 965 |
| 1000 void WindowTreeClientImpl::RequestClose(uint32_t window_id) { | 966 void WindowTreeClient::RequestClose(uint32_t window_id) { |
| 1001 Window* window = GetWindowByServerId(window_id); | 967 Window* window = GetWindowByServerId(window_id); |
| 1002 if (!window || !IsRoot(window)) | 968 if (!window || !IsRoot(window)) |
| 1003 return; | 969 return; |
| 1004 | 970 |
| 1005 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), | 971 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), |
| 1006 OnRequestClose(window)); | 972 OnRequestClose(window)); |
| 1007 } | 973 } |
| 1008 | 974 |
| 1009 void WindowTreeClientImpl::WmSetBounds(uint32_t change_id, | 975 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1010 Id window_id, | 976 Id window_id, |
| 1011 const gfx::Rect& transit_bounds) { | 977 const gfx::Rect& transit_bounds) { |
| 1012 Window* window = GetWindowByServerId(window_id); | 978 Window* window = GetWindowByServerId(window_id); |
| 1013 bool result = false; | 979 bool result = false; |
| 1014 if (window) { | 980 if (window) { |
| 1015 DCHECK(window_manager_delegate_); | 981 DCHECK(window_manager_delegate_); |
| 1016 gfx::Rect bounds = transit_bounds; | 982 gfx::Rect bounds = transit_bounds; |
| 1017 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); | 983 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); |
| 1018 if (result) { | 984 if (result) { |
| 1019 // If the resulting bounds differ return false. Returning false ensures | 985 // If the resulting bounds differ return false. Returning false ensures |
| 1020 // the client applies the bounds we set below. | 986 // the client applies the bounds we set below. |
| 1021 result = bounds == transit_bounds; | 987 result = bounds == transit_bounds; |
| 1022 window->SetBounds(bounds); | 988 window->SetBounds(bounds); |
| 1023 } | 989 } |
| 1024 } | 990 } |
| 1025 if (window_manager_internal_client_) | 991 if (window_manager_internal_client_) |
| 1026 window_manager_internal_client_->WmResponse(change_id, result); | 992 window_manager_internal_client_->WmResponse(change_id, result); |
| 1027 } | 993 } |
| 1028 | 994 |
| 1029 void WindowTreeClientImpl::WmSetProperty(uint32_t change_id, | 995 void WindowTreeClient::WmSetProperty(uint32_t change_id, |
| 1030 Id window_id, | 996 Id window_id, |
| 1031 const mojo::String& name, | 997 const mojo::String& name, |
| 1032 mojo::Array<uint8_t> transit_data) { | 998 mojo::Array<uint8_t> transit_data) { |
| 1033 Window* window = GetWindowByServerId(window_id); | 999 Window* window = GetWindowByServerId(window_id); |
| 1034 bool result = false; | 1000 bool result = false; |
| 1035 if (window) { | 1001 if (window) { |
| 1036 DCHECK(window_manager_delegate_); | 1002 DCHECK(window_manager_delegate_); |
| 1037 std::unique_ptr<std::vector<uint8_t>> data; | 1003 std::unique_ptr<std::vector<uint8_t>> data; |
| 1038 if (!transit_data.is_null()) { | 1004 if (!transit_data.is_null()) { |
| 1039 data.reset( | 1005 data.reset( |
| 1040 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); | 1006 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); |
| 1041 } | 1007 } |
| 1042 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); | 1008 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); |
| 1043 if (result) { | 1009 if (result) { |
| 1044 // If the resulting bounds differ return false. Returning false ensures | 1010 // If the resulting bounds differ return false. Returning false ensures |
| 1045 // the client applies the bounds we set below. | 1011 // the client applies the bounds we set below. |
| 1046 window->SetSharedPropertyInternal(name, data.get()); | 1012 window->SetSharedPropertyInternal(name, data.get()); |
| 1047 } | 1013 } |
| 1048 } | 1014 } |
| 1049 if (window_manager_internal_client_) | 1015 if (window_manager_internal_client_) |
| 1050 window_manager_internal_client_->WmResponse(change_id, result); | 1016 window_manager_internal_client_->WmResponse(change_id, result); |
| 1051 } | 1017 } |
| 1052 | 1018 |
| 1053 void WindowTreeClientImpl::WmCreateTopLevelWindow( | 1019 void WindowTreeClient::WmCreateTopLevelWindow( |
| 1054 uint32_t change_id, | 1020 uint32_t change_id, |
| 1055 ClientSpecificId requesting_client_id, | 1021 ClientSpecificId requesting_client_id, |
| 1056 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 1022 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
| 1057 std::map<std::string, std::vector<uint8_t>> properties = | 1023 std::map<std::string, std::vector<uint8_t>> properties = |
| 1058 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1024 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| 1059 Window* window = | 1025 Window* window = |
| 1060 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); | 1026 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); |
| 1061 embedded_windows_[requesting_client_id].insert(window); | 1027 embedded_windows_[requesting_client_id].insert(window); |
| 1062 if (window_manager_internal_client_) { | 1028 if (window_manager_internal_client_) { |
| 1063 window_manager_internal_client_->OnWmCreatedTopLevelWindow( | 1029 window_manager_internal_client_->OnWmCreatedTopLevelWindow( |
| 1064 change_id, server_id(window)); | 1030 change_id, server_id(window)); |
| 1065 } | 1031 } |
| 1066 } | 1032 } |
| 1067 | 1033 |
| 1068 void WindowTreeClientImpl::WmClientJankinessChanged(ClientSpecificId client_id, | 1034 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
| 1069 bool janky) { | 1035 bool janky) { |
| 1070 if (window_manager_delegate_) { | 1036 if (window_manager_delegate_) { |
| 1071 auto it = embedded_windows_.find(client_id); | 1037 auto it = embedded_windows_.find(client_id); |
| 1072 CHECK(it != embedded_windows_.end()); | 1038 CHECK(it != embedded_windows_.end()); |
| 1073 window_manager_delegate_->OnWmClientJankinessChanged( | 1039 window_manager_delegate_->OnWmClientJankinessChanged( |
| 1074 embedded_windows_[client_id], janky); | 1040 embedded_windows_[client_id], janky); |
| 1075 } | 1041 } |
| 1076 } | 1042 } |
| 1077 | 1043 |
| 1078 void WindowTreeClientImpl::OnAccelerator(uint32_t id, mojom::EventPtr event) { | 1044 void WindowTreeClient::OnAccelerator(uint32_t id, mojom::EventPtr event) { |
| 1079 window_manager_delegate_->OnAccelerator( | 1045 window_manager_delegate_->OnAccelerator( |
| 1080 id, *event.To<std::unique_ptr<ui::Event>>().get()); | 1046 id, *event.To<std::unique_ptr<ui::Event>>().get()); |
| 1081 } | 1047 } |
| 1082 | 1048 |
| 1083 void WindowTreeClientImpl::SetFrameDecorationValues( | 1049 void WindowTreeClient::SetFrameDecorationValues( |
| 1084 mojom::FrameDecorationValuesPtr values) { | 1050 mojom::FrameDecorationValuesPtr values) { |
| 1085 if (window_manager_internal_client_) { | 1051 if (window_manager_internal_client_) { |
| 1086 window_manager_internal_client_->WmSetFrameDecorationValues( | 1052 window_manager_internal_client_->WmSetFrameDecorationValues( |
| 1087 std::move(values)); | 1053 std::move(values)); |
| 1088 } | 1054 } |
| 1089 } | 1055 } |
| 1090 | 1056 |
| 1091 void WindowTreeClientImpl::SetNonClientCursor(Window* window, | 1057 void WindowTreeClient::SetNonClientCursor(Window* window, |
| 1092 mus::mojom::Cursor cursor_id) { | 1058 mus::mojom::Cursor cursor_id) { |
| 1093 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), | 1059 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), |
| 1094 cursor_id); | 1060 cursor_id); |
| 1095 } | 1061 } |
| 1096 | 1062 |
| 1097 void WindowTreeClientImpl::AddAccelerator( | 1063 void WindowTreeClient::AddAccelerator( |
| 1098 uint32_t id, | 1064 uint32_t id, |
| 1099 mojom::EventMatcherPtr event_matcher, | 1065 mojom::EventMatcherPtr event_matcher, |
| 1100 const base::Callback<void(bool)>& callback) { | 1066 const base::Callback<void(bool)>& callback) { |
| 1101 if (window_manager_internal_client_) { | 1067 if (window_manager_internal_client_) { |
| 1102 window_manager_internal_client_->AddAccelerator( | 1068 window_manager_internal_client_->AddAccelerator( |
| 1103 id, std::move(event_matcher), callback); | 1069 id, std::move(event_matcher), callback); |
| 1104 } | 1070 } |
| 1105 } | 1071 } |
| 1106 | 1072 |
| 1107 void WindowTreeClientImpl::RemoveAccelerator(uint32_t id) { | 1073 void WindowTreeClient::RemoveAccelerator(uint32_t id) { |
| 1108 if (window_manager_internal_client_) { | 1074 if (window_manager_internal_client_) { |
| 1109 window_manager_internal_client_->RemoveAccelerator(id); | 1075 window_manager_internal_client_->RemoveAccelerator(id); |
| 1110 } | 1076 } |
| 1111 } | 1077 } |
| 1112 | 1078 |
| 1113 void WindowTreeClientImpl::AddActivationParent(Window* window) { | 1079 void WindowTreeClient::AddActivationParent(Window* window) { |
| 1114 if (window_manager_internal_client_) | 1080 if (window_manager_internal_client_) |
| 1115 window_manager_internal_client_->AddActivationParent(server_id(window)); | 1081 window_manager_internal_client_->AddActivationParent(server_id(window)); |
| 1116 } | 1082 } |
| 1117 | 1083 |
| 1118 void WindowTreeClientImpl::RemoveActivationParent(Window* window) { | 1084 void WindowTreeClient::RemoveActivationParent(Window* window) { |
| 1119 if (window_manager_internal_client_) | 1085 if (window_manager_internal_client_) |
| 1120 window_manager_internal_client_->RemoveActivationParent(server_id(window)); | 1086 window_manager_internal_client_->RemoveActivationParent(server_id(window)); |
| 1121 } | 1087 } |
| 1122 | 1088 |
| 1123 void WindowTreeClientImpl::ActivateNextWindow() { | 1089 void WindowTreeClient::ActivateNextWindow() { |
| 1124 if (window_manager_internal_client_) | 1090 if (window_manager_internal_client_) |
| 1125 window_manager_internal_client_->ActivateNextWindow(); | 1091 window_manager_internal_client_->ActivateNextWindow(); |
| 1126 } | 1092 } |
| 1127 | 1093 |
| 1128 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1094 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1129 Window* window, | 1095 Window* window, |
| 1130 const gfx::Vector2d& offset, | 1096 const gfx::Vector2d& offset, |
| 1131 const gfx::Insets& hit_area) { | 1097 const gfx::Insets& hit_area) { |
| 1132 if (window_manager_internal_client_) { | 1098 if (window_manager_internal_client_) { |
| 1133 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1099 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1134 server_id(window), offset.x(), offset.y(), hit_area); | 1100 server_id(window), offset.x(), offset.y(), hit_area); |
| 1135 } | 1101 } |
| 1136 } | 1102 } |
| 1137 | 1103 |
| 1138 } // namespace mus | 1104 } // namespace mus |
| OLD | NEW |