Chromium Code Reviews| Index: remoting/host/linux/x_server_clipboard.h |
| diff --git a/remoting/host/linux/x_server_clipboard.h b/remoting/host/linux/x_server_clipboard.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3527a489c872cc0b2c789f8d75137f4b8265aa7c |
| --- /dev/null |
| +++ b/remoting/host/linux/x_server_clipboard.h |
| @@ -0,0 +1,104 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Don't include this file from any .h files because it pulls in some X headers. |
| + |
| +#ifndef REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ |
| +#define REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ |
| + |
| +#include <X11/Xatom.h> |
| +#include <X11/Xlib.h> |
| + |
| +#include <map> |
| +#include <set> |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/callback_forward.h" |
| +#include "base/timer.h" |
| + |
| +namespace remoting { |
| + |
| +// A class to allow manipulation of the X clipboard, using only X API calls. |
| +class XServerClipboard { |
| + public: |
| + typedef base::Callback<void(const std::string& mime_type, |
| + const std::string& data)> |
| + ClipboardChangedCallback; |
| + |
| + XServerClipboard(); |
| + ~XServerClipboard(); |
| + |
| + // The caller must ensure |display| is still valid whenever any other |
| + // 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.
|
| + void Init(Display* display, const ClipboardChangedCallback& callback); |
| + |
| + // Copy data to the X Clipboard. This acquires ownership of the |
| + // PRIMARY and CLIPBOARD selections. |
| + void SetClipboard(const std::string& mime_type, const std::string& data); |
| + |
| + // This method allows this object to be hooked up to the program's main event |
| + // 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.
|
| + // is not thread-safe, so all its methods must be called on the application's |
| + // 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.
|
| + void ProcessXEvent(XEvent* event); |
| + |
| + private: |
| + void OnSetSelectionOwnerNotify(Atom selection, Time timestamp); |
| + void OnPropertyNotify(XEvent* event); |
| + void OnSelectionNotify(XEvent* event); |
| + 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.
|
| + |
| + // Called when the selection owner has replied to a request for information |
| + // about a selection. |
| + void DoSelectionNotify(XSelectionEvent* event, |
| + Atom type, |
| + int format, |
| + int item_count, |
| + void* data); |
| + |
| + bool HandleSelectionTargetsEvent(XSelectionEvent* event, |
| + int format, |
| + int item_count, |
| + void* data); |
| + bool HandleSelectionStringEvent(XSelectionEvent* event, |
| + int format, |
| + int item_count, |
| + 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.
|
| + |
| + // Notify the registered callback of new clipboard text. |
| + void NotifyClipboardText(const std::string& text); |
| + |
| + 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.
|
| + 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.
|
| + void RequestSelectionTargets(Atom selection); |
| + void RequestSelectionString(Atom selection, Atom target); |
| + |
| + // Assert ownership of the specified |selection|. |
| + void AssertSelectionOwnership(Atom selection); |
| + |
| + Display* display_; |
| + Window clipboard_window_; |
| + bool have_xfixes_; |
| + int xfixes_event_base_; |
| + int xfixes_error_base_; |
| + Atom clipboard_atom_; |
| + Atom large_selection_atom_; |
| + Atom selection_string_atom_; |
| + Atom targets_atom_; |
| + Atom timestamp_atom_; |
| + Atom utf8_string_atom_; |
| + std::set<Atom> selections_owned_; |
| + std::map<Atom, Time> selection_own_time_; |
| + std::string data_; |
| + Atom large_selection_property_; |
| + base::TimeTicks get_selections_time_; |
| + ClipboardChangedCallback callback_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(XServerClipboard); |
| +}; |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ |