2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2017-11-16 16:00:00 +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 __nsClipboardX11_h_
|
|
|
|
#define __nsClipboardX11_h_
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2018-03-27 16:51:07 +03:00
|
|
|
enum ClipboardDataType { CLIPBOARD_DATA, CLIPBOARD_TEXT, CLIPBOARD_TARGETS };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-16 16:00:00 +03:00
|
|
|
class nsRetrievalContextX11 : public nsRetrievalContext {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2018-03-27 16:51:07 +03:00
|
|
|
enum State { INITIAL, COMPLETED, TIMED_OUT };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-27 16:51:07 +03:00
|
|
|
virtual const char* GetClipboardData(const char* aMimeType,
|
|
|
|
int32_t aWhichClipboard,
|
2017-12-18 15:34:38 +03:00
|
|
|
uint32_t* aContentLength) override;
|
2018-03-27 16:51:07 +03:00
|
|
|
virtual const char* GetClipboardText(int32_t aWhichClipboard) override;
|
|
|
|
virtual void ReleaseClipboardData(const char* aClipboardData) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-27 16:51:07 +03:00
|
|
|
virtual GdkAtom* GetTargets(int32_t aWhichClipboard,
|
2017-11-16 16:00:00 +03:00
|
|
|
int* aTargetNums) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-04 15:49:21 +03:00
|
|
|
virtual bool HasSelectionSupport(void) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-27 16:51:07 +03:00
|
|
|
// Call this when data or text has been retrieved.
|
|
|
|
void Complete(ClipboardDataType aDataType, const void* aData,
|
|
|
|
int aDataRequestNumber);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-16 16:00:00 +03:00
|
|
|
nsRetrievalContextX11();
|
|
|
|
virtual ~nsRetrievalContextX11() override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
private:
|
2018-03-27 16:51:07 +03:00
|
|
|
bool WaitForClipboardData(ClipboardDataType aDataType,
|
|
|
|
GtkClipboard* clipboard,
|
|
|
|
const char* aMimeType = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2017-11-16 16:00:00 +03:00
|
|
|
* Spins X event loop until timing out or being completed. Returns
|
2018-03-27 16:51:07 +03:00
|
|
|
* null if we time out, otherwise returns the completed data (passing
|
2017-11-16 16:00:00 +03:00
|
|
|
* ownership to caller).
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2018-03-27 16:51:07 +03:00
|
|
|
bool WaitForX11Content();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-27 16:51:07 +03:00
|
|
|
State mState;
|
|
|
|
int mClipboardRequestNumber;
|
|
|
|
void* mClipboardData;
|
|
|
|
uint32_t mClipboardDataLength;
|
|
|
|
GdkAtom mTargetMIMEType;
|
|
|
|
};
|
|
|
|
|
2017-11-16 16:00:00 +03:00
|
|
|
class ClipboardRequestHandler {
|
|
|
|
public:
|
|
|
|
ClipboardRequestHandler(nsRetrievalContextX11* aContext,
|
2018-03-27 16:51:07 +03:00
|
|
|
ClipboardDataType aDataType, int aDataRequestNumber)
|
|
|
|
: mContext(aContext),
|
|
|
|
mDataRequestNumber(aDataRequestNumber),
|
|
|
|
mDataType(aDataType) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-16 16:00:00 +03:00
|
|
|
void Complete(const void* aData) {
|
2018-03-27 16:51:07 +03:00
|
|
|
mContext->Complete(mDataType, aData, mDataRequestNumber);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-11-16 16:00:00 +03:00
|
|
|
private:
|
|
|
|
nsRetrievalContextX11* mContext;
|
|
|
|
int mDataRequestNumber;
|
2018-03-27 16:51:07 +03:00
|
|
|
ClipboardDataType mDataType;
|
2017-11-16 16:00:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __nsClipboardX11_h_ */
|