2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_ScrollPanelPresenter.cpp
20 * @brief This is the implementation file for the %_ScrollPanelPresenter class.
25 #include <FBaseErrorDefine.h>
26 #include <FBaseRtTimer.h>
27 #include <FBaseUtilMath.h>
28 #include <FBaseSysLog.h>
29 #include <FGrpFloatMatrix4.h>
30 #include <FUiAnimVisualElementValueAnimation.h>
31 #include "FUi_ResourceManager.h"
32 #include "FUi_UiTouchEvent.h"
33 #include "FUi_IAccessibilityListener.h"
34 #include "FUi_AccessibilityContainer.h"
35 #include "FUi_AccessibilityElement.h"
36 #include "FUiAnim_VisualElement.h"
37 #include "FUiCtrl_Scroll.h"
38 #include "FUiCtrl_ScrollPanel.h"
39 #include "FUiCtrl_ScrollPanelImpl.h"
40 #include "FUiCtrl_ScrollPanelPresenter.h"
41 #include "FUiCtrl_ScrollPanelModel.h"
43 using namespace Tizen::Base;
44 using namespace Tizen::Graphics;
45 using namespace Tizen::Ui::Animations;
49 const int SCROLL_PANEL_SCROLLING_ANIMATION_DURATION = 1000;
50 const int SCROLL_PANEL_OVERSCROLLING_MAX_DISTANCCE = 100;
52 const int SCROLL_PANEL_FLICK_IN_PIXEL_UNIT = 1000;
53 const int SCROLL_PANEL_FLICK_WEIGHT_VELOCITY = 1;
54 const int SCROLL_PANEL_FLICK_WEIGHT_DISTANCE = 5;
55 const int SCROLL_PANEL_FLICK_ALPHA_PER_PIXEL = 3;
57 const int SCROLL_PANEL_SCROLL_BAR_LOAD_EFFECT_TIMER_DURATION = 1000;
58 const int SCROLL_PANEL_FLICK_SCROLL_EFFECT_TIMER_DURATION = 2000;
60 const String SCROLLING_ANIMATION_NAME(L"SCROLL_PANEL_SCROLLING_ANIMATION");
63 namespace Tizen { namespace Ui { namespace Controls
66 _ScrollPanelPresenter::_ScrollPanelPresenter(void)
67 : __pScrollPanel(null)
68 , __pScrollPanelModel(null)
69 , __pPressedControl(null)
70 , __subControlMoved(false)
71 , __touchPressed(false)
72 , __scrollOccured(false)
73 , __scrollAnimationRunning(false)
74 , __flickRunning(false)
75 , __pFlickScrollEffectTimer(null)
76 , __flickDirection(_FLICK_DIRECTION_NONE)
78 , __pScrollBarLoadEffectTimer(null)
79 , __scrollBarFirstLoaded(true)
81 , __firstTouchMove(true)
82 , __firstScrollMoveDirection(SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL)
87 _ScrollPanelPresenter::~_ScrollPanelPresenter(void)
89 delete __pScrollBarLoadEffectTimer;
90 __pScrollBarLoadEffectTimer = null;
92 delete __pFlickScrollEffectTimer;
93 __pFlickScrollEffectTimer = null;
95 delete __pScrollPanelModel;
96 __pScrollPanelModel = null;
100 _ScrollPanelPresenter::Initialize(_ScrollPanel& scrollPanel)
102 result r = _PanelPresenter::Initialize(scrollPanel);
103 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
105 __pScrollPanel = &scrollPanel;
108 _ScrollPanelModel* pModel = new (std::nothrow) _ScrollPanelModel;
109 SysTryReturn(NID_UI_CTRL, pModel != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] The memory is insufficient", GetErrorMessage(E_OUT_OF_MEMORY));
111 __pScrollPanelModel = pModel;
117 _ScrollPanelPresenter::Draw(void)
119 if (__pScrollPanel->GetBackgroundBitmap() == null)
124 Canvas* pCanvas = __pScrollPanel->GetVisualElement()->GetCanvasN();
125 result r = GetLastResult();
126 SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
127 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
129 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
131 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
133 r = pCanvas->Clear();
134 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
136 DrawBackgrounBitmap(pCanvas);
138 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
148 _ScrollPanelPresenter::OnBoundsChanging(const Tizen::Graphics::Rectangle& bounds)
150 ScrollPanelScrollDirection scrollDirection = __pScrollPanel->GetScrollDirection();
151 Rectangle scrollArea = GetScrollAreaBounds();
152 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
154 if (scrollArea.width < bounds.width)
156 scrollArea.width = bounds.width;
161 if (scrollArea.height < bounds.height)
163 scrollArea.height = bounds.height;
166 int scrollPosition = GetScrollPosition();
167 int fixedScrollPosition = FixScrollPositionIntoScrollAreaBounds(scrollPosition, bounds, scrollArea);
168 if (scrollPosition != fixedScrollPosition)
170 ScrollTo(fixedScrollPosition, false);
171 result r = GetLastResult();
172 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
179 _ScrollPanelPresenter::OnBoundsChanged(void)
185 _ScrollPanelPresenter::OnChildAttached(const _Control& child)
187 if (&child != __pScrollPanel->GetVerticalScrollBar()
188 && &child != __pScrollPanel->GetHorizontalScrollBar())
190 if (__pScrollPanel->IsScrollAreaAutoResizingEnabled())
197 _AccessibilityContainer* pChildAccessibilityContainer = (const_cast<_Control&>(child)).GetAccessibilityContainer();
198 pChildAccessibilityContainer->AddListener(*__pScrollPanel);
204 _ScrollPanelPresenter::OnChildDetached(const _Control& child)
206 if (&child != __pScrollPanel->GetVerticalScrollBar()
207 && &child != __pScrollPanel->GetHorizontalScrollBar())
209 if (__pScrollPanel->IsScrollAreaAutoResizingEnabled())
216 _AccessibilityContainer* pChildAccessibilityContainer = (const_cast<_Control&>(child)).GetAccessibilityContainer();
217 pChildAccessibilityContainer->RemoveListener(*__pScrollPanel);
223 _ScrollPanelPresenter::OnChildBoundsChanged(const _Control& child)
225 if (&child != __pScrollPanel->GetVerticalScrollBar()
226 && &child != __pScrollPanel->GetHorizontalScrollBar())
233 _ScrollPanelPresenter::SetScrollPosition(int position, bool withAnimation)
235 // change scroll position
239 result r = GetLastResult();
240 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
243 position = FixScrollPositionIntoScrollAreaBounds(position);
244 ScrollTo(position, withAnimation);
245 result r = GetLastResult();
246 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
250 _ScrollPanelPresenter::GetScrollPosition(void) const
252 int scrollPosition = GetScrollPositionInternal();
253 return FixScrollPositionIntoScrollAreaBounds(scrollPosition);
257 _ScrollPanelPresenter::GetVerticalScrollPosition(void) const
259 int scrollPosition = GetVerticalScrollPositionInternal();
260 return FixScrollPositionIntoScrollAreaBounds(scrollPosition);
264 _ScrollPanelPresenter::SetVerticalScrollPosition(int position)
266 SetScrollPosition(position, true);
270 _ScrollPanelPresenter::GetHorizontalScrollPosition(void) const
272 int scrollPosition = GetHorizontalScrollPositionInternal();
273 return FixScrollPositionIntoScrollAreaBounds(scrollPosition);
277 _ScrollPanelPresenter::SetHorizontalScrollPosition(int position)
279 SetScrollPosition(position, true);
283 _ScrollPanelPresenter::GetScrollPositionInternal(void) const
285 ScrollPanelScrollDirection scrollDirection = __pScrollPanel->GetScrollDirection();
287 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
289 return GetHorizontalScrollPositionInternal();
293 return GetVerticalScrollPositionInternal();
298 _ScrollPanelPresenter::SetScrollPositionInternal(int position)
300 ScrollPanelScrollDirection scrollDirection = __pScrollPanel->GetScrollDirection();
301 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
303 SetHorizontalScrollPositionInternal(position);
307 SetVerticalScrollPositionInternal(position);
312 _ScrollPanelPresenter::GetVerticalScrollPositionInternal(void) const
314 return __pScrollPanelModel->GetCurrentVerticalScrollPosition();
318 _ScrollPanelPresenter::SetVerticalScrollPositionInternal(int position)
320 __pScrollPanelModel->SetCurrentVerticalScrollPosition(position);
324 _ScrollPanelPresenter::GetHorizontalScrollPositionInternal(void) const
326 return __pScrollPanelModel->GetCurrentHorizontalScrollPosition();
330 _ScrollPanelPresenter::SetHorizontalScrollPositionInternal(int position)
332 __pScrollPanelModel->SetCurrentHorizontalScrollPosition(position);
336 _ScrollPanelPresenter::StopScrollingAnimation(void)
338 __scrollAnimationRunning = false;
339 __pScrollPanel->GetVisualElement()->RemoveAnimation(SCROLLING_ANIMATION_NAME);
343 _ScrollPanelPresenter::FixScrollPositionIntoScrollAreaBounds(int position) const
345 return FixScrollPositionIntoScrollAreaBounds(position, __pScrollPanel->GetBounds(), GetScrollAreaBounds());
349 _ScrollPanelPresenter::FixScrollPositionIntoScrollAreaBounds(int position, Rectangle bounds, Rectangle scrollArea) const
351 int minScrollPos = 0;
352 int maxScrollPos = 0;
353 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
355 minScrollPos = scrollArea.x;
356 maxScrollPos = scrollArea.x + scrollArea.width - bounds.width;
360 minScrollPos = scrollArea.y;
361 maxScrollPos = scrollArea.y + scrollArea.height - bounds.height;
363 position = position < minScrollPos ? minScrollPos : position;
364 position = position > maxScrollPos ? maxScrollPos : position;
370 _ScrollPanelPresenter::ScrollToTop(void)
372 SetVerticalScrollPosition(GetScrollAreaBounds().y);
376 _ScrollPanelPresenter::ScrollToBottom(void)
378 SetVerticalScrollPosition(GetScrollAreaBounds().height - __pScrollPanel->GetBounds().height);
382 _ScrollPanelPresenter::ScrollToLeft(void)
384 SetHorizontalScrollPosition(GetScrollAreaBounds().x);
388 _ScrollPanelPresenter::ScrollToRight(void)
390 SetHorizontalScrollPosition(GetScrollAreaBounds().width - __pScrollPanel->GetBounds().width);
394 _ScrollPanelPresenter::RunPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
396 result r = E_SUCCESS;
398 // stop flick, stop scroll animation
399 if (__flickRunning || __scrollAnimationRunning)
401 StopScrollingAnimation();
404 __currentMovedPosition = touchInfo.GetCurrentPosition();
405 __previousTouchedPosition = __currentMovedPosition;
406 __pPressedControl = &(const_cast<_Control&>(source));
407 __subControlMoved = false;
408 __touchPressed = true;
409 __firstTouchMove = true;
415 _ScrollPanelPresenter::RunPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
417 if (__pPressedControl == &source && __touchPressed)
419 __previousTouchedPosition = __currentMovedPosition;
420 __currentMovedPosition = touchInfo.GetCurrentPosition();
422 if (__pScrollPanel != &source)
424 __subControlMoved = true;
427 if (__firstTouchMove)
429 ScrollPanelScrollDirection scrollDirection = __pScrollPanel->GetScrollDirection();
430 int scrollDistanceX = __previousTouchedPosition.x - __currentMovedPosition.x;
431 int scrollDistanceY = __previousTouchedPosition.y - __currentMovedPosition.y;
433 if (abs(scrollDistanceY) < abs(scrollDistanceX))
435 __firstScrollMoveDirection = SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL;
437 else if (abs(scrollDistanceY) > abs(scrollDistanceX))
439 __firstScrollMoveDirection = SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL;
443 __firstScrollMoveDirection = scrollDirection;
446 __firstTouchMove = false;
454 _ScrollPanelPresenter::RunPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
456 result r = E_SUCCESS;
458 if (__pPressedControl != &source)
463 __touchPressed = false;
464 __firstTouchMove = true;
466 if (__pScrollPanel->IsPageScrollEnabled() && !__flickRunning)
468 int currentPosition = 0;
472 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
474 pageSize = __pScrollPanel->GetPageScrollAlignSize().width;
475 maxPosition = GetScrollAreaBounds().width - pageSize;
476 currentPosition = GetHorizontalScrollPosition();
480 pageSize = __pScrollPanel->GetPageScrollAlignSize().height;
481 maxPosition = GetScrollAreaBounds().height - pageSize;
482 currentPosition = GetVerticalScrollPosition();
485 int targetPosition = 0;
486 int pageGap = currentPosition % pageSize;
487 int lowerPageIndex = currentPosition / pageSize;
488 int currentPageMin = pageSize * lowerPageIndex;
489 int currentPageMax = currentPageMin + pageSize;
490 currentPageMin = currentPageMax > maxPosition ? (maxPosition / pageSize) * pageSize : currentPageMin;
491 currentPageMax = currentPageMax > maxPosition ? maxPosition : currentPageMax;
493 if (pageGap <= currentPageMax - currentPageMin - pageGap)
495 targetPosition = currentPageMin;
499 targetPosition = currentPageMax;
502 if (targetPosition != currentPosition)
504 SetScrollPosition(targetPosition, true);
506 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
510 // scrollpanel child control touch released
511 if (__pScrollPanel != &source)
513 // for ScrollPanelEventListener
514 if (__subControlMoved)
516 __pScrollPanel->FireScrollPanelEvent(source, CORE_OTHER_CONTROL_SELECTED);
520 __pPressedControl = null;
521 __subControlMoved = false;
523 if (!__scrollAnimationRunning)
525 RollbackBouncing(true);
527 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
531 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
535 __scrollOccured = false;
536 __pScrollPanel->FireOnScrollStoppedEvent();
544 _ScrollPanelPresenter::RunPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
546 result r = E_SUCCESS;
548 if (__pPressedControl != &source)
553 __touchPressed = false;
554 __firstTouchMove = true;
556 __pPressedControl = null;
557 __subControlMoved = false;
559 if (!__scrollAnimationRunning)
561 RollbackBouncing(true);
563 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
567 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
570 if (__scrollOccured && !__scrollAnimationRunning)
572 __scrollOccured = false;
573 __pScrollPanel->FireOnScrollStoppedEvent();
579 _UiTouchEventDelivery
580 _ScrollPanelPresenter::OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
582 result r = RunPreviewTouchPressed(source, touchInfo);
583 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, _UI_TOUCH_EVENT_DELIVERY_YES, r, "[%s] Propagating.", GetErrorMessage(r));
585 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
588 _UiTouchEventDelivery
589 _ScrollPanelPresenter::OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
591 RunPreviewTouchMoved(source, touchInfo);
593 return _UI_TOUCH_EVENT_DELIVERY_YES;
596 _UiTouchEventDelivery
597 _ScrollPanelPresenter::OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
599 result r = RunPreviewTouchReleased(source, touchInfo);
600 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, _UI_TOUCH_EVENT_DELIVERY_YES, r, "[%s] Propagating.", GetErrorMessage(r));
602 return _UI_TOUCH_EVENT_DELIVERY_FORCED_YES;
605 _UiTouchEventDelivery
606 _ScrollPanelPresenter::OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
608 result r = RunPreviewTouchCanceled(source, touchInfo);
609 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, _UI_TOUCH_EVENT_DELIVERY_YES, r, "[%s] Propagating.", GetErrorMessage(r));
611 return _UI_TOUCH_EVENT_DELIVERY_YES;
615 _ScrollPanelPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
617 if (__pScrollPanel != &source)
622 result r = RunPreviewTouchPressed(source, touchInfo);
623 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
629 _ScrollPanelPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
631 if (__pPressedControl != &source)
646 if (__currentMovedPosition != touchInfo.GetCurrentPosition())
648 RunPreviewTouchMoved(source, touchInfo);
651 // calculate move distance
652 ScrollPanelScrollDirection scrollDirection = __pScrollPanel->GetScrollDirection();
653 ScrollInputMode scrollInputMode = __pScrollPanel->GetScrollInputMode();
654 int scrollDistance = 0;
655 int scrollDistanceX = __previousTouchedPosition.x - __currentMovedPosition.x;
656 int scrollDistanceY = __previousTouchedPosition.y - __currentMovedPosition.y;
658 if (scrollInputMode == SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION)
660 if (scrollDirection == __firstScrollMoveDirection)
662 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
664 scrollDistance = scrollDistanceX;
666 else if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL)
668 scrollDistance = scrollDistanceY;
673 RollbackBouncing(true);
674 result r = GetLastResult();
675 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
679 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
681 if ((__firstScrollMoveDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL && abs(scrollDistanceY) > abs(scrollDistanceX))
682 || (__firstScrollMoveDirection == SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL && abs(scrollDistanceY) < abs(scrollDistanceX)))
694 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
696 if (abs(scrollDistanceY) <= abs(scrollDistanceX))
698 scrollDistance = scrollDistanceX;
705 else if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL)
707 if (abs(scrollDistanceY) >= abs(scrollDistanceX))
709 scrollDistance = scrollDistanceY;
718 if (scrollDistance != 0)
721 result r = GetLastResult();
722 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
724 int realMoveDistance = ScrollTo(scrollDistance + GetScrollPositionInternal());
726 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
728 if (realMoveDistance == 0)
730 // not moved and bubbling
731 if (scrollInputMode == SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION)
733 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
735 if (abs(scrollDistanceY) < abs(scrollDistanceX))
744 else if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL)
746 if (abs(scrollDistanceY) > abs(scrollDistanceX))
771 _ScrollPanelPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
773 if (__pPressedControl != &source)
778 if (__pScrollPanel != &source)
783 result r = RunPreviewTouchReleased(source, touchInfo);
784 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
790 _ScrollPanelPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
792 if (__pPressedControl != &source)
797 if (__pScrollPanel != &source)
802 result r = RunPreviewTouchCanceled(source, touchInfo);
803 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
809 _ScrollPanelPresenter::OnTouchMoveHandled(const _Control& control)
811 RollbackBouncing(true);
812 result r = GetLastResult();
813 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
817 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
821 _ScrollPanelPresenter::OnScrollEndReached(_Control& source, ScrollEndEvent type)
826 _ScrollPanelPresenter::OnScrollPositionChanged(_Control& source, int scrollPos)
828 if (&source != __pScrollPanel->GetScrollBar())
836 SetScrollPosition(scrollPos, true);
841 result r = GetLastResult();
842 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
844 SetScrollPosition(scrollPos, false);
849 _ScrollPanelPresenter::DoFlickGestureRecognized(_TouchFlickGestureDetector& gesture)
856 Rectangle scrollArea = GetScrollAreaBounds();
857 Rectangle scrollPanelBounds = __pScrollPanel->GetBounds();
861 gesture.GetDistance(distanceX, distanceY);
862 _FlickDirection moveDirection = gesture.GetDirection();
864 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
866 if (moveDirection != _FLICK_DIRECTION_RIGHT && moveDirection != _FLICK_DIRECTION_LEFT)
873 moveDirection = _FLICK_DIRECTION_LEFT;
875 else if (distanceX > 0)
877 moveDirection = _FLICK_DIRECTION_RIGHT;
882 if (moveDirection != _FLICK_DIRECTION_DOWN && moveDirection != _FLICK_DIRECTION_UP)
889 moveDirection = _FLICK_DIRECTION_UP;
891 else if (distanceY > 0)
893 moveDirection = _FLICK_DIRECTION_DOWN;
897 if (__pScrollPanel->IsPageScrollEnabled() && __pScrollPanel->IsPageScrollFlickMoveLimitedOnePage())
899 int targetPosition = 0;
900 int currentScrollPosition = GetScrollPosition();
902 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
904 int pageSize = __pScrollPanel->GetPageScrollAlignSize().width;
909 targetPosition = currentScrollPosition - (currentScrollPosition % pageSize) + pageSize;
912 else if (distanceX > 0)
914 targetPosition = currentScrollPosition - (currentScrollPosition % pageSize);
919 int pageSize = __pScrollPanel->GetPageScrollAlignSize().height;
924 targetPosition = currentScrollPosition - (currentScrollPosition % pageSize) + pageSize;
927 else if (distanceX > 0)
929 targetPosition = currentScrollPosition - (currentScrollPosition % pageSize);
933 targetPosition = FixScrollPositionIntoScrollAreaBounds(targetPosition);
934 if (targetPosition == currentScrollPosition)
939 __flickRunning = true;
941 ScrollTo(targetPosition, true);
942 result r = GetLastResult();
943 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
947 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
956 // calculate flick amount
957 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
959 flickAmount = CalculateFlickAmount(distanceX, gesture.GetDuration());
963 flickAmount = CalculateFlickAmount(distanceY, gesture.GetDuration());
966 moveAmount = -flickAmount;
969 if (__pScrollPanel->IsPageScrollEnabled())
971 int scrollPosition = 0;
975 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
977 pageSize = __pScrollPanel->GetPageScrollAlignSize().width;
978 maxPosition = scrollArea.width - pageSize;
979 scrollPosition = __pScrollPanelModel->GetCurrentHorizontalScrollPosition();
983 pageSize = __pScrollPanel->GetPageScrollAlignSize().height;
984 maxPosition = scrollArea.height - pageSize;
985 scrollPosition = __pScrollPanelModel->GetCurrentVerticalScrollPosition();
988 int pageGap = (scrollPosition + moveAmount) % pageSize;
989 int lowerPageIndex = (scrollPosition + moveAmount) / pageSize;
990 int targetPageMin = pageSize * lowerPageIndex;
991 int targetPageMax = targetPageMin + pageSize;
992 targetPageMin = targetPageMax > maxPosition ? (maxPosition / pageSize) * pageSize : targetPageMin;
993 targetPageMax = targetPageMax > maxPosition ? maxPosition : targetPageMax;
995 if (pageGap <= targetPageMax - targetPageMin - pageGap)
997 moveAmount = targetPageMin - scrollPosition;
1001 moveAmount = targetPageMax - scrollPosition;
1005 if (moveAmount != 0)
1007 // scroll with animation
1008 __flickRunning = true;
1011 if (__flickCount >= 3)
1013 // flick finger gesture
1014 if (__flickDirection != moveDirection)
1016 StopFlickScrollEffectTimer();
1021 switch (__flickDirection)
1023 case _FLICK_DIRECTION_UP:
1026 case _FLICK_DIRECTION_DOWN:
1029 case _FLICK_DIRECTION_LEFT:
1032 case _FLICK_DIRECTION_RIGHT:
1044 if (__flickCount == 1)
1046 __flickDirection = moveDirection;
1047 StartFlickScrollEffectTimer();
1051 if (__flickDirection != moveDirection)
1053 StopFlickScrollEffectTimer();
1056 __flickDirection = moveDirection;
1057 StartFlickScrollEffectTimer();
1061 // limited flick amount
1062 int targetPosition = moveAmount + GetScrollPositionInternal();
1063 int scrollToPosition = FixScrollPositionIntoScrollAreaBounds(targetPosition);
1064 if (abs(scrollToPosition - targetPosition) > SCROLL_PANEL_OVERSCROLLING_MAX_DISTANCCE)
1066 switch (moveDirection)
1068 case _FLICK_DIRECTION_UP:
1069 targetPosition = scrollArea.height - scrollPanelBounds.height + SCROLL_PANEL_OVERSCROLLING_MAX_DISTANCCE;
1071 case _FLICK_DIRECTION_DOWN:
1072 targetPosition = scrollArea.y - SCROLL_PANEL_OVERSCROLLING_MAX_DISTANCCE;
1074 case _FLICK_DIRECTION_LEFT:
1075 targetPosition = scrollArea.width - scrollPanelBounds.width + SCROLL_PANEL_OVERSCROLLING_MAX_DISTANCCE;
1077 case _FLICK_DIRECTION_RIGHT:
1078 targetPosition = scrollArea.x - SCROLL_PANEL_OVERSCROLLING_MAX_DISTANCCE;
1085 ScrollTo(targetPosition, true);
1086 result r = GetLastResult();
1087 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1090 r = GetLastResult();
1091 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1097 StopFlickScrollEffectTimer();
1105 _ScrollPanelPresenter::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1107 return DoFlickGestureRecognized(gesture);
1111 _ScrollPanelPresenter::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
1113 StopScrollingAnimation();
1114 RollbackBouncing(true);
1120 _ScrollPanelPresenter::IsControlOutOfView(const _Control& control) const
1122 Rectangle controlBounds = control.GetBounds();
1123 int scrollPos = __pScrollPanel->GetScrollPosition();
1125 // is control out of view area
1126 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1128 if (controlBounds.x < scrollPos || controlBounds.x + controlBounds.width > scrollPos + __pScrollPanel->GetBounds().width)
1135 if (controlBounds.y < scrollPos || controlBounds.y + controlBounds.height > scrollPos + __pScrollPanel->GetBounds().height)
1145 _ScrollPanelPresenter::ScrollToControlWhenOutOfView(const _Control& control)
1147 if (IsControlOutOfView(control))
1149 ScrollToControl(const_cast<const _Control&>(control));
1150 result r = GetLastResult();
1151 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1156 _ScrollPanelPresenter::RollbackBouncing(bool withAnimation)
1158 if (!IsScrollable())
1163 int scrollPosition = GetScrollPositionInternal();
1164 int fixedScrollPosition = FixScrollPositionIntoScrollAreaBounds(scrollPosition);
1165 if (scrollPosition != fixedScrollPosition)
1168 result r = GetLastResult();
1169 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1171 ScrollTo(fixedScrollPosition, withAnimation);
1172 r = GetLastResult();
1173 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1178 _ScrollPanelPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1180 const _Control& controlObj = control.GetOwner();
1181 ScrollToControlWhenOutOfView(controlObj);
1182 result r = GetLastResult();
1183 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1189 _ScrollPanelPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1191 const _Control& controlObj = control.GetOwner();
1192 ScrollToControlWhenOutOfView(controlObj);
1193 result r = GetLastResult();
1194 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1200 _ScrollPanelPresenter::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1206 _ScrollPanelPresenter::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1212 _ScrollPanelPresenter::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1218 _ScrollPanelPresenter::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1224 _ScrollPanelPresenter::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
1226 if (&timer == __pScrollBarLoadEffectTimer)
1228 __scrollBarFirstLoaded = false;
1230 StopScrollBarLoadEffectTimer();
1233 result r = GetLastResult();
1234 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1236 else if (&timer == __pFlickScrollEffectTimer)
1238 StopFlickScrollEffectTimer();
1243 _ScrollPanelPresenter::CalculateFlickAmount(int flickDistance, int flickDuration)
1245 int flickAmount = ((((flickDistance * SCROLL_PANEL_FLICK_IN_PIXEL_UNIT) / flickDuration) * SCROLL_PANEL_FLICK_WEIGHT_VELOCITY) + (flickDistance * SCROLL_PANEL_FLICK_WEIGHT_DISTANCE)) / SCROLL_PANEL_FLICK_ALPHA_PER_PIXEL;
1251 _ScrollPanelPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
1257 _ScrollPanelPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
1263 _ScrollPanelPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
1265 __scrollAnimationRunning = false;
1266 __flickRunning = false;
1268 if (__scrollOccured)
1270 __scrollOccured = false;
1271 __pScrollPanel->FireOnScrollStoppedEvent();
1274 if (completedNormally)
1276 RollbackBouncing(true);
1277 result r = GetLastResult();
1278 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1282 int scrollPosition = GetScrollPositionInternal();
1283 int targetPosition = GetScrollPosition();
1284 if (scrollPosition != targetPosition)
1286 ChangeScrollBarPosition(targetPosition);
1287 SetScrollPositionInternal(targetPosition);
1292 result r = GetLastResult();
1293 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1297 _ScrollPanelPresenter::OnTickOccurred(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, const Variant& currentValue)
1299 _VisualElement* pVisualElement = __pScrollPanel->GetVisualElement();
1301 if (&target != pVisualElement)
1306 if (keyName == SCROLLING_ANIMATION_NAME)
1308 if (!__scrollAnimationRunning)
1313 ScrollToInternal(currentValue.ToInt());
1318 _ScrollPanelPresenter::UpdateLayout(void)
1320 __pScrollPanel->PartialUpdateLayout();
1324 _ScrollPanelPresenter::AdjustModel()
1326 _Scroll* pHorizontalScrollBar = __pScrollPanel->GetHorizontalScrollBar();
1327 _Scroll* pVerticalScrollBar = __pScrollPanel->GetVerticalScrollBar();
1329 Rectangle scrollPanelBounds = __pScrollPanel->GetBounds();
1330 ScrollPanelScrollDirection scrollDirection = __pScrollPanel->GetScrollDirection();
1333 Rectangle scrollArea = Rectangle(0, 0, scrollPanelBounds.width, scrollPanelBounds.height);
1335 if (__pScrollPanel->IsScrollAreaAutoResizingEnabled())
1337 int count = __pScrollPanel->GetChildCount();
1339 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL)
1341 for (int i = 0; i < count; i++)
1343 _Control* pControl = __pScrollPanel->GetChild(i);
1344 SysTryReturnVoidResult(NID_UI_CTRL, pControl != null, E_SYSTEM, "[%s] pControl(child) is invalid pointer.", GetErrorMessage(E_SYSTEM));
1346 if (pControl == pVerticalScrollBar || pControl == pHorizontalScrollBar)
1351 int targetMaxPos = pControl->GetBounds().GetBottomRight().y;
1352 scrollArea.height = (scrollArea.height < targetMaxPos) ? targetMaxPos : scrollArea.height;
1355 else if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1357 for (int i = 0; i < count; i++)
1359 _Control* pControl = __pScrollPanel->GetChild(i);
1360 SysTryReturnVoidResult(NID_UI_CTRL, pControl != null, E_SYSTEM, "[%s] pControl(child) is invalid pointer.", GetErrorMessage(E_SYSTEM));
1362 if (pControl == pVerticalScrollBar || pControl == pHorizontalScrollBar)
1367 int targetMaxPos = pControl->GetBounds().GetBottomRight().x;
1368 scrollArea.width = (scrollArea.width < targetMaxPos) ? targetMaxPos : scrollArea.width;
1374 scrollArea = GetScrollAreaBounds();
1375 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1377 scrollArea.width = scrollArea.width < scrollPanelBounds.width ? scrollPanelBounds.width : scrollArea.width;
1378 scrollArea.height = scrollPanelBounds.height;
1382 scrollArea.width = scrollPanelBounds.width;
1383 scrollArea.height = scrollArea.height < scrollPanelBounds.height ? scrollPanelBounds.height : scrollArea.height;
1387 // before change model ScrollPosition fix
1388 int scrollPosition = GetScrollPosition();
1389 int fixedScrollPosition = FixScrollPositionIntoScrollAreaBounds(scrollPosition, scrollPanelBounds, scrollArea);
1390 if (scrollPosition != fixedScrollPosition)
1392 ScrollTo(fixedScrollPosition, false);
1393 result r = GetLastResult();
1394 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1397 // change model values
1398 SetScrollAreaBoundsInternal(scrollArea);
1399 Dimension alignSize = Dimension(scrollPanelBounds.width, scrollPanelBounds.height);
1400 __pScrollPanel->SetPageScrollAlignSize(alignSize);
1403 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1405 if (scrollPanelBounds.width > 0 && scrollArea.width > scrollPanelBounds.width)
1407 if (pHorizontalScrollBar != null)
1409 pHorizontalScrollBar->OnParentBoundsChanged();
1411 // update scrollbar range
1412 ChangeScrollBarRange();
1413 result r = GetLastResult();
1414 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1419 SetScrollPosition(scrollArea.x, false);
1420 result r = GetLastResult();
1421 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1426 if (scrollPanelBounds.height > 0 && scrollArea.height > scrollPanelBounds.height)
1428 if (pVerticalScrollBar != null)
1430 pVerticalScrollBar->OnParentBoundsChanged();
1432 // update scrollbar range
1433 ChangeScrollBarRange();
1434 result r = GetLastResult();
1435 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1440 SetScrollPosition(scrollArea.y, false);
1441 result r = GetLastResult();
1442 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1446 if (!__scrollAnimationRunning)
1449 result r = GetLastResult();
1450 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1455 _ScrollPanelPresenter::ScrollToControl(const _Control& source)
1457 if (__pScrollPanel->GetChildCount() == 0)
1459 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[%s] ScrollPanel have no child control.", GetErrorMessage(E_INVALID_ARG));
1463 int validNum = __pScrollPanel->GetChildIndex(source);
1467 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[%s] source is not a child control.", GetErrorMessage(E_INVALID_ARG));
1471 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1473 //align source control to left position.
1474 SetHorizontalScrollPosition(source.GetBounds().x);
1475 result r = GetLastResult();
1476 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1480 //align source control to top position.
1481 SetVerticalScrollPosition(source.GetBounds().y);
1482 result r = GetLastResult();
1483 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1490 _ScrollPanelPresenter::ScrollTo(int targetPosition)
1492 return ScrollTo(targetPosition, false);
1497 _ScrollPanelPresenter::ScrollTo(int targetPosition, bool withAnimation)
1499 StopScrollingAnimation();
1503 // Calculate real move distance
1504 int scrollToPosition = FixScrollPositionIntoScrollAreaBounds(targetPosition);
1506 int oldPosition = GetScrollPositionInternal();
1507 VisualElementValueAnimation* pScrollingAnimation = __pScrollPanel->GetScrollingAnimation();
1508 pScrollingAnimation->SetStartValue(Variant(oldPosition));
1509 pScrollingAnimation->SetEndValue(Variant(targetPosition));
1510 pScrollingAnimation->SetDuration(SCROLL_PANEL_SCROLLING_ANIMATION_DURATION);
1511 _VisualElement* pVisualElement = __pScrollPanel->GetVisualElement();
1512 __scrollAnimationRunning = true;
1513 pVisualElement->AddAnimation(SCROLLING_ANIMATION_NAME, *pScrollingAnimation);
1515 return scrollToPosition - oldPosition;
1519 return ScrollToInternal(targetPosition);
1525 _ScrollPanelPresenter::ScrollToInternal(int targetPosition)
1527 ScrollPanelScrollDirection scrollDirection = __pScrollPanel->GetScrollDirection();
1528 _VisualElement* pVisualElement = __pScrollPanel->GetVisualElement();
1529 int previousScrollPosition = GetScrollPositionInternal();
1531 FloatPoint floatPointDistance;
1533 int scrollToPosition = FixScrollPositionIntoScrollAreaBounds(targetPosition);
1535 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1537 distance = scrollToPosition - FixScrollPositionIntoScrollAreaBounds(previousScrollPosition);
1538 floatPointDistance.SetPosition(-distance, 0.0f);
1542 distance = scrollToPosition - FixScrollPositionIntoScrollAreaBounds(previousScrollPosition);
1543 floatPointDistance.SetPosition(0.0f, -distance);
1548 result r = pVisualElement->ScrollByPoint(floatPointDistance, false);
1549 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, 0, r, "[%s] Propagating.", GetErrorMessage(r));
1551 __scrollOccured = true;
1554 ChangeScrollBarPosition(targetPosition);
1555 SetScrollPositionInternal(targetPosition);
1559 Rectangle scrollPanelBounds = __pScrollPanel->GetBounds();
1560 Rectangle scrollArea = GetScrollAreaBounds();
1562 if (scrollDirection == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1564 if (scrollArea.width > scrollPanelBounds.width)
1566 int minScrollPos = scrollArea.x;
1567 int maxScrollPos = scrollArea.width - scrollPanelBounds.width;
1569 if ((targetPosition >= minScrollPos && targetPosition <= maxScrollPos)
1570 || (previousScrollPosition > minScrollPos || previousScrollPosition < maxScrollPos))
1572 __pScrollPanel->FireOnScrollPositionChangedEvent();
1575 if (previousScrollPosition > minScrollPos && previousScrollPosition < maxScrollPos)
1577 if (targetPosition <= minScrollPos)
1579 __pScrollPanel->FireOnScrollEndEvent(SCROLL_END_EVENT_END_LEFT);
1581 else if (targetPosition >= maxScrollPos)
1583 __pScrollPanel->FireOnScrollEndEvent(SCROLL_END_EVENT_END_RIGHT);
1590 if (scrollArea.height > scrollPanelBounds.height)
1592 int minScrollPos = scrollArea.y;
1593 int maxScrollPos = scrollArea.height - scrollPanelBounds.height;
1595 if ((targetPosition >= minScrollPos && targetPosition <= maxScrollPos)
1596 || (previousScrollPosition > minScrollPos || previousScrollPosition < maxScrollPos))
1598 __pScrollPanel->FireOnScrollPositionChangedEvent();
1601 if (previousScrollPosition > minScrollPos && previousScrollPosition < maxScrollPos)
1603 if (targetPosition <= minScrollPos)
1605 __pScrollPanel->FireOnScrollEndEvent(SCROLL_END_EVENT_END_TOP);
1607 else if (targetPosition >= maxScrollPos)
1609 __pScrollPanel->FireOnScrollEndEvent(SCROLL_END_EVENT_END_BOTTOM);
1620 _ScrollPanelPresenter::ChangeScrollBarPosition(int position)
1622 _Scroll* pScrollBar = __pScrollPanel->GetScrollBar();
1624 if (pScrollBar != null && __pScrollPanel->IsAncestorOf(*pScrollBar))
1626 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1628 result r = pScrollBar->SetScrollPosition(position);
1629 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1633 result r = pScrollBar->SetScrollPosition(position);
1634 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1640 _ScrollPanelPresenter::ChangeScrollBarRange(void)
1642 _Scroll* pScrollBar = __pScrollPanel->GetScrollBar();
1644 if (pScrollBar != null)
1647 int scrollRange = 0;
1649 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1651 viewRange = __pScrollPanel->GetBounds().width;
1652 scrollRange = GetScrollAreaBounds().width;
1656 viewRange = __pScrollPanel->GetBounds().height;
1657 scrollRange = GetScrollAreaBounds().height;
1660 if (viewRange <= scrollRange)
1662 result r = pScrollBar->SetScrollRange(viewRange, scrollRange);
1663 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1665 if (viewRange != scrollRange && __scrollBarFirstLoaded)
1668 result r = GetLastResult();
1669 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1671 StartScrollBarLoadEffectTimer();
1672 r = GetLastResult();
1673 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1680 _ScrollPanelPresenter::StartScrollBarLoadEffectTimer(void)
1682 result r = E_SUCCESS;
1684 if (__pScrollBarLoadEffectTimer == null)
1686 __pScrollBarLoadEffectTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
1687 SysTryReturnVoidResult(NID_UI_CTRL, __pScrollBarLoadEffectTimer != null, E_OUT_OF_MEMORY, "[%s] The memory is insufficient", GetErrorMessage(E_OUT_OF_MEMORY));
1689 r = __pScrollBarLoadEffectTimer->Construct(*this);
1690 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1692 r = __pScrollBarLoadEffectTimer->Start(SCROLL_PANEL_SCROLL_BAR_LOAD_EFFECT_TIMER_DURATION);
1693 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1699 delete __pScrollBarLoadEffectTimer;
1700 __pScrollBarLoadEffectTimer = null;
1706 _ScrollPanelPresenter::StopScrollBarLoadEffectTimer(void)
1708 delete __pScrollBarLoadEffectTimer;
1709 __pScrollBarLoadEffectTimer = null;
1713 _ScrollPanelPresenter::StartFlickScrollEffectTimer(void)
1715 result r = E_SUCCESS;
1717 if (__pFlickScrollEffectTimer == null)
1719 __pFlickScrollEffectTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
1720 SysTryReturnVoidResult(NID_UI_CTRL, __pFlickScrollEffectTimer != null, E_OUT_OF_MEMORY, "[%s] The memory is insufficient", GetErrorMessage(E_OUT_OF_MEMORY));
1722 r = __pFlickScrollEffectTimer->Construct(*this);
1723 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1725 r = __pFlickScrollEffectTimer->Start(SCROLL_PANEL_FLICK_SCROLL_EFFECT_TIMER_DURATION);
1726 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1732 delete __pFlickScrollEffectTimer;
1733 __pFlickScrollEffectTimer = null;
1739 _ScrollPanelPresenter::StopFlickScrollEffectTimer(void)
1742 __flickDirection = _FLICK_DIRECTION_NONE;
1744 delete __pFlickScrollEffectTimer;
1745 __pFlickScrollEffectTimer = null;
1749 _ScrollPanelPresenter::FadeOutScrollBar(void)
1751 if (!__scrollAnimationRunning && !__scrollBarFirstLoaded)
1753 _Scroll* pScrollBar = __pScrollPanel->GetScrollBar();
1754 if (pScrollBar != null)
1756 if (!pScrollBar->IsEnabledHandler())
1758 result r = pScrollBar->SetScrollVisibility(false);
1759 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1762 result r = pScrollBar->SetScrollingEffectVisibility(false);
1763 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1769 _ScrollPanelPresenter::StopFadeOutScrollBar(void)
1771 _Scroll* pScrollBar = __pScrollPanel->GetScrollBar();
1773 if (pScrollBar != null)
1775 pScrollBar->CancelFadeEffect();
1780 _ScrollPanelPresenter::FadeInScrollBar(void)
1782 if (!IsScrollable())
1787 _Scroll* pScrollBar = __pScrollPanel->GetScrollBar();
1789 if (pScrollBar != null)
1791 if (__pScrollPanel->IsScrollBarVisible())
1793 result r = pScrollBar->SetScrollVisibility(true);
1794 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1797 result r = pScrollBar->SetScrollingEffectVisibility(true);
1798 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1803 _ScrollPanelPresenter::IsScrollable(void) const
1805 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1807 return __pScrollPanel->GetBounds().width >0 && __pScrollPanel->GetBounds().width < GetScrollAreaBounds().width;
1811 return __pScrollPanel->GetBounds().height > 0 && __pScrollPanel->GetBounds().height < GetScrollAreaBounds().height;
1816 _ScrollPanelPresenter::GetScrollAreaBounds(void) const
1818 return __pScrollPanelModel->GetScrollAreaBounds();
1822 _ScrollPanelPresenter::SetClientAreaHeight(int height)
1824 SysTryReturn(NID_UI_CTRL, __pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_VERTICAL, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] The height of the client area cannot be set when the scroll direction is horizontal.", GetErrorMessage(E_INVALID_OPERATION));
1825 Rectangle bounds = GetScrollAreaBounds();
1826 bounds.height = height;
1828 return SetScrollAreaBounds(bounds);
1832 _ScrollPanelPresenter::SetClientAreaWidth(int width)
1834 SysTryReturn(NID_UI_CTRL, __pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL, E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] The width of the client area cannot be set when the scroll direction is vertical.", GetErrorMessage(E_INVALID_OPERATION));
1835 Rectangle bounds = GetScrollAreaBounds();
1836 bounds.width = width;
1838 return SetScrollAreaBounds(bounds);
1842 _ScrollPanelPresenter::SetScrollAreaBoundsInternal(Rectangle& bounds)
1844 if (__pScrollPanel->IsFixingClientBoundsEnable())
1846 __pScrollPanel->SetClientBounds(bounds);
1848 __pScrollPanelModel->SetScrollAreaBounds(bounds);
1852 _ScrollPanelPresenter::SetScrollAreaBounds(Rectangle& bounds)
1854 SysTryReturn(NID_UI_CTRL, !__pScrollPanel->IsScrollAreaAutoResizingEnabled(), E_INVALID_OPERATION, E_INVALID_OPERATION, "[%s] The width of the client area cannot be set when auto resizing of the client area is off.", GetErrorMessage(E_INVALID_OPERATION));
1859 if (__pScrollPanel->GetScrollDirection() == SCROLL_PANEL_SCROLL_DIRECTION_HORIZONTAL)
1861 SysTryReturn(NID_UI_CTRL, __pScrollPanel->GetBounds().width <= bounds.width, E_INVALID_ARG, E_INVALID_ARG, "[%s] width is less than the width of ScrollPanel", GetErrorMessage(E_INVALID_ARG));
1862 bounds.height = __pScrollPanel->GetBounds().height;
1866 SysTryReturn(NID_UI_CTRL, __pScrollPanel->GetBounds().height <= bounds.height, E_INVALID_ARG, E_INVALID_ARG, "[%s] height is less than the height of ScrollPanel", GetErrorMessage(E_INVALID_ARG));
1867 bounds.width = __pScrollPanel->GetBounds().width;
1870 // before change model ScrollPosition fix
1871 Rectangle scrollPanelBounds = __pScrollPanel->GetBounds();
1872 int scrollPosition = GetScrollPosition();
1873 int fixedScrollPosition = FixScrollPositionIntoScrollAreaBounds(scrollPosition, scrollPanelBounds, bounds);
1874 if (scrollPosition != fixedScrollPosition)
1876 ScrollTo(fixedScrollPosition, false);
1877 result r = GetLastResult();
1878 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1881 SetScrollAreaBoundsInternal(bounds);
1884 result r = GetLastResult();
1885 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1891 _ScrollPanelPresenter::GetPressedControl(void) const
1893 return __pPressedControl;
1897 _ScrollPanelPresenter::GetPreviousTouchPosition(void) const
1899 return __previousTouchedPosition;
1903 _ScrollPanelPresenter::GetCurrentTouchPosition(void) const
1905 return __currentMovedPosition;
1909 _ScrollPanelPresenter::IsScrollAnimationRunning(void) const
1911 return __scrollAnimationRunning;
1914 }}} // Tizen::Ui::Controls