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 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 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(WIN) 50typedef struct IDataObject* DragDataRef; 51#include <wtf/text/WTFString.h> 52#elif PLATFORM(GTK) 53namespace WebCore { 54class DataObjectGtk; 55} 56typedef WebCore::DataObjectGtk* DragDataRef; 57#elif PLATFORM(EFL) || PLATFORM(IOS) 58typedef void* DragDataRef; 59#endif 60 61namespace WebCore { 62 63class Frame; 64class DocumentFragment; 65class URL; 66class Range; 67 68enum DragApplicationFlags { 69 DragApplicationNone = 0, 70 DragApplicationIsModal = 1, 71 DragApplicationIsSource = 2, 72 DragApplicationHasAttachedSheet = 4, 73 DragApplicationIsCopyKeyDown = 8 74}; 75 76#if PLATFORM(WIN) 77typedef HashMap<unsigned, Vector<String>> DragDataMap; 78#endif 79 80class DragData { 81public: 82 enum FilenameConversionPolicy { DoNotConvertFilenames, ConvertFilenames }; 83 84 // clientPosition is taken to be the position of the drag event within the target window, with (0,0) at the top left 85 DragData(DragDataRef, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation, DragApplicationFlags = DragApplicationNone); 86 DragData(const String& dragStorageName, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation, DragApplicationFlags = DragApplicationNone); 87#if PLATFORM(WIN) 88 DragData(const DragDataMap&, const IntPoint& clientPosition, const IntPoint& globalPosition, DragOperation sourceOperationMask, DragApplicationFlags = DragApplicationNone); 89 const DragDataMap& dragDataMap(); 90 void getDragFileDescriptorData(int& size, String& pathname); 91 void getDragFileContentData(int size, void* dataBlob); 92#endif 93 const IntPoint& clientPosition() const { return m_clientPosition; } 94 const IntPoint& globalPosition() const { return m_globalPosition; } 95 DragApplicationFlags flags() const { return m_applicationFlags; } 96 DragDataRef platformData() const { return m_platformDragData; } 97 DragOperation draggingSourceOperationMask() const { return m_draggingSourceOperationMask; } 98 bool containsURL(Frame*, FilenameConversionPolicy filenamePolicy = ConvertFilenames) const; 99 bool containsPlainText() const; 100 bool containsCompatibleContent() const; 101 String asURL(Frame*, FilenameConversionPolicy filenamePolicy = ConvertFilenames, String* title = 0) const; 102 String asPlainText(Frame*) const; 103 void asFilenames(Vector<String>&) const; 104 Color asColor() const; 105 PassRefPtr<DocumentFragment> asFragment(Frame*, Range& context, bool allowPlainText, bool& chosePlainText) const; 106 bool canSmartReplace() const; 107 bool containsColor() const; 108 bool containsFiles() const; 109 unsigned numberOfFiles() const; 110 int modifierKeyState() const; 111#if PLATFORM(MAC) 112 const String& pasteboardName() const { return m_pasteboardName; } 113#endif 114 115#if PLATFORM(GTK) 116 // This constructor should used only by WebKit2 IPC because DragData 117 // is initialized by the decoder and not in the constructor. 118 DragData() { } 119 120 DragData& operator =(const DragData& data) 121 { 122 m_clientPosition = data.m_clientPosition; 123 m_globalPosition = data.m_globalPosition; 124 m_platformDragData = data.m_platformDragData; 125 m_draggingSourceOperationMask = data.m_draggingSourceOperationMask; 126 m_applicationFlags = data.m_applicationFlags; 127 return *this; 128 } 129#endif 130 131private: 132 IntPoint m_clientPosition; 133 IntPoint m_globalPosition; 134 DragDataRef m_platformDragData; 135 DragOperation m_draggingSourceOperationMask; 136 DragApplicationFlags m_applicationFlags; 137#if PLATFORM(MAC) 138 String m_pasteboardName; 139#endif 140#if PLATFORM(WIN) 141 DragDataMap m_dragDataMap; 142#endif 143}; 144 145} 146 147#endif // !DragData_h 148