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

Side by Side Diff: chrome/browser/gtk/tab_contents_drag_source.cc

Issue 668125: Basic DragImage implementation.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/gtk/tab_contents_drag_source.h" 5 #include "chrome/browser/gtk/tab_contents_drag_source.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/gfx/gtk_util.h"
9 #include "app/gtk_dnd_util.h" 10 #include "app/gtk_dnd_util.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/mime_util.h" 12 #include "base/mime_util.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/download/download_manager.h" 14 #include "chrome/browser/download/download_manager.h"
14 #include "chrome/browser/download/drag_download_file.h" 15 #include "chrome/browser/download/drag_download_file.h"
15 #include "chrome/browser/download/drag_download_util.h" 16 #include "chrome/browser/download/drag_download_util.h"
16 #include "chrome/browser/gtk/gtk_util.h" 17 #include "chrome/browser/gtk/gtk_util.h"
17 #include "chrome/browser/renderer_host/render_view_host.h" 18 #include "chrome/browser/renderer_host/render_view_host.h"
18 #include "chrome/browser/renderer_host/render_view_host_delegate.h" 19 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 gtk_widget_destroy(drag_widget_); 63 gtk_widget_destroy(drag_widget_);
63 g_object_unref(drag_widget_); 64 g_object_unref(drag_widget_);
64 drag_widget_ = NULL; 65 drag_widget_ = NULL;
65 } 66 }
66 67
67 TabContents* TabContentsDragSource::tab_contents() const { 68 TabContents* TabContentsDragSource::tab_contents() const {
68 return tab_contents_view_->tab_contents(); 69 return tab_contents_view_->tab_contents();
69 } 70 }
70 71
71 void TabContentsDragSource::StartDragging(const WebDropData& drop_data, 72 void TabContentsDragSource::StartDragging(const WebDropData& drop_data,
72 GdkEventButton* last_mouse_down) { 73 GdkEventButton* last_mouse_down,
74 const SkBitmap& image,
75 const gfx::Point& image_offset) {
73 int targets_mask = 0; 76 int targets_mask = 0;
74 77
75 if (!drop_data.plain_text.empty()) 78 if (!drop_data.plain_text.empty())
76 targets_mask |= GtkDndUtil::TEXT_PLAIN; 79 targets_mask |= GtkDndUtil::TEXT_PLAIN;
77 if (drop_data.url.is_valid()) { 80 if (drop_data.url.is_valid()) {
78 targets_mask |= GtkDndUtil::TEXT_URI_LIST; 81 targets_mask |= GtkDndUtil::TEXT_URI_LIST;
79 targets_mask |= GtkDndUtil::CHROME_NAMED_URL; 82 targets_mask |= GtkDndUtil::CHROME_NAMED_URL;
80 targets_mask |= GtkDndUtil::NETSCAPE_URL; 83 targets_mask |= GtkDndUtil::NETSCAPE_URL;
81 } 84 }
82 if (!drop_data.text_html.empty()) 85 if (!drop_data.text_html.empty())
83 targets_mask |= GtkDndUtil::TEXT_HTML; 86 targets_mask |= GtkDndUtil::TEXT_HTML;
84 if (!drop_data.file_contents.empty()) 87 if (!drop_data.file_contents.empty())
85 targets_mask |= GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS; 88 targets_mask |= GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS;
86 if (!drop_data.download_metadata.empty() && 89 if (!drop_data.download_metadata.empty() &&
87 drag_download_util::ParseDownloadMetadata(drop_data.download_metadata, 90 drag_download_util::ParseDownloadMetadata(drop_data.download_metadata,
88 &wide_download_mime_type_, 91 &wide_download_mime_type_,
89 &download_file_name_, 92 &download_file_name_,
90 &download_url_)) { 93 &download_url_)) {
91 targets_mask |= GtkDndUtil::DIRECT_SAVE_FILE; 94 targets_mask |= GtkDndUtil::DIRECT_SAVE_FILE;
92 } 95 }
93 96
94 if (targets_mask == 0) { 97 if (targets_mask == 0) {
95 NOTIMPLEMENTED(); 98 NOTIMPLEMENTED();
96 if (tab_contents()->render_view_host()) 99 if (tab_contents()->render_view_host())
97 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); 100 tab_contents()->render_view_host()->DragSourceSystemDragEnded();
98 } 101 }
99 102
100 drop_data_.reset(new WebDropData(drop_data)); 103 drop_data_.reset(new WebDropData(drop_data));
104 drag_image_ = image;
105 image_offset_ = image_offset;
101 106
102 GtkTargetList* list = GtkDndUtil::GetTargetListFromCodeMask(targets_mask); 107 GtkTargetList* list = GtkDndUtil::GetTargetListFromCodeMask(targets_mask);
103 if (targets_mask & GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS) { 108 if (targets_mask & GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS) {
104 drag_file_mime_type_ = gdk_atom_intern( 109 drag_file_mime_type_ = gdk_atom_intern(
105 mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE); 110 mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE);
106 gtk_target_list_add(list, drag_file_mime_type_, 111 gtk_target_list_add(list, drag_file_mime_type_,
107 0, GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS); 112 0, GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS);
108 } 113 }
109 114
110 drag_failed_ = false; 115 drag_failed_ = false;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 GtkDndUtil::GetAtomForTarget( 301 GtkDndUtil::GetAtomForTarget(
297 GtkDndUtil::DIRECT_SAVE_FILE), 302 GtkDndUtil::DIRECT_SAVE_FILE),
298 GtkDndUtil::GetAtomForTarget( 303 GtkDndUtil::GetAtomForTarget(
299 GtkDndUtil::TEXT_PLAIN_NO_CHARSET), 304 GtkDndUtil::TEXT_PLAIN_NO_CHARSET),
300 8, 305 8,
301 GDK_PROP_MODE_REPLACE, 306 GDK_PROP_MODE_REPLACE,
302 reinterpret_cast<const guchar*>( 307 reinterpret_cast<const guchar*>(
303 generated_download_file_name.value().c_str()), 308 generated_download_file_name.value().c_str()),
304 generated_download_file_name.value().length()); 309 generated_download_file_name.value().length());
305 } 310 }
311
312 if (!drag_image_.isNull()) {
313 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&drag_image_);
314 gtk_drag_set_icon_pixbuf(drag_context, pixbuf,
315 image_offset_.x(), image_offset_.y());
316 // Let the drag take ownership.
317 g_object_unref(pixbuf);
318 }
306 } 319 }
307 320
308 void TabContentsDragSource::OnDragEnd(GdkDragContext* drag_context, 321 void TabContentsDragSource::OnDragEnd(GdkDragContext* drag_context,
309 WebDragOperation operation) { 322 WebDragOperation operation) {
310 MessageLoopForUI::current()->RemoveObserver(this); 323 MessageLoopForUI::current()->RemoveObserver(this);
311 324
312 if (!download_url_.is_empty()) { 325 if (!download_url_.is_empty()) {
313 gdk_property_delete(drag_context->source_window, 326 gdk_property_delete(drag_context->source_window,
314 GtkDndUtil::GetAtomForTarget( 327 GtkDndUtil::GetAtomForTarget(
315 GtkDndUtil::DIRECT_SAVE_FILE)); 328 GtkDndUtil::DIRECT_SAVE_FILE));
(...skipping 11 matching lines...) Expand all
327 340
328 if (tab_contents()->render_view_host()) 341 if (tab_contents()->render_view_host())
329 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); 342 tab_contents()->render_view_host()->DragSourceSystemDragEnded();
330 343
331 drop_data_.reset(); 344 drop_data_.reset();
332 } 345 }
333 346
334 gfx::NativeView TabContentsDragSource::GetContentNativeView() const { 347 gfx::NativeView TabContentsDragSource::GetContentNativeView() const {
335 return tab_contents_view_->GetContentNativeView(); 348 return tab_contents_view_->GetContentNativeView();
336 } 349 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/tab_contents_drag_source.h ('k') | chrome/browser/renderer_host/render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698