1 /* 2 * Copyright (C) 2001 Peter Kelly (pmk (at) post.com) 3 * Copyright (C) 2001 Tobias Anton (anton (at) stud.fbi.fh-darmstadt.de) 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig (at) gmail.com) 5 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 6 * 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. 11 * 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. 16 * 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. 21 * 22 */ 23 24 #ifndef Clipboard_h 25 #define Clipboard_h 26 27 #include "bindings/v8/ScriptWrappable.h" 28 #include "core/dom/ClipboardAccessPolicy.h" 29 #include "core/dom/Node.h" 30 #include "core/loader/cache/ResourcePtr.h" 31 #include "core/page/DragActions.h" 32 #include "core/platform/DragImage.h" 33 #include "core/platform/graphics/IntPoint.h" 34 #include "wtf/Forward.h" 35 36 namespace WebCore { 37 38 class ImageResource; 39 class DataTransferItemList; 40 class DragData; 41 class DragImage; 42 class FileList; 43 class Frame; 44 class Range; 45 46 // State available during IE's events for drag and drop and copy/paste 47 class Clipboard : public RefCounted<Clipboard>, public ScriptWrappable { 48 public: 49 // Whether this clipboard is serving a drag-drop or copy-paste request. 50 enum ClipboardType { 51 CopyAndPaste, 52 DragAndDrop, 53 }; 54 55 static PassRefPtr<Clipboard> create(ClipboardAccessPolicy, DragData*, Frame*); 56 57 virtual ~Clipboard() { } 58 59 bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; } 60 bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; } 61 62 String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; } 63 void setDropEffect(const String&); 64 bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; } 65 String effectAllowed() const { return m_effectAllowed; } 66 void setEffectAllowed(const String&); 67 68 virtual void clearData(const String& type) = 0; 69 virtual void clearAllData() = 0; 70 virtual String getData(const String& type) const = 0; 71 virtual bool setData(const String& type, const String& data) = 0; 72 73 // extensions beyond IE's API 74 virtual ListHashSet<String> types() const = 0; 75 virtual PassRefPtr<FileList> files() const = 0; 76 77 IntPoint dragLocation() const { return m_dragLoc; } 78 ImageResource* dragImage() const { return m_dragImage.get(); } 79 virtual void setDragImage(ImageResource*, const IntPoint&) = 0; 80 Node* dragImageElement() const { return m_dragImageElement.get(); } 81 virtual void setDragImageElement(Node*, const IntPoint&) = 0; 82 83 virtual PassOwnPtr<DragImage> createDragImage(IntPoint& dragLocation) const = 0; 84 virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*) = 0; 85 virtual void writeURL(const KURL&, const String&, Frame*) = 0; 86 virtual void writeRange(Range*, Frame*) = 0; 87 virtual void writePlainText(const String&) = 0; 88 89 virtual bool hasData() = 0; 90 91 void setAccessPolicy(ClipboardAccessPolicy); 92 bool canReadTypes() const; 93 bool canReadData() const; 94 bool canWriteData() const; 95 // Note that the spec doesn't actually allow drag image modification outside the dragstart 96 // event. This capability is maintained for backwards compatiblity for ports that have 97 // supported this in the past. On many ports, attempting to set a drag image outside the 98 // dragstart operation is a no-op anyway. 99 bool canSetDragImage() const; 100 101 DragOperation sourceOperation() const; 102 DragOperation destinationOperation() const; 103 void setSourceOperation(DragOperation); 104 void setDestinationOperation(DragOperation); 105 106 bool hasDropZoneType(const String&); 107 108 void setDragHasStarted() { m_dragStarted = true; } 109 110 virtual PassRefPtr<DataTransferItemList> items() = 0; 111 112 protected: 113 Clipboard(ClipboardAccessPolicy, ClipboardType); 114 115 bool dragStarted() const { return m_dragStarted; } 116 117 private: 118 bool hasFileOfType(const String&) const; 119 bool hasStringOfType(const String&) const; 120 121 // Instead of using this member directly, prefer to use the can*() methods above. 122 ClipboardAccessPolicy m_policy; 123 String m_dropEffect; 124 String m_effectAllowed; 125 bool m_dragStarted; 126 ClipboardType m_clipboardType; 127 128 protected: 129 IntPoint m_dragLoc; 130 ResourcePtr<ImageResource> m_dragImage; 131 RefPtr<Node> m_dragImageElement; 132 }; 133 134 DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation); 135 String convertDragOperationToDropZoneOperation(DragOperation); 136 137 } // namespace WebCore 138 139 #endif // Clipboard_h 140