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