OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 module mojo.services.view_manager { | 5 module mojo.services.view_manager { |
6 | 6 |
7 struct INode { | 7 struct INode { |
8 uint32 parent_id; | 8 uint32 parent_id; |
9 uint32 node_id; | 9 uint32 node_id; |
10 uint32 view_id; | 10 uint32 view_id; |
11 }; | 11 }; |
12 | 12 |
13 // Functions that mutate the hierarchy take a |change_id|. |change_id| is an | 13 // Functions that mutate the hierarchy take two change ids: |
14 // arbitrary value assigned by the client originating the change. It may be | 14 // |server_change_id|: this is an ever increasing integer used to identify the |
15 // used by the client originating the change to later identify the change in | 15 // change. Every hierarchy change increases this value. The server only accepts |
16 // an OnNodeHierarchyChanged callback. |change_id| is only passed to the client | 16 // changes where the supplied |server_change_id| matches the expected next |
17 // that originated the change; all other clients get a value of 0. | 17 // value. This ensures changes are made in a well defined order. The client is |
| 18 // told the |server_change_id| when the connection is initially established and |
| 19 // subsequentely in any changes. |
18 // | 20 // |
19 // Nodes are identified by a uint32. The upper 16 bits are the connection id, | 21 // |client_change_id|: this id is for use by the client to further identify the |
20 // and the lower 16 the id assigned by the client. CreateNode() only takes a | 22 // change. This value is supplied in the mutation notifications to clients. |
21 // uint16 as the connection id of the originating connection is used. | 23 // Connections that did not originate the change get a value of 0. |
| 24 // |
| 25 // Nodes and Views are identified by a uint32. The upper 16 bits are the |
| 26 // connection id, and the lower 16 the id assigned by the client. Functions |
| 27 // that take a 16 bit value (such as CreateNode()) use the id of the current |
| 28 // connection. |
22 // | 29 // |
23 // The root node is identified with a connection id of 0, and value of 1. | 30 // The root node is identified with a connection id of 0, and value of 1. |
24 [Client=IViewManagerClient] | 31 [Client=IViewManagerClient] |
25 interface IViewManager { | 32 interface IViewManager { |
26 // Creates a new node with the specified id. It is up to the client to ensure | 33 // Creates a new node with the specified id. It is up to the client to ensure |
27 // the id is unique to the connection (the id need not be globally unique). | 34 // the id is unique to the connection (the id need not be globally unique). |
28 CreateNode(uint16 node_id) => (bool success); | 35 CreateNode(uint16 node_id) => (bool success); |
29 | 36 |
30 // Deletes a node. This does not recurse. Children are removed from the node | 37 // Deletes a node. This does not recurse. Children are removed from the node |
31 // before it is destroyed. | 38 // before it is destroyed. Deletion is always allowed and implicitly advances |
| 39 // the server_change_id. |
32 DeleteNode(uint32 node_id, uint32 change_id) => (bool success); | 40 DeleteNode(uint32 node_id, uint32 change_id) => (bool success); |
33 | 41 |
34 // Reparents a node. See description above class for details of |change_id|. | 42 // Reparents a node. See description above class for details of |change_id|. |
35 AddNode(uint32 parent, uint32 child, uint32 change_id) => (bool success); | 43 // This fails for any of the following reasons: |
| 44 // . |server_change_id| is not the expected id. |
| 45 // . |parent| or |child| does not identify a valid node. |
| 46 // . |child| is an ancestor of |parent|. |
| 47 // . |child| is already a child of |parent|. |
| 48 AddNode(uint32 parent, |
| 49 uint32 child, |
| 50 uint32 server_change_id, |
| 51 uint32 client_change_id) => (bool success); |
36 | 52 |
37 // Removes a view from its current parent. See description above class for | 53 // Removes a view from its current parent. See description above class for |
38 // details of |change_id|. | 54 // details of |change_id|. This fails if the node is not valid, |
39 RemoveNodeFromParent(uint32 node_id, uint32 change_id) => (bool success); | 55 // |server_change_id| doesn't match, or the node already has no parent. |
| 56 RemoveNodeFromParent(uint32 node_id, |
| 57 uint32 server_change_id, |
| 58 uint32 client_change_id) => (bool success); |
40 | 59 |
41 // Returns the nodes comprising the tree starting at |node_id|. |node_id| is | 60 // Returns the nodes comprising the tree starting at |node_id|. |node_id| is |
42 // the first result in the return value, unless |node_id| is invalid, in which | 61 // the first result in the return value, unless |node_id| is invalid, in which |
43 // case an empty vector is returned. The nodes are visited using a depth first | 62 // case an empty vector is returned. The nodes are visited using a depth first |
44 // search (pre-order). | 63 // search (pre-order). |
45 GetNodeTree(uint32 node_id) => (INode[] nodes); | 64 GetNodeTree(uint32 node_id) => (INode[] nodes); |
46 | 65 |
47 // Creates a new view with the specified id. It is up to the client to ensure | 66 // Creates a new view with the specified id. It is up to the client to ensure |
48 // the id is unique to the connection (the id need not be globally unique). | 67 // the id is unique to the connection (the id need not be globally unique). |
49 CreateView(uint16 view_id) => (bool success); | 68 CreateView(uint16 view_id) => (bool success); |
50 | 69 |
51 // Deletes the view with the specified id. | 70 // Deletes the view with the specified id. |
52 DeleteView(uint32 view_id, uint32 change_id) => (bool success); | 71 DeleteView(uint32 view_id, uint32 change_id) => (bool success); |
53 | 72 |
54 // Sets the view a node is showing. | 73 // Sets the view a node is showing. |
55 SetView(uint32 node_id, uint32 view_id, uint32 change_id) => (bool success); | 74 SetView(uint32 node_id, uint32 view_id, uint32 change_id) => (bool success); |
56 | 75 |
57 // Shows the specified image (png encoded) in the specified view. | 76 // Shows the specified image (png encoded) in the specified view. |
58 SetViewContents(uint32 view_id, | 77 SetViewContents(uint32 view_id, |
59 handle<shared_buffer> buffer, | 78 handle<shared_buffer> buffer, |
60 uint32 buffer_size); | 79 uint32 buffer_size); |
61 }; | 80 }; |
62 | 81 |
63 interface IViewManagerClient { | 82 interface IViewManagerClient { |
64 // Invoked once the connection has been established. |connection_id| is the id | 83 // Invoked once the connection has been established. |connection_id| is the id |
65 // used to uniquely identify the connection. | 84 // that uniquely identifies this connection. |next_server_change_id| is the |
66 OnConnectionEstablished(uint16 connection_id); | 85 // id of the next change the server is expecting. |
| 86 OnConnectionEstablished(uint16 connection_id, |
| 87 uint32 next_server_change_id); |
67 | 88 |
68 // Invoked when a change is done to the hierarchy. A value of 0 is used to | 89 // Invoked when a change is done to the hierarchy. A value of 0 is used to |
69 // identify a null node. For example, if the old_parent is NULL, 0 is | 90 // identify a null node. For example, if the old_parent is NULL, 0 is |
70 // supplied. See description above ViewManager for details on |change_id|. | 91 // supplied. See description above ViewManager for details on the change ids. |
71 OnNodeHierarchyChanged(uint32 node, | 92 OnNodeHierarchyChanged(uint32 node, |
72 uint32 new_parent, | 93 uint32 new_parent, |
73 uint32 old_parent, | 94 uint32 old_parent, |
74 uint32 change_id); | 95 uint32 server_change_id, |
| 96 uint32 client_change_id); |
| 97 |
| 98 // Invoked when a node is deleted. |
| 99 OnNodeDeleted(uint32 node, |
| 100 uint32 server_change_id, |
| 101 uint32 client_change_id); |
| 102 |
75 | 103 |
76 // Invoked when the view associated with a node is replaced by another view. | 104 // Invoked when the view associated with a node is replaced by another view. |
77 // 0 is used to identify a null view. | 105 // 0 is used to identify a null view. |
78 OnNodeViewReplaced(uint32 node, | 106 OnNodeViewReplaced(uint32 node, |
79 uint32 new_view_id, | 107 uint32 new_view_id, |
80 uint32 old_view_id, | 108 uint32 old_view_id, |
81 uint32 change_id); | 109 uint32 client_change_id); |
82 | |
83 // Invoked when a node is deleted. | |
84 OnNodeDeleted(uint32 node, uint32 change_id); | |
85 }; | 110 }; |
86 | 111 |
87 } | 112 } |
OLD | NEW |