| 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 // This file declares the ScopedClipboardWriter class, a wrapper around | 5 // This file declares the ScopedClipboardWriter class, a wrapper around |
| 6 // the Clipboard class which simplifies writing data to the system clipboard. | 6 // the Clipboard class which simplifies writing data to the system clipboard. |
| 7 // Upon deletion the class atomically writes all data to |clipboard_|, | 7 // Upon deletion the class atomically writes all data to |clipboard_|, |
| 8 // avoiding any potential race condition with other processes that are also | 8 // avoiding any potential race condition with other processes that are also |
| 9 // writing to the system clipboard. | 9 // writing to the system clipboard. |
| 10 #ifndef BASE_SCOPED_CLIPBOARD_WRITER_H_ | 10 #ifndef BASE_SCOPED_CLIPBOARD_WRITER_H_ |
| 11 #define BASE_SCOPED_CLIPBOARD_WRITER_H_ | 11 #define BASE_SCOPED_CLIPBOARD_WRITER_H_ |
| 12 | 12 |
| 13 #include <string> |
| 14 #include <vector> |
| 15 |
| 13 #include "base/clipboard.h" | 16 #include "base/clipboard.h" |
| 17 #include "base/file_path.h" |
| 18 #include "base/string16.h" |
| 14 | 19 |
| 15 // This class is a wrapper for |Clipboard| that handles packing data | 20 // This class is a wrapper for |Clipboard| that handles packing data |
| 16 // into a Clipboard::ObjectMap. | 21 // into a Clipboard::ObjectMap. |
| 17 // NB: You should probably NOT be using this class if you include | 22 // NB: You should probably NOT be using this class if you include |
| 18 // webkit_glue.h. Use ScopedClipboardWriterGlue instead. | 23 // webkit_glue.h. Use ScopedClipboardWriterGlue instead. |
| 19 class ScopedClipboardWriter { | 24 class ScopedClipboardWriter { |
| 20 public: | 25 public: |
| 21 // Create an instance that is a simple wrapper around clipboard. | 26 // Create an instance that is a simple wrapper around clipboard. |
| 22 ScopedClipboardWriter(Clipboard* clipboard); | 27 ScopedClipboardWriter(Clipboard* clipboard); |
| 23 | 28 |
| 24 ~ScopedClipboardWriter(); | 29 ~ScopedClipboardWriter(); |
| 25 | 30 |
| 26 // Converts |text| to UTF-8 and adds it to the clipboard. | 31 // Converts |text| to UTF-8 and adds it to the clipboard. |
| 27 void WriteText(const std::wstring& text); | 32 void WriteText(const string16& text); |
| 28 | 33 |
| 29 // Adds HTML to the clipboard. The url parameter is optional, but especially | 34 // Adds HTML to the clipboard. The url parameter is optional, but especially |
| 30 // useful if the HTML fragment contains relative links. | 35 // useful if the HTML fragment contains relative links. |
| 31 void WriteHTML(const std::wstring& markup, const std::string& source_url); | 36 void WriteHTML(const string16& markup, const std::string& source_url); |
| 32 | 37 |
| 33 // Adds a bookmark to the clipboard. | 38 // Adds a bookmark to the clipboard. |
| 34 void WriteBookmark(const std::wstring& bookmark_title, | 39 void WriteBookmark(const string16& bookmark_title, |
| 35 const std::string& url); | 40 const std::string& url); |
| 36 | 41 |
| 37 // Adds both a bookmark and an HTML hyperlink to the clipboard. It is a | 42 // Adds both a bookmark and an HTML hyperlink to the clipboard. It is a |
| 38 // convenience wrapper around WriteBookmark and WriteHTML. |link_text| is | 43 // convenience wrapper around WriteBookmark and WriteHTML. |link_text| is |
| 39 // used as the bookmark title. | 44 // used as the bookmark title. |
| 40 void WriteHyperlink(const std::wstring& link_text, const std::string& url); | 45 void WriteHyperlink(const string16& link_text, const std::string& url); |
| 41 | 46 |
| 42 // Adds a file or group of files to the clipboard. | 47 // Adds a file or group of files to the clipboard. |
| 43 void WriteFile(const std::wstring& file); | 48 void WriteFile(const FilePath& file); |
| 44 void WriteFiles(const std::vector<std::wstring>& files); | 49 void WriteFiles(const std::vector<FilePath>& files); |
| 45 | 50 |
| 46 // Used by WebKit to determine whether WebKit wrote the clipboard last | 51 // Used by WebKit to determine whether WebKit wrote the clipboard last |
| 47 void WriteWebSmartPaste(); | 52 void WriteWebSmartPaste(); |
| 48 | 53 |
| 49 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| 50 // Adds a bitmap to the clipboard | 55 // Adds a bitmap to the clipboard |
| 51 // This is the slowest way to copy a bitmap to the clipboard as we must first | 56 // This is the slowest way to copy a bitmap to the clipboard as we must first |
| 52 // memcpy the pixels into GDI and the blit the bitmap to the clipboard. | 57 // memcpy the pixels into GDI and the blit the bitmap to the clipboard. |
| 53 // Pixel format is assumed to be 32-bit BI_RGB. | 58 // Pixel format is assumed to be 32-bit BI_RGB. |
| 54 void WriteBitmapFromPixels(const void* pixels, const gfx::Size& size); | 59 void WriteBitmapFromPixels(const void* pixels, const gfx::Size& size); |
| 55 #endif // defined(OS_WIN) | 60 #endif // defined(OS_WIN) |
| 56 | 61 |
| 57 protected: | 62 protected: |
| 58 // We accumulate the data passed to the various targets in the |objects_| | 63 // We accumulate the data passed to the various targets in the |objects_| |
| 59 // vector, and pass it to Clipboard::WriteObjects() during object destruction. | 64 // vector, and pass it to Clipboard::WriteObjects() during object destruction. |
| 60 Clipboard::ObjectMap objects_; | 65 Clipboard::ObjectMap objects_; |
| 61 Clipboard* clipboard_; | 66 Clipboard* clipboard_; |
| 62 | 67 |
| 63 private: | 68 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); | 69 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); |
| 65 }; | 70 }; |
| 66 | 71 |
| 67 #endif // SCOPED_CLIPBOARD_WRITER_H_ | 72 #endif // SCOPED_CLIPBOARD_WRITER_H_ |
| 68 | 73 |
| OLD | NEW |