summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-18 19:39:51 +0000
committerpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-18 19:39:51 +0000
commitf26c5200032a7ff315c2dda86089cf0f323cb4d7 (patch)
tree50a46e80ff107ee03081d6d31742a8d54c7e4510 /ui
parentf8126f5ef7fc32ab6132ebd5aaf59d408b11d5fd (diff)
downloadchromium_src-f26c5200032a7ff315c2dda86089cf0f323cb4d7.zip
chromium_src-f26c5200032a7ff315c2dda86089cf0f323cb4d7.tar.gz
chromium_src-f26c5200032a7ff315c2dda86089cf0f323cb4d7.tar.bz2
Makes dragging download item HiDPI.
Bug=None Test=Manual, see below. Run Chrome with --force-device-scale-factor=2 Go to google.com and download web page. When download is completed, drag download item. Make sure that the text shown while dragging is not blurry. Review URL: https://chromiumcodereview.appspot.com/10785036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147294 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/base/dragdrop/drag_utils.cc95
1 files changed, 65 insertions, 30 deletions
diff --git a/ui/base/dragdrop/drag_utils.cc b/ui/base/dragdrop/drag_utils.cc
index 41f422e..910fda13 100644
--- a/ui/base/dragdrop/drag_utils.cc
+++ b/ui/base/dragdrop/drag_utils.cc
@@ -12,11 +12,14 @@
#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;
@@ -24,42 +27,74 @@ static const int kLinkDragImageVPadding = 3;
static const int kFileDragImageMaxWidth = 200;
static const SkColor kFileDragImageTextColor = SK_ColorBLACK;
-void CreateDragImageForFile(const FilePath& file_name,
- const gfx::ImageSkia* icon,
- ui::OSExchangeData* data_object) {
- DCHECK(icon);
- DCHECK(data_object);
+class FileDragImageSource : public gfx::CanvasImageSource {
+ public:
+ FileDragImageSource(const FilePath& file_name, const gfx::ImageSkia& icon)
+ : CanvasImageSource(CalculateSize(icon), false),
+ file_name_(file_name),
+ icon_(icon) {
+ }
- // Set up our text portion
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- gfx::Font font = rb.GetFont(ResourceBundle::BaseFont);
+ virtual ~FileDragImageSource() {
+ }
- 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 */);
+ // Overridden from gfx::CanvasImageSource.
+ void Draw(gfx::Canvas* canvas) OVERRIDE {
+ // Set up our text portion
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ gfx::Font font = rb.GetFont(ResourceBundle::BaseFont);
- // Paint the icon.
- canvas.DrawImageInt(*icon, (width - icon->width()) / 2, 0);
+ // Paint the icon.
+ canvas->DrawImageInt(icon_, (size().width() - icon_.width()) / 2, 0);
- string16 name = file_name.BaseName().LossyDisplayName();
- const int flags = gfx::Canvas::TEXT_ALIGN_CENTER;
+ string16 name = file_name_.BaseName().LossyDisplayName();
+ 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,
+ size().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,
+ size().width(), font.GetHeight(),
+ flags | gfx::Canvas::NO_SUBPIXEL_RENDERING);
#endif
+ }
+
+ private:
+ gfx::Size CalculateSize(const gfx::ImageSkia& icon) const {
+ 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;
+ return gfx::Size(width, height);
+ }
+
+ const FilePath file_name_;
+ const gfx::ImageSkia icon_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileDragImageSource);
+};
- SetDragImageOnDataObject(canvas, gfx::Size(width, height),
- gfx::Point(width / 2, kLinkDragImageVPadding),
+} // namespace
+
+void CreateDragImageForFile(const FilePath& file_name,
+ const gfx::ImageSkia* icon,
+ ui::OSExchangeData* data_object) {
+ DCHECK(icon);
+ DCHECK(data_object);
+ gfx::CanvasImageSource* source = new FileDragImageSource(file_name, *icon);
+ gfx::Size size = source->size();
+ // ImageSkia takes ownership of |source|.
+ gfx::ImageSkia image = gfx::ImageSkia(source, size);
+
+ SetDragImageOnDataObject(image, size,
+ gfx::Point(size.width() / 2, kLinkDragImageVPadding),
data_object);
}
@@ -67,8 +102,8 @@ void SetDragImageOnDataObject(const gfx::Canvas& canvas,
const gfx::Size& size,
const gfx::Point& cursor_offset,
ui::OSExchangeData* data_object) {
- SetDragImageOnDataObject(canvas.ExtractImageSkiaRep(), size, cursor_offset,
- data_object);
+ gfx::ImageSkia image = gfx::ImageSkia(canvas.ExtractImageSkiaRep());
+ SetDragImageOnDataObject(image, size, cursor_offset, data_object);
}
} // namespace drag_utils