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 <set> |
| 14 #include <string> |
| 15 |
| 16 #include "base/basictypes.h" |
| 17 #include "base/callback_forward.h" |
| 18 #include "base/timer.h" |
| 19 |
| 20 namespace remoting { |
| 21 |
| 22 // A class to allow manipulation of the X clipboard, using only X API calls. |
| 23 // This class is not thread-safe, so all its methods must be called on the |
| 24 // application's main event-processing thread. |
| 25 class XServerClipboard { |
| 26 public: |
| 27 typedef base::Callback<void(const std::string& mime_type, |
| 28 const std::string& data)> |
| 29 ClipboardChangedCallback; |
| 30 |
| 31 XServerClipboard(); |
| 32 ~XServerClipboard(); |
| 33 |
| 34 // Start monitoring |display|'s selections, and invoke |callback| whenever |
| 35 // their content changes. The caller must ensure |display| is still valid |
| 36 // whenever any other methods are called on this object. |
| 37 void Init(Display* display, const ClipboardChangedCallback& callback); |
| 38 |
| 39 // Copy data to the X Clipboard. This acquires ownership of the |
| 40 // PRIMARY and CLIPBOARD selections. |
| 41 void SetClipboard(const std::string& mime_type, const std::string& data); |
| 42 |
| 43 // Process |event| if it is an X selection notification. The caller should |
| 44 // invoke this for every event it receives from |display|. |
| 45 void ProcessXEvent(XEvent* event); |
| 46 |
| 47 private: |
| 48 // Handlers for X selection events. |
| 49 void OnSetSelectionOwnerNotify(Atom selection, Time timestamp); |
| 50 void OnPropertyNotify(XEvent* event); |
| 51 void OnSelectionNotify(XEvent* event); |
| 52 void OnSelectionRequest(XEvent* event); |
| 53 |
| 54 // Called when the selection owner has replied to a request for information |
| 55 // about a selection. |
| 56 void HandleSelectionNotify(XSelectionEvent* event, |
| 57 Atom type, |
| 58 int format, |
| 59 int item_count, |
| 60 void* data); |
| 61 |
| 62 // These methods return true if selection processing is complete, false |
| 63 // otherwise. |
| 64 bool HandleSelectionTargetsEvent(XSelectionEvent* event, |
| 65 int format, |
| 66 int item_count, |
| 67 void* data); |
| 68 bool HandleSelectionStringEvent(XSelectionEvent* event, |
| 69 int format, |
| 70 int item_count, |
| 71 void* data); |
| 72 |
| 73 // Notify the registered callback of new clipboard text. |
| 74 void NotifyClipboardText(const std::string& text); |
| 75 |
| 76 // These methods trigger the X server or selection owner to send back an |
| 77 // event containing the requested information. |
| 78 void RequestSelectionTargets(Atom selection); |
| 79 void RequestSelectionString(Atom selection, Atom target); |
| 80 |
| 81 // Assert ownership of the specified |selection|. |
| 82 void AssertSelectionOwnership(Atom selection); |
| 83 bool IsSelectionOwner(Atom selection); |
| 84 |
| 85 Display* display_; |
| 86 Window clipboard_window_; |
| 87 int xfixes_event_base_; |
| 88 int xfixes_error_base_; |
| 89 Atom clipboard_atom_; |
| 90 Atom large_selection_atom_; |
| 91 Atom selection_string_atom_; |
| 92 Atom targets_atom_; |
| 93 Atom timestamp_atom_; |
| 94 Atom utf8_string_atom_; |
| 95 std::set<Atom> selections_owned_; |
| 96 std::string data_; |
| 97 Atom large_selection_property_; |
| 98 base::TimeTicks get_selections_time_; |
| 99 ClipboardChangedCallback callback_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(XServerClipboard); |
| 102 }; |
| 103 |
| 104 } // namespace remoting |
| 105 |
| 106 #endif // REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ |
OLD | NEW |