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