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/CairoOperations.h>
#include <WebCore/DataTransfer.h>
#include <WebCore/DragData.h>
#include <WebCore/GraphicsContext.h>
#include <WebCore/Pasteboard.h>
#include <WebCore/PlatformContextCairo.h>
#include <WebCore/SelectionData.h>
#include <cairo.h>
namespace WebKit {
using namespace WebCore;
static RefPtr<ShareableBitmap> convertCairoSurfaceToShareableBitmap(cairo_surface_t* surface)
{
if (!surface)
return nullptr;
IntSize imageSize(cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface));
auto bitmap = ShareableBitmap::createShareable(imageSize, { });
auto graphicsContext = bitmap->createGraphicsContext();
ASSERT(graphicsContext->hasPlatformContext());
auto& state = graphicsContext->state();
Cairo::drawSurface(*graphicsContext->platformContext(), surface, IntRect(IntPoint(), imageSize), IntRect(IntPoint(), imageSize), state.imageInterpolationQuality, state.alpha, Cairo::ShadowState(state));
return bitmap;
}
void WebDragClient::didConcludeEditDrag()
{
}
void WebDragClient::startDrag(DragItem item, DataTransfer& dataTransfer, Frame&)
{
auto& dragImage = item.image;
RefPtr<ShareableBitmap> bitmap = convertCairoSurfaceToShareableBitmap(dragImage.get().get());
ShareableBitmap::Handle handle;
if (bitmap && !bitmap->createHandle(handle))
return;
m_page->willStartDrag();
m_page->send(Messages::WebPageProxy::StartDrag(dataTransfer.pasteboard().selectionData(), dataTransfer.sourceOperationMask(), handle));
}
};
#endif // ENABLE(DRAG_SUPPORT)