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

Side by Side Diff: ui/views/drag_utils.cc

Issue 8735009: views: Move some random files from views/ to ui/views/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 | « ui/views/drag_utils.h ('k') | ui/views/drag_utils_aura.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) 2011 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 "ui/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/ui_resources.h" 11 #include "grit/ui_resources.h"
12 #include "ui/base/dragdrop/os_exchange_data.h" 12 #include "ui/base/dragdrop/os_exchange_data.h"
13 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/canvas_skia.h" 14 #include "ui/gfx/canvas_skia.h"
15 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
16 #include "ui/views/controls/button/text_button.h" 16 #include "ui/views/controls/button/text_button.h"
17 17
18 using ui::OSExchangeData;
19
20 namespace drag_utils { 18 namespace drag_utils {
21 19
22 // Maximum width of the link drag image in pixels. 20 // Maximum width of the link drag image in pixels.
23 static const int kLinkDragImageMaxWidth = 200; 21 static const int kLinkDragImageMaxWidth = 200;
24 static const int kLinkDragImageVPadding = 3; 22 static const int kLinkDragImageVPadding = 3;
25 23
26 // File dragging pixel measurements 24 // File dragging pixel measurements
27 static const int kFileDragImageMaxWidth = 200; 25 static const int kFileDragImageMaxWidth = 200;
28 static const SkColor kFileDragImageTextColor = SK_ColorBLACK; 26 static const SkColor kFileDragImageTextColor = SK_ColorBLACK;
29 27
30 void SetURLAndDragImage(const GURL& url, 28 void SetURLAndDragImage(const GURL& url,
31 const string16& title, 29 const string16& title,
32 const SkBitmap& icon, 30 const SkBitmap& icon,
33 OSExchangeData* data) { 31 ui::OSExchangeData* data) {
34 DCHECK(url.is_valid() && data); 32 DCHECK(url.is_valid() && data);
35 33
36 data->SetURL(url, title); 34 data->SetURL(url, title);
37 35
38 // Create a button to render the drag image for us. 36 // Create a button to render the drag image for us.
39 views::TextButton button(NULL, 37 views::TextButton button(NULL,
40 title.empty() ? UTF8ToUTF16(url.spec()) : title); 38 title.empty() ? UTF8ToUTF16(url.spec()) : title);
41 button.set_max_width(kLinkDragImageMaxWidth); 39 button.set_max_width(kLinkDragImageMaxWidth);
42 if (icon.isNull()) { 40 if (icon.isNull()) {
43 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( 41 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
44 IDR_DEFAULT_FAVICON)); 42 IDR_DEFAULT_FAVICON));
45 } else { 43 } else {
46 button.SetIcon(icon); 44 button.SetIcon(icon);
47 } 45 }
48 gfx::Size prefsize = button.GetPreferredSize(); 46 gfx::Size prefsize = button.GetPreferredSize();
49 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); 47 button.SetBounds(0, 0, prefsize.width(), prefsize.height());
50 48
51 // Render the image. 49 // Render the image.
52 gfx::CanvasSkia canvas(prefsize.width(), prefsize.height(), false); 50 gfx::CanvasSkia canvas(prefsize.width(), prefsize.height(), false);
53 button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG); 51 button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG);
54 SetDragImageOnDataObject(canvas, prefsize, 52 SetDragImageOnDataObject(canvas, prefsize,
55 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); 53 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data);
56 } 54 }
57 55
58 void CreateDragImageForFile(const FilePath& file_name, 56 void CreateDragImageForFile(const FilePath& file_name,
59 const SkBitmap* icon, 57 const SkBitmap* icon,
60 OSExchangeData* data_object) { 58 ui::OSExchangeData* data_object) {
61 DCHECK(icon); 59 DCHECK(icon);
62 DCHECK(data_object); 60 DCHECK(data_object);
63 61
64 // Set up our text portion 62 // Set up our text portion
65 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 63 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
66 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); 64 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont);
67 65
68 const int width = kFileDragImageMaxWidth; 66 const int width = kFileDragImageMaxWidth;
69 // Add +2 here to allow room for the halo. 67 // Add +2 here to allow room for the halo.
70 const int height = font.GetHeight() + icon->height() + 68 const int height = font.GetHeight() + icon->height() +
(...skipping 17 matching lines...) Expand all
88 #endif 86 #endif
89 87
90 SetDragImageOnDataObject(canvas, gfx::Size(width, height), 88 SetDragImageOnDataObject(canvas, gfx::Size(width, height),
91 gfx::Point(width / 2, kLinkDragImageVPadding), 89 gfx::Point(width / 2, kLinkDragImageVPadding),
92 data_object); 90 data_object);
93 } 91 }
94 92
95 void SetDragImageOnDataObject(const gfx::Canvas& canvas, 93 void SetDragImageOnDataObject(const gfx::Canvas& canvas,
96 const gfx::Size& size, 94 const gfx::Size& size,
97 const gfx::Point& cursor_offset, 95 const gfx::Point& cursor_offset,
98 OSExchangeData* data_object) { 96 ui::OSExchangeData* data_object) {
99 SetDragImageOnDataObject( 97 SetDragImageOnDataObject(
100 canvas.AsCanvasSkia()->ExtractBitmap(), size, cursor_offset, data_object); 98 canvas.AsCanvasSkia()->ExtractBitmap(), size, cursor_offset, data_object);
101 } 99 }
102 100
103 } // namespace drag_utils 101 } // namespace drag_utils
OLDNEW
« no previous file with comments | « ui/views/drag_utils.h ('k') | ui/views/drag_utils_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698