chromium/content/common/web_contents_ns_view_bridge.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 remote_cocoa.mojom;

import "content/public/common/drop_data.mojom";
import "mojo/public/mojom/base/file_path.mojom";
import "ui/events/mojom/event.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
import "ui/gfx/image/mojom/image.mojom";
import "url/mojom/origin.mojom";
import "url/mojom/url.mojom";

// Interface through which a WebContentsViewMac communicates with its NSView in
// another process.
interface WebContentsNSView {
  // Set this to be a child NSView of the NSView mapped to by
  // |parent_ns_view_id|.
  SetParentNSView(uint64 parent_ns_view_id);

  // Clear the parent NSView and related state.
  ResetParentNSView();

  // Set the NSView's frame in its NSWindow to |bounds_in_window|.
  SetBounds(gfx.mojom.Rect bounds_in_window);

  // Short or hide the NSView.
  SetVisible(bool visible);

  // Make the NSView be the first responder for its window.
  MakeFirstResponder();

  // Called when a subview asks this to take focus back (e.g, because it has
  // iterated past the last or first focusable element on the page). The
  // iteration direction is in |reverse|.
  TakeFocus(bool reverse);

  // Initiate a drag from the web contents area.
  //
  // /!\ The last argument on this IPC does not use the term "privileged" in the
  // sense of a privileged process. (This message is sent between two non-render
  // processes.) Rather, the last argument uses the term "privileged" to refer
  // to whether the WebContents initiating the drag is being used to implement
  // a UI surface. See `WebContentsDelegate::IsPrivileged()` for more context.
  StartDrag(content.mojom.DropData drop_data,
            url.mojom.Origin source_origin,
            uint32 operation_mask,
            gfx.mojom.ImageSkia? image,
            gfx.mojom.Vector2d image_offset,
            bool is_privileged);

  // Intended for desktop PWAs with manifest entry of window-controls-overlay,
  // this informs the view of which area at the top of the view is available for
  // web contents.
  UpdateWindowControlsOverlay(gfx.mojom.Rect bounding_rect);

  // TODO(crbug.com/40226213): This is a work around for a bug in mojo
  // where close notifications for associated messages pipes can sometimes be
  // delivered later than they should. This method is called before closing the
  // remote, and is treated as if a close notification was received.
  Destroy();
};

// The method through which a window was focused (directly focused, or by
// iterating through NSViews).
enum SelectionDirection {
  // The selection was not made through iteration.
  kDirect,
  // The selection is made by iterating to the next valid selection.
  kForward,
  // The selection is made by iterating to the previous valid selection.
  kReverse,
};

// The visibility of the window embedding a web contents NSView.
enum Visibility {
  // The view is part of a window that may be visible.
  kVisible,
  // The view is part of a window that is fully occluded.
  kOccluded,
  // The view is not part of any window or is part of a hidden window.
  kHidden,
};

// The data extracted from an NSDraggingInfo at draggingEntered,
// draggingUpdated, and performDragOperation.
struct DraggingInfo {
  // The dragging location in the NSView, with the origin in the upper-left.
  gfx.mojom.PointF location_in_view;

  // The dragging location in the NSScreen, with the origin in the upper-left.
  gfx.mojom.PointF location_in_screen;

  // The URL data from the drag, if any. Note that this is redundant in that it
  // is already present in DropData. It is here because it is used by methods
  // that don't use DropData.
  url.mojom.Url? url;

  // The operation mask.
  uint32 operation_mask;
};

// Interface through which the NSView in another process communicates with its
// owning WebContentsViewMac.
interface WebContentsNSViewHost {
  // Notification that a mouse `event` was dispatched to the WebContents's view.
  OnMouseEvent(ui.mojom.Event event);

  // Called when the NSView becomes first responder, with |direction| set to
  // indicate iteration direction (if any).
  OnBecameFirstResponder(SelectionDirection direction);

  // Called when the window displaying the web contents becomes visible, hidden,
  // or occluded.
  OnWindowVisibilityChanged(Visibility visibility);

  // Transmit the data that is being dropped on the NSView. This is called prior
  // to DraggingEntered.
  SetDropData(content.mojom.DropData drop_data);

  // Called in response to the -[NSDraggingDestination draggingEntered] method
  // being called on the NSView. Returns the resulting operation in |result|.
  [Sync]
  DraggingEntered(DraggingInfo dragging_info) => (uint32 result);

  // Called in response to the -[NSDraggingDestination draggingExited] method.
  DraggingExited();

  // Called in response to the -[NSDraggingDestination draggingUpdated] method
  // being called on the NSView. Returns the resulting operation in |result|.
  [Sync]
  DraggingUpdated(DraggingInfo dragging_info) => (uint32 result);

  // Called in response to the -[NSDraggingDestination performDragOperation:]
  // method being called on the NSView. Returns the result of the operation in
  // |result|.
  [Sync]
  PerformDragOperation(DraggingInfo dragging_info) => (bool result);

  // Called in response to the -namesOfPromisedFilesDroppedAtDestination method
  // being called on the NSView. The |file_path| input argument is the
  // requested destination file, and the output |file_path| is the actual
  // destination file.
  [Sync]
  DragPromisedFileTo(mojo_base.mojom.FilePath file_path,
                     content.mojom.DropData drop_data,
                     url.mojom.Url download_url,
                     url.mojom.Origin source_origin) =>
                         (mojo_base.mojom.FilePath file_path);

  // Called in to the -draggedImage: method being called on the NSView.
  EndDrag(uint32 drag_operation,
          gfx.mojom.PointF local_point,
          gfx.mojom.PointF screen_point);
};