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" |
11 #include "base/mime_util.h" | 11 #include "base/mime_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/download/download_manager.h" | 13 #include "chrome/browser/download/download_manager.h" |
14 #include "chrome/browser/download/drag_download_file.h" | 14 #include "chrome/browser/download/drag_download_file.h" |
15 #include "chrome/browser/download/drag_download_util.h" | 15 #include "chrome/browser/download/drag_download_util.h" |
16 #include "chrome/browser/gtk/gtk_util.h" | 16 #include "chrome/browser/gtk/gtk_util.h" |
17 #include "chrome/browser/renderer_host/render_view_host.h" | 17 #include "chrome/browser/renderer_host/render_view_host.h" |
18 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 18 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
20 #include "chrome/browser/tab_contents/tab_contents_view.h" | 20 #include "chrome/browser/tab_contents/tab_contents_view.h" |
21 #include "gfx/gtk_util.h" | 21 #include "gfx/gtk_util.h" |
22 #include "net/base/file_stream.h" | 22 #include "net/base/file_stream.h" |
23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
24 #include "webkit/glue/webdropdata.h" | 24 #include "webkit/glue/webdropdata.h" |
25 | 25 |
26 using WebKit::WebDragOperation; | 26 using WebKit::WebDragOperation; |
| 27 using WebKit::WebDragOperationsMask; |
27 using WebKit::WebDragOperationNone; | 28 using WebKit::WebDragOperationNone; |
28 | 29 |
29 TabContentsDragSource::TabContentsDragSource( | 30 TabContentsDragSource::TabContentsDragSource( |
30 TabContentsView* tab_contents_view) | 31 TabContentsView* tab_contents_view) |
31 : tab_contents_view_(tab_contents_view), | 32 : tab_contents_view_(tab_contents_view), |
32 drag_failed_(false), | 33 drag_failed_(false), |
33 drag_widget_(NULL) { | 34 drag_widget_(NULL) { |
34 drag_widget_ = gtk_invisible_new(); | 35 drag_widget_ = gtk_invisible_new(); |
35 g_signal_connect(drag_widget_, "drag-failed", | 36 g_signal_connect(drag_widget_, "drag-failed", |
36 G_CALLBACK(OnDragFailedThunk), this); | 37 G_CALLBACK(OnDragFailedThunk), this); |
(...skipping 26 matching lines...) Expand all Loading... |
63 gtk_widget_destroy(drag_widget_); | 64 gtk_widget_destroy(drag_widget_); |
64 g_object_unref(drag_widget_); | 65 g_object_unref(drag_widget_); |
65 drag_widget_ = NULL; | 66 drag_widget_ = NULL; |
66 } | 67 } |
67 | 68 |
68 TabContents* TabContentsDragSource::tab_contents() const { | 69 TabContents* TabContentsDragSource::tab_contents() const { |
69 return tab_contents_view_->tab_contents(); | 70 return tab_contents_view_->tab_contents(); |
70 } | 71 } |
71 | 72 |
72 void TabContentsDragSource::StartDragging(const WebDropData& drop_data, | 73 void TabContentsDragSource::StartDragging(const WebDropData& drop_data, |
| 74 WebDragOperationsMask allowed_ops, |
73 GdkEventButton* last_mouse_down, | 75 GdkEventButton* last_mouse_down, |
74 const SkBitmap& image, | 76 const SkBitmap& image, |
75 const gfx::Point& image_offset) { | 77 const gfx::Point& image_offset) { |
76 int targets_mask = 0; | 78 int targets_mask = 0; |
77 | 79 |
78 if (!drop_data.plain_text.empty()) | 80 if (!drop_data.plain_text.empty()) |
79 targets_mask |= gtk_dnd_util::TEXT_PLAIN; | 81 targets_mask |= gtk_dnd_util::TEXT_PLAIN; |
80 if (drop_data.url.is_valid()) { | 82 if (drop_data.url.is_valid()) { |
81 targets_mask |= gtk_dnd_util::TEXT_URI_LIST; | 83 targets_mask |= gtk_dnd_util::TEXT_URI_LIST; |
82 targets_mask |= gtk_dnd_util::CHROME_NAMED_URL; | 84 targets_mask |= gtk_dnd_util::CHROME_NAMED_URL; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // If we don't pass an event, GDK won't know what event time to start grabbing | 118 // If we don't pass an event, GDK won't know what event time to start grabbing |
117 // mouse events. Technically it's the mouse motion event and not the mouse | 119 // mouse events. Technically it's the mouse motion event and not the mouse |
118 // down event that causes the drag, but there's no reliable way to know | 120 // down event that causes the drag, but there's no reliable way to know |
119 // *which* motion event initiated the drag, so this will have to do. | 121 // *which* motion event initiated the drag, so this will have to do. |
120 // TODO(estade): This can sometimes be very far off, e.g. if the user clicks | 122 // TODO(estade): This can sometimes be very far off, e.g. if the user clicks |
121 // and holds and doesn't start dragging for a long time. I doubt it matters | 123 // and holds and doesn't start dragging for a long time. I doubt it matters |
122 // much, but we should probably look into the possibility of getting the | 124 // much, but we should probably look into the possibility of getting the |
123 // initiating event from webkit. | 125 // initiating event from webkit. |
124 GdkDragContext* context = gtk_drag_begin( | 126 GdkDragContext* context = gtk_drag_begin( |
125 drag_widget_, list, | 127 drag_widget_, list, |
126 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_LINK), | 128 gtk_dnd_util::WebDragOpToGdkDragAction(allowed_ops), |
127 1, // Drags are always initiated by the left button. | 129 1, // Drags are always initiated by the left button. |
128 reinterpret_cast<GdkEvent*>(last_mouse_down)); | 130 reinterpret_cast<GdkEvent*>(last_mouse_down)); |
129 // The drag adds a ref; let it own the list. | 131 // The drag adds a ref; let it own the list. |
130 gtk_target_list_unref(list); | 132 gtk_target_list_unref(list); |
131 | 133 |
132 // Sometimes the drag fails to start; |context| will be NULL and we won't | 134 // Sometimes the drag fails to start; |context| will be NULL and we won't |
133 // get a drag-end signal. | 135 // get a drag-end signal. |
134 if (!context) { | 136 if (!context) { |
135 drop_data_.reset(); | 137 drop_data_.reset(); |
136 if (tab_contents()->render_view_host()) | 138 if (tab_contents()->render_view_host()) |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 342 |
341 if (tab_contents()->render_view_host()) | 343 if (tab_contents()->render_view_host()) |
342 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); | 344 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); |
343 | 345 |
344 drop_data_.reset(); | 346 drop_data_.reset(); |
345 } | 347 } |
346 | 348 |
347 gfx::NativeView TabContentsDragSource::GetContentNativeView() const { | 349 gfx::NativeView TabContentsDragSource::GetContentNativeView() const { |
348 return tab_contents_view_->GetContentNativeView(); | 350 return tab_contents_view_->GetContentNativeView(); |
349 } | 351 } |
OLD | NEW |