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/view_tree_impl.h" | 5 #include "components/mus/view_tree_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "components/mus/connection_manager.h" | 9 #include "components/mus/connection_manager.h" |
10 #include "components/mus/default_access_policy.h" | 10 #include "components/mus/default_access_policy.h" |
11 #include "components/mus/display_manager.h" | 11 #include "components/mus/display_manager.h" |
12 #include "components/mus/server_view.h" | 12 #include "components/mus/server_view.h" |
13 #include "components/mus/view_tree_host_impl.h" | 13 #include "components/mus/view_tree_host_impl.h" |
14 #include "components/mus/window_manager_access_policy.h" | 14 #include "components/mus/window_manager_access_policy.h" |
15 #include "mojo/converters/geometry/geometry_type_converters.h" | 15 #include "mojo/converters/geometry/geometry_type_converters.h" |
16 #include "mojo/converters/ime/ime_type_converters.h" | 16 #include "mojo/converters/ime/ime_type_converters.h" |
17 #include "mojo/converters/input_events/input_events_type_converters.h" | 17 #include "mojo/converters/input_events/input_events_type_converters.h" |
18 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 18 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
19 #include "ui/platform_window/text_input_state.h" | 19 #include "ui/platform_window/text_input_state.h" |
20 | 20 |
21 using mojo::Array; | 21 using mojo::Array; |
22 using mojo::Callback; | 22 using mojo::Callback; |
23 using mojo::Id; | |
24 using mojo::InterfaceRequest; | 23 using mojo::InterfaceRequest; |
25 using mojo::OrderDirection; | 24 using mojo::OrderDirection; |
26 using mojo::Rect; | 25 using mojo::Rect; |
27 using mojo::ServiceProvider; | 26 using mojo::ServiceProvider; |
28 using mojo::ServiceProviderPtr; | 27 using mojo::ServiceProviderPtr; |
29 using mojo::String; | 28 using mojo::String; |
30 using mojo::ViewDataPtr; | 29 using mojo::ViewDataPtr; |
31 | 30 |
32 namespace view_manager { | 31 namespace mus { |
33 | 32 |
34 ViewTreeImpl::ViewTreeImpl(ConnectionManager* connection_manager, | 33 ViewTreeImpl::ViewTreeImpl(ConnectionManager* connection_manager, |
35 mojo::ConnectionSpecificId creator_id, | 34 ConnectionSpecificId creator_id, |
36 const ViewId& root_id) | 35 const ViewId& root_id) |
37 : connection_manager_(connection_manager), | 36 : connection_manager_(connection_manager), |
38 id_(connection_manager_->GetAndAdvanceNextConnectionId()), | 37 id_(connection_manager_->GetAndAdvanceNextConnectionId()), |
39 creator_id_(creator_id), | 38 creator_id_(creator_id), |
40 client_(nullptr), | 39 client_(nullptr), |
41 is_embed_root_(false) { | 40 is_embed_root_(false) { |
42 ServerView* view = GetView(root_id); | 41 ServerView* view = GetView(root_id); |
43 CHECK(view); | 42 CHECK(view); |
44 root_.reset(new ViewId(root_id)); | 43 root_.reset(new ViewId(root_id)); |
45 if (view->GetRoot() == view) { | 44 if (view->GetRoot() == view) { |
(...skipping 15 matching lines...) Expand all Loading... |
61 client_ = client; | 60 client_ = client; |
62 std::vector<const ServerView*> to_send; | 61 std::vector<const ServerView*> to_send; |
63 if (root_.get()) | 62 if (root_.get()) |
64 GetUnknownViewsFrom(GetView(*root_), &to_send); | 63 GetUnknownViewsFrom(GetView(*root_), &to_send); |
65 | 64 |
66 // TODO(beng): verify that host can actually be nullptr here. | 65 // TODO(beng): verify that host can actually be nullptr here. |
67 ViewTreeHostImpl* host = GetHost(); | 66 ViewTreeHostImpl* host = GetHost(); |
68 const ServerView* focused_view = host ? host->GetFocusedView() : nullptr; | 67 const ServerView* focused_view = host ? host->GetFocusedView() : nullptr; |
69 if (focused_view) | 68 if (focused_view) |
70 focused_view = access_policy_->GetViewForFocusChange(focused_view); | 69 focused_view = access_policy_->GetViewForFocusChange(focused_view); |
71 const mojo::Id focused_view_transport_id( | 70 const Id focused_view_transport_id( |
72 ViewIdToTransportId(focused_view ? focused_view->id() : ViewId())); | 71 ViewIdToTransportId(focused_view ? focused_view->id() : ViewId())); |
73 | 72 |
74 client->OnEmbed(id_, ViewToViewData(to_send.front()), tree.Pass(), | 73 client->OnEmbed(id_, ViewToViewData(to_send.front()), tree.Pass(), |
75 focused_view_transport_id, | 74 focused_view_transport_id, |
76 is_embed_root_ ? ViewTree::ACCESS_POLICY_EMBED_ROOT | 75 is_embed_root_ ? ViewTree::ACCESS_POLICY_EMBED_ROOT |
77 : ViewTree::ACCESS_POLICY_DEFAULT); | 76 : ViewTree::ACCESS_POLICY_DEFAULT); |
78 } | 77 } |
79 | 78 |
80 const ServerView* ViewTreeImpl::GetView(const ViewId& id) const { | 79 const ServerView* ViewTreeImpl::GetView(const ViewId& id) const { |
81 if (id_ == id.connection_id) { | 80 if (id_ == id.connection_id) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 !access_policy_->CanChangeViewVisibility(view)) { | 147 !access_policy_->CanChangeViewVisibility(view)) { |
149 return false; | 148 return false; |
150 } | 149 } |
151 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 150 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
152 view->SetVisible(visible); | 151 view->SetVisible(visible); |
153 return true; | 152 return true; |
154 } | 153 } |
155 | 154 |
156 bool ViewTreeImpl::Embed(const ViewId& view_id, | 155 bool ViewTreeImpl::Embed(const ViewId& view_id, |
157 mojo::ViewTreeClientPtr client, | 156 mojo::ViewTreeClientPtr client, |
158 mojo::ConnectionSpecificId* connection_id) { | 157 ConnectionSpecificId* connection_id) { |
159 *connection_id = kInvalidConnectionId; | 158 *connection_id = kInvalidConnectionId; |
160 if (!client.get() || !CanEmbed(view_id)) | 159 if (!client.get() || !CanEmbed(view_id)) |
161 return false; | 160 return false; |
162 PrepareForEmbed(view_id); | 161 PrepareForEmbed(view_id); |
163 ViewTreeImpl* new_connection = | 162 ViewTreeImpl* new_connection = |
164 connection_manager_->EmbedAtView(id_, view_id, client.Pass()); | 163 connection_manager_->EmbedAtView(id_, view_id, client.Pass()); |
165 if (is_embed_root_) | 164 if (is_embed_root_) |
166 *connection_id = new_connection->id(); | 165 *connection_id = new_connection->id(); |
167 return true; | 166 return true; |
168 } | 167 } |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 if (value.is_null()) { | 595 if (value.is_null()) { |
597 view->SetProperty(name, nullptr); | 596 view->SetProperty(name, nullptr); |
598 } else { | 597 } else { |
599 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); | 598 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); |
600 view->SetProperty(name, &data); | 599 view->SetProperty(name, &data); |
601 } | 600 } |
602 } | 601 } |
603 callback.Run(success); | 602 callback.Run(success); |
604 } | 603 } |
605 | 604 |
606 void ViewTreeImpl::RequestSurface(mojo::Id view_id, | 605 void ViewTreeImpl::RequestSurface(Id view_id, |
607 mojo::InterfaceRequest<mojo::Surface> surface, | 606 mojo::InterfaceRequest<mojo::Surface> surface, |
608 mojo::SurfaceClientPtr client) { | 607 mojo::SurfaceClientPtr client) { |
609 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 608 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
610 const bool success = view && access_policy_->CanSetViewSurfaceId(view); | 609 const bool success = view && access_policy_->CanSetViewSurfaceId(view); |
611 if (!success) | 610 if (!success) |
612 return; | 611 return; |
613 view->Bind(surface.Pass(), client.Pass()); | 612 view->Bind(surface.Pass(), client.Pass()); |
614 } | 613 } |
615 | 614 |
616 void ViewTreeImpl::SetViewTextInputState(uint32_t view_id, | 615 void ViewTreeImpl::SetViewTextInputState(uint32_t view_id, |
(...skipping 28 matching lines...) Expand all Loading... |
645 | 644 |
646 ViewTreeImpl* existing_owner = | 645 ViewTreeImpl* existing_owner = |
647 connection_manager_->GetConnectionWithRoot(view_id); | 646 connection_manager_->GetConnectionWithRoot(view_id); |
648 if (existing_owner) | 647 if (existing_owner) |
649 return; // Only allow changing the access policy when nothing is embedded. | 648 return; // Only allow changing the access policy when nothing is embedded. |
650 | 649 |
651 if (access_policy_->CanSetAccessPolicy(view)) | 650 if (access_policy_->CanSetAccessPolicy(view)) |
652 view->set_pending_access_policy(policy_bitmask); | 651 view->set_pending_access_policy(policy_bitmask); |
653 } | 652 } |
654 | 653 |
655 void ViewTreeImpl::Embed(mojo::Id transport_view_id, | 654 void ViewTreeImpl::Embed(Id transport_view_id, |
656 mojo::ViewTreeClientPtr client, | 655 mojo::ViewTreeClientPtr client, |
657 const EmbedCallback& callback) { | 656 const EmbedCallback& callback) { |
658 mojo::ConnectionSpecificId connection_id = kInvalidConnectionId; | 657 ConnectionSpecificId connection_id = kInvalidConnectionId; |
659 const bool result = Embed(ViewIdFromTransportId(transport_view_id), | 658 const bool result = Embed(ViewIdFromTransportId(transport_view_id), |
660 client.Pass(), &connection_id); | 659 client.Pass(), &connection_id); |
661 callback.Run(result, connection_id); | 660 callback.Run(result, connection_id); |
662 } | 661 } |
663 | 662 |
664 void ViewTreeImpl::SetFocus(uint32_t view_id) { | 663 void ViewTreeImpl::SetFocus(uint32_t view_id) { |
665 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 664 ServerView* view = GetView(ViewIdFromTransportId(view_id)); |
666 // TODO(beng): consider shifting non-policy drawn check logic to VTH's | 665 // TODO(beng): consider shifting non-policy drawn check logic to VTH's |
667 // FocusController. | 666 // FocusController. |
668 if (view && view->IsDrawn() && access_policy_->CanSetFocus(view)) { | 667 if (view && view->IsDrawn() && access_policy_->CanSetFocus(view)) { |
(...skipping 16 matching lines...) Expand all Loading... |
685 const ServerView* view) const { | 684 const ServerView* view) const { |
686 ViewTreeImpl* connection = | 685 ViewTreeImpl* connection = |
687 connection_manager_->GetConnectionWithRoot(view->id()); | 686 connection_manager_->GetConnectionWithRoot(view->id()); |
688 return connection && connection != this; | 687 return connection && connection != this; |
689 } | 688 } |
690 | 689 |
691 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView* view) { | 690 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView* view) { |
692 return is_embed_root_ && root_ && GetView(*root_)->Contains(view); | 691 return is_embed_root_ && root_ && GetView(*root_)->Contains(view); |
693 } | 692 } |
694 | 693 |
695 } // namespace view_manager | 694 } // namespace mus |
OLD | NEW |