OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Don't include this file from any .h files because it pulls in some X headers. | |
6 | |
7 #ifndef REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ | |
8 #define REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ | |
9 | |
10 #include <X11/Xatom.h> | |
11 #include <X11/Xlib.h> | |
12 | |
13 #include <map> | |
14 #include <set> | |
15 #include <string> | |
16 | |
17 #include "base/basictypes.h" | |
18 #include "base/callback_forward.h" | |
19 #include "base/timer.h" | |
20 | |
21 namespace remoting { | |
22 | |
23 // A class to allow manipulation of the X clipboard, using only X API calls. | |
24 class XServerClipboard { | |
25 public: | |
26 typedef base::Callback<void(const std::string& mime_type, | |
27 const std::string& data)> | |
28 ClipboardChangedCallback; | |
29 | |
30 XServerClipboard(); | |
31 ~XServerClipboard(); | |
32 | |
33 // The caller must ensure |display| is still valid whenever any other | |
34 // methods are called on this object. | |
Wez
2012/09/25 20:29:29
nit: Start this comment with an explanation of wha
Lambros
2012/09/25 22:42:39
Done.
| |
35 void Init(Display* display, const ClipboardChangedCallback& callback); | |
36 | |
37 // Copy data to the X Clipboard. This acquires ownership of the | |
38 // PRIMARY and CLIPBOARD selections. | |
39 void SetClipboard(const std::string& mime_type, const std::string& data); | |
40 | |
41 // This method allows this object to be hooked up to the program's main event | |
42 // loop. It should be invoked by the caller for each X11 event. This class | |
Wez
2012/09/25 20:29:29
nit: Rephrase the comment to describe what this ca
Lambros
2012/09/25 22:42:39
Done.
| |
43 // is not thread-safe, so all its methods must be called on the application's | |
44 // main event-processing thread. | |
Wez
2012/09/25 20:29:29
nit: Move the comment on the class' threading to t
Lambros
2012/09/25 22:42:39
Done.
| |
45 void ProcessXEvent(XEvent* event); | |
46 | |
47 private: | |
48 void OnSetSelectionOwnerNotify(Atom selection, Time timestamp); | |
49 void OnPropertyNotify(XEvent* event); | |
50 void OnSelectionNotify(XEvent* event); | |
51 void OnSelectionRequest(XEvent* event); | |
Wez
2012/09/25 20:29:29
Add a comment to this block of methods, e.g. "Hand
Lambros
2012/09/25 22:42:39
Done.
| |
52 | |
53 // Called when the selection owner has replied to a request for information | |
54 // about a selection. | |
55 void DoSelectionNotify(XSelectionEvent* event, | |
56 Atom type, | |
57 int format, | |
58 int item_count, | |
59 void* data); | |
60 | |
61 bool HandleSelectionTargetsEvent(XSelectionEvent* event, | |
62 int format, | |
63 int item_count, | |
64 void* data); | |
65 bool HandleSelectionStringEvent(XSelectionEvent* event, | |
66 int format, | |
67 int item_count, | |
68 void* data); | |
Wez
2012/09/25 20:29:29
Add a comment before these methods indicating that
Lambros
2012/09/25 22:42:39
Done.
| |
69 | |
70 // Notify the registered callback of new clipboard text. | |
71 void NotifyClipboardText(const std::string& text); | |
72 | |
73 bool IsSelectionOwner(Atom selection); | |
Wez
2012/09/25 20:29:29
nit: Move this near to AssertSelectionOwnership.
Lambros
2012/09/25 22:42:39
Done.
| |
74 void RequestSelectionTimestamp(Atom selection, Time time); | |
Wez
2012/09/25 20:29:29
Add a comment before the Request* methods indicati
Wez
2012/09/25 20:29:29
nit: Remove RequestSelectionTimestamp?
Lambros
2012/09/25 22:42:39
Done.
Lambros
2012/09/25 22:42:39
Done.
| |
75 void RequestSelectionTargets(Atom selection); | |
76 void RequestSelectionString(Atom selection, Atom target); | |
77 | |
78 // Assert ownership of the specified |selection|. | |
79 void AssertSelectionOwnership(Atom selection); | |
80 | |
81 Display* display_; | |
82 Window clipboard_window_; | |
83 bool have_xfixes_; | |
84 int xfixes_event_base_; | |
85 int xfixes_error_base_; | |
86 Atom clipboard_atom_; | |
87 Atom large_selection_atom_; | |
88 Atom selection_string_atom_; | |
89 Atom targets_atom_; | |
90 Atom timestamp_atom_; | |
91 Atom utf8_string_atom_; | |
92 std::set<Atom> selections_owned_; | |
93 std::map<Atom, Time> selection_own_time_; | |
94 std::string data_; | |
95 Atom large_selection_property_; | |
96 base::TimeTicks get_selections_time_; | |
97 ClipboardChangedCallback callback_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(XServerClipboard); | |
100 }; | |
101 | |
102 } // namespace remoting | |
103 | |
104 #endif // REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ | |
OLD | NEW |