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