2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003-2016 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 #include "CachedResourceHandle.h"
27 #include "DataTransferAccessPolicy.h"
28 #include "DragActions.h"
29 #include "DragImage.h"
30 #include <wtf/text/WTFString.h>
35 class DataTransferItemList;
37 class DragImageLoader;
42 class DataTransfer : public RefCounted<DataTransfer> {
44 static Ref<DataTransfer> createForCopyAndPaste(DataTransferAccessPolicy);
45 static Ref<DataTransfer> createForInputEvent(const String& plainText, const String& htmlText);
47 WEBCORE_EXPORT ~DataTransfer();
49 String dropEffect() const;
50 void setDropEffect(const String&);
52 String effectAllowed() const;
53 void setEffectAllowed(const String&);
55 DataTransferItemList& items();
56 Vector<String> types() const;
58 FileList& files() const;
60 void clearData(const String& type = String());
62 String getData(const String& type) const;
64 void setData(const String& type, const String& data);
66 void setDragImage(Element*, int x, int y);
68 void setAccessPolicy(DataTransferAccessPolicy);
69 bool canReadTypes() const;
70 bool canReadData() const;
71 bool canWriteData() const;
73 bool hasFileOfType(const String&);
74 bool hasStringOfType(const String&);
76 Pasteboard& pasteboard() { return *m_pasteboard; }
78 #if ENABLE(DRAG_SUPPORT)
79 static Ref<DataTransfer> createForDrag();
80 static Ref<DataTransfer> createForDrop(DataTransferAccessPolicy, const DragData&);
82 bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
84 DragOperation sourceOperation() const;
85 DragOperation destinationOperation() const;
86 void setSourceOperation(DragOperation);
87 void setDestinationOperation(DragOperation);
89 void setDragHasStarted() { m_shouldUpdateDragImage = true; }
90 DragImageRef createDragImage(IntPoint& dragLocation) const;
91 void updateDragImage();
95 enum Type { CopyAndPaste, DragAndDrop, InputEvent };
96 DataTransfer(DataTransferAccessPolicy, std::unique_ptr<Pasteboard>, Type = CopyAndPaste, bool forFileDrag = false);
98 #if ENABLE(DRAG_SUPPORT)
99 bool canSetDragImage() const;
102 DataTransferAccessPolicy m_policy;
103 std::unique_ptr<Pasteboard> m_pasteboard;
104 std::unique_ptr<DataTransferItemList> m_itemList;
106 mutable RefPtr<FileList> m_fileList;
108 #if ENABLE(DRAG_SUPPORT)
112 String m_effectAllowed;
113 bool m_shouldUpdateDragImage;
114 IntPoint m_dragLocation;
115 CachedResourceHandle<CachedImage> m_dragImage;
116 RefPtr<Element> m_dragImageElement;
117 std::unique_ptr<DragImageLoader> m_dragImageLoader;
121 } // namespace WebCore