forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextended_drag_source.h
122 lines (91 loc) · 3.57 KB
/
extended_drag_source.h
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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_EXO_EXTENDED_DRAG_SOURCE_H_
#define COMPONENTS_EXO_EXTENDED_DRAG_SOURCE_H_
#include <memory>
#include <string>
#include "ash/drag_drop/toplevel_window_drag_delegate.h"
#include "ash/wm/toplevel_window_event_handler.h"
#include "base/observer_list.h"
#include "components/exo/data_source_observer.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/aura/scoped_window_event_targeting_blocker.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-shared.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
namespace aura {
class Window;
}
namespace gfx {
class Vector2d;
}
namespace ui {
class LocatedEvent;
}
namespace exo {
class DataSource;
class Surface;
class ExtendedDragSource : public DataSourceObserver,
public ash::ToplevelWindowDragDelegate {
public:
class Delegate {
public:
virtual bool ShouldAllowDropAnywhere() const = 0;
virtual bool ShouldLockCursor() const = 0;
virtual void OnSwallowed(const std::string& mime_type) = 0;
virtual void OnUnswallowed(const std::string& mime_type,
const gfx::Vector2d& offset) = 0;
virtual void OnDataSourceDestroying() = 0;
protected:
virtual ~Delegate() = default;
};
class Observer {
public:
virtual void OnExtendedDragSourceDestroying(ExtendedDragSource* source) = 0;
protected:
virtual ~Observer() = default;
};
static ExtendedDragSource* Get();
ExtendedDragSource(DataSource* source, Delegate* delegate);
ExtendedDragSource(const ExtendedDragSource&) = delete;
ExtendedDragSource& operator=(const ExtendedDragSource&) = delete;
~ExtendedDragSource() override;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void Drag(Surface* surface, const gfx::Vector2d& offset);
bool IsActive() const;
// ash::ToplevelWindowDragDelegate:
void OnToplevelWindowDragStarted(const gfx::PointF& start_location,
ui::mojom::DragEventSource source) override;
ui::mojom::DragOperation OnToplevelWindowDragDropped() override;
void OnToplevelWindowDragCancelled() override;
void OnToplevelWindowDragEvent(ui::LocatedEvent* event) override;
// DataSourceObserver:
void OnDataSourceDestroying(DataSource* source) override;
aura::Window* GetDraggedWindowForTesting();
absl::optional<gfx::Vector2d> GetDragOffsetForTesting() const;
private:
class DraggedWindowHolder;
void MaybeLockCursor();
void UnlockCursor();
void StartDrag(aura::Window* toplevel,
const gfx::PointF& pointer_location_in_screen);
void OnDraggedWindowVisibilityChanging(bool visible);
gfx::Point CalculateOrigin(aura::Window* target) const;
void Cleanup();
static ExtendedDragSource* instance_;
DataSource* source_ = nullptr;
// Created and destroyed at wayland/zcr_extended_drag.cc and its lifetime is
// tied to the zcr_extended_drag_source_v1 object it's attached to.
Delegate* const delegate_;
gfx::PointF pointer_location_;
ui::mojom::DragEventSource drag_event_source_;
bool cursor_locked_ = false;
std::unique_ptr<DraggedWindowHolder> dragged_window_holder_;
std::unique_ptr<aura::ScopedWindowEventTargetingBlocker> event_blocker_;
base::ObserverList<Observer>::Unchecked observers_;
base::WeakPtrFactory<ExtendedDragSource> weak_factory_{this};
};
} // namespace exo
#endif // COMPONENTS_EXO_EXTENDED_DRAG_SOURCE_H_