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 "ui/aura/mus/window_tree_client.h" | 5 #include "ui/aura/mus/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> |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 void WindowTreeClient::RegisterWindowMus(WindowMus* window) { | 289 void WindowTreeClient::RegisterWindowMus(WindowMus* window) { |
290 DCHECK(windows_.find(window->server_id()) == windows_.end()); | 290 DCHECK(windows_.find(window->server_id()) == windows_.end()); |
291 windows_[window->server_id()] = window; | 291 windows_[window->server_id()] = window; |
292 } | 292 } |
293 | 293 |
294 WindowMus* WindowTreeClient::GetWindowByServerId(Id id) { | 294 WindowMus* WindowTreeClient::GetWindowByServerId(Id id) { |
295 IdToWindowMap::const_iterator it = windows_.find(id); | 295 IdToWindowMap::const_iterator it = windows_.find(id); |
296 return it != windows_.end() ? it->second : nullptr; | 296 return it != windows_.end() ? it->second : nullptr; |
297 } | 297 } |
298 | 298 |
| 299 bool WindowTreeClient::IsWindowKnown(aura::Window* window) { |
| 300 WindowMus* window_mus = WindowMus::Get(window); |
| 301 return windows_.count(window_mus->server_id()) > 0; |
| 302 } |
| 303 |
299 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( | 304 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( |
300 const InFlightChange& change) { | 305 const InFlightChange& change) { |
301 for (const auto& pair : in_flight_map_) { | 306 for (const auto& pair : in_flight_map_) { |
302 if (pair.second->window() == change.window() && | 307 if (pair.second->window() == change.window() && |
303 pair.second->change_type() == change.change_type() && | 308 pair.second->change_type() == change.change_type() && |
304 pair.second->Matches(change)) { | 309 pair.second->Matches(change)) { |
305 return pair.second.get(); | 310 return pair.second.get(); |
306 } | 311 } |
307 } | 312 } |
308 return nullptr; | 313 return nullptr; |
(...skipping 13 matching lines...) Expand all Loading... |
322 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); | 327 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); |
323 if (!existing_change) | 328 if (!existing_change) |
324 return false; | 329 return false; |
325 | 330 |
326 existing_change->SetRevertValueFrom(change); | 331 existing_change->SetRevertValueFrom(change); |
327 return true; | 332 return true; |
328 } | 333 } |
329 | 334 |
330 void WindowTreeClient::BuildWindowTree( | 335 void WindowTreeClient::BuildWindowTree( |
331 const std::vector<ui::mojom::WindowDataPtr>& windows) { | 336 const std::vector<ui::mojom::WindowDataPtr>& windows) { |
332 for (const auto& window_data : windows) { | 337 for (const auto& window_data : windows) |
333 WindowMus* parent = window_data->parent_id == kInvalidServerId | 338 CreateOrUpdateWindowFromWindowData(*window_data); |
334 ? nullptr | 339 } |
335 : GetWindowByServerId(window_data->parent_id); | 340 |
336 WindowMus* existing_window = GetWindowByServerId(window_data->window_id); | 341 void WindowTreeClient::CreateOrUpdateWindowFromWindowData( |
337 if (!existing_window) | 342 const ui::mojom::WindowData& window_data) { |
338 NewWindowFromWindowData(parent, window_data); | 343 WindowMus* parent = window_data.parent_id == kInvalidServerId |
339 else if (parent) | 344 ? nullptr |
340 parent->AddChildFromServer(existing_window); | 345 : GetWindowByServerId(window_data.parent_id); |
| 346 WindowMus* window = GetWindowByServerId(window_data.window_id); |
| 347 if (!window) |
| 348 window = NewWindowFromWindowData(parent, window_data); |
| 349 else if (parent) |
| 350 parent->AddChildFromServer(window); |
| 351 |
| 352 if (window_data.transient_parent_id == kInvalidServerId) |
| 353 return; |
| 354 |
| 355 // Adjust the transient parent if necessary. |
| 356 client::TransientWindowClient* transient_window_client = |
| 357 client::GetTransientWindowClient(); |
| 358 Window* existing_transient_parent = |
| 359 transient_window_client->GetTransientParent(window->GetWindow()); |
| 360 WindowMus* new_transient_parent = |
| 361 GetWindowByServerId(window_data.transient_parent_id); |
| 362 if (!new_transient_parent && existing_transient_parent) { |
| 363 WindowMus::Get(existing_transient_parent) |
| 364 ->RemoveTransientChildFromServer(window); |
| 365 } else if (new_transient_parent && |
| 366 new_transient_parent->GetWindow() != existing_transient_parent) { |
| 367 if (existing_transient_parent) { |
| 368 WindowMus::Get(existing_transient_parent) |
| 369 ->RemoveTransientChildFromServer(window); |
| 370 } |
| 371 new_transient_parent->AddTransientChildFromServer(window); |
341 } | 372 } |
342 } | 373 } |
343 | 374 |
344 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus( | 375 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus( |
345 const ui::mojom::WindowDataPtr& window_data, | 376 const ui::mojom::WindowData& window_data, |
346 WindowMusType window_mus_type) { | 377 WindowMusType window_mus_type) { |
347 std::unique_ptr<WindowPortMus> window_port_mus( | 378 std::unique_ptr<WindowPortMus> window_port_mus( |
348 base::MakeUnique<WindowPortMus>(this, window_mus_type)); | 379 base::MakeUnique<WindowPortMus>(this, window_mus_type)); |
349 window_port_mus->set_server_id(window_data->window_id); | 380 window_port_mus->set_server_id(window_data.window_id); |
350 RegisterWindowMus(window_port_mus.get()); | 381 RegisterWindowMus(window_port_mus.get()); |
351 return window_port_mus; | 382 return window_port_mus; |
352 } | 383 } |
353 | 384 |
354 void WindowTreeClient::SetLocalPropertiesFromServerProperties( | 385 void WindowTreeClient::SetLocalPropertiesFromServerProperties( |
355 WindowMus* window, | 386 WindowMus* window, |
356 const ui::mojom::WindowDataPtr& window_data) { | 387 const ui::mojom::WindowData& window_data) { |
357 for (auto& pair : window_data->properties) | 388 for (auto& pair : window_data.properties) |
358 window->SetPropertyFromServer(pair.first, &pair.second); | 389 window->SetPropertyFromServer(pair.first, &pair.second); |
359 } | 390 } |
360 | 391 |
361 std::unique_ptr<WindowTreeHostMus> WindowTreeClient::CreateWindowTreeHost( | 392 std::unique_ptr<WindowTreeHostMus> WindowTreeClient::CreateWindowTreeHost( |
362 WindowMusType window_mus_type, | 393 WindowMusType window_mus_type, |
363 const ui::mojom::WindowDataPtr& window_data, | 394 const ui::mojom::WindowData& window_data, |
364 int64_t display_id) { | 395 int64_t display_id) { |
365 std::unique_ptr<WindowPortMus> window_port = | 396 std::unique_ptr<WindowPortMus> window_port = |
366 CreateWindowPortMus(window_data, window_mus_type); | 397 CreateWindowPortMus(window_data, window_mus_type); |
367 roots_.insert(window_port.get()); | 398 roots_.insert(window_port.get()); |
368 std::unique_ptr<WindowTreeHostMus> window_tree_host = | 399 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
369 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this, | 400 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this, |
370 display_id); | 401 display_id); |
371 if (!window_data.is_null()) { | 402 SetLocalPropertiesFromServerProperties( |
372 SetLocalPropertiesFromServerProperties( | 403 WindowMus::Get(window_tree_host->window()), window_data); |
373 WindowMus::Get(window_tree_host->window()), window_data); | 404 if (window_data.visible) { |
374 if (window_data->visible) { | 405 SetWindowVisibleFromServer(WindowMus::Get(window_tree_host->window()), |
375 SetWindowVisibleFromServer(WindowMus::Get(window_tree_host->window()), | 406 true); |
376 true); | |
377 } | |
378 SetWindowBoundsFromServer(WindowMus::Get(window_tree_host->window()), | |
379 window_data->bounds); | |
380 } | 407 } |
| 408 SetWindowBoundsFromServer(WindowMus::Get(window_tree_host->window()), |
| 409 window_data.bounds); |
381 return window_tree_host; | 410 return window_tree_host; |
382 } | 411 } |
383 | 412 |
384 WindowMus* WindowTreeClient::NewWindowFromWindowData( | 413 WindowMus* WindowTreeClient::NewWindowFromWindowData( |
385 WindowMus* parent, | 414 WindowMus* parent, |
386 const ui::mojom::WindowDataPtr& window_data) { | 415 const ui::mojom::WindowData& window_data) { |
387 // This function is only called for windows coming from other clients. | 416 // This function is only called for windows coming from other clients. |
388 std::unique_ptr<WindowPortMus> window_port_mus( | 417 std::unique_ptr<WindowPortMus> window_port_mus( |
389 CreateWindowPortMus(window_data, WindowMusType::OTHER)); | 418 CreateWindowPortMus(window_data, WindowMusType::OTHER)); |
390 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); | 419 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); |
391 Window* window = new Window(nullptr, std::move(window_port_mus)); | 420 Window* window = new Window(nullptr, std::move(window_port_mus)); |
392 WindowMus* window_mus = window_port_mus_ptr; | 421 WindowMus* window_mus = window_port_mus_ptr; |
393 SetWindowTypeFromProperties(window, window_data->properties); | 422 SetWindowTypeFromProperties(window, window_data.properties); |
394 window->Init(ui::LAYER_NOT_DRAWN); | 423 window->Init(ui::LAYER_NOT_DRAWN); |
395 SetLocalPropertiesFromServerProperties(window_mus, window_data); | 424 SetLocalPropertiesFromServerProperties(window_mus, window_data); |
396 window_mus->SetBoundsFromServer(window_data->bounds); | 425 window_mus->SetBoundsFromServer(window_data.bounds); |
397 if (parent) | 426 if (parent) |
398 parent->AddChildFromServer(window_port_mus_ptr); | 427 parent->AddChildFromServer(window_port_mus_ptr); |
399 if (window_data->visible) | 428 if (window_data.visible) |
400 window_mus->SetVisibleFromServer(true); | 429 window_mus->SetVisibleFromServer(true); |
401 return window_port_mus_ptr; | 430 return window_port_mus_ptr; |
402 } | 431 } |
403 | 432 |
404 void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) { | 433 void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) { |
405 tree_ptr_ = std::move(window_tree_ptr); | 434 tree_ptr_ = std::move(window_tree_ptr); |
406 WindowTreeConnectionEstablished(tree_ptr_.get()); | 435 WindowTreeConnectionEstablished(tree_ptr_.get()); |
407 tree_ptr_->GetCursorLocationMemory( | 436 tree_ptr_->GetCursorLocationMemory( |
408 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, | 437 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, |
409 weak_factory_.GetWeakPtr())); | 438 weak_factory_.GetWeakPtr())); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 int64_t display_id, | 486 int64_t display_id, |
458 Id focused_window_id, | 487 Id focused_window_id, |
459 bool drawn) { | 488 bool drawn) { |
460 // WARNING: this is only called if WindowTreeClient was created as the | 489 // WARNING: this is only called if WindowTreeClient was created as the |
461 // result of an embedding. | 490 // result of an embedding. |
462 client_id_ = client_id; | 491 client_id_ = client_id; |
463 WindowTreeConnectionEstablished(window_tree); | 492 WindowTreeConnectionEstablished(window_tree); |
464 | 493 |
465 DCHECK(roots_.empty()); | 494 DCHECK(roots_.empty()); |
466 std::unique_ptr<WindowTreeHostMus> window_tree_host = | 495 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
467 CreateWindowTreeHost(WindowMusType::EMBED, root_data, display_id); | 496 CreateWindowTreeHost(WindowMusType::EMBED, *root_data, display_id); |
468 | 497 |
469 focus_synchronizer_->SetFocusFromServer( | 498 focus_synchronizer_->SetFocusFromServer( |
470 GetWindowByServerId(focused_window_id)); | 499 GetWindowByServerId(focused_window_id)); |
471 | 500 |
472 delegate_->OnEmbed(std::move(window_tree_host)); | 501 delegate_->OnEmbed(std::move(window_tree_host)); |
473 } | 502 } |
474 | 503 |
475 WindowTreeHostMus* WindowTreeClient::WmNewDisplayAddedImpl( | 504 WindowTreeHostMus* WindowTreeClient::WmNewDisplayAddedImpl( |
476 const display::Display& display, | 505 const display::Display& display, |
477 ui::mojom::WindowDataPtr root_data, | 506 ui::mojom::WindowDataPtr root_data, |
478 bool parent_drawn) { | 507 bool parent_drawn) { |
479 DCHECK(window_manager_delegate_); | 508 DCHECK(window_manager_delegate_); |
480 | 509 |
481 window_manager_delegate_->OnWmWillCreateDisplay(display); | 510 window_manager_delegate_->OnWmWillCreateDisplay(display); |
482 | 511 |
483 std::unique_ptr<WindowTreeHostMus> window_tree_host = | 512 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
484 CreateWindowTreeHost(WindowMusType::DISPLAY, root_data, display.id()); | 513 CreateWindowTreeHost(WindowMusType::DISPLAY, *root_data, display.id()); |
485 | 514 |
486 WindowTreeHostMus* window_tree_host_ptr = window_tree_host.get(); | 515 WindowTreeHostMus* window_tree_host_ptr = window_tree_host.get(); |
487 window_manager_delegate_->OnWmNewDisplay(std::move(window_tree_host), | 516 window_manager_delegate_->OnWmNewDisplay(std::move(window_tree_host), |
488 display); | 517 display); |
489 return window_tree_host_ptr; | 518 return window_tree_host_ptr; |
490 } | 519 } |
491 | 520 |
492 std::unique_ptr<EventResultCallback> | 521 std::unique_ptr<EventResultCallback> |
493 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { | 522 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { |
494 return base::MakeUnique<EventResultCallback>( | 523 return base::MakeUnique<EventResultCallback>( |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 void WindowTreeClient::OnWindowTreeHostCreated( | 1605 void WindowTreeClient::OnWindowTreeHostCreated( |
1577 WindowTreeHostMus* window_tree_host) { | 1606 WindowTreeHostMus* window_tree_host) { |
1578 // All WindowTreeHosts are destroyed before this, so we don't need to unset | 1607 // All WindowTreeHosts are destroyed before this, so we don't need to unset |
1579 // the DragDropClient. | 1608 // the DragDropClient. |
1580 client::SetDragDropClient(window_tree_host->window(), | 1609 client::SetDragDropClient(window_tree_host->window(), |
1581 drag_drop_controller_.get()); | 1610 drag_drop_controller_.get()); |
1582 } | 1611 } |
1583 | 1612 |
1584 void WindowTreeClient::OnTransientChildWindowAdded(Window* parent, | 1613 void WindowTreeClient::OnTransientChildWindowAdded(Window* parent, |
1585 Window* transient_child) { | 1614 Window* transient_child) { |
| 1615 // TransientWindowClient is a singleton and we allow multiple |
| 1616 // WindowTreeClients. Ignore changes to windows we don't know about (assume |
| 1617 // they came from another connection). |
| 1618 if (!IsWindowKnown(parent) || !IsWindowKnown(transient_child)) |
| 1619 return; |
| 1620 |
1586 if (WindowMus::Get(parent)->OnTransientChildAdded( | 1621 if (WindowMus::Get(parent)->OnTransientChildAdded( |
1587 WindowMus::Get(transient_child)) == WindowMus::ChangeSource::SERVER) { | 1622 WindowMus::Get(transient_child)) == WindowMus::ChangeSource::SERVER) { |
1588 return; | 1623 return; |
1589 } | 1624 } |
| 1625 |
1590 // The change originated from client code and needs to be sent to the server. | 1626 // The change originated from client code and needs to be sent to the server. |
1591 DCHECK(tree_); | 1627 DCHECK(tree_); |
1592 WindowMus* parent_mus = WindowMus::Get(parent); | 1628 WindowMus* parent_mus = WindowMus::Get(parent); |
1593 const uint32_t change_id = | 1629 const uint32_t change_id = |
1594 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 1630 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
1595 parent_mus, ChangeType::ADD_TRANSIENT_WINDOW)); | 1631 parent_mus, ChangeType::ADD_TRANSIENT_WINDOW)); |
1596 tree_->AddTransientWindow(change_id, parent_mus->server_id(), | 1632 tree_->AddTransientWindow(change_id, parent_mus->server_id(), |
1597 WindowMus::Get(transient_child)->server_id()); | 1633 WindowMus::Get(transient_child)->server_id()); |
1598 } | 1634 } |
1599 | 1635 |
1600 void WindowTreeClient::OnTransientChildWindowRemoved(Window* parent, | 1636 void WindowTreeClient::OnTransientChildWindowRemoved(Window* parent, |
1601 Window* transient_child) { | 1637 Window* transient_child) { |
| 1638 // See comments in OnTransientChildWindowAdded() for details on early return. |
| 1639 if (!IsWindowKnown(parent) || !IsWindowKnown(transient_child)) |
| 1640 return; |
| 1641 |
1602 if (WindowMus::Get(parent)->OnTransientChildRemoved( | 1642 if (WindowMus::Get(parent)->OnTransientChildRemoved( |
1603 WindowMus::Get(transient_child)) == WindowMus::ChangeSource::SERVER) { | 1643 WindowMus::Get(transient_child)) == WindowMus::ChangeSource::SERVER) { |
1604 return; | 1644 return; |
1605 } | 1645 } |
1606 // The change originated from client code and needs to be sent to the server. | 1646 // The change originated from client code and needs to be sent to the server. |
1607 DCHECK(tree_); | 1647 DCHECK(tree_); |
1608 WindowMus* child_mus = WindowMus::Get(transient_child); | 1648 WindowMus* child_mus = WindowMus::Get(transient_child); |
1609 const uint32_t change_id = | 1649 const uint32_t change_id = |
1610 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 1650 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
1611 child_mus, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT)); | 1651 child_mus, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT)); |
1612 tree_->RemoveTransientWindowFromParent(change_id, child_mus->server_id()); | 1652 tree_->RemoveTransientWindowFromParent(change_id, child_mus->server_id()); |
1613 } | 1653 } |
1614 | 1654 |
1615 void WindowTreeClient::OnWillRestackTransientChildAbove( | 1655 void WindowTreeClient::OnWillRestackTransientChildAbove( |
1616 Window* parent, | 1656 Window* parent, |
1617 Window* transient_child) { | 1657 Window* transient_child) { |
1618 DCHECK(parent->parent()); | 1658 DCHECK(parent->parent()); |
| 1659 // See comments in OnTransientChildWindowAdded() for details on early return. |
| 1660 if (!IsWindowKnown(parent->parent())) |
| 1661 return; |
| 1662 |
1619 DCHECK_EQ(parent->parent(), transient_child->parent()); | 1663 DCHECK_EQ(parent->parent(), transient_child->parent()); |
1620 WindowMus::Get(parent->parent()) | 1664 WindowMus::Get(parent->parent()) |
1621 ->PrepareForTransientRestack(WindowMus::Get(transient_child)); | 1665 ->PrepareForTransientRestack(WindowMus::Get(transient_child)); |
1622 } | 1666 } |
1623 | 1667 |
1624 void WindowTreeClient::OnDidRestackTransientChildAbove( | 1668 void WindowTreeClient::OnDidRestackTransientChildAbove( |
1625 Window* parent, | 1669 Window* parent, |
1626 Window* transient_child) { | 1670 Window* transient_child) { |
1627 DCHECK(parent->parent()); | 1671 DCHECK(parent->parent()); |
| 1672 // See comments in OnTransientChildWindowAdded() for details on early return. |
| 1673 if (!IsWindowKnown(parent->parent())) |
| 1674 return; |
1628 DCHECK_EQ(parent->parent(), transient_child->parent()); | 1675 DCHECK_EQ(parent->parent(), transient_child->parent()); |
1629 WindowMus::Get(parent->parent()) | 1676 WindowMus::Get(parent->parent()) |
1630 ->OnTransientRestackDone(WindowMus::Get(transient_child)); | 1677 ->OnTransientRestackDone(WindowMus::Get(transient_child)); |
1631 } | 1678 } |
1632 | 1679 |
1633 uint32_t WindowTreeClient::CreateChangeIdForDrag(WindowMus* window) { | 1680 uint32_t WindowTreeClient::CreateChangeIdForDrag(WindowMus* window) { |
1634 return ScheduleInFlightChange( | 1681 return ScheduleInFlightChange( |
1635 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); | 1682 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); |
1636 } | 1683 } |
1637 | 1684 |
1638 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { | 1685 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { |
1639 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1686 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
1640 this, capture_synchronizer_.get(), window)); | 1687 this, capture_synchronizer_.get(), window)); |
1641 } | 1688 } |
1642 | 1689 |
1643 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1690 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
1644 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1691 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
1645 this, focus_synchronizer_.get(), window)); | 1692 this, focus_synchronizer_.get(), window)); |
1646 } | 1693 } |
1647 | 1694 |
1648 } // namespace aura | 1695 } // namespace aura |
OLD | NEW |