chromium/third_party/blink/public/mojom/scroll/scroll_into_view_params.mojom

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

module blink.mojom;

import "third_party/blink/public/mojom/scroll/scroll_enums.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";

// This struct contains the required information for propagating some stages
// of scrolling process to cross process frames. Specifically for various types
// of programmatic scrolling such as scrolling an element into view, recursive
// scrolling across multiple processes is accommodated through passing the state
// using this struct to the browser and then to the target (parent) process.

// The default value matches ScrollAlignment::CenterIfNeeded().
struct ScrollAlignment {
  enum Behavior {
    kNoScroll = 0,
    kCenter,
    kTop,
    kBottom,
    kLeft,
    kRight,
    kClosestEdge,
  };

  Behavior rect_visible = kNoScroll;
  Behavior rect_hidden = kCenter;
  Behavior rect_partial = kClosestEdge;
};

struct FocusedEditableParams {
  // The location and size of the focused editable element whose caret is being
  // used as the rect to ScrollIntoView. The location is relative to the caret
  // rect which is being used to ScrollIntoView. The location must be stored
  // relative to the caret (rather than typical absolute, relative to frame,
  // coordinates) since each scroll will change the caret absolute position
  // which is transformed by ScrollIntoView but this out-of-band rect isn't.
  // The absolute rect for the editable can then be reconstructed at the end of
  // the ScrollIntoView from the caret rect.
  gfx.mojom.Vector2dF relative_location;
  gfx.mojom.SizeF size;

  // This can be set to false to indicate that zooming shouldn't occur, e.g.
  // because the editable may block pinch gestures. e.g if the textbox is
  // within a touch-action: none container the user can't zoom back out.
  bool can_zoom = true;
};

struct ScrollIntoViewParams {
  ScrollAlignment align_x;
  ScrollAlignment align_y;
  ScrollType type = ScrollType.kProgrammatic;
  bool make_visible_in_visual_viewport = true;
  ScrollBehavior behavior = ScrollBehavior.kAuto;
  bool is_for_scroll_sequence = false;

  // If present, indicates that the scroll into view is a result of focusing an
  // editable element. Unlike regular scroll into view, after revealing the
  // caret in the top most document, the viewport will perform an animated
  // scroll and zoom to make the editable a legible size and has special logic
  // for placement of the caret and editable for convenient input.
  FocusedEditableParams? for_focused_editable;

  // Whether a ScrollIntoView should bubble from an iframe to a parent that
  // isn't same-origin. This defaults to true since that's the behavior of JS
  // APIs and most legacy callsites but new uses should carefully consider
  // whether they need this behavior.
  bool cross_origin_boundaries = true;
};