Tizen 2.1 base
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / ClipboardHelper.h
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 #ifndef ClipboardHelper_h
27 #define ClipboardHelper_h
28
29 #include <wtf/Deque.h>
30 #include <wtf/PassOwnPtr.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/text/CString.h>
33 #include <wtf/text/WTFString.h>
34
35 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
36 #include <Ecore.h>
37 #endif
38
39 namespace WebKit {
40
41 class PageClientImpl;
42
43 typedef void (*ClipboardDataResultFunction)(const String&, const String&, void*);
44
45 class ClipboardCallback : public RefCounted<ClipboardCallback> {
46 public:
47
48     static PassRefPtr<ClipboardCallback> create(void* context, ClipboardDataResultFunction callback)
49     {
50         return adoptRef(new ClipboardCallback(context, callback));
51     }
52
53     ~ClipboardCallback()
54     {
55         ASSERT(!m_callback);
56     }
57
58     void performCallback(const String& data, const String& type)
59     {
60         ASSERT(m_callback);
61         m_callback(data, type, m_context);
62         m_callback = 0;
63     }
64
65 private:
66     ClipboardCallback(void* context, ClipboardDataResultFunction callback)
67         : m_context(context)
68         , m_callback(callback)
69     {
70     }
71
72     void* m_context;
73     ClipboardDataResultFunction m_callback;
74
75 };
76
77 class ClipboardHelper {
78 public:
79     static PassOwnPtr<ClipboardHelper> create(Evas_Object* ewkView, PageClientImpl* pageClient)
80     {
81         return adoptPtr(new ClipboardHelper(ewkView, pageClient));
82     }
83     ~ClipboardHelper();
84
85     enum SelectionType {
86         SelectionTypePrimary,
87         SelectionTypeSecondary,
88         SelectionTypeXDND,
89         SelectionTypeClipboard
90     };
91
92     static int numberOfItems();
93
94     void setData(const String& data, const String& type);
95     void requestData(void* context, ClipboardDataResultFunction, SelectionType type = SelectionTypeClipboard);
96
97     void clear();
98
99     void processResult(const String& data, const String& type);
100
101     PageClientImpl* pageClient() { return m_pageClient; }
102
103 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
104     void openClipboardWindow(bool isRichEditable);
105     bool isClipboardWindowOpened();
106     void connectClipboardWindow();
107     void clearClipboardSelectionClearHandler();
108     Evas_Object* ewkView() { return m_ewkView; }
109 #endif
110
111 private:
112     ClipboardHelper(Evas_Object* ewkView, PageClientImpl* pageClient)
113         : m_ewkView(ewkView)
114         , m_pageClient(pageClient)
115 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
116         , m_selectionClearHandler(0)
117 #endif
118     {
119     }
120
121     Evas_Object* m_ewkView;
122     PageClientImpl* m_pageClient;
123
124     Deque<RefPtr<ClipboardCallback> > m_callbackQueue;
125     Mutex m_callbackQueueLock;
126
127 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
128     Ecore_Event_Handler* m_selectionClearHandler;
129 #endif
130
131 };
132
133 } // namespace WebKit
134
135 #endif // ClipboardHelper_h