| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #undef LoWord | 48 #undef LoWord |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 namespace aura { | 51 namespace aura { |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { | 54 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { |
| 55 return (client_id << 16) | local_id; | 55 return (client_id << 16) | local_id; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool ShouldCreateTopLevel(ui::wm::WindowType type) { | |
| 59 switch (type) { | |
| 60 case ui::wm::WINDOW_TYPE_CONTROL: | |
| 61 case ui::wm::WINDOW_TYPE_UNKNOWN: | |
| 62 return false; | |
| 63 | |
| 64 case ui::wm::WINDOW_TYPE_NORMAL: | |
| 65 case ui::wm::WINDOW_TYPE_POPUP: | |
| 66 case ui::wm::WINDOW_TYPE_PANEL: | |
| 67 case ui::wm::WINDOW_TYPE_MENU: | |
| 68 case ui::wm::WINDOW_TYPE_TOOLTIP: | |
| 69 break; | |
| 70 } | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 inline uint16_t HiWord(uint32_t id) { | 58 inline uint16_t HiWord(uint32_t id) { |
| 75 return static_cast<uint16_t>((id >> 16) & 0xFFFF); | 59 return static_cast<uint16_t>((id >> 16) & 0xFFFF); |
| 76 } | 60 } |
| 77 | 61 |
| 78 inline uint16_t LoWord(uint32_t id) { | 62 inline uint16_t LoWord(uint32_t id) { |
| 79 return static_cast<uint16_t>(id & 0xFFFF); | 63 return static_cast<uint16_t>(id & 0xFFFF); |
| 80 } | 64 } |
| 81 | 65 |
| 82 struct WindowPortPropertyDataMus : public WindowPortPropertyData { | 66 struct WindowPortPropertyDataMus : public WindowPortPropertyData { |
| 83 std::string transport_name; | 67 std::string transport_name; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 DCHECK(window_manager_delegate_); | 194 DCHECK(window_manager_delegate_); |
| 211 | 195 |
| 212 ui::mojom::WindowManagerWindowTreeFactoryPtr factory; | 196 ui::mojom::WindowManagerWindowTreeFactoryPtr factory; |
| 213 connector->ConnectToInterface("service:ui", &factory); | 197 connector->ConnectToInterface("service:ui", &factory); |
| 214 ui::mojom::WindowTreePtr window_tree; | 198 ui::mojom::WindowTreePtr window_tree; |
| 215 factory->CreateWindowTree(GetProxy(&window_tree), | 199 factory->CreateWindowTree(GetProxy(&window_tree), |
| 216 binding_.CreateInterfacePtrAndBind()); | 200 binding_.CreateInterfacePtrAndBind()); |
| 217 SetWindowTree(std::move(window_tree)); | 201 SetWindowTree(std::move(window_tree)); |
| 218 } | 202 } |
| 219 | 203 |
| 220 void WindowTreeClient::WaitForEmbed() { | |
| 221 DCHECK(roots_.empty()); | |
| 222 // OnEmbed() is the first function called. | |
| 223 binding_.WaitForIncomingMethodCall(); | |
| 224 // TODO(sky): deal with pipe being closed before we get OnEmbed(). | |
| 225 } | |
| 226 | |
| 227 void WindowTreeClient::SetClientArea( | 204 void WindowTreeClient::SetClientArea( |
| 228 Window* window, | 205 Window* window, |
| 229 const gfx::Insets& client_area, | 206 const gfx::Insets& client_area, |
| 230 const std::vector<gfx::Rect>& additional_client_areas) { | 207 const std::vector<gfx::Rect>& additional_client_areas) { |
| 231 DCHECK(tree_); | 208 DCHECK(tree_); |
| 232 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, | 209 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, |
| 233 additional_client_areas); | 210 additional_client_areas); |
| 234 } | 211 } |
| 235 | 212 |
| 236 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { | 213 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 parents.pop_back(); | 369 parents.pop_back(); |
| 393 } | 370 } |
| 394 // This code is only called in a context where there is a parent. | 371 // This code is only called in a context where there is a parent. |
| 395 DCHECK(!parents.empty()); | 372 DCHECK(!parents.empty()); |
| 396 last_window = NewWindowFromWindowData( | 373 last_window = NewWindowFromWindowData( |
| 397 !parents.empty() ? parents.back() : nullptr, window_data); | 374 !parents.empty() ? parents.back() : nullptr, window_data); |
| 398 } | 375 } |
| 399 } | 376 } |
| 400 | 377 |
| 401 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus( | 378 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus( |
| 402 const ui::mojom::WindowDataPtr& window_data) { | 379 const ui::mojom::WindowDataPtr& window_data, |
| 380 WindowMusType window_mus_type) { |
| 403 std::unique_ptr<WindowPortMus> window_port_mus( | 381 std::unique_ptr<WindowPortMus> window_port_mus( |
| 404 base::MakeUnique<WindowPortMus>(this)); | 382 base::MakeUnique<WindowPortMus>(this, window_mus_type)); |
| 405 window_port_mus->set_server_id(window_data->window_id); | 383 window_port_mus->set_server_id(window_data->window_id); |
| 406 RegisterWindowMus(window_port_mus.get()); | 384 RegisterWindowMus(window_port_mus.get()); |
| 407 return window_port_mus; | 385 return window_port_mus; |
| 408 } | 386 } |
| 409 | 387 |
| 410 void WindowTreeClient::SetLocalPropertiesFromServerProperties( | 388 void WindowTreeClient::SetLocalPropertiesFromServerProperties( |
| 411 WindowMus* window, | 389 WindowMus* window, |
| 412 const ui::mojom::WindowDataPtr& window_data) { | 390 const ui::mojom::WindowDataPtr& window_data) { |
| 413 for (auto& pair : window_data->properties) { | 391 for (auto& pair : window_data->properties) { |
| 414 if (pair.second.is_null()) { | 392 if (pair.second.is_null()) { |
| 415 window->SetPropertyFromServer(pair.first, nullptr); | 393 window->SetPropertyFromServer(pair.first, nullptr); |
| 416 } else { | 394 } else { |
| 417 std::vector<uint8_t> stl_value = pair.second.To<std::vector<uint8_t>>(); | 395 std::vector<uint8_t> stl_value = pair.second.To<std::vector<uint8_t>>(); |
| 418 window->SetPropertyFromServer(pair.first, &stl_value); | 396 window->SetPropertyFromServer(pair.first, &stl_value); |
| 419 } | 397 } |
| 420 } | 398 } |
| 421 } | 399 } |
| 422 | 400 |
| 423 Window* WindowTreeClient::CreateWindowTreeHost( | 401 std::unique_ptr<WindowTreeHostMus> WindowTreeClient::CreateWindowTreeHost( |
| 424 RootWindowType type, | 402 WindowMusType window_mus_type, |
| 425 const ui::mojom::WindowDataPtr& window_data, | 403 const ui::mojom::WindowDataPtr& window_data, |
| 426 int64_t display_id, | 404 int64_t display_id) { |
| 427 Window* content_window) { | 405 std::unique_ptr<WindowPortMus> window_port = |
| 428 Window* user_window = nullptr; | 406 CreateWindowPortMus(window_data, window_mus_type); |
| 429 switch (type) { | 407 roots_.insert(window_port.get()); |
| 430 case RootWindowType::DISPLAY: { | 408 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
| 431 DCHECK(!content_window); | 409 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this, |
| 432 // See WindowTreeHostMus for details on ownership. | 410 display_id); |
| 433 WindowTreeHost* window_tree_host = new WindowTreeHostMus( | 411 if (!window_data.is_null()) { |
| 434 CreateWindowPortMus(window_data), this, type, display_id); | 412 SetLocalPropertiesFromServerProperties( |
| 435 user_window = window_tree_host->window(); | 413 WindowMus::Get(window_tree_host->window()), window_data); |
| 436 break; | |
| 437 } | |
| 438 case RootWindowType::EMBED: { | |
| 439 DCHECK(!content_window); | |
| 440 user_window = new Window(nullptr, CreateWindowPortMus(window_data)); | |
| 441 user_window->Init(ui::LAYER_TEXTURED); | |
| 442 // See WindowTreeHostMus for details on ownership. | |
| 443 new WindowTreeHostMus(base::MakeUnique<WindowPortMus>(this, false), this, | |
| 444 type, display_id, user_window); | |
| 445 break; | |
| 446 } | |
| 447 case RootWindowType::TOP_LEVEL: { | |
| 448 DCHECK(content_window); | |
| 449 user_window = content_window; | |
| 450 // See WindowTreeHostMus for details on ownership. | |
| 451 new WindowTreeHostMus(base::MakeUnique<WindowPortMus>(this, false), this, | |
| 452 type, display_id, user_window); | |
| 453 break; | |
| 454 } | |
| 455 } | 414 } |
| 456 WindowMus* user_window_mus = WindowMus::Get(user_window); | 415 return window_tree_host; |
| 457 roots_.insert(user_window_mus); | |
| 458 if (!window_data.is_null()) | |
| 459 SetLocalPropertiesFromServerProperties(user_window_mus, window_data); | |
| 460 // All WindowTreeHosts are destroyed before this, so we don't need to unset | |
| 461 // the DragDropClient. | |
| 462 client::SetDragDropClient(user_window->GetRootWindow(), | |
| 463 drag_drop_controller_.get()); | |
| 464 return user_window; | |
| 465 } | 416 } |
| 466 | 417 |
| 467 WindowMus* WindowTreeClient::NewWindowFromWindowData( | 418 WindowMus* WindowTreeClient::NewWindowFromWindowData( |
| 468 WindowMus* parent, | 419 WindowMus* parent, |
| 469 const ui::mojom::WindowDataPtr& window_data) { | 420 const ui::mojom::WindowDataPtr& window_data) { |
| 421 // This function is only called for windows coming from other clients. |
| 470 std::unique_ptr<WindowPortMus> window_port_mus( | 422 std::unique_ptr<WindowPortMus> window_port_mus( |
| 471 CreateWindowPortMus(window_data)); | 423 CreateWindowPortMus(window_data, WindowMusType::OTHER)); |
| 472 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); | 424 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); |
| 473 Window* window = new Window(nullptr, std::move(window_port_mus)); | 425 Window* window = new Window(nullptr, std::move(window_port_mus)); |
| 474 WindowMus* window_mus = window_port_mus_ptr; | 426 WindowMus* window_mus = window_port_mus_ptr; |
| 475 window->Init(ui::LAYER_NOT_DRAWN); | 427 window->Init(ui::LAYER_NOT_DRAWN); |
| 476 SetLocalPropertiesFromServerProperties(window_mus, window_data); | 428 SetLocalPropertiesFromServerProperties(window_mus, window_data); |
| 477 window_mus->SetBoundsFromServer(window_data->bounds); | 429 window_mus->SetBoundsFromServer(window_data->bounds); |
| 478 if (parent) | 430 if (parent) |
| 479 parent->AddChildFromServer(window_port_mus_ptr); | 431 parent->AddChildFromServer(window_port_mus_ptr); |
| 480 if (window_data->visible) | 432 if (window_data->visible) |
| 481 window_mus->SetVisibleFromServer(true); | 433 window_mus->SetVisibleFromServer(true); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 ui::mojom::WindowDataPtr root_data, | 488 ui::mojom::WindowDataPtr root_data, |
| 537 int64_t display_id, | 489 int64_t display_id, |
| 538 Id focused_window_id, | 490 Id focused_window_id, |
| 539 bool drawn) { | 491 bool drawn) { |
| 540 // WARNING: this is only called if WindowTreeClient was created as the | 492 // WARNING: this is only called if WindowTreeClient was created as the |
| 541 // result of an embedding. | 493 // result of an embedding. |
| 542 client_id_ = client_id; | 494 client_id_ = client_id; |
| 543 WindowTreeConnectionEstablished(window_tree); | 495 WindowTreeConnectionEstablished(window_tree); |
| 544 | 496 |
| 545 DCHECK(roots_.empty()); | 497 DCHECK(roots_.empty()); |
| 546 Window* root = CreateWindowTreeHost(RootWindowType::EMBED, root_data, | 498 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
| 547 display_id, nullptr); | 499 CreateWindowTreeHost(WindowMusType::EMBED, root_data, display_id); |
| 548 // TODO: needs to deal with drawn and display_id. | |
| 549 | 500 |
| 550 SetFocusFromServer(GetWindowByServerId(focused_window_id)); | 501 SetFocusFromServer(GetWindowByServerId(focused_window_id)); |
| 551 | 502 |
| 552 delegate_->OnEmbed(root); | 503 delegate_->OnEmbed(std::move(window_tree_host)); |
| 553 } | 504 } |
| 554 | 505 |
| 555 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( | 506 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( |
| 556 const display::Display& display, | 507 const display::Display& display, |
| 557 ui::mojom::WindowDataPtr root_data, | 508 ui::mojom::WindowDataPtr root_data, |
| 558 bool parent_drawn) { | 509 bool parent_drawn) { |
| 559 DCHECK(window_manager_delegate_); | 510 DCHECK(window_manager_delegate_); |
| 560 | 511 |
| 561 // TODO: need to deal with display_id and drawn. | 512 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
| 562 Window* root = CreateWindowTreeHost(RootWindowType::DISPLAY, root_data, | 513 CreateWindowTreeHost(WindowMusType::DISPLAY, root_data, display.id()); |
| 563 display.id(), nullptr); | |
| 564 // WindowPrivate(root).LocalSetDisplay(display.id()); | |
| 565 // WindowPrivate(root).LocalSetParentDrawn(parent_drawn); | |
| 566 | 514 |
| 567 window_manager_delegate_->OnWmNewDisplay(root, display); | 515 WindowTreeHost* window_tree_host_ptr = window_tree_host.get(); |
| 568 return root->GetHost(); | 516 window_manager_delegate_->OnWmNewDisplay(std::move(window_tree_host), |
| 517 display); |
| 518 return window_tree_host_ptr; |
| 569 } | 519 } |
| 570 | 520 |
| 571 std::unique_ptr<EventResultCallback> | 521 std::unique_ptr<EventResultCallback> |
| 572 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { | 522 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { |
| 573 return base::MakeUnique<EventResultCallback>( | 523 return base::MakeUnique<EventResultCallback>( |
| 574 base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck, | 524 base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck, |
| 575 base::Unretained(tree_), event_id)); | 525 base::Unretained(tree_), event_id)); |
| 576 } | 526 } |
| 577 | 527 |
| 578 void WindowTreeClient::OnReceivedCursorLocationMemory( | 528 void WindowTreeClient::OnReceivedCursorLocationMemory( |
| 579 mojo::ScopedSharedBufferHandle handle) { | 529 mojo::ScopedSharedBufferHandle handle) { |
| 580 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); | 530 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); |
| 581 DCHECK(cursor_location_mapping_); | 531 DCHECK(cursor_location_mapping_); |
| 582 } | 532 } |
| 583 | 533 |
| 584 void WindowTreeClient::SetWindowBoundsFromServer( | 534 void WindowTreeClient::SetWindowBoundsFromServer( |
| 585 WindowMus* window, | 535 WindowMus* window, |
| 586 const gfx::Rect& revert_bounds) { | 536 const gfx::Rect& revert_bounds) { |
| 587 if (!IsRoot(window)) { | 537 if (IsRoot(window)) { |
| 588 window->SetBoundsFromServer(revert_bounds); | 538 GetWindowTreeHostMus(window)->SetBoundsFromServer(revert_bounds); |
| 589 return; | 539 return; |
| 590 } | 540 } |
| 591 | 541 |
| 592 const gfx::Rect window_tree_host_bounds(gfx::Rect(revert_bounds.size())); | 542 window->SetBoundsFromServer(revert_bounds); |
| 593 std::unique_ptr<WindowMusChangeData> data = | |
| 594 window->PrepareForServerBoundsChange(window_tree_host_bounds); | |
| 595 // We need the root window to always have an origin of 0x0 locally. | |
| 596 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); | |
| 597 window_tree_host->set_origin_offset(revert_bounds.OffsetFromOrigin()); | |
| 598 window_tree_host->SetBoundsFromServer(window_tree_host_bounds); | |
| 599 } | 543 } |
| 600 | 544 |
| 601 void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window, | 545 void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window, |
| 602 bool visible) { | 546 bool visible) { |
| 603 if (!IsRoot(window)) { | 547 if (!IsRoot(window)) { |
| 604 window->SetVisibleFromServer(visible); | 548 window->SetVisibleFromServer(visible); |
| 605 return; | 549 return; |
| 606 } | 550 } |
| 607 | 551 |
| 608 std::unique_ptr<WindowMusChangeData> data1 = | 552 std::unique_ptr<WindowMusChangeData> data = |
| 609 window->PrepareForServerVisibilityChange(visible); | 553 window->PrepareForServerVisibilityChange(visible); |
| 610 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); | 554 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); |
| 611 if (visible) | 555 if (visible) |
| 612 window_tree_host->Show(); | 556 window_tree_host->Show(); |
| 613 else | 557 else |
| 614 window_tree_host->Hide(); | 558 window_tree_host->Hide(); |
| 615 } | 559 } |
| 616 | 560 |
| 617 std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated( | 561 void WindowTreeClient::ScheduleInFlightBoundsChange( |
| 618 WindowMus* window) { | 562 WindowMus* window, |
| 619 if (window->server_id() != 0 || !window->create_remote_window()) { | 563 const gfx::Rect& old_bounds, |
| 620 // This window was created by us, or should not have a window created on | 564 const gfx::Rect& new_bounds) { |
| 621 // the server. | 565 const uint32_t change_id = ScheduleInFlightChange( |
| 622 return nullptr; | 566 base::MakeUnique<InFlightBoundsChange>(this, window, old_bounds)); |
| 623 } | 567 tree_->SetWindowBounds(change_id, window->server_id(), new_bounds); |
| 568 } |
| 569 |
| 570 void WindowTreeClient::OnWindowMusCreated(WindowMus* window) { |
| 571 if (window->server_id() != kInvalidServerId) |
| 572 return; |
| 624 | 573 |
| 625 window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); | 574 window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); |
| 626 RegisterWindowMus(window); | 575 RegisterWindowMus(window); |
| 627 | 576 |
| 628 const bool create_top_level = | 577 const bool create_top_level = !window_manager_delegate_ && IsRoot(window); |
| 629 !window_manager_delegate_ && | |
| 630 ShouldCreateTopLevel(window->GetWindow()->type()); | |
| 631 | 578 |
| 632 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; | 579 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; |
| 633 std::set<const void*> property_keys = | 580 std::set<const void*> property_keys = |
| 634 window->GetWindow()->GetAllPropertKeys(); | 581 window->GetWindow()->GetAllPropertKeys(); |
| 635 PropertyConverter* property_converter = delegate_->GetPropertyConverter(); | 582 PropertyConverter* property_converter = delegate_->GetPropertyConverter(); |
| 636 for (const void* key : property_keys) { | 583 for (const void* key : property_keys) { |
| 637 std::string transport_name; | 584 std::string transport_name; |
| 638 std::unique_ptr<std::vector<uint8_t>> transport_value; | 585 std::unique_ptr<std::vector<uint8_t>> transport_value; |
| 639 if (!property_converter->ConvertPropertyForTransport( | 586 if (!property_converter->ConvertPropertyForTransport( |
| 640 window->GetWindow(), key, &transport_name, &transport_value)) { | 587 window->GetWindow(), key, &transport_name, &transport_value)) { |
| 641 continue; | 588 continue; |
| 642 } | 589 } |
| 643 if (!transport_value) { | 590 if (!transport_value) { |
| 644 transport_properties[transport_name] = mojo::Array<uint8_t>(nullptr); | 591 transport_properties[transport_name] = mojo::Array<uint8_t>(nullptr); |
| 645 } else { | 592 } else { |
| 646 transport_properties[transport_name] = | 593 transport_properties[transport_name] = |
| 647 mojo::Array<uint8_t>::From(*transport_value); | 594 mojo::Array<uint8_t>::From(*transport_value); |
| 648 } | 595 } |
| 649 } | 596 } |
| 650 | 597 |
| 651 const uint32_t change_id = | 598 const uint32_t change_id = |
| 652 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 599 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| 653 window, create_top_level ? ChangeType::NEW_TOP_LEVEL_WINDOW | 600 window, create_top_level ? ChangeType::NEW_TOP_LEVEL_WINDOW |
| 654 : ChangeType::NEW_WINDOW)); | 601 : ChangeType::NEW_WINDOW)); |
| 655 if (create_top_level) { | 602 if (create_top_level) { |
| 656 std::unique_ptr<WindowPortInitData> data( | |
| 657 base::MakeUnique<WindowPortInitData>()); | |
| 658 tree_->NewTopLevelWindow(change_id, window->server_id(), | 603 tree_->NewTopLevelWindow(change_id, window->server_id(), |
| 659 std::move(transport_properties)); | 604 std::move(transport_properties)); |
| 660 return data; | 605 } else { |
| 606 tree_->NewWindow(change_id, window->server_id(), |
| 607 std::move(transport_properties)); |
| 661 } | 608 } |
| 662 tree_->NewWindow(change_id, window->server_id(), | |
| 663 std::move(transport_properties)); | |
| 664 return nullptr; | |
| 665 } | |
| 666 | |
| 667 void WindowTreeClient::OnWindowMusInitDone( | |
| 668 WindowMus* window, | |
| 669 std::unique_ptr<WindowPortInitData> init_data) { | |
| 670 if (!init_data) | |
| 671 return; | |
| 672 | |
| 673 // Delay creating the WindowTreeHost until after Init(), otherwise we trigger | |
| 674 // crashes in code that expects window parenting to happen after | |
| 675 // Env::NotifyWindowInitialized() is called. | |
| 676 // | |
| 677 // Use the primary display. We'll get the real display when created. | |
| 678 CreateWindowTreeHost(RootWindowType::TOP_LEVEL, nullptr, | |
| 679 display::Screen::GetScreen()->GetPrimaryDisplay().id(), | |
| 680 window->GetWindow()); | |
| 681 } | 609 } |
| 682 | 610 |
| 683 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { | 611 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { |
| 684 if (focused_window_ == window) | 612 if (focused_window_ == window) |
| 685 focused_window_ = nullptr; | 613 focused_window_ = nullptr; |
| 686 | 614 |
| 687 // TODO: decide how to deal with windows not owned by this client. | 615 // TODO: decide how to deal with windows not owned by this client. |
| 688 if (WasCreatedByThisClient(window) || IsRoot(window)) { | 616 if (WasCreatedByThisClient(window) || IsRoot(window)) { |
| 689 const uint32_t change_id = | 617 const uint32_t change_id = |
| 690 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 618 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 712 in_flight_map_.erase(change_id); | 640 in_flight_map_.erase(change_id); |
| 713 | 641 |
| 714 const bool was_root = roots_.erase(window) > 0; | 642 const bool was_root = roots_.erase(window) > 0; |
| 715 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) | 643 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) |
| 716 delegate_->OnEmbedRootDestroyed(window->GetWindow()); | 644 delegate_->OnEmbedRootDestroyed(window->GetWindow()); |
| 717 } | 645 } |
| 718 | 646 |
| 719 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, | 647 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, |
| 720 const gfx::Rect& old_bounds, | 648 const gfx::Rect& old_bounds, |
| 721 const gfx::Rect& new_bounds) { | 649 const gfx::Rect& new_bounds) { |
| 722 const uint32_t change_id = ScheduleInFlightChange( | 650 // Changes to bounds of root windows are routed through |
| 723 base::MakeUnique<InFlightBoundsChange>(this, window, old_bounds)); | 651 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side |
| 724 gfx::Point origin(new_bounds.origin()); | 652 // effect of those and can be ignored. |
| 725 if (IsRoot(window)) { | 653 if (IsRoot(window)) |
| 726 // WindowTreeHostMus stores the true origin of root windows. | 654 return; |
| 727 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); | 655 |
| 728 origin += window_tree_host->origin_offset(); | 656 ScheduleInFlightBoundsChange(window, old_bounds, new_bounds); |
| 729 } | |
| 730 tree_->SetWindowBounds(change_id, window->server_id(), | |
| 731 gfx::Rect(origin, new_bounds.size())); | |
| 732 } | 657 } |
| 733 | 658 |
| 734 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, | 659 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, |
| 735 WindowMus* child) { | 660 WindowMus* child) { |
| 736 // TODO: add checks to ensure this can work. | 661 // TODO: add checks to ensure this can work. |
| 737 const uint32_t change_id = ScheduleInFlightChange( | 662 const uint32_t change_id = ScheduleInFlightChange( |
| 738 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); | 663 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); |
| 739 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); | 664 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); |
| 740 } | 665 } |
| 741 | 666 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 if (!in_flight_map_.count(change_id)) { | 912 if (!in_flight_map_.count(change_id)) { |
| 988 // The window may have been destroyed locally before the server could finish | 913 // The window may have been destroyed locally before the server could finish |
| 989 // creating the window, and before the server received the notification that | 914 // creating the window, and before the server received the notification that |
| 990 // the window has been destroyed. | 915 // the window has been destroyed. |
| 991 return; | 916 return; |
| 992 } | 917 } |
| 993 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 918 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 994 in_flight_map_.erase(change_id); | 919 in_flight_map_.erase(change_id); |
| 995 | 920 |
| 996 WindowMus* window = change->window(); | 921 WindowMus* window = change->window(); |
| 922 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); |
| 997 | 923 |
| 998 // Drawn state and display-id always come from the server (they can't be | 924 // Drawn state and display-id always come from the server (they can't be |
| 999 // modified locally). | 925 // modified locally). |
| 1000 GetWindowTreeHostMus(window)->set_display_id(display_id); | 926 window_tree_host->set_display_id(display_id); |
| 1001 | 927 |
| 1002 // The default visibilty is false, we only need update visibility if it | 928 // The default visibilty is false, we only need update visibility if it |
| 1003 // differs from that. | 929 // differs from that. |
| 1004 if (data->visible) { | 930 if (data->visible) { |
| 1005 InFlightVisibleChange visible_change(this, window, data->visible); | 931 InFlightVisibleChange visible_change(this, window, data->visible); |
| 1006 InFlightChange* current_change = | 932 InFlightChange* current_change = |
| 1007 GetOldestInFlightChangeMatching(visible_change); | 933 GetOldestInFlightChangeMatching(visible_change); |
| 1008 if (current_change) | 934 if (current_change) |
| 1009 current_change->SetRevertValueFrom(visible_change); | 935 current_change->SetRevertValueFrom(visible_change); |
| 1010 else | 936 else |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 WindowMus* window = GetWindowByServerId(window_id); | 1051 WindowMus* window = GetWindowByServerId(window_id); |
| 1126 WindowMus* relative_window = GetWindowByServerId(relative_window_id); | 1052 WindowMus* relative_window = GetWindowByServerId(relative_window_id); |
| 1127 WindowMus* parent = WindowMus::Get(window->GetWindow()->parent()); | 1053 WindowMus* parent = WindowMus::Get(window->GetWindow()->parent()); |
| 1128 if (window && relative_window && parent && | 1054 if (window && relative_window && parent && |
| 1129 parent == WindowMus::Get(relative_window->GetWindow()->parent())) { | 1055 parent == WindowMus::Get(relative_window->GetWindow()->parent())) { |
| 1130 parent->ReorderFromServer(window, relative_window, direction); | 1056 parent->ReorderFromServer(window, relative_window, direction); |
| 1131 } | 1057 } |
| 1132 } | 1058 } |
| 1133 | 1059 |
| 1134 void WindowTreeClient::OnWindowDeleted(Id window_id) { | 1060 void WindowTreeClient::OnWindowDeleted(Id window_id) { |
| 1061 // TODO(sky): decide how best to deal with this. It seems we should let the |
| 1062 // delegate do the actualy deletion. |
| 1135 delete GetWindowByServerId(window_id)->GetWindow(); | 1063 delete GetWindowByServerId(window_id)->GetWindow(); |
| 1136 } | 1064 } |
| 1137 | 1065 |
| 1138 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) { | 1066 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) { |
| 1139 WindowMus* window = GetWindowByServerId(window_id); | 1067 WindowMus* window = GetWindowByServerId(window_id); |
| 1140 if (!window) | 1068 if (!window) |
| 1141 return; | 1069 return; |
| 1142 | 1070 |
| 1143 InFlightVisibleChange new_change(this, window, visible); | 1071 InFlightVisibleChange new_change(this, window, visible); |
| 1144 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1072 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 return; | 1528 return; |
| 1601 } | 1529 } |
| 1602 | 1530 |
| 1603 const uint32_t change_id = ScheduleInFlightChange( | 1531 const uint32_t change_id = ScheduleInFlightChange( |
| 1604 base::MakeUnique<InFlightFocusChange>(this, focused_window_)); | 1532 base::MakeUnique<InFlightFocusChange>(this, focused_window_)); |
| 1605 focused_window_ = gained_focus_mus; | 1533 focused_window_ = gained_focus_mus; |
| 1606 tree_->SetFocus(change_id, focused_window_ ? focused_window_->server_id() | 1534 tree_->SetFocus(change_id, focused_window_ ? focused_window_->server_id() |
| 1607 : kInvalidServerId); | 1535 : kInvalidServerId); |
| 1608 } | 1536 } |
| 1609 | 1537 |
| 1610 void WindowTreeClient::SetRootWindowBounds(Window* window, gfx::Rect* bounds) { | 1538 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( |
| 1611 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); | 1539 WindowTreeHostMus* window_tree_host, |
| 1612 switch (window_tree_host->root_window_type()) { | 1540 const gfx::Rect& bounds) { |
| 1613 case RootWindowType::EMBED: | 1541 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), |
| 1614 NOTREACHED(); | 1542 window_tree_host->GetBounds(), bounds); |
| 1615 return; | 1543 } |
| 1616 case RootWindowType::TOP_LEVEL: | 1544 |
| 1617 // Top level requests are always in display coordinates. | 1545 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel() { |
| 1618 break; | 1546 std::unique_ptr<WindowPortMus> window_port = |
| 1619 case RootWindowType::DISPLAY: { | 1547 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL); |
| 1620 gfx::Point display_relative_origin(bounds->origin()); | 1548 roots_.insert(window_port.get()); |
| 1621 display_relative_origin -= | 1549 return window_port; |
| 1622 window_tree_host->GetDisplay().bounds().OffsetFromOrigin(); | 1550 } |
| 1623 bounds->set_origin(display_relative_origin); | 1551 |
| 1624 break; | 1552 void WindowTreeClient::OnWindowTreeHostCreated( |
| 1625 } | 1553 WindowTreeHostMus* window_tree_host) { |
| 1626 } | 1554 // All WindowTreeHosts are destroyed before this, so we don't need to unset |
| 1627 // We need the root window to always have an origin of 0x0 locally. | 1555 // the DragDropClient. |
| 1628 window_tree_host->set_origin_offset(bounds->OffsetFromOrigin()); | 1556 client::SetDragDropClient(window_tree_host->window(), |
| 1629 bounds->set_origin(gfx::Point()); | 1557 drag_drop_controller_.get()); |
| 1630 } | 1558 } |
| 1631 | 1559 |
| 1632 void WindowTreeClient::OnTransientChildWindowAdded(Window* parent, | 1560 void WindowTreeClient::OnTransientChildWindowAdded(Window* parent, |
| 1633 Window* transient_child) { | 1561 Window* transient_child) { |
| 1634 if (WindowMus::Get(parent)->OnTransientChildAdded( | 1562 if (WindowMus::Get(parent)->OnTransientChildAdded( |
| 1635 WindowMus::Get(transient_child)) == WindowMus::ChangeSource::SERVER) { | 1563 WindowMus::Get(transient_child)) == WindowMus::ChangeSource::SERVER) { |
| 1636 return; | 1564 return; |
| 1637 } | 1565 } |
| 1638 // The change originated from client code and needs to be sent to the server. | 1566 // The change originated from client code and needs to be sent to the server. |
| 1639 DCHECK(tree_); | 1567 DCHECK(tree_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1664 return ScheduleInFlightChange( | 1592 return ScheduleInFlightChange( |
| 1665 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); | 1593 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); |
| 1666 } | 1594 } |
| 1667 | 1595 |
| 1668 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { | 1596 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { |
| 1669 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1597 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1670 this, capture_synchronizer_.get(), window)); | 1598 this, capture_synchronizer_.get(), window)); |
| 1671 } | 1599 } |
| 1672 | 1600 |
| 1673 } // namespace aura | 1601 } // namespace aura |
| OLD | NEW |