1/*
2 * Copyright (C) 2007 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. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "Color.h"
29#include "DragActions.h"
30#include "IntPoint.h"
31#include <wtf/Forward.h>
32#include <wtf/HashMap.h>
33#include <wtf/Vector.h>
34#include <wtf/text/WTFString.h>
35
36#if PLATFORM(MAC)
37
38#ifdef __OBJC__
39#import <Foundation/Foundation.h>
40#import <AppKit/NSDragging.h>
41typedef id <NSDraggingInfo> DragDataRef;
42#else
43typedef void* DragDataRef;
44#endif
45
46#elif PLATFORM(WIN)
47typedef struct IDataObject* DragDataRef;
48#elif PLATFORM(GTK)
49namespace WebCore {
50class SelectionData;
51}
52typedef WebCore::SelectionData* DragDataRef;
53#else
54typedef void* DragDataRef;
55#endif
56
57namespace WebCore {
58
59enum DragApplicationFlags {
60 DragApplicationNone = 0,
61 DragApplicationIsModal = 1,
62 DragApplicationIsSource = 2,
63 DragApplicationHasAttachedSheet = 4,
64 DragApplicationIsCopyKeyDown = 8
65};
66
67#if PLATFORM(WIN)
68typedef HashMap<unsigned, Vector<String>> DragDataMap;
69#endif
70
71class DragData {
72public:
73 enum FilenameConversionPolicy { DoNotConvertFilenames, ConvertFilenames };
74 enum class DraggingPurpose { ForEditing, ForFileUpload, ForColorControl };
75
76 // clientPosition is taken to be the position of the drag event within the target window, with (0,0) at the top left
77 WEBCORE_EXPORT DragData(DragDataRef, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation, DragApplicationFlags = DragApplicationNone, DragDestinationAction actions = DragDestinationActionAny);
78 WEBCORE_EXPORT DragData(const String& dragStorageName, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation, DragApplicationFlags = DragApplicationNone, DragDestinationAction actions = DragDestinationActionAny);
79 // This constructor should used only by WebKit2 IPC because DragData
80 // is initialized by the decoder and not in the constructor.
81 DragData() { }
82#if PLATFORM(WIN)
83 WEBCORE_EXPORT DragData(const DragDataMap&, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation sourceOperationMask, DragApplicationFlags = DragApplicationNone);
84 const DragDataMap& dragDataMap();
85 void getDragFileDescriptorData(int& size, String& pathname);
86 void getDragFileContentData(int size, void* dataBlob);
87#endif
88 const IntPoint& clientPosition() const { return m_clientPosition; }
89 const IntPoint& globalPosition() const { return m_globalPosition; }
90 DragApplicationFlags flags() const { return m_applicationFlags; }
91 DragDataRef platformData() const { return m_platformDragData; }
92 DragOperation draggingSourceOperationMask() const { return m_draggingSourceOperationMask; }
93 bool containsURL(FilenameConversionPolicy = ConvertFilenames) const;
94 bool containsPlainText() const;
95 bool containsCompatibleContent(DraggingPurpose = DraggingPurpose::ForEditing) const;
96 String asURL(FilenameConversionPolicy = ConvertFilenames, String* title = nullptr) const;
97 String asPlainText() const;
98 Vector<String> asFilenames() const;
99 Color asColor() const;
100 bool canSmartReplace() const;
101 bool containsColor() const;
102 bool containsFiles() const;
103 unsigned numberOfFiles() const;
104 DragDestinationAction dragDestinationAction() const { return m_dragDestinationAction; }
105 void setFileNames(Vector<String>& fileNames) { m_fileNames = WTFMove(fileNames); }
106 const Vector<String>& fileNames() const { return m_fileNames; }
107#if PLATFORM(COCOA)
108 const String& pasteboardName() const { return m_pasteboardName; }
109 bool containsURLTypeIdentifier() const;
110 bool containsPromise() const;
111#endif
112
113#if PLATFORM(GTK)
114
115 DragData& operator =(const DragData& data)
116 {
117 m_clientPosition = data.m_clientPosition;
118 m_globalPosition = data.m_globalPosition;
119 m_platformDragData = data.m_platformDragData;
120 m_draggingSourceOperationMask = data.m_draggingSourceOperationMask;
121 m_applicationFlags = data.m_applicationFlags;
122 m_dragDestinationAction = data.m_dragDestinationAction;
123 return *this;
124 }
125#endif
126
127private:
128 IntPoint m_clientPosition;
129 IntPoint m_globalPosition;
130 DragDataRef m_platformDragData;
131 DragOperation m_draggingSourceOperationMask;
132 DragApplicationFlags m_applicationFlags;
133 Vector<String> m_fileNames;
134 DragDestinationAction m_dragDestinationAction;
135#if PLATFORM(COCOA)
136 String m_pasteboardName;
137#endif
138#if PLATFORM(WIN)
139 DragDataMap m_dragDataMap;
140#endif
141};
142
143}
144