OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CLIPBOARD_CLIPBOARD_H_ | 5 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
6 #define UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 6 #define UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... | |
39 typedef struct _GtkClipboard GtkClipboard; | 39 typedef struct _GtkClipboard GtkClipboard; |
40 #endif | 40 #endif |
41 | 41 |
42 #ifdef __OBJC__ | 42 #ifdef __OBJC__ |
43 @class NSString; | 43 @class NSString; |
44 #else | 44 #else |
45 class NSString; | 45 class NSString; |
46 #endif | 46 #endif |
47 | 47 |
48 namespace ui { | 48 namespace ui { |
49 class ClipboardTest; | |
49 | 50 |
50 class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { | 51 class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
51 public: | 52 public: |
52 // MIME type constants. | 53 // MIME type constants. |
53 static const char kMimeTypeText[]; | 54 static const char kMimeTypeText[]; |
54 static const char kMimeTypeURIList[]; | 55 static const char kMimeTypeURIList[]; |
55 static const char kMimeTypeDownloadURL[]; | 56 static const char kMimeTypeDownloadURL[]; |
56 static const char kMimeTypeHTML[]; | 57 static const char kMimeTypeHTML[]; |
57 static const char kMimeTypeRTF[]; | 58 static const char kMimeTypeRTF[]; |
58 static const char kMimeTypePNG[]; | 59 static const char kMimeTypePNG[]; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 return true; | 176 return true; |
176 #endif | 177 #endif |
177 } | 178 } |
178 return false; | 179 return false; |
179 } | 180 } |
180 | 181 |
181 static Buffer FromInt(int32 buffer) { | 182 static Buffer FromInt(int32 buffer) { |
182 return static_cast<Buffer>(buffer); | 183 return static_cast<Buffer>(buffer); |
183 } | 184 } |
184 | 185 |
185 Clipboard(); | 186 // Returns the clipboard object for the current thread. |
186 ~Clipboard(); | 187 // |
188 // Most implementations will have at most one clipboard which will live on | |
189 // the main UI thread, but Windows has tricky semantics where there have to | |
190 // be two clipboards: one that lives on the UI thread and one that lives on | |
191 // the IO thread. | |
192 static Clipboard* GetForCurrentThread(); | |
193 | |
194 // Destroys the clipboard for the current thread. Usually, this will clean up | |
195 // all clipboards, except on Windows. (Previous code leaks the IO thread | |
196 // clipboard, so it shouldn't be a problem.) | |
197 static void DestroyClipboardForCurrentThread(); | |
187 | 198 |
188 // Write a bunch of objects to the system clipboard. Copies are made of the | 199 // Write a bunch of objects to the system clipboard. Copies are made of the |
189 // contents of |objects|. On Windows they are copied to the system clipboard. | 200 // contents of |objects|. On Windows they are copied to the system clipboard. |
190 // On linux they are copied into a structure owned by the Clipboard object and | 201 // On linux they are copied into a structure owned by the Clipboard object and |
191 // kept until the system clipboard is set again. | 202 // kept until the system clipboard is set again. |
192 void WriteObjects(Buffer buffer, const ObjectMap& objects); | 203 void WriteObjects(Buffer buffer, const ObjectMap& objects); |
193 | 204 |
194 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most | 205 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most |
195 // platforms don't care. | 206 // platforms don't care. |
196 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) \ | 207 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) \ |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 // Firefox text/html | 288 // Firefox text/html |
278 static const FormatType& GetTextHtmlFormatType(); | 289 static const FormatType& GetTextHtmlFormatType(); |
279 static const FormatType& GetCFHDropFormatType(); | 290 static const FormatType& GetCFHDropFormatType(); |
280 static const FormatType& GetFileDescriptorFormatType(); | 291 static const FormatType& GetFileDescriptorFormatType(); |
281 static const FormatType& GetFileContentFormatZeroType(); | 292 static const FormatType& GetFileContentFormatZeroType(); |
282 #endif | 293 #endif |
283 | 294 |
284 private: | 295 private: |
285 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); | 296 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); |
286 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); | 297 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); |
298 friend class ClipboardTest; | |
dcheng
2012/09/05 18:28:06
Out of curiosity, is this because GetForCurrentThr
Elliot Glaysher
2012/09/05 19:26:45
Partly convenience, but also I wanted at least one
| |
299 | |
300 Clipboard(); | |
301 ~Clipboard(); | |
287 | 302 |
288 void DispatchObject(ObjectType type, const ObjectMapParams& params); | 303 void DispatchObject(ObjectType type, const ObjectMapParams& params); |
289 | 304 |
290 void WriteText(const char* text_data, size_t text_len); | 305 void WriteText(const char* text_data, size_t text_len); |
291 | 306 |
292 void WriteHTML(const char* markup_data, | 307 void WriteHTML(const char* markup_data, |
293 size_t markup_len, | 308 size_t markup_len, |
294 const char* url_data, | 309 const char* url_data, |
295 size_t url_len); | 310 size_t url_len); |
296 | 311 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 GtkClipboard* clipboard_; | 371 GtkClipboard* clipboard_; |
357 GtkClipboard* primary_selection_; | 372 GtkClipboard* primary_selection_; |
358 #endif | 373 #endif |
359 | 374 |
360 DISALLOW_COPY_AND_ASSIGN(Clipboard); | 375 DISALLOW_COPY_AND_ASSIGN(Clipboard); |
361 }; | 376 }; |
362 | 377 |
363 } // namespace ui | 378 } // namespace ui |
364 | 379 |
365 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 380 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
OLD | NEW |