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