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

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: Fix compile error 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
25 // The DragDropHelper object on Windows supports images with width upto 300 px.
26 // Images with widths more than that are clipped.
27 const int kMaxDragImageWidth = 300;
28
24 static void SetDragImageOnDataObject(HBITMAP hbitmap, 29 static void SetDragImageOnDataObject(HBITMAP hbitmap,
25 const gfx::Size& size_in_pixels, 30 const gfx::Size& size_in_pixels,
26 const gfx::Vector2d& cursor_offset, 31 const gfx::Vector2d& cursor_offset,
27 IDataObject* data_object) { 32 IDataObject* data_object) {
28 base::win::ScopedComPtr<IDragSourceHelper> helper; 33 base::win::ScopedComPtr<IDragSourceHelper> helper;
29 HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, 34 HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER,
30 IID_IDragSourceHelper, helper.ReceiveVoid()); 35 IID_IDragSourceHelper, helper.ReceiveVoid());
31 if (SUCCEEDED(rv)) { 36 if (SUCCEEDED(rv)) {
32 SHDRAGIMAGE sdi; 37 SHDRAGIMAGE sdi;
33 sdi.sizeDragImage = size_in_pixels.ToSIZE(); 38 sdi.sizeDragImage = size_in_pixels.ToSIZE();
39 sdi.sizeDragImage.cx =
40 std::min<int>(kMaxDragImageWidth, sdi.sizeDragImage.cx);
ananta 2015/12/01 02:47:07 If the width is more than 300 the bitmap is displa
34 sdi.crColorKey = 0xFFFFFFFF; 41 sdi.crColorKey = 0xFFFFFFFF;
35 sdi.hbmpDragImage = hbitmap; 42 sdi.hbmpDragImage = hbitmap;
36 sdi.ptOffset = gfx::PointAtOffsetFromOrigin(cursor_offset).ToPOINT(); 43 gfx::Point point_at_offset_in_pixels = gfx::win::DIPToScreenPoint(
44 gfx::PointAtOffsetFromOrigin(cursor_offset));
45 sdi.ptOffset = point_at_offset_in_pixels.ToPOINT();
37 helper->InitializeFromBitmap(&sdi, data_object); 46 helper->InitializeFromBitmap(&sdi, data_object);
38 } 47 }
39 } 48 }
40 49
41 // Blit the contents of the canvas to a new HBITMAP. It is the caller's 50 // Blit the contents of the canvas to a new HBITMAP. It is the caller's
42 // responsibility to release the |bits| buffer. 51 // responsibility to release the |bits| buffer.
43 static HBITMAP CreateHBITMAPFromSkBitmap(const SkBitmap& sk_bitmap) { 52 static HBITMAP CreateHBITMAPFromSkBitmap(const SkBitmap& sk_bitmap) {
44 base::win::ScopedGetDC screen_dc(NULL); 53 base::win::ScopedGetDC screen_dc(NULL);
45 BITMAPINFOHEADER header; 54 BITMAPINFOHEADER header;
46 gfx::CreateBitmapHeader(sk_bitmap.width(), sk_bitmap.height(), &header); 55 gfx::CreateBitmapHeader(sk_bitmap.width(), sk_bitmap.height(), &header);
(...skipping 29 matching lines...) Expand all
76 } 85 }
77 86
78 // TODO: the above code is used in non-Ash, while below is used in Ash. If we 87 // 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 88 // 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 89 // as it stands getting this information in ui/base would be a layering
81 // violation. 90 // violation.
82 data_object->provider().SetDragImage(image_skia, cursor_offset); 91 data_object->provider().SetDragImage(image_skia, cursor_offset);
83 } 92 }
84 93
85 } // namespace drag_utils 94 } // 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