| 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 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 Window* AddWindowToClient(WindowTreeClientImpl* client, | 43 Window* AddWindowToClient(WindowTreeClientImpl* client, |
| 44 Window* parent, | 44 Window* parent, |
| 45 const mojom::WindowDataPtr& window_data) { | 45 const mojom::WindowDataPtr& window_data) { |
| 46 // We don't use the ctor that takes a WindowTreeConnection here, since it | 46 // We don't use the ctor that takes a WindowTreeConnection here, since it |
| 47 // will call back to the service and attempt to create a new window. | 47 // will call back to the service and attempt to create a new window. |
| 48 Window* window = WindowPrivate::LocalCreate(); | 48 Window* window = WindowPrivate::LocalCreate(); |
| 49 WindowPrivate private_window(window); | 49 WindowPrivate private_window(window); |
| 50 private_window.set_connection(client); | 50 private_window.set_connection(client); |
| 51 private_window.set_server_id(window_data->window_id); | 51 private_window.set_server_id(window_data->window_id); |
| 52 private_window.set_visible(window_data->visible); | 52 private_window.set_visible(window_data->visible); |
| 53 private_window.LocalSetDisplay(window_data->display_id); | |
| 54 private_window.set_properties( | 53 private_window.set_properties( |
| 55 window_data->properties | 54 window_data->properties |
| 56 .To<std::map<std::string, std::vector<uint8_t>>>()); | 55 .To<std::map<std::string, std::vector<uint8_t>>>()); |
| 57 client->AddWindow(window); | 56 client->AddWindow(window); |
| 58 private_window.LocalSetBounds(gfx::Rect(), | 57 private_window.LocalSetBounds(gfx::Rect(), |
| 59 window_data->bounds.To<gfx::Rect>()); | 58 window_data->bounds.To<gfx::Rect>()); |
| 60 if (parent) | 59 if (parent) |
| 61 WindowPrivate(parent).LocalAddChild(window); | 60 WindowPrivate(parent).LocalAddChild(window); |
| 62 return window; | 61 return window; |
| 63 } | 62 } |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 roots_.insert(window); | 538 roots_.insert(window); |
| 540 tree_->NewTopLevelWindow(change_id, server_id(window), | 539 tree_->NewTopLevelWindow(change_id, server_id(window), |
| 541 std::move(transport_properties)); | 540 std::move(transport_properties)); |
| 542 } | 541 } |
| 543 return window; | 542 return window; |
| 544 } | 543 } |
| 545 | 544 |
| 546 void WindowTreeClientImpl::OnEmbedImpl(mojom::WindowTree* window_tree, | 545 void WindowTreeClientImpl::OnEmbedImpl(mojom::WindowTree* window_tree, |
| 547 ClientSpecificId client_id, | 546 ClientSpecificId client_id, |
| 548 mojom::WindowDataPtr root_data, | 547 mojom::WindowDataPtr root_data, |
| 548 int64_t display_id, |
| 549 Id focused_window_id, | 549 Id focused_window_id, |
| 550 bool drawn) { | 550 bool drawn) { |
| 551 // WARNING: this is only called if WindowTreeClientImpl was created as the | 551 // WARNING: this is only called if WindowTreeClientImpl was created as the |
| 552 // result of an embedding. | 552 // result of an embedding. |
| 553 tree_ = window_tree; | 553 tree_ = window_tree; |
| 554 client_id_ = client_id; | 554 client_id_ = client_id; |
| 555 | 555 |
| 556 DCHECK(roots_.empty()); | 556 DCHECK(roots_.empty()); |
| 557 Window* root = AddWindowToClient(this, nullptr, root_data); | 557 Window* root = AddWindowToClient(this, nullptr, root_data); |
| 558 WindowPrivate(root).LocalSetDisplay(display_id); |
| 558 roots_.insert(root); | 559 roots_.insert(root); |
| 559 | 560 |
| 560 focused_window_ = GetWindowByServerId(focused_window_id); | 561 focused_window_ = GetWindowByServerId(focused_window_id); |
| 561 | 562 |
| 562 WindowPrivate(root).LocalSetParentDrawn(drawn); | 563 WindowPrivate(root).LocalSetParentDrawn(drawn); |
| 563 | 564 |
| 564 delegate_->OnEmbed(root); | 565 delegate_->OnEmbed(root); |
| 565 | 566 |
| 566 if (focused_window_) { | 567 if (focused_window_) { |
| 567 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, | 568 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 } | 652 } |
| 652 | 653 |
| 653 void WindowTreeClientImpl::RemoveObserver( | 654 void WindowTreeClientImpl::RemoveObserver( |
| 654 WindowTreeConnectionObserver* observer) { | 655 WindowTreeConnectionObserver* observer) { |
| 655 observers_.RemoveObserver(observer); | 656 observers_.RemoveObserver(observer); |
| 656 } | 657 } |
| 657 | 658 |
| 658 void WindowTreeClientImpl::OnEmbed(ClientSpecificId client_id, | 659 void WindowTreeClientImpl::OnEmbed(ClientSpecificId client_id, |
| 659 mojom::WindowDataPtr root_data, | 660 mojom::WindowDataPtr root_data, |
| 660 mojom::WindowTreePtr tree, | 661 mojom::WindowTreePtr tree, |
| 662 int64_t display_id, |
| 661 Id focused_window_id, | 663 Id focused_window_id, |
| 662 bool drawn) { | 664 bool drawn) { |
| 663 DCHECK(!tree_ptr_); | 665 DCHECK(!tree_ptr_); |
| 664 tree_ptr_ = std::move(tree); | 666 tree_ptr_ = std::move(tree); |
| 665 tree_ptr_.set_connection_error_handler([this]() { delete this; }); | 667 tree_ptr_.set_connection_error_handler([this]() { delete this; }); |
| 666 | 668 |
| 667 if (window_manager_delegate_) { | 669 if (window_manager_delegate_) { |
| 668 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, | 670 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, |
| 669 tree_ptr_.associated_group())); | 671 tree_ptr_.associated_group())); |
| 670 } | 672 } |
| 671 | 673 |
| 672 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), | 674 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, |
| 673 focused_window_id, drawn); | 675 focused_window_id, drawn); |
| 674 } | 676 } |
| 675 | 677 |
| 676 void WindowTreeClientImpl::OnEmbeddedAppDisconnected(Id window_id) { | 678 void WindowTreeClientImpl::OnEmbeddedAppDisconnected(Id window_id) { |
| 677 Window* window = GetWindowByServerId(window_id); | 679 Window* window = GetWindowByServerId(window_id); |
| 678 if (window) { | 680 if (window) { |
| 679 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), | 681 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), |
| 680 OnWindowEmbeddedAppDisconnected(window)); | 682 OnWindowEmbeddedAppDisconnected(window)); |
| 681 } | 683 } |
| 682 } | 684 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 697 | 699 |
| 698 InFlightCaptureChange reset_change(this, nullptr); | 700 InFlightCaptureChange reset_change(this, nullptr); |
| 699 if (ApplyServerChangeToExistingInFlightChange(reset_change)) | 701 if (ApplyServerChangeToExistingInFlightChange(reset_change)) |
| 700 return; | 702 return; |
| 701 | 703 |
| 702 LocalSetCapture(nullptr); | 704 LocalSetCapture(nullptr); |
| 703 } | 705 } |
| 704 | 706 |
| 705 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id, | 707 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id, |
| 706 mojom::WindowDataPtr data, | 708 mojom::WindowDataPtr data, |
| 709 int64_t display_id, |
| 707 bool drawn) { | 710 bool drawn) { |
| 708 // The server ack'd the top level window we created and supplied the state | 711 // The server ack'd the top level window we created and supplied the state |
| 709 // of the window at the time the server created it. For properties we do not | 712 // of the window at the time the server created it. For properties we do not |
| 710 // have changes in flight for we can update them immediately. For properties | 713 // have changes in flight for we can update them immediately. For properties |
| 711 // with changes in flight we set the revert value from the server. | 714 // with changes in flight we set the revert value from the server. |
| 712 | 715 |
| 713 if (!in_flight_map_.count(change_id)) { | 716 if (!in_flight_map_.count(change_id)) { |
| 714 // The window may have been destroyed locally before the server could finish | 717 // The window may have been destroyed locally before the server could finish |
| 715 // creating the window, and before the server received the notification that | 718 // creating the window, and before the server received the notification that |
| 716 // the window has been destroyed. | 719 // the window has been destroyed. |
| 717 return; | 720 return; |
| 718 } | 721 } |
| 719 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 722 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 720 in_flight_map_.erase(change_id); | 723 in_flight_map_.erase(change_id); |
| 721 | 724 |
| 722 Window* window = change->window(); | 725 Window* window = change->window(); |
| 723 WindowPrivate window_private(window); | 726 WindowPrivate window_private(window); |
| 724 | 727 |
| 725 // Drawn state and display-id always come from the server (they can't be | 728 // Drawn state and display-id always come from the server (they can't be |
| 726 // modified locally). | 729 // modified locally). |
| 727 window_private.LocalSetParentDrawn(drawn); | 730 window_private.LocalSetParentDrawn(drawn); |
| 728 window_private.LocalSetDisplay(data->display_id); | 731 window_private.LocalSetDisplay(display_id); |
| 729 | 732 |
| 730 // The default visibilty is false, we only need update visibility if it | 733 // The default visibilty is false, we only need update visibility if it |
| 731 // differs from that. | 734 // differs from that. |
| 732 if (data->visible) { | 735 if (data->visible) { |
| 733 InFlightVisibleChange visible_change(window, data->visible); | 736 InFlightVisibleChange visible_change(window, data->visible); |
| 734 InFlightChange* current_change = | 737 InFlightChange* current_change = |
| 735 GetOldestInFlightChangeMatching(visible_change); | 738 GetOldestInFlightChangeMatching(visible_change); |
| 736 if (current_change) | 739 if (current_change) |
| 737 current_change->SetRevertValueFrom(visible_change); | 740 current_change->SetRevertValueFrom(visible_change); |
| 738 else | 741 else |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 const gfx::Vector2d& offset, | 1136 const gfx::Vector2d& offset, |
| 1134 const gfx::Insets& hit_area) { | 1137 const gfx::Insets& hit_area) { |
| 1135 if (window_manager_internal_client_) { | 1138 if (window_manager_internal_client_) { |
| 1136 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1139 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1137 server_id(window), offset.x(), offset.y(), | 1140 server_id(window), offset.x(), offset.y(), |
| 1138 mojo::Insets::From(hit_area)); | 1141 mojo::Insets::From(hit_area)); |
| 1139 } | 1142 } |
| 1140 } | 1143 } |
| 1141 | 1144 |
| 1142 } // namespace mus | 1145 } // namespace mus |
| OLD | NEW |