| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/web_contents/drag_utils_gtk.h" | 14 #include "content/browser/web_contents/drag_utils_gtk.h" |
| 15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
| 16 #include "content/public/browser/web_drag_dest_delegate.h" | 16 #include "content/public/browser/web_drag_dest_delegate.h" |
| 17 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 20 #include "ui/base/clipboard/custom_data_helper.h" | 20 #include "ui/base/clipboard/custom_data_helper.h" |
| 21 #include "ui/base/dragdrop/gtk_dnd_util.h" | 21 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| 22 #include "ui/base/gtk/gtk_screen_util.h" | 22 #include "ui/base/gtk/gtk_screen_util.h" |
| 23 | 23 |
| 24 using WebKit::WebDragOperation; | 24 using WebKit::WebDragOperation; |
| 25 using WebKit::WebDragOperationNone; | 25 using WebKit::WebDragOperationNone; |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 const int kNumGtkHandlers = 5; |
| 30 | 31 |
| 31 int GetModifierFlags(GtkWidget* widget) { | 32 int GetModifierFlags(GtkWidget* widget) { |
| 32 int modifier_state = 0; | 33 int modifier_state = 0; |
| 33 GdkModifierType state; | 34 GdkModifierType state; |
| 34 gdk_window_get_pointer(gtk_widget_get_window(widget), NULL, NULL, &state); | 35 gdk_window_get_pointer(gtk_widget_get_window(widget), NULL, NULL, &state); |
| 35 | 36 |
| 36 if (state & GDK_SHIFT_MASK) | 37 if (state & GDK_SHIFT_MASK) |
| 37 modifier_state |= WebKit::WebInputEvent::ShiftKey; | 38 modifier_state |= WebKit::WebInputEvent::ShiftKey; |
| 38 if (state & GDK_CONTROL_MASK) | 39 if (state & GDK_CONTROL_MASK) |
| 39 modifier_state |= WebKit::WebInputEvent::ControlKey; | 40 modifier_state |= WebKit::WebInputEvent::ControlKey; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 widget_(widget), | 52 widget_(widget), |
| 52 context_(NULL), | 53 context_(NULL), |
| 53 data_requests_(0), | 54 data_requests_(0), |
| 54 delegate_(NULL), | 55 delegate_(NULL), |
| 55 method_factory_(this) { | 56 method_factory_(this) { |
| 56 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), | 57 gtk_drag_dest_set(widget, static_cast<GtkDestDefaults>(0), |
| 57 NULL, 0, | 58 NULL, 0, |
| 58 static_cast<GdkDragAction>(GDK_ACTION_COPY | | 59 static_cast<GdkDragAction>(GDK_ACTION_COPY | |
| 59 GDK_ACTION_LINK | | 60 GDK_ACTION_LINK | |
| 60 GDK_ACTION_MOVE)); | 61 GDK_ACTION_MOVE)); |
| 61 g_signal_connect(widget, "drag-motion", | 62 |
| 62 G_CALLBACK(OnDragMotionThunk), this); | 63 // If adding a handler, make sure to update kNumGtkHandlers and add it to the |
| 63 g_signal_connect(widget, "drag-leave", | 64 // |handlers_| array so that it can be disconnected later on. |
| 64 G_CALLBACK(OnDragLeaveThunk), this); | 65 handlers_.reset(new int[kNumGtkHandlers]); |
| 65 g_signal_connect(widget, "drag-drop", | 66 handlers_.get()[0] = g_signal_connect( |
| 66 G_CALLBACK(OnDragDropThunk), this); | 67 widget, "drag-motion", G_CALLBACK(OnDragMotionThunk), this); |
| 67 g_signal_connect(widget, "drag-data-received", | 68 handlers_.get()[1] = g_signal_connect( |
| 68 G_CALLBACK(OnDragDataReceivedThunk), this); | 69 widget, "drag-leave", G_CALLBACK(OnDragLeaveThunk), this); |
| 70 handlers_.get()[2] = g_signal_connect( |
| 71 widget, "drag-drop", G_CALLBACK(OnDragDropThunk), this); |
| 72 handlers_.get()[3] = g_signal_connect( |
| 73 widget, "drag-data-received", G_CALLBACK(OnDragDataReceivedThunk), this); |
| 69 // TODO(tony): Need a drag-data-delete handler for moving content out of | 74 // TODO(tony): Need a drag-data-delete handler for moving content out of |
| 70 // the WebContents. http://crbug.com/38989 | 75 // the WebContents. http://crbug.com/38989 |
| 71 | 76 |
| 72 destroy_handler_ = g_signal_connect( | 77 handlers_.get()[4] = g_signal_connect( |
| 73 widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_); | 78 widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_); |
| 74 } | 79 } |
| 75 | 80 |
| 76 WebDragDestGtk::~WebDragDestGtk() { | 81 WebDragDestGtk::~WebDragDestGtk() { |
| 77 if (widget_) { | 82 if (widget_) { |
| 78 gtk_drag_dest_unset(widget_); | 83 gtk_drag_dest_unset(widget_); |
| 79 g_signal_handler_disconnect(widget_, destroy_handler_); | 84 for (int i = 0; i < kNumGtkHandlers; ++i) |
| 85 g_signal_handler_disconnect(widget_, handlers_.get()[i]); |
| 80 } | 86 } |
| 81 } | 87 } |
| 82 | 88 |
| 83 void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { | 89 void WebDragDestGtk::UpdateDragStatus(WebDragOperation operation) { |
| 84 if (context_) { | 90 if (context_) { |
| 85 is_drop_target_ = operation != WebDragOperationNone; | 91 is_drop_target_ = operation != WebDragOperationNone; |
| 86 gdk_drag_status(context_, WebDragOpToGdkDragAction(operation), | 92 gdk_drag_status(context_, WebDragOpToGdkDragAction(operation), |
| 87 drag_over_time_); | 93 drag_over_time_); |
| 88 } | 94 } |
| 89 } | 95 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 307 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
| 302 | 308 |
| 303 return TRUE; | 309 return TRUE; |
| 304 } | 310 } |
| 305 | 311 |
| 306 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { | 312 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { |
| 307 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); | 313 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
| 308 } | 314 } |
| 309 | 315 |
| 310 } // namespace content | 316 } // namespace content |
| OLD | NEW |