#pragma once
#include "DragImage.h"
#include "FloatPoint.h"
#include "IntPoint.h"
#include "IntRect.h"
#include "PasteboardWriterData.h"
namespace WebCore {
struct DragItem final {
DragImage image;
FloatPoint imageAnchorPoint;
DragSourceAction sourceAction { DragSourceActionNone };
IntPoint eventPositionInContentCoordinates;
IntPoint dragLocationInContentCoordinates;
IntPoint dragLocationInWindowCoordinates;
String title;
URL url;
IntRect dragPreviewFrameInRootViewCoordinates;
PasteboardWriterData data;
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static bool decode(Decoder&, DragItem&);
};
template<class Encoder>
void DragItem::encode(Encoder& encoder) const
{
encoder.encodeEnum(sourceAction);
encoder << imageAnchorPoint << eventPositionInContentCoordinates << dragLocationInContentCoordinates << dragLocationInWindowCoordinates << title << url << dragPreviewFrameInRootViewCoordinates;
bool hasIndicatorData = image.hasIndicatorData();
encoder << hasIndicatorData;
if (hasIndicatorData)
encoder << image.indicatorData().value();
}
template<class Decoder>
bool DragItem::decode(Decoder& decoder, DragItem& result)
{
if (!decoder.decodeEnum(result.sourceAction))
return false;
if (!decoder.decode(result.imageAnchorPoint))
return false;
if (!decoder.decode(result.eventPositionInContentCoordinates))
return false;
if (!decoder.decode(result.dragLocationInContentCoordinates))
return false;
if (!decoder.decode(result.dragLocationInWindowCoordinates))
return false;
if (!decoder.decode(result.title))
return false;
if (!decoder.decode(result.url))
return false;
if (!decoder.decode(result.dragPreviewFrameInRootViewCoordinates))
return false;
bool hasIndicatorData;
if (!decoder.decode(hasIndicatorData))
return false;
if (hasIndicatorData) {
std::optional<TextIndicatorData> indicatorData;
decoder >> indicatorData;
if (!indicatorData)
return false;
result.image.setIndicatorData(*indicatorData);
}
return true;
}
}