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 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.
| |
| 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 low-level X | |
|
Wez
2012/09/17 22:13:29
nit: low-level -> only
Lambros
2012/09/19 23:58:19
Done.
| |
| 24 // API calls. | |
| 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 // 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.
| |
| 35 // 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.
| |
| 36 void Init(Display* display, const ClipboardChangedCallback& callback); | |
| 37 | |
| 38 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.
| |
| 39 | |
| 40 // This method allows this object to be hooked up to the program's main event | |
| 41 // loop. It should be called when the event loop receives an X event, and | |
| 42 // all methods of this object should be called on this thread. | |
| 43 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
| |
| 44 | |
| 45 private: | |
| 46 // 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
| |
| 47 // by another application, this will eventually trigger the registered | |
| 48 // ClipboardChangedCallback. Of the two selections (PRIMARY and CLIPBOARD), | |
| 49 // the PRIMARY selection is tried first, and the CLIPBOARD selection is only | |
| 50 // used if it is newer than PRIMARY. If there is no new text since the | |
| 51 // previous call, then no callback will be made. Duplicate text is filtered | |
| 52 // out, so that the same text being selected again will not trigger the | |
| 53 // callback. | |
| 54 // The Init() method calls this to get the initial state of the X selections; | |
| 55 // 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;
| |
| 56 // If |selection| is CLIPBOARD or PRIMARY, it is checked. If |selection| is | |
| 57 // None, both CLIPBOARD and PRIMARY are checked. Other values of |selection| | |
| 58 // 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
| |
| 59 // If |timestamp| is non-zero, it is recorded as the "current selection time", | |
| 60 // 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.
| |
| 61 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,
| |
| 62 | |
| 63 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.
| |
| 64 | |
| 65 void OnPropertyNotify(XEvent* event); | |
| 66 void OnSelectionNotify(XEvent* event); | |
| 67 void OnSelectionRequest(XEvent* event); | |
| 68 | |
| 69 // This is called when the selection owner has replied to a request for | |
| 70 // information about a selection. | |
|
Wez
2012/09/17 22:13:29
nit: Reword: "Called when the ..."
Lambros
2012/09/19 23:58:19
Done.
| |
| 71 void DoSelectionNotify(XSelectionEvent* event, | |
| 72 Atom type, | |
| 73 int format, | |
| 74 int item_count, | |
| 75 void* data); | |
| 76 | |
| 77 bool GotSelectionTimestamp(XSelectionEvent* event, | |
| 78 int format, | |
| 79 int item_count, | |
| 80 void* data); | |
| 81 bool GotSelectionTargets(XSelectionEvent* event, | |
| 82 int format, | |
| 83 int item_count, | |
| 84 void* data); | |
| 85 bool GotSelectionString(XSelectionEvent* event, | |
| 86 int format, | |
| 87 int item_count, | |
| 88 void* data); | |
| 89 void GotCutTextUtf8(const std::string& text); | |
| 90 bool IsSelectionOwner(Atom selection); | |
| 91 void GetSelectionTimestamp(Atom selection, Time time); | |
| 92 void GetSelectionTargets(Atom selection); | |
| 93 void GetSelectionString(Atom selection, Atom target); | |
| 94 | |
| 95 // 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.
| |
| 96 // 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
| |
| 97 void OwnSelection(Atom selection, Time time); | |
| 98 | |
| 99 Display* display_; | |
| 100 Window clipboard_window_; | |
| 101 bool have_xfixes_; | |
| 102 int xfixes_event_base_; | |
| 103 int xfixes_error_base_; | |
| 104 Atom clipboard_atom_; | |
| 105 Atom large_selection_atom_; | |
| 106 Atom selection_string_atom_; | |
| 107 Atom targets_atom_; | |
| 108 Atom timestamp_atom_; | |
| 109 Atom utf8_string_atom_; | |
| 110 std::set<Atom> selections_owned_; | |
| 111 std::map<Atom, Time> selection_own_time_; | |
| 112 std::string data_; | |
| 113 Atom large_selection_property_; | |
| 114 Time current_selection_time_; | |
| 115 Atom new_selection_; | |
| 116 bool getting_initial_selection_; | |
| 117 bool new_cut_text_; | |
| 118 bool had_valid_timestamp_; | |
| 119 base::TimeTicks get_selections_time_; | |
| 120 ClipboardChangedCallback callback_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(XServerClipboard); | |
| 123 }; | |
| 124 | |
| 125 } // namespace remoting | |
| 126 | |
| 127 #endif // REMOTING_HOST_LINUX_X_SERVER_CLIPBOARD_H_ | |
| OLD | NEW |