| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/webclipboard_impl.h" | 5 #include "webkit/glue/webclipboard_impl.h" |
| 6 | 6 |
| 7 #include "base/clipboard.h" | 7 #include "base/clipboard.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 markup.append("\""); | 48 markup.append("\""); |
| 49 if (!title.isEmpty()) { | 49 if (!title.isEmpty()) { |
| 50 markup.append(" alt=\""); | 50 markup.append(" alt=\""); |
| 51 markup.append(EscapeForHTML(UTF16ToUTF8(title))); | 51 markup.append(EscapeForHTML(UTF16ToUTF8(title))); |
| 52 markup.append("\""); | 52 markup.append("\""); |
| 53 } | 53 } |
| 54 markup.append("/>"); | 54 markup.append("/>"); |
| 55 return markup; | 55 return markup; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool WebClipboardImpl::isFormatAvailable(Format format) { | 58 bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { |
| 59 Clipboard::FormatType format_type; | 59 Clipboard::FormatType format_type; |
| 60 Clipboard::Buffer buffer_type; |
| 60 | 61 |
| 61 switch (format) { | 62 switch (format) { |
| 62 case FormatHTML: | 63 case FormatHTML: |
| 63 format_type = Clipboard::GetHtmlFormatType(); | 64 format_type = Clipboard::GetHtmlFormatType(); |
| 64 break; | 65 break; |
| 65 case FormatSmartPaste: | 66 case FormatSmartPaste: |
| 66 format_type = Clipboard::GetWebKitSmartPasteFormatType(); | 67 format_type = Clipboard::GetWebKitSmartPasteFormatType(); |
| 67 break; | 68 break; |
| 68 case FormatBookmark: | 69 case FormatBookmark: |
| 69 #if defined(OS_WIN) || defined(OS_MACOSX) | 70 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 70 format_type = Clipboard::GetUrlWFormatType(); | 71 format_type = Clipboard::GetUrlWFormatType(); |
| 71 break; | 72 break; |
| 72 #endif | 73 #endif |
| 73 default: | 74 default: |
| 74 NOTREACHED(); | 75 NOTREACHED(); |
| 75 return false; | 76 return false; |
| 76 } | 77 } |
| 77 | 78 |
| 78 return ClipboardIsFormatAvailable(format_type); | 79 if (!ConvertBufferType(buffer, &buffer_type)) |
| 80 return false; |
| 81 |
| 82 return ClipboardIsFormatAvailable(format_type, buffer_type); |
| 79 } | 83 } |
| 80 | 84 |
| 81 WebString WebClipboardImpl::readPlainText() { | 85 WebString WebClipboardImpl::readPlainText(Buffer buffer) { |
| 82 if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextWFormatType())) { | 86 Clipboard::Buffer buffer_type; |
| 87 if (!ConvertBufferType(buffer, &buffer_type)) |
| 88 return WebString(); |
| 89 |
| 90 if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextWFormatType(), |
| 91 buffer_type)) { |
| 83 string16 text; | 92 string16 text; |
| 84 ClipboardReadText(&text); | 93 ClipboardReadText(buffer_type, &text); |
| 85 if (!text.empty()) | 94 if (!text.empty()) |
| 86 return text; | 95 return text; |
| 87 } | 96 } |
| 88 | 97 |
| 89 if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextFormatType())) { | 98 if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextFormatType(), |
| 99 buffer_type)) { |
| 90 std::string text; | 100 std::string text; |
| 91 ClipboardReadAsciiText(&text); | 101 ClipboardReadAsciiText(buffer_type, &text); |
| 92 if (!text.empty()) | 102 if (!text.empty()) |
| 93 return ASCIIToUTF16(text); | 103 return ASCIIToUTF16(text); |
| 94 } | 104 } |
| 95 | 105 |
| 96 return WebString(); | 106 return WebString(); |
| 97 } | 107 } |
| 98 | 108 |
| 99 WebString WebClipboardImpl::readHTML(WebURL* source_url) { | 109 WebString WebClipboardImpl::readHTML(Buffer buffer, WebURL* source_url) { |
| 110 Clipboard::Buffer buffer_type; |
| 111 if (!ConvertBufferType(buffer, &buffer_type)) |
| 112 return WebString(); |
| 113 |
| 100 string16 html_stdstr; | 114 string16 html_stdstr; |
| 101 GURL gurl; | 115 GURL gurl; |
| 102 ClipboardReadHTML(&html_stdstr, &gurl); | 116 ClipboardReadHTML(buffer_type, &html_stdstr, &gurl); |
| 103 *source_url = gurl; | 117 *source_url = gurl; |
| 104 return html_stdstr; | 118 return html_stdstr; |
| 105 } | 119 } |
| 106 | 120 |
| 107 void WebClipboardImpl::writeHTML( | 121 void WebClipboardImpl::writeHTML( |
| 108 const WebString& html_text, const WebURL& source_url, | 122 const WebString& html_text, const WebURL& source_url, |
| 109 const WebString& plain_text, bool write_smart_paste) { | 123 const WebString& plain_text, bool write_smart_paste) { |
| 110 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); | 124 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); |
| 111 scw.WriteHTML(html_text, source_url.spec()); | 125 scw.WriteHTML(html_text, source_url.spec()); |
| 112 scw.WriteText(plain_text); | 126 scw.WriteText(plain_text); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 137 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); | 151 scw.WriteBitmapFromPixels(bitmap.getPixels(), image.size()); |
| 138 } | 152 } |
| 139 | 153 |
| 140 if (!url.isEmpty()) { | 154 if (!url.isEmpty()) { |
| 141 scw.WriteBookmark(title, url.spec()); | 155 scw.WriteBookmark(title, url.spec()); |
| 142 scw.WriteHTML(UTF8ToUTF16(URLToImageMarkup(url, title)), ""); | 156 scw.WriteHTML(UTF8ToUTF16(URLToImageMarkup(url, title)), ""); |
| 143 scw.WriteText(UTF8ToUTF16(url.spec())); | 157 scw.WriteText(UTF8ToUTF16(url.spec())); |
| 144 } | 158 } |
| 145 } | 159 } |
| 146 | 160 |
| 161 bool WebClipboardImpl::ConvertBufferType(Buffer buffer, |
| 162 Clipboard::Buffer* result) { |
| 163 switch (buffer) { |
| 164 case BufferStandard: |
| 165 *result = Clipboard::BUFFER_STANDARD; |
| 166 break; |
| 167 case BufferSelection: |
| 168 #if defined(OS_LINUX) |
| 169 *result = Clipboard::BUFFER_SELECTION; |
| 170 break; |
| 171 #endif |
| 172 default: |
| 173 NOTREACHED(); |
| 174 return false; |
| 175 } |
| 176 return true; |
| 177 } |
| 178 |
| 147 } // namespace webkit_glue | 179 } // namespace webkit_glue |
| OLD | NEW |