Chromium Code Reviews| 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. | |
| 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 selection. | |
|
Wez
2012/09/20 23:37:46
nit: selections
Lambros
2012/09/21 17:05:57
Done.
| |
| 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 | |
| 43 // is not designed to be thread-safe, so all its methods should ideally be | |
|
Wez
2012/09/20 23:37:46
Surely you mean "must", not "should ideally"?
Lambros
2012/09/21 17:05:57
Done.
| |
| 44 // called on the same thread. In practice, this will mean calling all these | |
| 45 // methods on the application's main event-processing thread, which has the | |
| 46 // added benefit that all calls to Xlib (including XPending/XNextEvent) occur | |
| 47 // on one thread (per display). | |
|
Wez
2012/09/20 23:37:46
This comment seems to imply that the caller might
Lambros
2012/09/21 17:05:57
You're right, no point in being long-winded about
| |
| 48 void ProcessXEvent(XEvent* event); | |
| 49 | |
| 50 private: | |
| 51 // Check the state of the X PRIMARY and CLIPBOARD selections and queues a | |
|
Wez
2012/09/20 23:37:46
nit: queues -> queue
Lambros
2012/09/21 17:05:57
Done.
| |
| 52 // notification to the registered ClipboardChangedCallback if the content has | |
| 53 // changed since the previous call. | |
| 54 // |selection| specifies the selection to be checked (either PRIMARY or | |
| 55 // CLIPBOARD), or None to check both the CLIPBOARD and PRIMARY selections. | |
|
Wez
2012/09/20 23:37:46
nit: It looked to me like the implementation actua
Lambros
2012/09/21 17:05:57
Removed comment. This is just an event-handler no
| |
| 56 // Other values are treated as invalid and ignored. | |
| 57 // If |timestamp| is non-zero, it is assumed to come from an | |
| 58 // XFixesSelectionNotify event, and is recorded as the current selection | |
| 59 // timestamp and treated as new (when comparing with timestamps from incoming | |
| 60 // SelectionNotify events). | |
|
Wez
2012/09/20 23:37:46
I still don't understand this; if you're treating
| |
| 61 void GetSelections(Atom selection, Time timestamp); | |
| 62 | |
| 63 // This stops the GetSelections timer when the process of getting a selection | |
| 64 // is complete. | |
|
Wez
2012/09/20 23:37:46
There's no mention of a timer in the comment for G
Lambros
2012/09/21 17:05:57
Removed this method - it's now just one line of co
| |
| 65 void FinishGetSelections(); | |
| 66 | |
| 67 void OnPropertyNotify(XEvent* event); | |
| 68 void OnSelectionNotify(XEvent* event); | |
| 69 void OnSelectionRequest(XEvent* event); | |
| 70 | |
| 71 // Called when the selection owner has replied to a request for information | |
| 72 // about a selection. | |
| 73 void DoSelectionNotify(XSelectionEvent* event, | |
| 74 Atom type, | |
| 75 int format, | |
| 76 int item_count, | |
| 77 void* data); | |
| 78 | |
| 79 bool HandleSelectionTimestampEvent(XSelectionEvent* event, | |
|
Wez
2012/09/20 23:37:46
nit: Add a comment before this block of methods in
| |
| 80 int format, | |
| 81 int item_count, | |
| 82 void* data); | |
| 83 bool HandleSelectionTargetsEvent(XSelectionEvent* event, | |
| 84 int format, | |
| 85 int item_count, | |
| 86 void* data); | |
| 87 bool HandleSelectionStringEvent(XSelectionEvent* event, | |
| 88 int format, | |
| 89 int item_count, | |
| 90 void* data); | |
| 91 | |
| 92 // Notify the registered callback of new clipboard text. | |
| 93 void NotifyClipboardText(const std::string& text); | |
| 94 | |
| 95 bool IsSelectionOwner(Atom selection); | |
| 96 void RequestSelectionTimestamp(Atom selection, Time time); | |
|
Wez
2012/09/20 23:37:46
nit: Consider adding a comment to this block of me
| |
| 97 void RequestSelectionTargets(Atom selection); | |
| 98 void RequestSelectionString(Atom selection, Atom target); | |
| 99 | |
| 100 // Assert ownership of the specified |selection|. | |
| 101 void AssertSelectionOwnership(Atom selection); | |
| 102 | |
| 103 Display* display_; | |
| 104 Window clipboard_window_; | |
| 105 bool have_xfixes_; | |
| 106 int xfixes_event_base_; | |
| 107 int xfixes_error_base_; | |
| 108 Atom clipboard_atom_; | |
| 109 Atom large_selection_atom_; | |
| 110 Atom selection_string_atom_; | |
| 111 Atom targets_atom_; | |
| 112 Atom timestamp_atom_; | |
| 113 Atom utf8_string_atom_; | |
| 114 std::set<Atom> selections_owned_; | |
| 115 std::map<Atom, Time> selection_own_time_; | |
| 116 std::string data_; | |
| 117 Atom large_selection_property_; | |
| 118 Time current_selection_time_; | |
| 119 Atom new_selection_; | |
| 120 bool getting_initial_selection_; | |
| 121 bool new_cut_text_; | |
| 122 bool had_valid_timestamp_; | |
| 123 base::TimeTicks get_selections_time_; | |
|
Wez
2012/09/20 23:37:46
nit: get_selections_start_time_?
| |
| 124 ClipboardChangedCallback callback_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(XServerClipboard); | |
| 127 }; | |
| 128 | |
| 129 } // namespace remoting | |
| 130 | |
| 131 #endif // REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ | |
| OLD | NEW |