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

Side by Side Diff: views/drag_utils.cc

Issue 2862025: Canvas refactoring part 2.... (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
« no previous file with comments | « views/controls/tree/tree_view.cc ('k') | views/widget/root_view_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 13 #include "gfx/canvas.h"
14 #include "gfx/canvas_skia.h"
14 #include "gfx/font.h" 15 #include "gfx/font.h"
15 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
16 #include "grit/app_resources.h" 17 #include "grit/app_resources.h"
17 #include "views/controls/button/text_button.h" 18 #include "views/controls/button/text_button.h"
18 19
19 namespace drag_utils { 20 namespace drag_utils {
20 21
21 // Maximum width of the link drag image in pixels. 22 // Maximum width of the link drag image in pixels.
22 static const int kLinkDragImageMaxWidth = 200; 23 static const int kLinkDragImageMaxWidth = 200;
23 static const int kLinkDragImageVPadding = 3; 24 static const int kLinkDragImageVPadding = 3;
(...skipping 17 matching lines...) Expand all
41 if (icon.isNull()) { 42 if (icon.isNull()) {
42 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( 43 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
43 IDR_DEFAULT_FAVICON)); 44 IDR_DEFAULT_FAVICON));
44 } else { 45 } else {
45 button.SetIcon(icon); 46 button.SetIcon(icon);
46 } 47 }
47 gfx::Size prefsize = button.GetPreferredSize(); 48 gfx::Size prefsize = button.GetPreferredSize();
48 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); 49 button.SetBounds(0, 0, prefsize.width(), prefsize.height());
49 50
50 // Render the image. 51 // Render the image.
51 gfx::Canvas canvas(prefsize.width(), prefsize.height(), false); 52 gfx::CanvasSkia canvas(prefsize.width(), prefsize.height(), false);
52 button.Paint(&canvas, true); 53 button.Paint(canvas.AsCanvas(), true);
53 SetDragImageOnDataObject(canvas, prefsize, 54 SetDragImageOnDataObject(*canvas.AsCanvas(), prefsize,
54 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); 55 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data);
55 } 56 }
56 57
57 void CreateDragImageForFile(const FilePath::StringType& file_name, 58 void CreateDragImageForFile(const FilePath::StringType& file_name,
58 SkBitmap* icon, 59 SkBitmap* icon,
59 OSExchangeData* data_object) { 60 OSExchangeData* data_object) {
60 DCHECK(icon); 61 DCHECK(icon);
61 DCHECK(data_object); 62 DCHECK(data_object);
62 63
63 // Set up our text portion 64 // Set up our text portion
64 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 65 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
65 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); 66 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont);
66 67
67 const int width = kFileDragImageMaxWidth; 68 const int width = kFileDragImageMaxWidth;
68 // Add +2 here to allow room for the halo. 69 // Add +2 here to allow room for the halo.
69 const int height = font.height() + icon->height() + 70 const int height = font.height() + icon->height() +
70 kLinkDragImageVPadding + 2; 71 kLinkDragImageVPadding + 2;
71 gfx::Canvas canvas(width, height, false /* translucent */); 72 gfx::CanvasSkia canvas(width, height, false /* translucent */);
72 73
73 // Paint the icon. 74 // Paint the icon.
74 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); 75 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0);
75 76
76 #if defined(OS_WIN) 77 #if defined(OS_WIN)
77 // Paint the file name. We inset it one pixel to allow room for the halo. 78 // Paint the file name. We inset it one pixel to allow room for the halo.
78 std::wstring name = file_util::GetFilenameFromPath(file_name); 79 std::wstring name = file_util::GetFilenameFromPath(file_name);
79 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, 80 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE,
80 1, icon->height() + kLinkDragImageVPadding + 1, 81 1, icon->height() + kLinkDragImageVPadding + 1,
81 width - 2, font.height(), 82 width - 2, font.height(),
82 gfx::Canvas::TEXT_ALIGN_CENTER); 83 gfx::Canvas::TEXT_ALIGN_CENTER);
83 #else 84 #else
84 std::wstring name = file_util::GetFilenameFromPath(UTF8ToWide(file_name)); 85 std::wstring name = file_util::GetFilenameFromPath(UTF8ToWide(file_name));
85 canvas.DrawStringInt(name, font, kFileDragImageTextColor, 86 canvas.DrawStringInt(name, font, kFileDragImageTextColor,
86 0, icon->height() + kLinkDragImageVPadding, 87 0, icon->height() + kLinkDragImageVPadding,
87 width, font.height(), gfx::Canvas::TEXT_ALIGN_CENTER); 88 width, font.height(), gfx::Canvas::TEXT_ALIGN_CENTER);
88 #endif 89 #endif
89 90
90 SetDragImageOnDataObject(canvas, gfx::Size(width, height), 91 SetDragImageOnDataObject(*canvas.AsCanvas(), gfx::Size(width, height),
91 gfx::Point(width / 2, kLinkDragImageVPadding), 92 gfx::Point(width / 2, kLinkDragImageVPadding),
92 data_object); 93 data_object);
93 } 94 }
94 95
95 } // namespace drag_utils 96 } // namespace drag_utils
OLDNEW
« no previous file with comments | « views/controls/tree/tree_view.cc ('k') | views/widget/root_view_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698