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>
|
|
|
|
|
2022-02-02 17:55:12 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "nsClipboard.h"
|
|
|
|
|
2017-11-16 16:00:00 +03:00
|
|
|
class nsRetrievalContextX11 : public nsRetrievalContext {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2022-02-02 17:55:12 +03:00
|
|
|
enum class State { Initial, Completed, TimedOut };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2022-02-02 17:55:12 +03:00
|
|
|
ClipboardData GetClipboardData(const char* aMimeType,
|
|
|
|
int32_t aWhichClipboard) override;
|
|
|
|
mozilla::GUniquePtr<char> GetClipboardText(int32_t aWhichClipboard) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2022-02-02 17:55:12 +03:00
|
|
|
ClipboardTargets GetTargets(int32_t aWhichClipboard) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2022-02-02 17:55:12 +03:00
|
|
|
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();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
private:
|
2022-02-02 17:55:12 +03:00
|
|
|
ClipboardData WaitForClipboardData(ClipboardDataType aDataType,
|
2022-02-02 17:55:13 +03:00
|
|
|
int32_t aWhichClipboard,
|
2022-02-02 17:55:12 +03:00
|
|
|
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
|
|
|
*/
|
2022-02-02 17:55:12 +03:00
|
|
|
ClipboardData WaitForX11Content();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2022-02-02 17:55:12 +03:00
|
|
|
State mState = State::Initial;
|
|
|
|
int mClipboardRequestNumber = 0;
|
|
|
|
mozilla::Maybe<ClipboardData> mClipboardData;
|
2018-03-27 16:51:07 +03:00
|
|
|
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_ */
|