modified behavior of FocusUi on ScrollPanel
authorPark Kyoung Hee <kh1979.park@samsung.com>
Wed, 26 Jun 2013 08:07:40 +0000 (17:07 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Wed, 3 Jul 2013 07:44:26 +0000 (07:44 +0000)
- support to scroll for chidren of ScrollPanel's child control
modified ScrollToControl()
- when PageScroll is enabled ScrollPanel is scrolled to aligned position
modification for finxing issue N_SE-42436

Change-Id: Idd24a364300a83a725a62fb7e58999f49832ebe5
Signed-off-by: Park Kyoung Hee <kh1979.park@samsung.com>
src/ui/controls/FUiCtrl_ScrollPanel.cpp
src/ui/controls/FUiCtrl_ScrollPanelPresenter.cpp
src/ui/inc/FUiCtrl_ScrollPanel.h
src/ui/inc/FUiCtrl_ScrollPanelPresenter.h

index c15a86a..c5135a9 100644 (file)
@@ -447,9 +447,19 @@ _ScrollPanel::OnAccessibilityValueDecreased(const _AccessibilityContainer& contr
 void
 _ScrollPanel::OnChildControlFocusMoved(const _Control& control)
 {
+       ClearLastResult();
+
        __pScrollPanelPresenter->OnChildControlFocusMoved(control);
 }
 
+void
+_ScrollPanel::OnDescendantControlFocusMoved(const _Control& control)
+{
+       ClearLastResult();
+
+       __pScrollPanelPresenter->OnDescendantControlFocusMoved(control);
+}
+
 bool
 _ScrollPanel::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
 {
@@ -765,6 +775,14 @@ _ScrollPanel::SetHorizontalScrollPosition(float position)
        __pScrollPanelPresenter->SetHorizontalScrollPosition(position);
 }
 
+float
+_ScrollPanel::CalculatePagingScrollPosition(float position) const
+{
+       ClearLastResult();
+
+       return __pScrollPanelPresenter->CalculatePagingScrollPosition(position);
+}
+
 bool
 _ScrollPanel::ScrollToControl(const _Control& source, bool recursive)
 {
index 626c720..391e184 100644 (file)
@@ -60,6 +60,7 @@ namespace Tizen { namespace Ui { namespace Controls
 _ScrollPanelPresenter::_ScrollPanelPresenter(void)
        : __pScrollPanel(null)
        , __pScrollPanelModel(null)
+       , __limitAnimationDistance(0.0f)
        , __pPressedControl(null)
        , __subControlMoved(false)
        , __touchPressed(false)
@@ -493,41 +494,8 @@ _ScrollPanelPresenter::RunTouchReleased(const _Control& source, const _TouchInfo
 
        if (__pScrollPanel->IsPageScrollEnabled() && !__flickRunning && !__jumpToTopRunning)
        {
-               float currentPosition = 0.0f;
-               float maxPosition = 0.0f;
-               float pageSize = 0.0f;
-
-               if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
-               {
-                       pageSize = __pScrollPanel->GetPageScrollAlignSize().width;
-                       maxPosition = GetScrollAreaBounds().width - __pScrollPanel->GetBoundsF().width;
-                       currentPosition = GetHorizontalScrollPosition();
-               }
-               else
-               {
-                       pageSize = __pScrollPanel->GetPageScrollAlignSize().height;
-                       maxPosition = GetScrollAreaBounds().height - __pScrollPanel->GetBoundsF().height;
-                       currentPosition = GetVerticalScrollPosition();
-               }
-
-               float targetPosition = 0.0f;
-               int lowerPageIndex = currentPosition / pageSize;
-               float currentPageMin = pageSize * lowerPageIndex;
-               float pageGap = currentPosition - currentPageMin;
-               float currentPageMax = currentPageMin + pageSize;
-               if (currentPageMax > maxPosition)
-               {
-                       currentPageMax = maxPosition;
-               }
-
-               if (pageGap <= currentPageMax - currentPageMin - pageGap)
-               {
-                       targetPosition = currentPageMin;
-               }
-               else
-               {
-                       targetPosition = currentPageMax;
-               }
+               float currentPosition = GetScrollPosition();
+               float targetPosition = CalculatePagingScrollPosition(currentPosition);
 
                if (!_FloatCompare(targetPosition, currentPosition))
                {
@@ -1050,7 +1018,7 @@ _ScrollPanelPresenter::DoFlickGestureRecognized(_TouchFlickGestureDetector& gest
                                }
                        }
 
-                       ScrollTo(targetPosition, true);
+                       FlickTo(targetPosition, gesture.GetDuration());
                        result r = GetLastResult();
                        SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -1087,20 +1055,20 @@ _ScrollPanelPresenter::OnFlickGestureCanceled(_TouchFlickGestureDetector& gestur
 bool
 _ScrollPanelPresenter::IsControlOutOfView(const _Control& control) const
 {
-       FloatRectangle controlBounds = control.GetBoundsF();
-       float scrollPosition = __pScrollPanel->GetScrollPosition();
+       FloatRectangle controlBounds = control.GetAbsoluteBoundsF();
+       FloatRectangle scrollPanelBounds = __pScrollPanel->GetAbsoluteBoundsF();
 
        // is control out of view area
        if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
        {
-               if (controlBounds.x < scrollPosition || controlBounds.x + controlBounds.width > scrollPosition + __pScrollPanel->GetBoundsF().width)
+               if (controlBounds.x < scrollPanelBounds.x || controlBounds.x + controlBounds.width > scrollPanelBounds.x + scrollPanelBounds.width)
                {
                        return true;
                }
        }
        else
        {
-               if (controlBounds.y < scrollPosition || controlBounds.y + controlBounds.height > scrollPosition + __pScrollPanel->GetBoundsF().height)
+               if (controlBounds.y < scrollPanelBounds.y || controlBounds.y + controlBounds.height > scrollPanelBounds.y + scrollPanelBounds.height)
                {
                        return true;
                }
@@ -1114,12 +1082,51 @@ _ScrollPanelPresenter::ScrollToControlWhenOutOfView(const _Control& control)
 {
        if (IsControlOutOfView(control))
        {
-               ScrollToControl(control, false);
+               ScrollToControl(control, true);
                result r = GetLastResult();
                SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
        }
 }
 
+float
+_ScrollPanelPresenter::CalculatePagingScrollPosition(float position) const
+{
+       float maxPosition = 0.0f;
+       float pageSize = 0.0f;
+
+       if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
+       {
+               pageSize = __pScrollPanel->GetPageScrollAlignSize().width;
+               maxPosition = GetScrollAreaBounds().width - __pScrollPanel->GetBoundsF().width;
+       }
+       else
+       {
+               pageSize = __pScrollPanel->GetPageScrollAlignSize().height;
+               maxPosition = GetScrollAreaBounds().height - __pScrollPanel->GetBoundsF().height;
+       }
+
+       float targetPosition = 0.0f;
+       int lowerPageIndex = position / pageSize;
+       float currentPageMin = pageSize * lowerPageIndex;
+       float pageGap = position - currentPageMin;
+       float currentPageMax = currentPageMin + pageSize;
+       if (currentPageMax > maxPosition)
+       {
+               currentPageMax = maxPosition;
+       }
+
+       if (pageGap <= currentPageMax - currentPageMin - pageGap)
+       {
+               targetPosition = currentPageMin;
+       }
+       else
+       {
+               targetPosition = currentPageMax;
+       }
+
+       return targetPosition;
+}
+
 void
 _ScrollPanelPresenter::RollbackBouncing(bool withAnimation)
 {
@@ -1209,6 +1216,12 @@ _ScrollPanelPresenter::OnChildControlFocusMoved(const _Control& control)
        ScrollToControlWhenOutOfView(control);
 }
 
+void
+_ScrollPanelPresenter::OnDescendantControlFocusMoved(const _Control& control)
+{
+       ScrollToControlWhenOutOfView(control);
+}
+
 bool
 _ScrollPanelPresenter::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
 {
@@ -1464,10 +1477,40 @@ _ScrollPanelPresenter::ScrollToControl(const _Control& source, bool recursive)
                        _ScrollPanel* pScrollPanelParent = dynamic_cast<_ScrollPanel*> (pParent);
                        if (pScrollPanelParent != null)
                        {
-                               pScrollPanelParent->SetScrollPosition(controlPosition, false);
+                               FloatDimension pagingGap(0.0f, 0.0f);
+                               if (pScrollPanelParent->IsPageScrollEnabled())
+                               {
+                                       FloatPoint pagingPosition = controlPosition;
+                                       if (pScrollPanelParent->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
+                                       {
+                                               pagingPosition.x = pScrollPanelParent->CalculatePagingScrollPosition(controlPosition.x);
+                                               pagingGap.width = controlPosition.x - pagingPosition.x;
+                                               if (pagingGap.width < 0.0f)
+                                               {
+                                                       pagingPosition.x -= pScrollPanelParent->GetPageScrollAlignSize().width;
+                                                       pagingGap.width += pScrollPanelParent->GetPageScrollAlignSize().width;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               pagingPosition.y = pScrollPanelParent->CalculatePagingScrollPosition(controlPosition.y);
+                                               pagingGap.height = controlPosition.y - pagingPosition.y;
+                                               if (pagingGap.height < 0.0f)
+                                               {
+                                                       pagingPosition.y -= pScrollPanelParent->GetPageScrollAlignSize().height;
+                                                       pagingGap.height += pScrollPanelParent->GetPageScrollAlignSize().height;
+                                               }
+                                       }
 
-                               controlPosition.x -= pScrollPanelParent->GetHorizontalScrollPosition();
-                               controlPosition.y -= pScrollPanelParent->GetVerticalScrollPosition();
+                                       pScrollPanelParent->SetScrollPosition(pagingPosition, false);
+                               }
+                               else
+                               {
+                                       pScrollPanelParent->SetScrollPosition(controlPosition, false);
+                               }
+
+                               controlPosition.x -= pScrollPanelParent->GetHorizontalScrollPosition() + pagingGap.width;
+                               controlPosition.y -= pScrollPanelParent->GetVerticalScrollPosition() + pagingGap.height;
                        }
 
                        FloatPoint parentPosition = pParent->GetPositionF();
@@ -1478,6 +1521,34 @@ _ScrollPanelPresenter::ScrollToControl(const _Control& source, bool recursive)
                }
        }
 
+       if (__pScrollPanel->IsPageScrollEnabled())
+       {
+               FloatPoint pagingPosition = controlPosition;
+               if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
+               {
+                       pagingPosition.x  = CalculatePagingScrollPosition(controlPosition.x);
+                       if (pagingPosition.x > controlPosition.x)
+                       {
+                               controlPosition.x = pagingPosition.x - __pScrollPanel->GetPageScrollAlignSize().width;
+                       }
+                       else
+                       {
+                               controlPosition.x = pagingPosition.x;
+                       }
+               }
+               else
+               {
+                       pagingPosition.y  = CalculatePagingScrollPosition(controlPosition.y);
+                       if (pagingPosition.y > controlPosition.y)
+                       {
+                               controlPosition.y = pagingPosition.y - __pScrollPanel->GetPageScrollAlignSize().height;
+                       }
+                       else
+                       {
+                               controlPosition.y = pagingPosition.y;
+                       }
+               }
+       }
        SetScrollPosition(controlPosition, true);
        result r = GetLastResult();
        SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
@@ -1967,5 +2038,12 @@ _ScrollPanelPresenter::AccumulateFlickGesture(_FlickDirection direction)
        return false;
 }
 
+
+float
+_ScrollPanelPresenter::FlickTo(float targetPosition, float duration)
+{
+       return ScrollTo(targetPosition, true);
+}
+
 }}}    // Tizen::Ui::Controls
 
index 141202c..bd6a4a2 100644 (file)
@@ -131,7 +131,8 @@ public:
        virtual bool OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction);
 
        // Focus UI
-       void OnChildControlFocusMoved(const _Control& control);
+       virtual void OnChildControlFocusMoved(const _Control& control);
+       virtual void OnDescendantControlFocusMoved(const _Control& control);
 
        // scroll animation event listener
        virtual void OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target);
@@ -164,6 +165,8 @@ public:
        float GetHorizontalScrollPosition(void) const;
        void SetHorizontalScrollPosition(float position);
 
+       float CalculatePagingScrollPosition(float position) const;
+
        // scroll area type
        bool IsScrollAreaAutoResizingEnabled(void) const;
        void SetScrollAreaAutoResizingEnabled(bool autoResizingEnable);
index 8ac41ec..10ad22a 100644 (file)
@@ -96,8 +96,9 @@ public:
        virtual bool OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element);
        virtual bool OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction);
 
-   // Focus UI
+       // Focus UI
        virtual void OnChildControlFocusMoved(const _Control& control);
+       virtual void OnDescendantControlFocusMoved(const _Control& control);
 
        // scroll event listener
        virtual void OnScrollEndReached(_Control& source, ScrollEndEvent type);
@@ -147,6 +148,8 @@ public:
        float GetHorizontalScrollPosition(void) const;
        void SetHorizontalScrollPosition(float position);
 
+       float CalculatePagingScrollPosition(float position) const;
+
 protected:
        // Update Layout
        virtual void UpdateLayout(void);
@@ -163,8 +166,8 @@ protected:
 
        // Scroll operation
        virtual float ScrollToInternal(float targetPosition);
-       float ScrollTo(float distance);
-       float ScrollTo(float distance, bool withAnimation);
+       float ScrollTo(float targetPosition);
+       float ScrollTo(float targetPosition, bool withAnimation);
 
        // Scrollbar operations
        virtual void FadeOutScrollBar(void);
@@ -220,6 +223,7 @@ private:
        float CalculateFlickAmount(float flickDistance, float flickDuration);
        bool DoFlickGestureRecognized(_TouchFlickGestureDetector& gesture);
        bool AccumulateFlickGesture(_FlickDirection direction);
+       float FlickTo(float targetPosition, float duration);
 
 // Attribute
 private:
@@ -233,6 +237,8 @@ private:
        _ScrollPanel* __pScrollPanel;
        _ScrollPanelModel* __pScrollPanelModel;
 
+       float __limitAnimationDistance;
+
        _Control* __pPressedControl;
        bool __subControlMoved;
        bool __touchPressed;