1/*
2   Copyright (C) 2011 Samsung Electronics
3   Copyright (C) 2012 Intel Corporation. All rights reserved.
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19*/
20
21#ifndef EwkView_h
22#define EwkView_h
23
24#include "EvasGLContext.h"
25#include "EvasGLSurface.h"
26#include "EwkViewCallbacks.h"
27#include "ImmutableDictionary.h"
28#include "RefPtrEfl.h"
29#include "WKEinaSharedString.h"
30#include "WKRetainPtr.h"
31#include "WebViewEfl.h"
32#include "ewk_url_request_private.h"
33#include <Evas.h>
34#include <WebCore/FloatPoint.h>
35#include <WebCore/IntRect.h>
36#include <WebCore/RefPtrCairo.h>
37#include <WebCore/TextDirection.h>
38#include <WebCore/Timer.h>
39#include <WebKit2/WKBase.h>
40#include <wtf/HashMap.h>
41#include <wtf/OwnPtr.h>
42#include <wtf/RefPtr.h>
43#include <wtf/text/WTFString.h>
44
45#if ENABLE(TOUCH_EVENTS)
46#include "ewk_touch.h"
47#endif
48
49#include "WebContext.h"
50#include "WebPageGroup.h"
51#include "WebPreferences.h"
52
53typedef struct _cairo_surface cairo_surface_t;
54
55namespace WebKit {
56class ContextMenuClientEfl;
57class FindClientEfl;
58class FormClientEfl;
59class InputMethodContextEfl;
60class PageLoadClientEfl;
61class PagePolicyClientEfl;
62class PageUIClientEfl;
63class ViewClientEfl;
64#if USE(ACCELERATED_COMPOSITING)
65class PageViewportController;
66class PageViewportControllerClientEfl;
67#endif
68class WebPageGroup;
69class WebPageProxy;
70
71#if ENABLE(VIBRATION)
72class VibrationClientEfl;
73#endif
74}
75
76namespace WebCore {
77class AffineTransform;
78class Color;
79class CoordinatedGraphicsScene;
80class Cursor;
81class IntSize;
82class TransformationMatrix;
83}
84
85class EwkContext;
86class EwkBackForwardList;
87class EwkColorPicker;
88class EwkContextMenu;
89class EwkPageGroup;
90class EwkPopupMenu;
91class EwkSettings;
92class EwkWindowFeatures;
93
94#if USE(ACCELERATED_COMPOSITING)
95typedef struct _Evas_GL_Context Evas_GL_Context;
96typedef struct _Evas_GL_Surface Evas_GL_Surface;
97#endif
98
99typedef struct Ewk_View_Smart_Data Ewk_View_Smart_Data;
100typedef struct Ewk_View_Smart_Class Ewk_View_Smart_Class;
101
102class EwkView {
103public:
104    static EwkView* create(WKViewRef, Evas* canvas, Evas_Smart* smart = 0);
105
106    static bool initSmartClassInterface(Ewk_View_Smart_Class&);
107
108    static Evas_Object* toEvasObject(WKPageRef);
109
110    Evas_Object* evasObject() { return m_evasObject; }
111
112    WKViewRef wkView() const { return m_webView.get(); }
113    WKPageRef wkPage() const;
114
115    WebKit::WebPageProxy* page() { return webView()->page(); }
116    EwkContext* ewkContext() { return m_context.get(); }
117    EwkPageGroup* ewkPageGroup() { return m_pageGroup.get(); }
118    EwkSettings* settings() { return m_settings.get(); }
119    EwkBackForwardList* backForwardList() { return m_backForwardList.get(); }
120    EwkWindowFeatures* windowFeatures();
121
122#if USE(ACCELERATED_COMPOSITING)
123    WebKit::PageViewportController* pageViewportController() { return m_pageViewportController.get(); }
124#endif
125
126    void setDeviceScaleFactor(float scale);
127    float deviceScaleFactor() const;
128
129    WebCore::AffineTransform transformToScreen() const;
130
131    const char* url() const { return m_url; }
132    Evas_Object* createFavicon() const;
133    const char* title() const;
134    WebKit::InputMethodContextEfl* inputMethodContext();
135
136    const char* themePath() const;
137    void setThemePath(const char* theme);
138    const char* customTextEncodingName() const { return m_customEncoding; }
139    void setCustomTextEncodingName(const char* customEncoding);
140    const char* userAgent() const { return m_userAgent; }
141    void setUserAgent(const char* userAgent);
142
143    bool mouseEventsEnabled() const { return m_mouseEventsEnabled; }
144    void setMouseEventsEnabled(bool enabled);
145#if ENABLE(TOUCH_EVENTS)
146    void feedTouchEvent(Ewk_Touch_Event_Type type, const Eina_List* points, const Evas_Modifier* modifiers);
147    bool touchEventsEnabled() const { return m_touchEventsEnabled; }
148    void setTouchEventsEnabled(bool enabled);
149#endif
150
151    void setCursor(const WebCore::Cursor& cursor);
152
153    void scheduleUpdateDisplay();
154
155#if ENABLE(FULLSCREEN_API)
156    void enterFullScreen();
157    void exitFullScreen();
158#endif
159
160    WKRect windowGeometry() const;
161    void setWindowGeometry(const WKRect&);
162#if USE(ACCELERATED_COMPOSITING)
163    bool createGLSurface();
164    void setNeedsSurfaceResize() { m_pendingSurfaceResize = true; }
165#endif
166
167#if ENABLE(INPUT_TYPE_COLOR)
168    void requestColorPicker(WKColorPickerResultListenerRef listener, const WebCore::Color&);
169    void dismissColorPicker();
170#endif
171
172    WKPageRef createNewPage(PassRefPtr<EwkUrlRequest>, WKDictionaryRef windowFeatures);
173    void close();
174
175    void requestPopupMenu(WKPopupMenuListenerRef, const WKRect&, WKPopupItemTextDirection, double pageScaleFactor, WKArrayRef items, int32_t selectedIndex);
176    void closePopupMenu();
177
178    void customContextMenuItemSelected(WKContextMenuItemRef contextMenuItem);
179    void showContextMenu(WKPoint position, WKArrayRef items);
180    void hideContextMenu();
181
182    void updateTextInputState();
183
184    void requestJSAlertPopup(const WKEinaSharedString& message);
185    bool requestJSConfirmPopup(const WKEinaSharedString& message);
186    WKEinaSharedString requestJSPromptPopup(const WKEinaSharedString& message, const WKEinaSharedString& defaultValue);
187
188    template<EwkViewCallbacks::CallbackType callbackType>
189    EwkViewCallbacks::CallBack<callbackType> smartCallback() const
190    {
191        return EwkViewCallbacks::CallBack<callbackType>(m_evasObject);
192    }
193
194    unsigned long long informDatabaseQuotaReached(const String& databaseName, const String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage);
195
196    // FIXME: Remove when possible.
197    WebKit::WebView* webView();
198
199    // FIXME: needs refactoring (split callback invoke)
200    void informURLChange();
201
202    PassRefPtr<cairo_surface_t> takeSnapshot();
203
204private:
205    EwkView(WKViewRef, Evas_Object*);
206    ~EwkView();
207
208    void setDeviceSize(const WebCore::IntSize&);
209    Ewk_View_Smart_Data* smartData() const;
210
211    WebCore::IntSize size() const;
212    WebCore::IntSize deviceSize() const;
213
214    void displayTimerFired(WebCore::Timer<EwkView>*);
215
216    // Evas_Smart_Class callback interface:
217    static void handleEvasObjectAdd(Evas_Object*);
218    static void handleEvasObjectDelete(Evas_Object*);
219    static void handleEvasObjectMove(Evas_Object*, Evas_Coord x, Evas_Coord y);
220    static void handleEvasObjectResize(Evas_Object*, Evas_Coord width, Evas_Coord height);
221    static void handleEvasObjectShow(Evas_Object*);
222    static void handleEvasObjectHide(Evas_Object*);
223    static void handleEvasObjectColorSet(Evas_Object*, int red, int green, int blue, int alpha);
224    static void handleEvasObjectCalculate(Evas_Object*);
225
226    // Ewk_View_Smart_Class callback interface:
227    static Eina_Bool handleEwkViewFocusIn(Ewk_View_Smart_Data* smartData);
228    static Eina_Bool handleEwkViewFocusOut(Ewk_View_Smart_Data* smartData);
229    static Eina_Bool handleEwkViewMouseWheel(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Wheel* wheelEvent);
230    static Eina_Bool handleEwkViewMouseDown(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Down* downEvent);
231    static Eina_Bool handleEwkViewMouseUp(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Up* upEvent);
232    static Eina_Bool handleEwkViewMouseMove(Ewk_View_Smart_Data* smartData, const Evas_Event_Mouse_Move* moveEvent);
233    static Eina_Bool handleEwkViewKeyDown(Ewk_View_Smart_Data* smartData, const Evas_Event_Key_Down* downEvent);
234    static Eina_Bool handleEwkViewKeyUp(Ewk_View_Smart_Data* smartData, const Evas_Event_Key_Up* upEvent);
235
236#if ENABLE(TOUCH_EVENTS)
237    void feedTouchEvents(Ewk_Touch_Event_Type type);
238    static void handleTouchDown(void* data, Evas*, Evas_Object*, void* eventInfo);
239    static void handleTouchUp(void* data, Evas*, Evas_Object*, void* eventInfo);
240    static void handleTouchMove(void* data, Evas*, Evas_Object*, void* eventInfo);
241#endif
242    static void handleFaviconChanged(const char* pageURL, void* eventInfo);
243
244private:
245    // Note, initialization order matters.
246    WKRetainPtr<WKViewRef> m_webView;
247    Evas_Object* m_evasObject;
248    RefPtr<EwkContext> m_context;
249    RefPtr<EwkPageGroup> m_pageGroup;
250#if USE(ACCELERATED_COMPOSITING)
251    OwnPtr<Evas_GL> m_evasGL;
252    OwnPtr<WebKit::EvasGLContext> m_evasGLContext;
253    OwnPtr<WebKit::EvasGLSurface> m_evasGLSurface;
254    bool m_pendingSurfaceResize;
255#endif
256    WebCore::TransformationMatrix m_userViewportTransform;
257    OwnPtr<WebKit::PageLoadClientEfl> m_pageLoadClient;
258    OwnPtr<WebKit::PagePolicyClientEfl> m_pagePolicyClient;
259    OwnPtr<WebKit::PageUIClientEfl> m_pageUIClient;
260    OwnPtr<WebKit::ContextMenuClientEfl> m_contextMenuClient;
261    OwnPtr<WebKit::FindClientEfl> m_findClient;
262    OwnPtr<WebKit::FormClientEfl> m_formClient;
263    OwnPtr<WebKit::ViewClientEfl> m_viewClient;
264#if ENABLE(VIBRATION)
265    OwnPtr<WebKit::VibrationClientEfl> m_vibrationClient;
266#endif
267    OwnPtr<EwkBackForwardList> m_backForwardList;
268    OwnPtr<EwkSettings> m_settings;
269    RefPtr<EwkWindowFeatures> m_windowFeatures;
270    const void* m_cursorIdentifier; // This is an address, do not free it.
271    WKEinaSharedString m_url;
272    mutable WKEinaSharedString m_title;
273    WKEinaSharedString m_theme;
274    WKEinaSharedString m_customEncoding;
275    WKEinaSharedString m_userAgent;
276    bool m_mouseEventsEnabled;
277#if ENABLE(TOUCH_EVENTS)
278    bool m_touchEventsEnabled;
279#endif
280    WebCore::Timer<EwkView> m_displayTimer;
281    RefPtr<EwkContextMenu> m_contextMenu;
282    OwnPtr<EwkPopupMenu> m_popupMenu;
283    OwnPtr<WebKit::InputMethodContextEfl> m_inputMethodContext;
284#if ENABLE(INPUT_TYPE_COLOR)
285    OwnPtr<EwkColorPicker> m_colorPicker;
286#endif
287#if USE(ACCELERATED_COMPOSITING)
288    OwnPtr<WebKit::PageViewportControllerClientEfl> m_pageViewportControllerClient;
289    OwnPtr<WebKit::PageViewportController> m_pageViewportController;
290#endif
291    bool m_isAccelerated;
292
293    static Evas_Smart_Class parentSmartClass;
294};
295
296EwkView* toEwkView(const Evas_Object*);
297
298bool isEwkViewEvasObject(const Evas_Object*);
299
300#endif // EwkView_h
301