2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2017-12-18 15:36:12 +03:00
|
|
|
/* 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>
|
|
|
|
|
2020-03-18 15:30:50 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2019-12-03 17:03:01 +03:00
|
|
|
#include "nsClipboard.h"
|
|
|
|
#include "nsWaylandDisplay.h"
|
|
|
|
#include "mozwayland/mozwayland.h"
|
|
|
|
#include "wayland/gtk-primary-selection-client-protocol.h"
|
|
|
|
|
2018-02-01 13:23:01 +03:00
|
|
|
struct FastTrackClipboard;
|
|
|
|
|
2018-04-04 15:49:21 +03:00
|
|
|
class DataOffer {
|
|
|
|
public:
|
|
|
|
void AddMIMEType(const char* aMimeType);
|
|
|
|
|
|
|
|
GdkAtom* GetTargets(int* aTargetNum);
|
2018-04-05 14:00:58 +03:00
|
|
|
bool HasTarget(const char* aMimeType);
|
|
|
|
|
2018-04-04 15:49:21 +03:00
|
|
|
char* GetData(wl_display* aDisplay, const char* aMimeType,
|
|
|
|
uint32_t* aContentLength);
|
|
|
|
|
2020-03-16 13:56:57 +03:00
|
|
|
virtual ~DataOffer() = default;
|
2018-04-04 15:49:21 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
private:
|
2018-04-04 15:49:21 +03:00
|
|
|
virtual bool RequestDataTransfer(const char* aMimeType, int fd) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
protected:
|
2018-04-04 15:49:21 +03:00
|
|
|
nsTArray<GdkAtom> mTargetMIMETypes;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WaylandDataOffer : public DataOffer {
|
|
|
|
public:
|
2018-11-08 04:41:33 +03:00
|
|
|
explicit WaylandDataOffer(wl_data_offer* aWaylandDataOffer);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
void DragOfferAccept(const char* aMimeType, uint32_t aTime);
|
2020-01-31 14:37:34 +03:00
|
|
|
void SetDragStatus(GdkDragAction aPreferredAction, uint32_t aTime);
|
2018-04-04 15:49:21 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
GdkDragAction GetSelectedDragAction();
|
|
|
|
void SetSelectedDragAction(uint32_t aWaylandAction);
|
|
|
|
|
|
|
|
void SetAvailableDragActions(uint32_t aWaylandActions);
|
|
|
|
GdkDragAction GetAvailableDragActions();
|
|
|
|
|
2020-01-31 14:37:34 +03:00
|
|
|
void SetWaylandDragContext(nsWaylandDragContext* aDragContext);
|
|
|
|
nsWaylandDragContext* GetWaylandDragContext();
|
|
|
|
|
2018-06-01 13:24:17 +03:00
|
|
|
virtual ~WaylandDataOffer();
|
2018-04-05 17:16:43 +03:00
|
|
|
|
|
|
|
private:
|
2018-04-04 15:49:21 +03:00
|
|
|
bool RequestDataTransfer(const char* aMimeType, int fd) override;
|
|
|
|
|
|
|
|
wl_data_offer* mWaylandDataOffer;
|
2020-01-31 14:37:34 +03:00
|
|
|
RefPtr<nsWaylandDragContext> mDragContext;
|
2018-04-05 17:16:43 +03:00
|
|
|
uint32_t mSelectedDragAction;
|
2020-01-31 14:37:34 +03:00
|
|
|
uint32_t mAvailableDragActions;
|
2018-04-04 15:49:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class PrimaryDataOffer : public DataOffer {
|
|
|
|
public:
|
2018-11-08 04:41:33 +03:00
|
|
|
explicit PrimaryDataOffer(gtk_primary_selection_offer* aPrimaryDataOffer);
|
2018-04-05 17:16:43 +03:00
|
|
|
void SetAvailableDragActions(uint32_t aWaylandActions){};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-04 15:49:21 +03:00
|
|
|
virtual ~PrimaryDataOffer();
|
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
private:
|
2018-04-04 15:49:21 +03:00
|
|
|
bool RequestDataTransfer(const char* aMimeType, int fd) override;
|
|
|
|
|
|
|
|
gtk_primary_selection_offer* mPrimaryDataOffer;
|
|
|
|
};
|
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
class nsWaylandDragContext : public nsISupports {
|
|
|
|
NS_DECL_ISUPPORTS
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
public:
|
|
|
|
nsWaylandDragContext(WaylandDataOffer* aWaylandDataOffer,
|
|
|
|
wl_display* aDisplay);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-01-31 14:37:34 +03:00
|
|
|
void SetDragStatus(GdkDragAction aPreferredAction);
|
|
|
|
GdkDragAction GetAvailableDragActions();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
GtkWidget* GetWidget() { return mGtkWidget; }
|
|
|
|
GList* GetTargets();
|
|
|
|
char* GetData(const char* aMimeType, uint32_t* aContentLength);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
private:
|
2020-03-16 13:56:57 +03:00
|
|
|
virtual ~nsWaylandDragContext() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-03-18 15:30:50 +03:00
|
|
|
mozilla::UniquePtr<WaylandDataOffer> mDataOffer;
|
2018-04-05 17:16:43 +03:00
|
|
|
wl_display* mDisplay;
|
|
|
|
uint32_t mTime;
|
|
|
|
GtkWidget* mGtkWidget;
|
|
|
|
nscoord mX, mY;
|
|
|
|
};
|
|
|
|
|
2017-12-18 15:36:12 +03:00
|
|
|
class nsRetrievalContextWayland : public nsRetrievalContext {
|
|
|
|
public:
|
|
|
|
nsRetrievalContextWayland();
|
|
|
|
|
|
|
|
virtual const char* GetClipboardData(const char* aMimeType,
|
|
|
|
int32_t aWhichClipboard,
|
|
|
|
uint32_t* aContentLength) override;
|
2018-04-05 14:00:58 +03:00
|
|
|
virtual const char* GetClipboardText(int32_t aWhichClipboard) override;
|
2017-12-18 15:37:46 +03:00
|
|
|
virtual void ReleaseClipboardData(const char* aClipboardData) override;
|
2017-12-18 15:36:12 +03:00
|
|
|
|
|
|
|
virtual GdkAtom* GetTargets(int32_t aWhichClipboard,
|
|
|
|
int* aTargetNum) override;
|
2018-04-04 15:49:21 +03:00
|
|
|
virtual bool HasSelectionSupport(void) override;
|
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
void RegisterNewDataOffer(wl_data_offer* aWaylandDataOffer);
|
|
|
|
void RegisterNewDataOffer(gtk_primary_selection_offer* aPrimaryDataOffer);
|
2018-04-04 15:49:21 +03:00
|
|
|
|
|
|
|
void SetClipboardDataOffer(wl_data_offer* aWaylandDataOffer);
|
|
|
|
void SetPrimaryDataOffer(gtk_primary_selection_offer* aPrimaryDataOffer);
|
2018-04-05 17:16:43 +03:00
|
|
|
void AddDragAndDropDataOffer(wl_data_offer* aWaylandDataOffer);
|
|
|
|
nsWaylandDragContext* GetDragContext();
|
2018-04-04 15:49:21 +03:00
|
|
|
|
2018-04-05 17:16:43 +03:00
|
|
|
void ClearDragAndDropDataOffer();
|
2017-12-18 15:36:12 +03:00
|
|
|
|
2018-02-01 13:23:01 +03:00
|
|
|
void TransferFastTrackClipboard(int aClipboardRequestNumber,
|
|
|
|
GtkSelectionData* aSelectionData);
|
2017-12-18 15:36:12 +03:00
|
|
|
|
|
|
|
virtual ~nsRetrievalContextWayland() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mInitialized;
|
2019-12-03 17:03:01 +03:00
|
|
|
mozilla::widget::nsWaylandDisplay* mDisplay;
|
2018-04-04 15:49:21 +03:00
|
|
|
|
|
|
|
// Data offers provided by Wayland data device
|
|
|
|
GHashTable* mActiveOffers;
|
2020-03-18 15:30:50 +03:00
|
|
|
mozilla::UniquePtr<DataOffer> mClipboardOffer;
|
|
|
|
mozilla::UniquePtr<DataOffer> mPrimaryOffer;
|
2018-04-05 17:16:43 +03:00
|
|
|
RefPtr<nsWaylandDragContext> mDragContext;
|
2018-02-01 13:23:01 +03:00
|
|
|
|
|
|
|
int mClipboardRequestNumber;
|
|
|
|
char* mClipboardData;
|
|
|
|
uint32_t mClipboardDataLength;
|
2018-04-05 14:00:58 +03:00
|
|
|
|
|
|
|
// 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];
|
2017-12-18 15:36:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __nsClipboardWayland_h_ */
|