| 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/lib/window_tree_client_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 Window* AddWindowToConnection(WindowTreeClientImpl* client, | 36 Window* AddWindowToConnection(WindowTreeClientImpl* client, |
| 37 Window* parent, | 37 Window* parent, |
| 38 const mojom::WindowDataPtr& window_data) { | 38 const mojom::WindowDataPtr& window_data) { |
| 39 // We don't use the ctor that takes a WindowTreeConnection here, since it | 39 // We don't use the ctor that takes a WindowTreeConnection here, since it |
| 40 // will call back to the service and attempt to create a new window. | 40 // will call back to the service and attempt to create a new window. |
| 41 Window* window = WindowPrivate::LocalCreate(); | 41 Window* window = WindowPrivate::LocalCreate(); |
| 42 WindowPrivate private_window(window); | 42 WindowPrivate private_window(window); |
| 43 private_window.set_connection(client); | 43 private_window.set_connection(client); |
| 44 private_window.set_id(window_data->window_id); | 44 private_window.set_id(window_data->window_id); |
| 45 private_window.set_visible(window_data->visible); | 45 private_window.set_visible(window_data->visible); |
| 46 private_window.set_drawn(window_data->drawn); | |
| 47 private_window.LocalSetViewportMetrics(mojom::ViewportMetrics(), | 46 private_window.LocalSetViewportMetrics(mojom::ViewportMetrics(), |
| 48 *window_data->viewport_metrics); | 47 *window_data->viewport_metrics); |
| 49 private_window.set_properties( | 48 private_window.set_properties( |
| 50 window_data->properties | 49 window_data->properties |
| 51 .To<std::map<std::string, std::vector<uint8_t>>>()); | 50 .To<std::map<std::string, std::vector<uint8_t>>>()); |
| 52 client->AddWindow(window); | 51 client->AddWindow(window); |
| 53 private_window.LocalSetBounds(gfx::Rect(), | 52 private_window.LocalSetBounds(gfx::Rect(), |
| 54 window_data->bounds.To<gfx::Rect>()); | 53 window_data->bounds.To<gfx::Rect>()); |
| 55 if (parent) | 54 if (parent) |
| 56 WindowPrivate(parent).LocalAddChild(window); | 55 WindowPrivate(parent).LocalAddChild(window); |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 roots_.insert(window); | 476 roots_.insert(window); |
| 478 tree_->NewTopLevelWindow(change_id, window->id(), | 477 tree_->NewTopLevelWindow(change_id, window->id(), |
| 479 std::move(transport_properties)); | 478 std::move(transport_properties)); |
| 480 } | 479 } |
| 481 return window; | 480 return window; |
| 482 } | 481 } |
| 483 | 482 |
| 484 void WindowTreeClientImpl::OnEmbedImpl(mojom::WindowTree* window_tree, | 483 void WindowTreeClientImpl::OnEmbedImpl(mojom::WindowTree* window_tree, |
| 485 ConnectionSpecificId connection_id, | 484 ConnectionSpecificId connection_id, |
| 486 mojom::WindowDataPtr root_data, | 485 mojom::WindowDataPtr root_data, |
| 487 Id focused_window_id) { | 486 Id focused_window_id, |
| 487 bool drawn) { |
| 488 // WARNING: this is only called if WindowTreeClientImpl was created as the | 488 // WARNING: this is only called if WindowTreeClientImpl was created as the |
| 489 // result of an embedding. | 489 // result of an embedding. |
| 490 tree_ = window_tree; | 490 tree_ = window_tree; |
| 491 connection_id_ = connection_id; | 491 connection_id_ = connection_id; |
| 492 | 492 |
| 493 DCHECK(roots_.empty()); | 493 DCHECK(roots_.empty()); |
| 494 Window* root = AddWindowToConnection(this, nullptr, root_data); | 494 Window* root = AddWindowToConnection(this, nullptr, root_data); |
| 495 roots_.insert(root); | 495 roots_.insert(root); |
| 496 | 496 |
| 497 focused_window_ = GetWindowById(focused_window_id); | 497 focused_window_ = GetWindowById(focused_window_id); |
| 498 | 498 |
| 499 WindowPrivate(root).LocalSetParentDrawn(drawn); |
| 500 |
| 499 delegate_->OnEmbed(root); | 501 delegate_->OnEmbed(root); |
| 500 | 502 |
| 501 if (focused_window_) { | 503 if (focused_window_) { |
| 502 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, | 504 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, |
| 503 OnWindowTreeFocusChanged(focused_window_, nullptr)); | 505 OnWindowTreeFocusChanged(focused_window_, nullptr)); |
| 504 } | 506 } |
| 505 } | 507 } |
| 506 | 508 |
| 507 //////////////////////////////////////////////////////////////////////////////// | 509 //////////////////////////////////////////////////////////////////////////////// |
| 508 // WindowTreeClientImpl, WindowTreeConnection implementation: | 510 // WindowTreeClientImpl, WindowTreeConnection implementation: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 531 SetFocus(nullptr); | 533 SetFocus(nullptr); |
| 532 } | 534 } |
| 533 | 535 |
| 534 Window* WindowTreeClientImpl::NewWindow( | 536 Window* WindowTreeClientImpl::NewWindow( |
| 535 const Window::SharedProperties* properties) { | 537 const Window::SharedProperties* properties) { |
| 536 return NewWindowImpl(NewWindowType::CHILD, properties); | 538 return NewWindowImpl(NewWindowType::CHILD, properties); |
| 537 } | 539 } |
| 538 | 540 |
| 539 Window* WindowTreeClientImpl::NewTopLevelWindow( | 541 Window* WindowTreeClientImpl::NewTopLevelWindow( |
| 540 const Window::SharedProperties* properties) { | 542 const Window::SharedProperties* properties) { |
| 541 return NewWindowImpl(NewWindowType::TOP_LEVEL, properties); | 543 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); |
| 544 // Assume newly created top level windows are drawn by default, otherwise |
| 545 // requests to focus will fail. We will get the real value in |
| 546 // OnTopLevelCreated(). |
| 547 window->LocalSetParentDrawn(true); |
| 548 return window; |
| 542 } | 549 } |
| 543 | 550 |
| 544 ConnectionSpecificId WindowTreeClientImpl::GetConnectionId() { | 551 ConnectionSpecificId WindowTreeClientImpl::GetConnectionId() { |
| 545 return connection_id_; | 552 return connection_id_; |
| 546 } | 553 } |
| 547 | 554 |
| 548 //////////////////////////////////////////////////////////////////////////////// | 555 //////////////////////////////////////////////////////////////////////////////// |
| 549 // WindowTreeClientImpl, WindowTreeClient implementation: | 556 // WindowTreeClientImpl, WindowTreeClient implementation: |
| 550 | 557 |
| 551 void WindowTreeClientImpl::AddObserver(WindowTreeConnectionObserver* observer) { | 558 void WindowTreeClientImpl::AddObserver(WindowTreeConnectionObserver* observer) { |
| 552 observers_.AddObserver(observer); | 559 observers_.AddObserver(observer); |
| 553 } | 560 } |
| 554 | 561 |
| 555 void WindowTreeClientImpl::RemoveObserver( | 562 void WindowTreeClientImpl::RemoveObserver( |
| 556 WindowTreeConnectionObserver* observer) { | 563 WindowTreeConnectionObserver* observer) { |
| 557 observers_.RemoveObserver(observer); | 564 observers_.RemoveObserver(observer); |
| 558 } | 565 } |
| 559 | 566 |
| 560 void WindowTreeClientImpl::OnEmbed(ConnectionSpecificId connection_id, | 567 void WindowTreeClientImpl::OnEmbed(ConnectionSpecificId connection_id, |
| 561 mojom::WindowDataPtr root_data, | 568 mojom::WindowDataPtr root_data, |
| 562 mojom::WindowTreePtr tree, | 569 mojom::WindowTreePtr tree, |
| 563 Id focused_window_id) { | 570 Id focused_window_id, |
| 571 bool drawn) { |
| 564 DCHECK(!tree_ptr_); | 572 DCHECK(!tree_ptr_); |
| 565 tree_ptr_ = std::move(tree); | 573 tree_ptr_ = std::move(tree); |
| 566 tree_ptr_.set_connection_error_handler([this]() { delete this; }); | 574 tree_ptr_.set_connection_error_handler([this]() { delete this; }); |
| 567 | 575 |
| 568 if (window_manager_delegate_) { | 576 if (window_manager_delegate_) { |
| 569 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, | 577 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, |
| 570 tree_ptr_.associated_group())); | 578 tree_ptr_.associated_group())); |
| 571 } | 579 } |
| 572 | 580 |
| 573 OnEmbedImpl(tree_ptr_.get(), connection_id, std::move(root_data), | 581 OnEmbedImpl(tree_ptr_.get(), connection_id, std::move(root_data), |
| 574 focused_window_id); | 582 focused_window_id, drawn); |
| 575 } | 583 } |
| 576 | 584 |
| 577 void WindowTreeClientImpl::OnEmbeddedAppDisconnected(Id window_id) { | 585 void WindowTreeClientImpl::OnEmbeddedAppDisconnected(Id window_id) { |
| 578 Window* window = GetWindowById(window_id); | 586 Window* window = GetWindowById(window_id); |
| 579 if (window) { | 587 if (window) { |
| 580 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), | 588 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), |
| 581 OnWindowEmbeddedAppDisconnected(window)); | 589 OnWindowEmbeddedAppDisconnected(window)); |
| 582 } | 590 } |
| 583 } | 591 } |
| 584 | 592 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 597 return; | 605 return; |
| 598 | 606 |
| 599 InFlightCaptureChange reset_change(this, nullptr); | 607 InFlightCaptureChange reset_change(this, nullptr); |
| 600 if (ApplyServerChangeToExistingInFlightChange(reset_change)) | 608 if (ApplyServerChangeToExistingInFlightChange(reset_change)) |
| 601 return; | 609 return; |
| 602 | 610 |
| 603 LocalSetCapture(nullptr); | 611 LocalSetCapture(nullptr); |
| 604 } | 612 } |
| 605 | 613 |
| 606 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id, | 614 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id, |
| 607 mojom::WindowDataPtr data) { | 615 mojom::WindowDataPtr data, |
| 616 bool drawn) { |
| 608 // The server ack'd the top level window we created and supplied the state | 617 // The server ack'd the top level window we created and supplied the state |
| 609 // of the window at the time the server created it. For properties we do not | 618 // of the window at the time the server created it. For properties we do not |
| 610 // have changes in flight for we can update them immediately. For properties | 619 // have changes in flight for we can update them immediately. For properties |
| 611 // with changes in flight we set the revert value from the server. | 620 // with changes in flight we set the revert value from the server. |
| 612 | 621 |
| 613 if (!in_flight_map_.count(change_id)) { | 622 if (!in_flight_map_.count(change_id)) { |
| 614 // The window may have been destroyed locally before the server could finish | 623 // The window may have been destroyed locally before the server could finish |
| 615 // creating the window, and before the server received the notification that | 624 // creating the window, and before the server received the notification that |
| 616 // the window has been destroyed. | 625 // the window has been destroyed. |
| 617 return; | 626 return; |
| 618 } | 627 } |
| 619 scoped_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 628 scoped_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 620 in_flight_map_.erase(change_id); | 629 in_flight_map_.erase(change_id); |
| 621 | 630 |
| 622 Window* window = change->window(); | 631 Window* window = change->window(); |
| 623 WindowPrivate window_private(window); | 632 WindowPrivate window_private(window); |
| 624 | 633 |
| 625 // Drawn state and ViewportMetrics always come from the server (they can't | 634 // Drawn state and ViewportMetrics always come from the server (they can't |
| 626 // be modified locally). | 635 // be modified locally). |
| 627 window_private.set_drawn(data->drawn); | 636 window_private.LocalSetParentDrawn(drawn); |
| 628 window_private.LocalSetViewportMetrics(mojom::ViewportMetrics(), | 637 window_private.LocalSetViewportMetrics(mojom::ViewportMetrics(), |
| 629 *data->viewport_metrics); | 638 *data->viewport_metrics); |
| 630 | 639 |
| 631 // The default visibilty is false, we only need update visibility if it | 640 // The default visibilty is false, we only need update visibility if it |
| 632 // differs from that. | 641 // differs from that. |
| 633 if (data->visible) { | 642 if (data->visible) { |
| 634 InFlightVisibleChange visible_change(window, data->visible); | 643 InFlightVisibleChange visible_change(window, data->visible); |
| 635 InFlightChange* current_change = | 644 InFlightChange* current_change = |
| 636 GetOldestInFlightChangeMatching(visible_change); | 645 GetOldestInFlightChangeMatching(visible_change); |
| 637 if (current_change) | 646 if (current_change) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 if (!window) | 802 if (!window) |
| 794 return; | 803 return; |
| 795 | 804 |
| 796 InFlightVisibleChange new_change(window, visible); | 805 InFlightVisibleChange new_change(window, visible); |
| 797 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 806 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 798 return; | 807 return; |
| 799 | 808 |
| 800 WindowPrivate(window).LocalSetVisible(visible); | 809 WindowPrivate(window).LocalSetVisible(visible); |
| 801 } | 810 } |
| 802 | 811 |
| 803 void WindowTreeClientImpl::OnWindowDrawnStateChanged(Id window_id, bool drawn) { | 812 void WindowTreeClientImpl::OnWindowParentDrawnStateChanged(Id window_id, |
| 813 bool drawn) { |
| 804 Window* window = GetWindowById(window_id); | 814 Window* window = GetWindowById(window_id); |
| 805 if (window) | 815 if (window) |
| 806 WindowPrivate(window).LocalSetDrawn(drawn); | 816 WindowPrivate(window).LocalSetParentDrawn(drawn); |
| 807 } | 817 } |
| 808 | 818 |
| 809 void WindowTreeClientImpl::OnWindowSharedPropertyChanged( | 819 void WindowTreeClientImpl::OnWindowSharedPropertyChanged( |
| 810 Id window_id, | 820 Id window_id, |
| 811 const mojo::String& name, | 821 const mojo::String& name, |
| 812 mojo::Array<uint8_t> new_data) { | 822 mojo::Array<uint8_t> new_data) { |
| 813 Window* window = GetWindowById(window_id); | 823 Window* window = GetWindowById(window_id); |
| 814 if (!window) | 824 if (!window) |
| 815 return; | 825 return; |
| 816 | 826 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 | 1000 |
| 991 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1001 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 992 Window* window, | 1002 Window* window, |
| 993 const gfx::Vector2d& offset, | 1003 const gfx::Vector2d& offset, |
| 994 const gfx::Insets& hit_area) { | 1004 const gfx::Insets& hit_area) { |
| 995 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1005 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 996 window->id(), offset.x(), offset.y(), mojo::Insets::From(hit_area)); | 1006 window->id(), offset.x(), offset.y(), mojo::Insets::From(hit_area)); |
| 997 } | 1007 } |
| 998 | 1008 |
| 999 } // namespace mus | 1009 } // namespace mus |
| OLD | NEW |