| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/tab_contents/web_drag_dest_gtk.h" | 5 #include "content/browser/tab_contents/web_drag_dest_gtk.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { | 62 void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { |
| 63 if (context_) { | 63 if (context_) { |
| 64 is_drop_target_ = operation != WebDragOperationNone; | 64 is_drop_target_ = operation != WebDragOperationNone; |
| 65 gdk_drag_status(context_, content::WebDragOpToGdkDragAction(operation), | 65 gdk_drag_status(context_, content::WebDragOpToGdkDragAction(operation), |
| 66 drag_over_time_); | 66 drag_over_time_); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 void WebDragDestGtk::DragLeave() { | 70 void WebDragDestGtk::DragLeave() { |
| 71 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); | 71 GetRenderViewHost()->DragTargetDragLeave(); |
| 72 | 72 |
| 73 if (delegate()) | 73 if (delegate()) |
| 74 delegate()->OnDragLeave(); | 74 delegate()->OnDragLeave(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender, | 77 gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender, |
| 78 GdkDragContext* context, | 78 GdkDragContext* context, |
| 79 gint x, gint y, | 79 gint x, gint y, |
| 80 guint time) { | 80 guint time) { |
| 81 if (context_ != context) { | 81 if (context_ != context) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 108 gtk_drag_get_data(widget_, context, | 108 gtk_drag_get_data(widget_, context, |
| 109 ui::GetAtomForTarget(supported_targets[i]), | 109 ui::GetAtomForTarget(supported_targets[i]), |
| 110 time); | 110 time); |
| 111 } | 111 } |
| 112 | 112 |
| 113 if (delegate()) { | 113 if (delegate()) { |
| 114 gtk_drag_get_data(widget_, context, delegate()->GetBookmarkTargetAtom(), | 114 gtk_drag_get_data(widget_, context, delegate()->GetBookmarkTargetAtom(), |
| 115 time); | 115 time); |
| 116 } | 116 } |
| 117 } else if (data_requests_ == 0) { | 117 } else if (data_requests_ == 0) { |
| 118 web_contents_->GetRenderViewHost()-> | 118 GetRenderViewHost()->DragTargetDragOver( |
| 119 DragTargetDragOver( | 119 ui::ClientPoint(widget_), |
| 120 ui::ClientPoint(widget_), | 120 ui::ScreenPoint(widget_), |
| 121 ui::ScreenPoint(widget_), | 121 content::GdkDragActionToWebDragOp(context->actions)); |
| 122 content::GdkDragActionToWebDragOp(context->actions)); | |
| 123 | 122 |
| 124 if (delegate()) | 123 if (delegate()) |
| 125 delegate()->OnDragOver(); | 124 delegate()->OnDragOver(); |
| 126 | 125 |
| 127 drag_over_time_ = time; | 126 drag_over_time_ = time; |
| 128 } | 127 } |
| 129 | 128 |
| 130 // Pretend we are a drag destination because we don't want to wait for | 129 // Pretend we are a drag destination because we don't want to wait for |
| 131 // the renderer to tell us if we really are or not. | 130 // the renderer to tell us if we really are or not. |
| 132 return TRUE; | 131 return TRUE; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 delegate()->OnReceiveDataFromGtk(data); | 213 delegate()->OnReceiveDataFromGtk(data); |
| 215 } else { | 214 } else { |
| 216 delegate()->OnReceiveProcessedData(drop_data_->url, | 215 delegate()->OnReceiveProcessedData(drop_data_->url, |
| 217 drop_data_->url_title); | 216 drop_data_->url_title); |
| 218 } | 217 } |
| 219 } | 218 } |
| 220 | 219 |
| 221 if (data_requests_ == 0) { | 220 if (data_requests_ == 0) { |
| 222 // Tell the renderer about the drag. | 221 // Tell the renderer about the drag. |
| 223 // |x| and |y| are seemingly arbitrary at this point. | 222 // |x| and |y| are seemingly arbitrary at this point. |
| 224 web_contents_->GetRenderViewHost()-> | 223 GetRenderViewHost()->DragTargetDragEnter( |
| 225 DragTargetDragEnter(*drop_data_.get(), | 224 *drop_data_.get(), |
| 226 ui::ClientPoint(widget_), | 225 ui::ClientPoint(widget_), |
| 227 ui::ScreenPoint(widget_), | 226 ui::ScreenPoint(widget_), |
| 228 content::GdkDragActionToWebDragOp(context->actions)); | 227 content::GdkDragActionToWebDragOp(context->actions)); |
| 229 | 228 |
| 230 if (delegate()) | 229 if (delegate()) |
| 231 delegate()->OnDragEnter(); | 230 delegate()->OnDragEnter(); |
| 232 | 231 |
| 233 drag_over_time_ = time; | 232 drag_over_time_ = time; |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 | 235 |
| 237 // The drag has left our widget; forward this information to the renderer. | 236 // The drag has left our widget; forward this information to the renderer. |
| 238 void WebDragDestGtk::OnDragLeave(GtkWidget* sender, GdkDragContext* context, | 237 void WebDragDestGtk::OnDragLeave(GtkWidget* sender, GdkDragContext* context, |
| 239 guint time) { | 238 guint time) { |
| 240 // Set |context_| to NULL to make sure we will recognize the next DragMotion | 239 // Set |context_| to NULL to make sure we will recognize the next DragMotion |
| 241 // as an enter. | 240 // as an enter. |
| 242 context_ = NULL; | 241 context_ = NULL; |
| 243 drop_data_.reset(); | 242 drop_data_.reset(); |
| 244 // When GTK sends us a drag-drop signal, it is shortly (and synchronously) | 243 // When GTK sends us a drag-drop signal, it is shortly (and synchronously) |
| 245 // preceded by a drag-leave. The renderer doesn't like getting the signals | 244 // preceded by a drag-leave. The renderer doesn't like getting the signals |
| 246 // in this order so delay telling it about the drag-leave till we are sure | 245 // in this order so delay telling it about the drag-leave till we are sure |
| 247 // we are not getting a drop as well. | 246 // we are not getting a drop as well. |
| 248 MessageLoop::current()->PostTask(FROM_HERE, | 247 MessageLoop::current()->PostTask(FROM_HERE, |
| 249 base::Bind(&WebDragDestGtk::DragLeave, method_factory_.GetWeakPtr())); | 248 base::Bind(&WebDragDestGtk::DragLeave, method_factory_.GetWeakPtr())); |
| 250 } | 249 } |
| 251 | 250 |
| 252 // Called by GTK when the user releases the mouse, executing a drop. | 251 // Called by GTK when the user releases the mouse, executing a drop. |
| 253 gboolean WebDragDestGtk::OnDragDrop(GtkWidget* sender, GdkDragContext* context, | 252 gboolean WebDragDestGtk::OnDragDrop(GtkWidget* sender, GdkDragContext* context, |
| 254 gint x, gint y, guint time) { | 253 gint x, gint y, guint time) { |
| 255 // Cancel that drag leave! | 254 // Cancel that drag leave! |
| 256 method_factory_.InvalidateWeakPtrs(); | 255 method_factory_.InvalidateWeakPtrs(); |
| 257 | 256 |
| 258 web_contents_->GetRenderViewHost()-> | 257 GetRenderViewHost()-> |
| 259 DragTargetDrop(ui::ClientPoint(widget_), ui::ScreenPoint(widget_)); | 258 DragTargetDrop(ui::ClientPoint(widget_), ui::ScreenPoint(widget_)); |
| 260 | 259 |
| 261 if (delegate()) | 260 if (delegate()) |
| 262 delegate()->OnDrop(); | 261 delegate()->OnDrop(); |
| 263 | 262 |
| 264 // The second parameter is just an educated guess as to whether or not the | 263 // The second parameter is just an educated guess as to whether or not the |
| 265 // drag succeeded, but at least we will get the drag-end animation right | 264 // drag succeeded, but at least we will get the drag-end animation right |
| 266 // sometimes. | 265 // sometimes. |
| 267 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 266 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
| 268 | 267 |
| 269 return TRUE; | 268 return TRUE; |
| 270 } | 269 } |
| 271 | 270 |
| 271 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { |
| 272 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
| 273 } |
| 274 |
| 272 } // namespace content | 275 } // namespace content |
| OLD | NEW |