| OLD | NEW |
| 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/gtk_dnd_util.h" | 9 #include "app/gtk_dnd_util.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 gtk_widget_destroy(drag_widget_); | 63 gtk_widget_destroy(drag_widget_); |
| 64 g_object_unref(drag_widget_); | 64 g_object_unref(drag_widget_); |
| 65 drag_widget_ = NULL; | 65 drag_widget_ = NULL; |
| 66 } | 66 } |
| 67 | 67 |
| 68 TabContents* TabContentsDragSource::tab_contents() const { | 68 TabContents* TabContentsDragSource::tab_contents() const { |
| 69 return tab_contents_view_->tab_contents(); | 69 return tab_contents_view_->tab_contents(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void TabContentsDragSource::StartDragging(const WebDropData& drop_data, | 72 void TabContentsDragSource::StartDragging(const WebDropData& drop_data, |
| 73 GdkEventButton* last_mouse_down) { | 73 GdkEventButton* last_mouse_down, |
| 74 const SkBitmap& image, |
| 75 const gfx::Point& image_offset) { |
| 74 int targets_mask = 0; | 76 int targets_mask = 0; |
| 75 | 77 |
| 76 if (!drop_data.plain_text.empty()) | 78 if (!drop_data.plain_text.empty()) |
| 77 targets_mask |= gtk_dnd_util::TEXT_PLAIN; | 79 targets_mask |= gtk_dnd_util::TEXT_PLAIN; |
| 78 if (drop_data.url.is_valid()) { | 80 if (drop_data.url.is_valid()) { |
| 79 targets_mask |= gtk_dnd_util::TEXT_URI_LIST; | 81 targets_mask |= gtk_dnd_util::TEXT_URI_LIST; |
| 80 targets_mask |= gtk_dnd_util::CHROME_NAMED_URL; | 82 targets_mask |= gtk_dnd_util::CHROME_NAMED_URL; |
| 81 targets_mask |= gtk_dnd_util::NETSCAPE_URL; | 83 targets_mask |= gtk_dnd_util::NETSCAPE_URL; |
| 82 } | 84 } |
| 83 if (!drop_data.text_html.empty()) | 85 if (!drop_data.text_html.empty()) |
| 84 targets_mask |= gtk_dnd_util::TEXT_HTML; | 86 targets_mask |= gtk_dnd_util::TEXT_HTML; |
| 85 if (!drop_data.file_contents.empty()) | 87 if (!drop_data.file_contents.empty()) |
| 86 targets_mask |= gtk_dnd_util::CHROME_WEBDROP_FILE_CONTENTS; | 88 targets_mask |= gtk_dnd_util::CHROME_WEBDROP_FILE_CONTENTS; |
| 87 if (!drop_data.download_metadata.empty() && | 89 if (!drop_data.download_metadata.empty() && |
| 88 drag_download_util::ParseDownloadMetadata(drop_data.download_metadata, | 90 drag_download_util::ParseDownloadMetadata(drop_data.download_metadata, |
| 89 &wide_download_mime_type_, | 91 &wide_download_mime_type_, |
| 90 &download_file_name_, | 92 &download_file_name_, |
| 91 &download_url_)) { | 93 &download_url_)) { |
| 92 targets_mask |= gtk_dnd_util::DIRECT_SAVE_FILE; | 94 targets_mask |= gtk_dnd_util::DIRECT_SAVE_FILE; |
| 93 } | 95 } |
| 94 | 96 |
| 95 if (targets_mask == 0) { | 97 if (targets_mask == 0) { |
| 96 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
| 97 if (tab_contents()->render_view_host()) | 99 if (tab_contents()->render_view_host()) |
| 98 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); | 100 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); |
| 99 } | 101 } |
| 100 | 102 |
| 101 drop_data_.reset(new WebDropData(drop_data)); | 103 drop_data_.reset(new WebDropData(drop_data)); |
| 104 drag_image_ = image; |
| 105 image_offset_ = image_offset; |
| 102 | 106 |
| 103 GtkTargetList* list = gtk_dnd_util::GetTargetListFromCodeMask(targets_mask); | 107 GtkTargetList* list = gtk_dnd_util::GetTargetListFromCodeMask(targets_mask); |
| 104 if (targets_mask & gtk_dnd_util::CHROME_WEBDROP_FILE_CONTENTS) { | 108 if (targets_mask & gtk_dnd_util::CHROME_WEBDROP_FILE_CONTENTS) { |
| 105 drag_file_mime_type_ = gdk_atom_intern( | 109 drag_file_mime_type_ = gdk_atom_intern( |
| 106 mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE); | 110 mime_util::GetDataMimeType(drop_data.file_contents).c_str(), FALSE); |
| 107 gtk_target_list_add(list, drag_file_mime_type_, | 111 gtk_target_list_add(list, drag_file_mime_type_, |
| 108 0, gtk_dnd_util::CHROME_WEBDROP_FILE_CONTENTS); | 112 0, gtk_dnd_util::CHROME_WEBDROP_FILE_CONTENTS); |
| 109 } | 113 } |
| 110 | 114 |
| 111 drag_failed_ = false; | 115 drag_failed_ = false; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 gtk_dnd_util::GetAtomForTarget( | 301 gtk_dnd_util::GetAtomForTarget( |
| 298 gtk_dnd_util::DIRECT_SAVE_FILE), | 302 gtk_dnd_util::DIRECT_SAVE_FILE), |
| 299 gtk_dnd_util::GetAtomForTarget( | 303 gtk_dnd_util::GetAtomForTarget( |
| 300 gtk_dnd_util::TEXT_PLAIN_NO_CHARSET), | 304 gtk_dnd_util::TEXT_PLAIN_NO_CHARSET), |
| 301 8, | 305 8, |
| 302 GDK_PROP_MODE_REPLACE, | 306 GDK_PROP_MODE_REPLACE, |
| 303 reinterpret_cast<const guchar*>( | 307 reinterpret_cast<const guchar*>( |
| 304 generated_download_file_name.value().c_str()), | 308 generated_download_file_name.value().c_str()), |
| 305 generated_download_file_name.value().length()); | 309 generated_download_file_name.value().length()); |
| 306 } | 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 } |
| 307 } | 319 } |
| 308 | 320 |
| 309 void TabContentsDragSource::OnDragEnd(GdkDragContext* drag_context, | 321 void TabContentsDragSource::OnDragEnd(GdkDragContext* drag_context, |
| 310 WebDragOperation operation) { | 322 WebDragOperation operation) { |
| 311 MessageLoopForUI::current()->RemoveObserver(this); | 323 MessageLoopForUI::current()->RemoveObserver(this); |
| 312 | 324 |
| 313 if (!download_url_.is_empty()) { | 325 if (!download_url_.is_empty()) { |
| 314 gdk_property_delete(drag_context->source_window, | 326 gdk_property_delete(drag_context->source_window, |
| 315 gtk_dnd_util::GetAtomForTarget( | 327 gtk_dnd_util::GetAtomForTarget( |
| 316 gtk_dnd_util::DIRECT_SAVE_FILE)); | 328 gtk_dnd_util::DIRECT_SAVE_FILE)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 328 | 340 |
| 329 if (tab_contents()->render_view_host()) | 341 if (tab_contents()->render_view_host()) |
| 330 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); | 342 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); |
| 331 | 343 |
| 332 drop_data_.reset(); | 344 drop_data_.reset(); |
| 333 } | 345 } |
| 334 | 346 |
| 335 gfx::NativeView TabContentsDragSource::GetContentNativeView() const { | 347 gfx::NativeView TabContentsDragSource::GetContentNativeView() const { |
| 336 return tab_contents_view_->GetContentNativeView(); | 348 return tab_contents_view_->GetContentNativeView(); |
| 337 } | 349 } |
| OLD | NEW |