Home | History | Annotate | Download | only in clipboard
      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/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"
     37 
     38 namespace WebCore {
     39 
     40 class DataObject;
     41 class DataTransferItemList;
     42 class DragImage;
     43 class Element;
     44 class ExceptionState;
     45 class FileList;
     46 class LocalFrame;
     47 class ImageResource;
     48 class Node;
     49 class Range;
     50 
     51 // State available during IE's events for drag and drop and copy/paste
     52 class Clipboard : public RefCountedWillBeGarbageCollectedFinalized<Clipboard>, public ScriptWrappable {
     53 public:
     54     // Whether this clipboard is serving a drag-drop or copy-paste request.
     55     enum ClipboardType {
     56         CopyAndPaste,
     57         DragAndDrop,
     58     };
     59 
     60     static PassRefPtrWillBeRawPtr<Clipboard> create(ClipboardType, ClipboardAccessPolicy, PassRefPtrWillBeRawPtr<DataObject>);
     61     ~Clipboard();
     62 
     63     bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; }
     64     bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; }
     65 
     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&);
     71 
     72     void clearData(const String& type = String());
     73     String getData(const String& type) const;
     74     bool setData(const String& type, const String& data);
     75 
     76     // extensions beyond IE's API
     77     Vector<String> types() const;
     78     PassRefPtrWillBeRawPtr<FileList> files() const;
     79 
     80     IntPoint dragLocation() const { return m_dragLoc; }
     81     void setDragImage(Element*, int x, int y, ExceptionState&);
     82     void clearDragImage();
     83     ImageResource* dragImageResource() const { return m_dragImage.get(); }
     84     void setDragImageResource(ImageResource*, const IntPoint&);
     85     Node* dragImageElement() const { return m_dragImageElement.get(); }
     86     void setDragImageElement(Node*, const IntPoint&);
     87 
     88     PassOwnPtr<DragImage> createDragImage(IntPoint& dragLocation, LocalFrame*) const;
     89     void declareAndWriteDragImage(Element*, const KURL&, const String& title);
     90     void writeURL(const KURL&, const String&);
     91     void writeRange(Range*, LocalFrame*);
     92     void writePlainText(const String&);
     93 
     94     bool hasData();
     95 
     96     void setAccessPolicy(ClipboardAccessPolicy);
     97     bool canReadTypes() const;
     98     bool canReadData() const;
     99     bool canWriteData() const;
    100     // Note that the spec doesn't actually allow drag image modification outside the dragstart
    101     // event. This capability is maintained for backwards compatiblity for ports that have
    102     // supported this in the past. On many ports, attempting to set a drag image outside the
    103     // dragstart operation is a no-op anyway.
    104     bool canSetDragImage() const;
    105 
    106     DragOperation sourceOperation() const;
    107     DragOperation destinationOperation() const;
    108     void setSourceOperation(DragOperation);
    109     void setDestinationOperation(DragOperation);
    110 
    111     bool hasDropZoneType(const String&);
    112 
    113     PassRefPtrWillBeRawPtr<DataTransferItemList> items();
    114 
    115     PassRefPtrWillBeRawPtr<DataObject> dataObject() const;
    116 
    117     void trace(Visitor*);
    118 
    119 private:
    120     Clipboard(ClipboardType, ClipboardAccessPolicy, PassRefPtrWillBeRawPtr<DataObject>);
    121 
    122     void setDragImage(ImageResource*, Node*, const IntPoint&);
    123 
    124     bool hasFileOfType(const String&) const;
    125     bool hasStringOfType(const String&) const;
    126 
    127     // Instead of using this member directly, prefer to use the can*() methods above.
    128     ClipboardAccessPolicy m_policy;
    129     String m_dropEffect;
    130     String m_effectAllowed;
    131     ClipboardType m_clipboardType;
    132     RefPtrWillBeMember<DataObject> m_dataObject;
    133 
    134     IntPoint m_dragLoc;
    135     ResourcePtr<ImageResource> m_dragImage;
    136     RefPtrWillBeMember<Node> m_dragImageElement;
    137 };
    138 
    139 DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation);
    140 String convertDragOperationToDropZoneOperation(DragOperation);
    141 
    142 } // namespace WebCore
    143 
    144 #endif // Clipboard_h
    145