Changeset 58885 in webkit


Ignore:
Timestamp:
May 6, 2010 9:32:42 AM (14 years ago)
Author:
Martin Robinson
Message:

2010-05-06 Martin Robinson <Martin Robinson>

Reviewed by Gustavo Noronha Silva.

[GTK] Enable DOM clipboard and drag-and-drop access
https://bugs.webkit.org/show_bug.cgi?id=30623

Convert dragging portion of drag-and-drop to use DataObjectGtk.

  • wtf/gobject/GRefPtr.h: Add forward declarations for GObject functions.

2010-05-06 Martin Robinson <Martin Robinson>

Reviewed by Gustavo Noronha Silva.

[GTK] Enable DOM clipboard and drag-and-drop access
https://bugs.webkit.org/show_bug.cgi?id=30623

Convert dragging portion of drag-and-drop to use DataObjectGtk.

No new tests, because functionality has not changed.

  • page/gtk/EventHandlerGtk.cpp: (WebCore::EventHandler::createDraggingClipboard): Pass the DataObjectGtk as a parameter here.
  • platform/gtk/ClipboardGtk.h: (WebCore::ClipboardGtk::create): Take the DataObject as a parameter instead of creating it here. (WebCore::ClipboardGtk::helper): Added. (WebCore::ClipboardGtk::dataObject): Added.
  • platform/gtk/PasteboardHelper.h: Make targetListForDataObject a public method.

2010-05-06 Martin Robinson <Martin Robinson>

Reviewed by Gustavo Noronha Silva.

[GTK] Enable DOM clipboard and drag-and-drop access
https://bugs.webkit.org/show_bug.cgi?id=30623

