Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: ui/base/dragdrop/drag_utils_win.cc

Issue 1475263002: Ensure that the drag image during drag drop operations on Windows is of the correct scale. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
11 #include "base/win/scoped_comptr.h" 11 #include "base/win/scoped_comptr.h"
12 #include "base/win/scoped_hdc.h" 12 #include "base/win/scoped_hdc.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/base/dragdrop/os_exchange_data.h" 14 #include "ui/base/dragdrop/os_exchange_data.h"
15 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" 15 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
16 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/gdi_util.h" 17 #include "ui/gfx/gdi_util.h"
18 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
19 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/skbitmap_operations.h" 20 #include "ui/gfx/skbitmap_operations.h"
21 #include "ui/gfx/win/dpi.h"
21 22
22 namespace drag_utils { 23 namespace drag_utils {
23 24
24 static void SetDragImageOnDataObject(HBITMAP hbitmap, 25 static void SetDragImageOnDataObject(HBITMAP hbitmap,
25 const gfx::Size& size_in_pixels, 26 const gfx::Size& size_in_pixels,
26 const gfx::Vector2d& cursor_offset, 27 const gfx::Vector2d& cursor_offset,
27 IDataObject* data_object) { 28 IDataObject* data_object) {
28 base::win::ScopedComPtr<IDragSourceHelper> helper; 29 base::win::ScopedComPtr<IDragSourceHelper> helper;
29 HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, 30 HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER,
30 IID_IDragSourceHelper, helper.ReceiveVoid()); 31 IID_IDragSourceHelper, helper.ReceiveVoid());
(...skipping 23 matching lines...) Expand all
54 SkAutoLockPixels lock(sk_bitmap); 55 SkAutoLockPixels lock(sk_bitmap);
55 memcpy( 56 memcpy(
56 bits, sk_bitmap.getPixels(), sk_bitmap.height() * sk_bitmap.rowBytes()); 57 bits, sk_bitmap.getPixels(), sk_bitmap.height() * sk_bitmap.rowBytes());
57 return bitmap; 58 return bitmap;
58 } 59 }
59 60
60 void SetDragImageOnDataObject(const gfx::ImageSkia& image_skia, 61 void SetDragImageOnDataObject(const gfx::ImageSkia& image_skia,
61 const gfx::Vector2d& cursor_offset, 62 const gfx::Vector2d& cursor_offset,
62 ui::OSExchangeData* data_object) { 63 ui::OSExchangeData* data_object) {
63 DCHECK(data_object && !image_skia.size().IsEmpty()); 64 DCHECK(data_object && !image_skia.size().IsEmpty());
65
66 // Attempt to find a bitmap matching the current dpi scale, failing which we
67 // fallback to the 1x bitmap.
68 SkBitmap skia_bitmap;
69 if (image_skia.HasRepresentation(gfx::GetDPIScale())) {
sky 2015/11/25 23:32:54 If it doesn't have a rep for the specified dpi, sh
ananta 2015/11/25 23:37:14 My bad. We should just use GetRepresentation which
70 gfx::ImageSkiaRep image_rep_for_scale = image_skia.GetRepresentation(
71 gfx::GetDPIScale());
72 skia_bitmap = image_rep_for_scale.sk_bitmap();
73 } else {
74 skia_bitmap = *image_skia.bitmap();
75 }
76
64 // InitializeFromBitmap() doesn't expect an alpha channel and is confused 77 // InitializeFromBitmap() doesn't expect an alpha channel and is confused
65 // by premultiplied colors, so unpremultiply the bitmap. 78 // by premultiplied colors, so unpremultiply the bitmap.
66 // SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap. 79 // SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap.
67 HBITMAP bitmap = CreateHBITMAPFromSkBitmap( 80 HBITMAP bitmap = CreateHBITMAPFromSkBitmap(SkBitmapOperations::UnPreMultiply(
68 SkBitmapOperations::UnPreMultiply(*image_skia.bitmap())); 81 skia_bitmap));
69 if (bitmap) { 82 if (bitmap) {
70 // Attach 'bitmap' to the data_object. 83 // Attach 'bitmap' to the data_object.
71 SetDragImageOnDataObject( 84 SetDragImageOnDataObject(
72 bitmap, 85 bitmap,
73 gfx::Size(image_skia.bitmap()->width(), image_skia.bitmap()->height()), 86 gfx::Size(image_skia.bitmap()->width(), image_skia.bitmap()->height()),
74 cursor_offset, 87 cursor_offset,
75 ui::OSExchangeDataProviderWin::GetIDataObject(*data_object)); 88 ui::OSExchangeDataProviderWin::GetIDataObject(*data_object));
76 } 89 }
77 90
78 // TODO: the above code is used in non-Ash, while below is used in Ash. If we 91 // TODO: the above code is used in non-Ash, while below is used in Ash. If we
79 // could figure this context out then we wouldn't do unnecessary work. However 92 // could figure this context out then we wouldn't do unnecessary work. However
80 // as it stands getting this information in ui/base would be a layering 93 // as it stands getting this information in ui/base would be a layering
81 // violation. 94 // violation.
82 data_object->provider().SetDragImage(image_skia, cursor_offset); 95 data_object->provider().SetDragImage(image_skia, cursor_offset);
83 } 96 }
84 97
85 } // namespace drag_utils 98 } // namespace drag_utils
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698