| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ui/views/button_drag_utils.h" | 5 #include "ui/views/button_drag_utils.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
| 10 #include "ui/base/dragdrop/drag_utils.h" | 10 #include "ui/base/dragdrop/drag_utils.h" |
| 11 #include "ui/base/dragdrop/os_exchange_data.h" | 11 #include "ui/base/dragdrop/os_exchange_data.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/gfx/canvas_skia.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/views/controls/button/text_button.h" | 14 #include "ui/views/controls/button/text_button.h" |
| 15 | 15 |
| 16 namespace button_drag_utils { | 16 namespace button_drag_utils { |
| 17 | 17 |
| 18 // Maximum width of the link drag image in pixels. | 18 // Maximum width of the link drag image in pixels. |
| 19 static const int kLinkDragImageMaxWidth = 200; | 19 static const int kLinkDragImageMaxWidth = 200; |
| 20 | 20 |
| 21 void SetURLAndDragImage(const GURL& url, | 21 void SetURLAndDragImage(const GURL& url, |
| 22 const string16& title, | 22 const string16& title, |
| 23 const SkBitmap& icon, | 23 const SkBitmap& icon, |
| 24 ui::OSExchangeData* data) { | 24 ui::OSExchangeData* data) { |
| 25 DCHECK(url.is_valid() && data); | 25 DCHECK(url.is_valid() && data); |
| 26 | 26 |
| 27 data->SetURL(url, title); | 27 data->SetURL(url, title); |
| 28 | 28 |
| 29 // Create a button to render the drag image for us. | 29 // Create a button to render the drag image for us. |
| 30 views::TextButton button(NULL, | 30 views::TextButton button(NULL, |
| 31 title.empty() ? UTF8ToUTF16(url.spec()) : title); | 31 title.empty() ? UTF8ToUTF16(url.spec()) : title); |
| 32 button.set_max_width(kLinkDragImageMaxWidth); | 32 button.set_max_width(kLinkDragImageMaxWidth); |
| 33 if (icon.isNull()) { | 33 if (icon.isNull()) { |
| 34 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( | 34 button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 35 IDR_DEFAULT_FAVICON)); | 35 IDR_DEFAULT_FAVICON)); |
| 36 } else { | 36 } else { |
| 37 button.SetIcon(icon); | 37 button.SetIcon(icon); |
| 38 } | 38 } |
| 39 gfx::Size prefsize = button.GetPreferredSize(); | 39 gfx::Size prefsize = button.GetPreferredSize(); |
| 40 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); | 40 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); |
| 41 | 41 |
| 42 // Render the image. | 42 // Render the image. |
| 43 gfx::CanvasSkia canvas(prefsize, false); | 43 gfx::Canvas canvas(prefsize, false); |
| 44 button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG); | 44 button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG); |
| 45 drag_utils::SetDragImageOnDataObject(canvas, prefsize, | 45 drag_utils::SetDragImageOnDataObject(canvas, prefsize, |
| 46 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); | 46 gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace button_drag_utils | 49 } // namespace button_drag_utils |
| OLD | NEW |