OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 BASE_CLIPBOARD_H_ | 5 #ifndef BASE_CLIPBOARD_H_ |
6 #define BASE_CLIPBOARD_H_ | 6 #define BASE_CLIPBOARD_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
| 10 #include <utility> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
12 #include "base/gfx/size.h" | 14 #include "base/gfx/size.h" |
13 #include "base/shared_memory.h" | 15 #include "base/shared_memory.h" |
14 | 16 |
15 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
16 #if defined(__OBJC__) | 18 #if defined(__OBJC__) |
17 @class NSString; | 19 @class NSString; |
18 #else | 20 #else |
19 class NSString; | 21 class NSString; |
20 #endif | 22 #endif |
21 #endif | 23 #endif |
22 | 24 |
23 class Clipboard { | 25 class Clipboard { |
24 public: | 26 public: |
25 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
26 typedef unsigned int FormatType; | 28 typedef unsigned int FormatType; |
27 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
28 typedef NSString *FormatType; | 30 typedef NSString *FormatType; |
29 #elif defined(OS_LINUX) | 31 #elif defined(OS_LINUX) |
30 typedef struct _GdkAtom* FormatType; | 32 typedef struct _GdkAtom* FormatType; |
31 typedef struct _GtkClipboard GtkClipboard; | 33 typedef struct _GtkClipboard GtkClipboard; |
| 34 // A mapping from target (format) string to the relevant data (usually a |
| 35 // string, but potentially arbitrary data). |
| 36 typedef std::map<std::string, std::pair<uint8*, size_t> > TargetMap; |
32 #endif | 37 #endif |
33 | 38 |
34 Clipboard(); | 39 Clipboard(); |
35 ~Clipboard(); | 40 ~Clipboard(); |
36 | 41 |
37 // Clears the clipboard. It is usually a good idea to clear the clipboard | 42 // Clears the clipboard. It is usually a good idea to clear the clipboard |
38 // before writing content to the clipboard. | 43 // before writing content to the clipboard. |
39 void Clear(); | 44 void Clear(); |
40 | 45 |
41 // Adds UNICODE and ASCII text to the clipboard. | 46 // Adds UNICODE and ASCII text to the clipboard. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Reads HTML from the clipboard, if available. | 96 // Reads HTML from the clipboard, if available. |
92 void ReadHTML(std::wstring* markup, std::string* src_url) const; | 97 void ReadHTML(std::wstring* markup, std::string* src_url) const; |
93 | 98 |
94 // Reads a bookmark from the clipboard, if available. | 99 // Reads a bookmark from the clipboard, if available. |
95 void ReadBookmark(std::wstring* title, std::string* url) const; | 100 void ReadBookmark(std::wstring* title, std::string* url) const; |
96 | 101 |
97 // Reads a file or group of files from the clipboard, if available, into the | 102 // Reads a file or group of files from the clipboard, if available, into the |
98 // out parameter. | 103 // out parameter. |
99 void ReadFile(std::wstring* file) const; | 104 void ReadFile(std::wstring* file) const; |
100 void ReadFiles(std::vector<std::wstring>* files) const; | 105 void ReadFiles(std::vector<std::wstring>* files) const; |
101 | 106 |
102 // Get format Identifiers for various types. | 107 // Get format Identifiers for various types. |
103 static FormatType GetUrlFormatType(); | 108 static FormatType GetUrlFormatType(); |
104 static FormatType GetUrlWFormatType(); | 109 static FormatType GetUrlWFormatType(); |
105 static FormatType GetMozUrlFormatType(); | 110 static FormatType GetMozUrlFormatType(); |
106 static FormatType GetPlainTextFormatType(); | 111 static FormatType GetPlainTextFormatType(); |
107 static FormatType GetPlainTextWFormatType(); | 112 static FormatType GetPlainTextWFormatType(); |
108 static FormatType GetFilenameFormatType(); | 113 static FormatType GetFilenameFormatType(); |
109 static FormatType GetFilenameWFormatType(); | 114 static FormatType GetFilenameWFormatType(); |
110 // Win: MS HTML Format, Other: Generic HTML format | 115 // Win: MS HTML Format, Other: Generic HTML format |
111 static FormatType GetHtmlFormatType(); | 116 static FormatType GetHtmlFormatType(); |
(...skipping 16 matching lines...) Expand all Loading... |
128 static void ParseHTMLClipboardFormat(const std::string& html_fragment, | 133 static void ParseHTMLClipboardFormat(const std::string& html_fragment, |
129 std::wstring* markup, | 134 std::wstring* markup, |
130 std::string* src_url); | 135 std::string* src_url); |
131 | 136 |
132 static void ParseBookmarkClipboardFormat(const std::wstring& bookmark, | 137 static void ParseBookmarkClipboardFormat(const std::wstring& bookmark, |
133 std::wstring* title, | 138 std::wstring* title, |
134 std::string* url); | 139 std::string* url); |
135 | 140 |
136 HWND clipboard_owner_; | 141 HWND clipboard_owner_; |
137 #elif defined(OS_LINUX) | 142 #elif defined(OS_LINUX) |
| 143 // Write changes to gtk clipboard. |
| 144 void SetGtkClipboard(); |
| 145 // Free pointers in clipboard_data_ and clear() the map. |
| 146 void FreeTargetMap(); |
| 147 // Insert a mapping into clipboard_data_, or change an existing mapping. |
| 148 uint8* InsertOrOverwrite(std::string target, uint8* data, size_t data_len); |
| 149 |
| 150 // We have to be able to store multiple formats on the clipboard |
| 151 // simultaneously. The Chrome Clipboard class accomplishes this by |
| 152 // expecting that consecutive calls to Write* (WriteHTML, WriteText, etc.) |
| 153 // The GTK clipboard interface does not naturally support consecutive calls |
| 154 // building on one another. So we keep all data in a map, and always pass the |
| 155 // map when we are setting the gtk clipboard. Consecutive calls to Write* |
| 156 // will write to the map and set the GTK clipboard, then add to the same |
| 157 // map and set the GTK clipboard again. GTK thinks it is wiping out the |
| 158 // clipboard but we are actually keeping the previous data. |
| 159 TargetMap clipboard_data_; |
138 GtkClipboard* clipboard_; | 160 GtkClipboard* clipboard_; |
139 #endif | 161 #endif |
140 | 162 |
141 DISALLOW_EVIL_CONSTRUCTORS(Clipboard); | 163 DISALLOW_EVIL_CONSTRUCTORS(Clipboard); |
142 }; | 164 }; |
143 | 165 |
144 #endif // BASE_CLIPBOARD_H_ | 166 #endif // BASE_CLIPBOARD_H_ |
145 | 167 |
OLD | NEW |