[WK2] call ewkViewFrameRendered after nonempty layout finished.
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / PageClientImpl.cpp
index e8d6199..8583168 100755 (executable)
@@ -89,17 +89,20 @@ PageClientImpl::PageClientImpl(EwkViewImpl* viewImpl)
     , m_viewportConstraints()
     , m_viewFocused(false)
     , m_viewWindowActive(true)
-    , m_pageDidRendered(false)
+    , m_pageDidRendered(true)
     , m_viewportAngle(0)
     , m_viewportFitsToContent(false)
 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
     , m_visibleContentRect(IntRect())
-    , m_scaleFactor(1.0f)
+    , m_scaleFactor(0)
     , m_hasSuspendedContent(false)
 #endif
 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
     , m_restoredScaleFactor(0)
 #endif
+#if ENABLE(TIZEN_WEBKIT2_BEFORE_PAGE_RENDERED_SCROLL_POSITION)
+    , m_scrollPositionBeforePageRendered(IntPoint())
+#endif
     , m_isVisible(true)
     , m_isScrollableLayerFocused(false)
     , m_isScrollableNodeFocused(false)
@@ -110,6 +113,13 @@ PageClientImpl::PageClientImpl(EwkViewImpl* viewImpl)
 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
     , m_isContextMenuVisible(false)
 #endif
+#if ENABLE(TIZEN_PRERENDERING_FOR_ROTATION)
+    , m_waitFrameOfNewViewortSize(false)
+#endif
+#if ENABLE(TIZEN_BACKGROUND_DISK_CACHE)
+    , m_isForeground(true)
+#endif
+    , m_nonemptyLayoutRendered(false)
 #endif // #if OS(TIZEN)
 {
 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING)
@@ -133,6 +143,8 @@ PageClientImpl::PageClientImpl(EwkViewImpl* viewImpl)
 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
     m_formDataCandidate = FormDataCandidate::create(m_viewImpl);
 #endif
+    Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
+    m_viewportAngle = ecore_evas_rotation_get(ee);
 #endif
 
     setBackgroundColor(1, 1, 1, 1);
@@ -140,7 +152,8 @@ PageClientImpl::PageClientImpl(EwkViewImpl* viewImpl)
 
 PageClientImpl::~PageClientImpl()
 {
-    m_viewImpl->page()->close();
+    if (m_viewImpl && m_viewImpl->page())
+        m_viewImpl->page()->close();
 }
 
 #if OS(TIZEN)
