Changeset 97012 in webkit


Ignore:
Timestamp:
Oct 8, 2011 10:46:00 AM (13 years ago)
Author:
Martin Robinson
Message:

[GTK] Implement drag and drop support in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=63706

Reviewed by Philippe Normand.

Source/WebCore:

  • platform/DragData.h:
  • platform/gtk/DataObjectGtk.cpp:

(WebCore::DataObjectGtk::text): Mark as const.
(WebCore::DataObjectGtk::markup): Ditto.
(WebCore::DataObjectGtk::urlLabel): Ditto.

  • platform/gtk/DataObjectGtk.h: Remove unused member

m_dragContext.
(WebCore::DataObjectGtk::url): Mark as const.
(WebCore::DataObjectGtk::uriList): Ditto.
(WebCore::DataObjectGtk::filenames): Ditto.
(WebCore::DataObjectGtk::image): Ditto.
(WebCore::DataObjectGtk::hasText): Ditto.
(WebCore::DataObjectGtk::hasMarkup): Ditto.
(WebCore::DataObjectGtk::hasURIList): Ditto.
(WebCore::DataObjectGtk::hasURL): Ditto.
(WebCore::DataObjectGtk::hasFilenames): Ditto.
(WebCore::DataObjectGtk::hasImage): Ditto.

  • platform/gtk/DragIcon.cpp: Added. A helper which takes care of

creating a transparent drag window for drags.

  • platform/gtk/DragIcon.h: Added.

Source/WebKit2:

  • GNUmakefile.am: Add new files to compilation.
  • Shared/gtk/ArgumentCodersGtk.cpp: Added.

(CoreIPC::encodeImage): Encode a GdkPixbuf.
(CoreIPC::decodeImage): Decode a GdkPixbuf.
(CoreIPC::encodeDataObject): Encode a DataObjectGtk.
(CoreIPC::decodeDataObject): Decode a DataObjectGtk.
(CoreIPC::::encode): Encode DragData.
(CoreIPC::::decode): Decode DragData.

  • Shared/gtk/ArgumentCodersGtk.h:
  • UIProcess/API/gtk/PageClientImpl.cpp:

(WebKit::PageClientImpl::startDrag):

  • UIProcess/API/gtk/PageClientImpl.h:
  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkit_web_view_base_init): Set the view as a potential drop destination.
(webkitWebViewBaseDragDataGet): Added, delegate to GtkDragAndDropHelper.
(webkitWebViewBaseDragEnd): Ditto.
(webkitWebViewBaseDragDataReceived): Ditto.
(webkitWebViewBaseDragEnter): Ditto.
(webkitWebViewBaseDragMotion): Ditto.
(doDragLeaveLater): Ditto.
(webkitWebViewBaseDragLeave): Ditto.
(webkitWebViewBaseDragDrop): Ditto.
(webkit_web_view_base_class_init): Override GtkWidget drag and drop methods.
(webkitWebViewBaseStartDrag): Calls gtk_drag_begin() to start a drag operation.

  • UIProcess/API/gtk/WebKitWebViewBasePrivate.h: Add webkitWebViewBaseStartDrag().
  • UIProcess/PageClient.h: Add startDrag().
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::performDragControllerAction): Share the Qt version.

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • WebProcess/WebCoreSupport/WebDragClient.cpp:
  • WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp: Added.
  • WebProcess/WebPage/WebPage.cpp: Add drag support for GTK+.
  • WebProcess/WebPage/WebPage.h: Ditto.
  • WebProcess/WebPage/WebPage.messages.in: Ditto.
