| 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 "WebImage.h" | 7 #include "WebImage.h" |
| 8 #include "WebString.h" | 8 #include "WebString.h" |
| 9 #include "WebURL.h" | 9 #include "WebURL.h" |
| 10 | 10 |
| 11 #include "base/clipboard.h" | 11 #include "base/clipboard.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/string16.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 16 #include "webkit/glue/scoped_clipboard_writer_glue.h" | 17 #include "webkit/glue/scoped_clipboard_writer_glue.h" |
| 17 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
| 18 | 19 |
| 19 using WebKit::WebClipboard; | 20 using WebKit::WebClipboard; |
| 20 using WebKit::WebImage; | 21 using WebKit::WebImage; |
| 21 using WebKit::WebString; | 22 using WebKit::WebString; |
| 22 using WebKit::WebURL; | 23 using WebKit::WebURL; |
| 23 | 24 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 default: | 66 default: |
| 66 NOTREACHED(); | 67 NOTREACHED(); |
| 67 return false; | 68 return false; |
| 68 } | 69 } |
| 69 | 70 |
| 70 return ClipboardIsFormatAvailable(format_type); | 71 return ClipboardIsFormatAvailable(format_type); |
| 71 } | 72 } |
| 72 | 73 |
| 73 WebString WebClipboardImpl::readPlainText() { | 74 WebString WebClipboardImpl::readPlainText() { |
| 74 if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextWFormatType())) { | 75 if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextWFormatType())) { |
| 75 std::wstring text; | 76 string16 text; |
| 76 ClipboardReadText(&text); | 77 ClipboardReadText(&text); |
| 77 if (!text.empty()) | 78 if (!text.empty()) |
| 78 return WideToUTF16Hack(text); | 79 return text; |
| 79 } | 80 } |
| 80 | 81 |
| 81 if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextFormatType())) { | 82 if (ClipboardIsFormatAvailable(Clipboard::GetPlainTextFormatType())) { |
| 82 std::string text; | 83 std::string text; |
| 83 ClipboardReadAsciiText(&text); | 84 ClipboardReadAsciiText(&text); |
| 84 if (!text.empty()) | 85 if (!text.empty()) |
| 85 return UTF8ToUTF16(text); | 86 return ASCIIToUTF16(text); |
| 86 } | 87 } |
| 87 | 88 |
| 88 return WebString(); | 89 return WebString(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 WebString WebClipboardImpl::readHTML(WebURL* source_url) { | 92 WebString WebClipboardImpl::readHTML(WebURL* source_url) { |
| 92 std::wstring html_stdstr; | 93 string16 html_stdstr; |
| 93 GURL gurl; | 94 GURL gurl; |
| 94 ClipboardReadHTML(&html_stdstr, &gurl); | 95 ClipboardReadHTML(&html_stdstr, &gurl); |
| 95 *source_url = gurl; | 96 *source_url = gurl; |
| 96 return WideToUTF16Hack(html_stdstr); | 97 return html_stdstr; |
| 97 } | 98 } |
| 98 | 99 |
| 99 void WebClipboardImpl::writeHTML( | 100 void WebClipboardImpl::writeHTML( |
| 100 const WebString& html_text, const WebURL& source_url, | 101 const WebString& html_text, const WebURL& source_url, |
| 101 const WebString& plain_text, bool write_smart_paste) { | 102 const WebString& plain_text, bool write_smart_paste) { |
| 102 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); | 103 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); |
| 103 scw.WriteHTML(UTF16ToWideHack(html_text), source_url.spec()); | 104 scw.WriteHTML(html_text, source_url.spec()); |
| 104 scw.WriteText(UTF16ToWideHack(plain_text)); | 105 scw.WriteText(plain_text); |
| 105 | 106 |
| 106 if (write_smart_paste) | 107 if (write_smart_paste) |
| 107 scw.WriteWebSmartPaste(); | 108 scw.WriteWebSmartPaste(); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { | 111 void WebClipboardImpl::writeURL(const WebURL& url, const WebString& title) { |
| 111 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); | 112 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); |
| 112 | 113 |
| 113 scw.WriteBookmark(UTF16ToWideHack(title), url.spec()); | 114 scw.WriteBookmark(title, url.spec()); |
| 114 scw.WriteHTML(UTF8ToWide(URLToMarkup(url, title)), ""); | 115 scw.WriteHTML(UTF8ToUTF16(URLToMarkup(url, title)), ""); |
| 115 scw.WriteText(UTF8ToWide(url.spec())); | 116 scw.WriteText(UTF8ToUTF16(url.spec())); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void WebClipboardImpl::writeImage( | 119 void WebClipboardImpl::writeImage( |
| 119 const WebImage& image, const WebURL& url, const WebString& title) { | 120 const WebImage& image, const WebURL& url, const WebString& title) { |
| 120 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); | 121 ScopedClipboardWriterGlue scw(ClipboardGetClipboard()); |
| 121 | 122 |
| 122 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
| 123 if (!image.isNull()) | 124 if (!image.isNull()) |
| 124 scw.WriteBitmapFromPixels(image.pixels(), image.size()); | 125 scw.WriteBitmapFromPixels(image.pixels(), image.size()); |
| 125 #endif | 126 #endif |
| 126 | 127 |
| 127 if (!url.isEmpty()) { | 128 if (!url.isEmpty()) { |
| 128 scw.WriteBookmark(UTF16ToWideHack(title), url.spec()); | 129 scw.WriteBookmark(title, url.spec()); |
| 129 scw.WriteHTML(UTF8ToWide(URLToImageMarkup(url, title)), ""); | 130 scw.WriteHTML(UTF8ToUTF16(URLToImageMarkup(url, title)), ""); |
| 130 scw.WriteText(UTF8ToWide(url.spec())); | 131 scw.WriteText(UTF8ToUTF16(url.spec())); |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 | 134 |
| 134 } // namespace webkit_glue | 135 } // namespace webkit_glue |
| OLD | NEW |