Chromium Code Reviews| 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/web_contents/web_drag_dest_gtk.h" | 5 #include "content/browser/web_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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 widget_(widget), | 51 widget_(widget), |
| 52 context_(NULL), | 52 context_(NULL), |
| 53 data_requests_(0), | 53 data_requests_(0), |
| 54 delegate_(NULL), | 54 delegate_(NULL), |
| 55 method_factory_(this) { | 55 method_factory_(this) { |
| 56 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), | 56 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), |
| 57 NULL, 0, | 57 NULL, 0, |
| 58 static_cast<GdkDragAction>(GDK_ACTION_COPY | | 58 static_cast<GdkDragAction>(GDK_ACTION_COPY | |
| 59 GDK_ACTION_LINK | | 59 GDK_ACTION_LINK | |
| 60 GDK_ACTION_MOVE)); | 60 GDK_ACTION_MOVE)); |
| 61 g_signal_connect(widget, "drag-motion", | 61 |
| 62 G_CALLBACK(OnDragMotionThunk), this); | 62 // If adding a handler, make sure to also update the number of handlers in |
| 63 g_signal_connect(widget, "drag-leave", | 63 // ~WebDragDestGtk. |
| 64 G_CALLBACK(OnDragLeaveThunk), this); | 64 handlers_.reset(new int[5]); |
|
Charlie Reis
2013/03/14 22:08:38
Magic numbers aren't good. Better to declare a kN
mthiesse
2013/03/15 15:26:49
Done.
| |
| 65 g_signal_connect(widget, "drag-drop", | 65 handlers_.get()[0] = g_signal_connect( |
| 66 G_CALLBACK(OnDragDropThunk), this); | 66 widget, "drag-motion", G_CALLBACK(OnDragMotionThunk), this); |
| 67 g_signal_connect(widget, "drag-data-received", | 67 handlers_.get()[1] = g_signal_connect( |
| 68 G_CALLBACK(OnDragDataReceivedThunk), this); | 68 widget, "drag-leave", G_CALLBACK(OnDragLeaveThunk), this); |
| 69 handlers_.get()[2] = g_signal_connect( | |
| 70 widget, "drag-drop", G_CALLBACK(OnDragDropThunk), this); | |
| 71 handlers_.get()[3] = g_signal_connect( | |
| 72 widget, "drag-data-received", G_CALLBACK(OnDragDataReceivedThunk), this); | |
| 69 // TODO(tony): Need a drag-data-delete handler for moving content out of | 73 // TODO(tony): Need a drag-data-delete handler for moving content out of |
| 70 // the WebContents. http://crbug.com/38989 | 74 // the WebContents. http://crbug.com/38989 |
| 71 | 75 |
| 72 destroy_handler_ = g_signal_connect( | 76 handlers_.get()[4] = g_signal_connect( |
| 73 widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_); | 77 widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_); |
| 74 } | 78 } |
| 75 | 79 |
| 76 WebDragDestGtk::~WebDragDestGtk() { | 80 WebDragDestGtk::~WebDragDestGtk() { |
| 77 if (widget_) { | 81 if (widget_) { |
| 78 gtk_drag_dest_unset(widget_); | 82 gtk_drag_dest_unset(widget_); |
| 79 g_signal_handler_disconnect(widget_, destroy_handler_); | 83 for (int i = 0; i < 5; ++i) |
| 84 g_signal_handler_disconnect(widget_, handlers_.get()[i]); | |
| 80 } | 85 } |
| 81 } | 86 } |
| 82 | 87 |
| 83 void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { | 88 void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { |
| 84 if (context_) { | 89 if (context_) { |
| 85 is_drop_target_ = operation != WebDragOperationNone; | 90 is_drop_target_ = operation != WebDragOperationNone; |
| 86 gdk_drag_status(context_, WebDragOpToGdkDragAction(operation), | 91 gdk_drag_status(context_, WebDragOpToGdkDragAction(operation), |
| 87 drag_over_time_); | 92 drag_over_time_); |
| 88 } | 93 } |
| 89 } | 94 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 306 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
| 302 | 307 |
| 303 return TRUE; | 308 return TRUE; |
| 304 } | 309 } |
| 305 | 310 |
| 306 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { | 311 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { |
| 307 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); | 312 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
| 308 } | 313 } |
| 309 | 314 |
| 310 } // namespace content | 315 } // namespace content |
| OLD | NEW |