Move event dispatch to view manager
[chromium-blink-merge.git] / components / view_manager / public / interfaces / view_manager.mojom
blobcb02ea6b07c1bfcdf0f1e0b5b33361943d363812
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 module mojo;
7 import "components/native_viewport/public/interfaces/native_viewport.mojom";
8 import "components/surfaces/public/interfaces/surface_id.mojom";
9 import "components/view_manager/public/interfaces/view_manager_constants.mojom";
10 import "mojo/public/interfaces/application/service_provider.mojom";
11 import "ui/mojo/events/input_events.mojom";
12 import "ui/mojo/geometry/geometry.mojom";
14 struct ViewData {
15   uint32 parent_id;
16   uint32 view_id;
17   mojo.Rect bounds;
18   map<string, array<uint8>> properties;
19   // True if this view is visible. The view may not be drawn on screen (see
20   // drawn for specifics).
21   bool visible;
22   // True if this view is drawn on screen. A view is drawn if attached to the
23   // root and all ancestors (including this view) are visible.
24   bool drawn;
25   ViewportMetrics viewport_metrics;
28 enum ErrorCode {
29   NONE,
30   VALUE_IN_USE,
31   ILLEGAL_ARGUMENT,
34 // Views are identified by a uint32. The upper 16 bits are the connection id,
35 // and the lower 16 the id assigned by the client.
37 // The root view is identified with a connection id of 0, and value of 1.
38 interface ViewManagerService {
39   // Creates a new view with the specified id. It is up to the client to ensure
40   // the id is unique to the connection (the id need not be globally unique).
41   // Additionally the connection id (embedded in |view_id|) must match that of
42   // the connection.
43   // Errors:
44   //   ERROR_CODE_VALUE_IN_USE: a view already exists with the specified id.
45   //   ERROR_CODE_ILLEGAL_ARGUMENT: The connection part of |view_id| does not
46   //     match the connection id of the client.
47   //
48   // TODO(erg): Once we have default values in mojo, make this take a map of
49   // properties.
50   CreateView(uint32 view_id) => (ErrorCode error_code);
52   // Deletes a view. This does not recurse. No hierarchy change notifications
53   // are sent as a result of this. Only the connection that created the view can
54   // delete it.
55   DeleteView(uint32 view_id) => (bool success);
57   // Sets the specified bounds of the specified view.
58   SetViewBounds(uint32 view_id, mojo.Rect bounds) => (bool success);
60   // Sets the visibility of the specified view to |visible|. Connections are
61   // allowed to change the visibility of any view they have created, as well as
62   // any of their roots.
63   SetViewVisibility(uint32 view_id, bool visible) => (bool success);
65   // Sets an individual named property. Setting an individual property to null
66   // deletes the property.
67   SetViewProperty(uint32 view_id,
68                   string name,
69                   array<uint8>? value) => (bool success);
71   // Reparents a view.
72   // This fails for any of the following reasons:
73   // . |parent| or |child| does not identify a valid view.
74   // . |child| is an ancestor of |parent|.
75   // . |child| is already a child of |parent|.
76   //
77   // This may result in a connection getting OnViewDeleted(). See
78   // RemoveViewFromParent for details.
79   AddView(uint32 parent, uint32 child) => (bool success);
81   // Removes a view from its current parent. This fails if the view is not
82   // valid or the view already has no parent.
83   //
84   // Removing a view from a parent may result in OnViewDeleted() being sent to
85   // other connections. For example, connection A has views 1 and 2, with 2 a
86   // child of 1. Connection B has a root 1. If 2 is removed from 1 then B gets
87   // OnViewDeleted(). This is done as view 2 is effectively no longer visible to
88   // connection B.
89   RemoveViewFromParent(uint32 view_id) => (bool success);
91   // Reorders a view in its parent, relative to |relative_view_id| according to
92   // |direction|.
93   // Only the connection that created the view's parent can reorder its
94   // children.
95   ReorderView(uint32 view_id,
96               uint32 relative_view_id,
97               OrderDirection direction) => (bool success);
99   // Returns the views comprising the tree starting at |view_id|. |view_id| is
100   // the first result in the return value, unless |view_id| is invalid, in which
101   // case an empty vector is returned. The views are visited using a depth first
102   // search (pre-order).
103   GetViewTree(uint32 view_id) => (array<ViewData> views);
105   // Shows the surface in the specified view.
106   SetViewSurfaceId(uint32 view_id, SurfaceId surface_id) => (bool success);
108   // A connection may grant access to a view from another connection by way of
109   // the embed functions. There are two variants of this call:
110   //
111   // . EmbedUrl: the ViewManager connects to the app at the supplied url and
112   //   asks it for a ViewManagerClient.
113   // . With the second variant a ViewManagerClient is directly supplied.
114   //
115   // In both cases the new ViewManagerClient is configured with a root of
116   // |view_id|.
117   //
118   // The caller must have created |view_id|. If not the request fails and the
119   // response is false.
120   //
121   // A view may only be a root of one connection at a time. Subsequent calls to
122   // Embed() for the same view result in the view being removed from the
123   // currently embedded app. The embedded app is told this by way of
124   // OnViewDeleted().
125   //
126   // The embedder can detect when the embedded app disconnects by way of
127   // OnEmbeddedAppDisconnected().
128   //
129   // When a connection embeds an app the connection no longer has priviledges
130   // to access or see any of the children of the view. If the view had existing
131   // children the children are removed. The one exception is the root
132   // connection.
133   //
134   // |services| encapsulates services offered by the embedder to the embedded
135   // app alongside this Embed() call. |exposed_services| provides a means for
136   // the embedder to connect to services exposed by the embedded app. Note that
137   // if a different app is subsequently embedded at |view_id| the
138   // ServiceProvider connections to its client in the embedded app and any
139   // services it provided are not broken and continue to be valid.
140   EmbedUrl(string url,
141            uint32 view_id,
142            ServiceProvider&? services,
143            ServiceProvider? exposed_services) => (bool success);
144   Embed(uint32 view_id, ViewManagerClient client) => (bool success);
146   SetFocus(uint32 view_id) => (bool success);
149 // Changes to views are not sent to the connection that originated the
150 // change. For example, if connection 1 changes the bounds of a view by calling
151 // SetBounds(), connection 1 does not receive OnViewBoundsChanged().
152 interface ViewManagerClient {
153   // Invoked when the client application has been embedded at |root|.
154   // See Embed() on ViewManagerService for more details. |view_manager_service|
155   // will be a handle back to the view manager service, unless the connection is
156   // to the WindowManager in which case it will be null.
157   OnEmbed(uint16 connection_id,
158           string embedder_url,
159           ViewData root,
160           ViewManagerService? view_manager_service,
161           ServiceProvider&? services,
162           ServiceProvider? exposed_services,
163           uint32 focused_view);
165   // Invoked when the application embedded at |view| is disconnected.
166   OnEmbeddedAppDisconnected(uint32 view);
168   // Invoked when a view's bounds have changed.
169   OnViewBoundsChanged(uint32 view,
170                       mojo.Rect old_bounds,
171                       mojo.Rect new_bounds);
173   // Invoked when the viewport metrics for the view have changed.
174   // Clients are expected to propagate this to the view tree.
175   OnViewViewportMetricsChanged(mojo.ViewportMetrics old_metrics,
176                                mojo.ViewportMetrics new_metrics);
178   // Invoked when a change is done to the hierarchy. A value of 0 is used to
179   // identify a null view. For example, if the old_parent is NULL, 0 is
180   // supplied.
181   // |views| contains any views that are that the client has not been told
182   // about. This is not sent for hierarchy changes of views not known to this
183   // client or not attached to the tree.
184   OnViewHierarchyChanged(uint32 view,
185                          uint32 new_parent,
186                          uint32 old_parent,
187                          array<ViewData> views);
189   // Invoked when the order of views within a parent changes.
190   OnViewReordered(uint32 view_id,
191                   uint32 relative_view_id,
192                   OrderDirection direction);
194   // Invoked when a view is deleted.
195   OnViewDeleted(uint32 view);
197   // Invoked when the visibility of the specified view changes.
198   OnViewVisibilityChanged(uint32 view, bool visible);
200   // Invoked when a change to the visibility of |view| or one if it's ancestors
201   // is done such that the drawn state changes. This is only invoked for the
202   // top most view of a particular connection. For example, if you have the
203   // hierarchy: A -> B1 -> B2 (B2 is a child of B1 and B1 a child of A), B1/B2
204   // are from connection 2 and A from connection 1 with all views visible and
205   // drawn and the visiblity of A changes to false, then connection 2 is told
206   // the drawn state of B1 has changed (to false), but is not told anything
207   // about B2 as it's drawn state can be calculated from that of B1.
208   //
209   // NOTE: This is not invoked if OnViewVisibilityChanged() is invoked.
210   OnViewDrawnStateChanged(uint32 view, bool drawn);
212   // Invoked when a view property is changed. If this change is a removal,
213   // |new_data| is null.
214   OnViewSharedPropertyChanged(uint32 view, string name, array<uint8>? new_data);
216   // Invoked when an event is targeted at the specified view.
217   OnViewInputEvent(uint32 view, mojo.Event event) => ();
219   OnViewFocused(uint32 focused_view_id);