Convert dragging portion of drag-and-drop to use DataObjectGtk.

  • WebCoreSupport/DragClientGtk.cpp: (WebKit::DragClient::willPerformDragDestinationAction): Remove the notImplemented. It is implemented, it's just a no-op. (WebKit::DragClient::startDrag): Start the drag context via the ClipboardGtk and PasteboardHelper now.
  • WebCoreSupport/DragClientGtk.h: Small style fix.
  • webkit/webkitprivate.h: Add a HashMap of contexts and DataObjects here to to represent all current drag operations.
  • webkit/webkitwebview.cpp: (webkit_web_view_dispose): Clear all data objects during disposal. (webkit_web_view_drag_end): When a drag is over, just remove it from the map. (webkit_web_view_drag_data_get): To get the drag data, just grab it from the DataObject.
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r58878 r58885  
     12010-05-06  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Reviewed by Gustavo Noronha Silva.
     4
     5        [GTK] Enable DOM clipboard and drag-and-drop access
     6        https://bugs.webkit.org/show_bug.cgi?id=30623
     7
     8        Convert dragging portion of drag-and-drop to use DataObjectGtk.
     9
     10        * wtf/gobject/GRefPtr.h: Add forward declarations for GObject functions.
     11
    1122010-05-06  Steve Block  <steveblock@google.com>
    213
  • trunk/JavaScriptCore/wtf/gobject/GRefPtr.h

    r55149 r58885  
    2828
    2929typedef struct _GHashTable GHashTable;
     30typedef void* gpointer;
     31extern "C" void g_object_unref(gpointer object);
     32extern "C" gpointer  g_object_ref_sink(gpointer object);
    3033
    3134namespace WTF {
  • trunk/WebCore/ChangeLog

    r58884 r58885  
     12010-05-06  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Reviewed by Gustavo Noronha Silva.
     4
     5        [GTK] Enable DOM clipboard and drag-and-drop access
     6        https://bugs.webkit.org/show_bug.cgi?id=30623
     7
     8        Convert dragging portion of drag-and-drop to use DataObjectGtk.
     9
     10        No new tests, because functionality has not changed.
     11
     12        * page/gtk/EventHandlerGtk.cpp:
     13        (WebCore::EventHandler::createDraggingClipboard): Pass the DataObjectGtk as a parameter here.
     14        * platform/gtk/ClipboardGtk.h:
     15        (WebCore::ClipboardGtk::create): Take the DataObject as a parameter instead of creating it here.
     16        (WebCore::ClipboardGtk::helper): Added.
     17        (WebCore::ClipboardGtk::dataObject): Added.
     18        * platform/gtk/PasteboardHelper.h: Make targetListForDataObject a public method.
     19
    1202010-05-06  Pavel Feldman  <pfeldman@chromium.org>
    221
  • trunk/WebCore/page/gtk/EventHandlerGtk.cpp

    r48735 r58885  
    9797PassRefPtr<Clipboard> EventHandler::createDraggingClipboard() const
    9898{
    99     return ClipboardGtk::create(ClipboardWritable, true);
     99    return ClipboardGtk::create(ClipboardWritable, DataObjectGtk::create(), true);
    100100}
    101101
  • trunk/WebCore/platform/gtk/ClipboardGtk.h

    r58470 r58885  
    4646        }
    4747
    48         static PassRefPtr<ClipboardGtk> create(ClipboardAccessPolicy policy, bool isForDragging)
     48        static PassRefPtr<ClipboardGtk> create(ClipboardAccessPolicy policy, PassRefPtr<DataObjectGtk> dataObject, bool isForDragging)
    4949        {
    50             return adoptRef(new ClipboardGtk(policy, DataObjectGtk::create(), isForDragging));
     50            return adoptRef(new ClipboardGtk(policy, dataObject, isForDragging));
    5151        }
    5252        virtual ~ClipboardGtk();
     
    7474        virtual bool hasData();
    7575
     76        PasteboardHelper* helper() { return m_helper; }
     77        PassRefPtr<DataObjectGtk> dataObject() { return m_dataObject; }
     78
    7679    private:
    7780        ClipboardGtk(ClipboardAccessPolicy, GtkClipboard*);
  • trunk/WebCore/platform/gtk/PasteboardHelper.h

    r58470 r58885  
    33 * Copyright (C) 2009 Holger Hans Peter Freyther
    44 * Copyright (C) 2010 Martin Robinson <mrobinson@webkit.org>
     5 * Copyright (C) 2010 Igalia S.L.
    56 * All rights reserved.
    67 *
     
    5051    GtkClipboard* getPrimarySelectionClipboard(Frame*) const;
    5152    GtkTargetList* targetList() const;
     53    GtkTargetList* targetListForDataObject(DataObjectGtk*);
    5254    void fillSelectionData(GtkSelectionData*, guint, DataObjectGtk*);
    5355    void writeClipboardContents(GtkClipboard*, GClosure* closure = 0);
     
    6365private:
    6466    GtkTargetList* m_targetList;
    65     GtkTargetList* targetListForDataObject(DataObjectGtk*);
    6667};
    6768
  • trunk/WebKit/gtk/ChangeLog

    r58703 r58885  
     12010-05-06  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Reviewed by Gustavo Noronha Silva.
     4
     5        [GTK] Enable DOM clipboard and drag-and-drop access
     6        https://bugs.webkit.org/show_bug.cgi?id=30623
     7
     8        Convert dragging portion of drag-and-drop to use DataObjectGtk.
     9
     10        * WebCoreSupport/DragClientGtk.cpp:
     11        (WebKit::DragClient::willPerformDragDestinationAction): Remove the notImplemented. It is implemented, it's just a no-op.
     12        (WebKit::DragClient::startDrag): Start the drag context via the ClipboardGtk and PasteboardHelper now.
     13        * WebCoreSupport/DragClientGtk.h: Small style fix.
     14        * webkit/webkitprivate.h: Add a HashMap of contexts and DataObjects here to to represent all current drag operations.
     15        * webkit/webkitwebview.cpp:
     16        (webkit_web_view_dispose): Clear all data objects during disposal.
     17        (webkit_web_view_drag_end): When a drag is over, just remove it from the map.
     18        (webkit_web_view_drag_data_get): To get the drag data, just grab it from the DataObject.
     19
    1202010-05-03  Abhishek Arya  <inferno@chromium.org>
    221
  • trunk/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp

    r47497 r58885  
    11/*
     2 * Copyright (C) Igalia S.L.
     3 *
    24 *  This library is free software; you can redistribute it and/or
    35 *  modify it under the terms of the GNU Lesser General Public
     
    1820#include "DragClientGtk.h"
    1921
     22#include "ClipboardGtk.h"
     23#include "DataObjectGtk.h"
    2024#include "Document.h"
    2125#include "Element.h"
    2226#include "Frame.h"
     27#include "GRefPtrGtk.h"
    2328#include "NotImplemented.h"
     29#include "PasteboardHelper.h"
    2430#include "RenderObject.h"
     31#include "webkitprivate.h"
    2532#include "webkitwebview.h"
    2633
     
    4249void DragClient::willPerformDragDestinationAction(DragDestinationAction, DragData*)
    4350{
    44     notImplemented();
    4551}
    4652
     
    6268}
    6369
    64 void DragClient::startDrag(DragImageRef image, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard*, Frame* frame, bool linkDrag)
     70void DragClient::startDrag(DragImageRef image, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool linkDrag)
    6571{
    66     Element* targetElement = frame->document()->elementFromPoint(m_startPos.x(), m_startPos.y());
    67     bool imageDrag = false;
    68 
    69     if (targetElement)
    70         imageDrag = targetElement->renderer()->isImage();
    71 
    72     GdkAtom textHtml = gdk_atom_intern_static_string("text/html");
    73     GdkAtom netscapeUrl = gdk_atom_intern_static_string("_NETSCAPE_URL");
    74 
    75     GtkTargetList* targetList = gtk_target_list_new(NULL, 0);
    76     gtk_target_list_add(targetList, textHtml, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML);
    77     gtk_target_list_add_text_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT);
    78 
    79     if (linkDrag || imageDrag) {
    80         gtk_target_list_add(targetList, netscapeUrl, 0, WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL);
    81         gtk_target_list_add_uri_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST);
    82     }
    83 
    84     if (imageDrag)
    85         gtk_target_list_add_image_targets(targetList, WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE, false);
     72    ClipboardGtk* clipboardGtk = reinterpret_cast<ClipboardGtk*>(clipboard);
    8673
    8774    GdkDragAction dragAction = GDK_ACTION_COPY;
    88     if (linkDrag) {
    89         dragAction = GDK_ACTION_LINK;
    90         if (imageDrag)
    91             dragAction = (GdkDragAction)(dragAction | GDK_ACTION_COPY);
    92     }
     75    if (linkDrag)
     76        dragAction = (GdkDragAction) (dragAction | GDK_ACTION_LINK);
    9377
     78    WebKitWebView* webView = webkit_web_frame_get_web_view(kit(frame));
     79    RefPtr<DataObjectGtk> dataObject = clipboardGtk->dataObject();
     80
     81    GRefPtr<GtkTargetList> targetList(clipboardGtk->helper()->targetListForDataObject(dataObject.get()));
    9482    GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
    9583    reinterpret_cast<GdkEventButton*>(event)->window = gtk_widget_get_window(GTK_WIDGET(m_webView));
    9684    reinterpret_cast<GdkEventButton*>(event)->time = GDK_CURRENT_TIME;
    9785
    98     GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(m_webView),
    99                                              targetList, dragAction, 1, event);
    100     g_object_ref(context);
     86    GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(m_webView), targetList.get(), dragAction, 1, event);
     87    webView->priv->draggingDataObjects.set(context, dataObject);
    10188
    10289    if (image)
     
    10491    else
    10592        gtk_drag_set_icon_default(context);
    106 
    107     gtk_target_list_unref(targetList);
    10893}
    10994
  • trunk/WebKit/gtk/WebCoreSupport/DragClientGtk.h

    r47243 r58885  
    5252        virtual void dragControllerDestroyed();
    5353
    54         private:
    55             WebKitWebView* m_webView;
    56             WebCore::IntPoint m_startPos;
     54    private:
     55        WebKitWebView* m_webView;
     56        WebCore::IntPoint m_startPos;
    5757    };
    5858}
  • trunk/WebKit/gtk/webkit/webkitprivate.h

    r57986 r58885  
    33 * Copyright (C) 2008 Jan Michael C. Alonzo
    44 * Copyright (C) 2008 Collabora Ltd.
     5 * Copyright (C) 2010 Igalia S.L.
    56 *
    67 * This library is free software; you can redistribute it and/or
     
    4748#include "ArchiveResource.h"
    4849#include "BackForwardList.h"
     50#include "DataObjectGtk.h"
    4951#include <enchant.h>
    5052#include "GOwnPtr.h"
     
    150152        GHashTable* subResources;
    151153        char* tooltipText;
     154
     155        HashMap<GdkDragContext*, RefPtr<WebCore::DataObjectGtk> > draggingDataObjects;
    152156    };
    153157
  • trunk/WebKit/gtk/webkit/webkitwebview.cpp

    r58703 r58885  
    11251125    }
    11261126
     1127    priv->draggingDataObjects.clear();
     1128
    11271129    G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object);
    11281130}
     
    12351237static void webkit_web_view_drag_end(GtkWidget* widget, GdkDragContext* context)
    12361238{
    1237     g_object_unref(context);
    1238 }
    1239 
    1240 struct DNDContentsRequest
    1241 {
    1242     gint info;
    1243     GtkSelectionData* dnd_selection_data;
    1244 
    1245     gboolean is_url_label_request;
    1246     gchar* url;
    1247 };
    1248 
    1249 void clipboard_contents_received(GtkClipboard* clipboard, GtkSelectionData* selection_data, gpointer data)
    1250 {
    1251     DNDContentsRequest* contents_request = reinterpret_cast<DNDContentsRequest*>(data);
    1252 
    1253     if (contents_request->is_url_label_request) {
    1254         // We have received contents of the label clipboard. Use them to form
    1255         // required structures. When formed, enhance the dnd's selection data
    1256         // with them and return.
    1257 
    1258         // If the label is empty, use the url itself.
    1259         gchar* url_label = reinterpret_cast<gchar*>(gtk_selection_data_get_text(selection_data));
    1260         if (!url_label)
    1261             url_label = g_strdup(contents_request->url);
    1262 
    1263         gchar* data = 0;
    1264         switch (contents_request->info) {
    1265         case WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST:
    1266             data = g_strdup_printf("%s\r\n%s\r\n", contents_request->url, url_label);
    1267             break;
    1268         case WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL:
    1269             data = g_strdup_printf("%s\n%s", contents_request->url, url_label);
    1270             break;
    1271         }
    1272 
    1273         if (data) {
    1274             gtk_selection_data_set(contents_request->dnd_selection_data,
    1275                                    contents_request->dnd_selection_data->target, 8,
    1276                                    reinterpret_cast<const guchar*>(data), strlen(data));
    1277             g_free(data);
    1278         }
    1279 
    1280         g_free(url_label);
    1281         g_free(contents_request->url);
    1282         g_free(contents_request);
    1283 
     1239    WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(WEBKIT_WEB_VIEW(widget));
     1240
     1241    // This might happen if a drag is still in progress after a WebKitWebView
     1242    // is diposed and before it is finalized.
     1243    if (!priv->draggingDataObjects.contains(context))
    12841244        return;
    1285     }
    1286 
    1287     switch (contents_request->info) {
    1288     case WEBKIT_WEB_VIEW_TARGET_INFO_HTML:
    1289     case WEBKIT_WEB_VIEW_TARGET_INFO_TEXT:
    1290         {
    1291         gchar* data = reinterpret_cast<gchar*>(gtk_selection_data_get_text(selection_data));
    1292         if (data) {
    1293             gtk_selection_data_set(contents_request->dnd_selection_data,
    1294                                    contents_request->dnd_selection_data->target, 8,
    1295                                    reinterpret_cast<const guchar*>(data),
    1296                                    strlen(data));
    1297             g_free(data);
    1298         }
    1299         break;
    1300         }
    1301     case WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE:
    1302         {
    1303         GdkPixbuf* pixbuf = gtk_selection_data_get_pixbuf(selection_data);
    1304         if (pixbuf) {
    1305             gtk_selection_data_set_pixbuf(contents_request->dnd_selection_data, pixbuf);
    1306             g_object_unref(pixbuf);
    1307         }
    1308         break;
    1309         }
    1310     case WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST:
    1311     case WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL:
    1312         // URL's label is stored in another clipboard, so we store URL into
    1313         // contents request, mark the latter as an url label request
    1314         // and request for contents of the label clipboard.
    1315         contents_request->is_url_label_request = TRUE;
    1316         contents_request->url = reinterpret_cast<gchar*>(gtk_selection_data_get_text(selection_data));
    1317 
    1318         gtk_clipboard_request_contents(gtk_clipboard_get(gdk_atom_intern_static_string("WebKitClipboardUrlLabel")),
    1319                                        selection_data->target, clipboard_contents_received, contents_request);
    1320         break;
    1321     }
    1322 }
    1323 
    1324 static void webkit_web_view_drag_data_get(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selection_data, guint info, guint time_)
    1325 {
    1326     GdkAtom selection_atom = GDK_NONE;
    1327     GdkAtom target_atom = selection_data->target;
    1328 
    1329     switch (info) {
    1330         case WEBKIT_WEB_VIEW_TARGET_INFO_HTML:
    1331             selection_atom = gdk_atom_intern_static_string("WebKitClipboardHtml");
    1332             // HTML markup data is set as text, therefor, we need a text-like target atom
    1333             target_atom = gdk_atom_intern_static_string("UTF8_STRING");
    1334             break;
    1335         case WEBKIT_WEB_VIEW_TARGET_INFO_TEXT:
    1336             selection_atom = gdk_atom_intern_static_string("WebKitClipboardText");
    1337             break;
    1338         case WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE:
    1339             selection_atom = gdk_atom_intern_static_string("WebKitClipboardImage");
    1340             break;
    1341         case WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST:
    1342         case WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL:
    1343             selection_atom = gdk_atom_intern_static_string("WebKitClipboardUrl");
    1344             // We require URL and label, which are both stored in text format
    1345             // and are needed to be retrieved as such.
    1346             target_atom = gdk_atom_intern_static_string("UTF8_STRING");
    1347             break;
    1348     }
    1349 
    1350     DNDContentsRequest* contents_request = g_new(DNDContentsRequest, 1);
    1351     contents_request->info = info;
    1352     contents_request->is_url_label_request = FALSE;
    1353     contents_request->dnd_selection_data = selection_data;
    1354 
    1355     gtk_clipboard_request_contents(gtk_clipboard_get(selection_atom), target_atom,
    1356                                    clipboard_contents_received, contents_request);
     1245
     1246    priv->draggingDataObjects.remove(context);
     1247}
     1248
     1249static void webkit_web_view_drag_data_get(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint)
     1250{
     1251    WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(WEBKIT_WEB_VIEW(widget));
     1252
     1253    // This might happen if a drag is still in progress after a WebKitWebView
     1254    // is diposed and before it is finalized.
     1255    if (!priv->draggingDataObjects.contains(context))
     1256        return;
     1257
     1258    pasteboardHelperInstance()->fillSelectionData(selectionData, info, priv->draggingDataObjects.get(context).get());
    13571259}
    13581260
Note: See TracChangeset for help on using the changeset viewer.