| 1 | /* |
| 2 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "DragActions.h" |
| 29 | #include "DragImage.h" |
| 30 | #include "FloatPoint.h" |
| 31 | #include "IntPoint.h" |
| 32 | #include "IntRect.h" |
| 33 | #include "PasteboardWriterData.h" |
| 34 | #include "PromisedAttachmentInfo.h" |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | struct DragItem final { |
| 39 | DragImage image; |
| 40 | |
| 41 | // Where the image should be positioned relative to the cursor. |
| 42 | FloatPoint imageAnchorPoint; |
| 43 | |
| 44 | DragSourceAction sourceAction { DragSourceActionNone }; |
| 45 | IntPoint eventPositionInContentCoordinates; |
| 46 | IntPoint dragLocationInContentCoordinates; |
| 47 | IntPoint dragLocationInWindowCoordinates; |
| 48 | String title; |
| 49 | URL url; |
| 50 | IntRect dragPreviewFrameInRootViewCoordinates; |
| 51 | |
| 52 | PasteboardWriterData data; |
| 53 | PromisedAttachmentInfo promisedAttachmentInfo; |
| 54 | |
| 55 | template<class Encoder> void encode(Encoder&) const; |
| 56 | template<class Decoder> static bool decode(Decoder&, DragItem&); |
| 57 | }; |
| 58 | |
| 59 | template<class Encoder> |
| 60 | void DragItem::encode(Encoder& encoder) const |
| 61 | { |
| 62 | // FIXME(173815): We should encode and decode PasteboardWriterData and platform drag image data |
| 63 | // here too, as part of moving off of the legacy dragging codepath. |
| 64 | encoder.encodeEnum(sourceAction); |
| 65 | encoder << imageAnchorPoint << eventPositionInContentCoordinates << dragLocationInContentCoordinates << dragLocationInWindowCoordinates << title << url << dragPreviewFrameInRootViewCoordinates; |
| 66 | bool hasIndicatorData = image.hasIndicatorData(); |
| 67 | encoder << hasIndicatorData; |
| 68 | if (hasIndicatorData) |
| 69 | encoder << image.indicatorData().value(); |
| 70 | bool hasVisiblePath = image.hasVisiblePath(); |
| 71 | encoder << hasVisiblePath; |
| 72 | if (hasVisiblePath) |
| 73 | encoder << image.visiblePath().value(); |
| 74 | encoder << promisedAttachmentInfo; |
| 75 | } |
| 76 | |
| 77 | template<class Decoder> |
| 78 | bool DragItem::decode(Decoder& decoder, DragItem& result) |
| 79 | { |
| 80 | if (!decoder.decodeEnum(result.sourceAction)) |
| 81 | return false; |
| 82 | if (!decoder.decode(result.imageAnchorPoint)) |
| 83 | return false; |
| 84 | if (!decoder.decode(result.eventPositionInContentCoordinates)) |
| 85 | return false; |
| 86 | if (!decoder.decode(result.dragLocationInContentCoordinates)) |
| 87 | return false; |
| 88 | if (!decoder.decode(result.dragLocationInWindowCoordinates)) |
| 89 | return false; |
| 90 | if (!decoder.decode(result.title)) |
| 91 | return false; |
| 92 | if (!decoder.decode(result.url)) |
| 93 | return false; |
| 94 | if (!decoder.decode(result.dragPreviewFrameInRootViewCoordinates)) |
| 95 | return false; |
| 96 | bool hasIndicatorData; |
| 97 | if (!decoder.decode(hasIndicatorData)) |
| 98 | return false; |
| 99 | if (hasIndicatorData) { |
| 100 | Optional<TextIndicatorData> indicatorData; |
| 101 | decoder >> indicatorData; |
| 102 | if (!indicatorData) |
| 103 | return false; |
| 104 | result.image.setIndicatorData(*indicatorData); |
| 105 | } |
| 106 | bool hasVisiblePath; |
| 107 | if (!decoder.decode(hasVisiblePath)) |
| 108 | return false; |
| 109 | if (hasVisiblePath) { |
| 110 | Optional<Path> visiblePath; |
| 111 | decoder >> visiblePath; |
| 112 | if (!visiblePath) |
| 113 | return false; |
| 114 | result.image.setVisiblePath(*visiblePath); |
| 115 | } |
| 116 | if (!decoder.decode(result.promisedAttachmentInfo)) |
| 117 | return false; |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | } |
| 122 | |