1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156

content / common / web_contents_ns_view_bridge.mojom [blame]

// 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);
};