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