WebDragClientGtk.cpp [plain text]
#include "config.h"
#include "WebDragClient.h"
#if ENABLE(DRAG_SUPPORT)
#include "ArgumentCodersGtk.h"
#include "ShareableBitmap.h"
#include "WebPage.h"
#include "WebPageProxyMessages.h"
#include <WebCore/DataObjectGtk.h>
#include <WebCore/DataTransfer.h>
#include <WebCore/DragData.h>
#include <WebCore/GraphicsContext.h>
#include <WebCore/Pasteboard.h>
#include <WebCore/PlatformContextCairo.h>
using namespace WebCore;
namespace WebKit {
static PassRefPtr<ShareableBitmap> convertCairoSurfaceToShareableBitmap(cairo_surface_t* surface)
{
if (!surface)
return 0;
IntSize imageSize(cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface));
RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(imageSize, ShareableBitmap::SupportsAlpha);
auto graphicsContext = bitmap->createGraphicsContext();
graphicsContext->platformContext()->drawSurfaceToContext(surface, IntRect(IntPoint(), imageSize), IntRect(IntPoint(), imageSize), graphicsContext.get());
return bitmap.release();
}
void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& clientPosition, const IntPoint& globalPosition, DataTransfer& dataTransfer, Frame&, bool)
{
RefPtr<ShareableBitmap> bitmap = convertCairoSurfaceToShareableBitmap(dragImage);
ShareableBitmap::Handle handle;
if (bitmap && !bitmap->createHandle(handle))
return;
RefPtr<DataObjectGtk> dataObject = dataTransfer.pasteboard().dataObject();
DragData dragData(dataObject.get(), clientPosition, globalPosition, dataTransfer.sourceOperation());
m_page->send(Messages::WebPageProxy::StartDrag(dragData, handle));
}
};
#endif // ENABLE(DRAG_SUPPORT)