summaryrefslogtreecommitdiffstats
path: root/ui/views/button_drag_utils.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-05 05:37:26 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-05 05:37:26 +0000
commitf68e5d85edd4fb2e47ff01346d7138429c1ec5c4 (patch)
tree38191ef62fc83ad1a6c32015e29be187b5160e04 /ui/views/button_drag_utils.cc
parentbd2fb568f441498d0cf542b9c8db9d718f9c6475 (diff)
downloadchromium_src-f68e5d85edd4fb2e47ff01346d7138429c1ec5c4.zip
chromium_src-f68e5d85edd4fb2e47ff01346d7138429c1ec5c4.tar.gz
chromium_src-f68e5d85edd4fb2e47ff01346d7138429c1ec5c4.tar.bz2
Move most of ui/views/drag_utils to ui/base/dragdrop so it can be used outside of views. I tried to move SetURLAndDragImage as well, but that would cause a lot of code duplication from Views' TextButton class that would make us worse off (things like mirroring and limiting size).
BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9582041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/button_drag_utils.cc')
-rw-r--r--ui/views/button_drag_utils.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/ui/views/button_drag_utils.cc b/ui/views/button_drag_utils.cc
new file mode 100644
index 0000000..4c4c414
--- /dev/null
+++ b/ui/views/button_drag_utils.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/button_drag_utils.h"
+
+#include "base/utf_string_conversions.h"
+#include "googleurl/src/gurl.h"
+#include "grit/ui_resources.h"
+#include "ui/base/dragdrop/drag_utils.h"
+#include "ui/base/dragdrop/os_exchange_data.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/canvas_skia.h"
+#include "ui/views/controls/button/text_button.h"
+
+namespace button_drag_utils {
+
+// Maximum width of the link drag image in pixels.
+static const int kLinkDragImageMaxWidth = 200;
+
+void SetURLAndDragImage(const GURL& url,
+ const string16& title,
+ const SkBitmap& icon,
+ ui::OSExchangeData* data) {
+ DCHECK(url.is_valid() && data);
+
+ data->SetURL(url, title);
+
+ // Create a button to render the drag image for us.
+ views::TextButton button(NULL,
+ title.empty() ? UTF8ToUTF16(url.spec()) : title);
+ button.set_max_width(kLinkDragImageMaxWidth);
+ if (icon.isNull()) {
+ button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_DEFAULT_FAVICON));
+ } else {
+ button.SetIcon(icon);
+ }
+ gfx::Size prefsize = button.GetPreferredSize();
+ button.SetBounds(0, 0, prefsize.width(), prefsize.height());
+
+ // Render the image.
+ gfx::CanvasSkia canvas(prefsize, false);
+ button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG);
+ drag_utils::SetDragImageOnDataObject(canvas, prefsize,
+ gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data);
+}
+
+} // namespace button_drag_utils