| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 module mojo; | |
| 6 | |
| 7 import "components/view_manager/public/interfaces/surface_id.mojom"; | |
| 8 import "components/view_manager/public/interfaces/view_manager_constants.mojom"; | |
| 9 import "mojo/application/public/interfaces/service_provider.mojom"; | |
| 10 import "network/public/interfaces/url_loader.mojom"; | |
| 11 import "ui/mojo/events/input_events.mojom"; | |
| 12 import "ui/mojo/ime/text_input_state.mojom"; | |
| 13 import "ui/mojo/geometry/geometry.mojom"; | |
| 14 | |
| 15 struct ViewportMetrics { | |
| 16 Size size_in_pixels; | |
| 17 // A value of 0 indicates the real value is not yet available. | |
| 18 float device_pixel_ratio = 0.0; | |
| 19 }; | |
| 20 | |
| 21 struct ViewData { | |
| 22 uint32 parent_id; | |
| 23 uint32 view_id; | |
| 24 mojo.Rect bounds; | |
| 25 map<string, array<uint8>> properties; | |
| 26 // True if this view is visible. The view may not be drawn on screen (see | |
| 27 // drawn for specifics). | |
| 28 bool visible; | |
| 29 // True if this view is drawn on screen. A view is drawn if attached to the | |
| 30 // root and all ancestors (including this view) are visible. | |
| 31 bool drawn; | |
| 32 ViewportMetrics viewport_metrics; | |
| 33 }; | |
| 34 | |
| 35 enum ErrorCode { | |
| 36 NONE, | |
| 37 VALUE_IN_USE, | |
| 38 ILLEGAL_ARGUMENT, | |
| 39 }; | |
| 40 | |
| 41 // Views are identified by a uint32. The upper 16 bits are the connection id, | |
| 42 // and the lower 16 the id assigned by the client. | |
| 43 // | |
| 44 // The root view is identified with a connection id of 0, and value of 1. | |
| 45 interface ViewManagerService { | |
| 46 // Creates a new view with the specified id. It is up to the client to ensure | |
| 47 // the id is unique to the connection (the id need not be globally unique). | |
| 48 // Additionally the connection id (embedded in |view_id|) must match that of | |
| 49 // the connection. | |
| 50 // Errors: | |
| 51 // ERROR_CODE_VALUE_IN_USE: a view already exists with the specified id. | |
| 52 // ERROR_CODE_ILLEGAL_ARGUMENT: The connection part of |view_id| does not | |
| 53 // match the connection id of the client. | |
| 54 // | |
| 55 // TODO(erg): Once we have default values in mojo, make this take a map of | |
| 56 // properties. | |
| 57 CreateView(uint32 view_id) => (ErrorCode error_code); | |
| 58 | |
| 59 // Deletes a view. This does not recurse. No hierarchy change notifications | |
| 60 // are sent as a result of this. Only the connection that created the view can | |
| 61 // delete it. | |
| 62 DeleteView(uint32 view_id) => (bool success); | |
| 63 | |
| 64 // Sets the specified bounds of the specified view. | |
| 65 SetViewBounds(uint32 view_id, mojo.Rect bounds) => (bool success); | |
| 66 | |
| 67 // Sets the visibility of the specified view to |visible|. Connections are | |
| 68 // allowed to change the visibility of any view they have created, as well as | |
| 69 // any of their roots. | |
| 70 SetViewVisibility(uint32 view_id, bool visible) => (bool success); | |
| 71 | |
| 72 // Sets an individual named property. Setting an individual property to null | |
| 73 // deletes the property. | |
| 74 SetViewProperty(uint32 view_id, | |
| 75 string name, | |
| 76 array<uint8>? value) => (bool success); | |
| 77 | |
| 78 // Reparents a view. | |
| 79 // This fails for any of the following reasons: | |
| 80 // . |parent| or |child| does not identify a valid view. | |
| 81 // . |child| is an ancestor of |parent|. | |
| 82 // . |child| is already a child of |parent|. | |
| 83 // | |
| 84 // This may result in a connection getting OnViewDeleted(). See | |
| 85 // RemoveViewFromParent for details. | |
| 86 AddView(uint32 parent, uint32 child) => (bool success); | |
| 87 | |
| 88 // Removes a view from its current parent. This fails if the view is not | |
| 89 // valid or the view already has no parent. | |
| 90 // | |
| 91 // Removing a view from a parent may result in OnViewDeleted() being sent to | |
| 92 // other connections. For example, connection A has views 1 and 2, with 2 a | |
| 93 // child of 1. Connection B has a root 1. If 2 is removed from 1 then B gets | |
| 94 // OnViewDeleted(). This is done as view 2 is effectively no longer visible to | |
| 95 // connection B. | |
| 96 RemoveViewFromParent(uint32 view_id) => (bool success); | |
| 97 | |
| 98 // Reorders a view in its parent, relative to |relative_view_id| according to | |
| 99 // |direction|. | |
| 100 // Only the connection that created the view's parent can reorder its | |
| 101 // children. | |
| 102 ReorderView(uint32 view_id, | |
| 103 uint32 relative_view_id, | |
| 104 OrderDirection direction) => (bool success); | |
| 105 | |
| 106 // Returns the views comprising the tree starting at |view_id|. |view_id| is | |
| 107 // the first result in the return value, unless |view_id| is invalid, in which | |
| 108 // case an empty vector is returned. The views are visited using a depth first | |
| 109 // search (pre-order). | |
| 110 GetViewTree(uint32 view_id) => (array<ViewData> views); | |
| 111 | |
| 112 // Shows the surface in the specified view. | |
| 113 SetViewSurfaceId(uint32 view_id, SurfaceId surface_id) => (bool success); | |
| 114 | |
| 115 // Tells the ViewManagerService that the ViewManagerClient wants to get | |
| 116 // OnEmbedForDescendant() when EmbedAllowingReembed() is invoked on any | |
| 117 // descendant Views. | |
| 118 // | |
| 119 // See Embed() docs for more details. | |
| 120 // | |
| 121 // TODO(sky): this needs to be restricted in some way. Maybe the root can | |
| 122 // grant this ability? | |
| 123 SetEmbedRoot(); | |
| 124 | |
| 125 // A connection may grant access to a view from another connection by way of | |
| 126 // the embed functions. The following variants exist: | |
| 127 // | |
| 128 // . Embed: the client supplies the ViewManagerClient to embed. | |
| 129 // . EmbedAllowingReembed: walks the view tree for the first embed root | |
| 130 // ancestor and asks it to perform the embed (OnEmbedForDescendant()). | |
| 131 // The embed root ancestor may allow or disallow the request. If there is no | |
| 132 // embed root ancestor ViewManager connects to the application and requests | |
| 133 // a ViewManagerClient from it. | |
| 134 // | |
| 135 // In all cases the new ViewManagerClient is configured with a root of | |
| 136 // |view_id|. | |
| 137 // | |
| 138 // The caller must have created |view_id|. If not the request fails and the | |
| 139 // response is false. | |
| 140 // | |
| 141 // A view may only have one embedding in it at a time. Subsequent calls to | |
| 142 // Embed() for the same view result in the currently embedded | |
| 143 // ViewManagerClient being removed. The embedded app is told this by way of | |
| 144 // OnUnembed(), which is followed by OnViewDeleted() (as the connection no | |
| 145 // longer has access to the view). | |
| 146 // | |
| 147 // The embedder can detect when the embedded app disconnects by way of | |
| 148 // OnEmbeddedAppDisconnected(). | |
| 149 // | |
| 150 // When a connection embeds an app the connection no longer has privileges | |
| 151 // to access or see any of the children of the view. If the view had existing | |
| 152 // children the children are removed. The one exception is the root | |
| 153 // connection and any embed roots. The root always see the full tree, and | |
| 154 // embed roots see the complete tree at their embed point. | |
| 155 Embed(uint32 view_id, ViewManagerClient client) => (bool success); | |
| 156 EmbedAllowingReembed(uint32 view_id, URLRequest request) => (bool success); | |
| 157 | |
| 158 SetFocus(uint32 view_id) => (bool success); | |
| 159 | |
| 160 // Set text input state for the given view. | |
| 161 SetViewTextInputState(uint32 view_id, TextInputState state); | |
| 162 | |
| 163 // Set the input method editor UI (software keyboard, etc) visibility. | |
| 164 // If state is non-null, the specified view's text input state is updated. | |
| 165 // Otherwise the existing state is used. | |
| 166 SetImeVisibility(uint32 view_id, bool visible, TextInputState? state); | |
| 167 }; | |
| 168 | |
| 169 // Changes to views are not sent to the connection that originated the | |
| 170 // change. For example, if connection 1 changes the bounds of a view by calling | |
| 171 // SetBounds(), connection 1 does not receive OnViewBoundsChanged(). | |
| 172 interface ViewManagerClient { | |
| 173 // Invoked when the client application has been embedded at |root|. | |
| 174 // See Embed() on ViewManagerService for more details. |view_manager_service| | |
| 175 // will be a handle back to the view manager service, unless the connection is | |
| 176 // to the WindowManager in which case it will be null. | |
| 177 OnEmbed(uint16 connection_id, | |
| 178 ViewData root, | |
| 179 ViewManagerService? view_manager_service, | |
| 180 uint32 focused_view); | |
| 181 | |
| 182 // Asks the ViewManagerClient that was marked as an embed root for the | |
| 183 // ViewManagerClient to embed in |view|. The embed can be disallowed by | |
| 184 // calling the callback with nullptr. | |
| 185 OnEmbedForDescendant(uint32 view, URLRequest request) => | |
| 186 (ViewManagerClient? client); | |
| 187 | |
| 188 // Invoked when the application embedded at |view| is disconnected. | |
| 189 OnEmbeddedAppDisconnected(uint32 view); | |
| 190 | |
| 191 // Sent when another connection is embedded in the View this connection was | |
| 192 // previously embedded in. See Embed() for more information. | |
| 193 OnUnembed(); | |
| 194 | |
| 195 // Invoked when a view's bounds have changed. | |
| 196 OnViewBoundsChanged(uint32 view, | |
| 197 mojo.Rect old_bounds, | |
| 198 mojo.Rect new_bounds); | |
| 199 | |
| 200 // Invoked when the viewport metrics for the view have changed. | |
| 201 // Clients are expected to propagate this to the view tree. | |
| 202 OnViewViewportMetricsChanged(mojo.ViewportMetrics old_metrics, | |
| 203 mojo.ViewportMetrics new_metrics); | |
| 204 | |
| 205 // Invoked when a change is done to the hierarchy. A value of 0 is used to | |
| 206 // identify a null view. For example, if the old_parent is NULL, 0 is | |
| 207 // supplied. | |
| 208 // |views| contains any views that are that the client has not been told | |
| 209 // about. This is not sent for hierarchy changes of views not known to this | |
| 210 // client or not attached to the tree. | |
| 211 OnViewHierarchyChanged(uint32 view, | |
| 212 uint32 new_parent, | |
| 213 uint32 old_parent, | |
| 214 array<ViewData> views); | |
| 215 | |
| 216 // Invoked when the order of views within a parent changes. | |
| 217 OnViewReordered(uint32 view_id, | |
| 218 uint32 relative_view_id, | |
| 219 OrderDirection direction); | |
| 220 | |
| 221 // Invoked when a view is deleted. | |
| 222 OnViewDeleted(uint32 view); | |
| 223 | |
| 224 // Invoked when the visibility of the specified view changes. | |
| 225 OnViewVisibilityChanged(uint32 view, bool visible); | |
| 226 | |
| 227 // Invoked when a change to the visibility of |view| or one if it's ancestors | |
| 228 // is done such that the drawn state changes. This is only invoked for the | |
| 229 // top most view of a particular connection. For example, if you have the | |
| 230 // hierarchy: A -> B1 -> B2 (B2 is a child of B1 and B1 a child of A), B1/B2 | |
| 231 // are from connection 2 and A from connection 1 with all views visible and | |
| 232 // drawn and the visiblity of A changes to false, then connection 2 is told | |
| 233 // the drawn state of B1 has changed (to false), but is not told anything | |
| 234 // about B2 as it's drawn state can be calculated from that of B1. | |
| 235 // | |
| 236 // NOTE: This is not invoked if OnViewVisibilityChanged() is invoked. | |
| 237 OnViewDrawnStateChanged(uint32 view, bool drawn); | |
| 238 | |
| 239 // Invoked when a view property is changed. If this change is a removal, | |
| 240 // |new_data| is null. | |
| 241 OnViewSharedPropertyChanged(uint32 view, string name, array<uint8>? new_data); | |
| 242 | |
| 243 // Invoked when an event is targeted at the specified view. | |
| 244 OnViewInputEvent(uint32 view, mojo.Event event) => (); | |
| 245 | |
| 246 OnViewFocused(uint32 focused_view_id); | |
| 247 }; | |
| OLD | NEW |