| 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::WebDragOperationNone; |
| 20 using WebKit::WebDragOperationCopy; | |
| 21 using WebKit::WebDragOperationLink; | |
| 22 using WebKit::WebDragOperationMove; | |
| 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 | |
| 38 | 20 |
| 39 WebDragDestGtk::WebDragDestGtk(TabContents* tab_contents, GtkWidget* widget) | 21 WebDragDestGtk::WebDragDestGtk(TabContents* tab_contents, GtkWidget* widget) |
| 40 : tab_contents_(tab_contents), | 22 : tab_contents_(tab_contents), |
| 41 widget_(widget), | 23 widget_(widget), |
| 42 context_(NULL), | 24 context_(NULL), |
| 43 method_factory_(this) { | 25 method_factory_(this) { |
| 44 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), | 26 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), |
| 45 NULL, 0, | 27 NULL, 0, |
| 46 static_cast<GdkDragAction>(GDK_ACTION_COPY | | 28 static_cast<GdkDragAction>(GDK_ACTION_COPY | |
| 47 GDK_ACTION_LINK | | 29 GDK_ACTION_LINK | |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // TODO(estade): support image drags? | 85 // TODO(estade): support image drags? |
| 104 }; | 86 }; |
| 105 | 87 |
| 106 data_requests_ = arraysize(supported_targets); | 88 data_requests_ = arraysize(supported_targets); |
| 107 for (size_t i = 0; i < arraysize(supported_targets); ++i) { | 89 for (size_t i = 0; i < arraysize(supported_targets); ++i) { |
| 108 gtk_drag_get_data(widget_, context, | 90 gtk_drag_get_data(widget_, context, |
| 109 gtk_dnd_util::GetAtomForTarget(supported_targets[i]), | 91 gtk_dnd_util::GetAtomForTarget(supported_targets[i]), |
| 110 time); | 92 time); |
| 111 } | 93 } |
| 112 } else if (data_requests_ == 0) { | 94 } else if (data_requests_ == 0) { |
| 113 // TODO(snej): Pass appropriate DragOperation instead of hardcoding | |
| 114 tab_contents_->render_view_host()-> | 95 tab_contents_->render_view_host()-> |
| 115 DragTargetDragOver(gtk_util::ClientPoint(widget_), | 96 DragTargetDragOver( |
| 116 gtk_util::ScreenPoint(widget_), | 97 gtk_util::ClientPoint(widget_), |
| 117 GdkDragActionToWebDragOp(context->actions)); | 98 gtk_util::ScreenPoint(widget_), |
| 99 gtk_dnd_util::GdkDragActionToWebDragOp(context->actions)); |
| 118 if (tab_contents_->GetBookmarkDragDelegate()) | 100 if (tab_contents_->GetBookmarkDragDelegate()) |
| 119 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data_); | 101 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data_); |
| 120 drag_over_time_ = time; | 102 drag_over_time_ = time; |
| 121 } | 103 } |
| 122 | 104 |
| 123 // Pretend we are a drag destination because we don't want to wait for | 105 // Pretend we are a drag destination because we don't want to wait for |
| 124 // the renderer to tell us if we really are or not. | 106 // the renderer to tell us if we really are or not. |
| 125 return TRUE; | 107 return TRUE; |
| 126 } | 108 } |
| 127 | 109 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 NULL, data, | 174 NULL, data, |
| 193 gtk_dnd_util::CHROME_BOOKMARK_ITEM, | 175 gtk_dnd_util::CHROME_BOOKMARK_ITEM, |
| 194 tab_contents_->profile(), NULL, NULL)); | 176 tab_contents_->profile(), NULL, NULL)); |
| 195 bookmark_drag_data_.SetOriginatingProfile(tab_contents_->profile()); | 177 bookmark_drag_data_.SetOriginatingProfile(tab_contents_->profile()); |
| 196 } | 178 } |
| 197 } | 179 } |
| 198 | 180 |
| 199 if (data_requests_ == 0) { | 181 if (data_requests_ == 0) { |
| 200 // Tell the renderer about the drag. | 182 // Tell the renderer about the drag. |
| 201 // |x| and |y| are seemingly arbitrary at this point. | 183 // |x| and |y| are seemingly arbitrary at this point. |
| 202 // TODO(snej): Pass appropriate DragOperation instead of hardcoding. | |
| 203 tab_contents_->render_view_host()-> | 184 tab_contents_->render_view_host()-> |
| 204 DragTargetDragEnter(*drop_data_.get(), | 185 DragTargetDragEnter(*drop_data_.get(), |
| 205 gtk_util::ClientPoint(widget_), | 186 gtk_util::ClientPoint(widget_), |
| 206 gtk_util::ScreenPoint(widget_), | 187 gtk_util::ScreenPoint(widget_), |
| 207 GdkDragActionToWebDragOp(context->actions)); | 188 gtk_dnd_util::GdkDragActionToWebDragOp(context->actions)); |
| 208 | 189 |
| 209 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with | 190 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with |
| 210 // support for (at the moment experimental) drag and drop extensions. | 191 // support for (at the moment experimental) drag and drop extensions. |
| 211 if (tab_contents_->GetBookmarkDragDelegate()) { | 192 if (tab_contents_->GetBookmarkDragDelegate()) { |
| 212 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter( | 193 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter( |
| 213 bookmark_drag_data_); | 194 bookmark_drag_data_); |
| 214 } | 195 } |
| 215 | 196 |
| 216 drag_over_time_ = time; | 197 drag_over_time_ = time; |
| 217 } | 198 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 246 // support for (at the moment experimental) drag and drop extensions. | 227 // support for (at the moment experimental) drag and drop extensions. |
| 247 if (tab_contents_->GetBookmarkDragDelegate()) | 228 if (tab_contents_->GetBookmarkDragDelegate()) |
| 248 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data_); | 229 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data_); |
| 249 | 230 |
| 250 // The second parameter is just an educated guess as to whether or not the | 231 // The second parameter is just an educated guess as to whether or not the |
| 251 // drag succeeded, but at least we will get the drag-end animation right | 232 // drag succeeded, but at least we will get the drag-end animation right |
| 252 // sometimes. | 233 // sometimes. |
| 253 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 234 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
| 254 return TRUE; | 235 return TRUE; |
| 255 } | 236 } |
| OLD | NEW |