Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: views/drag_utils.cc

Issue 2825018: Canvas refactoring part 3.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/os_exchange_data.h" 8 #include "app/os_exchange_data.h"
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "gfx/canvas.h"
14 #include "gfx/canvas_skia.h" 13 #include "gfx/canvas_skia.h"
15 #include "gfx/font.h" 14 #include "gfx/font.h"
16 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
17 #include "grit/app_resources.h" 16 #include "grit/app_resources.h"
18 #include "views/controls/button/text_button.h" 17 #include "views/controls/button/text_button.h"
19 18
20 namespace drag_utils { 19 namespace drag_utils {
21 20
22 // Maximum width of the link drag image in pixels. 21 // Maximum width of the link drag image in pixels.
23 static const int kLinkDragImageMaxWidth = 200; 22 static const int kLinkDragImageMaxWidth = 200;
(...skipping 18 matching lines...) Expand all
42 if (icon.isNull()) { 41 if (icon.isNull()) {
43 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( 42 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
44 IDR_DEFAULT_FAVICON)); 43 IDR_DEFAULT_FAVICON));
45 } else { 44 } else {
46 button.SetIcon(icon); 45 button.SetIcon(icon);
47 } 46 }
48 gfx::Size prefsize = button.GetPreferredSize(); 47 gfx::Size prefsize = button.GetPreferredSize();
49 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); 48 button.SetBounds(0, 0, prefsize.width(), prefsize.height());
50 49
51 // Render the image. 50 // Render the image.
52 // TODO(beng): Convert to CanvasSkia 51 gfx::CanvasSkia canvas(prefsize.width(), prefsize.height(), false);
53 gfx::Canvas canvas(prefsize.width(), prefsize.height(), false);
54 button.Paint(&canvas, true); 52 button.Paint(&canvas, true);
55 SetDragImageOnDataObject(canvas, prefsize, 53 SetDragImageOnDataObject(canvas, prefsize,
56 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); 54 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data);
57 } 55 }
58 56
59 void CreateDragImageForFile(const FilePath::StringType& file_name, 57 void CreateDragImageForFile(const FilePath::StringType& file_name,
60 SkBitmap* icon, 58 SkBitmap* icon,
61 OSExchangeData* data_object) { 59 OSExchangeData* data_object) {
62 DCHECK(icon); 60 DCHECK(icon);
63 DCHECK(data_object); 61 DCHECK(data_object);
64 62
65 // Set up our text portion 63 // Set up our text portion
66 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 64 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
67 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); 65 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont);
68 66
69 const int width = kFileDragImageMaxWidth; 67 const int width = kFileDragImageMaxWidth;
70 // Add +2 here to allow room for the halo. 68 // Add +2 here to allow room for the halo.
71 const int height = font.height() + icon->height() + 69 const int height = font.height() + icon->height() +
72 kLinkDragImageVPadding + 2; 70 kLinkDragImageVPadding + 2;
73 // TODO(beng): Convert to CanvasSkia 71 gfx::CanvasSkia canvas(width, height, false /* translucent */);
74 gfx::Canvas canvas(width, height, false /* translucent */);
75 72
76 // Paint the icon. 73 // Paint the icon.
77 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); 74 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0);
78 75
79 #if defined(OS_WIN) 76 #if defined(OS_WIN)
80 // Paint the file name. We inset it one pixel to allow room for the halo. 77 // Paint the file name. We inset it one pixel to allow room for the halo.
81 std::wstring name = file_util::GetFilenameFromPath(file_name); 78 std::wstring name = file_util::GetFilenameFromPath(file_name);
82 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, 79 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE,
83 1, icon->height() + kLinkDragImageVPadding + 1, 80 1, icon->height() + kLinkDragImageVPadding + 1,
84 width - 2, font.height(), 81 width - 2, font.height(),
85 gfx::Canvas::TEXT_ALIGN_CENTER); 82 gfx::Canvas::TEXT_ALIGN_CENTER);
86 #else 83 #else
87 std::wstring name = file_util::GetFilenameFromPath(UTF8ToWide(file_name)); 84 std::wstring name = file_util::GetFilenameFromPath(UTF8ToWide(file_name));
88 canvas.DrawStringInt(name, font, kFileDragImageTextColor, 85 canvas.DrawStringInt(name, font, kFileDragImageTextColor,
89 0, icon->height() + kLinkDragImageVPadding, 86 0, icon->height() + kLinkDragImageVPadding,
90 width, font.height(), gfx::Canvas::TEXT_ALIGN_CENTER); 87 width, font.height(), gfx::Canvas::TEXT_ALIGN_CENTER);
91 #endif 88 #endif
92 89
93 SetDragImageOnDataObject(canvas, gfx::Size(width, height), 90 SetDragImageOnDataObject(canvas, gfx::Size(width, height),
94 gfx::Point(width / 2, kLinkDragImageVPadding), 91 gfx::Point(width / 2, kLinkDragImageVPadding),
95 data_object); 92 data_object);
96 } 93 }
97 94
98 } // namespace drag_utils 95 } // namespace drag_utils
OLDNEW
« gfx/canvas.h ('K') | « views/controls/table/table_view.cc ('k') | views/drag_utils_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698