Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 [DartPackage="mojo_services"] | |
| 6 module mojo.ui; | |
| 7 | |
| 8 import "mojo/public/interfaces/application/service_provider.mojom"; | |
| 9 import "mojo/services/ui/views/interfaces/layouts.mojom"; | |
| 10 | |
| 11 // A view token is an opaque transferable reference to a view which | |
| 12 // be exchanged among clients of the ViewManager. | |
| 13 // | |
| 14 // Since view tokens can be used to add a view to the view tree and affect | |
| 15 // the behavior of a view they should only be shared with the view's | |
| 16 // intended container. | |
| 17 // | |
| 18 // TODO(jeffbrown): This implementation is a temporary placeholder until | |
| 19 // we extend Mojo to provide a way to create tokens which cannot be forged. | |
| 20 struct ViewToken { | |
| 21 uint32 value; | |
| 22 }; | |
| 23 | |
| 24 // A view is a graphical user interface component which is responsible | |
| 25 // for drawing and supporting user interactions in the area of the screen | |
| 26 // that it occupies. | |
| 27 // | |
| 28 // A view may also act as a container for other views (known as the | |
| 29 // view's children) which it may freely layout and position anywhere | |
| 30 // within its bounds to form a composite user interface. The hierarchy | |
| 31 // of views thus formed is called a view tree. | |
| 32 // | |
| 33 // A view must registered with the view manager before it can be shown. | |
| 34 interface View { | |
| 35 // Called when the view needs to update its layout and provide its size. | |
| 36 // | |
| 37 // This method may be called for one or more of the following reasons: | |
| 38 // | |
| 39 // 1. The view called RequestLayout() to mark itself as needing layout. | |
| 40 // 2. The view's parent called LayoutChild() for the first time to | |
| 41 // provide layout parameters to this view. | |
| 42 // 3. The view's parent called LayoutChild() and provided a | |
| 43 // set of layout parameters which differ from its prior call to | |
| 44 // OnLayout(). | |
| 45 // 4. One or more of the view's children were just added to the view | |
| 46 // tree using AddChild() or removed from the tree using RemoveChild(). | |
| 47 // 5. One or more of the view's children produced different layout | |
| 48 // information during their last layout pass causing a recursive | |
| 49 // layout to occur. | |
| 50 // | |
| 51 // The |children_needing_layout| array includes the keys of all children | |
| 52 // which require a layout. The view is responsible for calling LayoutChild() | |
| 53 // at least once for each child in the array in addition to any other | |
| 54 // children which might also need to be updated. | |
| 55 // | |
| 56 // Layout requests are coalesced for efficiency. Certain intermediate | |
| 57 // updates may be dropped if the view is unable to keep up with them | |
| 58 // in a timely manner. Do nothing updates are always dropped. | |
| 59 // | |
| 60 // The implementation should invoke the callback once the event has | |
| 61 // been handled and the view is ready to be shown in its new aspect. | |
| 62 // | |
| 63 // The result of the layout may cause the parent's layout to be invalidated. | |
| 64 // When this happens, the parent's own OnLayout() method will be called | |
| 65 // and will be informed that this child needs layout. | |
| 66 // | |
| 67 // Recursive layout happens in any of the following circumstances: | |
| 68 // | |
| 69 // 1. If the resulting surface has changed since the last layout. | |
| 70 // 2. If the resulting size has changed since the last layout and | |
| 71 // the parent view uses its child's size as part of its own layout | |
| 72 // calculations, as indicated in the parameters to the parent's most | |
| 73 // recent call to LayoutChild(). | |
| 74 // | |
| 75 // It is an error to return a malformed |info| which does not satisfy | |
| 76 // the requested |layout_params|, such as by returning a null size or | |
| 77 // a size which exceeds the requested constraints; the view's connection | |
| 78 // will be closed. | |
| 79 OnLayout(mojo.ui.ViewLayoutParams layout_params, | |
| 80 array<uint32> children_needing_layout) => (mojo.ui.ViewLayoutInfo info); | |
| 81 | |
| 82 // Called when a child view has become unavailable. | |
| 83 // | |
| 84 // A child may become unavailable for many reasons such being unregistered | |
| 85 // by its application, abnormal termination of its application, or | |
| 86 // cycles being introduced in the view tree. | |
| 87 // | |
| 88 // To complete removal of an unavailable child, this view component must | |
| 89 // call RemoveChild() on its view host with |child_key|. | |
| 90 // | |
| 91 // The implementation should invoke the callback once the event has | |
| 92 // been handled. | |
| 93 OnChildUnavailable(uint32 child_key) => (); | |
| 94 }; | |
| 95 | |
| 96 // The view host provides an interface for a view to configure itself and | |
| 97 // interact with its local environment, such as adding and removing | |
| 98 // children and specifying layout constraints. | |
| 99 // | |
| 100 // Each view obtains its own view host when registered with the ViewManager. | |
| 101 // To unregister the view, close its view host message pipe. | |
| 102 interface ViewHost { | |
| 103 // Gets a service provider to access services which are associated with | |
| 104 // the view such as input, accessibility and editing capabilities. | |
| 105 // The view service provider is private to the view and should not be | |
| 106 // shared with anyone else. | |
| 107 GetServiceProvider(mojo.ServiceProvider& service_provider); | |
| 108 | |
| 109 // Requests that the view host's OnLayout() method be called to compute a | |
| 110 // new layout due to a change in the view's layout information. | |
| 111 RequestLayout(); | |
| 112 | |
| 113 // Adds the view referenced by |child_view_token| as a child of the view host | |
| 114 // and assigns it the provided |child_key| to identify it among its children. | |
| 115 // The view host may remove the child later by passing the same |child_key| | |
| 116 // to RemoveChild(). | |
| 117 // | |
| 118 // It is important for the view host to choose locally unique values for | |
| 119 // |child_key| to ensure that each child can be distinguished even as | |
| 120 // more children are added or removed. We recommend using a simple | |
| 121 // counter which is incremented on each (re-)addition. | |
| 122 // | |
| 123 // If the child becomes unavailable at any time prior to being removed | |
| 124 // then a OnChildUnavailable() message will be sent. | |
| 125 // | |
| 126 // If |child_view_token| refers to a view which is already unavailable or | |
| 127 // if adding the view would create a cycle in the view tree then the | |
| 128 // call proceeds as if it succeeded but an OnChildUnavailable() message | |
| 129 // will be sent. | |
| 130 // | |
| 131 // If |child_view_token| refers to a view which already has a parent or is | |
| 132 // the root of a view tree then an OnChildUnavailable() or OnRootUnavailable() | |
| 133 // message will be sent to its old parent or root and the the view will be | |
| 134 // (re-)added to its new parent as usual. This special case also applies | |
| 135 // when the specified view is already a child of this view host, in which | |
| 136 // case the behavior is similar to the view having been transferred to | |
| 137 // some other parent and then back again. | |
| 138 // | |
| 139 // Note that unavailable children remain in their parent's list of | |
| 140 // children until their parent explicitly calls RemoveChild() to remove | |
| 141 // them. Meanwhile, these children behave as if they were completely | |
| 142 // unresponsive. | |
| 143 // | |
| 144 // It is an error to add a view whose |child_key| already appears | |
| 145 // in the view host's list of children; the view host connection will | |
| 146 // be closed. | |
| 147 AddChild(uint32 child_key, mojo.ui.ViewToken child_view_token); | |
| 148 | |
| 149 // Removes the view referenced by |child_key| from the view host's | |
| 150 // list of children. | |
| 151 // | |
| 152 // It is an error to remove a view whose |child_key| does not appear | |
| 153 // in the view host's list of children; the view host connection will | |
| 154 // be closed. | |
| 155 RemoveChild(uint32 child_key); | |
| 156 | |
| 157 // Sets the layout parameters of the child view referenced by |child_key| and | |
| 158 // retrieves its layout information. | |
| 159 // | |
| 160 // If |provide_size| is true, the size of the child will be returned | |
| 161 // within |info|, otherwise it will be set to null and the view manager | |
| 162 // will assume that the view host's layout is not dependent on knowledge | |
|
jamesr
2015/10/26 19:35:38
is 'view host' here equivalent to 'parent'? having
jeffbrown
2015/10/27 01:49:07
Yeah, I hate referring to the "host" here. There'
| |
| 163 // of the child's size. Setting |provide_size| to false is more | |
| 164 // efficient since it allows the view manager to suppress unnecessary | |
| 165 // layout operations when only the child's size has changed. | |
| 166 // | |
| 167 // It is an error to specify a |child_key| that does not appear in | |
| 168 // the view host's list of children; the view host connection will | |
| 169 // be closed. | |
| 170 // | |
| 171 // The returned |info| is null if this layout request was canceled either | |
| 172 // because it has been superceded by a subsequently issued layout request | |
| 173 // or because the child has become unavailable. | |
| 174 // | |
| 175 // It is an error to specify malformed |child_layout_params| such | |
| 176 // as invalid size constraints; the view host connection will be closed. | |
| 177 LayoutChild(uint32 child_key, mojo.ui.ViewLayoutParams child_layout_params, | |
| 178 bool provide_size) => (mojo.ui.ViewLayoutInfo? info); | |
| 179 }; | |
| OLD | NEW |