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

Side by Side Diff: views/drag_utils.cc

Issue 3083022: Rework gfx::Font by moving platform-specific code into inner classes.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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/textfield/textfield.cc ('k') | views/view_text_utils.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/os_exchange_data.h" 7 #include "app/os_exchange_data.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 OSExchangeData* data_object) { 58 OSExchangeData* data_object) {
59 DCHECK(icon); 59 DCHECK(icon);
60 DCHECK(data_object); 60 DCHECK(data_object);
61 61
62 // Set up our text portion 62 // Set up our text portion
63 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 63 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
64 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); 64 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont);
65 65
66 const int width = kFileDragImageMaxWidth; 66 const int width = kFileDragImageMaxWidth;
67 // Add +2 here to allow room for the halo. 67 // Add +2 here to allow room for the halo.
68 const int height = font.height() + icon->height() + 68 const int height = font.GetHeight() + icon->height() +
69 kLinkDragImageVPadding + 2; 69 kLinkDragImageVPadding + 2;
70 gfx::CanvasSkia canvas(width, height, false /* translucent */); 70 gfx::CanvasSkia canvas(width, height, false /* translucent */);
71 71
72 // Paint the icon. 72 // Paint the icon.
73 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); 73 canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0);
74 74
75 #if defined(OS_WIN) 75 #if defined(OS_WIN)
76 // Paint the file name. We inset it one pixel to allow room for the halo. 76 // Paint the file name. We inset it one pixel to allow room for the halo.
77 std::wstring name = file_util::GetFilenameFromPath(file_name); 77 std::wstring name = file_util::GetFilenameFromPath(file_name);
78 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE, 78 canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE,
79 1, icon->height() + kLinkDragImageVPadding + 1, 79 1, icon->height() + kLinkDragImageVPadding + 1,
80 width - 2, font.height(), 80 width - 2, font.GetHeight(),
81 gfx::Canvas::TEXT_ALIGN_CENTER); 81 gfx::Canvas::TEXT_ALIGN_CENTER);
82 #else 82 #else
83 std::wstring name = FilePath(file_name).BaseName().ToWStringHack(); 83 std::wstring name = FilePath(file_name).BaseName().ToWStringHack();
84 canvas.DrawStringInt(name, font, kFileDragImageTextColor, 84 canvas.DrawStringInt(name, font, kFileDragImageTextColor,
85 0, icon->height() + kLinkDragImageVPadding, 85 0, icon->height() + kLinkDragImageVPadding,
86 width, font.height(), gfx::Canvas::TEXT_ALIGN_CENTER); 86 width, font.GetHeight(), gfx::Canvas::TEXT_ALIGN_CENTER);
87 #endif 87 #endif
88 88
89 SetDragImageOnDataObject(canvas, gfx::Size(width, height), 89 SetDragImageOnDataObject(canvas, gfx::Size(width, height),
90 gfx::Point(width / 2, kLinkDragImageVPadding), 90 gfx::Point(width / 2, kLinkDragImageVPadding),
91 data_object); 91 data_object);
92 } 92 }
93 93
94 void SetDragImageOnDataObject(const gfx::Canvas& canvas, 94 void SetDragImageOnDataObject(const gfx::Canvas& canvas,
95 const gfx::Size& size, 95 const gfx::Size& size,
96 const gfx::Point& cursor_offset, 96 const gfx::Point& cursor_offset,
97 OSExchangeData* data_object) { 97 OSExchangeData* data_object) {
98 SetDragImageOnDataObject( 98 SetDragImageOnDataObject(
99 canvas.AsCanvasSkia()->ExtractBitmap(), size, cursor_offset, data_object); 99 canvas.AsCanvasSkia()->ExtractBitmap(), size, cursor_offset, data_object);
100 } 100 }
101 101
102 } // namespace drag_utils 102 } // namespace drag_utils
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield.cc ('k') | views/view_text_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698