Chromium Code Reviews| 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" |
| 11 #include "ui/aura/mus/window_tree_client.h" | 11 #include "ui/aura/mus/window_tree_client.h" |
| 12 #include "ui/aura/mus/window_tree_client_delegate.h" | 12 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_observer.h" | 14 #include "ui/aura/window_observer.h" |
| 15 #include "ui/aura/window_property.h" | 15 #include "ui/aura/window_property.h" |
| 16 | 16 |
| 17 namespace aura { | 17 namespace aura { |
| 18 | 18 |
| 19 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; | 19 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; |
| 20 | 20 |
| 21 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; | 21 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 WindowMus* WindowMus::Get(Window* window) { | 24 WindowMus* WindowMus::Get(Window* window) { |
| 25 return WindowPortMus::Get(window); | 25 return WindowPortMus::Get(window); |
| 26 } | 26 } |
| 27 | 27 |
| 28 WindowPortMus::WindowPortMus(WindowTreeClient* client, | 28 WindowPortMus::WindowPortMus(WindowTreeClient* client, |
| 29 bool create_remote_window) | 29 WindowMusType window_mus_type) |
| 30 : WindowMus(create_remote_window), window_tree_client_(client) {} | 30 : WindowMus(window_mus_type), window_tree_client_(client) {} |
| 31 | 31 |
| 32 WindowPortMus::~WindowPortMus() { | 32 WindowPortMus::~WindowPortMus() { |
| 33 if (surface_info_) | 33 if (surface_info_) |
| 34 SetSurfaceIdFromServer(nullptr); | 34 SetSurfaceIdFromServer(nullptr); |
| 35 | 35 |
| 36 window_tree_client_->OnWindowMusDestroyed(this); | 36 window_tree_client_->OnWindowMusDestroyed(this); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 WindowPortMus* WindowPortMus::Get(Window* window) { | 40 WindowPortMus* WindowPortMus::Get(Window* window) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 113 |
| 114 PropertyConverter* WindowPortMus::GetPropertyConverter() { | 114 PropertyConverter* WindowPortMus::GetPropertyConverter() { |
| 115 return window_tree_client_->delegate_->GetPropertyConverter(); | 115 return window_tree_client_->delegate_->GetPropertyConverter(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 Window* WindowPortMus::GetWindow() { | 118 Window* WindowPortMus::GetWindow() { |
| 119 return window_; | 119 return window_; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void WindowPortMus::AddChildFromServer(WindowMus* window) { | 122 void WindowPortMus::AddChildFromServer(WindowMus* window) { |
| 123 DCHECK(has_server_window()); | |
|
sadrul
2016/11/02 16:03:04
Some of these DCHECK()s should still be OK?
sky
2016/11/02 16:53:23
The DCHECKs were intended to catch the case of win
| |
| 124 ServerChangeData data; | 123 ServerChangeData data; |
| 125 data.child_id = window->server_id(); | 124 data.child_id = window->server_id(); |
| 126 ScopedServerChange change(this, ServerChangeType::ADD, data); | 125 ScopedServerChange change(this, ServerChangeType::ADD, data); |
| 127 window_->AddChild(window->GetWindow()); | 126 window_->AddChild(window->GetWindow()); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void WindowPortMus::RemoveChildFromServer(WindowMus* child) { | 129 void WindowPortMus::RemoveChildFromServer(WindowMus* child) { |
| 131 DCHECK(has_server_window()); | |
| 132 ServerChangeData data; | 130 ServerChangeData data; |
| 133 data.child_id = child->server_id(); | 131 data.child_id = child->server_id(); |
| 134 ScopedServerChange change(this, ServerChangeType::REMOVE, data); | 132 ScopedServerChange change(this, ServerChangeType::REMOVE, data); |
| 135 window_->RemoveChild(child->GetWindow()); | 133 window_->RemoveChild(child->GetWindow()); |
| 136 } | 134 } |
| 137 | 135 |
| 138 void WindowPortMus::ReorderFromServer(WindowMus* child, | 136 void WindowPortMus::ReorderFromServer(WindowMus* child, |
| 139 WindowMus* relative, | 137 WindowMus* relative, |
| 140 ui::mojom::OrderDirection direction) { | 138 ui::mojom::OrderDirection direction) { |
| 141 DCHECK(has_server_window()); | |
| 142 // Keying off solely the id isn't entirely accurate, in so far as if Window | 139 // Keying off solely the id isn't entirely accurate, in so far as if Window |
| 143 // does some other reordering then the server and client are out of sync. | 140 // does some other reordering then the server and client are out of sync. |
| 144 // But we assume only one client can make changes to a particular window at | 141 // But we assume only one client can make changes to a particular window at |
| 145 // a time, so this should be ok. | 142 // a time, so this should be ok. |
| 146 ServerChangeData data; | 143 ServerChangeData data; |
| 147 data.child_id = child->server_id(); | 144 data.child_id = child->server_id(); |
| 148 ScopedServerChange change(this, ServerChangeType::REORDER, data); | 145 ScopedServerChange change(this, ServerChangeType::REORDER, data); |
| 149 if (direction == ui::mojom::OrderDirection::BELOW) | 146 if (direction == ui::mojom::OrderDirection::BELOW) |
| 150 window_->StackChildBelow(child->GetWindow(), relative->GetWindow()); | 147 window_->StackChildBelow(child->GetWindow(), relative->GetWindow()); |
| 151 else | 148 else |
| 152 window_->StackChildAbove(child->GetWindow(), relative->GetWindow()); | 149 window_->StackChildAbove(child->GetWindow(), relative->GetWindow()); |
| 153 } | 150 } |
| 154 | 151 |
| 155 void WindowPortMus::SetBoundsFromServer(const gfx::Rect& bounds) { | 152 void WindowPortMus::SetBoundsFromServer(const gfx::Rect& bounds) { |
| 156 DCHECK(has_server_window()); | |
| 157 ServerChangeData data; | 153 ServerChangeData data; |
| 158 data.bounds = bounds; | 154 data.bounds = bounds; |
| 159 ScopedServerChange change(this, ServerChangeType::BOUNDS, data); | 155 ScopedServerChange change(this, ServerChangeType::BOUNDS, data); |
| 160 window_->SetBounds(bounds); | 156 window_->SetBounds(bounds); |
| 161 } | 157 } |
| 162 | 158 |
| 163 void WindowPortMus::SetVisibleFromServer(bool visible) { | 159 void WindowPortMus::SetVisibleFromServer(bool visible) { |
| 164 DCHECK(has_server_window()); | |
| 165 ServerChangeData data; | 160 ServerChangeData data; |
| 166 data.visible = visible; | 161 data.visible = visible; |
| 167 ScopedServerChange change(this, ServerChangeType::VISIBLE, data); | 162 ScopedServerChange change(this, ServerChangeType::VISIBLE, data); |
| 168 if (visible) | 163 if (visible) |
| 169 window_->Show(); | 164 window_->Show(); |
| 170 else | 165 else |
| 171 window_->Hide(); | 166 window_->Hide(); |
| 172 } | 167 } |
| 173 | 168 |
| 174 void WindowPortMus::SetOpacityFromServer(float opacity) { | 169 void WindowPortMus::SetOpacityFromServer(float opacity) { |
| 175 // TODO(sky): this may not be necessary anymore. | 170 // TODO(sky): route to server. |
| 176 DCHECK(has_server_window()); | |
| 177 // Changes to opacity don't make it back to the server. | 171 // Changes to opacity don't make it back to the server. |
| 178 window_->layer()->SetOpacity(opacity); | 172 window_->layer()->SetOpacity(opacity); |
| 179 } | 173 } |
| 180 | 174 |
| 181 void WindowPortMus::SetPredefinedCursorFromServer(ui::mojom::Cursor cursor) { | 175 void WindowPortMus::SetPredefinedCursorFromServer(ui::mojom::Cursor cursor) { |
| 182 // As this does nothing more than set the cursor we don't need to use | 176 // As this does nothing more than set the cursor we don't need to use |
| 183 // ServerChange. | 177 // ServerChange. |
| 184 predefined_cursor_ = cursor; | 178 predefined_cursor_ = cursor; |
| 185 } | 179 } |
| 186 | 180 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 209 } | 203 } |
| 210 WindowPortMus* parent = Get(window_->parent()); | 204 WindowPortMus* parent = Get(window_->parent()); |
| 211 if (parent && parent->surface_id_handler_) { | 205 if (parent && parent->surface_id_handler_) { |
| 212 parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, | 206 parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, |
| 213 &surface_info); | 207 &surface_info); |
| 214 } | 208 } |
| 215 surface_info_ = std::move(surface_info); | 209 surface_info_ = std::move(surface_info); |
| 216 } | 210 } |
| 217 | 211 |
| 218 void WindowPortMus::AddTransientChildFromServer(WindowMus* child) { | 212 void WindowPortMus::AddTransientChildFromServer(WindowMus* child) { |
| 219 DCHECK(has_server_window()); | |
| 220 ServerChangeData data; | 213 ServerChangeData data; |
| 221 data.child_id = child->server_id(); | 214 data.child_id = child->server_id(); |
| 222 ScopedServerChange change(this, ServerChangeType::ADD_TRANSIENT, data); | 215 ScopedServerChange change(this, ServerChangeType::ADD_TRANSIENT, data); |
| 223 client::GetTransientWindowClient()->AddTransientChild(window_, | 216 client::GetTransientWindowClient()->AddTransientChild(window_, |
| 224 child->GetWindow()); | 217 child->GetWindow()); |
| 225 } | 218 } |
| 226 | 219 |
| 227 void WindowPortMus::RemoveTransientChildFromServer(WindowMus* child) { | 220 void WindowPortMus::RemoveTransientChildFromServer(WindowMus* child) { |
| 228 DCHECK(has_server_window()); | |
| 229 ServerChangeData data; | 221 ServerChangeData data; |
| 230 data.child_id = child->server_id(); | 222 data.child_id = child->server_id(); |
| 231 ScopedServerChange change(this, ServerChangeType::REMOVE_TRANSIENT, data); | 223 ScopedServerChange change(this, ServerChangeType::REMOVE_TRANSIENT, data); |
| 232 client::GetTransientWindowClient()->RemoveTransientChild(window_, | 224 client::GetTransientWindowClient()->RemoveTransientChild(window_, |
| 233 child->GetWindow()); | 225 child->GetWindow()); |
| 234 } | 226 } |
| 235 | 227 |
| 236 WindowPortMus::ChangeSource WindowPortMus::OnTransientChildAdded( | 228 WindowPortMus::ChangeSource WindowPortMus::OnTransientChildAdded( |
| 237 WindowMus* child) { | 229 WindowMus* child) { |
| 238 DCHECK(has_server_window()); | |
| 239 ServerChangeData change_data; | 230 ServerChangeData change_data; |
| 240 change_data.child_id = child->server_id(); | 231 change_data.child_id = child->server_id(); |
| 241 // If there was a change it means we scheduled the change by way of | 232 // If there was a change it means we scheduled the change by way of |
| 242 // AddTransientChildFromServer(), which came from the server. | 233 // AddTransientChildFromServer(), which came from the server. |
| 243 return RemoveChangeByTypeAndData(ServerChangeType::ADD_TRANSIENT, change_data) | 234 return RemoveChangeByTypeAndData(ServerChangeType::ADD_TRANSIENT, change_data) |
| 244 ? ChangeSource::SERVER | 235 ? ChangeSource::SERVER |
| 245 : ChangeSource::LOCAL; | 236 : ChangeSource::LOCAL; |
| 246 } | 237 } |
| 247 | 238 |
| 248 WindowPortMus::ChangeSource WindowPortMus::OnTransientChildRemoved( | 239 WindowPortMus::ChangeSource WindowPortMus::OnTransientChildRemoved( |
| 249 WindowMus* child) { | 240 WindowMus* child) { |
| 250 DCHECK(has_server_window()); | |
| 251 ServerChangeData change_data; | 241 ServerChangeData change_data; |
| 252 change_data.child_id = child->server_id(); | 242 change_data.child_id = child->server_id(); |
| 253 // If there was a change it means we scheduled the change by way of | 243 // If there was a change it means we scheduled the change by way of |
| 254 // RemoveTransientChildFromServer(), which came from the server. | 244 // RemoveTransientChildFromServer(), which came from the server. |
| 255 return RemoveChangeByTypeAndData(ServerChangeType::REMOVE_TRANSIENT, | 245 return RemoveChangeByTypeAndData(ServerChangeType::REMOVE_TRANSIENT, |
| 256 change_data) | 246 change_data) |
| 257 ? ChangeSource::SERVER | 247 ? ChangeSource::SERVER |
| 258 : ChangeSource::LOCAL; | 248 : ChangeSource::LOCAL; |
| 259 } | 249 } |
| 260 | 250 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 278 data->change = base::MakeUnique<ScopedServerChange>( | 268 data->change = base::MakeUnique<ScopedServerChange>( |
| 279 this, ServerChangeType::VISIBLE, change_data); | 269 this, ServerChangeType::VISIBLE, change_data); |
| 280 return std::move(data); | 270 return std::move(data); |
| 281 } | 271 } |
| 282 | 272 |
| 283 void WindowPortMus::NotifyEmbeddedAppDisconnected() { | 273 void WindowPortMus::NotifyEmbeddedAppDisconnected() { |
| 284 for (WindowObserver& observer : *GetObservers(window_)) | 274 for (WindowObserver& observer : *GetObservers(window_)) |
| 285 observer.OnEmbeddedAppDisconnected(window_); | 275 observer.OnEmbeddedAppDisconnected(window_); |
| 286 } | 276 } |
| 287 | 277 |
| 288 std::unique_ptr<WindowPortInitData> WindowPortMus::OnPreInit(Window* window) { | 278 void WindowPortMus::OnPreInit(Window* window) { |
| 289 window_ = window; | 279 window_ = window; |
| 290 return window_tree_client_->OnWindowMusCreated(this); | 280 window_tree_client_->OnWindowMusCreated(this); |
| 291 } | |
| 292 | |
| 293 void WindowPortMus::OnPostInit(std::unique_ptr<WindowPortInitData> init_data) { | |
| 294 window_tree_client_->OnWindowMusInitDone(this, std::move(init_data)); | |
| 295 } | 281 } |
| 296 | 282 |
| 297 void WindowPortMus::OnDeviceScaleFactorChanged(float device_scale_factor) {} | 283 void WindowPortMus::OnDeviceScaleFactorChanged(float device_scale_factor) {} |
| 298 | 284 |
| 299 void WindowPortMus::OnWillAddChild(Window* child) { | 285 void WindowPortMus::OnWillAddChild(Window* child) { |
| 300 if (!has_server_window()) | |
| 301 return; | |
| 302 | |
| 303 ServerChangeData change_data; | 286 ServerChangeData change_data; |
| 304 change_data.child_id = Get(child)->server_id(); | 287 change_data.child_id = Get(child)->server_id(); |
| 305 if (!RemoveChangeByTypeAndData(ServerChangeType::ADD, change_data)) | 288 if (!RemoveChangeByTypeAndData(ServerChangeType::ADD, change_data)) |
| 306 window_tree_client_->OnWindowMusAddChild(this, Get(child)); | 289 window_tree_client_->OnWindowMusAddChild(this, Get(child)); |
| 307 } | 290 } |
| 308 | 291 |
| 309 void WindowPortMus::OnWillRemoveChild(Window* child) { | 292 void WindowPortMus::OnWillRemoveChild(Window* child) { |
| 310 if (!has_server_window()) | |
| 311 return; | |
| 312 | |
| 313 ServerChangeData change_data; | 293 ServerChangeData change_data; |
| 314 change_data.child_id = Get(child)->server_id(); | 294 change_data.child_id = Get(child)->server_id(); |
| 315 if (!RemoveChangeByTypeAndData(ServerChangeType::REMOVE, change_data)) | 295 if (!RemoveChangeByTypeAndData(ServerChangeType::REMOVE, change_data)) |
| 316 window_tree_client_->OnWindowMusRemoveChild(this, Get(child)); | 296 window_tree_client_->OnWindowMusRemoveChild(this, Get(child)); |
| 317 } | 297 } |
| 318 | 298 |
| 319 void WindowPortMus::OnWillMoveChild(size_t current_index, size_t dest_index) { | 299 void WindowPortMus::OnWillMoveChild(size_t current_index, size_t dest_index) { |
| 320 if (!has_server_window()) | |
| 321 return; | |
| 322 | |
| 323 ServerChangeData change_data; | 300 ServerChangeData change_data; |
| 324 change_data.child_id = Get(window_->children()[current_index])->server_id(); | 301 change_data.child_id = Get(window_->children()[current_index])->server_id(); |
| 325 if (!RemoveChangeByTypeAndData(ServerChangeType::REORDER, change_data)) | 302 if (!RemoveChangeByTypeAndData(ServerChangeType::REORDER, change_data)) |
| 326 window_tree_client_->OnWindowMusMoveChild(this, current_index, dest_index); | 303 window_tree_client_->OnWindowMusMoveChild(this, current_index, dest_index); |
| 327 } | 304 } |
| 328 | 305 |
| 329 void WindowPortMus::OnVisibilityChanged(bool visible) { | 306 void WindowPortMus::OnVisibilityChanged(bool visible) { |
| 330 if (!has_server_window()) | |
| 331 return; | |
| 332 | |
| 333 ServerChangeData change_data; | 307 ServerChangeData change_data; |
| 334 change_data.visible = visible; | 308 change_data.visible = visible; |
| 335 if (!RemoveChangeByTypeAndData(ServerChangeType::VISIBLE, change_data)) | 309 if (!RemoveChangeByTypeAndData(ServerChangeType::VISIBLE, change_data)) |
| 336 window_tree_client_->OnWindowMusSetVisible(this, visible); | 310 window_tree_client_->OnWindowMusSetVisible(this, visible); |
| 337 } | 311 } |
| 338 | 312 |
| 339 void WindowPortMus::OnDidChangeBounds(const gfx::Rect& old_bounds, | 313 void WindowPortMus::OnDidChangeBounds(const gfx::Rect& old_bounds, |
| 340 const gfx::Rect& new_bounds) { | 314 const gfx::Rect& new_bounds) { |
| 341 if (!has_server_window()) | |
| 342 return; | |
| 343 | |
| 344 ServerChangeData change_data; | 315 ServerChangeData change_data; |
| 345 change_data.bounds = new_bounds; | 316 change_data.bounds = new_bounds; |
| 346 if (!RemoveChangeByTypeAndData(ServerChangeType::BOUNDS, change_data)) | 317 if (!RemoveChangeByTypeAndData(ServerChangeType::BOUNDS, change_data)) |
| 347 window_tree_client_->OnWindowMusBoundsChanged(this, old_bounds, new_bounds); | 318 window_tree_client_->OnWindowMusBoundsChanged(this, old_bounds, new_bounds); |
| 348 } | 319 } |
| 349 | 320 |
| 350 std::unique_ptr<WindowPortPropertyData> WindowPortMus::OnWillChangeProperty( | 321 std::unique_ptr<WindowPortPropertyData> WindowPortMus::OnWillChangeProperty( |
| 351 const void* key) { | 322 const void* key) { |
| 352 if (!has_server_window()) | |
| 353 return nullptr; | |
| 354 | |
| 355 return window_tree_client_->OnWindowMusWillChangeProperty(this, key); | 323 return window_tree_client_->OnWindowMusWillChangeProperty(this, key); |
| 356 } | 324 } |
| 357 | 325 |
| 358 void WindowPortMus::OnPropertyChanged( | 326 void WindowPortMus::OnPropertyChanged( |
| 359 const void* key, | 327 const void* key, |
| 360 std::unique_ptr<WindowPortPropertyData> data) { | 328 std::unique_ptr<WindowPortPropertyData> data) { |
| 361 if (!has_server_window()) | |
| 362 return; | |
| 363 | |
| 364 ServerChangeData change_data; | 329 ServerChangeData change_data; |
| 365 change_data.property_name = | 330 change_data.property_name = |
| 366 GetPropertyConverter()->GetTransportNameForPropertyKey(key); | 331 GetPropertyConverter()->GetTransportNameForPropertyKey(key); |
| 367 // TODO(sky): investigate to see if we need to compare data. In particular do | 332 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 368 // we ever have a case where changing a property cascades into changing the | 333 // we ever have a case where changing a property cascades into changing the |
| 369 // same property? | 334 // same property? |
| 370 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 335 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 371 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); | 336 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); |
| 372 } | 337 } |
| 373 | 338 |
| 374 } // namespace aura | 339 } // namespace aura |
| OLD | NEW |