DragData.h revision e7913fbdd6f145fe1644c90c22aa73cb733c9e17
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/Vector.h>
35
36#if PLATFORM(MAC)
37#include <wtf/RetainPtr.h>
38#ifdef __OBJC__
39#import <Foundation/Foundation.h>
40#import <AppKit/NSDragging.h>
41typedef id <NSDraggingInfo> DragDataRef;
42@class NSPasteboard;
43#else
44typedef void* DragDataRef;
45class NSPasteboard;
46#endif
47#elif PLATFORM(QT)
48QT_BEGIN_NAMESPACE
49class QMimeData;
50QT_END_NAMESPACE
51typedef const QMimeData* DragDataRef;
52#elif PLATFORM(WIN)
53typedef struct IDataObject* DragDataRef;
54#elif PLATFORM(WX)
55typedef class wxDataObject* DragDataRef;
56#elif PLATFORM(GTK)
57namespace WebCore {
58class DataObjectGtk;
59}
60typedef WebCore::DataObjectGtk* DragDataRef;
61#elif defined ANDROID
62typedef void* DragDataRef;
63#elif PLATFORM(CHROMIUM)
64#include "DragDataRef.h"
65#elif PLATFORM(HAIKU)
66class BMessage;
67typedef class BMessage* DragDataRef;
68#elif PLATFORM(EFL) || PLATFORM(BREWMP)
69typedef void* DragDataRef;
70#endif
71
72
73namespace WebCore {
74
75class Frame;
76class DocumentFragment;
77class KURL;
78class Range;
79
80enum DragApplicationFlags {
81    DragApplicationNone = 0,
82    DragApplicationIsModal = 1,
83    DragApplicationIsSource = 2,
84    DragApplicationHasAttachedSheet = 4,
85    DragApplicationIsCopyKeyDown = 8
86};
87
88class DragData {
89public:
90    enum FilenameConversionPolicy { DoNotConvertFilenames, ConvertFilenames };
91
92    // clientPosition is taken to be the position of the drag event within the target window, with (0,0) at the top left
93    DragData(DragDataRef, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation, DragApplicationFlags = DragApplicationNone);
94    DragData(const String& dragStorageName, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation, DragApplicationFlags = DragApplicationNone);
95
96    const IntPoint& clientPosition() const { return m_clientPosition; }
97    const IntPoint& globalPosition() const { return m_globalPosition; }
98    DragApplicationFlags flags() { return m_applicationFlags; }
99    DragDataRef platformData() const { return m_platformDragData; }
100    DragOperation draggingSourceOperationMask() const { return m_draggingSourceOperationMask; }
101    bool containsURL(Frame*, FilenameConversionPolicy filenamePolicy = ConvertFilenames) const;
102    bool containsPlainText() const;
103    bool containsCompatibleContent() const;
104    String asURL(Frame*, FilenameConversionPolicy filenamePolicy = ConvertFilenames, String* title = 0) const;
105    String asPlainText(Frame*) const;
106    void asFilenames(Vector<String>&) const;
107    Color asColor() const;
108    PassRefPtr<DocumentFragment> asFragment(Frame*, PassRefPtr<Range> context,
109                                            bool allowPlainText, bool& chosePlainText) const;
110    bool canSmartReplace() const;
111    bool containsColor() const;
112    bool containsFiles() const;
113private:
114    IntPoint m_clientPosition;
115    IntPoint m_globalPosition;
116    DragDataRef m_platformDragData;
117    DragOperation m_draggingSourceOperationMask;
118    DragApplicationFlags m_applicationFlags;
119#if PLATFORM(MAC)
120    RetainPtr<NSPasteboard> m_pasteboard;
121#endif
122};
123
124}
125
126#endif // !DragData_h
127
128