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 import "../geometry/geometry.mojom" 6 import "../input_events/input_events.mojom" 7 import "view_manager_constants.mojom" 8 9 module mojo.view_manager { 10 11 struct NodeData { 12 uint32 parent_id; 13 uint32 node_id; 14 uint32 view_id; 15 mojo.Rect bounds; 16 }; 17 18 // ViewManagerInitService is responsible for launching the client that controls 19 // the root node. mojo::view_manager returns an instance of this. All other 20 // connections are established by the client this creates. 21 interface ViewManagerInitService { 22 EmbedRoot(string url) => (bool success); 23 }; 24 25 // Functions that mutate the hierarchy take a change id. This is an ever 26 // increasing integer used to identify the change. Every hierarchy change 27 // increases this value. The server only accepts changes where the supplied 28 // |server_change_id| matches the expected next value. This ensures changes are 29 // made in a well defined order. 30 // 31 // Nodes and Views are identified by a uint32. The upper 16 bits are the 32 // connection id, and the lower 16 the id assigned by the client. 33 // 34 // The root node is identified with a connection id of 0, and value of 1. 35 [Client=ViewManagerClient] 36 interface ViewManagerService { 37 // Creates a new node with the specified id. It is up to the client to ensure 38 // the id is unique to the connection (the id need not be globally unique). 39 // Additionally the connection id (embedded in |node_id|) must match that of 40 // the connection. 41 CreateNode(uint32 node_id) => (bool success); 42 43 // Deletes a node. This does not recurse. No hierarchy change notifications 44 // are sent as a result of this. Only the connection that created the node can 45 // delete it. 46 DeleteNode(uint32 node_id, uint32 change_id) => (bool success); 47 48 // Sets the specified bounds of the specified node. 49 SetNodeBounds(uint32 node_id, mojo.Rect bounds) => (bool success); 50 51 // Reparents a node. See description above class for details of |change_id|. 52 // This fails for any of the following reasons: 53 // . |server_change_id| is not the expected id. 54 // . |parent| or |child| does not identify a valid node. 55 // . |child| is an ancestor of |parent|. 56 // . |child| is already a child of |parent|. 57 // 58 // This may result in a connection getting OnNodeDeleted(). See 59 // RemoveNodeFromParent for details. 60 AddNode(uint32 parent, 61 uint32 child, 62 uint32 server_change_id) => (bool success); 63 64 // Removes a view from its current parent. See description above class for 65 // details of |change_id|. This fails if the node is not valid, 66 // |server_change_id| doesn't match, or the node already has no parent. 67 // 68 // Removing a node from a parent may result in OnNodeDeleted() being sent to 69 // other connections. For example, connection A has nodes 1 and 2, with 2 a 70 // child of 1. Connection B has a root 1. If 2 is removed from 1 then B gets 71 // OnNodeDeleted(). This is done as node 2 is effectively no longer visible to 72 // connection B. 73 RemoveNodeFromParent(uint32 node_id, 74 uint32 server_change_id) => (bool success); 75 76 // Reorders a node in its parent, relative to |relative_node_id| according to 77 // |direction|. 78 // Only the connection that created the node's parent can reorder its 79 // children. 80 ReorderNode(uint32 node_id, 81 uint32 relative_node_id, 82 OrderDirection direction, 83 uint32 server_change_id) => (bool success); 84 85 // Returns the nodes comprising the tree starting at |node_id|. |node_id| is 86 // the first result in the return value, unless |node_id| is invalid, in which 87 // case an empty vector is returned. The nodes are visited using a depth first 88 // search (pre-order). 89 GetNodeTree(uint32 node_id) => (NodeData[] nodes); 90 91 // Creates a new view with the specified id. It is up to the client to ensure 92 // the id is unique to the connection (the id need not be globally unique). 93 // Additionally the connection id (embedded in |view_id|) must match that of 94 // the connection. 95 CreateView(uint32 view_id) => (bool success); 96 97 // Deletes the view with the specified id. Only the connection that created 98 // the view can delete it. 99 DeleteView(uint32 view_id) => (bool success); 100 101 // Sets the view a node is showing. 102 SetView(uint32 node_id, uint32 view_id) => (bool success); 103 104 // Shows the specified image (png encoded) in the specified view. 105 SetViewContents(uint32 view_id, 106 handle<shared_buffer> buffer, 107 uint32 buffer_size) => (bool success); 108 109 // Sets focus to the specified node. 110 SetFocus(uint32 node_id) => (bool success); 111 112 // Embeds the app at |url| in the specified nodes. More specifically this 113 // creates a new connection to the specified url, expecting to get an 114 // ViewManagerClient and configures it with the root nodes |nodes|. Fails 115 // if |nodes| is empty or contains nodes that were not created by this 116 // connection. 117 // If a particular client invokes Embed() multiple times with the same url, 118 // the connection is reused. When this happens the ViewManagerClient is 119 // notified of the additional roots by way of OnRootsAdded(). 120 Embed(string url, uint32[] nodes) => (bool success); 121 122 // TODO(sky): move these to a separate interface when FIFO works. 123 124 // Sends OnViewInputEvent() to the owner of the specified view. 125 DispatchOnViewInputEvent(uint32 view_id, mojo.Event event); 126 }; 127 128 // Changes to nodes/views are not sent to the connection that originated the 129 // change. For example, if connection 1 attaches a view to a node (SetView()) 130 // connection 1 does not receive OnNodeViewReplaced(). 131 [Client=ViewManagerService] 132 interface ViewManagerClient { 133 // Invoked once the connection has been established. |connection_id| is the id 134 // that uniquely identifies this connection. |next_server_change_id| is the 135 // id of the next change the server is expecting. |nodes| are the nodes 136 // parented to the root. 137 OnViewManagerConnectionEstablished(uint16 connection_id, 138 string creator_url, 139 uint32 next_server_change_id, 140 NodeData[] nodes); 141 142 // See description of ViewManagerService::Connect() for details as to when 143 // this is invoked. 144 OnRootsAdded(NodeData[] nodes); 145 146 // This is sent to clients when a change is made to the server that results 147 // in the |server_change_id| changing but the client isn't notified. This is 148 // not sent if the client receives a callback giving a new 149 // |server_change_id|. For example, if a client 1 changes the hierarchy in 150 // some way but client 2 isn't notified of the change, then client 2 gets 151 // OnServerChangeIdAdvanced(). 152 OnServerChangeIdAdvanced(uint32 next_server_change_id); 153 154 // Invoked when a node's bounds have changed. 155 OnNodeBoundsChanged(uint32 node, mojo.Rect old_bounds, mojo.Rect new_bounds); 156 157 // Invoked when a change is done to the hierarchy. A value of 0 is used to 158 // identify a null node. For example, if the old_parent is NULL, 0 is 159 // supplied. See description above ViewManager for details on the change ids. 160 // |nodes| contains any nodes that are that the client has not been told 161 // about. This is not sent for hierarchy changes of nodes not known to this 162 // client or not attached to the tree. 163 OnNodeHierarchyChanged(uint32 node, 164 uint32 new_parent, 165 uint32 old_parent, 166 uint32 server_change_id, 167 NodeData[] nodes); 168 169 // Invoked when the order of nodes within a parent changes. 170 OnNodeReordered(uint32 node_id, 171 uint32 relative_node_id, 172 OrderDirection direction, 173 uint32 server_change_id); 174 175 // Invoked when a node is deleted. 176 OnNodeDeleted(uint32 node, uint32 server_change_id); 177 178 // Invoked when the view associated with a node is replaced by another view. 179 // 0 is used to identify a null view. 180 OnNodeViewReplaced(uint32 node, uint32 new_view_id, uint32 old_view_id); 181 182 // Invoked when a view is deleted. 183 OnViewDeleted(uint32 view); 184 185 // Invoked when an event is targeted at the specified view. 186 OnViewInputEvent(uint32 view, mojo.Event event) => (); 187 188 // TODO(sky): move to separate interface when FIFO sorted out. 189 190 DispatchOnViewInputEvent(uint32 view, mojo.Event event); 191 }; 192 193 } 194