Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2686)

Unified Diff: remoting/host/linux/x_server_clipboard.h

Issue 10909133: Implement clipboard for Chromoting Linux hosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Stomped another MessagePumpLibevent Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..196b3d3a99fbd70233a6f59bfa13e9ce6cb21fcf
--- /dev/null
+++ b/remoting/host/linux/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.
Wez 2012/09/17 22:13:29 nit: in -> from?
Lambros 2012/09/19 23:58:19 Done.
+
+#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 low-level X
Wez 2012/09/17 22:13:29 nit: low-level -> only
Lambros 2012/09/19 23:58:19 Done.
+// 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
Wez 2012/09/17 22:13:29 nit: should -> must?
Lambros 2012/09/19 23:58:19 Done.
+ // methods are called on this object.
Wez 2012/09/17 22:13:29 nit: Suggest reword: ... |display| is still valid
Lambros 2012/09/19 23:58:19 Done.
+ void Init(Display* display, const ClipboardChangedCallback& callback);
+
+ void SetClipboard(const std::string& mime_type, const std::string& data);
Wez 2012/09/17 22:13:29 nit: Add a sentence to describe this API.
Lambros 2012/09/19 23:58:19 Done.
+
+ // 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);
Wez 2012/09/17 22:13:29 nit: Reword: Invoked by the caller for each X11 ev
Lambros 2012/09/19 23:58:19 Not necessarily. But then the caller needs to do s
+
+ private:
+ // This checks the state of the X selections. If there is new text selected
Wez 2012/09/17 22:13:29 nit: Suggest reword: "Checks the state of the X P
+ // 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.
Wez 2012/09/17 22:13:29 nit: I don't think you need to document this here;
+ // 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.
Wez 2012/09/17 22:13:29 nit: Why ignore other values rather than treating
Wez 2012/09/17 22:13:29 nit: Suggest reword "|selection| specifies the sel
Lambros 2012/09/19 23:58:19 We ignore them because we might conceivably get th
+ // If |timestamp| is non-zero, it is recorded as the "current selection time",
+ // and is treated as new.
Wez 2012/09/17 22:13:29 nit: This doesn't really explain what |timestamp|
Lambros 2012/09/19 23:58:19 I've expanded the wording a bit.
+ void GetSelections(Atom selection, Time timestamp);
Wez 2012/09/17 22:13:29 Looks like this is the handler for XFixes' SetSele
Lambros 2012/09/19 23:58:19 It's also called during init (although arguably it
Wez 2012/09/20 23:37:46 OK, but can we re-name it to OnSetSelectionOwner,
+
+ void FinishGetSelections();
Wez 2012/09/17 22:13:29 nit: Add a comment explaining what this is for.
Lambros 2012/09/19 23:58:19 Done.
+
+ 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.
Wez 2012/09/17 22:13:29 nit: Reword: "Called when the ..."
Lambros 2012/09/19 23:58:19 Done.
+ 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
Wez 2012/09/17 22:13:29 nit: Which window?
Lambros 2012/09/19 23:58:19 Done.
+ // time should be taken from an X event).
Wez 2012/09/17 22:13:29 nit: Suggest reword: "Assert ownership of the spec
Lambros 2012/09/19 23:58:19 Given that we only ever pass CurrentTime in, I've
+ 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_LINUX_X_SERVER_CLIPBOARD_H_

Powered by Google App Engine
This is Rietveld 408576698