@@ -153,53 +166,56 @@ PageClientImpl::ViewportConstraints PageClientImpl::computeViewportConstraints(c
     constraints.layoutSize = attributes.layoutSize;
     constraints.contentsDefinedInitialScale = (ViewportArguments::ValueAuto != attributes.initialScale);
 
-    double defaultViewLevel = m_viewImpl->page()->pageGroup()->preferences()->defaultViewLevel();
-    // If defaultViewLevel is 1, "Default View" is set as "Readable"
-    // if not, "Default View" is set as "Fit to width"
-    if (defaultViewLevel) {
+    bool autoFittingEnabled = m_viewImpl->page()->pageGroup()->preferences()->autoFittingEnabled();
+    if (autoFittingEnabled)
+        constraints.initialScale = attributes.minimumScale * attributes.devicePixelRatio;
+    else {
         // if content doesn't set initial scale value, set readable scale factor
         // if not, set initial scale factor of viewport attribute
         if (attributes.initialScale == ViewportArguments::ValueAuto)
             constraints.initialScale = m_viewImpl->page()->deviceScaleFactor();
         else
             constraints.initialScale = attributes.initialScale * attributes.devicePixelRatio;
-    } else {
-        // Minimize initial scale factor
-        constraints.initialScale = attributes.minimumScale * attributes.devicePixelRatio;
     }
 
     // adjust scale with both minimum and maximum scale factor
-    constraints.initialScale = clampTo(constraints.initialScale, constraints.minimumScale, constraints.maximumScale);
+    constraints.initialScale = adjustScaleWithViewport(constraints.initialScale);
 
     return constraints;
 }
 
 double PageClientImpl::adjustScaleWithViewport(double scale)
 {
-    return clampTo(scale, m_viewportConstraints.minimumScale, m_viewportConstraints.maximumScale);
+    double minimumScale = min(m_viewportConstraints.minimumScale, m_viewportConstraints.maximumScale);
+    return clampTo(scale, minimumScale, m_viewportConstraints.maximumScale);
 }
 
 #if USE(TILED_BACKING_STORE) && ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
-void PageClientImpl::updateViewportSize(const IntSize& viewportSize)
+void PageClientImpl::updateViewportSize(const IntSize& viewportSize, const int angle)
 {
-    // update device width & height
-    int deviceWidth = WebCore::getDefaultScreenResolution().width();
-    int deviceHeight = WebCore::getDefaultScreenResolution().height();
-    Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
-    int angle = ecore_evas_rotation_get(ee);
-    if (angle == 90 || angle == 270) {
-        int tempWidth = deviceWidth;
-        deviceWidth = deviceHeight;
-        deviceHeight = tempWidth;
-    }
-    m_viewImpl->page()->pageGroup()->preferences()->setDeviceWidth(deviceWidth);
-    m_viewImpl->page()->pageGroup()->preferences()->setDeviceHeight(deviceHeight);
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI(" view size: [%d, %d], angle: [%d]", viewportSize.width(), viewportSize.height(), angle);
+#endif
 
     // update viewport size of webkit
-    m_visibleContentRect.setSize(viewportSize);
     m_viewImpl->page()->setViewportSize(viewportSize);
 }
+
+void PageClientImpl::updateVisibleContentRectSize(const IntSize& size)
+{
+    // update visible content rect's size
+    m_visibleContentRect.setSize(size);
+}
+#endif
+
+void PageClientImpl::prepareRestoredVisibleContectRect()
+{
+    m_restoredScaleFactor = scaleFactor();
+    m_restoredScrollPosition = scrollPosition();
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", m_restoredScrollPosition.x(), m_restoredScrollPosition.y(), m_restoredScaleFactor);
 #endif
+}
 
 void PageClientImpl::initializeVisibleContentRect()
 {
@@ -208,6 +224,10 @@ void PageClientImpl::initializeVisibleContentRect()
 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
     IntPoint initialScrollPosition;
     float initialScaleFactor = m_viewportConstraints.initialScale;
+#if ENABLE(TIZEN_WEBKIT2_BEFORE_PAGE_RENDERED_SCROLL_POSITION)
+    initialScrollPosition = m_scrollPositionBeforePageRendered;
+    m_scrollPositionBeforePageRendered = IntPoint();
+#endif
 #if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
     // if scroll position and scale factor are restored by history controller,
     // move scroll position and scale factor with them
@@ -215,6 +235,12 @@ void PageClientImpl::initializeVisibleContentRect()
         initialScrollPosition = m_restoredScrollPosition;
         initialScaleFactor = m_restoredScaleFactor;
     }
+#if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
+    m_restoredScaleFactor = 0;
+#endif
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", initialScrollPosition.x(), initialScrollPosition.y(), initialScaleFactor);
+#endif
 #endif
     setVisibleContentRect(IntRect(initialScrollPosition, m_visibleContentRect.size()), initialScaleFactor);
 #else
@@ -230,11 +256,19 @@ double PageClientImpl::availableMinimumScale()
     IntSize contentsSize = m_viewImpl->page()->contentsSize();
     double horizontalMinScale = max(((double)viewSize().width() / contentsSize.width()), 0.25);
     double verticalMinScale = max(((double)viewSize().height() / contentsSize.height()), 0.25);
-    return max(horizontalMinScale, verticalMinScale);
+    // If there's only a bit ignorable difference between horizontalMinScale and verticalMinScale,
+    // ignore verticalMinScale to fit content's width to view
+    const double ignorableThreshold = 0.01;
+    if (fabs(horizontalMinScale - verticalMinScale) < ignorableThreshold)
+        verticalMinScale = horizontalMinScale;
+    return min(max(horizontalMinScale, verticalMinScale), m_viewportConstraints.maximumScale);
 }
 
 void PageClientImpl::fitViewportToContent()
 {
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", m_visibleContentRect.x(), m_visibleContentRect.y(), m_viewportConstraints.minimumScale);
+#endif
     setVisibleContentRect(m_visibleContentRect, m_viewportConstraints.minimumScale);
 }
 
