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/tab_contents/web_drag_dest_gtk.h" | 5 #include "chrome/browser/tab_contents/web_drag_dest_gtk.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_path.h" | 10 #include "base/file_path.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/gtk/bookmark_utils_gtk.h" | 12 #include "chrome/browser/gtk/bookmark_utils_gtk.h" |
13 #include "chrome/browser/gtk/gtk_util.h" | 13 #include "chrome/browser/gtk/gtk_util.h" |
14 #include "chrome/browser/renderer_host/render_view_host.h" | 14 #include "chrome/browser/renderer_host/render_view_host.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 | 17 |
18 using WebKit::WebDragOperation; | 18 using WebKit::WebDragOperation; |
| 19 using WebKit::WebDragOperationNone; |
19 using WebKit::WebDragOperationCopy; | 20 using WebKit::WebDragOperationCopy; |
| 21 using WebKit::WebDragOperationLink; |
20 using WebKit::WebDragOperationMove; | 22 using WebKit::WebDragOperationMove; |
21 using WebKit::WebDragOperationNone; | 23 |
| 24 namespace { |
| 25 |
| 26 WebDragOperation GdkDragActionToWebDragOp(GdkDragAction action) { |
| 27 WebDragOperation op = WebDragOperationNone; |
| 28 if (action & GDK_ACTION_COPY) |
| 29 op = static_cast<WebDragOperation>(op | WebDragOperationCopy); |
| 30 if (action & GDK_ACTION_LINK) |
| 31 op = static_cast<WebDragOperation>(op | WebDragOperationLink); |
| 32 if (action & GDK_ACTION_MOVE) |
| 33 op = static_cast<WebDragOperation>(op | WebDragOperationMove); |
| 34 return op; |
| 35 } |
| 36 |
| 37 } // namespace |
22 | 38 |
23 WebDragDestGtk::WebDragDestGtk(TabContents* tab_contents, GtkWidget* widget) | 39 WebDragDestGtk::WebDragDestGtk(TabContents* tab_contents, GtkWidget* widget) |
24 : tab_contents_(tab_contents), | 40 : tab_contents_(tab_contents), |
25 widget_(widget), | 41 widget_(widget), |
26 context_(NULL), | 42 context_(NULL), |
27 method_factory_(this) { | 43 method_factory_(this) { |
28 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), | 44 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), |
29 NULL, 0, GDK_ACTION_COPY); | 45 NULL, 0, |
| 46 static_cast<GdkDragAction>(GDK_ACTION_COPY | |
| 47 GDK_ACTION_LINK | |
| 48 GDK_ACTION_MOVE)); |
30 g_signal_connect(widget, "drag-motion", | 49 g_signal_connect(widget, "drag-motion", |
31 G_CALLBACK(OnDragMotionThunk), this); | 50 G_CALLBACK(OnDragMotionThunk), this); |
32 g_signal_connect(widget, "drag-leave", | 51 g_signal_connect(widget, "drag-leave", |
33 G_CALLBACK(OnDragLeaveThunk), this); | 52 G_CALLBACK(OnDragLeaveThunk), this); |
34 g_signal_connect(widget, "drag-drop", | 53 g_signal_connect(widget, "drag-drop", |
35 G_CALLBACK(OnDragDropThunk), this); | 54 G_CALLBACK(OnDragDropThunk), this); |
36 g_signal_connect(widget, "drag-data-received", | 55 g_signal_connect(widget, "drag-data-received", |
37 G_CALLBACK(OnDragDataReceivedThunk), this); | 56 G_CALLBACK(OnDragDataReceivedThunk), this); |
| 57 // TODO(tony): Need a drag-data-delete handler for moving content out of |
| 58 // the tab contents. http://crbug.com/38989 |
38 | 59 |
39 destroy_handler_ = g_signal_connect( | 60 destroy_handler_ = g_signal_connect( |
40 widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_); | 61 widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_); |
41 } | 62 } |
42 | 63 |
43 WebDragDestGtk::~WebDragDestGtk() { | 64 WebDragDestGtk::~WebDragDestGtk() { |
44 if (widget_) { | 65 if (widget_) { |
45 gtk_drag_dest_unset(widget_); | 66 gtk_drag_dest_unset(widget_); |
46 g_signal_handler_disconnect(widget_, destroy_handler_); | 67 g_signal_handler_disconnect(widget_, destroy_handler_); |
47 } | 68 } |
48 } | 69 } |
49 | 70 |
50 void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { | 71 void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { |
51 if (context_) { | 72 if (context_) { |
52 // TODO(estade): we might want to support other actions besides copy, | |
53 // but that would increase the cost of getting our drag success guess | |
54 // wrong. | |
55 is_drop_target_ = operation != WebDragOperationNone; | 73 is_drop_target_ = operation != WebDragOperationNone; |
56 gdk_drag_status(context_, is_drop_target_ ? GDK_ACTION_COPY : | 74 gdk_drag_status(context_, gtk_dnd_util::WebDragOpToGdkDragAction(operation), |
57 static_cast<GdkDragAction>(0), | |
58 drag_over_time_); | 75 drag_over_time_); |
59 } | 76 } |
60 } | 77 } |
61 | 78 |
62 void WebDragDestGtk::DragLeave() { | 79 void WebDragDestGtk::DragLeave() { |
63 tab_contents_->render_view_host()->DragTargetDragLeave(); | 80 tab_contents_->render_view_host()->DragTargetDragLeave(); |
64 | 81 |
65 if (tab_contents_->GetBookmarkDragDelegate()) { | 82 if (tab_contents_->GetBookmarkDragDelegate()) { |
66 tab_contents_->GetBookmarkDragDelegate()->OnDragLeave(bookmark_drag_data_); | 83 tab_contents_->GetBookmarkDragDelegate()->OnDragLeave(bookmark_drag_data_); |
67 } | 84 } |
(...skipping 22 matching lines...) Expand all Loading... |
90 for (size_t i = 0; i < arraysize(supported_targets); ++i) { | 107 for (size_t i = 0; i < arraysize(supported_targets); ++i) { |
91 gtk_drag_get_data(widget_, context, | 108 gtk_drag_get_data(widget_, context, |
92 gtk_dnd_util::GetAtomForTarget(supported_targets[i]), | 109 gtk_dnd_util::GetAtomForTarget(supported_targets[i]), |
93 time); | 110 time); |
94 } | 111 } |
95 } else if (data_requests_ == 0) { | 112 } else if (data_requests_ == 0) { |
96 // TODO(snej): Pass appropriate DragOperation instead of hardcoding | 113 // TODO(snej): Pass appropriate DragOperation instead of hardcoding |
97 tab_contents_->render_view_host()-> | 114 tab_contents_->render_view_host()-> |
98 DragTargetDragOver(gtk_util::ClientPoint(widget_), | 115 DragTargetDragOver(gtk_util::ClientPoint(widget_), |
99 gtk_util::ScreenPoint(widget_), | 116 gtk_util::ScreenPoint(widget_), |
100 static_cast<WebDragOperation>( | 117 GdkDragActionToWebDragOp(context->actions)); |
101 WebDragOperationCopy | WebDragOperationMove)); | |
102 if (tab_contents_->GetBookmarkDragDelegate()) | 118 if (tab_contents_->GetBookmarkDragDelegate()) |
103 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data_); | 119 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data_); |
104 drag_over_time_ = time; | 120 drag_over_time_ = time; |
105 } | 121 } |
106 | 122 |
107 // Pretend we are a drag destination because we don't want to wait for | 123 // Pretend we are a drag destination because we don't want to wait for |
108 // the renderer to tell us if we really are or not. | 124 // the renderer to tell us if we really are or not. |
109 return TRUE; | 125 return TRUE; |
110 } | 126 } |
111 | 127 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 bookmark_drag_data_.SetOriginatingProfile(tab_contents_->profile()); | 195 bookmark_drag_data_.SetOriginatingProfile(tab_contents_->profile()); |
180 } | 196 } |
181 } | 197 } |
182 | 198 |
183 if (data_requests_ == 0) { | 199 if (data_requests_ == 0) { |
184 // Tell the renderer about the drag. | 200 // Tell the renderer about the drag. |
185 // |x| and |y| are seemingly arbitrary at this point. | 201 // |x| and |y| are seemingly arbitrary at this point. |
186 // TODO(snej): Pass appropriate DragOperation instead of hardcoding. | 202 // TODO(snej): Pass appropriate DragOperation instead of hardcoding. |
187 tab_contents_->render_view_host()-> | 203 tab_contents_->render_view_host()-> |
188 DragTargetDragEnter(*drop_data_.get(), | 204 DragTargetDragEnter(*drop_data_.get(), |
189 gtk_util::ClientPoint(widget_), | 205 gtk_util::ClientPoint(widget_), |
190 gtk_util::ScreenPoint(widget_), | 206 gtk_util::ScreenPoint(widget_), |
191 static_cast<WebDragOperation>( | 207 GdkDragActionToWebDragOp(context->actions)); |
192 WebDragOperationCopy | WebDragOperationMove)); | |
193 | 208 |
194 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with | 209 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with |
195 // support for (at the moment experimental) drag and drop extensions. | 210 // support for (at the moment experimental) drag and drop extensions. |
196 if (tab_contents_->GetBookmarkDragDelegate()) { | 211 if (tab_contents_->GetBookmarkDragDelegate()) { |
197 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter( | 212 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter( |
198 bookmark_drag_data_); | 213 bookmark_drag_data_); |
199 } | 214 } |
200 | 215 |
201 drag_over_time_ = time; | 216 drag_over_time_ = time; |
202 } | 217 } |
(...skipping 22 matching lines...) Expand all Loading... |
225 | 240 |
226 tab_contents_->render_view_host()-> | 241 tab_contents_->render_view_host()-> |
227 DragTargetDrop(gtk_util::ClientPoint(widget_), | 242 DragTargetDrop(gtk_util::ClientPoint(widget_), |
228 gtk_util::ScreenPoint(widget_)); | 243 gtk_util::ScreenPoint(widget_)); |
229 | 244 |
230 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with | 245 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with |
231 // support for (at the moment experimental) drag and drop extensions. | 246 // support for (at the moment experimental) drag and drop extensions. |
232 if (tab_contents_->GetBookmarkDragDelegate()) | 247 if (tab_contents_->GetBookmarkDragDelegate()) |
233 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data_); | 248 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data_); |
234 | 249 |
235 // The second parameter is just an educated guess, but at least we will | 250 // The second parameter is just an educated guess as to whether or not the |
236 // get the drag-end animation right sometimes. | 251 // drag succeeded, but at least we will get the drag-end animation right |
| 252 // sometimes. |
237 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 253 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
238 return TRUE; | 254 return TRUE; |
239 } | 255 } |
OLD | NEW |