1/* 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, 2013 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 "CachedResourceHandle.h" 28#include "ClipboardAccessPolicy.h" 29#include "DragActions.h" 30#include "DragImage.h" 31#include "IntPoint.h" 32#include "Node.h" 33 34// This DOM object now works by calling through to classes in the platform layer. 35// Specifically, the class currently named Pasteboard. The legacy style instead 36// uses this as an abstract base class. 37#define WTF_USE_LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS PLATFORM(IOS) 38 39#if USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS) 40#define LEGACY_VIRTUAL virtual 41#else 42#define LEGACY_VIRTUAL 43#endif 44 45#if USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS) 46#define LEGACY_PURE = 0 47#else 48#define LEGACY_PURE 49#endif 50 51namespace WebCore { 52 53 class CachedImage; 54 class DataTransferItemList; 55 class DragData; 56 class DragImageLoader; 57 class FileList; 58 class Frame; 59 class Pasteboard; 60 61 // State available during IE's events for drag and drop and copy/paste 62 class Clipboard : public RefCounted<Clipboard> { 63 public: 64 // Whether this clipboard is serving a drag-drop or copy-paste request. 65 enum ClipboardType { 66 CopyAndPaste, 67 DragAndDrop, 68 }; 69 70 static PassRefPtr<Clipboard> create(ClipboardAccessPolicy, DragData*, Frame*); 71 72 LEGACY_VIRTUAL ~Clipboard(); 73 74 bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; } 75 bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; } 76 77 String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; } 78 void setDropEffect(const String&); 79 bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; } 80 String effectAllowed() const { return m_effectAllowed; } 81 void setEffectAllowed(const String&); 82 83 LEGACY_VIRTUAL void clearData(const String& type) LEGACY_PURE; 84 LEGACY_VIRTUAL void clearData() LEGACY_PURE; 85 86 void setDragImage(Element*, int x, int y); 87#if USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS) 88 virtual void setDragImage(CachedImage*, const IntPoint&) = 0; 89 virtual void setDragImageElement(Node*, const IntPoint&) = 0; 90#endif 91 92 LEGACY_VIRTUAL String getData(const String& type) const LEGACY_PURE; 93 LEGACY_VIRTUAL bool setData(const String& type, const String& data) LEGACY_PURE; 94 95 LEGACY_VIRTUAL ListHashSet<String> types() const LEGACY_PURE; 96 LEGACY_VIRTUAL PassRefPtr<FileList> files() const LEGACY_PURE; 97 98 IntPoint dragLocation() const { return m_dragLoc; } 99 CachedImage* dragImage() const { return m_dragImage.get(); } 100 Node* dragImageElement() const { return m_dragImageElement.get(); } 101 102 LEGACY_VIRTUAL DragImageRef createDragImage(IntPoint& dragLocation) const LEGACY_PURE; 103#if ENABLE(DRAG_SUPPORT) 104 LEGACY_VIRTUAL void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*) LEGACY_PURE; 105#endif 106 LEGACY_VIRTUAL void writeURL(const KURL&, const String&, Frame*) LEGACY_PURE; 107 LEGACY_VIRTUAL void writeRange(Range*, Frame*) LEGACY_PURE; 108 LEGACY_VIRTUAL void writePlainText(const String&) LEGACY_PURE; 109 110 LEGACY_VIRTUAL bool hasData() LEGACY_PURE; 111 112 void setAccessPolicy(ClipboardAccessPolicy); 113 bool canReadTypes() const; 114 bool canReadData() const; 115 bool canWriteData() const; 116 // Note that the spec doesn't actually allow drag image modification outside the dragstart 117 // event. This capability is maintained for backwards compatiblity for ports that have 118 // supported this in the past. On many ports, attempting to set a drag image outside the 119 // dragstart operation is a no-op anyway. 120 bool canSetDragImage() const; 121 122 DragOperation sourceOperation() const; 123 DragOperation destinationOperation() const; 124 void setSourceOperation(DragOperation); 125 void setDestinationOperation(DragOperation); 126 127 bool hasDropZoneType(const String&); 128 129 void setDragHasStarted() { m_dragStarted = true; } 130 131#if ENABLE(DATA_TRANSFER_ITEMS) 132 LEGACY_VIRTUAL PassRefPtr<DataTransferItemList> items() = 0; 133#endif 134 135#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS) 136 static PassRefPtr<Clipboard> createForCopyAndPaste(ClipboardAccessPolicy); 137 138 const Pasteboard& pasteboard() { return *m_pasteboard; } 139#endif 140 141#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS) && ENABLE(DRAG_SUPPORT) 142 static PassRefPtr<Clipboard> createForDragAndDrop(); 143 144 void updateDragImage(); 145#endif 146 147 protected: 148#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS) 149 Clipboard(ClipboardAccessPolicy, ClipboardType, PassOwnPtr<Pasteboard>, bool forFileDrag = false); 150#else 151 Clipboard(ClipboardAccessPolicy, ClipboardType); 152#endif 153 154 bool dragStarted() const { return m_dragStarted; } 155 156 private: 157 bool hasFileOfType(const String&) const; 158 bool hasStringOfType(const String&) const; 159 160 // Instead of using this member directly, prefer to use the can*() methods above. 161 ClipboardAccessPolicy m_policy; 162 String m_dropEffect; 163 String m_effectAllowed; 164 bool m_dragStarted; 165 ClipboardType m_clipboardType; 166 167 protected: 168 IntPoint m_dragLoc; 169 CachedResourceHandle<CachedImage> m_dragImage; 170 RefPtr<Node> m_dragImageElement; 171 172#if !USE(LEGACY_STYLE_ABSTRACT_CLIPBOARD_CLASS) 173 private: 174 OwnPtr<Pasteboard> m_pasteboard; 175 bool m_forFileDrag; 176#if ENABLE(DRAG_SUPPORT) 177 OwnPtr<DragImageLoader> m_dragImageLoader; 178#endif 179#endif 180 }; 181 182 DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation); 183 String convertDragOperationToDropZoneOperation(DragOperation); 184 185#undef LEGACY_VIRTUAL 186#undef LEGACY_PURE 187 188} // namespace WebCore 189 190#endif // Clipboard_h 191