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