From 423f7ab80f814c5f4e4784e70bd3c36c44497314 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 16 Dec 2015 12:38:16 +0100 Subject: Implement drag and drop support Create a QDrag for drag and drop operations that are started in the web page. React on drag and drop event of QWidget and QQuickItem. Task-number: QTBUG-43008 Change-Id: If09f09de6e6d5b5f02835985a17cc6bc3262f411 Reviewed-by: Alexandru Croitor Reviewed-by: Allan Sandfeld Jensen --- src/core/web_contents_view_qt.cpp | 56 +++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'src/core/web_contents_view_qt.cpp') diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp index 67addacd5..153966aea 100644 --- a/src/core/web_contents_view_qt.cpp +++ b/src/core/web_contents_view_qt.cpp @@ -40,10 +40,14 @@ #include "content_browser_client_qt.h" #include "render_widget_host_view_qt_delegate.h" #include "type_conversion.h" +#include "web_contents_adapter.h" #include "web_engine_context.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/public/common/context_menu_params.h" +#include + +#include namespace QtWebEngineCore { @@ -164,15 +168,51 @@ void WebContentsViewQt::ShowContextMenu(content::RenderFrameHost *, const conten m_client->contextMenuRequested(contextMenuData); } -void WebContentsViewQt::StartDragging(const content::DropData& drop_data, blink::WebDragOperationsMask allowed_ops, const gfx::ImageSkia& image, const gfx::Vector2d& image_offset, const content::DragEventSourceInfo& event_info) +Qt::DropActions toQtDropActions(blink::WebDragOperationsMask ops) +{ + Qt::DropActions result; + if (ops & blink::WebDragOperationCopy) + result |= Qt::CopyAction; + if (ops & blink::WebDragOperationLink) + result |= Qt::LinkAction; + if (ops & blink::WebDragOperationMove || ops & blink::WebDragOperationDelete) + result |= Qt::MoveAction; + return result; +} + +Qt::DropAction toQt(blink::WebDragOperation op) +{ + if (op == blink::WebDragOperationCopy) + return Qt::CopyAction; + if (op == blink::WebDragOperationLink) + return Qt::LinkAction; + if (op == blink::WebDragOperationMove || op == blink::WebDragOperationDelete) + return Qt::MoveAction; + return Qt::IgnoreAction; +} + +void WebContentsViewQt::StartDragging(const content::DropData &drop_data, + blink::WebDragOperationsMask allowed_ops, + const gfx::ImageSkia &image, + const gfx::Vector2d &image_offset, + const content::DragEventSourceInfo &event_info) +{ + Q_UNUSED(event_info); + + QPixmap pixmap; + QPoint hotspot; + pixmap = QPixmap::fromImage(toQImage(image.GetRepresentation(m_client->dpiScale()))); + if (!pixmap.isNull()) { + hotspot.setX(image_offset.x()); + hotspot.setY(image_offset.y()); + } + + m_client->startDragging(drop_data, toQtDropActions(allowed_ops), pixmap, hotspot); +} + +void WebContentsViewQt::UpdateDragCursor(blink::WebDragOperation dragOperation) { - Q_UNUSED(&drop_data); - Q_UNUSED(allowed_ops); - Q_UNUSED(&image); - Q_UNUSED(&image_offset); - Q_UNUSED(&event_info); - // Tell the renderer to cancel the drag, see StartDragging's declaration in render_view_host_delegate_view.h for info. - m_webContents->SystemDragEnded(); + m_client->webContentsAdapter()->updateDragAction(toQt(dragOperation)); } void WebContentsViewQt::TakeFocus(bool reverse) -- cgit v1.2.3