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