Tizen 2.1 base
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / DragHandle.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 "DragHandle.h"
30
31 #include <Edje.h>
32
33 using namespace WebCore;
34
35 namespace WebKit {
36
37 DragHandle::DragHandle(Evas_Object* object, const String& theme, const String& path, Drag* drag)
38     : m_drag(drag)
39     , m_dragJob(0)
40 {
41     m_icon = edje_object_add(evas_object_evas_get(object));
42     if (!m_icon)
43         return;
44
45     if (!edje_object_file_set(m_icon, theme.utf8().data(), path.utf8().data()))
46         return;
47
48     edje_object_signal_emit(m_icon, "dragndrop,drop,out", "dragndrop");
49     evas_object_smart_member_add(m_icon, object);
50
51     evas_object_propagate_events_set(m_icon, false);
52     evas_object_event_callback_add(m_icon, EVAS_CALLBACK_MOUSE_DOWN, mouseDown, this);
53     evas_object_event_callback_add(m_icon, EVAS_CALLBACK_MOUSE_MOVE, mouseMove, this);
54     evas_object_event_callback_add(m_icon, EVAS_CALLBACK_MOUSE_UP, mouseUp, this);
55 }
56
57 DragHandle::~DragHandle()
58 {
59     if (m_dragJob) {
60         ecore_job_del(m_dragJob);
61         m_dragJob = 0;
62     }
63
64     if (m_icon) {
65         evas_object_event_callback_del(m_icon, EVAS_CALLBACK_MOUSE_DOWN, mouseDown);
66         evas_object_event_callback_del(m_icon, EVAS_CALLBACK_MOUSE_MOVE, mouseMove);
67         evas_object_event_callback_del(m_icon, EVAS_CALLBACK_MOUSE_UP, mouseUp);
68         evas_object_del(m_icon);
69     }
70 }
71
72 void DragHandle::move(const IntPoint& point)
73 {
74     if (m_icon)
75         evas_object_move(m_icon, point.x(), point.y());
76 }
77
78 void DragHandle::show()
79 {
80     if (m_icon)
81         evas_object_show(m_icon);
82 }
83
84 void DragHandle::hide()
85 {
86     if (m_icon) {
87         evas_object_hide(m_icon);
88         edje_object_signal_emit(m_icon, "dragndrop,drop,out", "dragndrop");
89     }
90 }
91
92 void DragHandle::updateHandleIcon(bool isDropAble)
93 {
94     if(!m_icon)
95         return;
96
97     if (isDropAble)
98         edje_object_signal_emit(m_icon, "dragndrop,drop,in", "dragndrop");
99     else
100         edje_object_signal_emit(m_icon, "dragndrop,drop,out", "dragndrop");
101 }
102
103 // callbacks
104 void DragHandle::mouseDown(void* data, Evas*, Evas_Object*, void* eventInfo)
105 {
106     Evas_Event_Mouse_Down* event = static_cast<Evas_Event_Mouse_Down*>(eventInfo);
107     DragHandle* handle = static_cast<DragHandle*>(data);
108
109     handle->setMousePosition(IntPoint(event->canvas.x, event->canvas.y));
110 }
111
112 void DragHandle::mouseMove(void* data, Evas*, Evas_Object*, void* eventInfo)
113 {
114     Evas_Event_Mouse_Move* event = static_cast<Evas_Event_Mouse_Move*>(eventInfo);
115     DragHandle* handle = static_cast<DragHandle*>(data);
116
117     handle->setMousePosition(IntPoint(event->cur.canvas.x, event->cur.canvas.y));
118
119     if (!handle->m_dragJob)
120        handle->m_dragJob = ecore_job_add(update, data);
121 }
122
123 void DragHandle::mouseUp(void* data, Evas*, Evas_Object*, void* eventInfo)
124 {
125     DragHandle* handle = static_cast<DragHandle*>(data);
126     handle->m_drag->handleMouseUp(handle);
127 }
128
129 // job
130 void DragHandle::update(void* data)
131 {
132     DragHandle* handle = static_cast<DragHandle*>(data);
133     handle->m_drag->handleMouseMove(handle);
134     handle->m_dragJob = 0;
135 }
136
137 } // namespace WebKit
138
139 #endif // TIZEN_DRAG_SUPPORT