summaryrefslogtreecommitdiffstats
path: root/components/mus/public/interfaces/view_tree.mojom
blob: 47ed4c78d4d9c4ec5e6ad13883776c20ca81459a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module mojo;

import "components/mus/public/interfaces/compositor_frame.mojom";
import "components/mus/public/interfaces/surface_id.mojom";
import "components/mus/public/interfaces/mus_constants.mojom";
import "mojo/application/public/interfaces/service_provider.mojom";
import "network/public/interfaces/url_loader.mojom";
import "ui/mojo/events/input_events.mojom";
import "ui/mojo/ime/text_input_state.mojom";
import "ui/mojo/geometry/geometry.mojom";

struct ViewportMetrics {
  Size size_in_pixels;
  // A value of 0 indicates the real value is not yet available.
  float device_pixel_ratio = 0.0;
};

struct ViewData {
  uint32 parent_id;
  uint32 view_id;
  mojo.Rect bounds;
  map<string, array<uint8>> properties;
  // True if this view is visible. The view may not be drawn on screen (see
  // drawn for specifics).
  bool visible;
  // True if this view is drawn on screen. A view is drawn if attached to the
  // root and all ancestors (including this view) are visible.
  bool drawn;
  ViewportMetrics viewport_metrics;
};

enum ErrorCode {
  NONE,
  VALUE_IN_USE,
  ILLEGAL_ARGUMENT,
};

// Views are identified by a uint32. The upper 16 bits are the connection id,
// and the lower 16 the id assigned by the client.
//
// The root view is identified with a connection id of 0, and value of 1.
interface ViewTree {
  enum AccessPolicy {
    DEFAULT = 0,

    // An embed root has the following abilities:
    // . The app sees all the descendants of the view the app is ebmedded at,
    //   even those from separate connections.
    // . The app is able to Embed() in all the descendants of the view the app
    //   is embedded at, even those from separate connections.
    // Only connections originating from the ViewTreeHostFactory can grant this
    // policy.
    EMBED_ROOT = 1,
  };

  // Creates a new view with the specified id. It is up to the client to ensure
  // the id is unique to the connection (the id need not be globally unique).
  // Additionally the connection id (embedded in |view_id|) must match that of
  // the connection.
  // Errors:
  //   ERROR_CODE_VALUE_IN_USE: a view already exists with the specified id.
  //   ERROR_CODE_ILLEGAL_ARGUMENT: The connection part of |view_id| does not
  //     match the connection id of the client.
  //
  // TODO(erg): Once we have default values in mojo, make this take a map of
  // properties.
  CreateView(uint32 view_id) => (ErrorCode error_code);

  // Deletes a view. This does not recurse. No hierarchy change notifications
  // are sent as a result of this. Only the connection that created the view can
  // delete it.
  DeleteView(uint32 view_id) => (bool success);

  // Sets the specified bounds of the specified view.
  SetViewBounds(uint32 view_id, mojo.Rect bounds) => (bool success);

  // Sets the visibility of the specified view to |visible|. Connections are
  // allowed to change the visibility of any view they have created, as well as
  // any of their roots.
  SetViewVisibility(uint32 view_id, bool visible) => (bool success);

  // Sets an individual named property. Setting an individual property to null
  // deletes the property.
  SetViewProperty(uint32 view_id,
                  string name,
                  array<uint8>? value) => (bool success);

  // Requests a Surface for a particular view.
  RequestSurface(uint32 view_id, Surface& surface, SurfaceClient client);

  // Reparents a view.
  // This fails for any of the following reasons:
  // . |parent| or |child| does not identify a valid view.
  // . |child| is an ancestor of |parent|.
  // . |child| is already a child of |parent|.
  //
  // This may result in a connection getting OnViewDeleted(). See
  // RemoveViewFromParent for details.
  AddView(uint32 parent, uint32 child) => (bool success);

  // Removes a view from its current parent. This fails if the view is not
  // valid or the view already has no parent.
  //
  // Removing a view from a parent may result in OnViewDeleted() being sent to
  // other connections. For example, connection A has views 1 and 2, with 2 a
  // child of 1. Connection B has a root 1. If 2 is removed from 1 then B gets
  // OnViewDeleted(). This is done as view 2 is effectively no longer visible to
  // connection B.
  RemoveViewFromParent(uint32 view_id) => (bool success);

  // Reorders a view in its parent, relative to |relative_view_id| according to
  // |direction|.
  // Only the connection that created the view's parent can reorder its
  // children.
  ReorderView(uint32 view_id,
              uint32 relative_view_id,
              OrderDirection direction) => (bool success);

  // Returns the views comprising the tree starting at |view_id|. |view_id| is
  // the first result in the return value, unless |view_id| is invalid, in which
  // case an empty vector is returned. The views are visited using a depth first
  // search (pre-order).
  GetViewTree(uint32 view_id) => (array<ViewData> views);

