Fix for screen flickering on page have lots of contents size change
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / PageClientImpl.h
1 /*
2  * Copyright (C) 2011 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 PageClientImpl_h
27 #define PageClientImpl_h
28
29 #include "PageClient.h"
30 #include <Evas.h>
31
32 #if OS(TIZEN)
33 #include "WebEditCommandProxy.h"
34 #include <WebCore/ViewportArguments.h>
35
36 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
37 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
38 #include "DrawingAreaProxyImpl.h"
39 #include <WebCore/Color.h>
40 #endif
41 #endif
42 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
43 #include "TextSelection.h"
44 #endif
45 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
46 #include "OfflinePageSave.h"
47 #endif
48 #if ENABLE(TIZEN_DRAG_SUPPORT)
49 #include "Drag.h"
50 #endif
51 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
52 #include "FormDataCandidate.h"
53 #endif
54 #endif // #if OS(TIZEN)
55
56 class EwkViewImpl;
57
58 namespace WebKit {
59
60 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
61 class MainFrameScrollbarTizen;
62 #endif
63
64 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
65 class TextSelection;
66 #endif
67
68 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
69 class ClipboardHelper;
70 #endif
71
72 #if ENABLE(TIZEN_DRAG_SUPPORT)
73 class Drag;
74 #endif
75
76 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
77 class FormDataCandidate;
78 #endif
79
80 class PageClientImpl : public PageClient {
81 public:
82     static PassOwnPtr<PageClientImpl> create(EwkViewImpl* viewImpl)
83     {
84         return adoptPtr(new PageClientImpl(viewImpl));
85     }
86     virtual ~PageClientImpl();
87
88     EwkViewImpl* viewImpl() const;
89
90 #if OS(TIZEN)
91     struct ViewportConstraints {
92         ViewportConstraints()
93             : initialScale(1.0)
94             , minimumScale(0.25)
95             , maximumScale(5.0)
96             , userScalable(true)
97             , contentsDefinedInitialScale(false)
98             , layoutSize(WebCore::IntSize())
99         {
100         }
101         double initialScale;
102         double minimumScale;
103         double maximumScale;
104         bool userScalable;
105         bool contentsDefinedInitialScale;
106         WebCore::IntSize layoutSize;
107     };
108
109     ViewportConstraints viewportConstraints() { return m_viewportConstraints; }
110     ViewportConstraints computeViewportConstraints(const WebCore::ViewportAttributes&);
111     double adjustScaleWithViewport(double);
112 #if USE(TILED_BACKING_STORE) && ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
113     TIZEN_VIRTUAL void updateViewportSize(const WebCore::IntSize& viewportSize);
114 #endif
115     void initializeVisibleContentRect();
116     double availableMinimumScale();
117     void fitViewportToContent();
118     bool wasViewportFitsToContent() { return m_viewportFitsToContent; }
119
120     void setFocusedNodeRect(const WebCore::IntRect&);
121     WebCore::IntRect focusedNodeRect() { return m_focusedNodeRect; };
122
123 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
124     void textChangeInTextField(const String& name, const String& value);
125 #endif
126
127     void setViewFocused(bool focused) { m_viewFocused = focused; }
128     void setViewWindowActive(bool active) { m_viewWindowActive = active; }
129     void updateFormNavigation(int length, int offset);
130
131 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
132 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
133     DrawingAreaProxy* drawingArea() const;
134 #endif
135     float scaleFactor();
136     const WebCore::IntPoint scrollPosition();
137     WebCore::IntRect adjustVisibleContentRect(WebCore::IntRect, float);
138     void setVisibleContentRect(const WebCore::IntRect&, float newScale, const WebCore::FloatPoint& trajectory = WebCore::FloatPoint());
139     TIZEN_VIRTUAL void displayViewport();
140     TIZEN_VIRTUAL void drawContents();
141 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
142     virtual void drawContents(BackingStore::PlatformGraphicsContext);
143 #endif
144     void scaleImage(double, WebCore::IntPoint);
145     void scaleContents(double, const WebCore::IntPoint&);
146     WebCore::IntRect visibleContentRect() { return m_visibleContentRect; }
147
148 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
149     void updateScrollbar();
150     void frameRectChanged();
151     void updateVisibility();
152 #endif
153
154     // FIXME: The concept of suspending content comes from webkit opensource's PageViewportController,
155     // so below code should be replaced when PageViewportController codes are merged.
156     // Please do not use below codes. They are only for scaling contents.
157     void suspendContent();
158     void resumeContent();
159     WebCore::FloatPoint boundContentsPositionAtScale(const WebCore::FloatPoint&, float scale);
160 #else
161     float scaleFactor() { return page()->pageScaleFactor(); }
162     WebCore::IntPoint scrollPosition() { return page()->scrollPosition(); }
163 #endif // #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
164
165 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
166     bool isTextSelectionDowned();
167     bool isTextSelectionMode();
168     void setIsTextSelectionMode(bool isTextSelectionMode);
169     void updateTextSelectionHandlesAndContextMenu(bool isShow, bool isScrolling = false);
170     bool textSelectionDown(const WebCore::IntPoint& point, bool isStartedTextSelectionFromOutside = false);
171     void textSelectionMove(const WebCore::IntPoint& point, bool isStartedTextSelectionFromOutside = false);
172     void textSelectionUp(const WebCore::IntPoint& point, bool isStartedTextSelectionFromOutside = false);
173     bool isTextSelectionHandleDowned();
174 #if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
175     void textSelectonHandleDown(const WebCore::IntPoint& point);
176     void textSelectonHandleMove(const WebCore::IntPoint& point);
177     void textSelectonHandleUp();
178 #endif
179     void requestToShowTextSelectionHandlesAndContextMenu();
180 #endif
181
182 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
183     void saveSerializedHTMLDataForMainPage(const String& serializedData, const String& fileName);
184     void saveSubresourcesData(Vector<WebSubresourceTizen>& subresourceData);
185     void startOfflinePageSave(String& path, String& url, String& title);
186 #endif
187
188 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
189     void setClipboardData(const String& data, const String& type);
190     void clearClipboardData();
191 #endif
192
193 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
194     void pasteContextMenuSelected();
195 #endif
196
197
198 #if ENABLE(TIZEN_WEBKIT2_VIEW_VISIBILITY)
199     void setIsVisible(bool isVisible);
200 #endif
201
202 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
203     bool scrollBy(WebCore::IntSize);
204     void scrollTo(WebCore::IntPoint);
205 #endif
206
207     void setIsScrollableLayerFocused(const bool b) { m_isScrollableLayerFocused = b; }
208     bool isScrollableLayerFocused() const { return m_isScrollableLayerFocused; }
209
210     void setIsScrollableNodeFocused(const bool b) { m_isScrollableNodeFocused = b; }
211     bool isScrollableNodeFocused() const { return m_isScrollableNodeFocused; }
212
213 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
214     void setOverflowResult(bool pressed, WebLayerID);
215     void findScrollableNode(const WebCore::IntPoint&);
216 #endif
217
218 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
219     bool isContextMenuVisible() { return m_isContextMenuVisible; }
220     void setIsContextMenuVisible(bool isVisible) { m_isContextMenuVisible = isVisible; }
221 #endif
222     TIZEN_VIRTUAL void didRenderFrame();
223 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
224     void setBackgroundColor(double red, double green, double blue, double alpha);
225     TIZEN_VIRTUAL bool makeContextCurrent() { return true; }
226 #endif
227 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
228     void didGetTextStyleStateForSelection(int underlineState, int italicState, int boldState);
229 #endif
230
231     virtual void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&);
232
233 #if ENABLE(TIZEN_ICON_DATABASE)
234     virtual void didReceiveIcon();
235 #endif
236
237 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
238     void clipboardContextMenuSelected();
239     bool isClipboardWindowOpened();
240     void clearClipboardSelectionHandler();
241 #endif
242
243 #if ENABLE(TIZEN_DRAG_SUPPORT)
244     void setDragPoint(const WebCore::IntPoint& point);
245     bool isDragMode();
246     void setDragMode(bool isDragMode);
247 #endif
248
249 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
250     void hideFocusRing();
251 #endif
252
253 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
254     bool isShowingFormDataCandidate();
255     void updateFormDataCandidate(const Vector<String>& data);
256     void hideFormDataCandidate();
257     void showFormDataCandidate(const WebCore::IntRect& rect);
258 #endif
259
260 #endif // #if OS(TIZEN)
261
262 private:
263     // PageClient
264     virtual PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy();
265     virtual void setViewNeedsDisplay(const WebCore::IntRect&);
266     virtual void displayView();
267     virtual void scrollView(const WebCore::IntRect&, const WebCore::IntSize&);
268     virtual bool isViewWindowActive() { return m_viewWindowActive; }
269     virtual bool isViewFocused() { return m_viewFocused; }
270     virtual bool isViewVisible();
271     virtual bool isViewInWindow();
272
273     virtual void processDidCrash();
274     virtual void didRelaunchProcess();
275     virtual void pageClosed();
276
277     virtual void toolTipChanged(const String&, const String&);
278
279     virtual void setCursor(const WebCore::Cursor&);
280     virtual void setCursorHiddenUntilMouseMoves(bool);
281     virtual void didChangeViewportProperties(const WebCore::ViewportAttributes&);
282
283     virtual void registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo);
284     virtual void clearAllEditCommands();
285     virtual bool canUndoRedo(WebPageProxy::UndoOrRedo);
286     virtual void executeUndoRedo(WebPageProxy::UndoOrRedo);
287     virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
288     virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
289     virtual WebCore::IntPoint screenToWindow(const WebCore::IntPoint&);
290     virtual WebCore::IntRect windowToScreen(const WebCore::IntRect&);
291
292     void updateTextInputState();
293     virtual void handleDownloadRequest(DownloadProxy*);
294
295     virtual void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool);
296 #if ENABLE(GESTURE_EVENTS)
297     virtual void doneWithGestureEvent(const WebGestureEvent&, bool wasEventHandled);
298 #endif
299 #if ENABLE(TOUCH_EVENTS)
300     virtual void doneWithTouchEvent(const NativeWebTouchEvent&, bool wasEventHandled);
301 #endif
302
303     virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy*);
304     virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*);
305
306 #if ENABLE(INPUT_TYPE_COLOR)
307     virtual PassRefPtr<WebColorChooserProxy> createColorChooserProxy(WebPageProxy*, const WebCore::Color& initialColor);
308 #endif
309
310     virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool, bool);
311 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
312     TIZEN_VIRTUAL void initializeAcceleratedCompositingMode();
313     TIZEN_VIRTUAL void finalizeAcceleratedCompositingMode() {}
314     virtual void enterAcceleratedCompositingMode(const LayerTreeContext&) {}
315     virtual void exitAcceleratedCompositingMode() {}
316
317     virtual void updateAcceleratedCompositingMode(const LayerTreeContext&);
318 #endif
319
320     virtual void didChangeScrollbarsForMainFrame() const;
321
322 #if OS(TIZEN)
323 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
324     void createScrollbarIfNeeded(bool horizontalBar, bool verticalBar);
325 #endif
326
327     virtual void didFirstVisuallyNonEmptyLayoutForMainFrame();
328     virtual void didChangeContentsSize(const WebCore::IntSize);
329     virtual void pageScaleFactorDidChange();
330 #endif
331
332     virtual void didCommitLoadForMainFrame(bool);
333     virtual void didFinishLoadingDataForCustomRepresentation(const String&, const CoreIPC::DataReference&);
334     virtual double customRepresentationZoomFactor();
335     virtual void setCustomRepresentationZoomFactor(double);
336
337     virtual void flashBackingStoreUpdates(const Vector<WebCore::IntRect>&);
338     virtual void findStringInCustomRepresentation(const String&, FindOptions, unsigned);
339     virtual void countStringMatchesInCustomRepresentation(const String&, FindOptions, unsigned);
340
341 #if USE(TILED_BACKING_STORE)
342     virtual void pageDidRequestScroll(const WebCore::IntPoint&);
343 #endif
344
345 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
346     virtual void pageDidRequestRestoreVisibleContentRect(const WebCore::IntPoint&, float);
347 #endif
348
349 #if ENABLE(TIZEN_DRAG_SUPPORT)
350     virtual void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage);
351 #endif
352
353 #if ENABLE(TIZEN_REGISTER_PROTOCOL_HANDLER)
354     virtual void registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title);
355 #endif
356 #if ENABLE(TIZEN_CUSTOM_SCHEME_HANDLER)
357     virtual unsigned int isProtocolHandlerRegistered(const String& scheme, const String& baseURL, const String& url);
358     virtual void unregisterProtocolHandler(const String& scheme, const String& baseURL, const String& url);
359 #endif
360 #if ENABLE(TIZEN_REGISTER_CONTENT_HANDLER)
361     virtual void registerContentHandler(const String& mimeType, const String& baseURL, const String& url, const String& title);
362     virtual unsigned int isContentHandlerRegistered(const String& mimeType, const String& baseURL, const String& url);
363     virtual void unregisterContentHandler(const String& mimeType, const String& baseURL, const String& url);
364 #endif
365 #if ENABLE(TIZEN_SEARCH_PROVIDER)
366     virtual void addSearchProvider(const String& baseURL, const String& engineURL);
367     virtual unsigned long isSearchProviderInstalled(const String& baseURL, const String& engineURL);
368 #endif
369
370 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
371     virtual bool getStandaloneStatus();
372 #endif
373
374 #if ENABLE(SCREEN_ORIENTATION_SUPPORT) && ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT)
375     virtual bool lockOrientation(int willLockOrientation);
376     virtual void unlockOrientation();
377 #endif
378
379 protected:
380     explicit PageClientImpl(EwkViewImpl*);
381
382     virtual WebCore::IntSize viewSize();
383
384     EwkViewImpl* m_viewImpl;
385
386 #if OS(TIZEN)
387     ViewportConstraints m_viewportConstraints;
388
389     bool m_viewFocused;
390     bool m_viewWindowActive;
391
392     bool m_pageDidRendered;
393
394     // Both angle and wasMinimized are added to handle device rotation
395     int m_viewportAngle;
396     bool m_viewportFitsToContent;
397
398     WebCore::IntRect m_focusedNodeRect;
399
400 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
401     WebCore::IntRect m_visibleContentRect;
402     float m_scaleFactor;
403
404     // FIXME: The concept of suspending content comes from webkit opensource's PageViewportController,
405     // so below code should be replaced when PageViewportController codes are merged.
406     // Please do not use below codes. They are only for scaling contents.
407     bool m_hasSuspendedContent;
408 #endif // ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
409
410 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
411     WebCore::IntPoint m_restoredScrollPosition;
412     float m_restoredScaleFactor;
413 #endif
414
415 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
416     RefPtr<MainFrameScrollbarTizen> m_horizontalScrollbar;
417     RefPtr<MainFrameScrollbarTizen> m_verticalScrollbar;
418 #endif
419 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
420     OwnPtr<TextSelection> m_textSelection;
421 #endif
422 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
423     OwnPtr<OfflinePageSave> m_offlinePageSave;
424 #endif
425 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
426     OwnPtr<ClipboardHelper> m_clipboardHelper;
427 #endif
428 #if ENABLE(TIZEN_DRAG_SUPPORT)
429     OwnPtr<Drag> m_drag;
430 #endif
431 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
432     OwnPtr<FormDataCandidate> m_formDataCandidate;
433 #endif
434     bool m_suspendPainting;
435     bool m_suspendResource;
436     bool m_suspendRequested;
437     bool m_isVisible;
438
439     bool m_isScrollableLayerFocused;
440     bool m_isScrollableNodeFocused;
441
442 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
443     bool m_shouldMakeBackupTexture;
444     bool m_shouldShowBackupTexture;
445     WebCore::IntRect m_initialViewRect;
446 #endif
447
448 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
449     bool m_isContextMenuVisible;
450 #endif
451
452     WebCore::Color m_bgColor;
453
454     Vector<RefPtr<WebKit::WebEditCommandProxy> > m_undoCommands;
455     Vector<RefPtr<WebKit::WebEditCommandProxy> > m_redoCommands;
456 #endif // #if OS(TIZEN)
457 };
458
459
460 #if ENABLE(TIZEN_WEBKIT2_TILED_AC) && ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
461 class PageClientEvasGL : public PageClientImpl {
462 public:
463     static PassOwnPtr<PageClientEvasGL> create(EwkViewImpl* viewImpl)
464     {
465         return adoptPtr(new PageClientEvasGL(viewImpl));
466     }
467     ~PageClientEvasGL();
468
469     virtual void updateViewportSize(const WebCore::IntSize& viewportSize);
470     virtual void setViewNeedsDisplay(const WebCore::IntRect&);
471     virtual void displayViewport();
472     virtual void drawContents();
473     virtual void didRenderFrame();
474     virtual bool makeContextCurrent();
475
476 private:
477     explicit PageClientEvasGL(EwkViewImpl* viewImpl);
478
479     virtual void initializeAcceleratedCompositingMode();
480     virtual void finalizeAcceleratedCompositingMode();
481     virtual void enterAcceleratedCompositingMode(const LayerTreeContext&);
482     virtual void exitAcceleratedCompositingMode();
483
484     void setTargetSurface();
485
486     Evas_GL* m_evasGL;
487     Evas_GL_API* m_evasGlApi;
488     Evas_GL_Context* m_context;
489     Evas_GL_Surface* m_surface;
490     Evas_GL_Config* m_config;
491 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
492     int m_angle;
493 #endif
494
495     bool m_isAcceleratedCompositingModeInitialized;
496 };
497 #endif
498
499 } // namespace WebKit
500
501 #endif // PageClientImpl_h