@@ -366,13 +400,31 @@ void PageClientImpl::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
 
 void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttributes& attributes)
 {
+    double scaleRatioBeforeRotation = m_scaleFactor / m_viewportConstraints.minimumScale;
     m_viewportConstraints = computeViewportConstraints(attributes);
 
+    // Initially, m_scaleFactor is not decided yet.
+    // So, we should update visible content rect at here.
+    if (!m_scaleFactor) {
+        setVisibleContentRect(m_visibleContentRect, m_viewportConstraints.initialScale);
+        return;
+    }
+
     // if content is reloaded, contents size will not be changed
     // so, we need to calculate minimum scale here.
     // if content size is changed later, minimum scale will be re-calculated on didChangeContentsSize()
-    if (m_viewportConstraints.userScalable)
+    if (m_viewportConstraints.userScalable) {
+        if (fabs(m_viewportConstraints.initialScale - m_viewportConstraints.minimumScale) < numeric_limits<float>::epsilon())
+            m_viewportConstraints.initialScale = availableMinimumScale();
         m_viewportConstraints.minimumScale = availableMinimumScale();
+    }
+
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI("layout size: [%d, %d], scale: [%.2f, %.2f, %.2f], user scalable: [%s]",
+        m_viewportConstraints.layoutSize.width(), m_viewportConstraints.layoutSize.height(),
+        m_viewportConstraints.initialScale, m_viewportConstraints.minimumScale, m_viewportConstraints.maximumScale,
+        m_viewportConstraints.userScalable ? "TRUE" : "FALSE");
+#endif
 
     // setVisibleContentRect() should be called to adjust visible content rect only when view is resized
     if (!m_pageDidRendered || m_viewImpl->page()->estimatedProgress() <= 0.1)
@@ -383,6 +435,7 @@ void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttribut
         return;
 
     float newScale = scaleFactor();
+    IntPoint newScrollPosition = m_visibleContentRect.location();
     Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
     int angle = ecore_evas_rotation_get(ee);
     bool isRotated = (angle != m_viewportAngle);
@@ -390,13 +443,22 @@ void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttribut
     // if it's rotated, we need to fit content to viewport by minimize the scale
     if (isRotated) {
         m_viewportAngle = angle;
-        if (m_viewportFitsToContent)
-            newScale = m_viewportConstraints.minimumScale;
+        newScale = m_viewportConstraints.minimumScale * scaleRatioBeforeRotation;
+        newScrollPosition.scale(newScale / m_scaleFactor, newScale / m_scaleFactor);
     }
+
+#if ENABLE(TIZEN_PRERENDERING_FOR_ROTATION)
+    if (m_waitFrameOfNewViewortSize)
+        ewk_view_resume(m_viewImpl->view());
+#endif
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f], rotated: [%s]", m_visibleContentRect.x(), m_visibleContentRect.y(), newScale, isRotated ? "Rotated" : "Not rotated");
+#endif
+
 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
-    setVisibleContentRect(m_visibleContentRect, newScale);
+    setVisibleContentRect(IntRect(newScrollPosition, m_visibleContentRect.size()), newScale);
 #else
-    m_viewImpl->page()->scalePage(newScale, m_visibleContentRect.location());
+    m_viewImpl->page()->scalePage(newScale, newScrollPosition);
 #endif
 
 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
