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