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