@@ -404,6 +466,11 @@ void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttribut
     if (smartData->api->formdata_candidate_is_showing(smartData))
         smartData->api->formdata_candidate_hide(smartData);
 #endif
+
+#if ENABLE(TIZEN_FULLSCREEN_API)
+    if (m_viewImpl->page()->fullScreenManager()->isFullScreen())
+        m_viewImpl->page()->fullScreenManager()->updateMediaControlsStyle();
+#endif
 }
 
 #if OS(TIZEN)
@@ -601,6 +668,7 @@ void PageClientImpl::didChangeScrollbarsForMainFrame() const
 #if OS(TIZEN)
 void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame()
 {
+    m_nonemptyLayoutRendered = true;
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
     m_initialViewRect.setSize(viewSize());
 #endif
@@ -608,6 +676,9 @@ void PageClientImpl::didFirstVisuallyNonEmptyLayoutForMainFrame()
 
 void PageClientImpl::didChangeContentsSize(const WebCore::IntSize size)
 {
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI(" [%d, %d]", size.width(), size.height());
+#endif
 #if USE(TILED_BACKING_STORE)
     if (size.isEmpty())
         return;
@@ -637,9 +708,14 @@ void PageClientImpl::didChangeContentsSize(const WebCore::IntSize size)
     // FIXME: Do we really need to adjust visible content rect at here?
     // if contents size is changed smaller and visible content rect is outside of content area,
     // adjust visible content rect
-    IntRect adjustedVisibleContentRect = adjustVisibleContentRect(m_visibleContentRect, scaleFactor());
-    if (adjustedVisibleContentRect != m_visibleContentRect)
+    bool needScrollAdjustment = (adjustVisibleContentRect(m_visibleContentRect, scaleFactor()) != m_visibleContentRect);
+    bool needScaleAdjustment = (fabs(adjustScaleWithViewport(scaleFactor()) - scaleFactor()) > numeric_limits<float>::epsilon());
+    if (needScrollAdjustment || needScaleAdjustment) {
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+        TIZEN_LOGI(" setVisibleContentRect: [%d, %d], [%.2f]", m_visibleContentRect.x(), m_visibleContentRect.y(), scaleFactor());
+#endif
         setVisibleContentRect(m_visibleContentRect, scaleFactor());
+    }
 }
 
 void PageClientImpl::pageScaleFactorDidChange()
@@ -653,9 +729,7 @@ void PageClientImpl::didCommitLoadForMainFrame(bool)
 #if OS(TIZEN)
     m_pageDidRendered = false;
     m_viewportFitsToContent = false;
-#if ENABLE(TIZEN_WEBKIT2_HISTORICAL_RESTORE_VISIBLE_CONTENT_RECT)
-    m_restoredScaleFactor = 0;
-#endif
+    m_nonemptyLayoutRendered = false;
     return;
 #endif
     notImplemented();
@@ -694,13 +768,15 @@ void PageClientImpl::countStringMatchesInCustomRepresentation(const String&, Fin
 
 void PageClientImpl::updateTextInputState()
 {
-    InputMethodContextEfl* inputMethodContext = m_viewImpl->inputMethodContext();
-    if (inputMethodContext)
-        inputMethodContext->updateTextInputState();
-
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
     m_textSelection->update();
+    if (isTextSelectionMode() && isTextSelectionHandleDowned())
+        return;
 #endif
+
+    InputMethodContextEfl* inputMethodContext = m_viewImpl->inputMethodContext();
+    if (inputMethodContext)
+        inputMethodContext->updateTextInputState();
 }
 
 void PageClientImpl::handleDownloadRequest(DownloadProxy* download)
@@ -720,8 +796,15 @@ void PageClientImpl::pageDidRequestScroll(const IntPoint& point)
 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
     IntPoint newPoint = point;
     newPoint.scale(scaleFactor(), scaleFactor());
+#if ENABLE(TIZEN_WEBKIT2_BEFORE_PAGE_RENDERED_SCROLL_POSITION)
+    if (!m_pageDidRendered)
+        m_scrollPositionBeforePageRendered = newPoint;
+    else
+        setVisibleContentRect(IntRect(newPoint, m_visibleContentRect.size()), scaleFactor());
+#else
     setVisibleContentRect(IntRect(newPoint, m_visibleContentRect.size()), scaleFactor());
 #endif
+#endif
 }
 #endif
 
@@ -732,6 +815,9 @@ void PageClientImpl::pageDidRequestRestoreVisibleContentRect(const IntPoint& poi
     m_restoredScrollPosition = point;
     m_restoredScrollPosition.scale(scale, scale);
     m_restoredScaleFactor = scale;
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", m_restoredScrollPosition.x(), m_restoredScrollPosition.y(), m_restoredScaleFactor);
+#endif
 
     // Before contents size is fixed, just update visible content rect's position
     m_visibleContentRect.setLocation(m_restoredScrollPosition);
@@ -825,7 +911,7 @@ void PageClientImpl::setVisibleContentRect(const IntRect& newRect, float newScal
                                                       ceilf(m_visibleContentRect.height() / m_scaleFactor));
     if (!drawingArea())
         return;
-    drawingArea()->setVisibleContentsRect(mapToContentsVisibleContentRect, newScale, trajectory, FloatPoint(m_viewImpl->scrollPosition()));
+    drawingArea()->setVisibleContentsRect(mapToContentsVisibleContentRect, m_scaleFactor, trajectory, FloatPoint(m_viewImpl->scrollPosition()));
 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
     // FIXME: We need to calculate exact visibleRect size here instead of mapToContentsVisibleContentRect.
     drawingArea()->setVisibleContentsRectForScrollingContentsLayers(mapToContentsVisibleContentRect);
@@ -928,6 +1014,10 @@ void PageClientImpl::resumeContent()
     if (!m_hasSuspendedContent)
         return;
 
+#if ENABLE(TIZEN_DLOG_SUPPORT)
+    TIZEN_LOGI("scroll position: [%d, %d], scale factor: [%.2f]", m_viewImpl->scrollPosition().x(), m_viewImpl->scrollPosition().y(), m_viewImpl->scaleFactor());
+#endif
+
     // FIXME: Update visibleContentRect with m_viewImpl after resuming content.
     // The concept is that the values of EwkViewImpl and PageClient can be different
     // during suspending content and they become same when content is resumed.
@@ -1043,7 +1133,7 @@ bool PageClientImpl::textSelectionDown(const WebCore::IntPoint& point, bool isSt
 {
     if (!evas_object_focus_get(m_viewImpl->view())) {
         InputMethodContextEfl* inputMethodContext = m_viewImpl->inputMethodContext();
-        if (inputMethodContext && !inputMethodContext->isShow())
+        if (inputMethodContext)
             inputMethodContext->hideIMFContext();
 
         evas_object_focus_set(m_viewImpl->view(), true);
@@ -1084,12 +1174,20 @@ void PageClientImpl::textSelectonHandleUp()
 }
 #endif
 
-#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
 void PageClientImpl::requestToShowTextSelectionHandlesAndContextMenu()
 {
     m_textSelection->requestToShow();
 }
-#endif
+
+void PageClientImpl::initTextSelectionHandlesMouseDownedStatus()
+{
+    m_textSelection->initHandlesMouseDownedStatus();
+}
+
+void PageClientImpl::changeContextMenuPosition(IntPoint& point)
+{
+    m_textSelection->changeContextMenuPosition(point);
+}
 #endif
 
 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
@@ -1296,6 +1394,11 @@ void PageClientImpl::unlockOrientation()
 
 void PageClientImpl::didRenderFrame()
 {
+#if OS(TIZEN)
+    if (m_nonemptyLayoutRendered)
+        ewkViewFrameRendered(m_viewImpl->view());
+#endif
+
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
     if (m_shouldShowBackupTexture && m_isVisible)
         m_shouldShowBackupTexture = false;
@@ -1304,6 +1407,13 @@ void PageClientImpl::didRenderFrame()
         m_pageDidRendered = true;
         initializeVisibleContentRect();
     }
+
+#if ENABLE(TIZEN_PRERENDERING_FOR_ROTATION)
+    if (m_waitFrameOfNewViewortSize) {
+        m_waitFrameOfNewViewortSize = false;
+        ewkViewRotatePrepared(m_viewImpl->view());
+    }
+#endif
 }
 
 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
@@ -1338,47 +1448,6 @@ void PageClientImpl::findScrollableNode(const IntPoint& point)
 }
 #endif
 
-#if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
-void PageClientImpl::didGetTextStyleStateForSelection(int underlineState, int italicState, int boldState)
-{
-    WebCore::IntPoint startPoint, endPoint;
-    WebCore::IntRect leftRect, rightRect;
-
-    WebCore::IntRect caretRect;
-    m_viewImpl->page()->getCaretPosition(caretRect);
-    if (!caretRect.isEmpty()) {
-        startPoint.setX(caretRect.x());
-        startPoint.setY(caretRect.y() + caretRect.height());
-
-        endPoint.setX(caretRect.x() + caretRect.width());
-        endPoint.setY(caretRect.y() + caretRect.height());
-    }
-#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
-    else if (m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect)) {
-        startPoint.setX(leftRect.x());
-        startPoint.setY(leftRect.y() + leftRect.height());
-
-        endPoint.setX(rightRect.x() + rightRect.width());
-        endPoint.setY(rightRect.y() + rightRect.height());
-    }
-#endif
-
-    startPoint.scale(scaleFactor(), scaleFactor());
-    endPoint.scale(scaleFactor(), scaleFactor());
-
-    int viewPositionX, viewPositionY;
-    evas_object_geometry_get(m_viewImpl->view(), &viewPositionX, &viewPositionY, NULL, NULL);
-
-    startPoint.move(-scrollPosition().x(),  -scrollPosition().y());
-    startPoint.move(viewPositionX, viewPositionY);
-
-    endPoint.move(-scrollPosition().x(),  -scrollPosition().y());
-    endPoint.move(viewPositionX, viewPositionY);
-
-    ewkViewDidGetTextStyleStateForSelection(m_viewImpl->view(), underlineState, italicState, boldState, startPoint, endPoint);
-}
-#endif
-
 void PageClientImpl::didFindZoomableArea(const IntPoint& target, const IntRect& area)
 {
     ewk_view_zoomable_area_set(m_viewImpl->view(), target, area);
@@ -1418,10 +1487,16 @@ PageClientEvasGL::PageClientEvasGL(EwkViewImpl* viewImpl)
 
 PageClientEvasGL::~PageClientEvasGL()
 {
-    m_viewImpl->page()->close();
+    if (m_viewImpl && m_viewImpl->page())
+        m_viewImpl->page()->close();
+}
+
+void PageClientEvasGL::updateViewportSize(const WebCore::IntSize& viewportSize, const int angle)
+{
+    PageClientImpl::updateViewportSize(viewportSize, angle);
 }
 
-void PageClientEvasGL::updateViewportSize(const WebCore::IntSize& viewportSize)
+void PageClientEvasGL::updateVisibleContentRectSize(const WebCore::IntSize& size)
 {
     if (m_surface) {
         evas_gl_surface_destroy(m_evasGL, m_surface);
@@ -1429,14 +1504,15 @@ void PageClientEvasGL::updateViewportSize(const WebCore::IntSize& viewportSize)
     }
     setTargetSurface();
 
-    PageClientImpl::updateViewportSize(viewportSize);
+    PageClientImpl::updateVisibleContentRectSize(size);
 }
 
 void PageClientEvasGL::setViewNeedsDisplay(const WebCore::IntRect& rect)
 {
-#if !ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
-    drawContents();
+#if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
+    if (!isDirectRendering())
 #endif
+    drawContents();
     m_viewImpl->redrawRegion(rect);
 
 #if ENABLE(TIZEN_SCREEN_READER)
@@ -1450,10 +1526,11 @@ void PageClientEvasGL::displayViewport()
 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
     // We should not draw here when Direct Rendering is enabled.
     // Because we will draw directly when evas is updated - on_pixels_for_accelerated_compositing().
-    ewk_view_mark_for_sync(m_viewImpl->view());
-#else
-    setViewNeedsDisplay(IntRect(IntPoint(), viewSize()));
+    if (isDirectRendering())
+        ewk_view_mark_for_sync(m_viewImpl->view());
+    else
 #endif
+    setViewNeedsDisplay(IntRect(IntPoint(), viewSize()));
 
 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
     updateScrollbar();
@@ -1466,7 +1543,14 @@ void PageClientEvasGL::displayViewport()
 
 void PageClientEvasGL::drawContents()
 {
-    if (evas_gl_make_current(m_evasGL, m_surface, m_context) != EINA_TRUE)
+    if (!drawingArea() || !(drawingArea()->layerTreeCoordinatorProxy()))
+        return;
+
+    WebLayerTreeRenderer* renderer = drawingArea()->layerTreeCoordinatorProxy()->layerTreeRenderer();
+    if (!renderer)
+        return;
+
+    if (!makeContextCurrent())
         return;
 
     WebCore::TransformationMatrix matrix;
@@ -1474,55 +1558,52 @@ void PageClientEvasGL::drawContents()
     IntSize ewkViewSize = viewSize();
 
 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
-    Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
-    m_angle = ecore_evas_rotation_get(ee);
-    if (drawingArea())
-        drawingArea()->setAngle(m_angle);
-    matrix.rotate3d(0.0, 0.0, 1.0, 360 - m_angle);
-
-    if (m_angle == 90 || m_angle == 270) {
-        glViewport(0, 0, ewkViewSize.height(), ewkViewSize.width());
-        if (m_angle == 90)
-            matrix.translate(-ewkViewSize.width(), 0);
-        else if (m_angle == 270)
-            matrix.translate(0, -ewkViewSize.height());
-        clipRect = IntRect(IntPoint(), ewkViewSize.transposedSize());
-    } else {
+    if (isDirectRendering()) {
+        Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(m_viewImpl->view()));
+        m_angle = ecore_evas_rotation_get(ee);
+        renderer->setAngle(m_angle);
+        matrix.rotate3d(0.0, 0.0, 1.0, 360 - m_angle);
+
+        if (m_angle == 90 || m_angle == 270) {
+            glViewport(0, 0, ewkViewSize.height(), ewkViewSize.width());
+            if (m_angle == 90)
+                matrix.translate(-ewkViewSize.width(), 0);
+            else if (m_angle == 270)
+                matrix.translate(0, -ewkViewSize.height());
+            clipRect = IntRect(IntPoint(), ewkViewSize.transposedSize());
+        } else {
+            glViewport(0, 0, ewkViewSize.width(), ewkViewSize.height());
+            if (m_angle == 180)
+                matrix.translate(-ewkViewSize.width(), -ewkViewSize.height());
+            clipRect = IntRect(IntPoint(), ewkViewSize);
+        }
+    } else
+#endif
+    {
         glViewport(0, 0, ewkViewSize.width(), ewkViewSize.height());
-        if (m_angle == 180)
-            matrix.translate(-ewkViewSize.width(), -ewkViewSize.height());
         clipRect = IntRect(IntPoint(), ewkViewSize);
     }
-#else
-    glViewport(0, 0, ewkViewSize.width(), ewkViewSize.height());
-    clipRect = IntRect(IntPoint(), ewkViewSize);
-#endif
+
     matrix *= m_viewImpl->transformToView().toTransformationMatrix();
 
-    if (drawingArea()) {
-        if (drawingArea()->layerTreeCoordinatorProxy()) {
-            WebLayerTreeRenderer* renderer = drawingArea()->layerTreeCoordinatorProxy()->layerTreeRenderer();
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
-            if (m_shouldMakeBackupTexture) {
-                glViewport(0, 0, m_initialViewRect.width(), m_initialViewRect.height());
-                glClearColor(1, 1, 1, 1);
-                glClear(GL_COLOR_BUFFER_BIT);
-                renderer->paintToBackupTexture(matrix, 1.0f, m_initialViewRect, m_bgColor);
-                m_shouldMakeBackupTexture = false;
-            } else if (m_shouldShowBackupTexture) {
-                matrix.makeIdentity();
-                glViewport(0, 0, m_initialViewRect.width(), m_initialViewRect.height());
-                renderer->showBackupTexture(matrix, 1.0f, m_initialViewRect);
-            } else
-#endif
-            renderer->paintToCurrentGLContext(matrix, 1.0f, clipRect, m_bgColor);
-        }
-    }
+    if (m_shouldMakeBackupTexture) {
+        glViewport(0, 0, m_initialViewRect.width(), m_initialViewRect.height());
+        glClearColor(1, 1, 1, 1);
+        glClear(GL_COLOR_BUFFER_BIT);
+        renderer->paintToBackupTexture(matrix, 1.0f, m_initialViewRect, m_bgColor);
+        m_shouldMakeBackupTexture = false;
+    } else if (m_shouldShowBackupTexture) {
+        matrix.makeIdentity();
+        glViewport(0, 0, m_initialViewRect.width(), m_initialViewRect.height());
+        renderer->showBackupTexture(matrix, 1.0f, m_initialViewRect);
+    } else
+#endif
+    renderer->paintToCurrentGLContext(matrix, 1.0f, clipRect, m_bgColor);
 }
 
 void PageClientEvasGL::didRenderFrame()
 {
-    ewkViewFrameRendered(m_viewImpl->view());
     PageClientImpl::didRenderFrame();
 }
 
@@ -1537,8 +1618,11 @@ void PageClientEvasGL::initializeAcceleratedCompositingMode()
 
     m_config = evas_gl_config_new();
 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
-    setenv("EVAS_GL_DIRECT_OVERRIDE", "1", 1);
-    m_config->options_bits = EVAS_GL_OPTIONS_DIRECT;
+    char* directRenderingEnv = getenv("TIZEN_WEBKIT_DIRECT_RENDERING");
+    if (!directRenderingEnv || atoi(directRenderingEnv)) {
+        setenv("EVAS_GL_DIRECT_OVERRIDE", "1", 1);
+        m_config->options_bits = EVAS_GL_OPTIONS_DIRECT;
+    }
 #endif
     m_config->color_format = EVAS_GL_RGBA_8888;
     m_config->depth_bits = EVAS_GL_DEPTH_BIT_24;
@@ -1631,15 +1715,18 @@ void PageClientEvasGL::setTargetSurface()
     }
 
 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
-    makeContextCurrent();
-#else
-    if (makeContextCurrent()) {
-        glViewport(0, 0, width, height);
-        glClearColor(1.0, 1.0, 1.0, 1.0);
-        glClear(GL_COLOR_BUFFER_BIT);
-        glFinish();
-    }
+    if (isDirectRendering())
+        makeContextCurrent();
+    else
 #endif
+    {
+        if (makeContextCurrent()) {
+            glViewport(0, 0, width, height);
+            glClearColor(1.0, 1.0, 1.0, 1.0);
+            glClear(GL_COLOR_BUFFER_BIT);
+            glFinish();
+        }
+    }
 
     Evas_Native_Surface nativeSurface;
     if (evas_gl_native_surface_get(m_evasGL, m_surface, &nativeSurface))