Implement Focus UI
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / EwkViewImpl.h
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 EwkViewImpl_h
22 #define EwkViewImpl_h
23
24 #include "RefPtrEfl.h"
25 #include "WKEinaSharedString.h"
26 #include "WKRetainPtr.h"
27 #include <Evas.h>
28 #include <WebCore/TextDirection.h>
29 #include <WebCore/Timer.h>
30 #include <WebKit2/WKBase.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/OwnPtr.h>
33 #include <wtf/RefPtr.h>
34 #include <wtf/text/WTFString.h>
35
36 #if ENABLE(TOUCH_EVENTS)
37 #include "ewk_touch.h"
38 #endif
39
40 #if USE(ACCELERATED_COMPOSITING)
41 #include <Evas_GL.h>
42 #endif
43
44 #if OS(TIZEN)
45 #include "JavaScriptPopup.h"
46 #include "OpenPanel.h"
47 #include "ewk_auth_challenge_private.h"
48 #include <JavaScriptCore/JSRetainPtr.h>
49 #include <WebCore/IntPoint.h>
50
51 #if ENABLE(TIZEN_GESTURE)
52 #include "GestureRecognizer.h"
53 #include "GestureClient.h"
54 #endif
55
56 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
57 #include "InputPicker.h"
58 #endif
59
60 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
61 #include "FocusRing.h"
62 #endif
63
64 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
65 #include "ewk_popup_picker.h"
66 #endif
67 #endif
68
69 #define EWK_VIEW_IMPL_GET(smartData, impl)                                     \
70     EwkViewImpl* impl = smartData->priv
71
72 #define EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, ...)                      \
73     if (!smartData) {                                                          \
74         EINA_LOG_CRIT("smart data is null");                                   \
75         return __VA_ARGS__;                                                    \
76     }                                                                          \
77     EWK_VIEW_IMPL_GET(smartData, impl);                                        \
78     do {                                                                       \
79         if (!impl) {                                                           \
80             EINA_LOG_CRIT("no private data for object %p (%s)",                \
81                 smartData->self, evas_object_type_get(smartData->self));       \
82             return __VA_ARGS__;                                                \
83         }                                                                      \
84     } while (0)
85
86 namespace WebKit {
87 class FindClientEfl;
88 class FormClientEfl;
89 class InputMethodContextEfl;
90 class PageClientImpl;
91 class PageLoadClientEfl;
92 class PagePolicyClientEfl;
93 class PageUIClientEfl;
94 class PageViewportControllerClientEfl;
95 class PageViewportController;
96 class ResourceLoadClientEfl;
97 class WebPageProxy;
98 class WebPopupItem;
99 class WebPopupMenuProxyEfl;
100 }
101
102 namespace WebCore {
103 class Color;
104 class Cursor;
105 class IntRect;
106 class IntSize;
107 }
108
109 class Ewk_Back_Forward_List;
110 class Ewk_Context;
111 class Ewk_Download_Job;
112 class Ewk_Error;
113 class Ewk_Form_Submission_Request;
114 class Ewk_Intent;
115 class Ewk_Intent_Service;
116 class Ewk_Navigation_Policy_Decision;
117 class Ewk_Resource;
118 class Ewk_Settings;
119 class Ewk_Url_Request;
120 class Ewk_Url_Response;
121
122 typedef struct Ewk_View_Smart_Data Ewk_View_Smart_Data;
123
124 #if OS(TIZEN)
125 namespace WebCore {
126 class AffineTransform;
127 }
128
129 // FIXME: we have to include ewk_view.h instead of typedef,
130 // because there are "circular include" in the local code unlike open source,
131 // so we can not do typedef again here.
132 //typedef struct Ewk_View_Smart_Data Ewk_View_Smart_Data;
133 #include "ewk_view.h"
134
135 struct Ewk_View_Callback_Context {
136     union {
137         Ewk_Web_App_Capable_Get_Callback webAppCapableCallback;
138         Ewk_Web_App_Icon_URL_Get_Callback webAppIconURLCallback;
139         Ewk_Web_App_Icon_URLs_Get_Callback webAppIconURLsCallback;
140 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
141         Ewk_Web_Storage_Quota_Get_Callback webStorageQuotaCallback;
142 #endif
143         Ewk_View_Script_Execute_Callback scriptExecuteCallback;
144         Ewk_View_Plain_Text_Get_Callback plainTextGetCallback;
145 #if ENABLE(TIZEN_SUPPORT_MHTML)
146         Ewk_View_MHTML_Data_Get_Callback mhtmlDataGetCallback;
147 #endif
148         Ewk_View_JavaScript_Alert_Callback javascriptAlertCallback;
149         Ewk_View_JavaScript_Confirm_Callback javascriptConfirmCallback;
150         Ewk_View_JavaScript_Prompt_Callback javascriptPromptCallback;
151 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
152         Ewk_View_Before_Unload_Confirm_Panel_Callback beforeUnloadConfirmPanelCallback;
153 #endif
154         Ewk_View_Open_Panel_Callback openPanelCallback;
155 #if ENABLE(TIZEN_APPLICATION_CACHE)
156         Ewk_View_Applicacion_Cache_Permission_Callback applicationCachePermissionCallback;
157 #endif
158 #if ENABLE(TIZEN_INDEXED_DATABASE)
159         Ewk_View_Exceeded_Indexed_Database_Quota_Callback exceededIndexedDatabaseQuotaCallback;
160 #endif
161 #if ENABLE(TIZEN_SQL_DATABASE)
162         Ewk_View_Exceeded_Database_Quota_Callback exceededDatabaseQuotaCallback;
163 #endif
164 #if ENABLE(TIZEN_FILE_SYSTEM)
165         Ewk_View_Exceeded_Local_File_System_Quota_Callback exceededLocalFileSystemQuotaCallback;
166 #endif
167     };
168
169     Evas_Object* ewkView;
170     void* userData;
171 };
172 typedef struct Ewk_View_Callback_Context Ewk_View_Callback_Context;
173 #endif
174
175 class EwkViewImpl {
176 public:
177     explicit EwkViewImpl(Evas_Object* view);
178     ~EwkViewImpl();
179
180     static EwkViewImpl* fromEvasObject(const Evas_Object* view);
181
182     inline Evas_Object* view() { return m_view; }
183     WKPageRef wkPage();
184     inline WebKit::WebPageProxy* page() { return pageProxy.get(); }
185     Ewk_Context* ewkContext() { return context.get(); }
186     Ewk_Settings* settings() { return m_settings.get(); }
187
188     WebCore::IntSize size() const;
189     bool isFocused() const;
190     bool isVisible() const;
191
192     const char* url() const { return m_url; }
193     const char* faviconURL() const { return m_faviconURL; }
194     const char* title() const;
195     WebKit::InputMethodContextEfl* inputMethodContext();
196
197     const char* themePath() const;
198     void setThemePath(const char* theme);
199     const char* customTextEncodingName() const;
200     void setCustomTextEncodingName(const char* encoding);
201
202     bool mouseEventsEnabled() const { return m_mouseEventsEnabled; }
203     void setMouseEventsEnabled(bool enabled);
204 #if ENABLE(TOUCH_EVENTS)
205     bool touchEventsEnabled() const { return m_touchEventsEnabled; }
206     void setTouchEventsEnabled(bool enabled);
207 #endif
208
209     void setCursor(const WebCore::Cursor& cursor);
210     void redrawRegion(const WebCore::IntRect& rect);
211     void setImageData(void* imageData, const WebCore::IntSize& size);
212
213 #if ENABLE(INPUT_TYPE_COLOR)
214     bool setColorPickerColor(const WebCore::Color& color);
215 #endif
216
217     static void addToPageViewMap(const Evas_Object* ewkView);
218     static void removeFromPageViewMap(const Evas_Object* ewkView);
219     static const Evas_Object* viewFromPageViewMap(const WKPageRef);
220
221 #if ENABLE(FULLSCREEN_API)
222     void enterFullScreen();
223     void exitFullScreen();
224 #endif
225
226 #if USE(ACCELERATED_COMPOSITING)
227     bool createGLSurface(const WebCore::IntSize& viewSize);
228     bool enterAcceleratedCompositingMode();
229     bool exitAcceleratedCompositingMode();
230 #endif
231
232 #if ENABLE(INPUT_TYPE_COLOR)
233     void requestColorPicker(int r, int g, int b, int a, WKColorPickerResultListenerRef listener);
234     void dismissColorPicker();
235 #endif
236
237     WKPageRef createNewPage();
238     void closePage();
239
240 #if ENABLE(TIZEN_MULTIPLE_SELECT)
241     void requestPopupMenu(WebKit::WebPopupMenuProxyEfl*, const WebCore::IntRect&, WebCore::TextDirection, double pageScaleFactor, const Vector<WebKit::WebPopupItem>& items, int32_t selectedIndex, bool);
242 #else
243     void requestPopupMenu(WebKit::WebPopupMenuProxyEfl*, const WebCore::IntRect&, WebCore::TextDirection, double pageScaleFactor, const Vector<WebKit::WebPopupItem>& items, int32_t selectedIndex);
244 #endif
245     void updateTextInputState();
246
247     void requestJSAlertPopup(const WKEinaSharedString& message);
248     bool requestJSConfirmPopup(const WKEinaSharedString& message);
249     WKEinaSharedString requestJSPromptPopup(const WKEinaSharedString& message, const WKEinaSharedString& defaultValue);
250
251     void informDownloadJobCancelled(Ewk_Download_Job* download);
252     void informDownloadJobFailed(Ewk_Download_Job* download, Ewk_Error* error);
253     void informDownloadJobFinished(Ewk_Download_Job* download);
254     void informDownloadJobRequested(Ewk_Download_Job* download);
255
256     void informNewFormSubmissionRequest(Ewk_Form_Submission_Request* request);
257     void informLoadError(Ewk_Error* error);
258     void informLoadFinished();
259     void informLoadProgress(double progress);
260     void informProvisionalLoadFailed(Ewk_Error* error);
261 #if USE(TILED_BACKING_STORE)
262     void informLoadCommitted();
263 #endif
264     void informProvisionalLoadRedirect();
265     void informProvisionalLoadStarted();
266
267     void informResourceLoadStarted(Ewk_Resource* resource, Ewk_Url_Request* request);
268     void informResourceLoadResponse(Ewk_Resource* resource, Ewk_Url_Response* response);
269     void informResourceLoadFailed(Ewk_Resource* resource, Ewk_Error* error);
270     void informResourceLoadFinished(Ewk_Resource* resource);
271     void informResourceRequestSent(Ewk_Resource* resource, Ewk_Url_Request* request, Ewk_Url_Response* redirectResponse);
272
273     void informNavigationPolicyDecision(Ewk_Navigation_Policy_Decision* decision);
274     void informNewWindowPolicyDecision(Ewk_Navigation_Policy_Decision* decision);
275     void informBackForwardListChange();
276
277     void informTitleChange(const String& title);
278     void informTooltipTextChange(const String& text);
279     void informTextFound(unsigned matchCount);
280     void informIconChange();
281     void informWebProcessCrashed();
282     void informContentsSizeChange(const WebCore::IntSize& size);
283     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);
284     void informURLChange();
285
286 #if ENABLE(WEB_INTENTS)
287     void informIntentRequest(Ewk_Intent* ewkIntent);
288 #endif
289 #if ENABLE(WEB_INTENTS_TAG)
290     void informIntentServiceRegistration(Ewk_Intent_Service* ewkIntentService);
291 #endif
292
293 #if OS(TIZEN)
294 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
295     WebCore::AffineTransform transformFromView() const;
296     WebCore::AffineTransform transformToView() const;
297 #endif
298     WebCore::AffineTransform transformToScene() const;
299     WebCore::AffineTransform transformFromScene() const;
300     WebCore::AffineTransform transformToScreen() const;
301
302 #if ENABLE(TIZEN_WEBKIT2_SEPERATE_LOAD_PROGRESS)
303     void informLoadProgressStarted();
304     void informLoadProgressFinished();
305 #endif
306
307 #if ENABLE(TIZEN_DATALIST_ELEMENT)
308     void deleteDataList();
309 #endif
310
311 #if USE(TILED_BACKING_STORE)
312     void setScaleFactor(float scaleFactor) { m_scaleFactor = scaleFactor; }
313     float scaleFactor() const { return m_scaleFactor; }
314
315     void setScrollPosition(WebCore::IntPoint position) { m_scrollPosition = position; }
316     const WebCore::IntPoint scrollPosition() const { return m_scrollPosition; }
317 #endif
318
319 #if ENABLE(TIZEN_GESTURE)
320 #if ENABLE(TOUCH_EVENTS)
321     void feedTouchEventsByType(Ewk_Touch_Event_Type);
322 #endif
323     void setDoubleTapEnabled(bool);
324 #endif
325
326     void didChangeScrollAndScale(const WebCore::IntPoint&, float);
327
328 #if ENABLE(TIZEN_FOCUS_UI)
329     static void pages(Vector<RefPtr<WebKit::WebPageProxy> >&);
330 #endif
331 #endif // #if OS(TIZEN)
332
333     // FIXME: Make members private for encapsulation.
334     OwnPtr<WebKit::PageClientImpl> pageClient;
335 #if ENABLE(WAIT_UPVERSION)
336 #if USE(TILED_BACKING_STORE)
337     OwnPtr<WebKit::PageViewportControllerClientEfl> pageViewportControllerClient;
338     OwnPtr<WebKit::PageViewportController> pageViewportController;
339 #endif
340 #endif
341     RefPtr<WebKit::WebPageProxy> pageProxy;
342     OwnPtr<WebKit::PageLoadClientEfl> pageLoadClient;
343     OwnPtr<WebKit::PagePolicyClientEfl> pagePolicyClient;
344     OwnPtr<WebKit::PageUIClientEfl> pageUIClient;
345     OwnPtr<WebKit::ResourceLoadClientEfl> resourceLoadClient;
346     OwnPtr<WebKit::FindClientEfl> findClient;
347     OwnPtr<WebKit::FormClientEfl> formClient;
348
349     OwnPtr<Ewk_Back_Forward_List> backForwardList;
350     RefPtr<Ewk_Context> context;
351
352     WebKit::WebPopupMenuProxyEfl* popupMenuProxy;
353     Eina_List* popupMenuItems;
354
355 #if USE(ACCELERATED_COMPOSITING)
356     Evas_GL* evasGl;
357     Evas_GL_Context* evasGlContext;
358     Evas_GL_Surface* evasGlSurface;
359 #endif
360
361 #if OS(TIZEN)
362 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
363     int orientation;
364 #endif
365
366     JSGlobalContextRef javascriptGlobalContext;
367
368     WKEinaSharedString userAgent;
369
370 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
371     WKEinaSharedString webAppIconURL;
372     Eina_List* webAppIconURLs;
373 #endif
374
375     OwnPtr<Ewk_View_Callback_Context> alertContext;
376     OwnPtr<Ewk_View_Callback_Context> confirmContext;
377     OwnPtr<Ewk_View_Callback_Context> promptContext;
378
379 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
380     OwnPtr<Ewk_View_Callback_Context> beforeUnloadConfirmPanelContext;
381 #endif
382
383     OwnPtr<Ewk_View_Callback_Context> openpanelContext;
384     OwnPtr<WebKit::JavaScriptPopup> javascriptPopup;
385     bool isWaitingForJavaScriptPopupReply;
386     OwnPtr<WebKit::OpenPanel> openPanel;
387
388 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
389     OwnPtr<WebKit::InputPicker> inputPicker;
390     WKEinaSharedString inputValue;
391 #endif
392
393     Ewk_Auth_Challenge* authChallenge;
394     Ewk_Policy_Decision* policyDecision;
395     WKOpenPanelResultListenerRef openPanelListener;
396
397 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
398     Ewk_Certificate_Policy_Decision* certificatePolicyDecision;
399 #endif
400
401 #if ENABLE(TIZEN_MEDIA_STREAM)
402     Eina_List* userMediaPermissionRequests;
403 #endif
404
405 #if ENABLE(TIZEN_GEOLOCATION)
406     Ewk_Geolocation* geolocation;
407     Eina_List* geolocationPermissionRequests;
408 #endif
409
410     bool suspendRequested;
411     bool suspendedPainting;
412     bool suspendedResources;
413
414 #if ENABLE(TIZEN_NOTIFICATIONS)
415     Eina_List* notifications;
416     Eina_List* notificationPermissionRequests;
417 #endif
418
419 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
420     Ewk_Popup_Picker* popupPicker;
421 #endif
422
423     bool isVerticalEdge;
424     bool isHorizontalEdge;
425
426 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
427     OwnPtr<FocusRing> focusRing;
428 #endif
429
430 #if ENABLE(TIZEN_GESTURE)
431     OwnPtr<WebKit::GestureRecognizer> gestureRecognizer;
432     OwnPtr<WebKit::GestureClient> gestureClient;
433 #if ENABLE(TOUCH_EVENTS)
434     Evas_Coord_Point touchDownPoint;
435     bool exceedTouchMoveThreshold;
436     bool wasHandledTouchStart;
437     bool wasHandledTouchMove;
438 #endif
439     bool holdHorizontalPanning;
440     bool holdVerticalPanning;
441 #endif // #if ENABLE(TIZEN_GESTURE)
442
443 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
444     bool mainFrameScrollbarVisibility;
445 #endif
446
447 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
448     Ecore_Animator* compositionAnimator;
449 #endif
450
451 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
452     WKEinaSharedString selectedText;
453 #endif
454
455 #if ENABLE(TIZEN_DATALIST_ELEMENT)
456     Eina_List* dataList;
457 #endif
458
459 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
460     struct {
461         Ewk_Orientation_Lock_Cb callback;
462         void* data;
463     } orientationLock;
464 #endif
465
466 #if ENABLE(TIZEN_WEBKIT2_CREATE_VIEW_WITH_CREATED_PAGE_GROUP_WITH_IDENTIFIER)
467     RefPtr<WebKit::WebPageGroup> pageGroup;
468 #endif
469
470 #if ENABLE(TIZEN_APPLICATION_CACHE)
471     OwnPtr<Ewk_View_Callback_Context> applicationCachePermissionContext;
472     Ewk_Security_Origin* applicationCachePermissionOrigin;
473     bool isWaitingForApplicationCachePermission;
474 #endif
475 #if ENABLE(TIZEN_INDEXED_DATABASE)
476     OwnPtr<Ewk_View_Callback_Context> exceededIndexedDatabaseQuotaContext;
477 #endif
478 #if ENABLE(TIZEN_SQL_DATABASE)
479     OwnPtr<Ewk_View_Callback_Context> exceededDatabaseQuotaContext;
480 #endif
481 #if ENABLE(TIZEN_FILE_SYSTEM)
482     OwnPtr<Ewk_View_Callback_Context> exceededLocalFileSystemQuotaContext;
483 #endif
484     Ewk_Security_Origin* exceededQuotaOrigin;
485     bool isWaitingForExceededQuotaPopupReply;
486 #endif // #if OS(TIZEN)
487
488 private:
489     inline Ewk_View_Smart_Data* smartData() const;
490     void displayTimerFired(WebCore::Timer<EwkViewImpl>*);
491
492     static void onMouseDown(void* data, Evas*, Evas_Object*, void* eventInfo);
493     static void onMouseUp(void* data, Evas*, Evas_Object*, void* eventInfo);
494     static void onMouseMove(void* data, Evas*, Evas_Object*, void* eventInfo);
495 #if ENABLE(TOUCH_EVENTS)
496     void feedTouchEvents(Ewk_Touch_Event_Type type);
497     static void onTouchDown(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
498     static void onTouchUp(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
499     static void onTouchMove(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
500 #endif
501
502     Evas_Object* m_view;
503     OwnPtr<Ewk_Settings> m_settings;
504     RefPtr<Evas_Object> m_cursorObject;
505     WKEinaSharedString m_cursorGroup;
506     WKEinaSharedString m_faviconURL;
507     WKEinaSharedString m_url;
508     mutable WKEinaSharedString m_title;
509     WKEinaSharedString m_theme;
510     mutable WKEinaSharedString m_customEncoding;
511     bool m_mouseEventsEnabled;
512 #if ENABLE(TOUCH_EVENTS)
513     bool m_touchEventsEnabled;
514 #endif
515     WKRetainPtr<WKColorPickerResultListenerRef> m_colorPickerResultListener;
516     WebCore::Timer<EwkViewImpl> m_displayTimer;
517     WTF::Vector <WebCore::IntRect> m_dirtyRects;
518     OwnPtr<WebKit::InputMethodContextEfl> m_inputMethodContext;
519
520     typedef HashMap<WKPageRef, const Evas_Object*> PageViewMap;
521     static PageViewMap pageViewMap;
522
523 #if OS(TIZEN)
524 #if USE(TILED_BACKING_STORE)
525     float m_scaleFactor;
526     WebCore::IntPoint m_scrollPosition;
527 #endif
528 #endif
529 };
530
531 #endif // EwkViewImpl_h