license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 5 | #ifndef BASE_CLIPBOARD_H_ |
| 6 | #define BASE_CLIPBOARD_H_ |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/basictypes.h" |
| 12 | #include "base/gfx/size.h" |
| 13 | #include "base/shared_memory.h" |
| 14 | |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 15 | #if defined(OS_MACOSX) |
| 16 | @class NSString; |
| 17 | #endif |
| 18 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 19 | class Clipboard { |
| 20 | public: |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 21 | #if defined(OS_WIN) |
| 22 | typedef unsigned int FormatType; |
| 23 | #elif defined(OS_MACOSX) |
| 24 | typedef NSString *FormatType; |
| 25 | #endif |
| 26 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 27 | Clipboard(); |
| 28 | ~Clipboard(); |
| 29 | |
| 30 | // Clears the clipboard. It is usually a good idea to clear the clipboard |
| 31 | // before writing content to the clipboard. |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 32 | void Clear(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 33 | |
| 34 | // Adds UNICODE and ASCII text to the clipboard. |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 35 | void WriteText(const std::wstring& text); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 36 | |
| 37 | // Adds HTML to the clipboard. The url parameter is optional, but especially |
| 38 | // useful if the HTML fragment contains relative links |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 39 | void WriteHTML(const std::wstring& markup, const std::string& src_url); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 40 | |
| 41 | // Adds a bookmark to the clipboard |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 42 | void WriteBookmark(const std::wstring& title, const std::string& url); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 43 | |
| 44 | // Adds both a bookmark and an HTML hyperlink to the clipboard. It is a |
| 45 | // convenience wrapper around WriteBookmark and WriteHTML. |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 46 | void WriteHyperlink(const std::wstring& title, const std::string& url); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 47 | |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 48 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 49 | // Adds a bitmap to the clipboard |
| 50 | // This is the slowest way to copy a bitmap to the clipboard as we must first |
| 51 | // memcpy the pixels into GDI and the blit the bitmap to the clipboard. |
| 52 | // Pixel format is assumed to be 32-bit BI_RGB. |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 53 | void WriteBitmap(const void* pixels, const gfx::Size& size); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 54 | |
| 55 | // Adds a bitmap to the clipboard |
| 56 | // This function requires read and write access to the bitmap, but does not |
| 57 | // actually modify the shared memory region. |
| 58 | // Pixel format is assumed to be 32-bit BI_RGB. |
| 59 | void WriteBitmapFromSharedMemory(const SharedMemory& bitmap, |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 60 | const gfx::Size& size); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 61 | |
| 62 | // Adds a bitmap to the clipboard |
| 63 | // This is the fastest way to copy a bitmap to the clipboard. The HBITMAP |
| 64 | // may either be device-dependent or device-independent. |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 65 | void WriteBitmapFromHandle(HBITMAP hbitmap, const gfx::Size& size); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 66 | |
| 67 | // Used by WebKit to determine whether WebKit wrote the clipboard last |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 68 | void WriteWebSmartPaste(); |
| 69 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 70 | |
| 71 | // Adds a file or group of files to the clipboard. |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 72 | void WriteFile(const std::wstring& file); |
| 73 | void WriteFiles(const std::vector<std::wstring>& files); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 74 | |
| 75 | // Tests whether the clipboard contains a certain format |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 76 | bool IsFormatAvailable(FormatType format) const; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 77 | |
| 78 | // Reads UNICODE text from the clipboard, if available. |
| 79 | void ReadText(std::wstring* result) const; |
| 80 | |
| 81 | // Reads ASCII text from the clipboard, if available. |
| 82 | void ReadAsciiText(std::string* result) const; |
| 83 | |
| 84 | // Reads HTML from the clipboard, if available. |
| 85 | void ReadHTML(std::wstring* markup, std::string* src_url) const; |
| 86 | |
| 87 | // Reads a bookmark from the clipboard, if available. |
| 88 | void ReadBookmark(std::wstring* title, std::string* url) const; |
| 89 | |
| 90 | // Reads a file or group of files from the clipboard, if available, into the |
ericroman@google.com | dbff4f5 | 2008-08-19 01:00:38 +0900 | [diff] [blame] | 91 | // out parameter. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 92 | void ReadFile(std::wstring* file) const; |
| 93 | void ReadFiles(std::vector<std::wstring>* files) const; |
| 94 | |
| 95 | private: |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 96 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 97 | static void MarkupToHTMLClipboardFormat(const std::wstring& markup, |
| 98 | const std::string& src_url, |
| 99 | std::string* html_fragment); |
| 100 | |
| 101 | static void ParseHTMLClipboardFormat(const std::string& html_fragment, |
| 102 | std::wstring* markup, |
| 103 | std::string* src_url); |
| 104 | |
| 105 | static void ParseBookmarkClipboardFormat(const std::wstring& bookmark, |
| 106 | std::wstring* title, |
| 107 | std::string* url); |
| 108 | |
| 109 | HWND clipboard_owner_; |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 110 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 111 | |
| 112 | DISALLOW_EVIL_CONSTRUCTORS(Clipboard); |
| 113 | }; |
| 114 | |
avi@google.com | ccb3d9f | 2008-08-13 01:25:23 +0900 | [diff] [blame] | 115 | #endif // BASE_CLIPBOARD_H_ |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 116 | |