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 #ifndef COMPONENTS_MUS_PUBLIC_CPP_LIB_VIEW_TREE_CLIENT_IMPL_H_
6 #define COMPONENTS_MUS_PUBLIC_CPP_LIB_VIEW_TREE_CLIENT_IMPL_H_
8 #include "components/mus/public/cpp/types.h"
9 #include "components/mus/public/cpp/view.h"
10 #include "components/mus/public/cpp/view_tree_connection.h"
11 #include "components/mus/public/interfaces/view_tree.mojom.h"
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
15 class ViewTreeConnection
;
16 class ViewTreeDelegate
;
18 // Manages the connection with the View Manager service.
19 class ViewTreeClientImpl
: public ViewTreeConnection
,
20 public mojo::ViewTreeClient
{
22 ViewTreeClientImpl(ViewTreeDelegate
* delegate
,
23 mojo::InterfaceRequest
<mojo::ViewTreeClient
> request
);
24 ~ViewTreeClientImpl() override
;
26 bool connected() const { return tree_
; }
27 ConnectionSpecificId
connection_id() const { return connection_id_
; }
29 // API exposed to the view implementations that pushes local changes to the
31 void DestroyView(Id view_id
);
33 // These methods take TransportIds. For views owned by the current connection,
34 // the connection id high word can be zero. In all cases, the TransportId 0x1
35 // refers to the root view.
36 void AddChild(Id child_id
, Id parent_id
);
37 void RemoveChild(Id child_id
, Id parent_id
);
39 void Reorder(Id view_id
, Id relative_view_id
, mojo::OrderDirection direction
);
41 // Returns true if the specified view was created by this connection.
42 bool OwnsView(Id id
) const;
44 void SetBounds(Id view_id
, const mojo::Rect
& bounds
);
45 void SetFocus(Id view_id
);
46 void SetVisible(Id view_id
, bool visible
);
47 void SetProperty(Id view_id
,
48 const std::string
& name
,
49 const std::vector
<uint8_t>& data
);
50 void SetViewTextInputState(Id view_id
, mojo::TextInputStatePtr state
);
51 void SetImeVisibility(Id view_id
,
53 mojo::TextInputStatePtr state
);
55 void Embed(Id view_id
,
56 mojo::ViewTreeClientPtr client
,
57 uint32_t policy_bitmask
,
58 const mojo::ViewTree::EmbedCallback
& callback
);
60 void RequestSurface(Id view_id
,
61 mojo::InterfaceRequest
<mojo::Surface
> surface
,
62 mojo::SurfaceClientPtr client
);
64 void set_change_acked_callback(const mojo::Callback
<void(void)>& callback
) {
65 change_acked_callback_
= callback
;
67 void ClearChangeAckedCallback() { change_acked_callback_
.reset(); }
69 // Start/stop tracking views. While tracked, they can be retrieved via
70 // ViewTreeConnection::GetViewById.
71 void AddView(View
* view
);
72 void RemoveView(Id view_id
);
74 bool is_embed_root() const { return is_embed_root_
; }
76 // Called after the root view's observers have been notified of destruction
77 // (as the last step of ~View). This ordering ensures that the View Manager
78 // is torn down after the root.
79 void OnRootDestroyed(View
* root
);
82 typedef std::map
<Id
, View
*> IdToViewMap
;
84 Id
CreateViewOnServer();
86 // Overridden from ViewTreeConnection:
87 View
* GetRoot() override
;
88 View
* GetViewById(Id id
) override
;
89 View
* GetFocusedView() override
;
90 View
* CreateView() override
;
91 bool IsEmbedRoot() override
;
92 ConnectionSpecificId
GetConnectionId() override
;
94 // Overridden from ViewTreeClient:
95 void OnEmbed(ConnectionSpecificId connection_id
,
96 mojo::ViewDataPtr root
,
97 mojo::ViewTreePtr tree
,
99 uint32_t access_policy
) override
;
100 void OnEmbeddedAppDisconnected(Id view_id
) override
;
101 void OnUnembed() override
;
102 void OnViewBoundsChanged(Id view_id
,
103 mojo::RectPtr old_bounds
,
104 mojo::RectPtr new_bounds
) override
;
105 void OnViewViewportMetricsChanged(
106 mojo::ViewportMetricsPtr old_metrics
,
107 mojo::ViewportMetricsPtr new_metrics
) override
;
108 void OnViewHierarchyChanged(Id view_id
,
111 mojo::Array
<mojo::ViewDataPtr
> views
) override
;
112 void OnViewReordered(Id view_id
,
114 mojo::OrderDirection direction
) override
;
115 void OnViewDeleted(Id view_id
) override
;
116 void OnViewVisibilityChanged(Id view_id
, bool visible
) override
;
117 void OnViewDrawnStateChanged(Id view_id
, bool drawn
) override
;
118 void OnViewSharedPropertyChanged(Id view_id
,
119 const mojo::String
& name
,
120 mojo::Array
<uint8_t> new_data
) override
;
121 void OnViewInputEvent(Id view_id
,
122 mojo::EventPtr event
,
123 const mojo::Callback
<void()>& callback
) override
;
124 void OnViewFocused(Id focused_view_id
) override
;
126 void RootDestroyed(View
* root
);
128 void OnActionCompleted(bool success
);
130 mojo::Callback
<void(bool)> ActionCompletedCallback();
132 ConnectionSpecificId connection_id_
;
133 ConnectionSpecificId next_id_
;
135 mojo::Callback
<void(void)> change_acked_callback_
;
137 ViewTreeDelegate
* delegate_
;
145 View
* activated_view_
;
147 mojo::Binding
<ViewTreeClient
> binding_
;
148 mojo::ViewTreePtr tree_
;
154 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewTreeClientImpl
);
159 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_VIEW_TREE_CLIENT_IMPL_H_