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