Fixed drag position issue
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / Drag.cpp
1 /*
2  * Copyright (C) 2012 Samsung Electronics
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. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27
28 #if ENABLE(TIZEN_DRAG_SUPPORT)
29 #include "Drag.h"
30
31 #include "EwkViewImpl.h"
32 #include "ewk_view.h"
33 #include <WebCore/DragActions.h>
34 #include <WebCore/DragData.h>
35 #include <WebCore/DragSession.h>
36 #include <wtf/text/CString.h>
37
38 using namespace WebCore;
39
40 namespace WebKit {
41
42 Drag::Drag(EwkViewImpl* viewImpl)
43       : m_viewImpl(viewImpl)
44       , m_isDragMode(false)
45       , m_dragStorageName("Drag")
46       , m_dragData(0)
47 {
48     ASSERT(viewImpl);
49
50     m_Handle = new DragHandle(viewImpl->view(), EDJE_DIR"/Drag.edj", "drag_support", this);
51 }
52
53 Drag::~Drag()
54 {
55     delete m_Handle;
56 }
57
58 WebFrameProxy* Drag::focusedOrMainFrame()
59 {
60     WebFrameProxy* frame = m_viewImpl->page()->focusedFrame();
61     if(!frame)
62         frame = m_viewImpl->page()->mainFrame();
63
64     return frame;
65 }
66
67 void Drag::setDragMode(bool isDragMode)
68 {
69     if (!isDragMode)
70         hide();
71
72     m_isDragMode = isDragMode;
73 }
74
75 void Drag::setDragData(WebCore::DragData* dragdata, PassRefPtr<ShareableBitmap> dragImage)
76 {
77     m_dragData = dragdata;
78     m_dragImage = dragImage;
79 }
80
81 void Drag::hide()
82 {
83     IntPoint viewPoint = m_viewImpl->transformFromScene().mapPoint(m_Handle->position());
84
85     DragData* dragData = new DragData(m_dragData->platformData(), viewPoint,
86         viewPoint, m_dragData->draggingSourceOperationMask(), m_dragData->flags());
87
88     m_viewImpl->page()->dragExited(dragData ,m_dragStorageName);
89     m_Handle->hide();
90     m_viewImpl->page()->dragEnded(viewPoint, viewPoint, m_dragData->draggingSourceOperationMask());
91 }
92
93 void Drag::Show()
94 {
95     m_Handle->show();
96     m_Handle->move(m_savePoint);
97 }
98
99 // handle callbacks
100 void Drag::handleMouseDown(DragHandle* handle)
101 {
102     m_Handle->move(handle->position());
103 }
104
105 void Drag::handleMouseMove(DragHandle* handle)
106 {
107     IntPoint viewPoint = m_viewImpl->transformFromScene().mapPoint(handle->position());
108
109     DragData* dragData = new DragData(m_dragData->platformData(), viewPoint,
110         viewPoint, m_dragData->draggingSourceOperationMask(), m_dragData->flags());
111
112     m_viewImpl->page()->dragUpdated(dragData ,m_dragStorageName);
113
114     DragSession dragSession = m_viewImpl->page()->dragSession();
115     if (dragSession.operation != DragSourceActionNone)
116         handle->updateHandleIcon(true);
117      else
118         handle->updateHandleIcon(false);
119
120     m_Handle->move(handle->position());
121     delete(dragData);
122 }
123
124 void Drag::handleMouseUp(DragHandle* handle)
125 {
126     IntPoint viewPoint = m_viewImpl->transformFromScene().mapPoint(handle->position());
127
128     DragData* dragData = new DragData(m_dragData->platformData(), viewPoint,
129         viewPoint, m_dragData->draggingSourceOperationMask(), m_dragData->flags());
130
131     m_viewImpl->page()->dragUpdated(dragData ,m_dragStorageName);
132
133     DragSession dragSession = m_viewImpl->page()->dragSession();
134     if (dragSession.operation != DragSourceActionNone) {
135         m_viewImpl->page()->performDrag(dragData, m_dragStorageName);
136         setDragMode(false);
137         m_viewImpl->page()->dragEnded(viewPoint, viewPoint, m_dragData->draggingSourceOperationMask());
138     }
139     delete(dragData);
140 }
141 } // namespace WebKit
142
143 #endif // TIZEN_DRAG_SUPPORT