diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-28 17:53:36 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-28 17:53:36 +0000 |
commit | 9941f620af64aafe096b2c6ba5fcebd03d50031d (patch) | |
tree | f77f140accb0765ca6049406b1f498f56d53f85e | |
parent | 540bea826a8942aafaed9e1318e2e3065b0a4ba7 (diff) | |
download | chromium_src-9941f620af64aafe096b2c6ba5fcebd03d50031d.zip chromium_src-9941f620af64aafe096b2c6ba5fcebd03d50031d.tar.gz chromium_src-9941f620af64aafe096b2c6ba5fcebd03d50031d.tar.bz2 |
Refactors drag_utils.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/113954
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17080 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | views/drag_utils.cc | 81 | ||||
-rw-r--r-- | views/drag_utils.h | 6 | ||||
-rw-r--r-- | views/drag_utils_gtk.cc | 22 | ||||
-rw-r--r-- | views/drag_utils_win.cc | 78 | ||||
-rw-r--r-- | views/views.gyp | 4 |
5 files changed, 111 insertions, 80 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 diff --git a/views/drag_utils.h b/views/drag_utils.h index 5cf68af8..e04e37e 100644 --- a/views/drag_utils.h +++ b/views/drag_utils.h @@ -5,7 +5,6 @@ #ifndef VIEWS_DRAG_UTILS_H_ #define VIEWS_DRAG_UTILS_H_ -#include <objidl.h> #include <string> namespace gfx { @@ -30,7 +29,7 @@ void SetURLAndDragImage(const GURL& url, // portion will be truncated in the drag image. void CreateDragImageForFile(const std::wstring& file_name, SkBitmap* icon, - IDataObject* data_object); + OSExchangeData* data_object); // Sets the drag image on data_object from the supplied canvas. width/height // are the size of the image to use, and the offsets give the location of @@ -40,8 +39,7 @@ void SetDragImageOnDataObject(const gfx::Canvas& canvas, int height, int cursor_x_offset, int cursor_y_offset, - IDataObject* data_object); - + OSExchangeData* data_object); } // namespace drag_utils #endif // #ifndef VIEWS_DRAG_UTILS_H_ diff --git a/views/drag_utils_gtk.cc b/views/drag_utils_gtk.cc new file mode 100644 index 0000000..8a40b85 --- /dev/null +++ b/views/drag_utils_gtk.cc @@ -0,0 +1,22 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "views/drag_utils.h" + +#include "app/gfx/canvas.h" +#include "base/logging.h" +#include "app/os_exchange_data.h" + +namespace drag_utils { + +void SetDragImageOnDataObject(const gfx::Canvas& canvas, + int width, + int height, + int cursor_x_offset, + int cursor_y_offset, + OSExchangeData* data_object) { + NOTIMPLEMENTED(); +} + +} // namespace drag_utils diff --git a/views/drag_utils_win.cc b/views/drag_utils_win.cc new file mode 100644 index 0000000..ed01386 --- /dev/null +++ b/views/drag_utils_win.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "views/drag_utils.h" + +#include <objidl.h> +#include <shlobj.h> +#include <shobjidl.h> + +#include "app/gfx/canvas.h" +#include "app/os_exchange_data.h" +#include "base/gfx/gdi_util.h" + +namespace drag_utils { + +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 SetDragImageOnDataObject(const gfx::Canvas& canvas, + int width, + int height, + int cursor_x_offset, + int cursor_y_offset, + OSExchangeData* 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 diff --git a/views/views.gyp b/views/views.gyp index 85bb1d8..00a79bb 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -148,6 +148,8 @@ 'controls/tree/tree_view.h', 'drag_utils.cc', 'drag_utils.h', + 'drag_utils_gtk.cc', + 'drag_utils_win.cc', 'event.cc', 'event.h', 'event_gtk.cc', @@ -253,8 +255,6 @@ 'controls/textfield/textfield.cc', 'controls/text_field.cc', 'controls/tree/tree_view.cc', - 'drag_utils.cc', - 'drag_utils.h', 'event_win.cc', 'resize_corner.cc', 'widget/accelerator_handler.cc', |