| Index: ui/base/dragdrop/drag_utils.cc
|
| diff --git a/ui/base/dragdrop/drag_utils.cc b/ui/base/dragdrop/drag_utils.cc
|
| index 41f422e8a3c9951b9352a19c860f3cd4c282db54..f411809995dc3253275b4d7941a5e6f53c7dd654 100644
|
| --- a/ui/base/dragdrop/drag_utils.cc
|
| +++ b/ui/base/dragdrop/drag_utils.cc
|
| @@ -12,54 +12,87 @@
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/font.h"
|
| +#include "ui/gfx/image/canvas_image_source.h"
|
| #include "ui/gfx/point.h"
|
| #include "ui/gfx/size.h"
|
|
|
| namespace drag_utils {
|
| -
|
| +namespace {
|
| // Maximum width of the link drag image in pixels.
|
| -static const int kLinkDragImageVPadding = 3;
|
| +const int kLinkDragImageVPadding = 3;
|
|
|
| // File dragging pixel measurements
|
| -static const int kFileDragImageMaxWidth = 200;
|
| -static const SkColor kFileDragImageTextColor = SK_ColorBLACK;
|
| +const int kFileDragImageMaxWidth = 200;
|
| +const SkColor kFileDragImageTextColor = SK_ColorBLACK;
|
|
|
| -void CreateDragImageForFile(const FilePath& file_name,
|
| - const gfx::ImageSkia* icon,
|
| - ui::OSExchangeData* data_object) {
|
| - DCHECK(icon);
|
| - DCHECK(data_object);
|
| -
|
| - // Set up our text portion
|
| +gfx::Size GetImageSize(const gfx::ImageSkia& icon) {
|
| ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| gfx::Font font = rb.GetFont(ResourceBundle::BaseFont);
|
|
|
| const int width = kFileDragImageMaxWidth;
|
| // Add +2 here to allow room for the halo.
|
| - const int height = font.GetHeight() + icon->height() +
|
| - kLinkDragImageVPadding + 2;
|
| - gfx::Canvas canvas(gfx::Size(width, height), false /* translucent */);
|
| + const int height = font.GetHeight() + icon.height() +
|
| + kLinkDragImageVPadding + 2;
|
| + return gfx::Size(width, height);
|
| +}
|
|
|
| - // Paint the icon.
|
| - canvas.DrawImageInt(*icon, (width - icon->width()) / 2, 0);
|
| +class DragImageSource : public gfx::CanvasImageSource {
|
| + public:
|
| + DragImageSource(const gfx::ImageSkia& icon, const string16& name)
|
| + : CanvasImageSource(GetImageSize(icon), false /* translucent */),
|
| + icon_(icon),
|
| + name_(name) {
|
| + }
|
| + virtual ~DragImageSource() {}
|
|
|
| - string16 name = file_name.BaseName().LossyDisplayName();
|
| - const int flags = gfx::Canvas::TEXT_ALIGN_CENTER;
|
| + // gfx::CanvasImageSource overrides:
|
| + virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
|
| + // Set up our text portion
|
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| + gfx::Font font = rb.GetFont(ResourceBundle::BaseFont);
|
| +
|
| + int width = size().width();
|
| + // Paint the icon.
|
| + canvas->DrawImageInt(icon_, (width - icon_.width()) / 2, 0);
|
| +
|
| + const int flags = gfx::Canvas::TEXT_ALIGN_CENTER;
|
| #if defined(OS_WIN)
|
| - // Paint the file name. We inset it one pixel to allow room for the halo.
|
| - canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE,
|
| - 1, icon->height() + kLinkDragImageVPadding + 1,
|
| - width - 2, font.GetHeight(), flags);
|
| + // Paint the file name. We inset it one pixel to allow room for the halo.
|
| + canvas->DrawStringWithHalo(name_, font,
|
| + kFileDragImageTextColor, SK_ColorWHITE,
|
| + 1, icon_.height() + kLinkDragImageVPadding + 1,
|
| + width - 2, font.GetHeight(), flags);
|
| #else
|
| - // NO_SUBPIXEL_RENDERING is required when drawing to a non-opaque canvas.
|
| - canvas.DrawStringInt(name, font, kFileDragImageTextColor,
|
| - 0, icon->height() + kLinkDragImageVPadding,
|
| - width, font.GetHeight(),
|
| - flags | gfx::Canvas::NO_SUBPIXEL_RENDERING);
|
| + // NO_SUBPIXEL_RENDERING is required when drawing to a non-opaque canvas.
|
| + canvas->DrawStringInt(name_, font,
|
| + kFileDragImageTextColor,
|
| + 0, icon_.height() + kLinkDragImageVPadding,
|
| + width, font.GetHeight(),
|
| + flags | gfx::Canvas::NO_SUBPIXEL_RENDERING);
|
| #endif
|
| + }
|
| +
|
| + private:
|
| + const gfx::ImageSkia icon_;
|
| + const string16 name_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DragImageSource);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +void CreateDragImageForFile(const FilePath& file_name,
|
| + const gfx::ImageSkia* icon,
|
| + ui::OSExchangeData* data_object) {
|
| + DCHECK(icon);
|
| + DCHECK(data_object);
|
| +
|
| + string16 name = file_name.BaseName().LossyDisplayName();
|
| + DragImageSource* source = new DragImageSource(*icon, name);
|
| + gfx::Size size = source->size();
|
|
|
| - SetDragImageOnDataObject(canvas, gfx::Size(width, height),
|
| - gfx::Point(width / 2, kLinkDragImageVPadding),
|
| + SetDragImageOnDataObject(gfx::ImageSkia(source, size), size,
|
| + gfx::Point(size.width() / 2, kLinkDragImageVPadding),
|
| data_object);
|
| }
|
|
|
|
|