Location:
trunk/Source
Files:
3 added
22 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r97009 r97012  
     12011-10-03  Carlos Garcia Campos  <cgarcia@igalia.com> and Martin Robinson  <mrobinson@igalia.com>
     2
     3        [GTK] Implement drag and drop support in WebKit2
     4        https://bugs.webkit.org/show_bug.cgi?id=63706
     5
     6        Reviewed by Philippe Normand.
     7
     8        * platform/DragData.h:
     9        * platform/gtk/DataObjectGtk.cpp:
     10        (WebCore::DataObjectGtk::text): Mark as const.
     11        (WebCore::DataObjectGtk::markup): Ditto.
     12        (WebCore::DataObjectGtk::urlLabel): Ditto.
     13        * platform/gtk/DataObjectGtk.h: Remove unused member
     14        m_dragContext.
     15        (WebCore::DataObjectGtk::url): Mark as const.
     16        (WebCore::DataObjectGtk::uriList): Ditto.
     17        (WebCore::DataObjectGtk::filenames): Ditto.
     18        (WebCore::DataObjectGtk::image): Ditto.
     19        (WebCore::DataObjectGtk::hasText): Ditto.
     20        (WebCore::DataObjectGtk::hasMarkup): Ditto.
     21        (WebCore::DataObjectGtk::hasURIList): Ditto.
     22        (WebCore::DataObjectGtk::hasURL): Ditto.
     23        (WebCore::DataObjectGtk::hasFilenames): Ditto.
     24        (WebCore::DataObjectGtk::hasImage): Ditto.
     25        * platform/gtk/DragIcon.cpp: Added. A helper which takes care of
     26        creating a transparent drag window for drags.
     27        * platform/gtk/DragIcon.h: Added.
     28
    1292011-10-08  Abhishek Arya  <inferno@chromium.org>
    230
  • trunk/Source/WebCore/GNUmakefile.list.am

    r96966 r97012  
    40094009        Source/WebCore/platform/gtk/DataObjectGtk.h \
    40104010        Source/WebCore/platform/gtk/DragDataGtk.cpp \
     4011        Source/WebCore/platform/gtk/DragIcon.cpp \
     4012        Source/WebCore/platform/gtk/DragIcon.h \
    40114013        Source/WebCore/platform/gtk/DragImageGtk.cpp \
    40124014        Source/WebCore/platform/gtk/EventLoopGtk.cpp \
  • trunk/Source/WebCore/platform/DragData.h

    r95922 r97012  
    121121#endif
    122122
    123 #if PLATFORM(QT)
     123#if PLATFORM(QT) || PLATFORM(GTK)
    124124    // This constructor should used only by WebKit2 IPC because DragData
    125125    // is initialized by the decoder and not in the constructor.
  • trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp

    r95901 r97012  
    3434}
    3535
    36 String DataObjectGtk::text()
     36String DataObjectGtk::text() const
    3737{
    3838    if (m_range)
     
    4141}
    4242
    43 String DataObjectGtk::markup()
     43String DataObjectGtk::markup() const
    4444{
    4545    if (m_range)
     
    134134}
    135135
    136 String DataObjectGtk::urlLabel()
     136String DataObjectGtk::urlLabel() const
    137137{
    138138    if (hasText())
  • trunk/Source/WebCore/platform/gtk/DataObjectGtk.h

    r95901 r97012  
    3737    }
    3838
    39     const KURL& url() { return m_url; }
    40     const String& uriList() { return m_uriList; }
    41     const Vector<String>& filenames() { return m_filenames; }
    42     GdkPixbuf* image() { return m_image.get(); }
     39    const KURL& url() const { return m_url; }
     40    const String& uriList() const { return m_uriList; }
     41    const Vector<String>& filenames() const { return m_filenames; }
     42    GdkPixbuf* image() const { return m_image.get(); }
    4343    void setRange(PassRefPtr<Range> newRange) { m_range = newRange; }
    4444    void setImage(GdkPixbuf* newImage) { m_image = newImage; }
    45     void setDragContext(GdkDragContext* newDragContext) { m_dragContext = newDragContext; }
    4645    void setURL(const KURL&, const String&);
    47     bool hasText() { return m_range || !m_text.isEmpty(); }
    48     bool hasMarkup() { return m_range || !m_markup.isEmpty(); }
    49     bool hasURIList() { return !m_uriList.isEmpty(); }
    50     bool hasURL() { return !m_url.isEmpty() && m_url.isValid(); }
    51     bool hasFilenames() { return !m_filenames.isEmpty(); }
    52     bool hasImage() { return m_image; }
     46    bool hasText() const { return m_range || !m_text.isEmpty(); }
     47    bool hasMarkup() const { return m_range || !m_markup.isEmpty(); }
     48    bool hasURIList() const { return !m_uriList.isEmpty(); }
     49    bool hasURL() const { return !m_url.isEmpty() && m_url.isValid(); }
     50    bool hasFilenames() const { return !m_filenames.isEmpty(); }
     51    bool hasImage() const { return m_image; }
    5352    void clearURIList() { m_uriList = ""; }
    5453    void clearURL() { m_url = KURL(); }
    5554    void clearImage() { m_image = 0; }
    56     GdkDragContext* dragContext() { return m_dragContext.get(); }
    5755
    58     String text();
    59     String markup();
     56    String text() const;
     57    String markup() const;
    6058    void setText(const String&);
    6159    void setMarkup(const String&);
    6260    void setURIList(const String&);
    63     String urlLabel();
     61    String urlLabel() const;
    6462    void clear();
    6563    void clearText();
     
    7573    Vector<String> m_filenames;
    7674    GRefPtr<GdkPixbuf> m_image;
    77     GRefPtr<GdkDragContext> m_dragContext;
    7875    RefPtr<Range> m_range;
    7976};
  • trunk/Source/WebCore/platform/gtk/DragIcon.h

    r97011 r97012  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
    3  * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
    42 * Copyright (C) 2011 Igalia S.L.
    53 *
     
    2624 */
    2725
    28 #ifndef WebKitWebViewBasePrivate_h
    29 #define WebKitWebViewBasePrivate_h
     26#ifndef DragIcon_h
     27#define DragIcon_h
    3028
    31 #include "WebKitWebViewBase.h"
    32 #include "WebPageProxy.h"
    33 #include <WebKit2/WebKit2.h>
     29#include "IntPoint.h"
     30#include <RefPtrCairo.h>
    3431
    35 using namespace WebKit;
     32namespace WebCore {
    3633
    37 G_BEGIN_DECLS
     34class DragIcon {
     35public:
     36    DragIcon();
     37    virtual ~DragIcon();
    3838
    39 WebKitWebViewBase* webkitWebViewBaseCreate(WebContext*, WebPageGroup*);
     39    void draw(cairo_t*);
     40    void setImage(cairo_surface_t*);
     41    void useForDrag(GdkDragContext*);
     42    void useForDrag(GdkDragContext*, const IntPoint& hotspot);
    4043
    41 GtkIMContext* webkitWebViewBaseGetIMContext(WebKitWebViewBase*);
     44private:
     45    GtkWidget* m_window;
     46    RefPtr<cairo_surface_t> m_image;
     47    IntSize m_imageSize;
     48};
    4249
    43 WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase*);
     50}
    4451
    45 void webkitWebViewBaseCreateWebPage(WebKitWebViewBase*, WKContextRef, WKPageGroupRef);
    46 
    47 void webkitWebViewBaseSetTooltipText(WebKitWebViewBase*, const char*);
    48 
    49 void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase*);
    50 
    51 G_END_DECLS
    52 
    53 #endif // WebKitWebViewBasePrivate_h
     52#endif // DragIcon_h
  • trunk/Source/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp

    r96299 r97012  
    4343namespace WebKit {
    4444
    45 #ifdef GTK_API_VERSION_2
    46 static gboolean dragIconWindowDrawEventCallback(GtkWidget* widget, GdkEventExpose* event, DragClient* client)
    47 {
    48     RefPtr<cairo_t> context = adoptRef(gdk_cairo_create(event->window));
    49     client->drawDragIconWindow(widget, context.get());
    50     return TRUE;
    51 }
    52 #else
    53 static gboolean dragIconWindowDrawEventCallback(GtkWidget* widget, cairo_t* context, DragClient* client)
    54 {
    55     if (!gdk_cairo_get_clip_rectangle(context, 0))
    56         return FALSE;
    57     client->drawDragIconWindow(widget, context);
    58     return TRUE;
    59 }
    60 #endif // GTK_API_VERSION_2
    61 
    6245DragClient::DragClient(WebKitWebView* webView)
    6346    : m_webView(webView)
    6447    , m_startPos(0, 0)
    65     , m_dragIconWindow(gtk_window_new(GTK_WINDOW_POPUP))
    6648{
    67 #ifdef GTK_API_VERSION_2
    68     g_signal_connect(m_dragIconWindow, "expose-event", G_CALLBACK(dragIconWindowDrawEventCallback), this);
    69 #else
    70     g_signal_connect(m_dragIconWindow, "draw", G_CALLBACK(dragIconWindowDrawEventCallback), this);
    71 #endif
    7249}
    7350
    7451DragClient::~DragClient()
    7552{
    76     gtk_widget_destroy(m_dragIconWindow);
    7753}
    7854
     
    11490    webView->priv->clickCounter.reset();
    11591
    116     // This strategy originally comes from Chromium:
    117     // src/chrome/browser/gtk/tab_contents_drag_source.cc
    11892    if (image) {
    119         m_dragImage = image;
    120         IntSize imageSize(cairo_image_surface_get_width(image), cairo_image_surface_get_height(image));
    121         gtk_window_resize(GTK_WINDOW(m_dragIconWindow), imageSize.width(), imageSize.height());
    122 
    123         if (!gtk_widget_get_realized(m_dragIconWindow)) {
    124             GdkScreen* screen = gtk_widget_get_screen(m_dragIconWindow);
    125 #ifdef GTK_API_VERSION_2
    126             GdkColormap* rgba = gdk_screen_get_rgba_colormap(screen);
    127             if (rgba)
    128                 gtk_widget_set_colormap(m_dragIconWindow, rgba);
    129 #else
    130             GdkVisual* visual = gdk_screen_get_rgba_visual(screen);
    131             if (!visual)
    132                 visual = gdk_screen_get_system_visual(screen);
    133             gtk_widget_set_visual(m_dragIconWindow, visual);
    134 #endif // GTK_API_VERSION_2
    135         }
    136 
    137         IntSize origin = eventPos - dragImageOrigin;
    138         gtk_drag_set_icon_widget(context, m_dragIconWindow,
    139                                  origin.width(), origin.height());
     93        m_dragIcon.setImage(image);
     94        m_dragIcon.useForDrag(context, IntPoint(eventPos - dragImageOrigin));
    14095    } else
    14196        gtk_drag_set_icon_default(context);
    142 }
    143 
    144 void DragClient::drawDragIconWindow(GtkWidget* widget, cairo_t* context)
    145 {
    146     cairo_rectangle(context, 0, 0,
    147                     cairo_image_surface_get_width(m_dragImage.get()),
    148                     cairo_image_surface_get_height(m_dragImage.get()));
    149     cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);
    150     cairo_set_source_surface(context, m_dragImage.get(), 0, 0);
    151     cairo_fill(context);
    15297}
    15398
  • trunk/Source/WebKit/gtk/WebCoreSupport/DragClientGtk.h

    r77870 r97012  
    3232
    3333#include "DragClient.h"
     34#include "DragIcon.h"
    3435#include "GRefPtr.h"
    35 #include "RefPtrCairo.h"
    3636
    3737typedef struct _WebKitWebView WebKitWebView;
     
    5454        virtual void dragControllerDestroyed();
    5555
    56         void drawDragIconWindow(GtkWidget*, cairo_t*);
    57 
    5856    private:
    5957        WebKitWebView* m_webView;
    6058        WebCore::IntPoint m_startPos;
    61         GtkWidget* m_dragIconWindow;
    62         RefPtr<cairo_surface_t> m_dragImage;
     59        WebCore::DragIcon m_dragIcon;
    6360    };
    6461}
  • trunk/Source/WebKit2/ChangeLog

    r97010 r97012  
     12011-10-03  Carlos Garcia Campos  <cgarcia@igalia.com> and Martin Robinson  <mrobinson@igalia.com>
     2
     3        [GTK] Implement drag and drop support in WebKit2
     4        https://bugs.webkit.org/show_bug.cgi?id=63706
     5
     6        Reviewed by Philippe Normand.
     7
     8        * GNUmakefile.am: Add new files to compilation.
     9        * Shared/gtk/ArgumentCodersGtk.cpp: Added.
     10        (CoreIPC::encodeImage): Encode a GdkPixbuf.
     11        (CoreIPC::decodeImage): Decode a GdkPixbuf.
     12        (CoreIPC::encodeDataObject): Encode a DataObjectGtk.
     13        (CoreIPC::decodeDataObject): Decode a DataObjectGtk.
     14        (CoreIPC::::encode): Encode DragData.
     15        (CoreIPC::::decode): Decode DragData.
     16        * Shared/gtk/ArgumentCodersGtk.h:
     17        * UIProcess/API/gtk/PageClientImpl.cpp:
     18        (WebKit::PageClientImpl::startDrag):
     19        * UIProcess/API/gtk/PageClientImpl.h:
     20        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     21        (webkit_web_view_base_init): Set the view as a potential drop destination.
     22        (webkitWebViewBaseDragDataGet): Added, delegate to GtkDragAndDropHelper.
     23        (webkitWebViewBaseDragEnd): Ditto.
     24        (webkitWebViewBaseDragDataReceived): Ditto.
     25        (webkitWebViewBaseDragEnter): Ditto.
     26        (webkitWebViewBaseDragMotion): Ditto.
     27        (doDragLeaveLater): Ditto.
     28        (webkitWebViewBaseDragLeave): Ditto.
     29        (webkitWebViewBaseDragDrop): Ditto.
     30        (webkit_web_view_base_class_init): Override GtkWidget drag and drop methods.
     31        (webkitWebViewBaseStartDrag): Calls gtk_drag_begin() to start a drag operation.
     32        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h: Add webkitWebViewBaseStartDrag().
     33        * UIProcess/PageClient.h: Add startDrag().
     34        * UIProcess/WebPageProxy.cpp:
     35        (WebKit::WebPageProxy::performDragControllerAction): Share the Qt version.
     36        * UIProcess/WebPageProxy.h:
     37        * UIProcess/WebPageProxy.messages.in:
     38        * WebProcess/WebCoreSupport/WebDragClient.cpp:
     39        * WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp: Added.
     40        * WebProcess/WebPage/WebPage.cpp: Add drag support for GTK+.
     41        * WebProcess/WebPage/WebPage.h: Ditto.
     42        * WebProcess/WebPage/WebPage.messages.in: Ditto.
     43
    1442011-10-08  Viatcheslav Ostapenko  <ostapenko.viatcheslav@nokia.com>
    245
  • trunk/Source/WebKit2/GNUmakefile.am

    r96821 r97012  
    284284        Source/WebKit2/Shared/cairo/LayerTreeContextCairo.cpp \
    285285        Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp \
     286        Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h \
     287        Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp \
    286288        Source/WebKit2/Shared/gtk/NativeWebKeyboardEventGtk.cpp \
    287289        Source/WebKit2/Shared/gtk/NativeWebMouseEventGtk.cpp \
     
    750752        Source/WebKit2/WebProcess/ResourceCache/WebResourceCacheManager.cpp \
    751753        Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebContextMenuClientGtk.cpp \
     754        Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp \
    752755        Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp \
    753756        Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebErrorsGtk.cpp \
  • trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h

    r97011 r97012  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
    3  * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
    42 * Copyright (C) 2011 Igalia S.L.
    53 *
     
    2624 */
    2725
    28 #ifndef WebKitWebViewBasePrivate_h
    29 #define WebKitWebViewBasePrivate_h
     26#ifndef ArgumentCodersGtk_h
     27#define ArgumentCodersGtk_h
    3028
    31 #include "WebKitWebViewBase.h"
    32 #include "WebPageProxy.h"
    33 #include <WebKit2/WebKit2.h>
     29#include "ArgumentCoders.h"
    3430
    35 using namespace WebKit;
     31namespace WebCore {
     32class DataObjectGtk;
     33class DragData;
     34}
    3635
    37 G_BEGIN_DECLS
     36namespace CoreIPC {
    3837
    39 WebKitWebViewBase* webkitWebViewBaseCreate(WebContext*, WebPageGroup*);
     38template<> struct ArgumentCoder<WebCore::DragData> {
     39    static void encode(ArgumentEncoder*, const WebCore::DragData&);
     40    static bool decode(ArgumentDecoder*, WebCore::DragData&);
     41};
    4042
    41 GtkIMContext* webkitWebViewBaseGetIMContext(WebKitWebViewBase*);
     43} // namespace CoreIPC
    4244
    43 WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase*);
    44 
    45 void webkitWebViewBaseCreateWebPage(WebKitWebViewBase*, WKContextRef, WKPageGroupRef);
    46 
    47 void webkitWebViewBaseSetTooltipText(WebKitWebViewBase*, const char*);
    48 
    49 void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase*);
    50 
    51 G_END_DECLS
    52 
    53 #endif // WebKitWebViewBasePrivate_h
     45#endif // ArgumentCodersGtk_h
  • trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp

    r95901 r97012  
    286286}
    287287
     288void PageClientImpl::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
     289{
     290    webkitWebViewBaseStartDrag(WEBKIT_WEB_VIEW_BASE(m_viewWidget), dragData, dragImage);
     291}
     292
    288293} // namespace WebKit
  • trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h

    r95901 r97012  
    8888    virtual void findStringInCustomRepresentation(const String&, FindOptions, unsigned);
    8989    virtual void countStringMatchesInCustomRepresentation(const String&, FindOptions, unsigned);
     90    virtual void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage);
    9091
    9192#if USE(ACCELERATED_COMPOSITING)
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r96680 r97012  
    2626#include "WebKitPrivate.h"
    2727#include "WebPageProxy.h"
     28#include <WebCore/DragIcon.h>
    2829#include <WebKit2/WKBase.h>
    2930#include <WebKit2/WKRetainPtr.h>
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r95901 r97012  
    2929#include "WebKitWebViewBase.h"
    3030
     31#include "ClipboardGtk.h"
     32#include "ClipboardUtilitiesGtk.h"
     33#include "DataObjectGtk.h"
     34#include "DragData.h"
    3135#include "DrawingAreaProxyImpl.h"
    3236#include "GOwnPtrGtk.h"
    3337#include "GtkClickCounter.h"
     38#include "GtkUtilities.h"
    3439#include "GtkVersioning.h"
    3540#include "NativeWebKeyboardEvent.h"
     
    3843#include "NotImplemented.h"
    3944#include "PageClientImpl.h"
     45#include "PasteboardHelper.h"
    4046#include "RefPtrCairo.h"
    4147#include "WebContext.h"
     
    4349#include "WebKitWebViewBasePrivate.h"
    4450#include "WebPageProxy.h"
     51#include <WebCore/DragIcon.h>
     52#include <WebCore/GtkDragAndDropHelper.h>
     53#include <WebCore/RefPtrCairo.h>
    4554#include <WebCore/Region.h>
    4655#include <WebKit2/WKContext.h>
     
    5867    GtkClickCounter clickCounter;
    5968    CString tooltipText;
     69    GtkDragAndDropHelper dragAndDropHelper;
     70    DragIcon dragIcon;
    6071};
    6172
     
    133144    priv->shouldForwardNextKeyEvent = FALSE;
    134145
    135     gtk_widget_set_double_buffered(GTK_WIDGET(webkitWebViewBase), FALSE);
    136     gtk_widget_set_can_focus(GTK_WIDGET(webkitWebViewBase), TRUE);
     146    GtkWidget* viewWidget = GTK_WIDGET(webkitWebViewBase);
     147    gtk_widget_set_double_buffered(viewWidget, FALSE);
     148    gtk_widget_set_can_focus(viewWidget, TRUE);
    137149    priv->imContext = gtk_im_multicontext_new();
    138150
    139     priv->pageClient = PageClientImpl::create(GTK_WIDGET(webkitWebViewBase));
     151    priv->pageClient = PageClientImpl::create(viewWidget);
     152
     153    priv->dragAndDropHelper.setWidget(viewWidget);
     154
     155    gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), 0, 0,
     156                      static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
     157    gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::defaultPasteboardHelper()->targetList());
    140158}
    141159
     
    291309    // receives a hit test result.
    292310    gtk_tooltip_set_text(tooltip, priv->tooltipText.data());
     311    return TRUE;
     312}
     313
     314static void webkitWebViewBaseDragDataGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint time)
     315{
     316    WEBKIT_WEB_VIEW_BASE(widget)->priv->dragAndDropHelper.handleGetDragData(context, selectionData, info);
     317}
     318
     319static void webkitWebViewBaseDragEnd(GtkWidget* widget, GdkDragContext* context)
     320{
     321    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     322    if (!webViewBase->priv->dragAndDropHelper.handleDragEnd(context))
     323        return;
     324
     325    GdkDevice* device = gdk_drag_context_get_device(context);
     326    int x = 0, y = 0;
     327    gdk_device_get_window_at_position(device, &x, &y);
     328    int xRoot = 0, yRoot = 0;
     329    gdk_device_get_position(device, 0, &xRoot, &yRoot);
     330    webViewBase->priv->pageProxy->dragEnded(IntPoint(x, y), IntPoint(xRoot, yRoot),
     331                                            gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context)));
     332}
     333
     334static void webkitWebViewBaseDragDataReceived(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* selectionData, guint info, guint time)
     335{
     336    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     337    OwnPtr<DragData> dragData(webViewBase->priv->dragAndDropHelper.handleDragDataReceived(context, selectionData, info));
     338    if (!dragData)
     339        return;
     340
     341    webViewBase->priv->pageProxy->resetDragOperation();
     342    webViewBase->priv->pageProxy->dragEntered(dragData.get());
     343    DragOperation operation = webViewBase->priv->pageProxy->dragOperation();
     344    gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
     345}
     346
     347static gboolean webkitWebViewBaseDragMotion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
     348{
     349    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     350    OwnPtr<DragData> dragData(webViewBase->priv->dragAndDropHelper.handleDragMotion(context, IntPoint(x, y), time));
     351    if (!dragData)
     352        return TRUE;
     353
     354    webViewBase->priv->pageProxy->dragUpdated(dragData.get());
     355    DragOperation operation = webViewBase->priv->pageProxy->dragOperation();
     356    gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
     357    return TRUE;
     358}
     359
     360static void dragExitedCallback(GtkWidget* widget, DragData* dragData, bool dropHappened)
     361{
     362    // Don't call dragExited if we have just received a drag-drop signal. This
     363    // happens in the case of a successful drop onto the view.
     364    if (dropHappened)
     365        return;
     366
     367    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     368    webViewBase->priv->pageProxy->dragExited(dragData);
     369    webViewBase->priv->pageProxy->resetDragOperation();
     370}
     371
     372static void webkitWebViewBaseDragLeave(GtkWidget* widget, GdkDragContext* context, guint time)
     373{
     374    WEBKIT_WEB_VIEW_BASE(widget)->priv->dragAndDropHelper.handleDragLeave(context, dragExitedCallback);
     375}
     376
     377static gboolean webkitWebViewBaseDragDrop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
     378{
     379    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
     380    OwnPtr<DragData> dragData(webViewBase->priv->dragAndDropHelper.handleDragDrop(context, IntPoint(x, y)));
     381    if (!dragData)
     382        return FALSE;
     383
     384    SandboxExtension::Handle handle;
     385    webViewBase->priv->pageProxy->performDrag(dragData.get(), String(), handle);
     386    gtk_drag_finish(context, TRUE, FALSE, time);
    293387    return TRUE;
    294388}
     
    309403    widgetClass->motion_notify_event = webkitWebViewBaseMotionNotifyEvent;
    310404    widgetClass->query_tooltip = webkitWebViewBaseQueryTooltip;
     405    widgetClass->drag_end = webkitWebViewBaseDragEnd;
     406    widgetClass->drag_data_get = webkitWebViewBaseDragDataGet;
     407    widgetClass->drag_motion = webkitWebViewBaseDragMotion;
     408    widgetClass->drag_leave = webkitWebViewBaseDragLeave;
     409    widgetClass->drag_drop = webkitWebViewBaseDragDrop;
     410    widgetClass->drag_data_received = webkitWebViewBaseDragDataReceived;
    311411
    312412    GObjectClass* gobjectClass = G_OBJECT_CLASS(webkitWebViewBaseClass);
     
    356456}
    357457
     458void webkitWebViewBaseStartDrag(WebKitWebViewBase* webViewBase, const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
     459{
     460    WebKitWebViewBasePrivate* priv = webViewBase->priv;
     461
     462    RefPtr<DataObjectGtk> dataObject(dragData.platformData());
     463    GRefPtr<GtkTargetList> targetList(PasteboardHelper::defaultPasteboardHelper()->targetListForDataObject(dataObject.get()));
     464    GOwnPtr<GdkEvent> currentEvent(gtk_get_current_event());
     465    GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(webViewBase),
     466                                             targetList.get(),
     467                                             dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()),
     468                                             1, /* button */
     469                                             currentEvent.get());
     470    priv->dragAndDropHelper.startedDrag(context, dataObject.get());
     471
     472
     473    // A drag starting should prevent a double-click from happening. This might
     474    // happen if a drag is followed very quickly by another click (like in the DRT).
     475    priv->clickCounter.reset();
     476
     477    if (dragImage) {
     478        RefPtr<cairo_surface_t> image(dragImage->createCairoSurface());
     479        priv->dragIcon.setImage(image.get());
     480        priv->dragIcon.useForDrag(context);
     481    } else
     482        gtk_drag_set_icon_default(context);
     483}
     484
    358485void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase* webkitWebViewBase)
    359486{
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h

    r95901 r97012  
    4949void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase*);
    5050
     51void webkitWebViewBaseStartDrag(WebKitWebViewBase*, const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage);
     52
    5153G_END_DECLS
    5254
  • trunk/Source/WebKit2/UIProcess/PageClient.h

    r95901 r97012  
    104104    virtual void didChangeContentsSize(const WebCore::IntSize&) = 0;
    105105    virtual void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&) = 0;
     106#endif
    106107
     108#if PLATFORM(QT) || PLATFORM(GTK)
    107109    virtual void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage) = 0;
    108110#endif
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r97000 r97012  
    8484#endif
    8585
     86#if PLATFORM(GTK)
     87#include "ArgumentCodersGtk.h"
     88#endif
     89
    8690#ifndef NDEBUG
    8791#include <wtf/RefCountedLeakCounter.h>
     
    790794    process()->send(Messages::WebPage::PerformDragControllerAction(action, dragData->clientPosition(), dragData->globalPosition(),
    791795        dragData->draggingSourceOperationMask(), dragData->dragDataMap(), dragData->flags()), m_pageID);
    792 #elif PLATFORM(QT)
     796#elif PLATFORM(QT) || PLATFORM(GTK)
    793797    process()->send(Messages::WebPage::PerformDragControllerAction(action, *dragData), m_pageID);
    794798#else
     
    802806}
    803807
    804 #if PLATFORM(QT)
     808#if PLATFORM(QT) || PLATFORM(GTK)
    805809void WebPageProxy::startDrag(const DragData& dragData, const ShareableBitmap::Handle& dragImageHandle)
    806810{
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r96645 r97012  
    468468    void startDragDrop(const WebCore::IntPoint& imagePoint, const WebCore::IntPoint& dragPoint, uint64_t okEffect, const HashMap<UINT, Vector<String> >& dataMap, uint64_t fileSize, const String& pathname, const SharedMemory::Handle& fileContentHandle, const WebCore::IntSize& dragImageSize, const SharedMemory::Handle& dragImageHandle, bool isLinkDrag);
    469469#endif
    470 #if PLATFORM(QT)
     470#if PLATFORM(QT) || PLATFORM(GTK)
    471471    void startDrag(const WebCore::DragData&, const ShareableBitmap::Handle& dragImage);
    472472#endif
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r96413 r97012  
    213213    StartDragDrop(WebCore::IntPoint imagePoint, WebCore::IntPoint dragPoint, uint64_t okEffect, HashMap<UINT,Vector<String> > dataMap, uint64_t fileSize, String pathname, WebKit::SharedMemory::Handle fileContentHandle, WebCore::IntSize dragImageSize, WebKit::SharedMemory::Handle dragImage, bool linkDrag)
    214214#endif
    215 #if PLATFORM(QT)
     215#if PLATFORM(QT) || PLATFORM(GTK)
    216216    StartDrag(WebCore::DragData dragData, WebKit::ShareableBitmap::Handle dragImage)
    217217#endif
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebDragClient.cpp

    r95901 r97012  
    5353}
    5454
    55 #if !PLATFORM(MAC) && !PLATFORM(WIN) && !PLATFORM(QT)
     55#if !PLATFORM(MAC) && !PLATFORM(WIN) && !PLATFORM(QT) && !PLATFORM(GTK)
    5656void WebDragClient::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard*, Frame*, bool)
    5757{
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r96880 r97012  
    17871787}
    17881788
    1789 #elif PLATFORM(QT)
     1789#elif PLATFORM(QT) || PLATFORM(GTK)
    17901790void WebPage::performDragControllerAction(uint64_t action, WebCore::DragData dragData)
    17911791{
    17921792    if (!m_page) {
    17931793        send(Messages::WebPageProxy::DidPerformDragControllerAction(DragOperationNone));
     1794#if PLATFORM(QT)
    17941795        QMimeData* data = const_cast<QMimeData*>(dragData.platformData());
     1796#elif PLATFORM(GTK)
     1797        DataObjectGtk* data = const_cast<DataObjectGtk*>(dragData.platformData());
     1798#endif
    17951799        delete data;
    17961800        return;
     
    18191823    }
    18201824    // DragData does not delete its platformData so we need to do that here.
     1825#if PLATFORM(QT)
    18211826    QMimeData* data = const_cast<QMimeData*>(dragData.platformData());
     1827#elif PLATFORM(GTK)
     1828    DataObjectGtk* data = const_cast<DataObjectGtk*>(dragData.platformData());
     1829#endif
    18221830    delete data;
    18231831}
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r96740 r97012  
    6262#endif
    6363
     64#if PLATFORM(GTK)
     65#include "ArgumentCodersGtk.h"
     66#endif
     67
    6468#if ENABLE(TOUCH_EVENTS)
    6569#include <WebCore/PlatformTouchEvent.h>
     
    397401#if PLATFORM(WIN)
    398402    void performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const WebCore::DragDataMap&, uint32_t flags);
    399 #elif PLATFORM(QT)
     403#elif PLATFORM(QT) || PLATFORM(GTK)
    400404    void performDragControllerAction(uint64_t action, WebCore::DragData);
    401405#else
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r96645 r97012  
    129129    PerformDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, HashMap<UINT,Vector<String>> dataMap, uint32_t flags)
    130130#endif
    131 #if PLATFORM(QT)
     131#if PLATFORM(QT) || PLATFORM(GTK)
    132132    PerformDragControllerAction(uint64_t action, WebCore::DragData dragData)
    133133#endif
    134 #if !PLATFORM(WIN) && !PLATFORM(QT)
     134#if !PLATFORM(WIN) && !PLATFORM(QT) && !PLATFORM(GTK)
    135135    PerformDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, WTF::String dragStorageName, uint32_t flags, WebKit::SandboxExtension::Handle sandboxExtensionHandle)
    136136#endif
Note: See TracChangeset for help on using the changeset viewer.