Revert "Revert "Refine focus ring repainting code when web contents was changed.""
[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 #endif // #if OS(TIZEN)
328
329     // FIXME: Make members private for encapsulation.
330     OwnPtr<WebKit::PageClientImpl> pageClient;
331 #if ENABLE(WAIT_UPVERSION)
332 #if USE(TILED_BACKING_STORE)
333     OwnPtr<WebKit::PageViewportControllerClientEfl> pageViewportControllerClient;
334     OwnPtr<WebKit::PageViewportController> pageViewportController;
335 #endif
336 #endif
337     RefPtr<WebKit::WebPageProxy> pageProxy;
338     OwnPtr<WebKit::PageLoadClientEfl> pageLoadClient;
339     OwnPtr<WebKit::PagePolicyClientEfl> pagePolicyClient;
340     OwnPtr<WebKit::PageUIClientEfl> pageUIClient;
341     OwnPtr<WebKit::ResourceLoadClientEfl> resourceLoadClient;
342     OwnPtr<WebKit::FindClientEfl> findClient;
343     OwnPtr<WebKit::FormClientEfl> formClient;
344
345     OwnPtr<Ewk_Back_Forward_List> backForwardList;
346     RefPtr<Ewk_Context> context;
347
348     WebKit::WebPopupMenuProxyEfl* popupMenuProxy;
349     Eina_List* popupMenuItems;
350
351 #if USE(ACCELERATED_COMPOSITING)
352     Evas_GL* evasGl;
353     Evas_GL_Context* evasGlContext;
354     Evas_GL_Surface* evasGlSurface;
355 #endif
356
357 #if OS(TIZEN)
358 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
359     int orientation;
360 #endif
361
362     JSGlobalContextRef javascriptGlobalContext;
363
364     WKEinaSharedString userAgent;
365
366 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
367     WKEinaSharedString webAppIconURL;
368     Eina_List* webAppIconURLs;
369 #endif
370
371     OwnPtr<Ewk_View_Callback_Context> alertContext;
372     OwnPtr<Ewk_View_Callback_Context> confirmContext;
373     OwnPtr<Ewk_View_Callback_Context> promptContext;
374
375 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
376     OwnPtr<Ewk_View_Callback_Context> beforeUnloadConfirmPanelContext;
377 #endif
378
379     OwnPtr<Ewk_View_Callback_Context> openpanelContext;
380     OwnPtr<WebKit::JavaScriptPopup> javascriptPopup;
381     bool isWaitingForJavaScriptPopupReply;
382     OwnPtr<WebKit::OpenPanel> openPanel;
383
384 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
385     OwnPtr<WebKit::InputPicker> inputPicker;
386     WKEinaSharedString inputValue;
387 #endif
388
389     Ewk_Auth_Challenge* authChallenge;
390     Ewk_Policy_Decision* policyDecision;
391     WKOpenPanelResultListenerRef openPanelListener;
392
393 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
394     Ewk_Certificate_Policy_Decision* certificatePolicyDecision;
395 #endif
396
397 #if ENABLE(TIZEN_MEDIA_STREAM)
398     Eina_List* userMediaPermissionRequests;
399 #endif
400
401 #if ENABLE(TIZEN_GEOLOCATION)
402     Ewk_Geolocation* geolocation;
403     Eina_List* geolocationPermissionRequests;
404 #endif
405
406     bool suspendRequested;
407     bool suspendedPainting;
408     bool suspendedResources;
409
410 #if ENABLE(TIZEN_NOTIFICATIONS)
411     Eina_List* notifications;
412     Eina_List* notificationPermissionRequests;
413 #endif
414
415 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
416     Ewk_Popup_Picker* popupPicker;
417 #endif
418
419     bool isVerticalEdge;
420     bool isHorizontalEdge;
421
422 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
423     OwnPtr<FocusRing> focusRing;
424 #endif
425
426 #if ENABLE(TIZEN_GESTURE)
427     OwnPtr<WebKit::GestureRecognizer> gestureRecognizer;
428     OwnPtr<WebKit::GestureClient> gestureClient;
429 #if ENABLE(TOUCH_EVENTS)
430     Evas_Coord_Point touchDownPoint;
431     bool exceedTouchMoveThreshold;
432     bool wasHandledTouchStart;
433     bool wasHandledTouchMove;
434 #endif
435     bool holdHorizontalPanning;
436     bool holdVerticalPanning;
437 #endif // #if ENABLE(TIZEN_GESTURE)
438
439 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
440     bool mainFrameScrollbarVisibility;
441 #endif
442
443 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
444     Ecore_Animator* compositionAnimator;
445 #endif
446
447 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
448     WKEinaSharedString selectedText;
449 #endif
450
451 #if ENABLE(TIZEN_DATALIST_ELEMENT)
452     Eina_List* dataList;
453 #endif
454
455 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
456     struct {
457         Ewk_Orientation_Lock_Cb callback;
458         void* data;
459     } orientationLock;
460 #endif
461
462 #if ENABLE(TIZEN_WEBKIT2_CREATE_VIEW_WITH_CREATED_PAGE_GROUP_WITH_IDENTIFIER)
463     RefPtr<WebKit::WebPageGroup> pageGroup;
464 #endif
465
466 #if ENABLE(TIZEN_APPLICATION_CACHE)
467     OwnPtr<Ewk_View_Callback_Context> applicationCachePermissionContext;
468     Ewk_Security_Origin* applicationCachePermissionOrigin;
469     bool isWaitingForApplicationCachePermission;
470 #endif
471 #if ENABLE(TIZEN_INDEXED_DATABASE)
472     OwnPtr<Ewk_View_Callback_Context> exceededIndexedDatabaseQuotaContext;
473 #endif
474 #if ENABLE(TIZEN_SQL_DATABASE)
475     OwnPtr<Ewk_View_Callback_Context> exceededDatabaseQuotaContext;
476 #endif
477 #if ENABLE(TIZEN_FILE_SYSTEM)
478     OwnPtr<Ewk_View_Callback_Context> exceededLocalFileSystemQuotaContext;
479 #endif
480     Ewk_Security_Origin* exceededQuotaOrigin;
481     bool isWaitingForExceededQuotaPopupReply;
482 #endif // #if OS(TIZEN)
483
484 private:
485     inline Ewk_View_Smart_Data* smartData() const;
486     void displayTimerFired(WebCore::Timer<EwkViewImpl>*);
487
488     static void onMouseDown(void* data, Evas*, Evas_Object*, void* eventInfo);
489     static void onMouseUp(void* data, Evas*, Evas_Object*, void* eventInfo);
490     static void onMouseMove(void* data, Evas*, Evas_Object*, void* eventInfo);
491 #if ENABLE(TOUCH_EVENTS)
492     void feedTouchEvents(Ewk_Touch_Event_Type type);
493     static void onTouchDown(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
494     static void onTouchUp(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
495     static void onTouchMove(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
496 #endif
497
498     Evas_Object* m_view;
499     OwnPtr<Ewk_Settings> m_settings;
500     RefPtr<Evas_Object> m_cursorObject;
501     WKEinaSharedString m_cursorGroup;
502     WKEinaSharedString m_faviconURL;
503     WKEinaSharedString m_url;
504     mutable WKEinaSharedString m_title;
505     WKEinaSharedString m_theme;
506     mutable WKEinaSharedString m_customEncoding;
507     bool m_mouseEventsEnabled;
508 #if ENABLE(TOUCH_EVENTS)
509     bool m_touchEventsEnabled;
510 #endif
511     WKRetainPtr<WKColorPickerResultListenerRef> m_colorPickerResultListener;
512     WebCore::Timer<EwkViewImpl> m_displayTimer;
513     WTF::Vector <WebCore::IntRect> m_dirtyRects;
514     OwnPtr<WebKit::InputMethodContextEfl> m_inputMethodContext;
515
516     typedef HashMap<WKPageRef, const Evas_Object*> PageViewMap;
517     static PageViewMap pageViewMap;
518
519 #if OS(TIZEN)
520 #if USE(TILED_BACKING_STORE)
521     float m_scaleFactor;
522     WebCore::IntPoint m_scrollPosition;
523 #endif
524 #endif
525 };
526
527 #endif // EwkViewImpl_h