| 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> | 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 "ui/base/ui_export.h" | 17 #include "ui/base/ui_export.h" |
| 18 #include "ui/base/x/selection_utils.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 | 22 |
| 22 class SelectionFormatMap; | |
| 23 | |
| 24 // Owns a specific X11 selection on an X window. | 23 // Owns a specific X11 selection on an X window. |
| 25 // | 24 // |
| 26 // The selection owner object keeps track of which xwindow is the current | 25 // The selection owner object keeps track of which xwindow is the current |
| 27 // owner, and when its |xwindow_|, offers different data types to other | 26 // owner, and when its |xwindow_|, offers different data types to other |
| 28 // processes. | 27 // processes. |
| 29 class UI_EXPORT SelectionOwner { | 28 class UI_EXPORT SelectionOwner { |
| 30 public: | 29 public: |
| 31 SelectionOwner(Display* xdisplay, | 30 SelectionOwner(Display* xdisplay, |
| 32 ::Window xwindow, | 31 ::Window xwindow, |
| 33 ::Atom selection_name); | 32 ::Atom selection_name); |
| 34 ~SelectionOwner(); | 33 ~SelectionOwner(); |
| 35 | 34 |
| 36 // Returns the current selection data. Useful for fast paths. | 35 // Returns the current selection data. Useful for fast paths. |
| 37 SelectionFormatMap* selection_format_map() { return selection_data_.get(); } | 36 const SelectionFormatMap& selection_format_map() { return format_map_; } |
| 38 | 37 |
| 39 // Retrieves a list of types we're offering. | 38 // Retrieves a list of types we're offering. |
| 40 void RetrieveTargets(std::vector<Atom>* targets); | 39 void RetrieveTargets(std::vector<Atom>* targets); |
| 41 | 40 |
| 42 // Attempts to take ownership of the selection. If we're successful, present | 41 // Attempts to take ownership of the selection. If we're successful, present |
| 43 // |data| to other windows. | 42 // |data| to other windows. |
| 44 void TakeOwnershipOfSelection(scoped_ptr<SelectionFormatMap> data); | 43 void TakeOwnershipOfSelection(const SelectionFormatMap& data); |
| 45 | 44 |
| 46 // Releases the selection (if we own it) and clears any data we own. | 45 // Releases the selection (if we own it) and clears any data we own. |
| 47 void Clear(); | 46 void Clear(); |
| 48 | 47 |
| 49 // It is our owner's responsibility to plumb X11 events on |xwindow_| to us. | 48 // It is our owner's responsibility to plumb X11 events on |xwindow_| to us. |
| 50 void OnSelectionRequest(const XSelectionRequestEvent& event); | 49 void OnSelectionRequest(const XSelectionRequestEvent& event); |
| 51 void OnSelectionClear(const XSelectionClearEvent& event); | 50 void OnSelectionClear(const XSelectionClearEvent& event); |
| 52 // TODO(erg): Do we also need to follow PropertyNotify events? We currently | 51 // TODO(erg): Do we also need to follow PropertyNotify events? We currently |
| 53 // don't, but there were open todos in the previous implementation. | 52 // don't, but there were open todos in the previous implementation. |
| 54 | 53 |
| 55 private: | 54 private: |
| 56 // Our X11 state. | 55 // Our X11 state. |
| 57 Display* x_display_; | 56 Display* x_display_; |
| 58 ::Window x_window_; | 57 ::Window x_window_; |
| 59 | 58 |
| 60 // The X11 selection that this instance communicates on. | 59 // The X11 selection that this instance communicates on. |
| 61 ::Atom selection_name_; | 60 ::Atom selection_name_; |
| 62 | 61 |
| 63 // The data we are currently serving. | 62 // The data we are currently serving. |
| 64 scoped_ptr<SelectionFormatMap> selection_data_; | 63 SelectionFormatMap format_map_; |
| 65 | 64 |
| 66 X11AtomCache atom_cache_; | 65 X11AtomCache atom_cache_; |
| 67 | 66 |
| 68 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); | 67 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 } // namespace ui | 70 } // namespace ui |
| 72 | 71 |
| 73 #endif // UI_BASE_X_SELECTION_OWNER_H_ | 72 #endif // UI_BASE_X_SELECTION_OWNER_H_ |
| OLD | NEW |