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 "ui/base/dragdrop/drag_utils.h" | 5 #include "ui/base/dragdrop/drag_utils.h" |
6 | 6 |
7 #include <objidl.h> | 7 #include <objidl.h> |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include "base/win/scoped_comptr.h" | 12 #include "base/win/scoped_comptr.h" |
13 #include "base/win/scoped_hdc.h" | 13 #include "base/win/scoped_hdc.h" |
| 14 #include "skia/ext/skia_utils_win.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "ui/base/dragdrop/os_exchange_data.h" | 16 #include "ui/base/dragdrop/os_exchange_data.h" |
16 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 17 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
17 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
18 #include "ui/gfx/gdi_util.h" | 19 #include "ui/gfx/gdi_util.h" |
19 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
20 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
21 #include "ui/gfx/skbitmap_operations.h" | 22 #include "ui/gfx/skbitmap_operations.h" |
22 | 23 |
23 namespace drag_utils { | 24 namespace drag_utils { |
(...skipping 13 matching lines...) Expand all Loading... |
37 sdi.ptOffset = gfx::PointAtOffsetFromOrigin(cursor_offset).ToPOINT(); | 38 sdi.ptOffset = gfx::PointAtOffsetFromOrigin(cursor_offset).ToPOINT(); |
38 helper->InitializeFromBitmap(&sdi, data_object); | 39 helper->InitializeFromBitmap(&sdi, data_object); |
39 } | 40 } |
40 } | 41 } |
41 | 42 |
42 // Blit the contents of the canvas to a new HBITMAP. It is the caller's | 43 // Blit the contents of the canvas to a new HBITMAP. It is the caller's |
43 // responsibility to release the |bits| buffer. | 44 // responsibility to release the |bits| buffer. |
44 static HBITMAP CreateHBITMAPFromSkBitmap(const SkBitmap& sk_bitmap) { | 45 static HBITMAP CreateHBITMAPFromSkBitmap(const SkBitmap& sk_bitmap) { |
45 base::win::ScopedGetDC screen_dc(NULL); | 46 base::win::ScopedGetDC screen_dc(NULL); |
46 BITMAPINFOHEADER header; | 47 BITMAPINFOHEADER header; |
47 gfx::CreateBitmapHeader(sk_bitmap.width(), sk_bitmap.height(), &header); | 48 skia::CreateBitmapHeader(sk_bitmap.width(), sk_bitmap.height(), &header); |
48 void* bits; | 49 void* bits; |
49 HBITMAP bitmap = | 50 HBITMAP bitmap = |
50 CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header), | 51 CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header), |
51 DIB_RGB_COLORS, &bits, NULL, 0); | 52 DIB_RGB_COLORS, &bits, NULL, 0); |
52 if (!bitmap || !bits) | 53 if (!bitmap || !bits) |
53 return NULL; | 54 return NULL; |
54 DCHECK_EQ(sk_bitmap.rowBytes(), static_cast<size_t>(sk_bitmap.width() * 4)); | 55 DCHECK_EQ(sk_bitmap.rowBytes(), static_cast<size_t>(sk_bitmap.width() * 4)); |
55 SkAutoLockPixels lock(sk_bitmap); | 56 SkAutoLockPixels lock(sk_bitmap); |
56 memcpy( | 57 memcpy( |
57 bits, sk_bitmap.getPixels(), sk_bitmap.height() * sk_bitmap.rowBytes()); | 58 bits, sk_bitmap.getPixels(), sk_bitmap.height() * sk_bitmap.rowBytes()); |
(...skipping 19 matching lines...) Expand all Loading... |
77 } | 78 } |
78 | 79 |
79 // TODO: the above code is used in non-Ash, while below is used in Ash. If we | 80 // TODO: the above code is used in non-Ash, while below is used in Ash. If we |
80 // could figure this context out then we wouldn't do unnecessary work. However | 81 // could figure this context out then we wouldn't do unnecessary work. However |
81 // as it stands getting this information in ui/base would be a layering | 82 // as it stands getting this information in ui/base would be a layering |
82 // violation. | 83 // violation. |
83 data_object->provider().SetDragImage(image_skia, cursor_offset); | 84 data_object->provider().SetDragImage(image_skia, cursor_offset); |
84 } | 85 } |
85 | 86 |
86 } // namespace drag_utils | 87 } // namespace drag_utils |
OLD | NEW |