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 "DragActions.h"
28 #include "DragImage.h"
29 #include <wtf/text/WTFString.h>
34 class DataTransferItemList;
36 class DragImageLoader;
41 class DataTransfer : public RefCounted<DataTransfer> {
43 // https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode
44 enum class StoreMode { Invalid, ReadWrite, Readonly, Protected };
46 static Ref<DataTransfer> createForCopyAndPaste(StoreMode);
47 static Ref<DataTransfer> createForInputEvent(const String& plainText, const String& htmlText);
49 WEBCORE_EXPORT ~DataTransfer();
51 String dropEffect() const;
52 void setDropEffect(const String&);
54 String effectAllowed() const;
55 void setEffectAllowed(const String&);
57 DataTransferItemList& items();
58 Vector<String> types() const;
60 FileList& files() const;
62 void clearData(const String& type = String());
64 String getData(const String& type) const;
66 void setData(const String& type, const String& data);
68 void setDragImage(Element*, int x, int y);
70 void makeInvalidForSecurity() { m_storeMode = StoreMode::Invalid; }
72 bool canReadTypes() const;
73 bool canReadData() const;
74 bool canWriteData() const;
76 bool hasFileOfType(const String&);
77 bool hasStringOfType(const String&);
79 Pasteboard& pasteboard() { return *m_pasteboard; }
81 #if ENABLE(DRAG_SUPPORT)
82 static Ref<DataTransfer> createForDrag();
83 static Ref<DataTransfer> createForDrop(StoreMode, const DragData&);
85 bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
87 DragOperation sourceOperation() const;
88 DragOperation destinationOperation() const;
89 void setSourceOperation(DragOperation);
90 void setDestinationOperation(DragOperation);
92 void setDragHasStarted() { m_shouldUpdateDragImage = true; }
93 DragImageRef createDragImage(IntPoint& dragLocation) const;
94 void updateDragImage();
98 enum class Type { CopyAndPaste, DragAndDropData, DragAndDropFiles, InputEvent };
99 DataTransfer(StoreMode, std::unique_ptr<Pasteboard>, Type = Type::CopyAndPaste);
101 StoreMode m_storeMode;
102 std::unique_ptr<Pasteboard> m_pasteboard;
103 std::unique_ptr<DataTransferItemList> m_itemList;
105 mutable RefPtr<FileList> m_fileList;
107 #if ENABLE(DRAG_SUPPORT)
111 String m_effectAllowed;
112 bool m_shouldUpdateDragImage;
113 IntPoint m_dragLocation;
114 CachedResourceHandle<CachedImage> m_dragImage;
115 RefPtr<Element> m_dragImageElement;
116 std::unique_ptr<DragImageLoader> m_dragImageLoader;
120 } // namespace WebCore