Changeset 96299 in webkit
- Timestamp:
- Sep 28, 2011 11:02:57 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r96294 r96299 1 2011-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 1 18 2011-09-28 Dan Bernstein <mitz@apple.com> 2 19 -
trunk/Source/WebCore/GNUmakefile.list.am
r96215 r96299 3999 3999 Source/WebCore/platform/gtk/GtkClickCounter.cpp \ 4000 4000 Source/WebCore/platform/gtk/GtkClickCounter.h \ 4001 Source/WebCore/platform/gtk/GtkDragAndDropHelper.cpp \ 4002 Source/WebCore/platform/gtk/GtkDragAndDropHelper.h \ 4001 4003 Source/WebCore/platform/gtk/GtkUtilities.cpp \ 4002 4004 Source/WebCore/platform/gtk/GtkUtilities.h \ -
trunk/Source/WebKit/gtk/ChangeLog
r96234 r96299 1 2011-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 1 18 2011-09-28 Kaustubh Atrawalkar <kaustubh@motorola.com> 2 19 -
trunk/Source/WebKit/gtk/WebCoreSupport/DragClientGtk.cpp
r87978 r96299 108 108 109 109 GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(m_webView), targetList.get(), dragOperationToGdkDragActions(clipboard->sourceOperation()), 1, currentEvent.get()); 110 webView->priv->drag gingDataObjects.set(context, dataObject);110 webView->priv->dragAndDropHelper.startedDrag(context, dataObject.get()); 111 111 112 112 // A drag starting should prevent a double-click from happening. This might -
trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp
r95940 r96299 780 780 781 781 PlatformMouseEvent platformEvent(event); 782 platformEvent.setClickCount(priv->clickCounter.clickCountForGdkButtonEvent(widget, event)); 782 int count = priv->clickCounter.clickCountForGdkButtonEvent(widget, event); 783 platformEvent.setClickCount(count); 783 784 784 785 if (event->button == 3) … … 1334 1335 priv->subResources.clear(); 1335 1336 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 1341 1337 G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object); 1342 1338 } … … 1451 1447 { 1452 1448 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)) 1458 1450 return; 1459 1460 priv->draggingDataObjects.remove(context);1461 1451 1462 1452 Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); … … 1464 1454 return; 1465 1455 1456 // Synthesize a button release event to send with the drag end action. 1466 1457 GOwnPtr<GdkEvent> event(gdk_event_new(GDK_BUTTON_RELEASE)); 1467 1458 int x, y, xRoot, yRoot; … … 1491 1482 static void webkit_web_view_drag_data_get(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint) 1492 1483 { 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 1487 static void dragExitedCallback(GtkWidget* widget, DragData* dragData, bool dropHappened) 1488 { 1516 1489 // Don't call dragExited if we have just received a drag-drop signal. This 1517 1490 // 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(); 1528 1494 } 1529 1495 1530 1496 static void webkit_web_view_drag_leave(GtkWidget* widget, GdkDragContext* context, guint time) 1531 1497 { 1498 WEBKIT_WEB_VIEW(widget)->priv->dragAndDropHelper.handleDragLeave(context, dragExitedCallback); 1499 } 1500 1501 static gboolean webkit_web_view_drag_motion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time) 1502 { 1532 1503 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 1513 static 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) 1536 1518 return; 1537 1519 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 1524 static gboolean webkit_web_view_drag_drop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time) 1545 1525 { 1546 1526 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) 1614 1529 return FALSE; 1615 1530 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()); 1623 1532 gtk_drag_finish(context, TRUE, FALSE, time); 1624 1533 return TRUE; … … 3439 3348 priv->subResources = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref)); 3440 3349 3350 priv->dragAndDropHelper.setWidget(GTK_WIDGET(webView)); 3441 3351 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)); 3442 3352 gtk_drag_dest_set_target_list(GTK_WIDGET(webView), PasteboardHelper::defaultPasteboardHelper()->targetList()); -
trunk/Source/WebKit/gtk/webkit/webkitwebviewprivate.h
r95901 r96299 24 24 #define webkitwebviewprivate_h 25 25 26 #include "DataObjectGtk.h"27 26 #include "FullscreenVideoController.h" 28 27 #include "GtkClickCounter.h" 28 #include "GtkDragAndDropHelper.h" 29 29 #include "GOwnPtr.h" 30 30 #include "Page.h" … … 33 33 34 34 namespace WebKit { 35 36 35 WebCore::Page* core(WebKitWebView*); 37 36 WebKitWebView* 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 49 37 } 50 38 … … 101 89 102 90 WebCore::GtkClickCounter clickCounter; 103 HashMap<GdkDragContext*, RefPtr<WebCore::DataObjectGtk> > draggingDataObjects; 104 HashMap<GdkDragContext*, WebKit::DroppingContext*> droppingContexts; 105 91 WebCore::GtkDragAndDropHelper dragAndDropHelper; 106 92 bool selfScrolling; 107 93 };
Note: See TracChangeset
for help on using the changeset viewer.