diff options
Diffstat (limited to 'views/drag_utils.cc')
-rw-r--r-- | views/drag_utils.cc | 81 |
1 files changed, 7 insertions, 74 deletions
diff --git a/views/drag_utils.cc b/views/drag_utils.cc index 009fc47..7ba6a86 100644 --- a/views/drag_utils.cc +++ b/views/drag_utils.cc @@ -4,18 +4,13 @@ #include "views/drag_utils.h" -#include <objidl.h> -#include <shlobj.h> -#include <shobjidl.h> - #include "app/gfx/canvas.h" #include "app/gfx/font.h" #include "app/l10n_util.h" #include "app/os_exchange_data.h" #include "app/resource_bundle.h" #include "base/file_util.h" -#include "base/gfx/gdi_util.h" -#include "base/gfx/point.h" +#include "base/logging.h" #include "base/string_util.h" #include "googleurl/src/gurl.h" #include "grit/app_resources.h" @@ -26,60 +21,11 @@ namespace drag_utils { // Maximum width of the link drag image in pixels. static const int kLinkDragImageMaxWidth = 200; static const int kLinkDragImageVPadding = 3; -static const int kLinkDragImageVSpacing = 2; -static const int kLinkDragImageHPadding = 4; -static const SkColor kLinkDragImageBGColor = SkColorSetRGB(131, 146, 171); -//static const SkColor kLinkDragImageBGColor = SkColorSetRGB(195, 217, 255); -static const SkColor kLinkDragImageTextColor = SK_ColorBLACK; // File dragging pixel measurements static const int kFileDragImageMaxWidth = 200; static const SkColor kFileDragImageTextColor = SK_ColorBLACK; -static void SetDragImageOnDataObject(HBITMAP hbitmap, - int width, - int height, - int cursor_offset_x, - int cursor_offset_y, - IDataObject* data_object) { - IDragSourceHelper* helper = NULL; - HRESULT rv = CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, - IID_IDragSourceHelper, reinterpret_cast<LPVOID*>(&helper)); - if (SUCCEEDED(rv)) { - SHDRAGIMAGE sdi; - sdi.sizeDragImage.cx = width; - sdi.sizeDragImage.cy = height; - sdi.crColorKey = 0xFFFFFFFF; - sdi.hbmpDragImage = hbitmap; - sdi.ptOffset.x = cursor_offset_x; - sdi.ptOffset.y = cursor_offset_y; - helper->InitializeFromBitmap(&sdi, data_object); - } -}; - -// Blit the contents of the canvas to a new HBITMAP. It is the caller's -// responsibility to release the |bits| buffer. -static HBITMAP CreateBitmapFromCanvas(const gfx::Canvas& canvas, - int width, - int height) { - HDC screen_dc = GetDC(NULL); - BITMAPINFOHEADER header; - gfx::CreateBitmapHeader(width, height, &header); - void* bits; - HBITMAP bitmap = - CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header), - DIB_RGB_COLORS, &bits, NULL, 0); - HDC compatible_dc = CreateCompatibleDC(screen_dc); - HGDIOBJ old_object = SelectObject(compatible_dc, bitmap); - BitBlt(compatible_dc, 0, 0, width, height, - canvas.getTopPlatformDevice().getBitmapDC(), - 0, 0, SRCCOPY); - SelectObject(compatible_dc, old_object); - ReleaseDC(NULL, compatible_dc); - ReleaseDC(NULL, screen_dc); - return bitmap; -} - void SetURLAndDragImage(const GURL& url, const std::wstring& title, const SkBitmap& icon, @@ -111,12 +57,11 @@ void SetURLAndDragImage(const GURL& url, void CreateDragImageForFile(const std::wstring& file_name, SkBitmap* icon, - IDataObject* data_object) { + OSExchangeData* data_object) { DCHECK(icon); DCHECK(data_object); // Set up our text portion - const std::wstring& name = file_util::GetFilenameFromPath(file_name); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); @@ -130,30 +75,18 @@ void CreateDragImageForFile(const std::wstring& file_name, canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); // Paint the file name. We inset it one pixel to allow room for the halo. +#if defined(OS_WIN) + const std::wstring& name = file_util::GetFilenameFromPath(file_name); canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, 1, icon->height() + kLinkDragImageVPadding + 1, width - 2, font.height(), gfx::Canvas::TEXT_ALIGN_CENTER); +#else + NOTIMPLEMENTED(); +#endif SetDragImageOnDataObject(canvas, width, height, width / 2, kLinkDragImageVPadding, data_object); } -void SetDragImageOnDataObject(const gfx::Canvas& canvas, - int width, - int height, - int cursor_x_offset, - int cursor_y_offset, - IDataObject* data_object) { - DCHECK(data_object && width > 0 && height > 0); - // SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap. - HBITMAP bitmap = CreateBitmapFromCanvas(canvas, width, height); - - // Attach 'bitmap' to the data_object. - SetDragImageOnDataObject(bitmap, width, height, - cursor_x_offset, - cursor_y_offset, - data_object); -} - } // namespace drag_utils |