Home | History | Annotate | Download | only in dom
      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 "CachedResourceHandle.h"
     28 #include "ClipboardAccessPolicy.h"
     29 #include "DragActions.h"
     30 #include "DragImage.h"
     31 #include "IntPoint.h"
     32 #include "Node.h"
     33 
     34 namespace WebCore {
     35 
     36     class DataTransferItems;
     37     class DragData;
     38     class FileList;
     39     class Frame;
     40 
     41     // State available during IE's events for drag and drop and copy/paste
     42     class Clipboard : public RefCounted<Clipboard> {
     43     public:
     44         // Whether this clipboard is serving a drag-drop or copy-paste request.
     45         enum ClipboardType {
     46             CopyAndPaste,
     47             DragAndDrop,
     48         };
     49         static PassRefPtr<Clipboard> create(ClipboardAccessPolicy, DragData*, Frame*);
     50 
     51         virtual ~Clipboard() { }
     52 
     53         bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; }
     54         bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; }
     55 
     56         String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; }
     57         void setDropEffect(const String&);
     58         bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
     59         String effectAllowed() const { return m_effectAllowed; }
     60         void setEffectAllowed(const String&);
     61 
     62         virtual void clearData(const String& type) = 0;
     63         virtual void clearAllData() = 0;
     64         virtual String getData(const String& type, bool& success) const = 0;
     65         virtual bool setData(const String& type, const String& data) = 0;
     66 
     67         // extensions beyond IE's API
     68         virtual HashSet<String> types() const = 0;
     69         virtual PassRefPtr<FileList> files() const = 0;
     70 
     71         IntPoint dragLocation() const { return m_dragLoc; }
     72         CachedImage* dragImage() const { return m_dragImage.get(); }
     73         virtual void setDragImage(CachedImage*, const IntPoint&) = 0;
     74         Node* dragImageElement() const { return m_dragImageElement.get(); }
     75         virtual void setDragImageElement(Node*, const IntPoint&) = 0;
     76 
     77         virtual DragImageRef createDragImage(IntPoint& dragLocation) const = 0;
     78 #if ENABLE(DRAG_SUPPORT)
     79         virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*) = 0;
     80 #endif
     81         virtual void writeURL(const KURL&, const String&, Frame*) = 0;
     82         virtual void writeRange(Range*, Frame*) = 0;
     83         virtual void writePlainText(const String&) = 0;
     84 
     85         virtual bool hasData() = 0;
     86 
     87         void setAccessPolicy(ClipboardAccessPolicy);
     88         ClipboardAccessPolicy policy() const { return m_policy; }
     89 
     90         DragOperation sourceOperation() const;
     91         DragOperation destinationOperation() const;
     92         void setSourceOperation(DragOperation);
     93         void setDestinationOperation(DragOperation);
     94 
     95         void setDragHasStarted() { m_dragStarted = true; }
     96 
     97 #if ENABLE(DATA_TRANSFER_ITEMS)
     98         virtual PassRefPtr<DataTransferItems> items() = 0;
     99 #endif
    100 
    101     protected:
    102         Clipboard(ClipboardAccessPolicy, ClipboardType);
    103 
    104         bool dragStarted() const { return m_dragStarted; }
    105 
    106     private:
    107         ClipboardAccessPolicy m_policy;
    108         String m_dropEffect;
    109         String m_effectAllowed;
    110         bool m_dragStarted;
    111         ClipboardType m_clipboardType;
    112 
    113     protected:
    114         IntPoint m_dragLoc;
    115         CachedResourceHandle<CachedImage> m_dragImage;
    116         RefPtr<Node> m_dragImageElement;
    117     };
    118 
    119 } // namespace WebCore
    120 
    121 #endif // Clipboard_h
    122