WebDragClientGtk.cpp [plain text]
#include "config.h"
#include "WebDragClient.h"
#include "ArgumentCodersGtk.h"
#include "ShareableBitmap.h"
#include "WebPage.h"
#include "WebPageProxyMessages.h"
#include <WebCore/ClipboardGtk.h>
#include <WebCore/DragData.h>
#include <WebCore/GraphicsContext.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);
OwnPtr<GraphicsContext> 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, Clipboard* clipboard, Frame*, bool)
{
RefPtr<ShareableBitmap> bitmap = convertCairoSurfaceToShareableBitmap(dragImage);
ShareableBitmap::Handle handle;
if (bitmap && !bitmap->createHandle(handle))
return;
RefPtr<DataObjectGtk> dataObject = reinterpret_cast<ClipboardGtk*>(clipboard)->dataObject();
DragData dragData(dataObject.get(), clientPosition, globalPosition, clipboard->sourceOperation());
m_page->send(Messages::WebPageProxy::StartDrag(dragData, handle));
}
};