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 #include "config.h"
27 #include "DragClientQt.h"
28
29 #include "ClipboardQt.h"
30 #include "Frame.h"
31 #include "PlatformMouseEvent.h"
32 #include "qwebpage.h"
33
34 #include <QDrag>
35 #include <QMimeData>
36
37
38 namespace WebCore {
39
dragOperationsToDropActions(unsigned op)40 static inline Qt::DropActions dragOperationsToDropActions(unsigned op)
41 {
42 Qt::DropActions result = Qt::IgnoreAction;
43 if (op & DragOperationCopy)
44 result = Qt::CopyAction;
45 if (op & DragOperationMove)
46 result |= Qt::MoveAction;
47 if (op & DragOperationGeneric)
48 result |= Qt::MoveAction;
49 if (op & DragOperationLink)
50 result |= Qt::LinkAction;
51 return result;
52 }
53
dropActionToDragOperation(Qt::DropActions action)54 static inline DragOperation dropActionToDragOperation(Qt::DropActions action)
55 {
56 DragOperation result = DragOperationNone;
57 if (action & Qt::CopyAction)
58 result = DragOperationCopy;
59 if (action & Qt::LinkAction)
60 result = DragOperationLink;
61 if (action & Qt::MoveAction)
62 result = DragOperationMove;
63 return result;
64 }
65
actionMaskForDrag(DragData *)66 DragDestinationAction DragClientQt::actionMaskForDrag(DragData*)
67 {
68 return DragDestinationActionAny;
69 }
70
willPerformDragDestinationAction(DragDestinationAction,DragData *)71 void DragClientQt::willPerformDragDestinationAction(DragDestinationAction, DragData*)
72 {
73 }
74
dragControllerDestroyed()75 void DragClientQt::dragControllerDestroyed()
76 {
77 delete this;
78 }
79
dragSourceActionMaskForPoint(const IntPoint &)80 DragSourceAction DragClientQt::dragSourceActionMaskForPoint(const IntPoint&)
81 {
82 return DragSourceActionAny;
83 }
84
willPerformDragSourceAction(DragSourceAction,const IntPoint &,Clipboard *)85 void DragClientQt::willPerformDragSourceAction(DragSourceAction, const IntPoint&, Clipboard*)
86 {
87 }
88
startDrag(DragImageRef dragImage,const IntPoint &,const IntPoint &,Clipboard * clipboard,Frame * frame,bool)89 void DragClientQt::startDrag(DragImageRef dragImage, const IntPoint&, const IntPoint&, Clipboard* clipboard, Frame* frame, bool)
90 {
91 #ifndef QT_NO_DRAGANDDROP
92 QMimeData* clipboardData = static_cast<ClipboardQt*>(clipboard)->clipboardData();
93 static_cast<ClipboardQt*>(clipboard)->invalidateWritableData();
94 QWidget* view = m_webPage->view();
95 if (view) {
96 QDrag* drag = new QDrag(view);
97 if (dragImage)
98 drag->setPixmap(*dragImage);
99 else if (clipboardData && clipboardData->hasImage())
100 drag->setPixmap(qvariant_cast<QPixmap>(clipboardData->imageData()));
101 DragOperation dragOperationMask = clipboard->sourceOperation();
102 drag->setMimeData(clipboardData);
103 Qt::DropAction actualDropAction = drag->exec(dragOperationsToDropActions(dragOperationMask));
104
105 // Send dragEnd event
106 PlatformMouseEvent me(m_webPage->view()->mapFromGlobal(QCursor::pos()), QCursor::pos(), LeftButton, MouseEventMoved, 0, false, false, false, false, 0);
107 frame->eventHandler()->dragSourceEndedAt(me, dropActionToDragOperation(actualDropAction));
108 }
109 #endif
110 }
111
112
113 } // namespace WebCore
114