| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "views/drag_utils.h" | 5 #include "views/drag_utils.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "grit/app_resources.h" | 11 #include "grit/app_resources.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 42 if (icon.isNull()) { | 42 if (icon.isNull()) { |
| 43 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( | 43 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 44 IDR_DEFAULT_FAVICON)); | 44 IDR_DEFAULT_FAVICON)); |
| 45 } else { | 45 } else { |
| 46 button.SetIcon(icon); | 46 button.SetIcon(icon); |
| 47 } | 47 } |
| 48 gfx::Size prefsize = button.GetPreferredSize(); | 48 gfx::Size prefsize = button.GetPreferredSize(); |
| 49 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); | 49 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); |
| 50 | 50 |
| 51 // Render the image. | 51 // Render the image. |
| 52 gfx::CanvasSkia canvas(prefsize.width(), prefsize.height(), false); | 52 gfx::CanvasSkia canvas; |
| 53 canvas.Init(prefsize.width(), prefsize.height(), false); |
| 53 button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG); | 54 button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG); |
| 54 SetDragImageOnDataObject(canvas, prefsize, | 55 SetDragImageOnDataObject(canvas, prefsize, |
| 55 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); | 56 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void CreateDragImageForFile(const FilePath& file_name, | 59 void CreateDragImageForFile(const FilePath& file_name, |
| 59 const SkBitmap* icon, | 60 const SkBitmap* icon, |
| 60 OSExchangeData* data_object) { | 61 OSExchangeData* data_object) { |
| 61 DCHECK(icon); | 62 DCHECK(icon); |
| 62 DCHECK(data_object); | 63 DCHECK(data_object); |
| 63 | 64 |
| 64 // Set up our text portion | 65 // Set up our text portion |
| 65 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 66 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 66 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); | 67 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); |
| 67 | 68 |
| 68 const int width = kFileDragImageMaxWidth; | 69 const int width = kFileDragImageMaxWidth; |
| 69 // Add +2 here to allow room for the halo. | 70 // Add +2 here to allow room for the halo. |
| 70 const int height = font.GetHeight() + icon->height() + | 71 const int height = font.GetHeight() + icon->height() + |
| 71 kLinkDragImageVPadding + 2; | 72 kLinkDragImageVPadding + 2; |
| 72 gfx::CanvasSkia canvas(width, height, false /* translucent */); | 73 gfx::CanvasSkia canvas; |
| 74 canvas.Init(width, height, false /* translucent */); |
| 73 | 75 |
| 74 // Paint the icon. | 76 // Paint the icon. |
| 75 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); | 77 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); |
| 76 | 78 |
| 77 std::wstring name = UTF16ToWide(file_name.BaseName().LossyDisplayName()); | 79 std::wstring name = UTF16ToWide(file_name.BaseName().LossyDisplayName()); |
| 78 #if defined(OS_WIN) | 80 #if defined(OS_WIN) |
| 79 // Paint the file name. We inset it one pixel to allow room for the halo. | 81 // Paint the file name. We inset it one pixel to allow room for the halo. |
| 80 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, | 82 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, |
| 81 1, icon->height() + kLinkDragImageVPadding + 1, | 83 1, icon->height() + kLinkDragImageVPadding + 1, |
| 82 width - 2, font.GetHeight(), | 84 width - 2, font.GetHeight(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 | 96 |
| 95 void SetDragImageOnDataObject(const gfx::Canvas& canvas, | 97 void SetDragImageOnDataObject(const gfx::Canvas& canvas, |
| 96 const gfx::Size& size, | 98 const gfx::Size& size, |
| 97 const gfx::Point& cursor_offset, | 99 const gfx::Point& cursor_offset, |
| 98 OSExchangeData* data_object) { | 100 OSExchangeData* data_object) { |
| 99 SetDragImageOnDataObject( | 101 SetDragImageOnDataObject( |
| 100 canvas.AsCanvasSkia()->ExtractBitmap(), size, cursor_offset, data_object); | 102 canvas.AsCanvasSkia()->ExtractBitmap(), size, cursor_offset, data_object); |
| 101 } | 103 } |
| 102 | 104 |
| 103 } // namespace drag_utils | 105 } // namespace drag_utils |
| OLD | NEW |