1/*
2 * Copyright (C) 2007 Apple Inc.  All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef DragData_h
27#define DragData_h
28
29#include "Color.h"
30#include "DragActions.h"
31#include "IntPoint.h"
32
33#include <wtf/Forward.h>
34#include <wtf/HashMap.h>
35#include <wtf/Vector.h>
36
37#if PLATFORM(MAC)
38#include <wtf/RetainPtr.h>
39#include <wtf/text/WTFString.h>
40
41#ifdef __OBJC__
42#import <Foundation/Foundation.h>
43#import <AppKit/NSDragging.h>
44typedef id <NSDraggingInfo> DragDataRef;
45#else
46typedef void* DragDataRef;
47#endif
48
49#elif PLATFORM(QT)
50QT_BEGIN_NAMESPACE
51class QMimeData;
52QT_END_NAMESPACE
53typedef const QMimeData* DragDataRef;
54#elif PLATFORM(WIN)
55typedef struct IDataObject* DragDataRef;
56#include <wtf/text/WTFString.h>
57#elif PLATFORM(GTK)
58namespace WebCore {
59class DataObjectGtk;
60}
61typedef WebCore::DataObjectGtk* DragDataRef;
62#elif PLATFORM(EFL) || PLATFORM(BLACKBERRY)
63typedef void* DragDataRef;
64#endif
65
66
67namespace WebCore {
68
69class Frame;
70class DocumentFragment;
71class KURL;
72class Range;
73
74enum DragApplicationFlags {
75    DragApplicationNone = 0,
76    DragApplicationIsModal = 1,
77    DragApplicationIsSource = 2,
78    DragApplicationHasAttachedSheet = 4,
79    DragApplicationIsCopyKeyDown = 8
80};
81
82#if PLATFORM(WIN)
83typedef HashMap<UINT, Vector<String> > DragDataMap;
84#endif
85
86class DragData {
87public:
88    enum FilenameConversionPolicy { DoNotConvertFilenames, ConvertFilenames };
89
90    // clientPosition is taken to be the position of the drag event within the target window, with (0,0) at the top left
91    DragData(DragDataRef, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation, DragApplicationFlags = DragApplicationNone);
92    DragData(const String& dragStorageName, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation, DragApplicationFlags = DragApplicationNone);
93#if PLATFORM(WIN)
94    DragData(const DragDataMap&, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation sourceOperationMask, DragApplicationFlags = DragApplicationNone);
95    const DragDataMap& dragDataMap();
96    void getDragFileDescriptorData(int& size, String& pathname);
97    void getDragFileContentData(int size, void* dataBlob);
98#endif
99    const IntPoint& clientPosition() const { return m_clientPosition; }
100    const IntPoint& globalPosition() const { return m_globalPosition; }
101    DragApplicationFlags flags() const { return m_applicationFlags; }
102    DragDataRef platformData() const { return m_platformDragData; }
103    DragOperation draggingSourceOperationMask() const { return m_draggingSourceOperationMask; }
104    bool containsURL(Frame*, FilenameConversionPolicy filenamePolicy = ConvertFilenames) const;
105    bool containsPlainText() const;
106    bool containsCompatibleContent() const;
107    String asURL(Frame*, FilenameConversionPolicy filenamePolicy = ConvertFilenames, String* title = 0) const;
108    String asPlainText(Frame*) const;
109    void asFilenames(Vector<String>&) const;
110    Color asColor() const;
111    PassRefPtr<DocumentFragment> asFragment(Frame*, PassRefPtr<Range> context,
112                                            bool allowPlainText, bool& chosePlainText) const;
113    bool canSmartReplace() const;
114    bool containsColor() const;
115    bool containsFiles() const;
116    unsigned numberOfFiles() const;
117    int modifierKeyState() const;
118#if PLATFORM(MAC)
119    const String& pasteboardName() const { return m_pasteboardName; }
120#endif
121
122#if ENABLE(FILE_SYSTEM)
123    String droppedFileSystemId() const;
124#endif
125
126#if PLATFORM(QT) || PLATFORM(GTK)
127    // This constructor should used only by WebKit2 IPC because DragData
128    // is initialized by the decoder and not in the constructor.
129    DragData() { }
130
131    DragData& operator =(const DragData& data)
132    {
133        m_clientPosition = data.m_clientPosition;
134        m_globalPosition = data.m_globalPosition;
135        m_platformDragData = data.m_platformDragData;
136        m_draggingSourceOperationMask = data.m_draggingSourceOperationMask;
137        m_applicationFlags = data.m_applicationFlags;
138        return *this;
139    }
140#endif
141
142private:
143    IntPoint m_clientPosition;
144    IntPoint m_globalPosition;
145    DragDataRef m_platformDragData;
146    DragOperation m_draggingSourceOperationMask;
147    DragApplicationFlags m_applicationFlags;
148#if PLATFORM(MAC)
149    String m_pasteboardName;
150#endif
151#if PLATFORM(WIN)
152    DragDataMap m_dragDataMap;
153#endif
154};
155
156}
157
158#endif // !DragData_h
159