| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 [DartPackage="mojo_services"] | 5 [DartPackage="mojo_services"] |
| 6 module mojo.ui; | 6 module mojo.ui; |
| 7 | 7 |
| 8 import "mojo/public/interfaces/application/service_provider.mojom"; | 8 import "mojo/public/interfaces/application/service_provider.mojom"; |
| 9 import "mojo/services/gfx/composition/interfaces/scenes.mojom"; | 9 import "mojo/services/gfx/composition/interfaces/scenes.mojom"; |
| 10 import "mojo/services/ui/views/interfaces/layouts.mojom"; | 10 import "mojo/services/ui/views/interfaces/layouts.mojom"; |
| 11 | 11 |
| 12 // A view token is an opaque transferable reference to a view. | 12 // A view token is an opaque transferable reference to a view. |
| 13 // | 13 // |
| 14 // The ViewManager provides each view with a unique view token when | 14 // The ViewManager provides each view with a unique view token when |
| 15 // it is registered. The token can subsequently be passed to other | 15 // it is registered. The token can subsequently be passed to other |
| 16 // applications and may be used to add the view as a child of some | 16 // applications and may be used to add the view as a child of some |
| 17 // other view or to set it as the root of a view tree. | 17 // other view or to set it as the root of a view tree. |
| 18 // | 18 // |
| 19 // View tokens should be kept secret and should only be shared with | 19 // View tokens should be kept secret and should only be shared with |
| 20 // the view's intended container. | 20 // the view's intended container. |
| 21 // | 21 // |
| 22 // TODO(jeffbrown): This implementation is a temporary placeholder until | 22 // TODO(jeffbrown): This implementation is a temporary placeholder until |
| 23 // we extend Mojo to provide a way to create tokens which cannot be forged. | 23 // we extend Mojo to provide a way to create tokens which cannot be forged. |
| 24 struct ViewToken { | 24 struct ViewToken { |
| 25 uint32 value; | 25 uint32 value; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 // A view owner provides access to the view's token and keeps the |
| 29 // view alive. When the view owner is closed, the view will be |
| 30 // unregistered from the view manager. |
| 31 // |
| 32 // This interface is only intended to be implemented by the view manager |
| 33 // to obtain the desired ownership semantics. |
| 34 interface ViewOwner { |
| 35 // Gets the |ViewToken| associated with the view. |
| 36 GetToken() => (ViewToken token); |
| 37 }; |
| 38 |
| 28 // A view is a graphical user interface component which is responsible | 39 // A view is a graphical user interface component which is responsible |
| 29 // for drawing and supporting user interactions in the area of the screen | 40 // for drawing and supporting user interactions in the area of the screen |
| 30 // that it occupies. | 41 // that it occupies. |
| 31 // | 42 // |
| 32 // A view may also act as a container for other views (known as the | 43 // A view may also act as a container for other views (known as the |
| 33 // view's children) which it may freely layout and position anywhere | 44 // view's children) which it may freely layout and position anywhere |
| 34 // within its bounds to form a composite user interface. The hierarchy | 45 // within its bounds to form a composite user interface. The hierarchy |
| 35 // of views thus formed is called a view tree. | 46 // of views thus formed is called a view tree. |
| 36 // | 47 // |
| 37 // A view must registered with the view manager before it can be shown. | 48 // A view must registered with the view manager before it can be shown. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 OnChildUnavailable(uint32 child_key) => (); | 104 OnChildUnavailable(uint32 child_key) => (); |
| 94 }; | 105 }; |
| 95 | 106 |
| 96 // The view host provides an interface for a view to configure itself and | 107 // The view host provides an interface for a view to configure itself and |
| 97 // interact with its local environment, such as adding and removing | 108 // interact with its local environment, such as adding and removing |
| 98 // children and specifying layout constraints. | 109 // children and specifying layout constraints. |
| 99 // | 110 // |
| 100 // Each view obtains its own view host when registered with the ViewManager. | 111 // Each view obtains its own view host when registered with the ViewManager. |
| 101 // To unregister the view, close its view host message pipe. | 112 // To unregister the view, close its view host message pipe. |
| 102 interface ViewHost { | 113 interface ViewHost { |
| 114 // Gets the view's token. |
| 115 GetToken() => (ViewToken token); |
| 116 |
| 103 // Gets a service provider to access services which are associated with | 117 // Gets a service provider to access services which are associated with |
| 104 // the view such as input, accessibility and editing capabilities. | 118 // the view such as input, accessibility and editing capabilities. |
| 105 // The view service provider is private to the view and should not be | 119 // The view service provider is private to the view and should not be |
| 106 // shared with anyone else. | 120 // shared with anyone else. |
| 107 // | 121 // |
| 108 // See |mojo.ui.InputConnection|. | 122 // See |mojo.ui.InputConnection|. |
| 109 GetServiceProvider(mojo.ServiceProvider& service_provider); | 123 GetServiceProvider(mojo.ServiceProvider& service_provider); |
| 110 | 124 |
| 111 // Creates the view's scene, replacing any previous scene the view | 125 // Creates the view's scene, replacing any previous scene the view |
| 112 // might have had. | 126 // might have had. |
| 113 // | 127 // |
| 114 // The |scene| is used to supply content for the scene. The scene pipe | 128 // The |scene| is used to supply content for the scene. The scene pipe |
| 115 // is private to the scene and should not be shared with anyone else. | 129 // is private to the scene and should not be shared with anyone else. |
| 116 // | 130 // |
| 117 // To destroy the scene, simply close the |scene| message pipe. | 131 // To destroy the scene, simply close the |scene| message pipe. |
| 118 // | 132 // |
| 119 // See also: |mojo.gfx.composition.Compositor.CreateScene()|. | 133 // See also: |mojo.gfx.composition.Compositor.CreateScene()|. |
| 120 CreateScene(mojo.gfx.composition.Scene& scene); | 134 CreateScene(mojo.gfx.composition.Scene& scene); |
| 121 | 135 |
| 122 // Requests that the view's OnLayout() method be called to compute a | 136 // Requests that the view's OnLayout() method be called to compute a |
| 123 // new layout due to a change in the view's layout information. | 137 // new layout due to a change in the view's layout information. |
| 124 RequestLayout(); | 138 RequestLayout(); |
| 125 | 139 |
| 126 // Adds the view referenced by |child_view_token| as a child and assigns | 140 // Adds the view referenced by |child_view_owner| as a child and assigns |
| 127 // it the provided |child_key| to identify it among its children. | 141 // it the provided |child_key| to identify it among its children. |
| 128 // The parent may remove the child later by passing the same |child_key| | 142 // The parent may remove the child later by passing the same |child_key| |
| 129 // to RemoveChild(). | 143 // to RemoveChild(). |
| 130 // | 144 // |
| 145 // This method takes ownership of the view. |
| 146 // |
| 131 // It is important for the parent to choose locally unique values for | 147 // It is important for the parent to choose locally unique values for |
| 132 // |child_key| to ensure that each child can be distinguished even as | 148 // |child_key| to ensure that each child can be distinguished even as |
| 133 // more children are added or removed. We recommend using a simple | 149 // more children are added or removed. We recommend using a simple |
| 134 // counter which is incremented on each (re-)addition. | 150 // counter which is incremented on each (re-)addition. |
| 135 // | 151 // |
| 136 // If the child becomes unavailable at any time prior to being removed | 152 // If the child becomes unavailable at any time prior to being removed |
| 137 // then an OnChildUnavailable() message will be sent. | 153 // then an OnChildUnavailable() message will be sent. |
| 138 // | 154 // |
| 139 // If |child_view_token| refers to a view which is already unavailable or | 155 // If |child_view_owner| refers to a view which is already unavailable or |
| 140 // if adding the view would create a cycle in the view tree then the | 156 // if adding the view would create a cycle in the view tree then the |
| 141 // call proceeds as if it succeeded but an OnChildUnavailable() message | 157 // call proceeds as if it succeeded but an OnChildUnavailable() message |
| 142 // will be sent. | 158 // will be sent. |
| 143 // | 159 // |
| 144 // If |child_view_token| refers to a view which already has a parent or is | 160 // If |child_view_owner| refers to a view which already has a parent or is |
| 145 // the root of a view tree then an OnChildUnavailable() or OnRootUnavailable() | 161 // the root of a view tree then an OnChildUnavailable() or OnRootUnavailable() |
| 146 // message will be sent to its old parent or root and the the view will be | 162 // message will be sent to its old parent or root and the the view will be |
| 147 // (re-)added to its new parent as usual. This special case also applies | 163 // (re-)added to its new parent as usual. This special case also applies |
| 148 // when the specified view is already a child of this view, in which | 164 // when the specified view is already a child of this view, in which |
| 149 // case the behavior is similar to the view having been transferred to | 165 // case the behavior is similar to the view having been transferred to |
| 150 // some other parent and then back again. | 166 // some other parent and then back again. |
| 151 // | 167 // |
| 152 // Note that an unavailable child will remain in its parent's list of | 168 // Note that an unavailable child will remain in its parent's list of |
| 153 // children until its parent explicitly calls RemoveChild() to remove | 169 // children until its parent explicitly calls RemoveChild() to remove |
| 154 // it. | 170 // it. |
| 155 // | 171 // |
| 156 // It is an error to add a view whose |child_key| already appears | 172 // It is an error to add a view whose |child_key| already appears |
| 157 // in the view's list of children; the connection will be closed. | 173 // in the view's list of children; the connection will be closed. |
| 158 AddChild(uint32 child_key, mojo.ui.ViewToken child_view_token); | 174 AddChild(uint32 child_key, mojo.ui.ViewOwner child_view_owner); |
| 159 | 175 |
| 160 // Removes the view referenced by |child_key| from the view's | 176 // Removes the view referenced by |child_key| from the view's |
| 161 // list of children. | 177 // list of children. |
| 162 // | 178 // |
| 179 // If |transferred_view_owner| is not null, associates it with the |
| 180 // previously added child to allow it to be transferred elsewhere or |
| 181 // closes the |transferred_view_owner| message pipe if there was none. |
| 182 // |
| 163 // It is an error to remove a view whose |child_key| does not appear | 183 // It is an error to remove a view whose |child_key| does not appear |
| 164 // in the parent's list of children; the connection will be closed. | 184 // in the parent's list of children; the connection will be closed. |
| 165 RemoveChild(uint32 child_key); | 185 RemoveChild(uint32 child_key, mojo.ui.ViewOwner&? transferred_view_owner); |
| 166 | 186 |
| 167 // Sets the layout parameters of the child view referenced by |child_key| | 187 // Sets the layout parameters of the child view referenced by |child_key| |
| 168 // and retrieves its layout information. | 188 // and retrieves its layout information. |
| 169 // | 189 // |
| 170 // The returned |info| is null if this layout request was canceled either | 190 // The returned |info| is null if this layout request was canceled either |
| 171 // because it has been superceded by a subsequently issued layout request | 191 // because it has been superceded by a subsequently issued layout request |
| 172 // or because the child has become unavailable. | 192 // or because the child has become unavailable. |
| 173 // | 193 // |
| 174 // It is an error to specify a |child_key| that does not appear in | 194 // It is an error to specify a |child_key| that does not appear in |
| 175 // the parent's list of children; the connection will be closed. | 195 // the parent's list of children; the connection will be closed. |
| 176 // | 196 // |
| 177 // It is an error to specify malformed |child_layout_params| such | 197 // It is an error to specify malformed |child_layout_params| such |
| 178 // as invalid size constraints; the connection will be closed. | 198 // as invalid size constraints; the connection will be closed. |
| 179 LayoutChild(uint32 child_key, mojo.ui.ViewLayoutParams child_layout_params) | 199 LayoutChild(uint32 child_key, mojo.ui.ViewLayoutParams child_layout_params) |
| 180 => (mojo.ui.ViewLayoutInfo? info); | 200 => (mojo.ui.ViewLayoutInfo? info); |
| 181 }; | 201 }; |
| OLD | NEW |