Chromium Code Reviews| Index: remoting/host/x_server_clipboard.h |
| diff --git a/remoting/host/x_server_clipboard.h b/remoting/host/x_server_clipboard.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b0dd7f63ee292ec49158b34b01f9ecac57817e43 |
| --- /dev/null |
| +++ b/remoting/host/x_server_clipboard.h |
| @@ -0,0 +1,127 @@ |
| +// 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 in any .h files because it pulls in some X headers. |
| + |
| +#ifndef REMOTING_HOST_X_SERVER_CLIPBOARD_H_ |
|
Sergey Ulanov
2012/09/14 19:35:01
Please put this file in remoting/host/linux . Idea
Lambros
2012/09/14 21:35:13
Done.
|
| +#define REMOTING_HOST_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 low-level X |
| +// API calls. |
| +class XServerClipboard { |
| + public: |
| + typedef base::Callback<void(const std::string& mime_type, |
| + const std::string& data)> |
| + ClipboardChangedCallback; |
| + |
| + XServerClipboard(); |
| + ~XServerClipboard(); |
| + |
| + // The caller should ensure |display| remains valid as long as any other |
| + // methods are called on this object. |
| + void Init(Display* display, const ClipboardChangedCallback& callback); |
| + |
| + 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 called when the event loop receives an X event, and |
| + // all methods of this object should be called on this thread. |
| + void ProcessXEvent(XEvent* event); |
| + |
| + private: |
| + // This checks the state of the X selections. If there is new text selected |
| + // by another application, this will eventually trigger the registered |
| + // ClipboardChangedCallback. Of the two selections (PRIMARY and CLIPBOARD), |
| + // the PRIMARY selection is tried first, and the CLIPBOARD selection is only |
| + // used if it is newer than PRIMARY. If there is no new text since the |
| + // previous call, then no callback will be made. Duplicate text is filtered |
| + // out, so that the same text being selected again will not trigger the |
| + // callback. |
| + // The Init() method calls this to get the initial state of the X selections; |
| + // no callback will be triggered in this case. |
| + // If |selection| is CLIPBOARD or PRIMARY, it is checked. If |selection| is |
| + // None, both CLIPBOARD and PRIMARY are checked. Other values of |selection| |
| + // are ignored. |
| + // If |timestamp| is non-zero, it is recorded as the "current selection time", |
| + // and is treated as new. |
| + void GetSelections(Atom selection, Time timestamp); |
| + |
| + void FinishGetSelections(); |
| + |
| + void OnPropertyNotify(XEvent* event); |
| + void OnSelectionNotify(XEvent* event); |
| + void OnSelectionRequest(XEvent* event); |
| + |
| + // This is 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 GotSelectionTimestamp(XSelectionEvent* event, |
| + int format, |
| + int item_count, |
| + void* data); |
| + bool GotSelectionTargets(XSelectionEvent* event, |
| + int format, |
| + int item_count, |
| + void* data); |
| + bool GotSelectionString(XSelectionEvent* event, |
| + int format, |
| + int item_count, |
| + void* data); |
| + void GotCutTextUtf8(const std::string& text); |
| + bool IsSelectionOwner(Atom selection); |
| + void GetSelectionTimestamp(Atom selection, Time time); |
| + void GetSelectionTargets(Atom selection); |
| + void GetSelectionString(Atom selection, Atom target); |
| + |
| + // Request that the window owns the given selection from the given time (the |
| + // time should be taken from an X event). |
| + void OwnSelection(Atom selection, Time time); |
| + |
| + 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_; |
| + Time current_selection_time_; |
| + Atom new_selection_; |
| + bool getting_initial_selection_; |
| + bool new_cut_text_; |
| + bool had_valid_timestamp_; |
| + base::TimeTicks get_selections_time_; |
| + ClipboardChangedCallback callback_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(XServerClipboard); |
| +}; |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_HOST_X_SERVER_CLIPBOARD_H_ |