initial import
[vuplus_webkit] / Source / WebCore / dom / Clipboard.h
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 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         
50         static PassRefPtr<Clipboard> create(ClipboardAccessPolicy, DragData*, Frame*);
51
52         virtual ~Clipboard() { }
53
54         bool isForCopyAndPaste() const { return m_clipboardType == CopyAndPaste; }
55         bool isForDragAndDrop() const { return m_clipboardType == DragAndDrop; }
56
57         String dropEffect() const { return dropEffectIsUninitialized() ? "none" : m_dropEffect; }
58         void setDropEffect(const String&);
59         bool dropEffectIsUninitialized() const { return m_dropEffect == "uninitialized"; }
60         String effectAllowed() const { return m_effectAllowed; }
61         void setEffectAllowed(const String&);
62     
63         virtual void clearData(const String& type) = 0;
64         virtual void clearAllData() = 0;
65         virtual String getData(const String& type, bool& success) const = 0;
66         virtual bool setData(const String& type, const String& data) = 0;
67     
68         // extensions beyond IE's API
69         virtual HashSet<String> types() const = 0;
70         virtual PassRefPtr<FileList> files() const = 0;
71
72         LayoutPoint dragLocation() const { return m_dragLoc; }
73         CachedImage* dragImage() const { return m_dragImage.get(); }
74         virtual void setDragImage(CachedImage*, const LayoutPoint&) = 0;
75         Node* dragImageElement() const { return m_dragImageElement.get(); }
76         virtual void setDragImageElement(Node*, const LayoutPoint&) = 0;
77         
78         virtual DragImageRef createDragImage(LayoutPoint& dragLocation) const = 0;
79 #if ENABLE(DRAG_SUPPORT)
80         virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*) = 0;
81 #endif
82         virtual void writeURL(const KURL&, const String&, Frame*) = 0;
83         virtual void writeRange(Range*, Frame*) = 0;
84         virtual void writePlainText(const String&) = 0;
85
86         virtual bool hasData() = 0;
87         
88         void setAccessPolicy(ClipboardAccessPolicy);
89         ClipboardAccessPolicy policy() const { return m_policy; }
90
91         DragOperation sourceOperation() const;
92         DragOperation destinationOperation() const;
93         void setSourceOperation(DragOperation);
94         void setDestinationOperation(DragOperation);
95         
96         bool hasDropZoneType(const String&);
97         
98         void setDragHasStarted() { m_dragStarted = true; }
99
100 #if ENABLE(DATA_TRANSFER_ITEMS)
101         virtual PassRefPtr<DataTransferItems> items() = 0;
102 #endif
103         
104     protected:
105         Clipboard(ClipboardAccessPolicy, ClipboardType);
106
107         bool dragStarted() const { return m_dragStarted; }
108         
109     private:
110         bool hasFileOfType(const String&) const;
111         bool hasStringOfType(const String&) const;
112         
113         ClipboardAccessPolicy m_policy;
114         String m_dropEffect;
115         String m_effectAllowed;
116         bool m_dragStarted;
117         ClipboardType m_clipboardType;
118         
119     protected:
120         LayoutPoint m_dragLoc;
121         CachedResourceHandle<CachedImage> m_dragImage;
122         RefPtr<Node> m_dragImageElement;
123     };
124
125     DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation);
126     String convertDragOperationToDropZoneOperation(DragOperation);
127     
128 } // namespace WebCore
129
130 #endif // Clipboard_h