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