| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_BASE_X_SELECTION_REQUESTOR_H_ | 5 #ifndef UI_BASE_X_SELECTION_REQUESTOR_H_ |
| 6 #define UI_BASE_X_SELECTION_REQUESTOR_H_ | 6 #define UI_BASE_X_SELECTION_REQUESTOR_H_ |
| 7 | 7 |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 | 9 |
| 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
| 11 #undef RootWindow | 11 #undef RootWindow |
| 12 | 12 |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/memory/ref_counted_memory.h" |
| 17 #include "ui/base/ui_export.h" | 18 #include "ui/base/ui_export.h" |
| 18 #include "ui/base/x/x11_atom_cache.h" | 19 #include "ui/base/x/x11_atom_cache.h" |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 21 class SelectionData; | 22 class SelectionData; |
| 22 | 23 |
| 23 // Requests and later receives data from the X11 server through the selection | 24 // Requests and later receives data from the X11 server through the selection |
| 24 // system. | 25 // system. |
| 25 // | 26 // |
| 26 // X11 uses a system called "selections" to implement clipboards and drag and | 27 // X11 uses a system called "selections" to implement clipboards and drag and |
| 27 // drop. This class interprets messages from the statefull selection request | 28 // drop. This class interprets messages from the statefull selection request |
| 28 // API. SelectionRequestor should only deal with the X11 details; it does not | 29 // API. SelectionRequestor should only deal with the X11 details; it does not |
| 29 // implement per-component fast-paths. | 30 // implement per-component fast-paths. |
| 30 class UI_EXPORT SelectionRequestor { | 31 class UI_EXPORT SelectionRequestor { |
| 31 public: | 32 public: |
| 32 SelectionRequestor(Display* xdisplay, | 33 SelectionRequestor(Display* xdisplay, |
| 33 ::Window xwindow, | 34 ::Window xwindow, |
| 34 ::Atom selection_name); | 35 ::Atom selection_name); |
| 35 ~SelectionRequestor(); | 36 ~SelectionRequestor(); |
| 36 | 37 |
| 37 // Does the work of requesting |target| from the selection we handle, | 38 // Does the work of requesting |target| from the selection we handle, |
| 38 // spinning up the nested message loop, and reading the resulting data | 39 // spinning up the nested message loop, and reading the resulting data |
| 39 // back. |out_data| is allocated with the X allocator and must be freed with | 40 // back. |out_data| is allocated with the X allocator and must be freed with |
| 40 // XFree(). |out_data_bytes| is the length in machine chars, while | 41 // XFree(). |out_data_bytes| is the length in machine chars, while |
| 41 // |out_data_items| is the length in |out_type| items. | 42 // |out_data_items| is the length in |out_type| items. |
| 42 bool PerformBlockingConvertSelection(::Atom target, | 43 bool PerformBlockingConvertSelection( |
| 43 unsigned char** out_data, | 44 ::Atom target, |
| 44 size_t* out_data_bytes, | 45 scoped_refptr<base::RefCountedMemory>* out_data, |
| 45 size_t* out_data_items, | 46 size_t* out_data_bytes, |
| 46 ::Atom* out_type); | 47 size_t* out_data_items, |
| 48 ::Atom* out_type); |
| 47 | 49 |
| 48 // Returns the first of |types| offered by the current selection holder, or | 50 // Returns the first of |types| offered by the current selection holder, or |
| 49 // returns NULL if none of those types are available. | 51 // returns NULL if none of those types are available. |
| 50 scoped_ptr<SelectionData> RequestAndWaitForTypes( | 52 SelectionData RequestAndWaitForTypes(const std::vector< ::Atom>& types); |
| 51 const std::vector< ::Atom>& types); | |
| 52 | 53 |
| 53 // It is our owner's responsibility to plumb X11 SelectionNotify events on | 54 // It is our owner's responsibility to plumb X11 SelectionNotify events on |
| 54 // |xwindow_| to us. | 55 // |xwindow_| to us. |
| 55 void OnSelectionNotify(const XSelectionEvent& event); | 56 void OnSelectionNotify(const XSelectionEvent& event); |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 // Our X11 state. | 59 // Our X11 state. |
| 59 Display* x_display_; | 60 Display* x_display_; |
| 60 ::Window x_window_; | 61 ::Window x_window_; |
| 61 | 62 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 80 base::Closure quit_closure_; | 81 base::Closure quit_closure_; |
| 81 | 82 |
| 82 X11AtomCache atom_cache_; | 83 X11AtomCache atom_cache_; |
| 83 | 84 |
| 84 DISALLOW_COPY_AND_ASSIGN(SelectionRequestor); | 85 DISALLOW_COPY_AND_ASSIGN(SelectionRequestor); |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 } // namespace ui | 88 } // namespace ui |
| 88 | 89 |
| 89 #endif // UI_BASE_X_SELECTION_REQUESTOR_H_ | 90 #endif // UI_BASE_X_SELECTION_REQUESTOR_H_ |
| OLD | NEW |