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_UTILS_H_ | 5 #ifndef UI_BASE_X_SELECTION_UTILS_H_ |
6 #define UI_BASE_X_SELECTION_UTILS_H_ | 6 #define UI_BASE_X_SELECTION_UTILS_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 <map> | 13 #include <map> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "ui/base/clipboard/clipboard.h" | 16 #include "ui/base/clipboard/clipboard.h" |
17 #include "ui/base/ui_export.h" | 17 #include "ui/base/ui_export.h" |
| 18 #include "ui/base/x/x11_atom_cache.h" |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 class X11AtomCache; | 21 class X11AtomCache; |
21 | 22 |
| 23 extern const char kMimeTypeMozillaURL[]; |
| 24 extern const char kString[]; |
| 25 extern const char kText[]; |
| 26 extern const char kUtf8String[]; |
| 27 |
22 // Returns a list of all text atoms that we handle. | 28 // Returns a list of all text atoms that we handle. |
23 UI_EXPORT std::vector< ::Atom> GetTextAtomsFrom(const X11AtomCache* atom_cache); | 29 UI_EXPORT std::vector< ::Atom> GetTextAtomsFrom(const X11AtomCache* atom_cache); |
24 | 30 |
| 31 UI_EXPORT std::vector< ::Atom> GetURLAtomsFrom(const X11AtomCache* atom_cache); |
| 32 |
| 33 // Places the intersection of |one| and |two| into |output|. |
| 34 UI_EXPORT void GetAtomIntersection(const std::vector< ::Atom>& one, |
| 35 const std::vector< ::Atom>& two, |
| 36 std::vector< ::Atom>* output); |
| 37 |
25 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
26 | 39 |
27 // Represents the selection in different data formats. Binary data passed in is | 40 // Represents the selection in different data formats. Binary data passed in is |
28 // assumed to be allocated with new char[], and is owned by SelectionFormatMap. | 41 // assumed to be allocated with new char[], and is owned by SelectionFormatMap. |
29 class UI_EXPORT SelectionFormatMap { | 42 class UI_EXPORT SelectionFormatMap { |
30 public: | 43 public: |
31 // Our internal data store, which we only expose through iterators. | 44 // Our internal data store, which we only expose through iterators. |
32 typedef std::map< ::Atom, std::pair<char*, size_t> > InternalMap; | 45 typedef std::map< ::Atom, std::pair<char*, size_t> > InternalMap; |
33 typedef std::map< ::Atom, std::pair<char*, size_t> >::const_iterator | 46 typedef std::map< ::Atom, std::pair<char*, size_t> >::const_iterator |
34 const_iterator; | 47 const_iterator; |
(...skipping 10 matching lines...) Expand all Loading... |
45 const_iterator end() const { return data_.end(); } | 58 const_iterator end() const { return data_.end(); } |
46 const_iterator find(::Atom atom) const { return data_.find(atom); } | 59 const_iterator find(::Atom atom) const { return data_.find(atom); } |
47 size_t size() const { return data_.size(); } | 60 size_t size() const { return data_.size(); } |
48 | 61 |
49 private: | 62 private: |
50 InternalMap data_; | 63 InternalMap data_; |
51 | 64 |
52 DISALLOW_COPY_AND_ASSIGN(SelectionFormatMap); | 65 DISALLOW_COPY_AND_ASSIGN(SelectionFormatMap); |
53 }; | 66 }; |
54 | 67 |
| 68 /////////////////////////////////////////////////////////////////////////////// |
| 69 |
| 70 // A holder for data with optional X11 deletion semantics. |
| 71 class UI_EXPORT SelectionData { |
| 72 public: |
| 73 // |atom_cache| is still owned by caller. |
| 74 explicit SelectionData(Display* x_display); |
| 75 ~SelectionData(); |
| 76 |
| 77 ::Atom type() const { return type_; } |
| 78 char* data() const { return data_; } |
| 79 size_t size() const { return size_; } |
| 80 |
| 81 void Set(::Atom type, char* data, size_t size, bool owned); |
| 82 |
| 83 // If |type_| is a string type, convert the data to UTF8 and return it. |
| 84 std::string GetText() const; |
| 85 |
| 86 // If |type_| is the HTML type, returns the data as a string16. This detects |
| 87 // guesses the character encoding of the source. |
| 88 string16 GetHtml() const; |
| 89 |
| 90 // Assigns the raw data to the string. |
| 91 void AssignTo(std::string* result) const; |
| 92 void AssignTo(string16* result) const; |
| 93 |
| 94 private: |
| 95 ::Atom type_; |
| 96 char* data_; |
| 97 size_t size_; |
| 98 bool owned_; |
| 99 |
| 100 X11AtomCache atom_cache_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(SelectionData); |
| 103 }; |
| 104 |
55 } // namespace ui | 105 } // namespace ui |
56 | 106 |
57 #endif // UI_BASE_X_SELECTION_UTILS_H_ | 107 #endif // UI_BASE_X_SELECTION_UTILS_H_ |
OLD | NEW |