/src/mozilla-central/widget/gtk/nsClipboardX11.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* vim:expandtab:shiftwidth=4:tabstop=4: |
3 | | */ |
4 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
5 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
6 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
7 | | |
8 | | #ifndef __nsClipboardX11_h_ |
9 | | #define __nsClipboardX11_h_ |
10 | | |
11 | | #include "nsIClipboard.h" |
12 | | #include <gtk/gtk.h> |
13 | | |
14 | | enum ClipboardDataType { |
15 | | CLIPBOARD_DATA, |
16 | | CLIPBOARD_TEXT, |
17 | | CLIPBOARD_TARGETS |
18 | | }; |
19 | | |
20 | | class nsRetrievalContextX11 : public nsRetrievalContext |
21 | | { |
22 | | public: |
23 | | enum State { INITIAL, COMPLETED, TIMED_OUT }; |
24 | | |
25 | | virtual const char* GetClipboardData(const char* aMimeType, |
26 | | int32_t aWhichClipboard, |
27 | | uint32_t* aContentLength) override; |
28 | | virtual const char* GetClipboardText(int32_t aWhichClipboard) override; |
29 | | virtual void ReleaseClipboardData(const char* aClipboardData) override; |
30 | | |
31 | | virtual GdkAtom* GetTargets(int32_t aWhichClipboard, |
32 | | int* aTargetNums) override; |
33 | | |
34 | | virtual bool HasSelectionSupport(void) override; |
35 | | |
36 | | // Call this when data or text has been retrieved. |
37 | | void Complete(ClipboardDataType aDataType, |
38 | | const void* aData, |
39 | | int aDataRequestNumber); |
40 | | |
41 | | nsRetrievalContextX11(); |
42 | | virtual ~nsRetrievalContextX11() override; |
43 | | |
44 | | private: |
45 | | bool WaitForClipboardData(ClipboardDataType aDataType, |
46 | | GtkClipboard *clipboard, |
47 | | const char *aMimeType = nullptr); |
48 | | |
49 | | /** |
50 | | * Spins X event loop until timing out or being completed. Returns |
51 | | * null if we time out, otherwise returns the completed data (passing |
52 | | * ownership to caller). |
53 | | */ |
54 | | bool WaitForX11Content(); |
55 | | |
56 | | State mState; |
57 | | int mClipboardRequestNumber; |
58 | | void* mClipboardData; |
59 | | uint32_t mClipboardDataLength; |
60 | | GdkAtom mTargetMIMEType; |
61 | | }; |
62 | | |
63 | | class ClipboardRequestHandler |
64 | | { |
65 | | public: |
66 | | ClipboardRequestHandler(nsRetrievalContextX11 *aContext, |
67 | | ClipboardDataType aDataType, |
68 | | int aDataRequestNumber) |
69 | | : mContext(aContext) |
70 | | , mDataRequestNumber(aDataRequestNumber) |
71 | | , mDataType(aDataType) |
72 | 0 | {} |
73 | | |
74 | | void Complete(const void *aData) |
75 | 0 | { |
76 | 0 | mContext->Complete(mDataType, aData, mDataRequestNumber); |
77 | 0 | } |
78 | | |
79 | | private: |
80 | | nsRetrievalContextX11 *mContext; |
81 | | int mDataRequestNumber; |
82 | | ClipboardDataType mDataType; |
83 | | }; |
84 | | |
85 | | #endif /* __nsClipboardX11_h_ */ |