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, 2004, 2005, 2006, 2008 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.
27 #include "bindings/v8/ScriptWrappable.h"
28 #include "core/clipboard/ClipboardAccessPolicy.h"
29 #include "core/fetch/ResourcePtr.h"
30 #include "core/page/DragActions.h"
31 #include "platform/geometry/IntPoint.h"
32 #include "platform/heap/Handle.h"
33 #include "wtf/Forward.h"
34 #include "wtf/RefCounted.h"
35 #include "wtf/RefPtr.h"
36 #include "wtf/Vector.h"
41 class DataTransferItemList;
51 // State available during IE's events for drag and drop and copy/paste
52 class Clipboard : public RefCountedWillBeGarbageCollectedFinalized<Clipboard>, public ScriptWrappable {
54 // Whether this clipboard is serving a drag-drop or copy-paste request.
60 static PassRefPtrWillBeRawPtr<Clipboard> create(ClipboardType, ClipboardAccessPolicy, PassRefPtrWillBeRawPtr<DataObject>);
63 bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; }
64 bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; }
66 String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; }
67 void setDropEffect(const String&);
68 bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
69 String effectAllowed() const { return m_effectAllowed; }
70 void setEffectAllowed(const String&);
72 void clearData(const String& type = String());
73 String getData(const String& type) const;
74 bool setData(const String& type, const String& data);
76 // extensions beyond IE's API
77 Vector<String> types() const;
78 PassRefPtrWillBeRawPtr<FileList> files() const;
80 IntPoint dragLocation() const { return m_dragLoc; }
81 void setDragImage(Element*, int x, int y, ExceptionState&);
82 ImageResource* dragImageResource() const { return m_dragImage.get(); }
83 void setDragImageResource(ImageResource*, const IntPoint&);
84 Node* dragImageElement() const { return m_dragImageElement.get(); }
85 void setDragImageElement(Node*, const IntPoint&);
87 PassOwnPtr<DragImage> createDragImage(IntPoint& dragLocation, LocalFrame*) const;
88 void declareAndWriteDragImage(Element*, const KURL&, const String& title);
89 void writeURL(const KURL&, const String&);
90 void writeRange(Range*, LocalFrame*);
91 void writePlainText(const String&);
95 void setAccessPolicy(ClipboardAccessPolicy);
96 bool canReadTypes() const;
97 bool canReadData() const;
98 bool canWriteData() const;
99 // Note that the spec doesn't actually allow drag image modification outside the dragstart
100 // event. This capability is maintained for backwards compatiblity for ports that have
101 // supported this in the past. On many ports, attempting to set a drag image outside the
102 // dragstart operation is a no-op anyway.
103 bool canSetDragImage() const;
105 DragOperation sourceOperation() const;
106 DragOperation destinationOperation() const;
107 void setSourceOperation(DragOperation);
108 void setDestinationOperation(DragOperation);
110 bool hasDropZoneType(const String&);
112 PassRefPtrWillBeRawPtr<DataTransferItemList> items();
114 PassRefPtrWillBeRawPtr<DataObject> dataObject() const;
116 void trace(Visitor*);
119 Clipboard(ClipboardType, ClipboardAccessPolicy, PassRefPtrWillBeRawPtr<DataObject>);
121 void setDragImage(ImageResource*, Node*, const IntPoint&);
123 bool hasFileOfType(const String&) const;
124 bool hasStringOfType(const String&) const;
126 // Instead of using this member directly, prefer to use the can*() methods above.
127 ClipboardAccessPolicy m_policy;
129 String m_effectAllowed;
130 ClipboardType m_clipboardType;
131 RefPtrWillBeMember<DataObject> m_dataObject;
134 ResourcePtr<ImageResource> m_dragImage;
135 RefPtr<Node> m_dragImageElement;
138 DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation);
139 String convertDragOperationToDropZoneOperation(DragOperation);
141 } // namespace WebCore
143 #endif // Clipboard_h