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/os_exchange_data_provider_win.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
6 | 6 |
| 7 #include <objidl.h> |
| 8 #include <shlobj.h> |
| 9 #include <shobjidl.h> |
7 #include <stdint.h> | 10 #include <stdint.h> |
8 | 11 |
9 #include <algorithm> | 12 #include <algorithm> |
10 #include <iterator> | 13 #include <iterator> |
11 | 14 |
12 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
13 #include "base/i18n/file_util_icu.h" | 16 #include "base/i18n/file_util_icu.h" |
14 #include "base/logging.h" | 17 #include "base/logging.h" |
15 #include "base/macros.h" | 18 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
17 #include "base/pickle.h" | 20 #include "base/pickle.h" |
18 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/win/scoped_comptr.h" |
| 23 #include "base/win/scoped_hdc.h" |
19 #include "base/win/scoped_hglobal.h" | 24 #include "base/win/scoped_hglobal.h" |
20 #include "net/base/filename_util.h" | 25 #include "net/base/filename_util.h" |
| 26 #include "skia/ext/skia_utils_win.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/base/clipboard/clipboard.h" | 28 #include "ui/base/clipboard/clipboard.h" |
22 #include "ui/base/clipboard/clipboard_util_win.h" | 29 #include "ui/base/clipboard/clipboard_util_win.h" |
23 #include "ui/base/dragdrop/file_info.h" | 30 #include "ui/base/dragdrop/file_info.h" |
24 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/gfx/geometry/point.h" |
| 33 #include "ui/gfx/image/image_skia.h" |
| 34 #include "ui/gfx/skbitmap_operations.h" |
25 #include "ui/strings/grit/ui_strings.h" | 35 #include "ui/strings/grit/ui_strings.h" |
26 #include "url/gurl.h" | 36 #include "url/gurl.h" |
27 | 37 |
28 namespace ui { | 38 namespace ui { |
29 | 39 |
30 static const Clipboard::FormatType& GetRendererTaintFormatType() { | 40 static const Clipboard::FormatType& GetRendererTaintFormatType() { |
31 CR_DEFINE_STATIC_LOCAL( | 41 CR_DEFINE_STATIC_LOCAL( |
32 Clipboard::FormatType, | 42 Clipboard::FormatType, |
33 format, | 43 format, |
34 (ui::Clipboard::GetFormatType("chromium/x-renderer-taint"))); | 44 (ui::Clipboard::GetFormatType("chromium/x-renderer-taint"))); |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 auto info = base::MakeUnique<DataObjectImpl::StoredDataInfo>( | 543 auto info = base::MakeUnique<DataObjectImpl::StoredDataInfo>( |
534 Clipboard::GetCFHDropFormatType().ToFormatEtc(), storage); | 544 Clipboard::GetCFHDropFormatType().ToFormatEtc(), storage); |
535 info->downloader = download.downloader; | 545 info->downloader = download.downloader; |
536 data_->contents_.push_back(std::move(info)); | 546 data_->contents_.push_back(std::move(info)); |
537 | 547 |
538 // Adding a download file always enables async mode. | 548 // Adding a download file always enables async mode. |
539 data_->SetAsyncMode(VARIANT_TRUE); | 549 data_->SetAsyncMode(VARIANT_TRUE); |
540 } | 550 } |
541 | 551 |
542 void OSExchangeDataProviderWin::SetDragImage( | 552 void OSExchangeDataProviderWin::SetDragImage( |
543 const gfx::ImageSkia& image, | 553 const gfx::ImageSkia& image_skia, |
544 const gfx::Vector2d& cursor_offset) { | 554 const gfx::Vector2d& cursor_offset) { |
545 drag_image_ = image; | 555 DCHECK(!image_skia.size().IsEmpty()); |
546 drag_image_offset_ = cursor_offset; | 556 |
| 557 // InitializeFromBitmap() doesn't expect an alpha channel and is confused |
| 558 // by premultiplied colors, so unpremultiply the bitmap. |
| 559 SkBitmap unpremul_bitmap = |
| 560 SkBitmapOperations::UnPreMultiply(*image_skia.bitmap()); |
| 561 int width = unpremul_bitmap.width(); |
| 562 int height = unpremul_bitmap.height(); |
| 563 size_t rowbytes = unpremul_bitmap.rowBytes(); |
| 564 DCHECK_EQ(rowbytes, static_cast<size_t>(width) * 4u); |
| 565 |
| 566 void* bits; |
| 567 HBITMAP hbitmap; |
| 568 { |
| 569 BITMAPINFOHEADER header; |
| 570 skia::CreateBitmapHeader(width, height, &header); |
| 571 |
| 572 base::win::ScopedGetDC screen_dc(NULL); |
| 573 // By giving a null hSection, the |bits| will be destroyed when the |
| 574 // |hbitmap| is destroyed. |
| 575 hbitmap = |
| 576 CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header), |
| 577 DIB_RGB_COLORS, &bits, NULL, 0); |
| 578 } |
| 579 if (!hbitmap) |
| 580 return; |
| 581 |
| 582 { |
| 583 SkAutoLockPixels lock(unpremul_bitmap); |
| 584 memcpy(bits, unpremul_bitmap.getPixels(), height * rowbytes); |
| 585 } |
| 586 |
| 587 base::win::ScopedComPtr<IDragSourceHelper> helper; |
| 588 HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, |
| 589 IID_IDragSourceHelper, helper.ReceiveVoid()); |
| 590 if (!SUCCEEDED(rv)) |
| 591 return; |
| 592 |
| 593 // InitializeFromBitmap() takes ownership of |hbitmap|. |
| 594 SHDRAGIMAGE sdi; |
| 595 sdi.sizeDragImage.cx = width; |
| 596 sdi.sizeDragImage.cy = height; |
| 597 sdi.crColorKey = 0xFFFFFFFF; |
| 598 sdi.hbmpDragImage = hbitmap; |
| 599 sdi.ptOffset = gfx::PointAtOffsetFromOrigin(cursor_offset).ToPOINT(); |
| 600 helper->InitializeFromBitmap(&sdi, data_object()); |
547 } | 601 } |
548 | 602 |
549 const gfx::ImageSkia& OSExchangeDataProviderWin::GetDragImage() const { | 603 gfx::ImageSkia OSExchangeDataProviderWin::GetDragImage() const { |
550 return drag_image_; | 604 // This class sets the image on data_object() so it shouldn't be used in |
| 605 // situations where the drag image is later queried. In that case a different |
| 606 // OSExchangeData::Provider should be used. |
| 607 NOTREACHED(); |
| 608 return gfx::ImageSkia(); |
551 } | 609 } |
552 | 610 |
553 const gfx::Vector2d& OSExchangeDataProviderWin::GetDragImageOffset() const { | 611 gfx::Vector2d OSExchangeDataProviderWin::GetDragImageOffset() const { |
554 return drag_image_offset_; | 612 // This class sets the image on data_object() so it shouldn't be used in |
| 613 // situations where the drag image is later queried. In that case a different |
| 614 // OSExchangeData::Provider should be used. |
| 615 NOTREACHED(); |
| 616 return gfx::Vector2d(); |
555 } | 617 } |
556 | 618 |
557 /////////////////////////////////////////////////////////////////////////////// | 619 /////////////////////////////////////////////////////////////////////////////// |
558 // DataObjectImpl, IDataObject implementation: | 620 // DataObjectImpl, IDataObject implementation: |
559 | 621 |
560 // The following function, DuplicateMedium, is derived from WCDataObject.cpp | 622 // The following function, DuplicateMedium, is derived from WCDataObject.cpp |
561 // in the WebKit source code. This is the license information for the file: | 623 // in the WebKit source code. This is the license information for the file: |
562 /* | 624 /* |
563 * Copyright (C) 2007 Apple Inc. All rights reserved. | 625 * Copyright (C) 2007 Apple Inc. All rights reserved. |
564 * | 626 * |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 std::min(file_name.size(), static_cast<size_t>(MAX_PATH - 1u))); | 1121 std::min(file_name.size(), static_cast<size_t>(MAX_PATH - 1u))); |
1060 | 1122 |
1061 STGMEDIUM* storage = new STGMEDIUM; | 1123 STGMEDIUM* storage = new STGMEDIUM; |
1062 storage->tymed = TYMED_HGLOBAL; | 1124 storage->tymed = TYMED_HGLOBAL; |
1063 storage->hGlobal = hdata; | 1125 storage->hGlobal = hdata; |
1064 storage->pUnkForRelease = NULL; | 1126 storage->pUnkForRelease = NULL; |
1065 return storage; | 1127 return storage; |
1066 } | 1128 } |
1067 | 1129 |
1068 } // namespace ui | 1130 } // namespace ui |
OLD | NEW |