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