blob: f6f577121fb9c48da634088fe76816dfa9b14ebc [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library fuchsia.session;
using fuchsia.ui.views;
/// An interface used to present graphical views.
/// The `GraphicalPresenter` protocol is typically implemented by a session component or
/// its child that presents element views.
/// The presented views can be annotated with `fuchsia.session.Annotations` to communicate
/// presentation properties to the `GraphicalPresenter`.
protocol GraphicalPresenter {
/// Presents the view described by `view_spec`.
/// ## ViewSpec
/// `view_spec.view_holder_token` and `view_spec.view_ref` must be valid,
/// otherwise `PresentView` will fail with `ViewControllerEpitaph.INVALID_VIEW_SPEC`.
/// ## ViewController
/// `view_controller_request` allows clients to receive a `ViewController` for the
/// presented view. The client can use the `ViewController` to control the view's
/// presentation and receive events.
/// If `view_controller_request` is closed, the client can assume that the view is
/// no longer being presented, and will not be presented in the future.
/// If the client closes the `view_controller_request`, or does not provide a request
/// to `PresentView`, the view may be dismissed at any time with no signal to the client.
/// ## Errors
/// `PresentView` errors are signaled by closing `view_controller_request`
/// with an epitaph, `ViewControllerEpitaph`. See [`ViewController`].
/// + `view_spec` describes the view to present
/// + `view_controller_request` an optional request for a controller for the view
PresentView(ViewSpec view_spec, request<ViewController>? view_controller_request);
/// Epitaph returned when `ViewController` is closed to signal an error.
enum ViewControllerEpitaph {
/// The provided `ViewSpec` was missing a valid `ViewHolderToken`.
/// The presenter rejected the request to present the view.
/// A description of a view that can be presented by a `GraphicalPresenter`.
resource table ViewSpec {
/// The view holder token for the presented view.
1: fuchsia.ui.views.ViewHolderToken view_holder_token;
/// The `ViewRef` of the presented view.
2: fuchsia.ui.views.ViewRef view_ref;
/// The annotations associated with the presented view.
/// The presenter must observe incoming annotations and update the presentation
/// accordingly.
/// For views that come from elements, the annotations are expected to be the same
/// as the annotations for the element. For example, if the `GraphicalPresenter`
/// component uses `ElementManager` to add an element to the session, and gives it
/// an annotation, the presenter can expect that annotation to be passed back in
/// `ViewSpec.annotations` for the associated view.
/// Optional.
3: Annotations annotations;
/// An interface that gives clients of `GraphicalPresenter` control over a view
/// that was presented.
/// ## Lifecycle
/// The client must keep `ViewController` connected to ensure the view is
/// presented. Once `ViewController` is closed, the view will be
/// permanently dismissed.
/// For example, if the view originates from an element, the component
/// that manages the element's lifecycle may choose to stop the element's
/// component once the `ViewController` is closed.
/// ## Epitaph
/// This protocol is closed with an epitaph:
/// * `ViewControllerEpitaph.INVALID_VIEW_SPEC` if the view failed to be
/// presented because of a malformed `ViewSpec`
/// (see [`GraphicalPresenter.PresentView`])
/// * `ViewControllerEpitaph.REJECTED` if the presenter rejected the request
/// to present the view (see [`GraphicalPresenter.PresentView`])
/// * `ViewControllerEpitaph.ZX_OK` when the view is dismissed
protocol ViewController {
/// Annotates the view with `annotations`.
/// The presenter must observe incoming annotation requests and update
/// the presentation accordingly.
/// The presenter must adhere to the following rules for annotation updates:
/// * Annotations are added when their `Annotation.key` was not present in a
/// previous set of annotations
/// * Annotations are updated when their `Annotation.value` is non-null
/// * Annotations are deleted when their `Annotation.value` is null
/// When the `Annotate` call returns, clients can assume that annotations have
/// been updated and incorporated into the presentation.
Annotate(Annotations annotations) -> ();
/// Instructs the presenter to dismiss the associated view.
/// This call results in the `ViewController` being closed with a
/// `ZX_OK` epitaph once any exit animation has been performed, the
/// view/view holder connection has been severed, and the component
/// instance serving the view can be terminated.
/// Informs the view controller that the view was presented successfully.
-> OnPresented();