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
3 // found in the LICENSE file.
5 #include "components/view_manager/view_tree_impl.h"
8 #include "base/stl_util.h"
9 #include "components/view_manager/connection_manager.h"
10 #include "components/view_manager/default_access_policy.h"
11 #include "components/view_manager/display_manager.h"
12 #include "components/view_manager/server_view.h"
13 #include "components/view_manager/view_tree_host_impl.h"
14 #include "components/view_manager/window_manager_access_policy.h"
15 #include "mojo/converters/geometry/geometry_type_converters.h"
16 #include "mojo/converters/ime/ime_type_converters.h"
17 #include "mojo/converters/input_events/input_events_type_converters.h"
18 #include "mojo/converters/surfaces/surfaces_type_converters.h"
19 #include "ui/platform_window/text_input_state.h"
24 using mojo::InterfaceRequest
;
25 using mojo::OrderDirection
;
27 using mojo::ServiceProvider
;
28 using mojo::ServiceProviderPtr
;
30 using mojo::ViewDataPtr
;
32 namespace view_manager
{
34 ViewTreeImpl::ViewTreeImpl(
35 ConnectionManager
* connection_manager
,
36 mojo::ConnectionSpecificId creator_id
,
37 const ViewId
& root_id
)
38 : connection_manager_(connection_manager
),
39 id_(connection_manager_
->GetAndAdvanceNextConnectionId()),
40 creator_id_(creator_id
),
42 is_embed_root_(false) {
43 ServerView
* view
= GetView(root_id
);
45 root_
.reset(new ViewId(root_id
));
46 if (view
->GetRoot() == view
) {
47 access_policy_
.reset(new WindowManagerAccessPolicy(id_
, this));
48 is_embed_root_
= true;
50 access_policy_
.reset(new DefaultAccessPolicy(id_
, this));
51 is_embed_root_
= (view
->get_and_clear_pending_access_policy() &
52 ViewTree::ACCESS_POLICY_EMBED_ROOT
) != 0;
56 ViewTreeImpl::~ViewTreeImpl() {
60 void ViewTreeImpl::Init(mojo::ViewTreeClient
* client
, mojo::ViewTreePtr tree
) {
63 std::vector
<const ServerView
*> to_send
;
65 GetUnknownViewsFrom(GetView(*root_
), &to_send
);
67 // TODO(beng): verify that host can actually be nullptr here.
68 ViewTreeHostImpl
* host
= GetHost();
69 const ServerView
* focused_view
= host
? host
->GetFocusedView() : nullptr;
71 focused_view
= access_policy_
->GetViewForFocusChange(focused_view
);
72 const mojo::Id
focused_view_transport_id(
73 ViewIdToTransportId(focused_view
? focused_view
->id() : ViewId()));
75 client
->OnEmbed(id_
, ViewToViewData(to_send
.front()), tree
.Pass(),
76 focused_view_transport_id
,
77 is_embed_root_
? ViewTree::ACCESS_POLICY_EMBED_ROOT
78 : ViewTree::ACCESS_POLICY_DEFAULT
);
81 const ServerView
* ViewTreeImpl::GetView(const ViewId
& id
) const {
82 if (id_
== id
.connection_id
) {
83 ViewMap::const_iterator i
= view_map_
.find(id
.view_id
);
84 return i
== view_map_
.end() ? NULL
: i
->second
;
86 return connection_manager_
->GetView(id
);
89 bool ViewTreeImpl::IsRoot(const ViewId
& id
) const {
90 return root_
.get() && *root_
== id
;
93 ViewTreeHostImpl
* ViewTreeImpl::GetHost() {
95 connection_manager_
->GetViewTreeHostByView(GetView(*root_
)) : nullptr;
98 void ViewTreeImpl::OnWillDestroyViewTreeImpl(
99 ViewTreeImpl
* connection
) {
100 if (creator_id_
== connection
->id())
101 creator_id_
= kInvalidConnectionId
;
102 if (connection
->root_
&& connection
->root_
->connection_id
== id_
&&
103 view_map_
.count(connection
->root_
->view_id
) > 0) {
104 client()->OnEmbeddedAppDisconnected(
105 ViewIdToTransportId(*connection
->root_
));
107 if (root_
.get() && root_
->connection_id
== connection
->id())
111 mojo::ErrorCode
ViewTreeImpl::CreateView(const ViewId
& view_id
) {
112 if (view_id
.connection_id
!= id_
)
113 return mojo::ERROR_CODE_ILLEGAL_ARGUMENT
;
114 if (view_map_
.find(view_id
.view_id
) != view_map_
.end())
115 return mojo::ERROR_CODE_VALUE_IN_USE
;
116 view_map_
[view_id
.view_id
] = connection_manager_
->CreateServerView(view_id
);
117 known_views_
.insert(ViewIdToTransportId(view_id
));
118 return mojo::ERROR_CODE_NONE
;
121 bool ViewTreeImpl::AddView(const ViewId
& parent_id
, const ViewId
& child_id
) {
122 ServerView
* parent
= GetView(parent_id
);
123 ServerView
* child
= GetView(child_id
);
124 if (parent
&& child
&& child
->parent() != parent
&&
125 !child
->Contains(parent
) && access_policy_
->CanAddView(parent
, child
)) {
126 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
133 std::vector
<const ServerView
*> ViewTreeImpl::GetViewTree(
134 const ViewId
& view_id
) const {
135 const ServerView
* view
= GetView(view_id
);
136 std::vector
<const ServerView
*> views
;
138 GetViewTreeImpl(view
, &views
);
142 bool ViewTreeImpl::SetViewVisibility(const ViewId
& view_id
, bool visible
) {
143 ServerView
* view
= GetView(view_id
);
144 if (!view
|| view
->visible() == visible
||
145 !access_policy_
->CanChangeViewVisibility(view
)) {
148 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
149 view
->SetVisible(visible
);
153 bool ViewTreeImpl::Embed(const ViewId
& view_id
,
154 mojo::ViewTreeClientPtr client
) {
155 if (!client
.get() || !CanEmbed(view_id
))
157 PrepareForEmbed(view_id
);
159 connection_manager_
->EmbedAtView(id_
, view_id
, client
.Pass()));
163 void ViewTreeImpl::Embed(const ViewId
& view_id
, mojo::URLRequestPtr request
) {
164 if (!CanEmbed(view_id
))
166 PrepareForEmbed(view_id
);
167 connection_manager_
->EmbedAtView(id_
, view_id
, request
.Pass());
170 void ViewTreeImpl::ProcessViewBoundsChanged(
171 const ServerView
* view
,
172 const gfx::Rect
& old_bounds
,
173 const gfx::Rect
& new_bounds
,
174 bool originated_change
) {
175 if (originated_change
|| !IsViewKnown(view
))
177 client()->OnViewBoundsChanged(ViewIdToTransportId(view
->id()),
178 Rect::From(old_bounds
),
179 Rect::From(new_bounds
));
182 void ViewTreeImpl::ProcessViewportMetricsChanged(
183 const mojo::ViewportMetrics
& old_metrics
,
184 const mojo::ViewportMetrics
& new_metrics
,
185 bool originated_change
) {
186 client()->OnViewViewportMetricsChanged(old_metrics
.Clone(),
187 new_metrics
.Clone());
190 void ViewTreeImpl::ProcessWillChangeViewHierarchy(
191 const ServerView
* view
,
192 const ServerView
* new_parent
,
193 const ServerView
* old_parent
,
194 bool originated_change
) {
195 if (originated_change
)
198 const bool old_drawn
= view
->IsDrawn();
199 const bool new_drawn
= view
->visible() && new_parent
&& new_parent
->IsDrawn();
200 if (old_drawn
== new_drawn
)
203 NotifyDrawnStateChanged(view
, new_drawn
);
206 void ViewTreeImpl::ProcessViewPropertyChanged(
207 const ServerView
* view
,
208 const std::string
& name
,
209 const std::vector
<uint8_t>* new_data
,
210 bool originated_change
) {
211 if (originated_change
)
216 data
= Array
<uint8_t>::From(*new_data
);
218 client()->OnViewSharedPropertyChanged(ViewIdToTransportId(view
->id()),
219 String(name
), data
.Pass());
222 void ViewTreeImpl::ProcessViewHierarchyChanged(
223 const ServerView
* view
,
224 const ServerView
* new_parent
,
225 const ServerView
* old_parent
,
226 bool originated_change
) {
227 if (originated_change
&& !IsViewKnown(view
) && new_parent
&&
228 IsViewKnown(new_parent
)) {
229 std::vector
<const ServerView
*> unused
;
230 GetUnknownViewsFrom(view
, &unused
);
232 if (originated_change
|| connection_manager_
->is_processing_delete_view() ||
233 connection_manager_
->DidConnectionMessageClient(id_
)) {
237 if (!access_policy_
->ShouldNotifyOnHierarchyChange(
238 view
, &new_parent
, &old_parent
)) {
241 // Inform the client of any new views and update the set of views we know
243 std::vector
<const ServerView
*> to_send
;
244 if (!IsViewKnown(view
))
245 GetUnknownViewsFrom(view
, &to_send
);
246 const ViewId
new_parent_id(new_parent
? new_parent
->id() : ViewId());
247 const ViewId
old_parent_id(old_parent
? old_parent
->id() : ViewId());
248 client()->OnViewHierarchyChanged(ViewIdToTransportId(view
->id()),
249 ViewIdToTransportId(new_parent_id
),
250 ViewIdToTransportId(old_parent_id
),
251 ViewsToViewDatas(to_send
));
252 connection_manager_
->OnConnectionMessagedClient(id_
);
255 void ViewTreeImpl::ProcessViewReorder(const ServerView
* view
,
256 const ServerView
* relative_view
,
257 OrderDirection direction
,
258 bool originated_change
) {
259 if (originated_change
|| !IsViewKnown(view
) || !IsViewKnown(relative_view
))
262 client()->OnViewReordered(ViewIdToTransportId(view
->id()),
263 ViewIdToTransportId(relative_view
->id()),
267 void ViewTreeImpl::ProcessViewDeleted(const ViewId
& view
,
268 bool originated_change
) {
269 if (view
.connection_id
== id_
)
270 view_map_
.erase(view
.view_id
);
272 const bool in_known
= known_views_
.erase(ViewIdToTransportId(view
)) > 0;
277 if (originated_change
)
281 client()->OnViewDeleted(ViewIdToTransportId(view
));
282 connection_manager_
->OnConnectionMessagedClient(id_
);
286 void ViewTreeImpl::ProcessWillChangeViewVisibility(
287 const ServerView
* view
,
288 bool originated_change
) {
289 if (originated_change
)
292 if (IsViewKnown(view
)) {
293 client()->OnViewVisibilityChanged(ViewIdToTransportId(view
->id()),
298 bool view_target_drawn_state
;
299 if (view
->visible()) {
300 // View is being hidden, won't be drawn.
301 view_target_drawn_state
= false;
303 // View is being shown. View will be drawn if its parent is drawn.
304 view_target_drawn_state
= view
->parent() && view
->parent()->IsDrawn();
307 NotifyDrawnStateChanged(view
, view_target_drawn_state
);
310 void ViewTreeImpl::ProcessFocusChanged(
311 const ServerView
* old_focused_view
,
312 const ServerView
* new_focused_view
) {
313 const ServerView
* view
=
314 new_focused_view
? access_policy_
->GetViewForFocusChange(new_focused_view
)
316 client()->OnViewFocused(view
? ViewIdToTransportId(view
->id())
317 : ViewIdToTransportId(ViewId()));
320 bool ViewTreeImpl::IsViewKnown(const ServerView
* view
) const {
321 return known_views_
.count(ViewIdToTransportId(view
->id())) > 0;
324 bool ViewTreeImpl::CanReorderView(const ServerView
* view
,
325 const ServerView
* relative_view
,
326 OrderDirection direction
) const {
327 if (!view
|| !relative_view
)
330 if (!view
->parent() || view
->parent() != relative_view
->parent())
333 if (!access_policy_
->CanReorderView(view
, relative_view
, direction
))
336 std::vector
<const ServerView
*> children
= view
->parent()->GetChildren();
337 const size_t child_i
=
338 std::find(children
.begin(), children
.end(), view
) - children
.begin();
339 const size_t target_i
=
340 std::find(children
.begin(), children
.end(), relative_view
) -
342 if ((direction
== mojo::ORDER_DIRECTION_ABOVE
&& child_i
== target_i
+ 1) ||
343 (direction
== mojo::ORDER_DIRECTION_BELOW
&& child_i
+ 1 == target_i
)) {
350 bool ViewTreeImpl::DeleteViewImpl(ViewTreeImpl
* source
, ServerView
* view
) {
352 DCHECK_EQ(view
->id().connection_id
, id_
);
353 ConnectionManager::ScopedChange
change(source
, connection_manager_
, true);
358 void ViewTreeImpl::GetUnknownViewsFrom(
359 const ServerView
* view
,
360 std::vector
<const ServerView
*>* views
) {
361 if (IsViewKnown(view
) || !access_policy_
->CanGetViewTree(view
))
363 views
->push_back(view
);
364 known_views_
.insert(ViewIdToTransportId(view
->id()));
365 if (!access_policy_
->CanDescendIntoViewForViewTree(view
))
367 std::vector
<const ServerView
*> children(view
->GetChildren());
368 for (size_t i
= 0 ; i
< children
.size(); ++i
)
369 GetUnknownViewsFrom(children
[i
], views
);
372 void ViewTreeImpl::RemoveFromKnown(
373 const ServerView
* view
,
374 std::vector
<ServerView
*>* local_views
) {
375 if (view
->id().connection_id
== id_
) {
377 local_views
->push_back(GetView(view
->id()));
380 known_views_
.erase(ViewIdToTransportId(view
->id()));
381 std::vector
<const ServerView
*> children
= view
->GetChildren();
382 for (size_t i
= 0; i
< children
.size(); ++i
)
383 RemoveFromKnown(children
[i
], local_views
);
386 void ViewTreeImpl::RemoveRoot() {
388 const ViewId
root_id(*root_
);
390 // No need to do anything if we created the view.
391 if (root_id
.connection_id
== id_
)
394 client()->OnUnembed();
395 client()->OnViewDeleted(ViewIdToTransportId(root_id
));
396 connection_manager_
->OnConnectionMessagedClient(id_
);
398 // This connection no longer knows about the view. Unparent any views that
399 // were parented to views in the root.
400 std::vector
<ServerView
*> local_views
;
401 RemoveFromKnown(GetView(root_id
), &local_views
);
402 for (size_t i
= 0; i
< local_views
.size(); ++i
)
403 local_views
[i
]->parent()->Remove(local_views
[i
]);
406 Array
<ViewDataPtr
> ViewTreeImpl::ViewsToViewDatas(
407 const std::vector
<const ServerView
*>& views
) {
408 Array
<ViewDataPtr
> array(views
.size());
409 for (size_t i
= 0; i
< views
.size(); ++i
)
410 array
[i
] = ViewToViewData(views
[i
]).Pass();
414 ViewDataPtr
ViewTreeImpl::ViewToViewData(const ServerView
* view
) {
415 DCHECK(IsViewKnown(view
));
416 const ServerView
* parent
= view
->parent();
417 // If the parent isn't known, it means the parent is not visible to us (not
418 // in roots), and should not be sent over.
419 if (parent
&& !IsViewKnown(parent
))
421 ViewDataPtr
view_data(mojo::ViewData::New());
422 view_data
->parent_id
= ViewIdToTransportId(parent
? parent
->id() : ViewId());
423 view_data
->view_id
= ViewIdToTransportId(view
->id());
424 view_data
->bounds
= Rect::From(view
->bounds());
425 view_data
->properties
=
426 mojo::Map
<String
, Array
<uint8_t>>::From(view
->properties());
427 view_data
->visible
= view
->visible();
428 view_data
->drawn
= view
->IsDrawn();
429 view_data
->viewport_metrics
=
430 connection_manager_
->GetViewportMetricsForView(view
);
431 return view_data
.Pass();
434 void ViewTreeImpl::GetViewTreeImpl(
435 const ServerView
* view
,
436 std::vector
<const ServerView
*>* views
) const {
439 if (!access_policy_
->CanGetViewTree(view
))
442 views
->push_back(view
);
444 if (!access_policy_
->CanDescendIntoViewForViewTree(view
))
447 std::vector
<const ServerView
*> children(view
->GetChildren());
448 for (size_t i
= 0 ; i
< children
.size(); ++i
)
449 GetViewTreeImpl(children
[i
], views
);
452 void ViewTreeImpl::NotifyDrawnStateChanged(const ServerView
* view
,
453 bool new_drawn_value
) {
454 // Even though we don't know about view, it may be an ancestor of our root, in
455 // which case the change may effect our roots drawn state.
459 const ServerView
* root
= GetView(*root_
);
461 if (view
->Contains(root
) && (new_drawn_value
!= root
->IsDrawn())) {
462 client()->OnViewDrawnStateChanged(ViewIdToTransportId(root
->id()),
467 void ViewTreeImpl::DestroyViews() {
468 if (!view_map_
.empty()) {
469 ConnectionManager::ScopedChange
change(this, connection_manager_
, true);
470 // If we get here from the destructor we're not going to get
471 // ProcessViewDeleted(). Copy the map and delete from the copy so that we
472 // don't have to worry about whether |view_map_| changes or not.
473 ViewMap view_map_copy
;
474 view_map_
.swap(view_map_copy
);
475 STLDeleteValues(&view_map_copy
);
479 bool ViewTreeImpl::CanEmbed(const ViewId
& view_id
) const {
480 const ServerView
* view
= GetView(view_id
);
481 return view
&& access_policy_
->CanEmbed(view
);
484 void ViewTreeImpl::PrepareForEmbed(const ViewId
& view_id
) {
485 const ServerView
* view
= GetView(view_id
);
486 DCHECK(view
&& access_policy_
->CanEmbed(view
));
488 // Only allow a node to be the root for one connection.
489 ViewTreeImpl
* existing_owner
=
490 connection_manager_
->GetConnectionWithRoot(view_id
);
492 ConnectionManager::ScopedChange
change(this, connection_manager_
, true);
493 RemoveChildrenAsPartOfEmbed(view_id
);
494 if (existing_owner
) {
495 // Never message the originating connection.
496 connection_manager_
->OnConnectionMessagedClient(id_
);
497 existing_owner
->RemoveRoot();
501 void ViewTreeImpl::RemoveChildrenAsPartOfEmbed(const ViewId
& view_id
) {
502 ServerView
* view
= GetView(view_id
);
504 CHECK(view
->id().connection_id
== view_id
.connection_id
);
505 std::vector
<ServerView
*> children
= view
->GetChildren();
506 for (size_t i
= 0; i
< children
.size(); ++i
)
507 view
->Remove(children
[i
]);
510 void ViewTreeImpl::CreateView(
511 Id transport_view_id
,
512 const Callback
<void(mojo::ErrorCode
)>& callback
) {
513 callback
.Run(CreateView(ViewIdFromTransportId(transport_view_id
)));
516 void ViewTreeImpl::DeleteView(
517 Id transport_view_id
,
518 const Callback
<void(bool)>& callback
) {
519 ServerView
* view
= GetView(ViewIdFromTransportId(transport_view_id
));
520 bool success
= false;
521 if (view
&& access_policy_
->CanDeleteView(view
)) {
522 ViewTreeImpl
* connection
=
523 connection_manager_
->GetConnection(view
->id().connection_id
);
524 success
= connection
&& connection
->DeleteViewImpl(this, view
);
526 callback
.Run(success
);
529 void ViewTreeImpl::AddView(
532 const Callback
<void(bool)>& callback
) {
533 callback
.Run(AddView(ViewIdFromTransportId(parent_id
),
534 ViewIdFromTransportId(child_id
)));
537 void ViewTreeImpl::RemoveViewFromParent(
539 const Callback
<void(bool)>& callback
) {
540 bool success
= false;
541 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
542 if (view
&& view
->parent() && access_policy_
->CanRemoveViewFromParent(view
)) {
544 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
545 view
->parent()->Remove(view
);
547 callback
.Run(success
);
550 void ViewTreeImpl::ReorderView(Id view_id
,
552 OrderDirection direction
,
553 const Callback
<void(bool)>& callback
) {
554 bool success
= false;
555 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
556 ServerView
* relative_view
= GetView(ViewIdFromTransportId(relative_view_id
));
557 if (CanReorderView(view
, relative_view
, direction
)) {
559 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
560 view
->parent()->Reorder(view
, relative_view
, direction
);
561 connection_manager_
->ProcessViewReorder(view
, relative_view
, direction
);
563 callback
.Run(success
);
566 void ViewTreeImpl::GetViewTree(
568 const Callback
<void(Array
<ViewDataPtr
>)>& callback
) {
569 std::vector
<const ServerView
*> views(
570 GetViewTree(ViewIdFromTransportId(view_id
)));
571 callback
.Run(ViewsToViewDatas(views
));
574 void ViewTreeImpl::SetViewBounds(
576 mojo::RectPtr bounds
,
577 const Callback
<void(bool)>& callback
) {
578 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
579 const bool success
= view
&& access_policy_
->CanSetViewBounds(view
);
581 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
582 view
->SetBounds(bounds
.To
<gfx::Rect
>());
584 callback
.Run(success
);
587 void ViewTreeImpl::SetViewVisibility(
588 Id transport_view_id
,
590 const Callback
<void(bool)>& callback
) {
592 SetViewVisibility(ViewIdFromTransportId(transport_view_id
), visible
));
595 void ViewTreeImpl::SetViewProperty(
597 const mojo::String
& name
,
598 mojo::Array
<uint8_t> value
,
599 const mojo::Callback
<void(bool)>& callback
) {
600 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
601 const bool success
= view
&& access_policy_
->CanSetViewProperties(view
);
603 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
605 if (value
.is_null()) {
606 view
->SetProperty(name
, nullptr);
608 std::vector
<uint8_t> data
= value
.To
<std::vector
<uint8_t>>();
609 view
->SetProperty(name
, &data
);
612 callback
.Run(success
);
615 void ViewTreeImpl::RequestSurface(
617 mojo::InterfaceRequest
<mojo::Surface
> surface
,
618 mojo::SurfaceClientPtr client
) {
619 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
620 const bool success
= view
&& access_policy_
->CanSetViewSurfaceId(view
);
623 view
->Bind(surface
.Pass(), client
.Pass());
626 void ViewTreeImpl::SetViewTextInputState(
628 mojo::TextInputStatePtr state
) {
629 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
630 bool success
= view
&& access_policy_
->CanSetViewTextInputState(view
);
632 view
->SetTextInputState(state
.To
<ui::TextInputState
>());
635 void ViewTreeImpl::SetImeVisibility(Id transport_view_id
,
637 mojo::TextInputStatePtr state
) {
638 ServerView
* view
= GetView(ViewIdFromTransportId(transport_view_id
));
639 bool success
= view
&& access_policy_
->CanSetViewTextInputState(view
);
641 if (!state
.is_null())
642 view
->SetTextInputState(state
.To
<ui::TextInputState
>());
644 ViewTreeHostImpl
* host
= GetHost();
646 host
->SetImeVisibility(view
, visible
);
650 void ViewTreeImpl::SetAccessPolicy(Id transport_view_id
,
651 uint32 policy_bitmask
) {
652 const ViewId
view_id(ViewIdFromTransportId(transport_view_id
));
653 ServerView
* view
= GetView(view_id
);
657 ViewTreeImpl
* existing_owner
=
658 connection_manager_
->GetConnectionWithRoot(view_id
);
660 return; // Only allow changing the access policy when nothing is embedded.
662 if (access_policy_
->CanSetAccessPolicy(view
))
663 view
->set_pending_access_policy(policy_bitmask
);
666 void ViewTreeImpl::Embed(mojo::Id transport_view_id
,
667 mojo::ViewTreeClientPtr client
,
668 const mojo::Callback
<void(bool)>& callback
) {
669 callback
.Run(Embed(ViewIdFromTransportId(transport_view_id
), client
.Pass()));
672 void ViewTreeImpl::SetFocus(uint32_t view_id
) {
673 ServerView
* view
= GetView(ViewIdFromTransportId(view_id
));
674 // TODO(beng): consider shifting non-policy drawn check logic to VTH's
676 if (view
&& view
->IsDrawn() && access_policy_
->CanSetFocus(view
)) {
677 ConnectionManager::ScopedChange
change(this, connection_manager_
, false);
678 ViewTreeHostImpl
* host
= GetHost();
680 host
->SetFocusedView(view
);
684 bool ViewTreeImpl::IsRootForAccessPolicy(const ViewId
& id
) const {
688 bool ViewTreeImpl::IsViewKnownForAccessPolicy(const ServerView
* view
) const {
689 return IsViewKnown(view
);
692 bool ViewTreeImpl::IsViewRootOfAnotherConnectionForAccessPolicy(
693 const ServerView
* view
) const {
694 ViewTreeImpl
* connection
=
695 connection_manager_
->GetConnectionWithRoot(view
->id());
696 return connection
&& connection
!= this;
699 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView
* view
) {
700 return is_embed_root_
&& root_
&& GetView(*root_
)->Contains(view
);
703 } // namespace view_manager