| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <objidl.h> | 7 #include <objidl.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
| 10 | 10 |
| 11 #include "app/gfx/chrome_canvas.h" | 11 #include "app/gfx/canvas.h" |
| 12 #include "app/gfx/chrome_font.h" | 12 #include "app/gfx/font.h" |
| 13 #include "app/l10n_util.h" | 13 #include "app/l10n_util.h" |
| 14 #include "app/os_exchange_data.h" | 14 #include "app/os_exchange_data.h" |
| 15 #include "app/resource_bundle.h" | 15 #include "app/resource_bundle.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/gfx/gdi_util.h" | 17 #include "base/gfx/gdi_util.h" |
| 18 #include "base/gfx/point.h" | 18 #include "base/gfx/point.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 22 #include "views/controls/button/text_button.h" | 22 #include "views/controls/button/text_button.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 sdi.crColorKey = 0xFFFFFFFF; | 52 sdi.crColorKey = 0xFFFFFFFF; |
| 53 sdi.hbmpDragImage = hbitmap; | 53 sdi.hbmpDragImage = hbitmap; |
| 54 sdi.ptOffset.x = cursor_offset_x; | 54 sdi.ptOffset.x = cursor_offset_x; |
| 55 sdi.ptOffset.y = cursor_offset_y; | 55 sdi.ptOffset.y = cursor_offset_y; |
| 56 helper->InitializeFromBitmap(&sdi, data_object); | 56 helper->InitializeFromBitmap(&sdi, data_object); |
| 57 } | 57 } |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 // Blit the contents of the canvas to a new HBITMAP. It is the caller's | 60 // Blit the contents of the canvas to a new HBITMAP. It is the caller's |
| 61 // responsibility to release the |bits| buffer. | 61 // responsibility to release the |bits| buffer. |
| 62 static HBITMAP CreateBitmapFromCanvas(const ChromeCanvas& canvas, | 62 static HBITMAP CreateBitmapFromCanvas(const gfx::Canvas& canvas, |
| 63 int width, | 63 int width, |
| 64 int height) { | 64 int height) { |
| 65 HDC screen_dc = GetDC(NULL); | 65 HDC screen_dc = GetDC(NULL); |
| 66 BITMAPINFOHEADER header; | 66 BITMAPINFOHEADER header; |
| 67 gfx::CreateBitmapHeader(width, height, &header); | 67 gfx::CreateBitmapHeader(width, height, &header); |
| 68 void* bits; | 68 void* bits; |
| 69 HBITMAP bitmap = | 69 HBITMAP bitmap = |
| 70 CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header), | 70 CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&header), |
| 71 DIB_RGB_COLORS, &bits, NULL, 0); | 71 DIB_RGB_COLORS, &bits, NULL, 0); |
| 72 HDC compatible_dc = CreateCompatibleDC(screen_dc); | 72 HDC compatible_dc = CreateCompatibleDC(screen_dc); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 95 if (icon.isNull()) { | 95 if (icon.isNull()) { |
| 96 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( | 96 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 97 IDR_DEFAULT_FAVICON)); | 97 IDR_DEFAULT_FAVICON)); |
| 98 } else { | 98 } else { |
| 99 button.SetIcon(icon); | 99 button.SetIcon(icon); |
| 100 } | 100 } |
| 101 gfx::Size prefsize = button.GetPreferredSize(); | 101 gfx::Size prefsize = button.GetPreferredSize(); |
| 102 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); | 102 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); |
| 103 | 103 |
| 104 // Render the image. | 104 // Render the image. |
| 105 ChromeCanvas canvas(prefsize.width(), prefsize.height(), false); | 105 gfx::Canvas canvas(prefsize.width(), prefsize.height(), false); |
| 106 button.Paint(&canvas, true); | 106 button.Paint(&canvas, true); |
| 107 SetDragImageOnDataObject(canvas, prefsize.width(), prefsize.height(), | 107 SetDragImageOnDataObject(canvas, prefsize.width(), prefsize.height(), |
| 108 prefsize.width() / 2, prefsize.height() / 2, | 108 prefsize.width() / 2, prefsize.height() / 2, |
| 109 data); | 109 data); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void CreateDragImageForFile(const std::wstring& file_name, | 112 void CreateDragImageForFile(const std::wstring& file_name, |
| 113 SkBitmap* icon, | 113 SkBitmap* icon, |
| 114 IDataObject* data_object) { | 114 IDataObject* data_object) { |
| 115 DCHECK(icon); | 115 DCHECK(icon); |
| 116 DCHECK(data_object); | 116 DCHECK(data_object); |
| 117 | 117 |
| 118 // Set up our text portion | 118 // Set up our text portion |
| 119 const std::wstring& name = file_util::GetFilenameFromPath(file_name); | 119 const std::wstring& name = file_util::GetFilenameFromPath(file_name); |
| 120 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 120 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 121 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); | 121 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); |
| 122 | 122 |
| 123 const int width = kFileDragImageMaxWidth; | 123 const int width = kFileDragImageMaxWidth; |
| 124 // Add +2 here to allow room for the halo. | 124 // Add +2 here to allow room for the halo. |
| 125 const int height = font.height() + icon->height() + | 125 const int height = font.height() + icon->height() + |
| 126 kLinkDragImageVPadding + 2; | 126 kLinkDragImageVPadding + 2; |
| 127 ChromeCanvas canvas(width, height, false /* translucent */); | 127 gfx::Canvas canvas(width, height, false /* translucent */); |
| 128 | 128 |
| 129 // Paint the icon. | 129 // Paint the icon. |
| 130 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); | 130 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); |
| 131 | 131 |
| 132 // Paint the file name. We inset it one pixel to allow room for the halo. | 132 // Paint the file name. We inset it one pixel to allow room for the halo. |
| 133 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, | 133 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, |
| 134 1, icon->height() + kLinkDragImageVPadding + 1, | 134 1, icon->height() + kLinkDragImageVPadding + 1, |
| 135 width - 2, font.height(), | 135 width - 2, font.height(), |
| 136 ChromeCanvas::TEXT_ALIGN_CENTER); | 136 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 137 | 137 |
| 138 SetDragImageOnDataObject(canvas, width, height, width / 2, | 138 SetDragImageOnDataObject(canvas, width, height, width / 2, |
| 139 kLinkDragImageVPadding, data_object); | 139 kLinkDragImageVPadding, data_object); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void SetDragImageOnDataObject(const ChromeCanvas& canvas, | 142 void SetDragImageOnDataObject(const gfx::Canvas& canvas, |
| 143 int width, | 143 int width, |
| 144 int height, | 144 int height, |
| 145 int cursor_x_offset, | 145 int cursor_x_offset, |
| 146 int cursor_y_offset, | 146 int cursor_y_offset, |
| 147 IDataObject* data_object) { | 147 IDataObject* data_object) { |
| 148 DCHECK(data_object && width > 0 && height > 0); | 148 DCHECK(data_object && width > 0 && height > 0); |
| 149 // SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap. | 149 // SetDragImageOnDataObject(HBITMAP) takes ownership of the bitmap. |
| 150 HBITMAP bitmap = CreateBitmapFromCanvas(canvas, width, height); | 150 HBITMAP bitmap = CreateBitmapFromCanvas(canvas, width, height); |
| 151 | 151 |
| 152 // Attach 'bitmap' to the data_object. | 152 // Attach 'bitmap' to the data_object. |
| 153 SetDragImageOnDataObject(bitmap, width, height, | 153 SetDragImageOnDataObject(bitmap, width, height, |
| 154 cursor_x_offset, | 154 cursor_x_offset, |
| 155 cursor_y_offset, | 155 cursor_y_offset, |
| 156 data_object); | 156 data_object); |
| 157 } | 157 } |
| 158 | 158 |
| 159 } // namespace drag_utils | 159 } // namespace drag_utils |
| OLD | NEW |