fix scroll bug on scrollable ui controls
[framework/osp/web.git] / src / controls / FWebCtrl_Web.cpp
index 04cf64e..7e6add7 100755 (executable)
@@ -730,86 +730,182 @@ _Web::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
 
 
 bool
-_Web::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
+_Web::CanOutOfEdgeLeft(float scrollDistanceX, int pageDistance)
 {
-       if (__pEflWebkit.get())
+       if (scrollDistanceX < 0.0f)
        {
-               if (__gestureType == WEB_GESTURE_TYPE_TAP)
-               {
-                       __pPanningGestureHandler->InitializeTextSelectionStatus();
-               }
+               __edgeType &= ~WEB_EDGE_RIGHT;
 
-               SendTouchEventForJavaScript(touchInfo);
+               return false;
+       }
+       else if (scrollDistanceX > 0.0f && pageDistance != 0)
+       {
+               __edgeType &= ~WEB_EDGE_LEFT;
+       }
 
-               __pGestureHandler->OnTouchMoved(source, touchInfo);
+       return true;
+}
+
+
+bool
+_Web::CanOutOfEdgeRight(float scrollDistanceX, int pageDistance)
+{
+       if (scrollDistanceX > 0.0f)
+       {
+               __edgeType &= ~WEB_EDGE_LEFT;
+
+               return false;
+       }
+       else if (scrollDistanceX < 0.0f &&  pageDistance != 0)
+       {
+               __edgeType &= ~WEB_EDGE_RIGHT;
+       }
+
+       return true;
+}
+
+
+bool
+_Web::CanOutOfEdgeTop(float scrollDistanceY, int pageDistance)
+{
+       if (scrollDistanceY < 0.0f)
+       {
+               __edgeType &= ~WEB_EDGE_BOTTOM;
+
+               return false;
+       }
+       else if (scrollDistanceY > 0.0f && pageDistance != 0)
+       {
+               __edgeType &= ~WEB_EDGE_TOP;
+       }
+
+       return true;
+}
 
-               float scrollDistanceX = __previousTouchedPosition.x - touchInfo.GetCurrentPosition().x;
-               float scrollDistanceY = __previousTouchedPosition.y - touchInfo.GetCurrentPosition().y;
-               __previousTouchedPosition = touchInfo.GetCurrentPosition();
 
-               if (__edgeType !=  WEB_EDGE_NONE && __gestureType == WEB_GESTURE_TYPE_PANNING)
+bool
+_Web::CanOutOfEdgeBottom(float scrollDistanceY, int pageDistance)
+{
+       if (scrollDistanceY > 0.0f)
+       {
+               __edgeType &= ~WEB_EDGE_TOP;
+
+               return false;
+       }
+       else if (scrollDistanceY < 0.0f && pageDistance != 0)
+       {
+               __edgeType &= ~WEB_EDGE_BOTTOM;
+       }
+
+       return true;
+}
+
+
+bool
+_Web::CanConsumeTouchMoved(float scrollDistanceX, float scrollDistanceY)
+{
+       if (__edgeType ==  WEB_EDGE_NONE)
+       {
+               return true;
+       }
+
+       bool ret = true;
+
+       int scrollWidth = 0;
+       int scrollHeight = 0;
+       ewk_view_scroll_size_get(GetWebNativeNode(), &scrollWidth, &scrollHeight);
+
+       int scrollX = 0;
+       int scrollY = 0;
+       ewk_view_scroll_pos_get(GetWebNativeNode(), &scrollX, &scrollY);
+
+       if (scrollWidth == 0)
+       {
+               if (__edgeType & WEB_EDGE_TOP)
                {
-                       if (_Abs(scrollDistanceY) < _Abs(scrollDistanceX))
+                       if (!CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
                        {
-                               if  (__edgeType & WEB_EDGE_LEFT)
-                               {
-                                       if (scrollDistanceX < 0)
-                                       {
-                                               __edgeType &= ~WEB_EDGE_RIGHT;
-
-                                               return false;
-                                       }
-                                       else
-                                       {
-                                               __edgeType &= ~WEB_EDGE_LEFT;
-                                       }
-                               }
-                               else if  (__edgeType & WEB_EDGE_RIGHT)
-                               {
-                                       if (scrollDistanceX > 0)
-                                       {
-                                               __edgeType &= ~WEB_EDGE_LEFT;
-
-                                               return false;
-                                       }
-                                       else
-                                       {
-                                               __edgeType &= ~WEB_EDGE_RIGHT;
-                                       }
-                               }
+                               return false;
                        }
-                       else if (_Abs(scrollDistanceY) > _Abs(scrollDistanceX))
+               }
+               else if (__edgeType & WEB_EDGE_BOTTOM)
+               {
+                       if (!CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
                        {
-                               if  (__edgeType & WEB_EDGE_TOP)
-                               {
-                                       if (scrollDistanceY < 0)
-                                       {
-                                               __edgeType &= ~WEB_EDGE_BOTTOM;
-
-                                               return false;
-                                       }
-                                       else
-                                       {
-                                               __edgeType &= ~WEB_EDGE_TOP;
-                                       }
-                               }
-                               else if  (__edgeType & WEB_EDGE_BOTTOM)
-                               {
-                                       if (scrollDistanceY > 0)
-                                       {
-                                               __edgeType &= ~WEB_EDGE_TOP;
-
-                                               return false;
-                                       }
-                                       else
-                                       {
-                                               __edgeType &= ~WEB_EDGE_BOTTOM;
-                                       }
-                               }
+                               return false;
                        }
                }
+       }
 
-               return true;
+       if (scrollHeight == 0)
+       {
+               if (__edgeType & WEB_EDGE_LEFT)
+               {
+                       if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0))
+                       {
+                               return false;
+                       }
+               }
+               else if  (__edgeType & WEB_EDGE_RIGHT)
+               {
+                       if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth))
+                       {
+                               return false;
+                       }
+               }
+       }
+
+       if (scrollWidth > 0 && scrollHeight > 0)
+       {
+               if  ((__edgeType & WEB_EDGE_LEFT) && (__edgeType & WEB_EDGE_TOP))
+               {
+                       if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0) || !CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
+                       {
+                               return false;
+                       }
+               }
+               else if  ((__edgeType & WEB_EDGE_LEFT) && (__edgeType & WEB_EDGE_BOTTOM))
+               {
+                       if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0) || !CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
+                       {
+                               return false;
+                       }
+               }
+               else if  ((__edgeType & WEB_EDGE_RIGHT) && (__edgeType & WEB_EDGE_TOP))
+               {
+                       if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth) || !CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
+                       {
+                               return false;
+                       }
+               }
+               else if  ((__edgeType & WEB_EDGE_RIGHT) && (__edgeType & WEB_EDGE_BOTTOM))
+               {
+                       if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth) || !CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
+                       {
+                               return false;
+                       }
+               }
+       }
+
+       return true;
+}
+
+
+bool
+_Web::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
+{
+       if (__pEflWebkit.get())
+       {
+               SendTouchEventForJavaScript(touchInfo);
+
+               float scrollDistanceX = __previousTouchedPosition.x - touchInfo.GetCurrentPosition().x;
+               float scrollDistanceY = __previousTouchedPosition.y - touchInfo.GetCurrentPosition().y;
+               __previousTouchedPosition = touchInfo.GetCurrentPosition();
+
+               if (CanConsumeTouchMoved(scrollDistanceX, scrollDistanceY))
+               {
+                       return __pGestureHandler->OnTouchMoved(source, touchInfo);
+               }
        }
 
        return false;
@@ -846,30 +942,6 @@ _Web::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
 }
 
 
