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
Esse commit está contido em:
+7
-74
@@ -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
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
+2
-2
@@ -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',
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário