chromium/third_party/blink/public/mojom/page/widget.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 "cc/mojom/touch_action.mojom";
import "mojo/public/mojom/base/text_direction.mojom";
import "services/viz/public/mojom/compositing/local_surface_id.mojom";
import "skia/public/mojom/bitmap.mojom";
import "third_party/blink/public/mojom/frame/intrinsic_sizing_info.mojom";
import "third_party/blink/public/mojom/frame/viewport_intersection_state.mojom";
import "third_party/blink/public/mojom/input/ime_host.mojom";
import "third_party/blink/public/mojom/input/touch_event.mojom";
import "third_party/blink/public/mojom/drag/drag.mojom";
import "third_party/blink/public/mojom/widget/platform_widget.mojom";
import "third_party/blink/public/mojom/widget/device_emulation_params.mojom";
import "third_party/blink/public/mojom/widget/visual_properties.mojom";
import "ui/base/dragdrop/mojom/drag_drop_types.mojom";
import "ui/base/mojom/ui_base_types.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";

[EnableIf=is_mac]
import "ui/base/mojom/attributed_string.mojom";

// Implemented in Blink, this interface defines frame-widget-specific methods that
// will be invoked from the browser process (e.g. blink::WebFrameWidget).
interface FrameWidget {
  // Drag-and-drop methods:
  // |point_in_viewport| is the position of the drag event in the viewport
  // coordinates.
  // |screen_point| is the absolute position of the mouse pointer.
  // |key_modifiers| the event/keyboard modifiers that are active during the
  // operation. See WebInputEvent::Modifiers.

  // Notifies the Widget of a drag enter operation. |drag_data| only
  // contains a subset of the actual drag data the browser has and it
  // used to only start the drag action. Once the item is dropped |drag_data|
  // will be provided with the complete data. Once the renderer has
  // completed processing the event the callback is called with the type of
  // the current drag operation that is active and the browser will update
  // the mouse cursor displayed to the user.
  //
  // The callback also receives whether the document is handling the drag in
  // |document_is_handling_drag|. This can be false for example when the
  // the renderer may handle the drop directly with some default action or
  // in editable regions.
  DragTargetDragEnter(DragData drag_data,
                      gfx.mojom.PointF point_in_viewport,
                      gfx.mojom.PointF screen_point,
                      AllowedDragOperations operations_allowed,
                      uint32 key_modifiers)
      => (ui.mojom.DragOperation operation,
          bool document_is_handling_drag);

  // Notifies the Widget of a drag over operation. Once the renderer has
  // completed processing the event the callback is called with the type of
  // the current drag operation that is active and the browser will update
  // the mouse cursor displayed to the user.
  //
  // See comment for DragTargetDragEnter() for a discussion of |operation| and
  // |document_is_handling_drag|.
  DragTargetDragOver(gfx.mojom.PointF point_in_viewport,
                     gfx.mojom.PointF screen_point,
                     AllowedDragOperations operations_allowed,
                     uint32 key_modifiers)
      => (ui.mojom.DragOperation operation,
          bool document_is_handling_drag);

  // Notifies the Widget of a drag leave operation.
  DragTargetDragLeave(gfx.mojom.PointF point_in_viewport,
                      gfx.mojom.PointF screen_point);

  // Notifies the Widget of a drag drop operation.
  DragTargetDrop(DragData drag_data,
                 gfx.mojom.PointF point_in_viewport,
                 gfx.mojom.PointF screen_point,
                 uint32 key_modifiers) => ();

  // Notifies the Widget that a drag has terminated.
  DragSourceEndedAt(gfx.mojom.PointF point_in_viewport,
                    gfx.mojom.PointF screen_point,
                    ui.mojom.DragOperation drag_operation) => ();

  // Notifies the Widget that the system drag and drop operation has ended.
  DragSourceSystemDragEnded();

  // Notifies the Widget that stylus writing has started. This is used primarily
  // to focus the input element where writing was detected to allow committing
  // recognized text. Stylus writing ends with a Ime commit and we do not need
  // another message that writing has ended. This message responds with the
  // focused edit bounds and caret bounds after stylus writable element is
  // focused, and null if that element could not be focused.
  OnStartStylusWriting() => (gfx.mojom.Rect? focused_edit_bounds,
                             gfx.mojom.Rect? caret_bounds);

  // Exposes an interface to the renderer to provide positional and styling
  // information about the currently focused element.
  [EnableIf=is_android]
  PassImeRenderWidgetHost(pending_remote<ImeRenderWidgetHost> remote);

  // Makes the Widget background transparent or opaque.
  SetBackgroundOpaque(bool opaque);

  // Changes the text direction of the currently selected input field (if any).
  SetTextDirection(mojo_base.mojom.TextDirection direction);

