Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / clipboard / 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 "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     ImageResource* dragImageResource() const { return m_dragImage.get(); }
83     void setDragImageResource(ImageResource*, const IntPoint&);
84     Node* dragImageElement() const { return m_dragImageElement.get(); }
85     void setDragImageElement(Node*, const IntPoint&);
86
87     PassOwnPtr<DragImage> createDragImage(IntPoint& dragLocation, LocalFrame*) const;
88     void declareAndWriteDragImage(Element*, const KURL&, const String& title);
89     void writeURL(const KURL&, const String&);
90     void writeRange(Range*, LocalFrame*);
91     void writePlainText(const String&);
92
93     bool hasData();
94
95     void setAccessPolicy(ClipboardAccessPolicy);
96     bool canReadTypes() const;
97     bool canReadData() const;
98     bool canWriteData() const;
99     // Note that the spec doesn't actually allow drag image modification outside the dragstart
100     // event. This capability is maintained for backwards compatiblity for ports that have
101     // supported this in the past. On many ports, attempting to set a drag image outside the
102     // dragstart operation is a no-op anyway.
103     bool canSetDragImage() const;
104
105     DragOperation sourceOperation() const;
106     DragOperation destinationOperation() const;
107     void setSourceOperation(DragOperation);
108     void setDestinationOperation(DragOperation);
109
110     bool hasDropZoneType(const String&);
111
112     PassRefPtrWillBeRawPtr<DataTransferItemList> items();
113
114     PassRefPtrWillBeRawPtr<DataObject> dataObject() const;
115
116     void trace(Visitor*);
117
118 private:
119     Clipboard(ClipboardType, ClipboardAccessPolicy, PassRefPtrWillBeRawPtr<DataObject>);
120
121     void setDragImage(ImageResource*, Node*, const IntPoint&);
122
123     bool hasFileOfType(const String&) const;
124     bool hasStringOfType(const String&) const;
125
126     // Instead of using this member directly, prefer to use the can*() methods above.
127     ClipboardAccessPolicy m_policy;
128     String m_dropEffect;
129     String m_effectAllowed;
130     ClipboardType m_clipboardType;
131     RefPtrWillBeMember<DataObject> m_dataObject;
132
133     IntPoint m_dragLoc;
134     ResourcePtr<ImageResource> m_dragImage;
135     RefPtr<Node> m_dragImageElement;
136 };
137
138 DragOperation convertDropZoneOperationToDragOperation(const String& dragOperation);
139 String convertDragOperationToDropZoneOperation(DragOperation);
140
141 } // namespace WebCore
142
143 #endif // Clipboard_h