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 #include "webkit/support/mock_webclipboard_impl.h" | 5 #include "webkit/support/mock_webclipboard_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "third_party/WebKit/public/platform/WebCommon.h" | 13 #include "third_party/WebKit/public/platform/WebCommon.h" |
14 #include "third_party/WebKit/public/platform/WebDragData.h" | 14 #include "third_party/WebKit/public/platform/WebDragData.h" |
15 #include "third_party/WebKit/public/platform/WebImage.h" | 15 #include "third_party/WebKit/public/platform/WebImage.h" |
16 #include "third_party/WebKit/public/platform/WebURL.h" | 16 #include "third_party/WebKit/public/platform/WebURL.h" |
17 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
| 18 #include "ui/gfx/codec/png_codec.h" |
| 19 #include "ui/gfx/size.h" |
18 #include "webkit/glue/webkit_glue.h" | 20 #include "webkit/glue/webkit_glue.h" |
19 #include "webkit/renderer/clipboard_utils.h" | 21 #include "webkit/renderer/clipboard_utils.h" |
20 #include "webkit/support/webkit_support_gfx.h" | |
21 | 22 |
22 using WebKit::WebDragData; | 23 using WebKit::WebDragData; |
23 using WebKit::WebString; | 24 using WebKit::WebString; |
24 using WebKit::WebURL; | 25 using WebKit::WebURL; |
25 using WebKit::WebVector; | 26 using WebKit::WebVector; |
26 | 27 |
27 MockWebClipboardImpl::MockWebClipboardImpl() { | 28 MockWebClipboardImpl::MockWebClipboardImpl() { |
28 } | 29 } |
29 | 30 |
30 MockWebClipboardImpl::~MockWebClipboardImpl() { | 31 MockWebClipboardImpl::~MockWebClipboardImpl() { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 100 } |
100 | 101 |
101 WebKit::WebData MockWebClipboardImpl::readImage( | 102 WebKit::WebData MockWebClipboardImpl::readImage( |
102 WebKit::WebClipboard::Buffer buffer) { | 103 WebKit::WebClipboard::Buffer buffer) { |
103 std::string data; | 104 std::string data; |
104 std::vector<unsigned char> encoded_image; | 105 std::vector<unsigned char> encoded_image; |
105 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that | 106 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that |
106 // for endianess reasons, it will be BGRA8888 on Windows. | 107 // for endianess reasons, it will be BGRA8888 on Windows. |
107 const SkBitmap& bitmap = m_image.getSkBitmap(); | 108 const SkBitmap& bitmap = m_image.getSkBitmap(); |
108 SkAutoLockPixels lock(bitmap); | 109 SkAutoLockPixels lock(bitmap); |
| 110 gfx::PNGCodec::Encode(static_cast<unsigned char*>(bitmap.getPixels()), |
109 #if defined(OS_ANDROID) | 111 #if defined(OS_ANDROID) |
110 webkit_support::EncodeRGBAPNG(static_cast<unsigned char*>(bitmap.getPixels()), | 112 gfx::PNGCodec::FORMAT_RGBA, |
111 bitmap.width(), | |
112 bitmap.height(), | |
113 bitmap.rowBytes(), | |
114 &encoded_image); | |
115 #else | 113 #else |
116 webkit_support::EncodeBGRAPNG(static_cast<unsigned char*>(bitmap.getPixels()), | 114 gfx::PNGCodec::FORMAT_BGRA, |
117 bitmap.width(), | |
118 bitmap.height(), | |
119 bitmap.rowBytes(), | |
120 false, | |
121 &encoded_image); | |
122 #endif | 115 #endif |
| 116 gfx::Size(bitmap.width(), bitmap.height()), |
| 117 bitmap.rowBytes(), |
| 118 false /* discard_transparency */, |
| 119 std::vector<gfx::PNGCodec::Comment>(), |
| 120 &encoded_image); |
123 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), | 121 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), |
124 encoded_image.size()); | 122 encoded_image.size()); |
125 return data; | 123 return data; |
126 } | 124 } |
127 | 125 |
128 WebKit::WebString MockWebClipboardImpl::readCustomData( | 126 WebKit::WebString MockWebClipboardImpl::readCustomData( |
129 WebKit::WebClipboard::Buffer buffer, | 127 WebKit::WebClipboard::Buffer buffer, |
130 const WebKit::WebString& type) { | 128 const WebKit::WebString& type) { |
131 std::map<base::string16, base::string16>::const_iterator it = | 129 std::map<base::string16, base::string16>::const_iterator it = |
132 m_customData.find(type); | 130 m_customData.find(type); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 195 } |
198 } | 196 } |
199 | 197 |
200 void MockWebClipboardImpl::clear() { | 198 void MockWebClipboardImpl::clear() { |
201 m_plainText = WebString(); | 199 m_plainText = WebString(); |
202 m_htmlText = WebString(); | 200 m_htmlText = WebString(); |
203 m_image.reset(); | 201 m_image.reset(); |
204 m_customData.clear(); | 202 m_customData.clear(); |
205 m_writeSmartPaste = false; | 203 m_writeSmartPaste = false; |
206 } | 204 } |
OLD | NEW |