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