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 "wtf/Forward.h"
33 #include "wtf/RefCounted.h"
34 #include "wtf/RefPtr.h"
35 #include "wtf/Vector.h"
40 class DataTransferItemList;
50 // State available during IE's events for drag and drop and copy/paste
51 class Clipboard : public RefCounted<Clipboard>, public ScriptWrappable {
53 // Whether this clipboard is serving a drag-drop or copy-paste request.
59 static PassRefPtr<Clipboard> create(ClipboardType, ClipboardAccessPolicy, PassRefPtr<DataObject>);
62 bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; }
63 bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; }
65 String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; }
66 void setDropEffect(const String&);
67 bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
68 String effectAllowed() const { return m_effectAllowed; }
69 void setEffectAllowed(const String&);
71 void clearData(const String& type = String());
72 String getData(const String& type) const;
73 bool setData(const String& type, const String& data);
75 // extensions beyond IE's API
76 Vector<String> types() const;
77 PassRefPtr<FileList> files() const;
79 IntPoint dragLocation() const { return m_dragLoc; }
80 void setDragImage(Element*, int x, int y, ExceptionState&);
81 ImageResource* dragImageResource() const { return m_dragImage.get(); }
82 void setDragImageResource(ImageResource*, const IntPoint&);
83 Node* dragImageElement() const { return m_dragImageElement.get(); }
84 void setDragImageElement(Node*, const IntPoint&);
86 PassOwnPtr<DragImage> createDragImage(IntPoint& dragLocation, Frame*) const;
87 void declareAndWriteDragImage(Element*, const KURL&, const String& title);
88 void writeURL(const KURL&, const String&);
89 void writeRange(Range*, Frame*);
90 void writePlainText(const String&);
94 void setAccessPolicy(ClipboardAccessPolicy);
95 bool canReadTypes() const;
96 bool canReadData() const;
97 bool canWriteData() const;
98 // Note that the spec doesn't actually allow drag image modification outside the dragstart
99 // event. This capability is maintained for backwards compatiblity for ports that have
100 // supported this in the past. On many ports, attempting to set a drag image outside the
101 // dragstart operation is a no-op anyway.
102 bool canSetDragImage() const;
104 DragOperation sourceOperation() const;
105 DragOperation destinationOperation() const;
106 void setSourceOperation(DragOperation);
107 void setDestinationOperation(DragOperation);
109 bool hasDropZoneType(const String&);
111 PassRefPtr<DataTransferItemList> items();
113 PassRefPtr<DataObject> dataObject() const;
116 Clipboard(ClipboardType, ClipboardAccessPolicy, PassRefPtr<DataObject>);
118 void setDragImage(ImageResource*, Node*, const IntPoint&);
120 bool hasFileOfType(const String&) const;
121 bool hasStringOfType(const String&) const;
123 // Instead of using this member directly, prefer to use the can*() methods above.
124 ClipboardAccessPolicy m_policy;
126 String m_effectAllowed;
127 ClipboardType m_clipboardType;
128 RefPtr<DataObject> m_dataObject;
131 ResourcePtr<ImageResource> m_dragImage;
132 RefPtr<Node> m_dragImageElement;
135 DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation);
136 String convertDragOperationToDropZoneOperation(DragOperation);
138 } // namespace WebCore
140 #endif // Clipboard_h