Fixed sometimes foucs ring disappear late and is not shown.
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / FocusRing.cpp
index 902cef0..fad2579 100755 (executable)
 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
 #include "PageClientImpl.h"
 
+#if ENABLE(TOUCH_ADJUSTMENT)
+#include <Elementary.h>
+#endif
+
 using namespace WebKit;
 using namespace WebCore;
 
-const int FocusRing::s_imageOuterWidth = 4;
-const int FocusRing::s_imageInnerWidth = 2;
-
 FocusRing::FocusRing(EwkViewImpl* viewImpl)
     : m_viewImpl(viewImpl)
     , m_focusRingObject(0)
-    , m_isImageDrawing(false)
+    , m_imageOuterWidth(0)
+    , m_imageInnerWidth(0)
     , m_showTimer(0)
+    , m_hideTimer(0)
 {
 }
 
@@ -43,6 +46,9 @@ FocusRing::~FocusRing()
     if (m_showTimer)
         ecore_timer_del(m_showTimer);
 
+    if (m_hideTimer)
+        ecore_timer_del(m_hideTimer);
+
     if (m_focusRingObject)
         evas_object_del(m_focusRingObject);
 }
@@ -53,12 +59,14 @@ Eina_Bool FocusRing::showTimerCallback(void* data)
     return ECORE_CALLBACK_CANCEL;
 }
 
-void FocusRing::setImageDrawing(bool isImageDrawing)
+void FocusRing::setImage(const String& path, int outerWidth, int innerWidth)
 {
-    if (m_isImageDrawing == isImageDrawing)
+    if (m_imagePath == path && m_imageOuterWidth == outerWidth && m_imageInnerWidth == innerWidth)
         return;
 
-    m_isImageDrawing = isImageDrawing;
+    m_imagePath = path;
+    m_imageOuterWidth = outerWidth;
+    m_imageInnerWidth = innerWidth;
 
     if (m_focusRingObject) {
         evas_object_del(m_focusRingObject);
@@ -66,11 +74,26 @@ void FocusRing::setImageDrawing(bool isImageDrawing)
     }
 }
 
