OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/aura/mus/window_port_mus.h" | 5 #include "ui/aura/mus/window_port_mus.h" |
6 | 6 |
7 #include "ui/aura/client/aura_constants.h" | 7 #include "ui/aura/client/aura_constants.h" |
8 #include "ui/aura/client/transient_window_client.h" | 8 #include "ui/aura/client/transient_window_client.h" |
9 #include "ui/aura/mus/property_converter.h" | 9 #include "ui/aura/mus/property_converter.h" |
10 #include "ui/aura/mus/surface_id_handler.h" | 10 #include "ui/aura/mus/surface_id_handler.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 WindowPortMus::WindowPortMus(WindowTreeClient* client, | 29 WindowPortMus::WindowPortMus(WindowTreeClient* client, |
30 WindowMusType window_mus_type) | 30 WindowMusType window_mus_type) |
31 : WindowMus(window_mus_type), window_tree_client_(client) {} | 31 : WindowMus(window_mus_type), window_tree_client_(client) {} |
32 | 32 |
33 WindowPortMus::~WindowPortMus() { | 33 WindowPortMus::~WindowPortMus() { |
34 if (surface_info_) | 34 if (surface_info_) |
35 SetSurfaceIdFromServer(nullptr); | 35 SetSurfaceIdFromServer(nullptr); |
36 | 36 |
37 window_tree_client_->OnWindowMusDestroyed(this); | 37 // DESTROY is only scheduled from DestroyFromServer(), meaning if DESTROY is |
| 38 // present then the server originated the change. |
| 39 const WindowTreeClient::Origin origin = |
| 40 RemoveChangeByTypeAndData(ServerChangeType::DESTROY, ServerChangeData()) |
| 41 ? WindowTreeClient::Origin::SERVER |
| 42 : WindowTreeClient::Origin::CLIENT; |
| 43 window_tree_client_->OnWindowMusDestroyed(this, origin); |
38 } | 44 } |
39 | 45 |
40 // static | 46 // static |
41 WindowPortMus* WindowPortMus::Get(Window* window) { | 47 WindowPortMus* WindowPortMus::Get(Window* window) { |
42 return static_cast<WindowPortMus*>(WindowPort::Get(window)); | 48 return static_cast<WindowPortMus*>(WindowPort::Get(window)); |
43 } | 49 } |
44 | 50 |
45 void WindowPortMus::SetTextInputState(mojo::TextInputStatePtr state) { | 51 void WindowPortMus::SetTextInputState(mojo::TextInputStatePtr state) { |
46 window_tree_client_->SetWindowTextInputState(this, std::move(state)); | 52 window_tree_client_->SetWindowTextInputState(this, std::move(state)); |
47 } | 53 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 case ServerChangeType::REMOVE: | 122 case ServerChangeType::REMOVE: |
117 case ServerChangeType::REMOVE_TRANSIENT: | 123 case ServerChangeType::REMOVE_TRANSIENT: |
118 case ServerChangeType::REORDER: | 124 case ServerChangeType::REORDER: |
119 if (iter->data.child_id == data.child_id) | 125 if (iter->data.child_id == data.child_id) |
120 break; | 126 break; |
121 continue; | 127 continue; |
122 case ServerChangeType::BOUNDS: | 128 case ServerChangeType::BOUNDS: |
123 if (iter->data.bounds == data.bounds) | 129 if (iter->data.bounds == data.bounds) |
124 break; | 130 break; |
125 continue; | 131 continue; |
| 132 case ServerChangeType::DESTROY: |
| 133 // No extra data for delete. |
| 134 break; |
126 case ServerChangeType::PROPERTY: | 135 case ServerChangeType::PROPERTY: |
127 if (iter->data.property_name == data.property_name) | 136 if (iter->data.property_name == data.property_name) |
128 break; | 137 break; |
129 continue; | 138 continue; |
130 case ServerChangeType::VISIBLE: | 139 case ServerChangeType::VISIBLE: |
131 if (iter->data.visible == data.visible) | 140 if (iter->data.visible == data.visible) |
132 break; | 141 break; |
133 continue; | 142 continue; |
134 } | 143 } |
135 server_changes_.erase(iter); | 144 server_changes_.erase(iter); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 236 } |
228 } | 237 } |
229 WindowPortMus* parent = Get(window_->parent()); | 238 WindowPortMus* parent = Get(window_->parent()); |
230 if (parent && parent->surface_id_handler_) { | 239 if (parent && parent->surface_id_handler_) { |
231 parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, | 240 parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, |
232 &surface_info); | 241 &surface_info); |
233 } | 242 } |
234 surface_info_ = std::move(surface_info); | 243 surface_info_ = std::move(surface_info); |
235 } | 244 } |
236 | 245 |
| 246 void WindowPortMus::DestroyFromServer() { |
| 247 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
| 248 if (window_->parent()) { |
| 249 ServerChangeData data; |
| 250 data.child_id = server_id(); |
| 251 WindowPortMus* parent = Get(window_->parent()); |
| 252 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( |
| 253 parent, ServerChangeType::REMOVE, data); |
| 254 } |
| 255 // NOTE: this can't use ScopedServerChange as |this| is destroyed before the |
| 256 // function returns (ScopedServerChange would attempt to access |this| after |
| 257 // destruction). |
| 258 ScheduleChange(ServerChangeType::DESTROY, ServerChangeData()); |
| 259 delete window_; |
| 260 } |
| 261 |
237 void WindowPortMus::AddTransientChildFromServer(WindowMus* child) { | 262 void WindowPortMus::AddTransientChildFromServer(WindowMus* child) { |
238 ServerChangeData data; | 263 ServerChangeData data; |
239 data.child_id = child->server_id(); | 264 data.child_id = child->server_id(); |
240 ScopedServerChange change(this, ServerChangeType::ADD_TRANSIENT, data); | 265 ScopedServerChange change(this, ServerChangeType::ADD_TRANSIENT, data); |
241 client::GetTransientWindowClient()->AddTransientChild(window_, | 266 client::GetTransientWindowClient()->AddTransientChild(window_, |
242 child->GetWindow()); | 267 child->GetWindow()); |
243 } | 268 } |
244 | 269 |
245 void WindowPortMus::RemoveTransientChildFromServer(WindowMus* child) { | 270 void WindowPortMus::RemoveTransientChildFromServer(WindowMus* child) { |
246 ServerChangeData data; | 271 ServerChangeData data; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 change_data.property_name = | 383 change_data.property_name = |
359 GetPropertyConverter()->GetTransportNameForPropertyKey(key); | 384 GetPropertyConverter()->GetTransportNameForPropertyKey(key); |
360 // TODO(sky): investigate to see if we need to compare data. In particular do | 385 // TODO(sky): investigate to see if we need to compare data. In particular do |
361 // we ever have a case where changing a property cascades into changing the | 386 // we ever have a case where changing a property cascades into changing the |
362 // same property? | 387 // same property? |
363 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 388 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
364 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); | 389 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); |
365 } | 390 } |
366 | 391 |
367 } // namespace aura | 392 } // namespace aura |
OLD | NEW |