  // A connection may grant access to another connection by way of Embed().
  // Embed() results in the supplied ViewTreeClient being configured with a
  // root view of |view_id|. The supplied ViewTreeClient may create child
  // views and do other various tree operations (including Embed()), but does
  // not see nor have access to any of the views above the embed point.
  //
  // The caller must have created |view_id|. If not the request fails and the
  // response is false.
  //
  // When a connection embeds a ViewTreeClient the originating connection no
  // longer has privileges to access or see any of the children of the view. If
  // the view had existing children the children are removed. The one exception
  // is the root connection and any connections with the policy
  // ACCESS_POLICY_EMBED_ROOT.
  //
  // A view may only have one embedding in it at a time. Subsequent calls to
  // Embed() for the same view result in the currently embedded
  // ViewTreeClient being removed. The embedded app is told this by way of
  // OnUnembed(), which is followed by OnViewDeleted() (as the connection no
  // longer has access to the view).
  //
  // The embedder can detect when the embedded app disconnects by way of
  // OnEmbeddedAppDisconnected().
  //
  // The callback returns whether the embedding was successful, and if the
  // embedding was successful and the originating connection is an embed root
  // the resulting id of the new connection.
  //
  // policy_bitmask is a bitmask of the kAccessPolicy constants. See them for
  // details.
  Embed(uint32 view_id,
        ViewTreeClient client,
        uint32 policy_bitmask) => (bool success, uint16 connection_id);

  SetFocus(uint32 view_id);

  // Set text input state for the given view.
  SetViewTextInputState(uint32 view_id, TextInputState state);

  // Set the input method editor UI (software keyboard, etc) visibility.
  // If state is non-null, the specified view's text input state is updated.
  // Otherwise the existing state is used.
  SetImeVisibility(uint32 view_id, bool visible, TextInputState? state);
};

// Changes to views are not sent to the connection that originated the
// change. For example, if connection 1 changes the bounds of a view by calling
// SetBounds(), connection 1 does not receive OnViewBoundsChanged().
interface ViewTreeClient {
  // Invoked when the client application has been embedded at |root|.
  // See Embed() on ViewTree for more details. |tree| will be a handle back to
  // the view manager service, unless the connection is to the root connection
  // in which case it will be null.
  OnEmbed(uint16 connection_id,
          ViewData root,
          ViewTree? tree,
          uint32 focused_view,
          uint32 access_policy);

  // Invoked when the application embedded at |view| is disconnected. In other
  // words the embedded app closes the connection to the server. This is called
  // on the connection that created |view| as well as any ancestors that have
  // the embed root policy.
  OnEmbeddedAppDisconnected(uint32 view);

  // Sent when another connection is embedded in the View this connection was
  // previously embedded in. See Embed() for more information.
  OnUnembed();

  // Invoked when a view's bounds have changed.
  OnViewBoundsChanged(uint32 view,
                      mojo.Rect old_bounds,
                      mojo.Rect new_bounds);

  // Invoked when the viewport metrics for the view have changed.
  // Clients are expected to propagate this to the view tree.
  OnViewViewportMetricsChanged(mojo.ViewportMetrics old_metrics,
                               mojo.ViewportMetrics new_metrics);

  // Invoked when a change is done to the hierarchy. A value of 0 is used to
  // identify a null view. For example, if the old_parent is NULL, 0 is
  // supplied.
  // |views| contains any views that are that the client has not been told
  // about. This is not sent for hierarchy changes of views not known to this
  // client or not attached to the tree.
  OnViewHierarchyChanged(uint32 view,
                         uint32 new_parent,
                         uint32 old_parent,
                         array<ViewData> views);

  // Invoked when the order of views within a parent changes.
  OnViewReordered(uint32 view_id,
                  uint32 relative_view_id,
                  OrderDirection direction);

  // Invoked when a view is deleted.
  OnViewDeleted(uint32 view);

  // Invoked when the visibility of the specified view changes.
  OnViewVisibilityChanged(uint32 view, bool visible);

  // Invoked when a change to the visibility of |view| or one if it's ancestors
  // is done such that the drawn state changes. This is only invoked for the
  // top most view of a particular connection. For example, if you have the
  // hierarchy: A -> B1 -> B2 (B2 is a child of B1 and B1 a child of A), B1/B2
  // are from connection 2 and A from connection 1 with all views visible and
  // drawn and the visiblity of A changes to false, then connection 2 is told
  // the drawn state of B1 has changed (to false), but is not told anything
  // about B2 as it's drawn state can be calculated from that of B1.
  //
  // NOTE: This is not invoked if OnViewVisibilityChanged() is invoked.
  OnViewDrawnStateChanged(uint32 view, bool drawn);

  // Invoked when a view property is changed. If this change is a removal,
  // |new_data| is null.
  OnViewSharedPropertyChanged(uint32 view, string name, array<uint8>? new_data);

  // Invoked when an event is targeted at the specified view.
  OnViewInputEvent(uint32 view, mojo.Event event) => ();

  OnViewFocused(uint32 focused_view_id);
};