| 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_OWNER_H_ | 5 #ifndef UI_BASE_X_SELECTION_OWNER_H_ |
| 6 #define UI_BASE_X_SELECTION_OWNER_H_ | 6 #define UI_BASE_X_SELECTION_OWNER_H_ |
| 7 | 7 |
| 8 #include <X11/Xlib.h> | |
| 9 | |
| 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | |
| 11 #undef RootWindow | |
| 12 | |
| 13 #include <vector> | 8 #include <vector> |
| 14 | 9 |
| 15 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 16 #include "base/callback.h" | 11 #include "base/callback.h" |
| 17 #include "ui/base/ui_base_export.h" | 12 #include "ui/base/ui_base_export.h" |
| 18 #include "ui/base/x/selection_utils.h" | 13 #include "ui/base/x/selection_utils.h" |
| 19 #include "ui/gfx/x/x11_atom_cache.h" | 14 #include "ui/gfx/x/x11_atom_cache.h" |
| 15 #include "ui/gfx/x/x11_types.h" |
| 20 | 16 |
| 21 namespace ui { | 17 namespace ui { |
| 22 | 18 |
| 23 // Owns a specific X11 selection on an X window. | 19 // Owns a specific X11 selection on an X window. |
| 24 // | 20 // |
| 25 // The selection owner object keeps track of which xwindow is the current | 21 // The selection owner object keeps track of which xwindow is the current |
| 26 // owner, and when its |xwindow_|, offers different data types to other | 22 // owner, and when its |xwindow_|, offers different data types to other |
| 27 // processes. | 23 // processes. |
| 28 class UI_BASE_EXPORT SelectionOwner { | 24 class UI_BASE_EXPORT SelectionOwner { |
| 29 public: | 25 public: |
| 30 SelectionOwner(Display* xdisplay, | 26 SelectionOwner(XDisplay* xdisplay, |
| 31 ::Window xwindow, | 27 XID xwindow, |
| 32 ::Atom selection_name); | 28 XAtom selection_name); |
| 33 ~SelectionOwner(); | 29 ~SelectionOwner(); |
| 34 | 30 |
| 35 // Returns the current selection data. Useful for fast paths. | 31 // Returns the current selection data. Useful for fast paths. |
| 36 const SelectionFormatMap& selection_format_map() { return format_map_; } | 32 const SelectionFormatMap& selection_format_map() { return format_map_; } |
| 37 | 33 |
| 38 // Appends a list of types we're offering to |targets|. | 34 // Appends a list of types we're offering to |targets|. |
| 39 void RetrieveTargets(std::vector<Atom>* targets); | 35 void RetrieveTargets(std::vector<XAtom>* targets); |
| 40 | 36 |
| 41 // Attempts to take ownership of the selection. If we're successful, present | 37 // Attempts to take ownership of the selection. If we're successful, present |
| 42 // |data| to other windows. | 38 // |data| to other windows. |
| 43 void TakeOwnershipOfSelection(const SelectionFormatMap& data); | 39 void TakeOwnershipOfSelection(const SelectionFormatMap& data); |
| 44 | 40 |
| 45 // Clears our internal format map and clears the selection owner, whether we | 41 // Clears our internal format map and clears the selection owner, whether we |
| 46 // own the selection or not. | 42 // own the selection or not. |
| 47 void ClearSelectionOwner(); | 43 void ClearSelectionOwner(); |
| 48 | 44 |
| 49 // It is our owner's responsibility to plumb X11 events on |xwindow_| to us. | 45 // It is our owner's responsibility to plumb X11 events on |xwindow_| to us. |
| 50 void OnSelectionRequest(const XSelectionRequestEvent& event); | 46 void OnSelectionRequest(const XEvent& event); |
| 51 void OnSelectionClear(const XSelectionClearEvent& event); | 47 void OnSelectionClear(const XEvent& event); |
| 52 // TODO(erg): Do we also need to follow PropertyNotify events? We currently | 48 // TODO(erg): Do we also need to follow PropertyNotify events? We currently |
| 53 // don't, but there were open todos in the previous implementation. | 49 // don't, but there were open todos in the previous implementation. |
| 54 | 50 |
| 55 private: | 51 private: |
| 56 // Attempts to convert the selection to |target|. If the conversion is | 52 // Attempts to convert the selection to |target|. If the conversion is |
| 57 // successful, true is returned and the result is stored in the |property| | 53 // successful, true is returned and the result is stored in the |property| |
| 58 // of |requestor|. | 54 // of |requestor|. |
| 59 bool ProcessTarget(::Atom target, ::Window requestor, ::Atom property); | 55 bool ProcessTarget(XAtom target, XID requestor, XAtom property); |
| 60 | 56 |
| 61 // Our X11 state. | 57 // Our X11 state. |
| 62 Display* x_display_; | 58 XDisplay* x_display_; |
| 63 ::Window x_window_; | 59 XID x_window_; |
| 64 | 60 |
| 65 // The X11 selection that this instance communicates on. | 61 // The X11 selection that this instance communicates on. |
| 66 ::Atom selection_name_; | 62 XAtom selection_name_; |
| 67 | 63 |
| 68 // The data we are currently serving. | 64 // The data we are currently serving. |
| 69 SelectionFormatMap format_map_; | 65 SelectionFormatMap format_map_; |
| 70 | 66 |
| 71 X11AtomCache atom_cache_; | 67 X11AtomCache atom_cache_; |
| 72 | 68 |
| 73 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); | 69 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); |
| 74 }; | 70 }; |
| 75 | 71 |
| 76 } // namespace ui | 72 } // namespace ui |
| 77 | 73 |
| 78 #endif // UI_BASE_X_SELECTION_OWNER_H_ | 74 #endif // UI_BASE_X_SELECTION_OWNER_H_ |
| OLD | NEW |