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

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

Issue 9582041: Move most of ui/views/drag_utils to ui/base/dragdrop so it can be used outside of views. I tried to… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | « ui/views/button_drag_utils.h ('k') | ui/views/controls/menu/menu_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/button_drag_utils.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "googleurl/src/gurl.h"
9 #include "grit/ui_resources.h"
10 #include "ui/base/dragdrop/drag_utils.h"
11 #include "ui/base/dragdrop/os_exchange_data.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/canvas_skia.h"
14 #include "ui/views/controls/button/text_button.h"
15
16 namespace button_drag_utils {
17
18 // Maximum width of the link drag image in pixels.
19 static const int kLinkDragImageMaxWidth = 200;
20
21 void SetURLAndDragImage(const GURL& url,
22 const string16& title,
23 const SkBitmap& icon,
24 ui::OSExchangeData* data) {
25 DCHECK(url.is_valid() && data);
26
27 data->SetURL(url, title);
28
29 // Create a button to render the drag image for us.
30 views::TextButton button(NULL,
31 title.empty() ? UTF8ToUTF16(url.spec()) : title);
32 button.set_max_width(kLinkDragImageMaxWidth);
33 if (icon.isNull()) {
34 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
35 IDR_DEFAULT_FAVICON));
36 } else {
37 button.SetIcon(icon);
38 }
39 gfx::Size prefsize = button.GetPreferredSize();
40 button.SetBounds(0, 0, prefsize.width(), prefsize.height());
41
42 // Render the image.
43 gfx::CanvasSkia canvas(prefsize, false);
44 button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG);
45 drag_utils::SetDragImageOnDataObject(canvas, prefsize,
46 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data);
47 }
48
49 } // namespace button_drag_utils
OLDNEW
« no previous file with comments | « ui/views/button_drag_utils.h ('k') | ui/views/controls/menu/menu_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698