-void FocusRing::requestToShow(const IntPoint& position)
+void FocusRing::requestToShow(const IntPoint& position, bool immediately)
 {
-    if (m_isImageDrawing)
+    if (!m_imagePath.isNull())
         return;
 
+    if (immediately) {
+        if (m_focusRingObject && evas_object_visible_get(m_focusRingObject))
+            return;
+        else {
+            if (m_showTimer) {
+                ecore_timer_del(m_showTimer);
+                m_showTimer = 0;
+            }
+
+            m_position = position;
+            show(IntRect());
+            return;
+        }
+    }
+
     m_position = position;
 
     if (m_showTimer)
@@ -80,8 +103,12 @@ void FocusRing::requestToShow(const IntPoint& position)
 
 void FocusRing::show(const IntRect& rect, const bool includeOnlyImage)
 {
-    if (rect.isEmpty())
-        m_showTimer = 0;
+    if (rect.isEmpty()) {
+        if (m_showTimer) {
+            ecore_timer_del(m_showTimer);
+            m_showTimer = 0;
+        }
+    }
 
     PageClientImpl* pageClientImpl = m_viewImpl->pageClient.get();
     EINA_SAFETY_ON_NULL_RETURN(pageClientImpl);
@@ -92,7 +119,18 @@ void FocusRing::show(const IntRect& rect, const bool includeOnlyImage)
     if (rect.isEmpty()) {
 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
         IntPoint contentsPosition = m_viewImpl->transformFromScene().mapPoint(m_position);
+#if ENABLE(TOUCH_ADJUSTMENT)
+        Evas_Coord size = elm_config_finger_size_get();
+        IntSize fingerSize = IntSize(size, size);
+#if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
+        double scaleFactor = pageClientImpl->scaleFactor();
+        if (scaleFactor - 1 > numeric_limits<float>::epsilon())
+            fingerSize.scale(1 / scaleFactor, 1 / scaleFactor);
+#endif
+        WebHitTestResult::Data hitTestResultData = m_viewImpl->page()->hitTestResultAtPoint(contentsPosition, WebHitTestResult::HitTestModeDefault, fingerSize);
+#else
         WebHitTestResult::Data hitTestResultData = m_viewImpl->page()->hitTestResultAtPoint(contentsPosition);
+#endif
         if (hitTestResultData.focusedRect.isEmpty())
             return;
 
@@ -123,12 +161,12 @@ void FocusRing::show(const IntRect& rect, const bool includeOnlyImage)
     if (m_focusRingObject)
         evas_object_hide(m_focusRingObject);
     else {
-        if (!m_isImageDrawing)
+        if (m_imagePath.isNull())
             m_focusRingObject = evas_object_rectangle_add(evas_object_evas_get(m_viewImpl->view()));
         else {
             m_focusRingObject = evas_object_image_add(evas_object_evas_get(m_viewImpl->view()));
-            evas_object_image_file_set(m_focusRingObject, SCREEN_READER_FOCUS_RING_IMAGE_PATH, 0);
-            int border = s_imageOuterWidth + s_imageInnerWidth;
+            evas_object_image_file_set(m_focusRingObject, m_imagePath.utf8().data(), 0);
+            int border = m_imageOuterWidth + m_imageInnerWidth;
             evas_object_image_border_set(m_focusRingObject, border, border, border, border);
         }
 
@@ -136,12 +174,12 @@ void FocusRing::show(const IntRect& rect, const bool includeOnlyImage)
         evas_object_repeat_events_set(m_focusRingObject, true);
     }
 
-    if (!m_isImageDrawing) {
+    if (m_imagePath.isNull()) {
         evas_object_color_set(m_focusRingObject, focusRingColor.red(), focusRingColor.green(), focusRingColor.blue(), focusRingColor.alpha());
         evas_object_move(m_focusRingObject, focusRingRect.x(), focusRingRect.y());
         evas_object_resize(m_focusRingObject, focusRingRect.width(), focusRingRect.height());
     } else {
-        viewRect.inflate(-s_imageOuterWidth);
+        viewRect.inflate(-m_imageOuterWidth);
 
         if (focusRingRect.intersects(viewRect))
             focusRingRect.intersect(viewRect);
@@ -162,10 +200,10 @@ void FocusRing::show(const IntRect& rect, const bool includeOnlyImage)
             }
         }
 
-        evas_object_move(m_focusRingObject, focusRingRect.x() - s_imageOuterWidth, focusRingRect.y() - s_imageOuterWidth);
+        evas_object_move(m_focusRingObject, focusRingRect.x() - m_imageOuterWidth, focusRingRect.y() - m_imageOuterWidth);
 
-        int width = focusRingRect.width() + s_imageOuterWidth * 2;
-        int height = focusRingRect.height() + s_imageOuterWidth * 2;
+        int width = focusRingRect.width() + m_imageOuterWidth * 2;
+        int height = focusRingRect.height() + m_imageOuterWidth * 2;
         evas_object_image_fill_set(m_focusRingObject, 0, 0, width, height);
         evas_object_resize(m_focusRingObject, width, height);
     }
@@ -173,9 +211,27 @@ void FocusRing::show(const IntRect& rect, const bool includeOnlyImage)
     evas_object_show(m_focusRingObject);
 }
 
+void FocusRing::requestToHide(bool immediately)
+{
+    if (immediately) {
+        hide();
+        return;
+    }
+
+    if (m_hideTimer)
+        ecore_timer_del(m_hideTimer);
+    m_hideTimer = ecore_timer_add((double)s_hideTimerTime/1000.0, hideTimerCallback, this);
+}
+
+Eina_Bool FocusRing::hideTimerCallback(void* data)
+{
+    static_cast<FocusRing*>(data)->hide();
+    return ECORE_CALLBACK_CANCEL;
+}
+
 void FocusRing::hide(bool onlyColorDrawing)
 {
-    if (m_isImageDrawing && onlyColorDrawing)
+    if (!m_imagePath.isNull() && onlyColorDrawing)
         return;
 
     if (m_showTimer) {
@@ -183,6 +239,11 @@ void FocusRing::hide(bool onlyColorDrawing)
         m_showTimer = 0;
     }
 
+    if (m_hideTimer) {
+        ecore_timer_del(m_hideTimer);
+        m_hideTimer = 0;
+    }
+
     if (m_focusRingObject && evas_object_visible_get(m_focusRingObject))
         evas_object_hide(m_focusRingObject);