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 DataTransfer_h
     25 #define DataTransfer_h
     26 
     27 #include "bindings/core/v8/ScriptWrappable.h"
     28 #include "core/clipboard/DataTransferAccessPolicy.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 blink {
     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 // Used for drag and drop and copy/paste.
     52 // Drag and Drop: http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html
     53 // Clipboard API (copy/paste): http://dev.w3.org/2006/webapi/clipops/clipops.html
     54 class DataTransfer : public RefCountedWillBeGarbageCollectedFinalized<DataTransfer>, public ScriptWrappable {
     55     DEFINE_WRAPPERTYPEINFO();
     56 public:
     57     // Whether this transfer is serving a drag-drop or copy-paste request.
     58     enum DataTransferType {
     59         CopyAndPaste,
     60         DragAndDrop,
     61     };
     62 
     63     static PassRefPtrWillBeRawPtr<DataTransfer> create(DataTransferType, DataTransferAccessPolicy, PassRefPtrWillBeRawPtr<DataObject>);
     64     ~DataTransfer();
     65 
     66     bool isForCopyAndPaste() const { return m_transferType == CopyAndPaste; }
     67     bool isForDragAndDrop() const { return m_transferType == DragAndDrop; }
     68 
     69     String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; }
     70     void setDropEffect(const String&);
     71     bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
     72     String effectAllowed() const { return m_effectAllowed; }
     73     void setEffectAllowed(const String&);
     74 
     75     void clearData(const String& type = String());
     76     String getData(const String& type) const;
     77     void setData(const String& type, const String& data);
     78 
     79     // extensions beyond IE's API
     80     Vector<String> types() const;
     81     PassRefPtrWillBeRawPtr<FileList> files() const;
     82 
     83     IntPoint dragLocation() const { return m_dragLoc; }
     84     void setDragImage(Element*, int x, int y, ExceptionState&);
     85     void clearDragImage();
     86     ImageResource* dragImageResource() const { return m_dragImage.get(); }
     87     void setDragImageResource(ImageResource*, const IntPoint&);
     88     Node* dragImageElement() const { return m_dragImageElement.get(); }
     89     void setDragImageElement(Node*, const IntPoint&);
     90 
     91     PassOwnPtr<DragImage> createDragImage(IntPoint& dragLocation, LocalFrame*) const;
     92     void declareAndWriteDragImage(Element*, const KURL&, const String& title);
     93     void writeURL(const KURL&, const String&);
     94     void writeRange(Range*, LocalFrame*);
     95     void writePlainText(const String&);
     96 
     97     bool hasData();
     98 
     99     void setAccessPolicy(DataTransferAccessPolicy);
    100     bool canReadTypes() const;
    101     bool canReadData() const;
    102     bool canWriteData() const;
    103     // Note that the spec doesn't actually allow drag image modification outside the dragstart
    104     // event. This capability is maintained for backwards compatiblity for ports that have
    105     // supported this in the past. On many ports, attempting to set a drag image outside the
    106     // dragstart operation is a no-op anyway.
    107     bool canSetDragImage() const;
    108 
    109     DragOperation sourceOperation() const;
    110     DragOperation destinationOperation() const;
    111     void setSourceOperation(DragOperation);
    112     void setDestinationOperation(DragOperation);
    113 
    114     bool hasDropZoneType(const String&);
    115 
    116     PassRefPtrWillBeRawPtr<DataTransferItemList> items();
    117 
    118     PassRefPtrWillBeRawPtr<DataObject> dataObject() const;
    119 
    120     void trace(Visitor*);
    121 
    122 private:
    123     DataTransfer(DataTransferType, DataTransferAccessPolicy, PassRefPtrWillBeRawPtr<DataObject>);
    124 
    125     void setDragImage(ImageResource*, Node*, const IntPoint&);
    126 
    127     bool hasFileOfType(const String&) const;
    128     bool hasStringOfType(const String&) const;
    129 
    130     // Instead of using this member directly, prefer to use the can*() methods above.
    131     DataTransferAccessPolicy m_policy;
    132     String m_dropEffect;
    133     String m_effectAllowed;
    134     DataTransferType m_transferType;
    135     RefPtrWillBeMember<DataObject> m_dataObject;
    136 
    137     IntPoint m_dragLoc;
    138     ResourcePtr<ImageResource> m_dragImage;
    139     RefPtrWillBeMember<Node> m_dragImageElement;
    140 };
    141 
    142 DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation);
    143 String convertDragOperationToDropZoneOperation(DragOperation);
    144 
    145 } // namespace blink
    146 
    147 #endif // DataTransfer_h
    148