Fixed sometimes foucs ring disappear late and is not shown.
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / FocusRing.cpp
index 826a80e..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;
 
@@ -33,6 +37,7 @@ FocusRing::FocusRing(EwkViewImpl* viewImpl)
     , m_imageOuterWidth(0)
     , m_imageInnerWidth(0)
     , m_showTimer(0)
+    , m_hideTimer(0)
 {
 }
 
@@ -41,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);
 }
@@ -66,11 +74,26 @@ void FocusRing::setImage(const String& path, int outerWidth, int innerWidth)
     }
 }
 
-void FocusRing::requestToShow(const IntPoint& position)
+void FocusRing::requestToShow(const IntPoint& position, bool immediately)
 {
     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;
 
@@ -173,6 +211,24 @@ 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_imagePath.isNull() && onlyColorDrawing)
@@ -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);