_ScrollPanelPresenter::_ScrollPanelPresenter(void)
: __pScrollPanel(null)
, __pScrollPanelModel(null)
+ , __limitAnimationDistance(0.0f)
, __pPressedControl(null)
, __subControlMoved(false)
, __touchPressed(false)
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))
{
}
}
- ScrollTo(targetPosition, true);
+ FlickTo(targetPosition, gesture.GetDuration());
result r = GetLastResult();
SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
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;
}
{
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)
{
ScrollToControlWhenOutOfView(control);
}
+void
+_ScrollPanelPresenter::OnDescendantControlFocusMoved(const _Control& control)
+{
+ ScrollToControlWhenOutOfView(control);
+}
+
bool
_ScrollPanelPresenter::OnAccessibilityItemRefreshed(const _AccessibilityContainer& control, const _AccessibilityElement& element, _AccessibilityFocusDirection direction)
{
_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();
}
}
+ 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));
return false;
}
+
+float
+_ScrollPanelPresenter::FlickTo(float targetPosition, float duration)
+{
+ return ScrollTo(targetPosition, true);
+}
+
}}} // Tizen::Ui::Controls
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);
float GetHorizontalScrollPosition(void) const;
void SetHorizontalScrollPosition(float position);
+ float CalculatePagingScrollPosition(float position) const;
+
protected:
// Update Layout
virtual void UpdateLayout(void);
// 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);
float CalculateFlickAmount(float flickDistance, float flickDuration);
bool DoFlickGestureRecognized(_TouchFlickGestureDetector& gesture);
bool AccumulateFlickGesture(_FlickDirection direction);
+ float FlickTo(float targetPosition, float duration);
// Attribute
private:
_ScrollPanel* __pScrollPanel;
_ScrollPanelModel* __pScrollPanelModel;
+ float __limitAnimationDistance;
+
_Control* __pPressedControl;
bool __subControlMoved;
bool __touchPressed;