diff options
author | Steve Block <steveblock@google.com> | 2009-10-08 17:19:54 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2009-10-20 00:41:58 +0100 |
commit | 231d4e3152a9c27a73b6ac7badbe6be673aa3ddf (patch) | |
tree | a6c7e2d6cd7bfa7011cc39abbb436142d7a4a7c8 /WebKit/gtk/WebCoreSupport/DragClientGtk.cpp | |
parent | e196732677050bd463301566a68a643b6d14b907 (diff) | |
download | external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.zip external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.gz external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.bz2 |
Merge webkit.org at R49305 : Automatic merge by git.
Change-Id: I8968561bc1bfd72b8923b7118d3728579c6dbcc7
Diffstat (limited to 'WebKit/gtk/WebCoreSupport/DragClientGtk.cpp')
-rw-r--r-- | WebKit/gtk/WebCoreSupport/DragClientGtk.cpp | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp b/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp index f55b6ea..f4b0df1 100644 --- a/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp @@ -17,20 +17,36 @@ #include "config.h" #include "DragClientGtk.h" +#include "Document.h" +#include "Element.h" +#include "Frame.h" #include "NotImplemented.h" +#include "RenderObject.h" +#include "webkitwebview.h" + +#include <gtk/gtk.h> +#if !GTK_CHECK_VERSION(2, 14, 0) +#define gtk_widget_get_window(widget) (widget)->window +#endif using namespace WebCore; namespace WebKit { +DragClient::DragClient(WebKitWebView* webView) + : m_webView(webView) + , m_startPos(0, 0) +{ +} + void DragClient::willPerformDragDestinationAction(DragDestinationAction, DragData*) { notImplemented(); } -void DragClient::willPerformDragSourceAction(DragSourceAction, const IntPoint&, Clipboard*) +void DragClient::willPerformDragSourceAction(DragSourceAction, const IntPoint& startPos, Clipboard*) { - notImplemented(); + m_startPos = startPos; } DragDestinationAction DragClient::actionMaskForDrag(DragData*) @@ -45,12 +61,53 @@ DragSourceAction DragClient::dragSourceActionMaskForPoint(const IntPoint&) return DragSourceActionAny; } -void DragClient::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard*, Frame*, bool) +void DragClient::startDrag(DragImageRef image, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard*, Frame* frame, bool linkDrag) { - notImplemented(); + Element* targetElement = frame->document()->elementFromPoint(m_startPos.x(), m_startPos.y()); + bool imageDrag = false; + + if (targetElement) + imageDrag = targetElement->renderer()->isImage(); + + GdkAtom textHtml = gdk_atom_intern_static_string("text/html"); + GdkAtom netscapeUrl = gdk_atom_intern_static_string("_NETSCAPE_URL"); + + GtkTargetList* targetList = gtk_target_list_new(NULL, 0); + gtk_target_list_add(targetList, textHtml, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML); + gtk_target_list_add_text_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT); + + if (linkDrag || imageDrag) { + gtk_target_list_add(targetList, netscapeUrl, 0, WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL); + gtk_target_list_add_uri_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST); + } + + if (imageDrag) + gtk_target_list_add_image_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE, false); + + GdkDragAction dragAction = GDK_ACTION_COPY; + if (linkDrag) { + dragAction = GDK_ACTION_LINK; + if (imageDrag) + dragAction = (GdkDragAction)(dragAction | GDK_ACTION_COPY); + } + + GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); + reinterpret_cast<GdkEventButton*>(event)->window = gtk_widget_get_window(GTK_WIDGET(m_webView)); + reinterpret_cast<GdkEventButton*>(event)->time = GDK_CURRENT_TIME; + + GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(m_webView), + targetList, dragAction, 1, event); + g_object_ref(context); + + if (image) + gtk_drag_set_icon_pixbuf(context, image, eventPos.x() - dragImageOrigin.x(), eventPos.y() - dragImageOrigin.y()); + else + gtk_drag_set_icon_default(context); + + gtk_target_list_unref(targetList); } -DragImageRef DragClient::createDragImageForLink(KURL&, const String& label, Frame*) +DragImageRef DragClient::createDragImageForLink(KURL&, const String&, Frame*) { notImplemented(); return 0; @@ -61,4 +118,3 @@ void DragClient::dragControllerDestroyed() delete this; } } - |