  // Activate/deactivate the Widget.
  // Focused window is the window that receives keyboard input.
  // The focused window is always or is always contained by the Active window.
  // Active window is the one that contains the focused element.
  // https://www.chromium.org/developers/design-documents/aura/focus-and-activation
  SetActive(bool active);

  // Only valid for sub frame local roots.
  //
  // Sets the inherited effective touch action on an out-of-process iframe.
  SetInheritedEffectiveTouchActionForSubFrame(cc.mojom.TouchAction touch_action);

  // Toggles render throttling for an out-of-process iframe.
  UpdateRenderThrottlingStatusForSubFrame(
      bool is_throttled, bool subtree_throttled, bool display_locked);

  // When the browser receives a call to RenderFrameProxyHost::SetIsInert
  // from the parent widget's embedding renderer changing its inertness,
  // it sets the same inertness value to the renderer of the child subframe.
  // When a widget is inert, it is unable to process input events.
  // https://html.spec.whatwg.org/multipage/interaction.html#inert
  SetIsInertForSubFrame(bool inert);

  // Requests the word under the given point relative to the origin of the
  // widget and its baseline point.
  [EnableIf=is_mac]
  GetStringAtPoint(gfx.mojom.Point point_in_local_root)
      => (ui.mojom.AttributedString? string, gfx.mojom.Point baseline_point);

  // Enables device emulator.
  EnableDeviceEmulation(DeviceEmulationParams parameters);

  // Disables device emulator.
  DisableDeviceEmulation();

  // Binds an WidgetCompositor interface.
  BindWidgetCompositor(pending_receiver<WidgetCompositor> host);

  // Sent by a parent frame to notify its child about the state of the child's
  // intersection with the parent's viewport, primarily for use by the
  // IntersectionObserver API. Also see 'UpdateViewportIntersection' in
  // third_party/blink/public/mojom/frame/viewport_intersection_state.mojom
  SetViewportIntersection(ViewportIntersectionState intersection_state,
                          VisualProperties? visual_properties);

  // Sent to inform the renderer that fallback contents from the previous
  // Document, if any, have been cleared. This means that if the current
  // Document hasn't produced a frame yet we're likely displaying blank right
  // now. This is used to abort View Transitions, and possibly other optional
  // work.
  NotifyClearedDisplayedGraphics();
};

// Implemented in Browser, this interface defines frame-widget-specific methods that
// will be invoked from the render process (e.g. content::RenderWidgetHostImpl).
interface FrameWidgetHost {
  // Sent by a widget to the browser to request a page scale animation in the
  // main-frame's widget.
  AnimateDoubleTapZoomInMainFrame(
                    gfx.mojom.Point tap_point,
                    gfx.mojom.Rect rect_to_zoom);

  // Sent by a widget to the browser to request a page scale animation in the
  // main-frame's widget for find-in-page zoom.
  ZoomToFindInPageRectInMainFrame(gfx.mojom.Rect rect_to_zoom);

  // Notifies what type of touch event consumers, if any, exist in the renderer,
  // e.g. JavaScript touch event handlers or hit testable scrollbars.
  SetHasTouchEventConsumers(TouchEventConsumers touch_event_consumers);

  // Sent by a widget to the browser to be used for SVGs inside of <object> and
  // not for iframes. Informs the browser that the current frame's intrinsic
  // sizing info has changed. The browser can then notify a containing frame
  // that the frame may need to trigger a new layout.
  //
  // Also see blink::mojom::RemoteFrame::IntrinsicSizingInfoOfChildChanged.
  IntrinsicSizingInfoChanged(IntrinsicSizingInfo sizing_info);

  // Requests a non-decelerating synthetic fling animation to be latched on the
  // scroller at the start point, and whose velocity can be changed over time by
  // sending multiple AutoscrollFling gestures. Used for features like
  // middle-click autoscroll.
  //
  // Sent by a widget to the browser to notify the start point for the
  // autoscroll.
  AutoscrollStart(gfx.mojom.PointF position);

  // Sent by a widget to the browser to notify the velocity for the autoscroll
  // fling animation.
  AutoscrollFling(gfx.mojom.Vector2dF velocity);

  // Sent by a widget to the browser to notify the end of the autoscroll.
  AutoscrollEnd();
};

// Implemented in Browser, this interface defines popup-widget-specific methods
// that will be invoked from the render process (e.g. RenderWidgetHostImpl).
// Popup widgets in the renderer are owned by the PopupWidgetHost in the browser
// process, so the PopupWidgetHost channel disconnecting indicates that the
// widget in the renderer should be destroyed.
interface PopupWidgetHost {
  // Request that this popup be dismissed.
  RequestClosePopup();

  // Request the popup be shown. Rects are relative to screen origin in DIPs.
  ShowPopup(gfx.mojom.Rect initial_rect, gfx.mojom.Rect anchor_rect) => ();

  // Request that the browser change the bounds of the widget.
  SetPopupBounds(gfx.mojom.Rect bounds) => ();
};