| 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> |
| 14 |
| 13 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 14 #include "base/callback.h" | 16 #include "base/callback.h" |
| 15 #include "ui/base/ui_export.h" | 17 #include "ui/base/ui_export.h" |
| 16 #include "ui/base/x/x11_atom_cache.h" | 18 #include "ui/base/x/x11_atom_cache.h" |
| 17 | 19 |
| 18 namespace ui { | 20 namespace ui { |
| 21 class SelectionData; |
| 19 | 22 |
| 20 // Requests and later receives data from the X11 server through the selection | 23 // Requests and later receives data from the X11 server through the selection |
| 21 // system. | 24 // system. |
| 22 // | 25 // |
| 23 // X11 uses a system called "selections" to implement clipboards and drag and | 26 // X11 uses a system called "selections" to implement clipboards and drag and |
| 24 // drop. This class interprets messages from the statefull selection request | 27 // drop. This class interprets messages from the statefull selection request |
| 25 // API. SelectionRequestor should only deal with the X11 details; it does not | 28 // API. SelectionRequestor should only deal with the X11 details; it does not |
| 26 // implement per-component fast-paths. | 29 // implement per-component fast-paths. |
| 27 class UI_EXPORT SelectionRequestor { | 30 class UI_EXPORT SelectionRequestor { |
| 28 public: | 31 public: |
| 29 SelectionRequestor(Display* xdisplay, | 32 SelectionRequestor(Display* xdisplay, |
| 30 ::Window xwindow, | 33 ::Window xwindow, |
| 31 ::Atom selection_name); | 34 ::Atom selection_name); |
| 32 ~SelectionRequestor(); | 35 ~SelectionRequestor(); |
| 33 | 36 |
| 34 // Does the work of requesting |target| from the selection we handle, | 37 // Does the work of requesting |target| from the selection we handle, |
| 35 // spinning up the nested message loop, and reading the resulting data | 38 // spinning up the nested message loop, and reading the resulting data |
| 36 // back. |out_data| is allocated with the X allocator and must be freed with | 39 // back. |out_data| is allocated with the X allocator and must be freed with |
| 37 // XFree(). |out_data_bytes| is the length in machine chars, while | 40 // XFree(). |out_data_bytes| is the length in machine chars, while |
| 38 // |out_data_items| is the length in |out_type| items. | 41 // |out_data_items| is the length in |out_type| items. |
| 39 bool PerformBlockingConvertSelection(::Atom target, | 42 bool PerformBlockingConvertSelection(::Atom target, |
| 40 unsigned char** out_data, | 43 unsigned char** out_data, |
| 41 size_t* out_data_bytes, | 44 size_t* out_data_bytes, |
| 42 size_t* out_data_items, | 45 size_t* out_data_items, |
| 43 ::Atom* out_type); | 46 ::Atom* out_type); |
| 44 | 47 |
| 48 // Returns the first of |types| offered by the current selection holder, or |
| 49 // returns NULL if none of those types are available. |
| 50 scoped_ptr<SelectionData> RequestAndWaitForTypes( |
| 51 const std::vector< ::Atom>& types); |
| 52 |
| 45 // It is our owner's responsibility to plumb X11 SelectionNotify events on | 53 // It is our owner's responsibility to plumb X11 SelectionNotify events on |
| 46 // |xwindow_| to us. | 54 // |xwindow_| to us. |
| 47 void OnSelectionNotify(const XSelectionEvent& event); | 55 void OnSelectionNotify(const XSelectionEvent& event); |
| 48 | 56 |
| 49 private: | 57 private: |
| 50 // Our X11 state. | 58 // Our X11 state. |
| 51 Display* x_display_; | 59 Display* x_display_; |
| 52 ::Window x_window_; | 60 ::Window x_window_; |
| 53 | 61 |
| 54 // True if we're currently running a nested message loop, waiting for data to | 62 // True if we're currently running a nested message loop, waiting for data to |
| (...skipping 17 matching lines...) Expand all Loading... |
| 72 base::Closure quit_closure_; | 80 base::Closure quit_closure_; |
| 73 | 81 |
| 74 X11AtomCache atom_cache_; | 82 X11AtomCache atom_cache_; |
| 75 | 83 |
| 76 DISALLOW_COPY_AND_ASSIGN(SelectionRequestor); | 84 DISALLOW_COPY_AND_ASSIGN(SelectionRequestor); |
| 77 }; | 85 }; |
| 78 | 86 |
| 79 } // namespace ui | 87 } // namespace ui |
| 80 | 88 |
| 81 #endif // UI_BASE_X_SELECTION_REQUESTOR_H_ | 89 #endif // UI_BASE_X_SELECTION_REQUESTOR_H_ |
| OLD | NEW |