-void
-_Web::OnTouchPressHandled(const _Control& control)
-{
-}
-
-
-void
-_Web::OnTouchReleaseHandled(const _Control& control)
-{
-}
-
-
-void
-_Web::OnTouchMoveHandled(const _Control& control)
-{
-}
-
-
-void
-_Web::OnTouchCancelHandled(const _Control& control)
-{
-}
-
-
 bool
 _Web::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
 {
@@ -878,14 +950,14 @@ _Web::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
                return __pTapGestureHandler->OnLongPressGestureDetected(gesture);
        }
 
-       return true;
+       return false;
 }
 
 
 bool
 _Web::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
 {
-       return true;
+       return false;
 }
 
 
@@ -897,33 +969,33 @@ _Web::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
                return __pTapGestureHandler->OnTapGestureDetected(gesture);
        }
 
-       return true;
+       return false;
 }
 
 
 bool
 _Web::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
 {
-       return true;
+       return false;
 }
 
 
 bool
 _Web::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
 {
-       if (__pEflWebkit.get() && _WebSettingImpl::GetInstance(__pWebSetting.get())->IsScrollEnabled())
+       if (__pEflWebkit.get())
        {
                return __pFlickGestureHandler->OnFlickGestureDetected(gesture);
        }
 
-       return true;
+       return false;
 }
 
 
 bool
 _Web::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
 {
-       return true;
+       return false;
 }
 
 
@@ -935,7 +1007,7 @@ _Web::OnPinchGestureStarted(Tizen::Ui::_TouchPinchGestureDetector& gesture)
                return __pPinchGestureHandler->OnPinchGestureStarted(gesture);
        }
 
-       return true;
+       return false;
 }
 
 
@@ -947,7 +1019,7 @@ _Web::OnPinchGestureChanged(Tizen::Ui::_TouchPinchGestureDetector& gesture)
                return __pPinchGestureHandler->OnPinchGestureChanged(gesture);
        }
 
-       return true;
+       return false;
 }
 
 
@@ -959,14 +1031,14 @@ _Web::OnPinchGestureFinished(Tizen::Ui::_TouchPinchGestureDetector& gesture)
                return __pPinchGestureHandler->OnPinchGestureFinished(gesture);
        }
 
-       return true;
+       return false;
 }
 
 
 bool
 _Web::OnPinchGestureCanceled(Tizen::Ui::_TouchPinchGestureDetector& gesture)
 {
-       return true;
+       return false;
 }