| 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/tools/test_shell/mock_webclipboard_impl.h" | 5 #include "webkit/tools/test_shell/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/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCommon.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCommon.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.
h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.
h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 17 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
| 18 #include "webkit/glue/webclipboard_impl.h" | 18 #include "webkit/glue/webclipboard_impl.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
| 20 #include "webkit/support/webkit_support_gfx.h" | 20 #include "webkit/support/webkit_support_gfx.h" |
| 21 | 21 |
| 22 #if WEBKIT_USING_CG | |
| 23 #include <ApplicationServices/ApplicationServices.h> | |
| 24 #include <CoreFoundation/CoreFoundation.h> | |
| 25 #endif | |
| 26 | |
| 27 using WebKit::WebDragData; | 22 using WebKit::WebDragData; |
| 28 using WebKit::WebString; | 23 using WebKit::WebString; |
| 29 using WebKit::WebURL; | 24 using WebKit::WebURL; |
| 30 using WebKit::WebVector; | 25 using WebKit::WebVector; |
| 31 | 26 |
| 32 MockWebClipboardImpl::MockWebClipboardImpl() { | 27 MockWebClipboardImpl::MockWebClipboardImpl() { |
| 33 } | 28 } |
| 34 | 29 |
| 35 MockWebClipboardImpl::~MockWebClipboardImpl() { | 30 MockWebClipboardImpl::~MockWebClipboardImpl() { |
| 36 } | 31 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 *fragmentEnd = static_cast<unsigned>(m_htmlText.length()); | 96 *fragmentEnd = static_cast<unsigned>(m_htmlText.length()); |
| 102 return m_htmlText; | 97 return m_htmlText; |
| 103 } | 98 } |
| 104 | 99 |
| 105 WebKit::WebData MockWebClipboardImpl::readImage( | 100 WebKit::WebData MockWebClipboardImpl::readImage( |
| 106 WebKit::WebClipboard::Buffer buffer) { | 101 WebKit::WebClipboard::Buffer buffer) { |
| 107 std::string data; | 102 std::string data; |
| 108 std::vector<unsigned char> encoded_image; | 103 std::vector<unsigned char> encoded_image; |
| 109 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that | 104 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that |
| 110 // for endianess reasons, it will be BGRA8888 on Windows. | 105 // for endianess reasons, it will be BGRA8888 on Windows. |
| 111 #if WEBKIT_USING_SKIA | |
| 112 const SkBitmap& bitmap = m_image.getSkBitmap(); | 106 const SkBitmap& bitmap = m_image.getSkBitmap(); |
| 113 SkAutoLockPixels lock(bitmap); | 107 SkAutoLockPixels lock(bitmap); |
| 114 webkit_support::EncodeBGRAPNG(static_cast<unsigned char*>(bitmap.getPixels()), | 108 webkit_support::EncodeBGRAPNG(static_cast<unsigned char*>(bitmap.getPixels()), |
| 115 bitmap.width(), | 109 bitmap.width(), |
| 116 bitmap.height(), | 110 bitmap.height(), |
| 117 bitmap.rowBytes(), | 111 bitmap.rowBytes(), |
| 118 false, | 112 false, |
| 119 &encoded_image); | 113 &encoded_image); |
| 120 #elif WEBKIT_USING_CG | |
| 121 CGImageRef image = m_image.getCGImageRef(); | |
| 122 CFDataRef image_data_ref = | |
| 123 CGDataProviderCopyData(CGImageGetDataProvider(image)); | |
| 124 webkit_support::EncodeBGRAPNG(CFDataGetBytePtr(image_data_ref), | |
| 125 CGImageGetWidth(image), | |
| 126 CGImageGetHeight(image), | |
| 127 CGImageGetBytesPerRow(image), | |
| 128 false, | |
| 129 &encoded_image); | |
| 130 CFRelease(image_data_ref); | |
| 131 #endif | |
| 132 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), | 114 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), |
| 133 encoded_image.size()); | 115 encoded_image.size()); |
| 134 return data; | 116 return data; |
| 135 } | 117 } |
| 136 | 118 |
| 137 WebKit::WebString MockWebClipboardImpl::readCustomData( | 119 WebKit::WebString MockWebClipboardImpl::readCustomData( |
| 138 WebKit::WebClipboard::Buffer buffer, | 120 WebKit::WebClipboard::Buffer buffer, |
| 139 const WebKit::WebString& type) { | 121 const WebKit::WebString& type) { |
| 140 std::map<string16, string16>::const_iterator it = m_customData.find(type); | 122 std::map<string16, string16>::const_iterator it = m_customData.find(type); |
| 141 if (it != m_customData.end()) | 123 if (it != m_customData.end()) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 188 } |
| 207 } | 189 } |
| 208 | 190 |
| 209 void MockWebClipboardImpl::clear() { | 191 void MockWebClipboardImpl::clear() { |
| 210 m_plainText = WebString(); | 192 m_plainText = WebString(); |
| 211 m_htmlText = WebString(); | 193 m_htmlText = WebString(); |
| 212 m_image.reset(); | 194 m_image.reset(); |
| 213 m_customData.clear(); | 195 m_customData.clear(); |
| 214 m_writeSmartPaste = false; | 196 m_writeSmartPaste = false; |
| 215 } | 197 } |
| OLD | NEW |