e10ae5084a865cce2501b87760127a9152ee26e7
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / PageClientImpl.cpp
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 #include "config.h"
27 #include "PageClientImpl.h"
28
29 #include "EwkViewImpl.h"
30 #include "InputMethodContextEfl.h"
31 #include "NativeWebKeyboardEvent.h"
32 #include "NotImplemented.h"
33 #include "TransformationMatrix.h"
34 #include "WebContext.h"
35 #include "WebContextMenuProxy.h"
36 #include "WebPageProxy.h"
37 #include "WebPopupMenuProxyEfl.h"
38 #include "ewk_context.h"
39 #include "ewk_context_private.h"
40 #include "ewk_download_job.h"
41 #include "ewk_download_job_private.h"
42 #include "ewk_view.h"
43
44 #if OS(TIZEN)
45 #include "DrawingAreaProxyImpl.h"
46 #include "Editor.h"
47 #include "EflScreenUtilities.h"
48 #include "LayerTreeCoordinatorProxy.h"
49 #include "OpenGLShims.h"
50 #include "WebContextMenuProxyTizen.h"
51 #include "WebLayerTreeRenderer.h"
52 #include "WebPageGroup.h"
53 #include "WebPageMessages.h"
54 #include "WebPopupMenuProxyEfl.h"
55 #include "WebPreferences.h"
56 #include "ewk_view.h"
57 #include <Ecore_Evas.h>
58 #include <Ecore_X.h>
59
60 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
61 #include "MainFrameScrollbarTizen.h"
62 #endif
63
64 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
65 #include "ClipboardHelper.h"
66 #endif
67
68 #if ENABLE(TIZEN_DRAG_SUPPORT)
69 #include "DragData.h"
70 #endif
71 #endif
72
73 #if ENABLE(TIZEN_CACHE_MEMORY_OPTIMIZATION)
74 #include "ewk_context_private.h"
75 #endif
76
77 #if ENABLE(TIZEN_SCREEN_READER)
78 #include "ScreenReaderProxy.h"
79 #endif
80
81 using namespace WebCore;
82 using namespace std;
83
84 namespace WebKit {
85
86 PageClientImpl::PageClientImpl(EwkViewImpl* viewImpl)
87     : m_viewImpl(viewImpl)
88 #if OS(TIZEN)
89     , m_viewportConstraints()
90     , m_viewFocused(false)
91     , m_viewWindowActive(true)
92     , m_pageDidRendered(true)
93     , m_viewportAngle(0)
94     , m_viewportFitsToContent(false)
95 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
96     , m_visibleContentRect(IntRect())
97     , m_scaleFactor(0)
98     , m_hasSuspendedContent(false)
99 #endif
100 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
101     , m_restoredScaleFactor(0)
102 #endif
103 #if ENABLE(TIZEN_WEBKIT2_BEFORE_PAGE_RENDERED_SCROLL_POSITION)
104     , m_scrollPositionBeforePageRendered(IntPoint())
105 #endif
106     , m_isVisible(true)
107     , m_isScrollableLayerFocused(false)
108     , m_isScrollableNodeFocused(false)
109 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
110     , m_shouldMakeBackupTexture(false)
111     , m_shouldShowBackupTexture(false)
112 #endif
113 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
114     , m_isContextMenuVisible(false)
115 #endif
116 #if ENABLE(TIZEN_PRERENDERING_FOR_ROTATION)
117     , m_waitFrameOfNewViewortSize(false)
118 #endif
119     , m_nonemptyLayoutRendered(false)
120 #endif // #if OS(TIZEN)
121 {
122 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING)
123     setenv("CAIRO_GL_COMPOSITOR", "msaa", 1);
124     setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
125 #endif
126
127 #if OS(TIZEN)
128 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
129     m_textSelection = TextSelection::create(m_viewImpl);
130 #endif
131 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
132     m_offlinePageSave = OfflinePageSave::create(m_viewImpl);
133 #endif
134 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
135     m_clipboardHelper = ClipboardHelper::create(m_viewImpl);
136 #endif
137 #if ENABLE(TIZEN_DRAG_SUPPORT)
138     m_drag = Drag::create(m_viewImpl);
139 #endif
140 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
141     m_formDataCandidate = FormDataCandidate::create(m_viewImpl);
142 #endif
143     Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
144     m_viewportAngle = ecore_evas_rotation_get(ee);
145 #endif
146
147     setBackgroundColor(1, 1, 1, 1);
148 }
149
150 PageClientImpl::~PageClientImpl()
151 {
152     if (m_viewImpl && m_viewImpl->page())
153         m_viewImpl->page()->close();
154 }
155
156 #if OS(TIZEN)
157 PageClientImpl::ViewportConstraints PageClientImpl::computeViewportConstraints(const WebCore::ViewportAttributes& attributes)
158 {
159     PageClientImpl::ViewportConstraints constraints;
160     constraints.minimumScale = attributes.minimumScale * attributes.devicePixelRatio;
161     constraints.maximumScale = attributes.maximumScale * attributes.devicePixelRatio;
162     constraints.userScalable = attributes.userScalable;
163     constraints.layoutSize = attributes.layoutSize;
164     constraints.contentsDefinedInitialScale = (ViewportArguments::ValueAuto != attributes.initialScale);
165
166     bool autoFittingEnabled = m_viewImpl->page()->pageGroup()->preferences()->autoFittingEnabled();
167     if (autoFittingEnabled)
168         constraints.initialScale = attributes.minimumScale * attributes.devicePixelRatio;
169     else {
170         // if content doesn't set initial scale value, set readable scale factor
171         // if not, set initial scale factor of viewport attribute
172         if (attributes.initialScale == ViewportArguments::ValueAuto)
173             constraints.initialScale = m_viewImpl->page()->deviceScaleFactor();
174         else
175             constraints.initialScale = attributes.initialScale * attributes.devicePixelRatio;
176     }
177
178     // adjust scale with both minimum and maximum scale factor
179     constraints.initialScale = adjustScaleWithViewport(constraints.initialScale);
180
181     return constraints;
182 }
183
184 double PageClientImpl::adjustScaleWithViewport(double scale)
185 {
186     double minimumScale = min(m_viewportConstraints.minimumScale, m_viewportConstraints.maximumScale);
187     return clampTo(scale, minimumScale, m_viewportConstraints.maximumScale);
188 }
189
190 #if USE(TILED_BACKING_STORE) && ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
191 void PageClientImpl::updateViewportSize(const IntSize& viewportSize, const int angle)
192 {
193 #if ENABLE(TIZEN_DLOG_SUPPORT)
194     TIZEN_LOGI(" view size: [%d, %d], angle: [%d]", viewportSize.width(), viewportSize.height(), angle);
195 #endif
196
197     // update viewport size of webkit
198     m_viewImpl->page()->setViewportSize(viewportSize);
199 }
200
201 void PageClientImpl::updateVisibleContentRectSize(const IntSize& size)
202 {
203     // update visible content rect's size
204     m_visibleContentRect.setSize(size);
205 }
206 #endif
207
208 void PageClientImpl::prepareRestoredVisibleContectRect()
209 {
210     m_restoredScaleFactor = scaleFactor();
211     m_restoredScrollPosition = scrollPosition();
212 #if ENABLE(TIZEN_DLOG_SUPPORT)
213     TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", m_restoredScrollPosition.x(), m_restoredScrollPosition.y(), m_restoredScaleFactor);
214 #endif
215 }
216
217 void PageClientImpl::initializeVisibleContentRect()
218 {
219     _ewk_view_resume_painting(m_viewImpl->view());
220
221 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
222     IntPoint initialScrollPosition;
223     float initialScaleFactor = m_viewportConstraints.initialScale;
224 #if ENABLE(TIZEN_WEBKIT2_BEFORE_PAGE_RENDERED_SCROLL_POSITION)
225     initialScrollPosition = m_scrollPositionBeforePageRendered;
226     m_scrollPositionBeforePageRendered = IntPoint();
227 #endif
228 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
229     // if scroll position and scale factor are restored by history controller,
230     // move scroll position and scale factor with them
231     if (m_restoredScaleFactor) {
232         initialScrollPosition = m_restoredScrollPosition;
233         initialScaleFactor = m_restoredScaleFactor;
234     }
235 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
236     m_restoredScaleFactor = 0;
237 #endif
238 #if ENABLE(TIZEN_DLOG_SUPPORT)
239     TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", initialScrollPosition.x(), initialScrollPosition.y(), initialScaleFactor);
240 #endif
241 #endif
242     setVisibleContentRect(IntRect(initialScrollPosition, m_visibleContentRect.size()), initialScaleFactor);
243 #else
244     // Set initial scale.
245     m_viewImpl->page()->scalePage(m_viewportConstraints.initialScale, IntPoint(0, 0));
246 #endif
247 }
248
249 double PageClientImpl::availableMinimumScale()
250 {
251     // recalculate minimum scale factor if contents' width exceeds viewport layout width and userScalable is true.
252     // minimum scale factor shouldn't be smaller than 0.25(minimum zoom level)
253     IntSize contentsSize = m_viewImpl->page()->contentsSize();
254     double horizontalMinScale = max(((double)viewSize().width() / contentsSize.width()), 0.25);
255     double verticalMinScale = max(((double)viewSize().height() / contentsSize.height()), 0.25);
256     // If there's only a bit ignorable difference between horizontalMinScale and verticalMinScale,
257     // ignore verticalMinScale to fit content's width to view
258     const double ignorableThreshold = 0.01;
259     if (fabs(horizontalMinScale - verticalMinScale) < ignorableThreshold)
260         verticalMinScale = horizontalMinScale;
261     return min(max(horizontalMinScale, verticalMinScale), m_viewportConstraints.maximumScale);
262 }
263
264 void PageClientImpl::fitViewportToContent()
265 {
266 #if ENABLE(TIZEN_DLOG_SUPPORT)
267     TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", m_visibleContentRect.x(), m_visibleContentRect.y(), m_viewportConstraints.minimumScale);
268 #endif
269     setVisibleContentRect(m_visibleContentRect, m_viewportConstraints.minimumScale);
270 }
271
272 void PageClientImpl::setFocusedNodeRect(const IntRect& focusedNodeRect)
273 {
274     m_focusedNodeRect = focusedNodeRect;
275 }
276
277 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
278 bool PageClientImpl::scrollBy(IntSize scrollOffset)
279 {
280 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
281     // scrollOffset means device screen coordiate, not an actual offset of contents.
282     // Therefore, scrollOffset should be nomalized in order to make a tiled backing store
283     // in the actual scale.
284     IntSize scaledScrollOffset = m_viewImpl->transformFromScene().mapSize(scrollOffset);
285     if ((m_isScrollableLayerFocused || m_isScrollableNodeFocused)
286         && m_viewImpl->page()->scrollOverflow(FloatPoint(scaledScrollOffset.width(), scaledScrollOffset.height()))) {
287         displayViewport();
288         return false;
289     }
290 #endif
291
292     IntPoint oldScrollPosition = scrollPosition();
293     setVisibleContentRect(IntRect(oldScrollPosition + scrollOffset, m_visibleContentRect.size()), scaleFactor(), FloatPoint(scrollOffset.width(), scrollOffset.height()));
294
295     return true;
296 }
297
298 void PageClientImpl::scrollTo(IntPoint requestedScrollPosition)
299 {
300     setVisibleContentRect(IntRect(requestedScrollPosition, m_visibleContentRect.size()), scaleFactor());
301 }
302 #endif // #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
303
304 #endif // #if OS(TIZEN)
305
306 EwkViewImpl* PageClientImpl::viewImpl() const
307 {
308     return m_viewImpl;
309 }
310
311 // PageClient
312 PassOwnPtr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy()
313 {
314     return DrawingAreaProxyImpl::create(m_viewImpl->page());
315 }
316
317 void PageClientImpl::setViewNeedsDisplay(const WebCore::IntRect& rect)
318 {
319 #if OS(TIZEN)
320     ewk_view_mark_for_sync(m_viewImpl->view());
321 #else
322     m_viewImpl->redrawRegion(rect);
323 #endif
324
325 #if ENABLE(TIZEN_SCREEN_READER)
326     if (rect.intersects(ewkViewGetFocusRing(m_viewImpl->view())->rect()))
327         m_viewImpl->page()->recalcScreenReaderFocusRect();
328 #endif
329 }
330
331 void PageClientImpl::displayView()
332 {
333     notImplemented();
334 }
335
336 void PageClientImpl::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize&)
337 {
338     setViewNeedsDisplay(scrollRect);
339 }
340
341 WebCore::IntSize PageClientImpl::viewSize()
342 {
343     return m_viewImpl->size();
344 }
345
346 bool PageClientImpl::isViewVisible()
347 {
348 #if OS(TIZEN)
349     return m_isVisible;
350 #else
351     return m_viewImpl->isVisible();
352 #endif
353 }
354
355 bool PageClientImpl::isViewInWindow()
356 {
357     notImplemented();
358     return true;
359 }
360
361 void PageClientImpl::processDidCrash()
362 {
363     // Check if loading was ongoing, when web process crashed.
364     double loadProgress = ewk_view_load_progress_get(m_viewImpl->view());
365     if (loadProgress >= 0 && loadProgress < 1)
366         m_viewImpl->informLoadProgress(1);
367
368     m_viewImpl->informWebProcessCrashed();
369 }
370
371 void PageClientImpl::didRelaunchProcess()
372 {
373     const char* themePath = m_viewImpl->themePath();
374     if (themePath)
375         m_viewImpl->page()->setThemePath(themePath);
376 }
377
378 void PageClientImpl::pageClosed()
379 {
380     notImplemented();
381 }
382
383 void PageClientImpl::toolTipChanged(const String&, const String& newToolTip)
384 {
385     m_viewImpl->informTooltipTextChange(newToolTip);
386 }
387
388 void PageClientImpl::setCursor(const Cursor& cursor)
389 {
390     m_viewImpl->setCursor(cursor);
391 }
392
393 void PageClientImpl::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
394 {
395     notImplemented();
396 }
397
398 void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttributes& attributes)
399 {
400     double scaleRatioBeforeRotation = m_scaleFactor / m_viewportConstraints.minimumScale;
401     m_viewportConstraints = computeViewportConstraints(attributes);
402
403 #if ENABLE(TIZEN_GESTURE)
404     m_viewImpl->setDoubleTapEnabled(userScalable());
405 #endif
406
407     // Initially, m_scaleFactor is not decided yet.
408     // So, we should update visible content rect at here.
409     if (!m_scaleFactor) {
410         setVisibleContentRect(m_visibleContentRect, m_viewportConstraints.initialScale);
411         return;
412     }
413
414     // if content is reloaded, contents size will not be changed
415     // so, we need to calculate minimum scale here.
416     // if content size is changed later, minimum scale will be re-calculated on didChangeContentsSize()
417     if (m_viewportConstraints.userScalable) {
418         if (fabs(m_viewportConstraints.initialScale - m_viewportConstraints.minimumScale) < numeric_limits<float>::epsilon())
419             m_viewportConstraints.initialScale = availableMinimumScale();
420         m_viewportConstraints.minimumScale = availableMinimumScale();
421     }
422
423 #if ENABLE(TIZEN_DLOG_SUPPORT)
424     TIZEN_LOGI("layout size: [%d, %d], scale: [%.2f, %.2f, %.2f], user scalable: [%s]",
425         m_viewportConstraints.layoutSize.width(), m_viewportConstraints.layoutSize.height(),
426         m_viewportConstraints.initialScale, m_viewportConstraints.minimumScale, m_viewportConstraints.maximumScale,
427         m_viewportConstraints.userScalable ? "TRUE" : "FALSE");
428 #endif
429
430     // setVisibleContentRect() should be called to adjust visible content rect only when view is resized
431     if (!m_pageDidRendered || m_viewImpl->page()->estimatedProgress() <= 0.1)
432         return;
433
434     // if IME is opened, visible content rect will be updated by ewk_view_focused_node_adjust()
435     if (ewk_view_focused_node_adjust(m_viewImpl->view()))
436         return;
437
438     float newScale = scaleFactor();
439     IntPoint newScrollPosition = m_visibleContentRect.location();
440     Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
441     int angle = ecore_evas_rotation_get(ee);
442     bool isRotated = (angle != m_viewportAngle);
443
444     // if it's rotated, we need to fit content to viewport by minimize the scale
445     if (isRotated) {
446         m_viewportAngle = angle;
447         newScale = m_viewportConstraints.minimumScale * scaleRatioBeforeRotation;
448         newScrollPosition.scale(newScale / m_scaleFactor, newScale / m_scaleFactor);
449     }
450
451 #if ENABLE(TIZEN_PRERENDERING_FOR_ROTATION)
452     if (m_waitFrameOfNewViewortSize)
453         ewk_view_resume(m_viewImpl->view());
454 #endif
455 #if ENABLE(TIZEN_DLOG_SUPPORT)
456     TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f], rotated: [%s]", m_visibleContentRect.x(), m_visibleContentRect.y(), newScale, isRotated ? "Rotated" : "Not rotated");
457 #endif
458
459 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
460     setVisibleContentRect(IntRect(newScrollPosition, m_visibleContentRect.size()), newScale);
461 #else
462     m_viewImpl->page()->scalePage(newScale, newScrollPosition);
463 #endif
464
465 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
466     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(m_viewImpl->view()));
467     if (smartData->api->formdata_candidate_is_showing(smartData))
468         smartData->api->formdata_candidate_hide(smartData);
469 #endif
470
471 #if ENABLE(TIZEN_FULLSCREEN_API)
472     if (m_viewImpl->page()->fullScreenManager()->isFullScreen())
473         m_viewImpl->page()->fullScreenManager()->updateMediaControlsStyle();
474 #endif
475 }
476
477 #if OS(TIZEN)
478 void PageClientImpl::registerEditCommand(PassRefPtr<WebEditCommandProxy> command, WebPageProxy::UndoOrRedo undoOrRedo)
479 {
480     if (undoOrRedo == WebPageProxy::Undo) {
481         m_undoCommands.append(command);
482
483         int undoSize = m_undoCommands.size();
484         evas_object_smart_callback_call(m_viewImpl->view(), "undo,size", &undoSize);
485     }
486     else {
487         m_redoCommands.append(command);
488
489         int redoSize = m_redoCommands.size();
490         evas_object_smart_callback_call(m_viewImpl->view(), "redo,size", &redoSize);
491     }
492 }
493
494 void PageClientImpl::clearAllEditCommands()
495 {
496     m_undoCommands.clear();
497     m_redoCommands.clear();
498
499     int undoSize = m_undoCommands.size();
500     evas_object_smart_callback_call(m_viewImpl->view(), "undo,size", &undoSize);
501
502     int redoSize = m_redoCommands.size();
503     evas_object_smart_callback_call(m_viewImpl->view(), "redo,size", &redoSize);
504 }
505
506 bool PageClientImpl::canUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
507 {
508     if (undoOrRedo == WebPageProxy::Undo)
509         return !m_undoCommands.isEmpty();
510     else
511         return !m_redoCommands.isEmpty();
512 }
513
514 void PageClientImpl::executeUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
515 {
516     if (undoOrRedo == WebPageProxy::Undo) {
517         m_undoCommands.last()->unapply();
518         m_undoCommands.removeLast();
519
520         int undoSize = m_undoCommands.size();
521         evas_object_smart_callback_call(m_viewImpl->view(), "undo,size", &undoSize);
522     } else {
523         m_redoCommands.last()->reapply();
524         m_redoCommands.removeLast();
525
526         int redoSize = m_redoCommands.size();
527         evas_object_smart_callback_call(m_viewImpl->view(), "redo,size", &redoSize);
528     }
529 }
530 #else
531 void PageClientImpl::registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo)
532 {
533     notImplemented();
534 }
535
536 void PageClientImpl::clearAllEditCommands()
537 {
538     notImplemented();
539 }
540
541 bool PageClientImpl::canUndoRedo(WebPageProxy::UndoOrRedo)
542 {
543     notImplemented();
544     return false;
545 }
546
547 void PageClientImpl::executeUndoRedo(WebPageProxy::UndoOrRedo)
548 {
549     notImplemented();
550 }
551 #endif
552
553 FloatRect PageClientImpl::convertToDeviceSpace(const FloatRect& viewRect)
554 {
555     notImplemented();
556     return viewRect;
557 }
558
559 FloatRect PageClientImpl::convertToUserSpace(const FloatRect& viewRect)
560 {
561     notImplemented();
562     return viewRect;
563 }
564
565 IntPoint PageClientImpl::screenToWindow(const IntPoint& point)
566 {
567     notImplemented();
568     return point;
569 }
570
571 IntRect PageClientImpl::windowToScreen(const IntRect&)
572 {
573     notImplemented();
574     return IntRect();
575 }
576
577 void PageClientImpl::doneWithKeyEvent(const NativeWebKeyboardEvent&, bool)
578 {
579     notImplemented();
580 }
581
582 #if ENABLE(GESTURE_EVENTS)
583 void PageClientImpl::doneWithGestureEvent(const WebGestureEvent& event, bool wasEventHandled)
584 {
585     notImplemented();
586 }
587 #endif
588
589 #if ENABLE(TOUCH_EVENTS)
590 void PageClientImpl::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
591 {
592 #if OS(TIZEN)
593     ewk_view_touch_event_handler_result_set(m_viewImpl->view(), event.type(), wasEventHandled);
594 #else
595     notImplemented();
596 #endif // #if OS(TIZEN)
597 }
598 #endif
599
600 PassRefPtr<WebPopupMenuProxy> PageClientImpl::createPopupMenuProxy(WebPageProxy* page)
601 {
602     return WebPopupMenuProxyEfl::create(m_viewImpl, page);
603 }
604
605 PassRefPtr<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy* page)
606 {
607 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
608     return WebContextMenuProxyTizen::create(m_viewImpl->view(), page, this);
609 #else
610     notImplemented();
611     return 0;
612 #endif
613 }
614
615 #if ENABLE(INPUT_TYPE_COLOR)
616 PassRefPtr<WebColorChooserProxy> PageClientImpl::createColorChooserProxy(WebPageProxy*, const WebCore::Color&)
617 {
618     notImplemented();
619     return 0;
620 }
621 #endif
622
623 void PageClientImpl::setFindIndicator(PassRefPtr<FindIndicator>, bool, bool)
624 {
625     notImplemented();
626 }
627
628 #if !OS(TIZEN)
629 #if USE(ACCELERATED_COMPOSITING)
630 void PageClientImpl::enterAcceleratedCompositingMode(const LayerTreeContext&)
631 {
632     m_viewImpl->enterAcceleratedCompositingMode();
633 }
634
635 void PageClientImpl::exitAcceleratedCompositingMode()
636 {
637     m_viewImpl->exitAcceleratedCompositingMode();
638 }
639
640 void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext&)
641 {
642     notImplemented();
643 }
644 #endif // USE(ACCELERATED_COMPOSITING)
645 #endif
646
647 void PageClientImpl::initializeAcceleratedCompositingMode()
648 {
649 }
650
651 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
652 void PageClientImpl::updateAcceleratedCompositingMode(const LayerTreeContext&)
653 {
654     notImplemented();
655 }
656 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC)
657
658 void PageClientImpl::setBackgroundColor(double red, double green, double blue, double alpha)
659 {
660     WebCore::RGBA32 rgba= WebCore::makeRGBA32FromFloats((float)red, (float)green, (float)blue, (float)alpha);
661     m_bgColor.setRGB(rgba);
662 }
663
664 void PageClientImpl::didChangeScrollbarsForMainFrame() const
665 {
666     notImplemented();
667 }
668
669 #if OS(TIZEN)
670 void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame()
671 {
672     m_nonemptyLayoutRendered = true;
673 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
674     m_initialViewRect.setSize(viewSize());
675 #endif
676 }
677
678 void PageClientImpl::didChangeContentsSize(const WebCore::IntSize size)
679 {
680 #if ENABLE(TIZEN_DLOG_SUPPORT)
681     TIZEN_LOGI(" [%d, %d]", size.width(), size.height());
682 #endif
683 #if USE(TILED_BACKING_STORE)
684     if (size.isEmpty())
685         return;
686
687 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
688     if (drawingArea()->layerTreeCoordinatorProxy())
689         drawingArea()->layerTreeCoordinatorProxy()->setContentsSize(WebCore::FloatSize(size.width(), size.height()));
690 #endif
691
692     // if minimum scale factor is changed, update minimumScale.
693     if (m_viewportConstraints.userScalable) {
694         double minimumScale = availableMinimumScale();
695
696         // Sometimes initializeVisibleContentRect can be called after content size change.
697         // So, if initialScale is not set explicitly in content's meta viewport tag and is same to minimumScale, update initialScale too.
698         if (!m_viewportConstraints.contentsDefinedInitialScale
699             && fabs(m_viewportConstraints.initialScale - m_viewportConstraints.minimumScale) < numeric_limits<float>::epsilon())
700             m_viewportConstraints.initialScale = minimumScale;
701         m_viewportConstraints.minimumScale = minimumScale;
702     }
703 #else
704     m_viewImpl->informContentsSizeChange(size);
705 #endif
706     if (!m_pageDidRendered || m_viewImpl->page()->estimatedProgress() <= 0.1)
707         return;
708
709     // FIXME: Do we really need to adjust visible content rect at here?
710     // if contents size is changed smaller and visible content rect is outside of content area,
711     // adjust visible content rect
712     bool needScrollAdjustment = (adjustVisibleContentRect(m_visibleContentRect, scaleFactor()) != m_visibleContentRect);
713     bool needScaleAdjustment = (fabs(adjustScaleWithViewport(scaleFactor()) - scaleFactor()) > numeric_limits<float>::epsilon());
714     if (needScrollAdjustment || needScaleAdjustment) {
715 #if ENABLE(TIZEN_DLOG_SUPPORT)
716         TIZEN_LOGI(" setVisibleContentRect: [%d, %d], [%.2f]", m_visibleContentRect.x(), m_visibleContentRect.y(), scaleFactor());
717 #endif
718         setVisibleContentRect(m_visibleContentRect, scaleFactor());
719     }
720 }
721
722 void PageClientImpl::pageScaleFactorDidChange()
723 {
724     ewk_view_focused_node_adjust(m_viewImpl->view());
725 }
726 #endif // #if OS(TIZEN)
727
728 void PageClientImpl::didCommitLoadForMainFrame(bool)
729 {
730 #if OS(TIZEN)
731     m_pageDidRendered = false;
732     m_viewportFitsToContent = false;
733     m_nonemptyLayoutRendered = false;
734     return;
735 #endif
736     notImplemented();
737 }
738
739 void PageClientImpl::didFinishLoadingDataForCustomRepresentation(const String&, const CoreIPC::DataReference&)
740 {
741     notImplemented();
742 }
743
744 double PageClientImpl::customRepresentationZoomFactor()
745 {
746     notImplemented();
747     return 0;
748 }
749
750 void PageClientImpl::setCustomRepresentationZoomFactor(double)
751 {
752     notImplemented();
753 }
754
755 void PageClientImpl::flashBackingStoreUpdates(const Vector<IntRect>&)
756 {
757     notImplemented();
758 }
759
760 void PageClientImpl::findStringInCustomRepresentation(const String&, FindOptions, unsigned)
761 {
762     notImplemented();
763 }
764
765 void PageClientImpl::countStringMatchesInCustomRepresentation(const String&, FindOptions, unsigned)
766 {
767     notImplemented();
768 }
769
770 void PageClientImpl::updateTextInputState()
771 {
772 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
773     m_textSelection->update();
774     if (isTextSelectionMode() && isTextSelectionHandleDowned())
775         return;
776 #endif
777
778     InputMethodContextEfl* inputMethodContext = m_viewImpl->inputMethodContext();
779     if (inputMethodContext)
780         inputMethodContext->updateTextInputState();
781 }
782
783 void PageClientImpl::handleDownloadRequest(DownloadProxy* download)
784 {
785     Ewk_Context* context = m_viewImpl->ewkContext();
786     context->downloadManager()->registerDownload(download, m_viewImpl);
787 }
788
789 #if USE(TILED_BACKING_STORE)
790 void PageClientImpl::pageDidRequestScroll(const IntPoint& point)
791 {
792 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
793     Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(m_viewImpl->view()));
794     if (smartData->api->formdata_candidate_is_showing(smartData))
795         return;
796 #endif
797 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
798     IntPoint newPoint = point;
799     newPoint.scale(scaleFactor(), scaleFactor());
800 #if ENABLE(TIZEN_WEBKIT2_BEFORE_PAGE_RENDERED_SCROLL_POSITION)
801     if (!m_pageDidRendered)
802         m_scrollPositionBeforePageRendered = newPoint;
803     else
804         setVisibleContentRect(IntRect(newPoint, m_visibleContentRect.size()), scaleFactor());
805 #else
806     setVisibleContentRect(IntRect(newPoint, m_visibleContentRect.size()), scaleFactor());
807 #endif
808 #endif
809 }
810 #endif
811
812 #if OS(TIZEN)
813 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
814 void PageClientImpl::pageDidRequestRestoreVisibleContentRect(const IntPoint& point, float scale)
815 {
816     m_restoredScrollPosition = point;
817     m_restoredScrollPosition.scale(scale, scale);
818     m_restoredScaleFactor = scale;
819 #if ENABLE(TIZEN_DLOG_SUPPORT)
820     TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", m_restoredScrollPosition.x(), m_restoredScrollPosition.y(), m_restoredScaleFactor);
821 #endif
822
823     // Before contents size is fixed, just update visible content rect's position
824     m_visibleContentRect.setLocation(m_restoredScrollPosition);
825 }
826 #endif
827
828 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
829 void PageClientImpl::textChangeInTextField(const String& name, const String& value)
830 {
831     if (value == m_formDataCandidate->getCandidateValue()) {
832         m_formDataCandidate->updateCandidateValue(emptyString());
833         return;
834     }
835
836     m_formDataCandidate->updateCandidateValue(value);
837     ewk_view_text_change_in_textfield(m_viewImpl->view(), name, value);
838 }
839 #endif
840
841 void PageClientImpl::updateFormNavigation(int length, int offset)
842 {
843     notImplemented();
844 }
845
846 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
847 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
848 DrawingAreaProxy* PageClientImpl::drawingArea() const
849 {
850     return m_viewImpl->page()->drawingArea();
851 }
852 #endif
853
854 // Before rendering, scale factor and scroll position is different from m_viewImpl.
855 float PageClientImpl::scaleFactor()
856 {
857     return m_pageDidRendered ? m_viewImpl->scaleFactor() : (m_restoredScaleFactor ? m_restoredScaleFactor : m_viewportConstraints.initialScale);
858 }
859
860 const IntPoint PageClientImpl::scrollPosition()
861 {
862     return m_pageDidRendered ? m_viewImpl->scrollPosition() : (m_restoredScaleFactor ? m_restoredScrollPosition : IntPoint());
863 }
864
865 IntRect PageClientImpl::adjustVisibleContentRect(IntRect visibleContentRect, float targetScale)
866 {
867     IntSize contentsSize = m_viewImpl->page()->contentsSize();
868     contentsSize.scale(targetScale);
869     if (contentsSize.width() < visibleContentRect.width())
870         visibleContentRect.setX(0);
871     else
872         visibleContentRect.setX(clampTo(visibleContentRect.x(), 0, contentsSize.width() - visibleContentRect.width()));
873
874     if (contentsSize.height() < visibleContentRect.height())
875         visibleContentRect.setY(0);
876     else
877         visibleContentRect.setY(clampTo(visibleContentRect.y(), 0, contentsSize.height() - visibleContentRect.height()));
878     return visibleContentRect;
879 }
880
881 void PageClientImpl::setVisibleContentRect(const IntRect& newRect, float newScale, const FloatPoint& trajectory)
882 {
883 #if ENABLE(TIZEN_SCREEN_READER)
884     IntPoint previousScrollPosition(scrollPosition());
885     float previousScale = m_scaleFactor;
886 #endif
887
888     m_scaleFactor = adjustScaleWithViewport(newScale);
889     m_viewportFitsToContent = fabs(m_scaleFactor - m_viewportConstraints.minimumScale) < numeric_limits<float>::epsilon();
890     m_visibleContentRect.setLocation(newRect.location());
891     m_visibleContentRect = adjustVisibleContentRect(m_visibleContentRect, m_scaleFactor);
892
893     // update both drawing scale factor and scroll position after page is rendered
894     if (m_pageDidRendered) {
895         if (!m_hasSuspendedContent) {
896             // FIXME: We have to update EwkViewImpl's scale and position here because we use them to draw contents.
897             // PageViewport's values are updated when resuming content in the webkit opensource,
898             // but we have to update viewImpl's values here to sync with PageClient's values.
899             // However, We should not update them when hasSuspendedContent is true in order to maintain last values.
900             // The values will be updated when resuming content.
901             // Below codes should be refactored when PageViewportController codes are merged into Tizen.
902             m_viewImpl->setScaleFactor(m_scaleFactor);
903             m_viewImpl->setScrollPosition(m_visibleContentRect.location());
904         }
905     }
906
907     // enclosingIntRect produces inconsistent width and height when scale factor is not 1.
908     // So we removed enclosingIntRect and replaced with floorf and ceilf.
909     IntRect mapToContentsVisibleContentRect = IntRect(floorf(m_visibleContentRect.x() / m_scaleFactor),
910                                                       floorf(m_visibleContentRect.y() / m_scaleFactor),
911                                                       ceilf(m_visibleContentRect.width() / m_scaleFactor),
912                                                       ceilf(m_visibleContentRect.height() / m_scaleFactor));
913     if (!drawingArea())
914         return;
915     drawingArea()->setVisibleContentsRect(mapToContentsVisibleContentRect, m_scaleFactor, trajectory, FloatPoint(m_viewImpl->scrollPosition()));
916 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
917     // FIXME: We need to calculate exact visibleRect size here instead of mapToContentsVisibleContentRect.
918     drawingArea()->setVisibleContentsRectForScrollingContentsLayers(mapToContentsVisibleContentRect);
919 #endif
920     displayViewport();
921
922 #if ENABLE(TIZEN_SCREEN_READER)
923     if (ScreenReaderProxy::screenReader().isEnabled()
924         && (scrollPosition() != previousScrollPosition || m_scaleFactor != previousScale))
925         ewkViewGetFocusRing(m_viewImpl->view())->updateScrollAndScale(previousScrollPosition, previousScale);
926 #endif
927
928 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
929     if (!isClipboardWindowOpened())
930         updateTextSelectionHandlesAndContextMenu(true);
931 #endif
932 }
933
934 void PageClientImpl::displayViewport()
935 {
936     setViewNeedsDisplay(IntRect(IntPoint(), viewSize()));
937
938 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
939     updateScrollbar();
940 #endif
941
942 #if ENABLE(TIZEN_SCREEN_READER)
943     m_viewImpl->page()->recalcScreenReaderFocusRect();
944 #endif
945 }
946
947 void PageClientImpl::drawContents()
948 {
949 }
950
951 void PageClientImpl::drawContents(BackingStore::PlatformGraphicsContext context)
952 {
953     cairo_save(context);
954     const cairo_matrix_t matrix = cairo_matrix_t(m_viewImpl->transformToView());
955     cairo_transform(context, &matrix);
956
957     if (drawingArea()) {
958         if (drawingArea()->layerTreeCoordinatorProxy()) {
959             WebLayerTreeRenderer* renderer = drawingArea()->layerTreeCoordinatorProxy()->layerTreeRenderer();
960             renderer->paintToGraphicsContext(context, m_bgColor);
961         }
962     }
963
964     cairo_restore(context);
965 }
966
967 void PageClientImpl::scaleImage(double scaleFactor, IntPoint scrollPosition)
968 {
969 #if OS(TIZEN) && ENABLE(FULLSCREEN_API)
970     // We don't want to process scaling in the FullScreen mode.
971     if (m_viewImpl->page()->fullScreenManager()->isFullScreen())
972         return;
973 #endif
974
975 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
976     m_textSelection->hideHandlers();
977 #endif
978
979     // Adjust scaleFactor.
980 #if ENABLE(TIZEN_WEBKIT2_TEXT_ZOOM)
981     if (!m_viewImpl->page()->pageGroup()->preferences()->textZoomEnabled())
982         scaleFactor = adjustScaleWithViewport(scaleFactor);
983 #else
984     scaleFactor = adjustScaleWithViewport(scaleFactor);
985 #endif
986
987     scaleContents(scaleFactor, scrollPosition);
988 }
989
990 void PageClientImpl::scaleContents(double scaleFactor, const IntPoint& origin)
991 {
992 #if OS(TIZEN) && ENABLE(FULLSCREEN_API)
993     // We don't want to process scaling in the FullScreen mode.
994     if (m_viewImpl->page()->fullScreenManager()->isFullScreen())
995         return;
996 #endif
997     scaleFactor = adjustScaleWithViewport(scaleFactor);
998
999     setVisibleContentRect(IntRect(origin, m_visibleContentRect.size()), scaleFactor);
1000 }
1001
1002 // FIXME: The concept of suspending content comes from webkit opensource's PageViewportController,
1003 // so below code should be replaced when PageViewportController codes are merged.
1004 // Please do not use below codes. They are only for scaling contents.
1005 void PageClientImpl::suspendContent()
1006 {
1007     if (m_hasSuspendedContent)
1008         return;
1009
1010     m_hasSuspendedContent = true;
1011 }
1012
1013 void PageClientImpl::resumeContent()
1014 {
1015     if (!m_hasSuspendedContent)
1016         return;
1017
1018 #if ENABLE(TIZEN_DLOG_SUPPORT)
1019     TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", m_viewImpl->scrollPosition().x(), m_viewImpl->scrollPosition().y(), m_viewImpl->scaleFactor());
1020 #endif
1021
1022     // FIXME: Update visibleContentRect with m_viewImpl after resuming content.
1023     // The concept is that the values of EwkViewImpl and PageClient can be different
1024     // during suspending content and they become same when content is resumed.
1025     // Below codes should be refactored when PageViewportController codes are merged into Tizen.
1026     setVisibleContentRect(IntRect(m_viewImpl->scrollPosition(), m_visibleContentRect.size()), m_viewImpl->scaleFactor());
1027     m_hasSuspendedContent = false;
1028 }
1029
1030 FloatPoint PageClientImpl::boundContentsPositionAtScale(const FloatPoint& framePosition, float scale)
1031 {
1032     // We need to floor the viewport here as to allow aligning the content in device units. If not,
1033     // it might not be possible to scroll the last pixel and that affects fixed position elements.
1034     FloatRect bounds;
1035     const IntSize& contentsSize = m_viewImpl->page()->contentsSize();
1036     bounds.setWidth(std::max(0.f, contentsSize.width() - floorf(viewSize().width() / scale)));
1037     bounds.setHeight(std::max(0.f, contentsSize.height() - floorf(viewSize().height() / scale)));
1038
1039     FloatPoint position;
1040     // Unfortunately it doesn't seem to be enough, so just always allow one pixel more.
1041     position.setX(clampTo(framePosition.x(), bounds.x(), bounds.width() + 1));
1042     position.setY(clampTo(framePosition.y(), bounds.y(), bounds.height() + 1));
1043
1044     return position;
1045 }
1046
1047 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
1048 void PageClientImpl::createScrollbarIfNeeded(bool horizontalBar, bool verticalBar)
1049 {
1050     // create if needed.
1051     if (horizontalBar && !m_horizontalScrollbar) {
1052         m_horizontalScrollbar = MainFrameScrollbarTizen::createNativeScrollbar(m_viewImpl->view(), HorizontalScrollbar);
1053         IntRect hBarRect(0, viewSize().height(), viewSize().width(), 0);
1054         m_horizontalScrollbar->setFrameRect(hBarRect);
1055     } else if (!horizontalBar && m_horizontalScrollbar)
1056         m_horizontalScrollbar = 0;
1057
1058     if (verticalBar && !m_verticalScrollbar) {
1059         m_verticalScrollbar = MainFrameScrollbarTizen::createNativeScrollbar(m_viewImpl->view(), VerticalScrollbar);
1060         IntRect vBarRect(viewSize().width(), 0, 0, viewSize().height());
1061         m_verticalScrollbar->setFrameRect(vBarRect);
1062     } else if (!verticalBar && m_verticalScrollbar)
1063         m_verticalScrollbar = 0;
1064 }
1065
1066 void PageClientImpl::updateScrollbar()
1067 {
1068     IntSize scaledContentsSize = m_viewImpl->page()->contentsSize();
1069     scaledContentsSize.scale(scaleFactor());
1070
1071     bool newHasHorizontalScrollbar = false;
1072     bool newVerticalScrollbar = false;
1073     if (viewSize().width() < scaledContentsSize.width())
1074         newHasHorizontalScrollbar = true;
1075     if (viewSize().height() < scaledContentsSize.height())
1076         newVerticalScrollbar = true;
1077     createScrollbarIfNeeded(newHasHorizontalScrollbar, newVerticalScrollbar);
1078
1079     if (m_horizontalScrollbar) {
1080         m_horizontalScrollbar->setProportion(viewSize().width(), scaledContentsSize.width());
1081         m_horizontalScrollbar->setPosition(m_viewImpl->scrollPosition().x());
1082     }
1083     if (m_verticalScrollbar) {
1084         m_verticalScrollbar->setProportion(viewSize().height(), scaledContentsSize.height());
1085         m_verticalScrollbar->setPosition(m_viewImpl->scrollPosition().y());
1086     }
1087 }
1088
1089 void PageClientImpl::frameRectChanged()
1090 {
1091     if (m_horizontalScrollbar) {
1092         IntRect hBarRect(0, viewSize().height(), viewSize().width(), 0);
1093         m_horizontalScrollbar->setFrameRect(hBarRect);
1094     }
1095     if (m_verticalScrollbar) {
1096         IntRect vBarRect(viewSize().width(), 0, 0, viewSize().height());
1097         m_verticalScrollbar->setFrameRect(vBarRect);
1098     }
1099 }
1100
1101 void PageClientImpl::updateVisibility()
1102 {
1103     if (m_horizontalScrollbar)
1104         m_horizontalScrollbar->updateVisibility();
1105     if (m_verticalScrollbar)
1106         m_verticalScrollbar->updateVisibility();
1107 }
1108 #endif
1109 #endif // ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
1110
1111 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1112 bool PageClientImpl::isTextSelectionDowned()
1113 {
1114     return m_textSelection->isTextSelectionDowned();
1115 }
1116
1117 bool PageClientImpl::isTextSelectionMode()
1118 {
1119     return m_textSelection->isTextSelectionMode();
1120 }
1121
1122 void PageClientImpl::setIsTextSelectionMode(bool isTextSelectionMode)
1123 {
1124     m_textSelection->setIsTextSelectionMode(isTextSelectionMode);
1125 }
1126
1127 void PageClientImpl::updateTextSelectionHandlesAndContextMenu(bool isShow, bool isScrolling)
1128 {
1129     if (m_textSelection->isTextSelectionMode() && evas_object_focus_get(m_viewImpl->view()))
1130         m_textSelection->updateHandlesAndContextMenu(isShow, isScrolling);
1131 }
1132
1133 bool PageClientImpl::textSelectionDown(const WebCore::IntPoint& point, bool isStartedTextSelectionFromOutside)
1134 {
1135     if (!evas_object_focus_get(m_viewImpl->view())) {
1136         InputMethodContextEfl* inputMethodContext = m_viewImpl->inputMethodContext();
1137         if (inputMethodContext)
1138             inputMethodContext->hideIMFContext();
1139
1140         evas_object_focus_set(m_viewImpl->view(), true);
1141     }
1142
1143     return m_textSelection->textSelectionDown(point, isStartedTextSelectionFromOutside);
1144 }
1145
1146 void PageClientImpl::textSelectionMove(const WebCore::IntPoint& point, bool isStartedTextSelectionFromOutside)
1147 {
1148     m_textSelection->textSelectionMove(point, isStartedTextSelectionFromOutside);
1149 }
1150
1151 void PageClientImpl::textSelectionUp(const WebCore::IntPoint& point, bool isStartedTextSelectionFromOutside)
1152 {
1153     m_textSelection->textSelectionUp(point, isStartedTextSelectionFromOutside);
1154 }
1155
1156 bool PageClientImpl::isTextSelectionHandleDowned()
1157 {
1158     return m_textSelection->isTextSelectionHandleDowned();
1159 }
1160
1161 #if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
1162 void PageClientImpl::textSelectonHandleDown(const WebCore::IntPoint& point)
1163 {
1164     m_textSelection->textSelectionHandleDown(point);
1165 }
1166
1167 void PageClientImpl::textSelectonHandleMove(const WebCore::IntPoint& point)
1168 {
1169     m_textSelection->textSelectionHandleMove(point);
1170 }
1171
1172 void PageClientImpl::textSelectonHandleUp()
1173 {
1174     m_textSelection->textSelectionHandleUp();
1175 }
1176 #endif
1177
1178 void PageClientImpl::requestToShowTextSelectionHandlesAndContextMenu()
1179 {
1180     m_textSelection->requestToShow();
1181 }
1182
1183 void PageClientImpl::initTextSelectionHandlesMouseDownedStatus()
1184 {
1185     m_textSelection->initHandlesMouseDownedStatus();
1186 }
1187
1188 void PageClientImpl::changeContextMenuPosition(IntPoint& point)
1189 {
1190     m_textSelection->changeContextMenuPosition(point);
1191 }
1192 #endif
1193
1194 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
1195 void PageClientImpl::saveSerializedHTMLDataForMainPage(const String& serializedData, const String& fileName)
1196 {
1197     m_offlinePageSave->saveSerializedHTMLDataForMainPage(serializedData, fileName);
1198 }
1199
1200 void PageClientImpl::saveSubresourcesData(Vector<WebSubresourceTizen>& subresourceData)
1201 {
1202     m_offlinePageSave->saveSubresourcesData(subresourceData);
1203 }
1204
1205 void PageClientImpl::startOfflinePageSave(String& path, String& url, String& title)
1206 {
1207     m_offlinePageSave->startOfflinePageSave(path, url, title);
1208 }
1209 #endif
1210
1211 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
1212 void PageClientImpl::pasteContextMenuSelected()
1213 {
1214     m_clipboardHelper->pasteClipboardLastItem(m_viewImpl->page()->editorState().isContentRichlyEditable);
1215 }
1216 #endif
1217
1218 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
1219 void PageClientImpl::setClipboardData(const String& data, const String& type)
1220 {
1221 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
1222     m_clipboardHelper->setData(data, type);
1223 #endif
1224 }
1225
1226 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
1227 void PageClientImpl::clipboardContextMenuSelected()
1228 {
1229     m_clipboardHelper->openClipboardWindow(m_viewImpl->page()->editorState().isContentRichlyEditable);
1230 }
1231
1232 bool PageClientImpl::isClipboardWindowOpened()
1233 {
1234     return m_clipboardHelper->isClipboardWindowOpened();
1235 }
1236
1237 void PageClientImpl::closeClipboardWindow()
1238 {
1239     m_clipboardHelper->closeClipboardWindow();
1240 }
1241 #endif
1242
1243 void PageClientImpl::clearClipboardData()
1244 {
1245 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
1246     m_clipboardHelper->clear();
1247 #endif
1248 }
1249 #endif
1250
1251 #if ENABLE(TIZEN_WEBKIT2_VIEW_VISIBILITY)
1252 void PageClientImpl::setIsVisible(bool isVisible)
1253 {
1254 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
1255     if (m_isVisible != isVisible && m_viewImpl->view() && m_pageDidRendered) {
1256         if (!isVisible && (drawingArea() && drawingArea()->layerTreeCoordinatorProxy()) && !m_shouldShowBackupTexture) {
1257             Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
1258             int angle = ecore_evas_rotation_get(ee);
1259             if (angle == 0 || angle == 180) {
1260                 m_shouldMakeBackupTexture = true;
1261                 m_shouldShowBackupTexture = true;
1262                 drawContents();
1263             }
1264         }
1265     }
1266 #endif
1267
1268     m_isVisible = isVisible;
1269
1270     WebPageProxy* pageProxy = m_viewImpl->page();
1271     if (pageProxy)
1272         pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible);
1273
1274 #if ENABLE(TIZEN_CACHE_MEMORY_OPTIMIZATION)
1275     if (!m_isVisible)
1276         ewk_view_context_get(m_viewImpl->view())->clearAllDecodedData();
1277 #endif
1278 }
1279 #endif
1280
1281 #if ENABLE(TIZEN_DRAG_SUPPORT)
1282 void PageClientImpl::setDragPoint(const WebCore::IntPoint& point)
1283 {
1284     m_drag->setDragPoint(point);
1285 }
1286 bool PageClientImpl::isDragMode()
1287 {
1288     return m_drag->isDragMode();
1289 }
1290 void PageClientImpl::setDragMode(bool isDragMode)
1291 {
1292     m_drag->setDragMode(isDragMode);
1293 }
1294 void PageClientImpl::startDrag(const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
1295 {
1296     DragData* dragInfo = new DragData(dragData.platformData(), m_drag->getDragPoint(),
1297         m_drag->getDragPoint(), dragData.draggingSourceOperationMask(), dragData.flags());
1298
1299     String dragStorageName("Drag");
1300     m_viewImpl->page()->dragEntered(dragInfo, dragStorageName);
1301     setDragMode(true);
1302     m_drag->setDragData(dragInfo);
1303     m_drag->Show();
1304 }
1305 #endif
1306
1307 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
1308 bool PageClientImpl::isShowingFormDataCandidate()
1309 {
1310     return m_formDataCandidate->isShowing();
1311 }
1312
1313 void PageClientImpl::updateFormDataCandidate(const Vector<String>& data)
1314 {
1315     m_formDataCandidate->updateFormData(data);
1316 }
1317
1318 void PageClientImpl::hideFormDataCandidate()
1319 {
1320     m_formDataCandidate->hide();
1321 }
1322
1323 void PageClientImpl::showFormDataCandidate(const WebCore::IntRect& rect)
1324 {
1325     m_formDataCandidate->show(rect);
1326 }
1327 #endif
1328
1329 #if ENABLE(TIZEN_REGISTER_PROTOCOL_HANDLER)
1330 void PageClientImpl::registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title)
1331 {
1332     ewkViewRegisterProtocolHandlers(m_viewImpl->view(), scheme.utf8().data(), baseURL.utf8().data(), url.utf8().data(), title.utf8().data());
1333 }
1334 #endif
1335
1336 #if ENABLE(TIZEN_CUSTOM_SCHEME_HANDLER)
1337 unsigned int PageClientImpl::isProtocolHandlerRegistered(const String& scheme, const String& baseURL, const String& url)
1338 {
1339     return ewkViewIsProtocolHandlerRegistered(m_viewImpl->view(), scheme.utf8().data(), baseURL.utf8().data(), url.utf8().data());
1340 }
1341
1342 void PageClientImpl::unregisterProtocolHandler(const String& scheme, const String& baseURL, const String& url)
1343 {
1344     ewkViewUnregisterProtocolHandlers(m_viewImpl->view(), scheme.utf8().data(), baseURL.utf8().data(), url.utf8().data());
1345 }
1346 #endif
1347
1348 #if ENABLE(TIZEN_REGISTER_CONTENT_HANDLER)
1349 void PageClientImpl::registerContentHandler(const String& mimeType, const String& baseURL, const String& url, const String& title)
1350 {
1351     ewkViewRegisterContentHandlers(m_viewImpl->view(), mimeType.utf8().data(), baseURL.utf8().data(), url.utf8().data(), title.utf8().data());
1352 }
1353
1354 unsigned int PageClientImpl::isContentHandlerRegistered(const String& mimeType, const String& baseURL, const String& url)
1355 {
1356     return ewkViewIsContentHandlerRegistered(m_viewImpl->view(), mimeType.utf8().data(), baseURL.utf8().data(), url.utf8().data());
1357 }
1358
1359 void PageClientImpl::unregisterContentHandler(const String& mimeType, const String& baseURL, const String& url)
1360 {
1361     ewkViewUnregisterContentHandlers(m_viewImpl->view(), mimeType.utf8().data(), baseURL.utf8().data(), url.utf8().data());
1362 }
1363 #endif
1364
1365 #if ENABLE(TIZEN_SEARCH_PROVIDER)
1366 void PageClientImpl::addSearchProvider(const String& baseURL, const String& engineURL)
1367 {
1368     ewkViewAddSearchProvider(m_viewImpl->view(), baseURL.utf8().data(), engineURL.utf8().data());
1369 }
1370
1371 unsigned long PageClientImpl::isSearchProviderInstalled(const String& baseURL, const String& engineURL)
1372 {
1373     return ewkViewIsSearchProviderInstalled(m_viewImpl->view(), baseURL.utf8().data(), engineURL.utf8().data());
1374 }
1375 #endif
1376
1377 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
1378 bool PageClientImpl::getStandaloneStatus()
1379 {
1380     return ewkViewGetStandaloneStatus(m_viewImpl->view());
1381 }
1382 #endif
1383
1384 #if ENABLE(SCREEN_ORIENTATION_SUPPORT) && ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT)
1385 bool PageClientImpl::lockOrientation(int willLockOrientation)
1386 {
1387     return ewk_view_orientation_lock(m_viewImpl->view(), willLockOrientation);
1388 }
1389
1390 void PageClientImpl::unlockOrientation()
1391 {
1392     ewk_view_orientation_unlock(m_viewImpl->view());
1393 }
1394 #endif
1395
1396 void PageClientImpl::didRenderFrame()
1397 {
1398 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
1399     if (m_shouldShowBackupTexture && m_isVisible)
1400         m_shouldShowBackupTexture = false;
1401 #endif
1402     if (!m_pageDidRendered) {
1403         m_pageDidRendered = true;
1404         initializeVisibleContentRect();
1405     }
1406
1407 #if ENABLE(TIZEN_PRERENDERING_FOR_ROTATION)
1408     if (m_waitFrameOfNewViewortSize) {
1409         m_waitFrameOfNewViewortSize = false;
1410         ewkViewRotatePrepared(m_viewImpl->view());
1411     }
1412 #endif
1413 }
1414
1415 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1416 void PageClientImpl::setOverflowResult(bool pressed, WebLayerID webLayerID)
1417 {
1418     setIsScrollableLayerFocused(false);
1419     setIsScrollableNodeFocused(false);
1420
1421     if (pressed) {
1422         if (webLayerID) {
1423             setIsScrollableLayerFocused(true);
1424             m_viewImpl->page()->drawingArea()->layerTreeCoordinatorProxy()->layerTreeRenderer()->setFocusedLayerID(webLayerID);
1425         } else {
1426             setIsScrollableNodeFocused(true);
1427         }
1428     }
1429 }
1430
1431 void PageClientImpl::findScrollableNode(const IntPoint& point)
1432 {
1433     WebPageProxy* pageProxy = m_viewImpl->page();
1434     if (pageProxy && pageProxy->isLoadingFinished() && pageProxy->askOverflow()) {
1435         IntPoint pointForPress(m_viewImpl->transformFromScene().mapPoint(point));
1436         WebLayerID webLayerID = 0;
1437         bool checkOverflowLayer = false;
1438 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1439         DrawingAreaProxy* drawingArea = pageProxy->drawingArea();
1440         checkOverflowLayer = drawingArea && drawingArea->layerTreeCoordinatorProxy() && drawingArea->layerTreeCoordinatorProxy()->hasOverflowLayer();
1441 #endif
1442         setOverflowResult(pageProxy->setPressedNodeAtPoint(pointForPress, checkOverflowLayer, webLayerID), webLayerID);
1443     }
1444 }
1445 #endif
1446
1447 void PageClientImpl::didFindZoomableArea(const IntPoint& target, const IntRect& area)
1448 {
1449     ewk_view_zoomable_area_set(m_viewImpl->view(), target, area);
1450 }
1451
1452 #if ENABLE(TIZEN_ICON_DATABASE)
1453 void PageClientImpl::didReceiveIcon()
1454 {
1455     ewkViewIconReceived(m_viewImpl->view());
1456 }
1457 #endif
1458
1459 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1460 void PageClientImpl::hideFocusRing()
1461 {
1462     ewkViewFocusRingHide(m_viewImpl->view());
1463 }
1464 #endif
1465 #endif // #if OS(TIZEN)
1466
1467
1468 #if ENABLE(TIZEN_WEBKIT2_TILED_AC) && ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
1469 PageClientEvasGL::PageClientEvasGL(EwkViewImpl* viewImpl)
1470     : PageClientImpl(viewImpl)
1471     , m_evasGL(0)
1472     , m_evasGlApi(0)
1473     , m_context(0)
1474     , m_surface(0)
1475     , m_config(0)
1476 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
1477     , m_angle(0)
1478 #endif
1479     , m_isAcceleratedCompositingModeInitialized(false)
1480 {
1481     initializeAcceleratedCompositingMode();
1482 }
1483
1484 PageClientEvasGL::~PageClientEvasGL()
1485 {
1486     if (m_viewImpl && m_viewImpl->page())
1487         m_viewImpl->page()->close();
1488 }
1489
1490 void PageClientEvasGL::updateViewportSize(const WebCore::IntSize& viewportSize, const int angle)
1491 {
1492     PageClientImpl::updateViewportSize(viewportSize, angle);
1493 }
1494
1495 void PageClientEvasGL::updateVisibleContentRectSize(const WebCore::IntSize& size)
1496 {
1497     if (m_surface) {
1498         evas_gl_surface_destroy(m_evasGL, m_surface);
1499         m_surface = 0;
1500     }
1501     setTargetSurface();
1502
1503     PageClientImpl::updateVisibleContentRectSize(size);
1504 }
1505
1506 void PageClientEvasGL::setViewNeedsDisplay(const WebCore::IntRect& rect)
1507 {
1508 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
1509     if (!isDirectRendering())
1510 #endif
1511     drawContents();
1512     m_viewImpl->redrawRegion(rect);
1513
1514 #if ENABLE(TIZEN_SCREEN_READER)
1515     if (rect.intersects(ewkViewGetFocusRing(m_viewImpl->view())->rect()))
1516         m_viewImpl->page()->recalcScreenReaderFocusRect();
1517 #endif
1518 }
1519
1520 void PageClientEvasGL::displayViewport()
1521 {
1522 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
1523     // We should not draw here when Direct Rendering is enabled.
1524     // Because we will draw directly when evas is updated - on_pixels_for_accelerated_compositing().
1525     if (isDirectRendering())
1526         ewk_view_mark_for_sync(m_viewImpl->view());
1527     else
1528 #endif
1529     setViewNeedsDisplay(IntRect(IntPoint(), viewSize()));
1530
1531 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
1532     updateScrollbar();
1533 #endif
1534
1535 #if ENABLE(TIZEN_SCREEN_READER)
1536     m_viewImpl->page()->recalcScreenReaderFocusRect();
1537 #endif
1538 }
1539
1540 void PageClientEvasGL::drawContents()
1541 {
1542     if (!drawingArea() || !(drawingArea()->layerTreeCoordinatorProxy()))
1543         return;
1544
1545     WebLayerTreeRenderer* renderer = drawingArea()->layerTreeCoordinatorProxy()->layerTreeRenderer();
1546     if (!renderer)
1547         return;
1548
1549     if (!makeContextCurrent())
1550         return;
1551
1552     WebCore::TransformationMatrix matrix;
1553     IntRect clipRect;
1554     IntSize ewkViewSize = viewSize();
1555
1556 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
1557     if (isDirectRendering()) {
1558         Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
1559         m_angle = ecore_evas_rotation_get(ee);
1560         renderer->setAngle(m_angle);
1561         matrix.rotate3d(0.0, 0.0, 1.0, 360 - m_angle);
1562
1563         if (m_angle == 90 || m_angle == 270) {
1564             glViewport(0, 0, ewkViewSize.height(), ewkViewSize.width());
1565             if (m_angle == 90)
1566                 matrix.translate(-ewkViewSize.width(), 0);
1567             else if (m_angle == 270)
1568                 matrix.translate(0, -ewkViewSize.height());
1569             clipRect = IntRect(IntPoint(), ewkViewSize.transposedSize());
1570         } else {
1571             glViewport(0, 0, ewkViewSize.width(), ewkViewSize.height());
1572             if (m_angle == 180)
1573                 matrix.translate(-ewkViewSize.width(), -ewkViewSize.height());
1574             clipRect = IntRect(IntPoint(), ewkViewSize);
1575         }
1576     } else
1577 #endif
1578     {
1579         glViewport(0, 0, ewkViewSize.width(), ewkViewSize.height());
1580         clipRect = IntRect(IntPoint(), ewkViewSize);
1581     }
1582
1583     matrix *= m_viewImpl->transformToView().toTransformationMatrix();
1584
1585 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
1586     if (m_shouldMakeBackupTexture) {
1587         glViewport(0, 0, m_initialViewRect.width(), m_initialViewRect.height());
1588         glClearColor(1, 1, 1, 1);
1589         glClear(GL_COLOR_BUFFER_BIT);
1590         renderer->paintToBackupTexture(matrix, 1.0f, m_initialViewRect, m_bgColor);
1591         m_shouldMakeBackupTexture = false;
1592     } else if (m_shouldShowBackupTexture) {
1593         matrix.makeIdentity();
1594         glViewport(0, 0, m_initialViewRect.width(), m_initialViewRect.height());
1595         renderer->showBackupTexture(matrix, 1.0f, m_initialViewRect);
1596     } else
1597 #endif
1598     renderer->paintToCurrentGLContext(matrix, 1.0f, clipRect, m_bgColor);
1599 }
1600
1601 void PageClientEvasGL::didRenderFrame()
1602 {
1603     ewkViewFrameRendered(m_viewImpl->view());
1604     PageClientImpl::didRenderFrame();
1605 }
1606
1607 bool PageClientEvasGL::makeContextCurrent()
1608 {
1609     return evas_gl_make_current(m_evasGL, m_surface, m_context);
1610 }
1611
1612 void PageClientEvasGL::initializeAcceleratedCompositingMode()
1613 {
1614     Evas* evas = evas_object_evas_get(m_viewImpl->view());
1615
1616     m_config = evas_gl_config_new();
1617 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
1618     char* directRenderingEnv = getenv("TIZEN_WEBKIT_DIRECT_RENDERING");
1619     if (!directRenderingEnv || atoi(directRenderingEnv)) {
1620         setenv("EVAS_GL_DIRECT_OVERRIDE", "1", 1);
1621         m_config->options_bits = EVAS_GL_OPTIONS_DIRECT;
1622     }
1623 #endif
1624     m_config->color_format = EVAS_GL_RGBA_8888;
1625     m_config->depth_bits = EVAS_GL_DEPTH_BIT_24;
1626     m_config->stencil_bits = EVAS_GL_STENCIL_BIT_8;
1627
1628     m_evasGL = evas_gl_new(evas);
1629     if (!m_evasGL) {
1630         evas_gl_config_free(m_config);
1631         m_config = 0;
1632         TIZEN_LOGE("failed to create evas_gl");
1633         return;
1634     }
1635
1636     Evas_GL_API* evasGlApi = evas_gl_api_get(m_evasGL);
1637     if (!evasGlApi) {
1638         evas_gl_free(m_evasGL);
1639         m_evasGL = 0;
1640         evas_gl_config_free(m_config);
1641         m_config = 0;
1642         TIZEN_LOGE("failed to get evas_gl_api");
1643         return;
1644     }
1645     WebCore::EvasGlApiInterface::shared().initialize(evasGlApi);
1646
1647     m_context = evas_gl_context_create(m_evasGL, 0);
1648     if (!m_context) {
1649         evas_gl_free(m_evasGL);
1650         m_evasGL = 0;
1651         evas_gl_config_free(m_config);
1652         m_config = 0;
1653         TIZEN_LOGE("failed to create evas_gl_context");
1654         return;
1655     }
1656
1657     setTargetSurface();
1658     m_isAcceleratedCompositingModeInitialized =  true;
1659 }
1660
1661 void PageClientEvasGL::finalizeAcceleratedCompositingMode()
1662 {
1663     if (m_evasGL) {
1664         if (m_surface) {
1665             evas_gl_surface_destroy(m_evasGL, m_surface);
1666             m_surface = 0;
1667         }
1668         if (m_context) {
1669             evas_gl_context_destroy(m_evasGL, m_context);
1670             m_context = 0;
1671         }
1672         if (m_config) {
1673             evas_gl_config_free(m_config);
1674             m_config = 0;
1675         }
1676         evas_gl_free(m_evasGL);
1677         m_evasGL = 0;
1678     }
1679
1680 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
1681     setenv("EVAS_GL_DIRECT_OVERRIDE", "0", 1);
1682 #endif
1683     m_isAcceleratedCompositingModeInitialized = false;
1684 }
1685
1686 void PageClientEvasGL::enterAcceleratedCompositingMode(const LayerTreeContext&)
1687 {
1688     if (!m_isAcceleratedCompositingModeInitialized)
1689         initializeAcceleratedCompositingMode();
1690 }
1691
1692 void PageClientEvasGL::exitAcceleratedCompositingMode()
1693 {
1694     if (m_isAcceleratedCompositingModeInitialized)
1695         finalizeAcceleratedCompositingMode();
1696 }
1697
1698 void PageClientEvasGL::setTargetSurface()
1699 {
1700     if (!m_evasGL)
1701         return;
1702
1703     int width, height;
1704     evas_object_geometry_get(m_viewImpl->view(), 0, 0, &width, &height);
1705     if (width == 0 || height == 0)
1706         return;
1707
1708     m_surface = evas_gl_surface_create(m_evasGL, m_config, width, height);
1709     if (!m_surface) {
1710         TIZEN_LOGE("failed to create Evas_GL_Surface");
1711         return;
1712     }
1713
1714 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
1715     if (isDirectRendering())
1716         makeContextCurrent();
1717     else
1718 #endif
1719     {
1720         if (makeContextCurrent()) {
1721             glViewport(0, 0, width, height);
1722             glClearColor(1.0, 1.0, 1.0, 1.0);
1723             glClear(GL_COLOR_BUFFER_BIT);
1724             glFinish();
1725         }
1726     }
1727
1728     Evas_Native_Surface nativeSurface;
1729     if (evas_gl_native_surface_get(m_evasGL, m_surface, &nativeSurface))
1730         ewk_view_image_native_surface_set(m_viewImpl->view(), &nativeSurface);
1731 }
1732 #endif
1733
1734 } // namespace WebKit