File: wm_drag_handler.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (104 lines) | stat: -rw-r--r-- 4,450 bytes parent folder | download | duplicates (8)
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
// 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.

#ifndef UI_PLATFORM_WINDOW_WM_WM_DRAG_HANDLER_H_
#define UI_PLATFORM_WINDOW_WM_WM_DRAG_HANDLER_H_

#include <optional>

#include "base/component_export.h"
#include "base/functional/callback.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/native_widget_types.h"

namespace gfx {
class Point;
}

namespace ui {
class PlatformWindow;
class OSExchangeData;

class COMPONENT_EXPORT(WM) WmDragHandler {
 public:
  // Notifies when the drag operation finished.
  using DragFinishedCallback =
      base::OnceCallback<void(mojom::DragOperation operation)>;

  // A delegate class for a platform on which chrome manages a drag image and
  // needs to receive the drag location. This can be null if the platform itself
  // manages the drag image.
  class LocationDelegate {
   public:
    // Called every time when the drag location has changed.
    virtual void OnDragLocationChanged(const gfx::Point& screen_point_px) = 0;
    // Called when the currently negotiated operation has changed.
    virtual void OnDragOperationChanged(mojom::DragOperation operation) = 0;
    // DragWidget (if any) should be ignored when finding top window and
    // dispatching mouse events.
    virtual std::optional<gfx::AcceleratedWidget> GetDragWidget() = 0;

   protected:
    virtual ~LocationDelegate();
  };

  // Starts dragging `data`. Whereas, `operations` is a bitmask of
  // DragDropTypes::DragOperation values, which defines possible operations for
  // the drag source. The destination sets the resulting operation when the drop
  // action is performed. `source` indicates the source event type triggering
  // the drag, and `can_grab_pointer` indicates whether the implementation can
  // grab the mouse pointer (some platforms may need this). In progress updates
  // on the drag operation come back through the `location_delegate` on the
  // platform that chrome needs manages a drag image). This can be null if the
  // platform manages a drag image. `drag_started_callback` is called after the
  // request to start the drag was sent to the OS (see below for details), and
  // `drag_finished_callback` is called when drag operation finishes. These
  // callbacks are necessary because of the nested message loop (see below).
  //
  // `drag_started_callback` is called if and only if the drag actually starts.
  // If initialization fails and the drag doesn't start, it will not be called.
  // Also note that it might be called even when this method returns false if
  // the drag does start but is cancelled later on.
  //
  // This method runs a nested message loop, returning when the drag operation
  // is done. Care must be taken when calling this as it's entirely possible
  // that when this returns this object (and the calling object) have been
  // destroyed.
  //
  // Returns whether the operation ended well (i.e., had not been canceled).
  virtual bool StartDrag(const OSExchangeData& data,
                         int operations,
                         mojom::DragEventSource source,
                         gfx::NativeCursor cursor,
                         bool can_grab_pointer,
                         base::OnceClosure drag_started_callback,
                         DragFinishedCallback drag_finished_callback,
                         LocationDelegate* location_delegate) = 0;

  // Cancels the drag.
  virtual void CancelDrag() = 0;

  // Updates the drag image. An empty |image| may be used to hide a previously
  // set non-empty drag image, and a non-empty |image| shows the drag image
  // again if it was previously hidden.
  //
  // This must be called during an active drag session.
  virtual void UpdateDragImage(const gfx::ImageSkia& image,
                               const gfx::Vector2d& offset) = 0;

  // Returns whether capture should be released before a StartDrag() call.
  virtual bool ShouldReleaseCaptureForDrag(ui::OSExchangeData* data) const;
};

COMPONENT_EXPORT(WM)
void SetWmDragHandler(PlatformWindow* platform_window,
                      WmDragHandler* drag_handler);
COMPONENT_EXPORT(WM)
WmDragHandler* GetWmDragHandler(const PlatformWindow& platform_window);

}  // namespace ui

#endif  // UI_PLATFORM_WINDOW_WM_WM_DRAG_HANDLER_H_