chromium/cc/mojom/render_frame_metadata.mojom

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module cc.mojom;

import "services/viz/public/mojom/compositing/local_surface_id.mojom";
import "services/viz/public/mojom/compositing/selection.mojom";
import "services/viz/public/mojom/compositing/vertical_scroll_direction.mojom";
import "skia/public/mojom/skcolor4f.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";

// Contains information to assist in making a decision about forwarding
// pointerevents to viz for use in a delegated ink trail.
struct DelegatedInkBrowserMetadata {
  // Flag used to indicate the state of the hovering on the pointerevent that
  // the delegated ink metadata was created from. If this state does not match
  // the point under consideration to send to viz, it won't be sent. As soon
  // as it matches again the point will be sent, regardless of if the renderer
  // has processed the point that didn't match yet or not. It is true when
  // hovering, false otherwise.
  bool delegated_ink_is_hovering;
};

// See cc/trees/render_frame_metadata.h
struct RenderFrameMetadata {
  // The background color of a CompositorFrame. It can be used for filling the
  // content area if the primary surface is unavailable and fallback is not
  // specified.
  skia.mojom.SkColor4f root_background_color;

  // Scroll offset of the root layer. This optional parameter is only sent
  // during tests.
  gfx.mojom.PointF? root_scroll_offset;

  // Indicates whether the scroll offset of the root layer is at top, i.e.,
  // whether scroll_offset.y() == 0.
  bool is_scroll_offset_at_top;

  // Selection region relative to the current viewport. If the selection is
  // empty or otherwise unused, the bound types will indicate such.
  viz.mojom.Selection selection;

  // Determines whether the page is mobile optimized or not, which means at
  // least one of the following has to be true:
  // - page has a width=device-width or narrower viewport.
  // - page prevents zooming in or out (i.e. min and max page scale factors
  // are the same).
  bool is_mobile_optimized;

  // Existence of this flag informs the browser process to start forwarding
  // points to viz for use in a delegated ink trail. It contains more
  // information to be used in making the forwarding decision. It exists the
  // entire time points could be forwarded, and forwarding must stop as soon as
  // it is null.
  DelegatedInkBrowserMetadata? delegated_ink_metadata;

  // The device scale factor used to generate CompositorFrame.
  float device_scale_factor;

  // The size of the viewport used to generate a CompositorFrame.
  gfx.mojom.Size viewport_size_in_pixels;

  // The last viz::LocalSurfaceId used to submit a CompositorFrame.
  viz.mojom.LocalSurfaceId? local_surface_id;

  // The page scale factor used on the content.
  float page_scale_factor;

  // The subframe page scale factor used on the content. This value will match
  // |page_scale_factor|, which is only ever set for the main frame, and it is
  // only used for setting raster scale in child renderers.
  float external_page_scale_factor;

  // Used to position the Android location top bar and page content, whose
  // precise position is computed by the renderer compositor.
  float top_controls_height;

  float top_controls_shown_ratio;

  viz.mojom.VerticalScrollDirection new_vertical_scroll_direction;

  // Indicates the `item_sequence_number` for the primary main frame's
  // `content::FrameNavigationEntry`. This is only set if the primary main frame
  // is rendering to this compositor.
  int64 primary_main_frame_item_sequence_number;

  // Used to position Android/iOS bottom bar, whose position is computed by the
  // renderer compositor.
  [EnableIf=is_android_or_ios]
  float bottom_controls_height;

  [EnableIf=is_android_or_ios]
  float bottom_controls_shown_ratio;

  [EnableIf=is_android_or_ios]
  float top_controls_min_height_offset;

  [EnableIf=is_android_or_ios]
  float bottom_controls_min_height_offset;

  [EnableIf=is_android_or_ios]
  float min_page_scale_factor;

  [EnableIf=is_android_or_ios]
  float max_page_scale_factor;

  [EnableIf=is_android_or_ios]
  bool root_overflow_y_hidden;

  [EnableIf=is_android_or_ios]
  gfx.mojom.SizeF scrollable_viewport_size;

  [EnableIf=is_android_or_ios]
  gfx.mojom.SizeF root_layer_size;

  [EnableIf=is_android_or_ios]
  bool has_transparent_background;
};

[EnableIf=is_android]
enum RootScrollOffsetUpdateFrequency {
  // The client will only be notified of root scroll offsets via the regular
  // RenderFrameMetadata updates. This is the default behavior. See
  // `RenderFrameMetadataObserverImpl::ShouldSendRenderFrameMetadata()` for
  // details on when the RenderFrameMetadata updates occur.
  kNone,
  // The client will also be notified with an updated root scroll offset when a
  // scroll ends in addition to offset updates sent via RenderFrameMetadata
  // updates.
  kOnScrollEnd,
  // The client will be notified of any change to the root scroll offset.
  kAllUpdates,
};

// This interface is provided by the renderer. It impacts the frequency with
// which a fully populated RenderFrameMetadata object (above) is delivered to
// the RenderFrameMetadataObserverClient.
interface RenderFrameMetadataObserver {
  // When `frequency` is set to a value other than `kNone`, this notifies the
  // client of changes to the root scroll offset. The client is notified in
  // several ways:
  // . OnRenderFrameMetadataChanged(), is sent if the client would normally be
  //   notified of the frame (for example, the viewport changed). If `frequency`
  //   is `kNone`, the client is not sent `OnRootScrollOffsetChanged()`.
  // . OnRootScrollOffsetChanged() if the client is not notified of the frame
  //   change:
  //   - but `frequency` is `kOnScrollEnd` and a scroll has just ended.
  //   - but `frequency` is `kAllUpdates` and the scroll offset has changed.
  //
  // In other words, if this is sent, *only* the root-scroll-offset has changed
  // and the client is not sent a OnRenderFrameMetadataChanged() for the frame.
  // Used on Android for acessibility and GestureListenerManager.
  [EnableIf=is_android]
  UpdateRootScrollOffsetUpdateFrequency(
      RootScrollOffsetUpdateFrequency frequency);

  // When |enabled| is set to true, this will send RenderFrameMetadata to
  // the RenderFrameMetadataObserverClient for all frames. Only used for
  // tests.
  ReportAllFrameSubmissionsForTesting(bool enabled);
};

// This interface is provided by the browser. It is notified of changes to
// RenderFrameMetadata. It can be notified of all frame submissions, via
// RenderFrameMetadataObserver::ReportAllFrameSubmissionsForTesting, or of
// additional frames with root scroll offset changes via
// RenderFrameMetadataObserver::UpdateRootScrollOffsetUpdateFrequency.
interface RenderFrameMetadataObserverClient {
  // Notified when RenderFrameMetadata has changed.
  OnRenderFrameMetadataChanged(uint32 frame_token,
                               RenderFrameMetadata metadata);

  // Notified on all frame submissions.
  OnFrameSubmissionForTesting(uint32 frame_token);

  // Only called if UpdateRootScrollOffsetUpdateFrequency() has been called.
  [EnableIf=is_android]
  OnRootScrollOffsetChanged(gfx.mojom.PointF root_scroll_offset);
};