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
157
158
159
160
161
162
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __nsClipboardWayland_h_
#define __nsClipboardWayland_h_
#include <gtk/gtk.h>
#include <gdk/gdkwayland.h>
#include <nsTArray.h>
#include "mozilla/UniquePtr.h"
#include "nsClipboard.h"
#include "nsWaylandDisplay.h"
struct FastTrackClipboard;
class DataOffer {
public:
void AddMIMEType(const char* aMimeType);
GdkAtom* GetTargets(int* aTargetNum);
bool HasTarget(const char* aMimeType);
char* GetData(wl_display* aDisplay, const char* aMimeType,
uint32_t* aContentLength);
virtual ~DataOffer() = default;
private:
virtual bool RequestDataTransfer(const char* aMimeType, int fd) = 0;
protected:
nsTArray<GdkAtom> mTargetMIMETypes;
};
class WaylandDataOffer : public DataOffer {
public:
explicit WaylandDataOffer(wl_data_offer* aWaylandDataOffer);
void DragOfferAccept(const char* aMimeType, uint32_t aTime);
void SetDragStatus(GdkDragAction aPreferredAction, uint32_t aTime);
GdkDragAction GetSelectedDragAction();
void SetSelectedDragAction(uint32_t aWaylandAction);
void SetAvailableDragActions(uint32_t aWaylandActions);
GdkDragAction GetAvailableDragActions();
void SetWaylandDragContext(nsWaylandDragContext* aDragContext);
nsWaylandDragContext* GetWaylandDragContext();
virtual ~WaylandDataOffer();
private:
bool RequestDataTransfer(const char* aMimeType, int fd) override;
wl_data_offer* mWaylandDataOffer;
RefPtr<nsWaylandDragContext> mDragContext;
uint32_t mSelectedDragAction;
uint32_t mAvailableDragActions;
};
class PrimaryDataOffer : public DataOffer {
public:
explicit PrimaryDataOffer(gtk_primary_selection_offer* aPrimaryDataOffer);
explicit PrimaryDataOffer(zwp_primary_selection_offer_v1* aPrimaryDataOffer);
void SetAvailableDragActions(uint32_t aWaylandActions){};
virtual ~PrimaryDataOffer();
private:
bool RequestDataTransfer(const char* aMimeType, int fd) override;
gtk_primary_selection_offer* mPrimaryDataOfferGtk;
zwp_primary_selection_offer_v1* mPrimaryDataOfferZwpV1;
};
class nsWaylandDragContext : public nsISupports {
NS_DECL_ISUPPORTS
public:
nsWaylandDragContext(WaylandDataOffer* aWaylandDataOffer,
wl_display* aDisplay);
void DropDataEnter(GtkWidget* aGtkWidget, uint32_t aTime, nscoord aX,
nscoord aY);
void DropMotion(uint32_t aTime, nscoord aX, nscoord aY);
void GetLastDropInfo(uint32_t* aTime, nscoord* aX, nscoord* aY);
void SetDragStatus(GdkDragAction aPreferredAction);
GdkDragAction GetAvailableDragActions();
GtkWidget* GetWidget() { return mGtkWidget; }
GList* GetTargets();
char* GetData(const char* aMimeType, uint32_t* aContentLength);
private:
virtual ~nsWaylandDragContext() = default;
mozilla::UniquePtr<WaylandDataOffer> mDataOffer;
wl_display* mDisplay;
uint32_t mTime;
GtkWidget* mGtkWidget;
nscoord mX, mY;
};
class nsRetrievalContextWayland : public nsRetrievalContext {
public:
nsRetrievalContextWayland();
virtual const char* GetClipboardData(const char* aMimeType,
int32_t aWhichClipboard,
uint32_t* aContentLength) override;
virtual const char* GetClipboardText(int32_t aWhichClipboard) override;
virtual void ReleaseClipboardData(const char* aClipboardData) override;
virtual GdkAtom* GetTargets(int32_t aWhichClipboard,
int* aTargetNum) override;
virtual bool HasSelectionSupport(void) override;
void RegisterNewDataOffer(wl_data_offer* aWaylandDataOffer);
void RegisterNewDataOffer(gtk_primary_selection_offer* aPrimaryDataOffer);
void RegisterNewDataOffer(zwp_primary_selection_offer_v1* aPrimaryDataOffer);
void SetClipboardDataOffer(wl_data_offer* aWaylandDataOffer);
void SetPrimaryDataOffer(gtk_primary_selection_offer* aPrimaryDataOffer);
void SetPrimaryDataOffer(zwp_primary_selection_offer_v1* aPrimaryDataOffer);
void AddDragAndDropDataOffer(wl_data_offer* aWaylandDataOffer);
nsWaylandDragContext* GetDragContext();
void ClearDragAndDropDataOffer();
void TransferFastTrackClipboard(int aClipboardRequestNumber,
GtkSelectionData* aSelectionData);
virtual ~nsRetrievalContextWayland() override;
private:
bool mInitialized;
RefPtr<mozilla::widget::nsWaylandDisplay> mDisplay;
// Data offers provided by Wayland data device
GHashTable* mActiveOffers;
mozilla::UniquePtr<DataOffer> mClipboardOffer;
mozilla::UniquePtr<DataOffer> mPrimaryOffer;
RefPtr<nsWaylandDragContext> mDragContext;
int mClipboardRequestNumber;
char* mClipboardData;
uint32_t mClipboardDataLength;
// Mime types used for text data at Gtk+, see request_text_received_func()
// at gtkclipboard.c.
#define TEXT_MIME_TYPES_NUM 3
static const char* sTextMimeTypes[TEXT_MIME_TYPES_NUM];
};
#endif /* __nsClipboardWayland_h_ */
|