Changeset 96299 in webkit


Ignore:
Timestamp:
Sep 28, 2011 11:02:57 PM (13 years ago)
Author:
Martin Robinson
Message:

[GTK] Move drag-and-drop code which can be shared with WebKit2 to WebCore
https://bugs.webkit.org/show_bug.cgi?id=66890

Source/WebCore:

Added a GtkDragAndDropHelper class to hold all the logic that is common
between WebKit1 and WebKit2. This will allow greater code sharing between
the two ports.

Reviewed by Philippe Normand.

No new tests. This patch should not change behavior.

  • GNUmakefile.list.am: Added the GtkDragAndDropHelper to the sources list.
  • platform/gtk/GtkDragAndDropHelper.cpp: Added.
  • platform/gtk/GtkDragAndDropHelper.h: Added.

Source/WebKit/gtk:

Use the new GtkWidgetDragAndDropGlue class to hold the logic that will be
common between WebKit1 and WebKit2. Modify WebKitWebView to use this class.

Reviewed by Philippe Normand.

  • WebCoreSupport/DragClientGtk.cpp:

(WebKit::DragClient::startDrag): Inform the drag-and-drop glue about the drag.

  • webkit/webkitwebview.cpp: Use GtkWidgetDragAndDropGlue wherever this class was

maintaining drag-and-drop state itself.

  • webkit/webkitwebviewprivate.h: Swap out the drag-and-drop state for an instance

of the glue class.

Location:
trunk/Source
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r96294 r96299  
     12011-09-28  Martin Robinson  <mrobinson@igalia.com>
     2
     3        [GTK] Move drag-and-drop code which can be shared with WebKit2 to WebCore
     4        https://bugs.webkit.org/show_bug.cgi?id=66890
     5
     6        Added a GtkDragAndDropHelper class to hold all the logic that is common
     7        between WebKit1 and WebKit2. This will allow greater code sharing between
     8        the two ports.
     9
     10        Reviewed by Philippe Normand.
     11
     12        No new tests. This patch should not change behavior.
     13
     14        * GNUmakefile.list.am: Added the GtkDragAndDropHelper to the sources list.
     15        * platform/gtk/GtkDragAndDropHelper.cpp: Added.
     16        * platform/gtk/GtkDragAndDropHelper.h: Added.
     17
    1182011-09-28  Dan Bernstein  <mitz@apple.com>
    219
  • trunk/Source/WebCore/GNUmakefile.list.am

    r96215 r96299  
    39993999        Source/WebCore/platform/gtk/GtkClickCounter.cpp \
    40004000        Source/WebCore/platform/gtk/GtkClickCounter.h \
     4001        Source/WebCore/platform/gtk/GtkDragAndDropHelper.cpp \
     4002        Source/WebCore/platform/gtk/GtkDragAndDropHelper.h \
    40014003        Source/WebCore/platform/gtk/GtkUtilities.cpp \
    40024004        Source/WebCore/platform/gtk/GtkUtilities.h \
  • trunk/Source/WebKit/gtk/ChangeLog

    r96234 r96299  
     12011-09-28  Martin Robinson  <mrobinson@igalia.com>
     2
     3        [GTK] Move drag-and-drop code which can be shared with WebKit2 to WebCore
     4        https://bugs.webkit.org/show_bug.cgi?id=66890
     5
     6        Use the new GtkWidgetDragAndDropGlue class to hold the logic that will be
     7        common between WebKit1 and WebKit2. Modify WebKitWebView to use this class.
     8
     9        Reviewed by Philippe Normand.
     10
     11        * WebCoreSupport/DragClientGtk.cpp:
     12        (WebKit::DragClient::startDrag): Inform the drag-and-drop glue about the drag.
     13        * webkit/webkitwebview.cpp: Use GtkWidgetDragAndDropGlue wherever this class was
     14        maintaining drag-and-drop state itself.
     15        * webkit/webkitwebviewprivate.h: Swap out the drag-and-drop state for an instance
     16        of the glue class.
     17
    1182011-09-28  Kaustubh Atrawalkar  <kaustubh@motorola.com>
    219
  • trunk/Source/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp

    r87978 r96299  
    108108
    109109    GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(m_webView), targetList.get(), dragOperationToGdkDragActions(clipboard->sourceOperation()), 1, currentEvent.get());
    110     webView->priv->draggingDataObjects.set(context, dataObject);
     110    webView->priv->dragAndDropHelper.startedDrag(context, dataObject.get());
    111111
    112112    // A drag starting should prevent a double-click from happening. This might
  • trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp

    r95940 r96299  
    780780
    781781    PlatformMouseEvent platformEvent(event);
    782     platformEvent.setClickCount(priv->clickCounter.clickCountForGdkButtonEvent(widget, event));
     782    int count = priv->clickCounter.clickCountForGdkButtonEvent(widget, event);
     783    platformEvent.setClickCount(count);
    783784
    784785    if (event->button == 3)
     
    13341335    priv->subResources.clear();
    13351336
    1336     HashMap<GdkDragContext*, DroppingContext*>::iterator endDroppingContexts = priv->droppingContexts.end();
    1337     for (HashMap<GdkDragContext*, DroppingContext*>::iterator iter = priv->droppingContexts.begin(); iter != endDroppingContexts; ++iter)
    1338         delete (iter->second);
    1339     priv->droppingContexts.clear();
    1340 
    13411337    G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object);
    13421338}
     
    14511447{
    14521448    WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
    1453     WebKitWebViewPrivate* priv = webView->priv;
    1454 
    1455     // This might happen if a drag is still in progress after a WebKitWebView
    1456     // is disposed and before it is finalized.
    1457     if (!priv->draggingDataObjects.contains(context))
     1449    if (!webView->priv->dragAndDropHelper.handleDragEnd(context))
    14581450        return;
    1459 
    1460     priv->draggingDataObjects.remove(context);
    14611451
    14621452    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
     
    14641454        return;
    14651455
     1456    // Synthesize a button release event to send with the drag end action.
    14661457    GOwnPtr<GdkEvent> event(gdk_event_new(GDK_BUTTON_RELEASE));
    14671458    int x, y, xRoot, yRoot;
     
    14911482static void webkit_web_view_drag_data_get(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint)
    14921483{
    1493     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW(widget)->priv;
    1494 
    1495     // This might happen if a drag is still in progress after a WebKitWebView
    1496     // is diposed and before it is finalized.
    1497     if (!priv->draggingDataObjects.contains(context))
    1498         return;
    1499 
    1500     PasteboardHelper::defaultPasteboardHelper()->fillSelectionData(selectionData, info, priv->draggingDataObjects.get(context).get());
    1501 }
    1502 
    1503 static gboolean doDragLeaveLater(DroppingContext* context)
    1504 {
    1505     WebKitWebView* webView = context->webView;
    1506     WebKitWebViewPrivate* priv = webView->priv;
    1507 
    1508     if (!priv->droppingContexts.contains(context->gdkContext))
    1509         return FALSE;
    1510 
    1511     // If the view doesn't know about the drag yet (there are still pending data)
    1512     // requests, don't update it with information about the drag.
    1513     if (context->pendingDataRequests)
    1514         return FALSE;
    1515 
     1484    WEBKIT_WEB_VIEW(widget)->priv->dragAndDropHelper.handleGetDragData(context, selectionData, info);
     1485}
     1486
     1487static void dragExitedCallback(GtkWidget* widget, DragData* dragData, bool dropHappened)
     1488{
    15161489    // Don't call dragExited if we have just received a drag-drop signal. This
    15171490    // happens in the case of a successful drop onto the view.
    1518     if (!context->dropHappened) {
    1519         const IntPoint& position = context->lastMotionPosition;
    1520         DragData dragData(context->dataObject.get(), position, convertWidgetPointToScreenPoint(GTK_WIDGET(webView), position), DragOperationNone);
    1521         core(webView)->dragController()->dragExited(&dragData);
    1522     }
    1523 
    1524     core(webView)->dragController()->dragEnded();
    1525     priv->droppingContexts.remove(context->gdkContext);
    1526     delete context;
    1527     return FALSE;
     1491    if (!dropHappened)
     1492        core(WEBKIT_WEB_VIEW(widget))->dragController()->dragExited(dragData);
     1493    core(WEBKIT_WEB_VIEW(widget))->dragController()->dragEnded();
    15281494}
    15291495
    15301496static void webkit_web_view_drag_leave(GtkWidget* widget, GdkDragContext* context, guint time)
    15311497{
     1498    WEBKIT_WEB_VIEW(widget)->priv->dragAndDropHelper.handleDragLeave(context, dragExitedCallback);
     1499}
     1500
     1501static gboolean webkit_web_view_drag_motion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
     1502{
    15321503    WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
    1533     WebKitWebViewPrivate* priv = webView->priv;
    1534 
    1535     if (!priv->droppingContexts.contains(context))
     1504    OwnPtr<DragData> dragData(webView->priv->dragAndDropHelper.handleDragMotion(context, IntPoint(x, y), time));
     1505    if (!dragData)
     1506        return TRUE;
     1507
     1508    DragOperation operation = core(webView)->dragController()->dragUpdated(dragData.get());
     1509    gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
     1510    return TRUE;
     1511}
     1512
     1513static void webkit_web_view_drag_data_received(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* selectionData, guint info, guint time)
     1514{
     1515    WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
     1516    OwnPtr<DragData> dragData(webView->priv->dragAndDropHelper.handleDragDataReceived(context, selectionData, info));
     1517    if (!dragData)
    15361518        return;
    15371519
    1538     // During a drop GTK+ will fire a drag-leave signal right before firing
    1539     // the drag-drop signal. We want the actions for drag-leave to happen after
    1540     // those for drag-drop, so schedule them to happen asynchronously here.
    1541     g_timeout_add(0, reinterpret_cast<GSourceFunc>(doDragLeaveLater), priv->droppingContexts.get(context));
    1542 }
    1543 
    1544 static gboolean webkit_web_view_drag_motion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
     1520    DragOperation operation = core(webView)->dragController()->dragEntered(dragData.get());
     1521    gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
     1522}
     1523
     1524static gboolean webkit_web_view_drag_drop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
    15451525{
    15461526    WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
    1547     WebKitWebViewPrivate* priv = webView->priv;
    1548 
    1549     DroppingContext* droppingContext = 0;
    1550     IntPoint position = IntPoint(x, y);
    1551     if (!priv->droppingContexts.contains(context)) {
    1552         droppingContext = new DroppingContext;
    1553         droppingContext->webView = webView;
    1554         droppingContext->gdkContext = context;
    1555         droppingContext->dataObject = WebCore::DataObjectGtk::create();
    1556         droppingContext->dropHappened = false;
    1557         droppingContext->lastMotionPosition = position;
    1558         priv->droppingContexts.set(context, droppingContext);
    1559 
    1560         Vector<GdkAtom> acceptableTargets(PasteboardHelper::defaultPasteboardHelper()->dropAtomsForContext(widget, context));
    1561         droppingContext->pendingDataRequests = acceptableTargets.size();
    1562         for (size_t i = 0; i < acceptableTargets.size(); i++)
    1563             gtk_drag_get_data(widget, context, acceptableTargets.at(i), time);
    1564     } else {
    1565         droppingContext = priv->droppingContexts.get(context);
    1566         droppingContext->lastMotionPosition = position;
    1567     }
    1568 
    1569     // Don't send any drag information to WebCore until we've retrieved all
    1570     // the data for this drag operation. Otherwise we'd have to block to wait
    1571     // for the drag's data.
    1572     ASSERT(droppingContext);
    1573     if (droppingContext->pendingDataRequests > 0)
    1574         return TRUE;
    1575 
    1576     DragData dragData(droppingContext->dataObject.get(), position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
    1577     DragOperation operation = core(webView)->dragController()->dragUpdated(&dragData);
    1578     gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
    1579 
    1580     return TRUE;
    1581 }
    1582 
    1583 static void webkit_web_view_drag_data_received(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* selectionData, guint info, guint time)
    1584 {
    1585     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
    1586     WebKitWebViewPrivate* priv = webView->priv;
    1587 
    1588     if (!priv->droppingContexts.contains(context))
    1589         return;
    1590 
    1591     DroppingContext* droppingContext = priv->droppingContexts.get(context);
    1592     droppingContext->pendingDataRequests--;
    1593     PasteboardHelper::defaultPasteboardHelper()->fillDataObjectFromDropData(selectionData, info, droppingContext->dataObject.get());
    1594 
    1595     if (droppingContext->pendingDataRequests)
    1596         return;
    1597 
    1598     // The coordinates passed to drag-data-received signal are sometimes
    1599     // inaccurate in DRT, so use the coordinates of the last motion event.
    1600     const IntPoint& position = droppingContext->lastMotionPosition;
    1601 
    1602     // If there are no more pending requests, start sending dragging data to WebCore.
    1603     DragData dragData(droppingContext->dataObject.get(), position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
    1604     DragOperation operation = core(webView)->dragController()->dragEntered(&dragData);
    1605     gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
    1606 }
    1607 
    1608 static gboolean webkit_web_view_drag_drop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
    1609 {
    1610     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
    1611     WebKitWebViewPrivate* priv = webView->priv;
    1612 
    1613     if (!priv->droppingContexts.contains(context))
     1527    OwnPtr<DragData> dragData(webView->priv->dragAndDropHelper.handleDragDrop(context, IntPoint(x, y)));
     1528    if (!dragData)
    16141529        return FALSE;
    16151530
    1616     DroppingContext* droppingContext = priv->droppingContexts.get(context);
    1617     droppingContext->dropHappened = true;
    1618 
    1619     IntPoint position(x, y);
    1620     DragData dragData(droppingContext->dataObject.get(), position, convertWidgetPointToScreenPoint(widget, position), gdkDragActionToDragOperation(gdk_drag_context_get_actions(context)));
    1621     core(webView)->dragController()->performDrag(&dragData);
    1622 
     1531    core(webView)->dragController()->performDrag(dragData.get());
    16231532    gtk_drag_finish(context, TRUE, FALSE, time);
    16241533    return TRUE;
     
    34393348    priv->subResources = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref));
    34403349
     3350    priv->dragAndDropHelper.setWidget(GTK_WIDGET(webView));
    34413351    gtk_drag_dest_set(GTK_WIDGET(webView), static_cast<GtkDestDefaults>(0), 0, 0, static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
    34423352    gtk_drag_dest_set_target_list(GTK_WIDGET(webView), PasteboardHelper::defaultPasteboardHelper()->targetList());
  • trunk/Source/WebKit/gtk/webkit/webkitwebviewprivate.h

    r95901 r96299  
    2424#define webkitwebviewprivate_h
    2525
    26 #include "DataObjectGtk.h"
    2726#include "FullscreenVideoController.h"
    2827#include "GtkClickCounter.h"
     28#include "GtkDragAndDropHelper.h"
    2929#include "GOwnPtr.h"
    3030#include "Page.h"
     
    3333
    3434namespace WebKit {
    35 
    3635WebCore::Page* core(WebKitWebView*);
    3736WebKitWebView* kit(WebCore::Page*);
    38 
    39 
    40 typedef struct DroppingContext_ {
    41     WebKitWebView* webView;
    42     GdkDragContext* gdkContext;
    43     RefPtr<WebCore::DataObjectGtk> dataObject;
    44     WebCore::IntPoint lastMotionPosition;
    45     int pendingDataRequests;
    46     bool dropHappened;
    47 } DroppingContext;
    48 
    4937}
    5038
     
    10189
    10290    WebCore::GtkClickCounter clickCounter;
    103     HashMap<GdkDragContext*, RefPtr<WebCore::DataObjectGtk> > draggingDataObjects;
    104     HashMap<GdkDragContext*, WebKit::DroppingContext*> droppingContexts;
    105 
     91    WebCore::GtkDragAndDropHelper dragAndDropHelper;
    10692    bool selfScrolling;
    10793};
Note: See TracChangeset for help on using the changeset viewer.