(TextController/ScrollView) Reduced LOC
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/adaptor-framework/timer.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/object/property-notification.h>
25 #include <dali/public-api/object/weak-handle.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
29 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-base-impl.h>
30 #include <dali-toolkit/public-api/controls/control-impl.h>
31 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-effect.h>
32 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
33 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl-constraints.h>
34
35 namespace Dali
36 {
37 namespace Toolkit
38 {
39 namespace Internal
40 {
41 class ScrollView;
42 typedef IntrusivePtr<ScrollView> ScrollViewPtr;
43
44 class ScrollInternalConstraints;
45 typedef IntrusivePtr<ScrollInternalConstraints> ScrollInternalConstraintsPtr;
46
47 class ScrollOvershootIndicator;
48 typedef IntrusivePtr<ScrollOvershootIndicator> ScrollOvershootIndicatorPtr;
49
50 class ScrollViewPropertyHandler;
51
52 /**
53  * @copydoc Toolkit::ScrollView
54  */
55 class ScrollView : public ScrollBase
56 {
57 public:
58   /**
59    * FindDirection specifies how searching is conducted within the Find... routines.
60    */
61   enum FindDirection
62   {
63     None  = -3, ///< Includes none within the search query.
64     All   = -2, ///< Includes all within the search query.
65     Left  = -1, ///< Includes only those not right !(>)
66     Right = 1,  ///< Includes only those right (>)
67     Up    = -1, ///< Includes only those not below  !(>)
68     Down  = 1,  ///< Includes only those below (>)
69     Out   = -1, ///< Includes only those not infront  !(>)
70     In    = 1   ///< Includes only those infront (>)
71   };
72
73   enum LockAxis
74   {
75     LockPossible = 0, ///< Locking is possible, but not set in stone yet.
76     LockHorizontal,   ///< Locking is set to horizontal. (can pan vertically)
77     LockVertical,     ///< Locking is set to vertical. (can pan horizontally)
78     LockNone          ///< Locking is set to none (free panning).
79   };
80
81   enum ScrollStateFlag
82   {
83     AnimatingInternalX = 0x01, ///< animating mPropertyX due to externally requested ScrollTo or internal snapping operation
84     AnimatingInternalY = 0x02, ///< animating mPropertyY due to externally requested ScrollTo or internal snapping operation
85     SnappingInternalX  = 0x04, ///< snapping mPropertyX back to mPropertyPreScroll x value to remove x overshoot over time
86     SnappingInternalY  = 0x08, ///< snapping mPropertyY back to mPropertyPreScroll y value to remove y overshoot over time
87   };
88
89   static const unsigned int SCROLL_X_STATE_MASK    = AnimatingInternalX | SnappingInternalX;
90   static const unsigned int SCROLL_Y_STATE_MASK    = AnimatingInternalY | SnappingInternalY;
91   static const unsigned int SCROLL_ANIMATION_FLAGS = AnimatingInternalX | AnimatingInternalY;
92   static const unsigned int SNAP_ANIMATION_FLAGS   = SnappingInternalX | SnappingInternalY;
93
94 private:
95   typedef std::vector<Dali::Toolkit::ScrollViewEffect> ScrollViewEffectContainer; ///< Container of Dali::Toolkit::ScrollViewEffect
96   typedef ScrollViewEffectContainer::iterator          ScrollViewEffectIter;      ///< Iterator for Dali::Toolkit::ScrollViewEffectContainer
97
98 public:
99   /**
100    * Create a new ScrollView.
101    * @return A public handle to the newly allocated ScrollView.
102    */
103   static Dali::Toolkit::ScrollView New();
104
105 public:
106   /**
107    * @copydoc Toolkit::ScrollView::GetScrollSnapAlphaFunction
108    */
109   AlphaFunction GetScrollSnapAlphaFunction() const
110   {
111     return mSnapAlphaFunction;
112   }
113
114   /**
115    * @copydoc Toolkit::ScrollView::SetScrollSnapAlphaFunction
116    */
117   void SetScrollSnapAlphaFunction(AlphaFunction alpha)
118   {
119     mSnapAlphaFunction = alpha;
120   }
121
122   /**
123    * @copydoc Toolkit::ScrollView::GetScrollFlickAlphaFunction
124    */
125   AlphaFunction GetScrollFlickAlphaFunction() const
126   {
127     return mFlickAlphaFunction;
128   }
129
130   /**
131    * @copydoc Toolkit::ScrollView::SetScrollFlickAlphaFunction
132    */
133   void SetScrollFlickAlphaFunction(AlphaFunction alpha)
134   {
135     mFlickAlphaFunction = alpha;
136   }
137
138   /**
139    * @copydoc Toolkit::ScrollView::GetScrollSnapDuration
140    */
141   float GetScrollSnapDuration() const
142   {
143     return mSnapDuration;
144   }
145
146   /**
147    * @copydoc Toolkit::ScrollView::SetScrollSnapDuration
148    */
149   void SetScrollSnapDuration(float time)
150   {
151     mSnapDuration = time;
152   }
153
154   /**
155    * @copydoc Toolkit::ScrollView::GetScrollFlickDuration
156    */
157   float GetScrollFlickDuration() const
158   {
159     return mFlickDuration;
160   }
161
162   /**
163    * @copydoc Toolkit::ScrollView::SetScrollFlickDuration
164    */
165   void SetScrollFlickDuration(float time)
166   {
167     mFlickDuration = time;
168   }
169
170   /**
171    * @copydoc Toolkit::ScrollView::ApplyEffect
172    */
173   void ApplyEffect(Toolkit::ScrollViewEffect effect);
174
175   /**
176    * @copydoc Toolkit::ScrollView::RemoveEffect
177    */
178   void RemoveEffect(Toolkit::ScrollViewEffect effect);
179
180   /**
181    * @copydoc Toolkit::ScrollView::RemoveAllEffects
182    */
183   void RemoveAllEffects();
184
185   /**
186    * @copydoc Toolkit::ScrollView::ApplyConstraintToChildren
187    */
188   void ApplyConstraintToChildren(Constraint constraint);
189
190   /**
191    * @copydoc Toolkit::ScrollView::RemoveConstraintsFromChildren
192    */
193   void RemoveConstraintsFromChildren();
194
195   /**
196    * @copydoc Toolkit::ScrollView::GetRulerX
197    */
198   const RulerPtr GetRulerX() const
199   {
200     return mRulerX;
201   }
202
203   /**
204    * @copydoc Toolkit::ScrollView::GetRulerY
205    */
206   const RulerPtr GetRulerY() const
207   {
208     return mRulerY;
209   }
210
211   /**
212    * @copydoc Toolkit::ScrollView::SetRulerX
213    */
214   void SetRulerX(RulerPtr ruler);
215
216   /**
217    * @copydoc Toolkit::ScrollView::SetRulerY
218    */
219   void SetRulerY(RulerPtr ruler);
220
221   /**
222    * Retrieve the touch sensitivity.
223    *
224    * @return whether the touch sensitivity is true or false.
225    */
226   bool GetScrollSensitive()
227   {
228     return mSensitive;
229   }
230
231   /**
232    * @copydoc Toolkit::ScrollView::SetScrollSensitive
233    */
234   void SetScrollSensitive(bool sensitive);
235
236   /**
237    * @copydoc Toolkit::ScrollView::SetMaxOvershoot
238    */
239   void SetMaxOvershoot(float overshootX, float overshootY);
240
241   /**
242    * @copydoc Toolkit::ScrollView::SetSnapOvershootAlphaFunction
243    */
244   void SetSnapOvershootAlphaFunction(AlphaFunction alpha)
245   {
246     mSnapOvershootAlphaFunction = alpha;
247   }
248
249   /**
250    * Retrieve the duartion of Snap Overshoot animation
251    *
252    * @return the duration.
253    */
254   float GetSnapOvershootDuration()
255   {
256     return mSnapOvershootDuration;
257   }
258
259   /**
260    * @copydoc Toolkit::ScrollView::SetSnapOvershootDuration
261    */
262   void SetSnapOvershootDuration(float duration)
263   {
264     mSnapOvershootDuration = duration;
265   }
266
267   /**
268    * Retrieve whether Actor Auto-Snap mode is enabled or not.
269    *
270    * @return Actor Auto-Snap mode Enabled flag.
271    */
272   bool GetActorAutoSnap();
273
274   /**
275    * @copydoc Toolkit::ScrollView::SetActorAutoSnap
276    */
277   void SetActorAutoSnap(bool enable)
278   {
279     mActorAutoSnapEnabled = enable;
280   }
281
282   /**
283    * Enables or Disables Auto Resizing mode for ScrollView contents.
284    *
285    * When enabled, the ScrollView's X/Y Domains are restricted to the
286    * dimensions of the content's bounds, which may change as Actors are
287    * Added/Removed, and repositioned.
288    *
289    * @note This has been disabled for now, as this requires some fundamental
290    * changes to the way Actors positions and bounds are retrieved.
291    * (currently only constraints have these initial state knowledge)
292    *
293    * @param[in] enable Enables (true), or disables (false) Auto Resize.
294    */
295   void SetAutoResize(bool enable);
296
297   /**
298    * Returns whether the wrap mode has been enabled (true) or not (false).
299    *
300    * @return Wrap Mode Enabled flag.
301    */
302   bool GetWrapMode() const
303   {
304     return mWrapMode;
305   }
306
307   /**
308    * @copydoc Toolkit::ScrollView::SetWrapMode
309    */
310   void SetWrapMode(bool enable);
311
312   /**
313    * @copydoc Toolkit::ScrollView::GetScrollupdateDistance
314    */
315   int GetScrollUpdateDistance() const
316   {
317     return mScrollUpdateDistance;
318   }
319
320   /**
321    * @copydoc Toolkit::ScrollView::SetScrollUpdateDistance
322    */
323   void SetScrollUpdateDistance(int distance)
324   {
325     mScrollUpdateDistance = distance;
326   }
327
328   /**
329    * @copydoc Toolkit::ScrollView::GetAxisAutoLock
330    */
331   bool GetAxisAutoLock() const
332   {
333     return mAxisAutoLock;
334   }
335
336   /**
337    * @copydoc Toolkit::ScrollView::SetAxisAutoLock
338    */
339   void SetAxisAutoLock(bool enable);
340
341   /**
342    * @copydoc Toolkit::ScrollView::GetAxisAutoLockGradient
343    */
344   float GetAxisAutoLockGradient() const
345   {
346     return mAxisAutoLockGradient;
347   }
348
349   /**
350    * @copydoc Toolkit::ScrollView::SetAxisAutoLockGradient
351    */
352   void SetAxisAutoLockGradient(float gradient);
353
354   /**
355    * @copydoc Toolkit::ScrollView::GetFrictionCoefficient
356    */
357   float GetFrictionCoefficient() const
358   {
359     return mFrictionCoefficient;
360   }
361
362   /**
363    * @copydoc Toolkit::ScrollView::SetFrictionCoefficient
364    */
365   void SetFrictionCoefficient(float friction);
366
367   /**
368    * @copydoc Toolkit::ScrollView::GetFlickSpeedCoefficient
369    */
370   float GetFlickSpeedCoefficient() const
371   {
372     return mFlickSpeedCoefficient;
373   }
374
375   /**
376    * @copydoc Toolkit::ScrollView::SetFlickSpeedCoefficient
377    */
378   void SetFlickSpeedCoefficient(float speed)
379   {
380     mFlickSpeedCoefficient = speed;
381   }
382
383   /**
384    * @copydoc Toolkit::ScrollView::GetMinimumDistanceForFlick
385    */
386   Vector2 GetMinimumDistanceForFlick() const
387   {
388     return mMinFlickDistance;
389   }
390
391   /**
392    * @copydoc Toolkit::ScrollView::SetMinimumDistanceForFlick
393    */
394   void SetMinimumDistanceForFlick(const Vector2& distance)
395   {
396     mMinFlickDistance = distance;
397   }
398
399   /**
400    * @copydoc Toolkit::ScrollView::GetMinimumSpeedForFlick
401    */
402   float GetMinimumSpeedForFlick() const
403   {
404     return mFlickSpeedThreshold;
405   }
406
407   /**
408    * @copydoc Toolkit::ScrollView::SetMinimumSpeedForFlick
409    */
410   void SetMinimumSpeedForFlick(float speed)
411   {
412     mFlickSpeedThreshold = speed;
413   }
414
415   /**
416    * @copydoc Toolkit::ScrollView::GetMaxFlickSpeed
417    */
418   float GetMaxFlickSpeed() const
419   {
420     return mMaxFlickSpeed;
421   }
422
423   /**
424    * @copydoc Toolkit::ScrollView::SetMaxFlickSpeed
425    */
426   void SetMaxFlickSpeed(float speed)
427   {
428     mMaxFlickSpeed = speed;
429   }
430
431   /**
432    * @copydoc Toolkit::ScrollView::GetWheelScrollDistanceStep
433    */
434   Vector2 GetWheelScrollDistanceStep() const
435   {
436     return mWheelScrollDistanceStep;
437   }
438
439   /**
440    * @copydoc Toolkit::ScrollView::SetWheelScrollDistanceStep
441    */
442   void SetWheelScrollDistanceStep(Vector2 step)
443   {
444     mWheelScrollDistanceStep = step;
445   }
446
447   /**
448    * @copydoc Toolkit::ScrollView::GetCurrentPage
449    */
450   unsigned int GetCurrentPage() const;
451
452   /**
453    * @copydoc Toolkit::ScrollView::GetCurrentScrollPosition
454    */
455   Vector2 GetCurrentScrollPosition() const;
456
457   /**
458    * @copydoc ScrollTo(const Vector2&)
459    */
460   void TransformTo(const Vector2& position,
461                    DirectionBias  horizontalBias = DIRECTION_BIAS_NONE,
462                    DirectionBias  verticalBias   = DIRECTION_BIAS_NONE);
463
464   /**
465    * @copydoc ScrollTo(const Vector2&, float, AlhpaFunction, DirectionBias, DirectionBias)
466    */
467   void TransformTo(const Vector2& position, float duration, AlphaFunction alpha, DirectionBias horizontalBias = DIRECTION_BIAS_NONE, DirectionBias verticalBias = DIRECTION_BIAS_NONE);
468
469   /**
470    * @copydoc Toolkit::ScrollView::ScrollTo(const Vector2 &position)
471    */
472   void ScrollTo(const Vector2& position);
473
474   /**
475    * @copydoc Toolkit::Scrollable::ScrollTo(const Vector2& position, float duration)
476    */
477   void ScrollTo(const Vector2& position, float duration);
478
479   /**
480    * @copydoc Toolkit::Scrollable::ScrollTo(const Vector2& position, float duration, AlphaFunction alpha)
481    */
482   void ScrollTo(const Vector2& position, float duration, AlphaFunction alpha);
483
484   /**
485    * @copydoc Toolkit::ScrollView::ScrollTo(const Vector2 &position, float duration, DirectionBias horizontalBias, DirectionBias verticalBias)
486    */
487   void ScrollTo(const Vector2& position, float duration, DirectionBias horizontalBias, DirectionBias verticalBias);
488
489   /**
490    * @copydoc Toolkit::ScrollView::ScrollTo(const Vector2 &position, float duration, AlphaFunction alpha, DirectionBias horizontalBias, DirectionBias verticalBias)
491    */
492   void ScrollTo(const Vector2& position, float duration, AlphaFunction alpha, DirectionBias horizontalBias, DirectionBias verticalBias);
493
494   /**
495    * @copydoc Toolkit::ScrollView::ScrollTo(unsigned int page)
496    */
497   void ScrollTo(unsigned int page);
498
499   /**
500    * @copydoc Toolkit::ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
501    */
502   void ScrollTo(unsigned int page, float duration, DirectionBias bias = DIRECTION_BIAS_NONE);
503
504   /**
505    * @copydoc Toolkit::ScrollView::ScrollTo(Actor& actor)
506    */
507   void ScrollTo(Actor& actor);
508
509   /**
510    * @copydoc Toolkit::ScrollView::ScrollTo(Actor& actor, float duration)
511    */
512   void ScrollTo(Actor& actor, float duration);
513
514   /**
515    * @copydoc Toolkit::ScrollView::SetScrollingDirection()
516    */
517   void SetScrollingDirection(Radian direction, Radian threshold);
518
519   /**
520    * @copydoc Toolkit::ScrollView::RemoveScrollingDirection()
521    */
522   void RemoveScrollingDirection(Radian angle);
523
524   /**
525     * Finds the closest Actor to the current center of the ScrollView.
526     *
527     * @return A handle to the actor if found, or an empty handle if not.
528     */
529   Actor FindClosestActor();
530
531   /**
532    * Finds the closest Actor to position in ScrollView
533    *
534    * @param[in] position position within ScrollView.
535    * @param[in] dirX Whether to search only those elements that are Left,Right, or All
536    * @param[in] dirY Whether to search only those elements that are Up,Down, or All
537    * @param[in] dirZ Whether to search only those elements that are Out,In, or All
538    * @return A handle to the actor if found, or an empty handle if not.
539    */
540   Actor FindClosestActorToPosition(const Vector3& position, FindDirection dirX = All, FindDirection dirY = All, FindDirection dirZ = All);
541
542   /**
543    * @copydoc Toolkit::ScrollView::ScrollToSnapPoint
544   */
545   bool ScrollToSnapPoint();
546
547   /**
548    * Stops animation
549    */
550   void StopAnimation(void);
551
552   /**
553    * Stops the input animation
554    *
555    * @param[in] the animation to stop
556    */
557   void StopAnimation(Animation& animation);
558
559   /**
560    * Animates to position transform.
561    *
562    * @param[in] position The position to animate to
563    * @param[in] positionDuration The number of seconds this animation should run for in each axis.
564    * @param[in] alpha The easing alpha function to use.
565    * @param[in] findShortcuts (optional) Whether to find the shortest route (in Wrap mode)
566    * @param[in] horizontalBias (optional) Whether to bias animation to left or right (or no biasing)
567    * @param[in] verticalBias (optional) Whether to bias animation to top or bottom (or no biasing)
568    * @return True if animation necessary and taking place to reach desired transform.
569    */
570   bool AnimateTo(const Vector2& position, const Vector2& positionDuration, AlphaFunction alpha, bool findShortcuts = true, DirectionBias horizontalBias = DIRECTION_BIAS_NONE, DirectionBias verticalBias = DIRECTION_BIAS_NONE, SnapType snapType = SNAP);
571
572   /**
573    * @copydoc Toolkit::Scrollable::AddOverlay()
574    */
575   void AddOverlay(Actor actor);
576
577   /**
578    * @copydoc Toolkit::Scrollable::RemoveOverlay()
579    */
580   void RemoveOverlay(Actor actor);
581
582   /**
583    * @copydoc Toolkit::Internal::Scrollable::SetOvershootSize
584    */
585   void SetOvershootSize(const Vector2& size);
586
587   /**
588    * @copydoc Toolkit::Internal::Scrollable::SetOvershootEffectColor
589    */
590   void SetOvershootEffectColor(const Vector4& color);
591
592   //properties
593
594   /**
595    * Called when a property of an object of this type is set.
596    * @param[in] object The object whose property is set.
597    * @param[in] index The property index.
598    * @param[in] value The new property value.
599    */
600   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
601
602   /**
603    * Called to retrieve a property of an object of this type.
604    * @param[in] object The object whose property is to be retrieved.
605    * @param[in] index The property index.
606    * @return The current value of the property.
607    */
608   static Property::Value GetProperty(BaseObject* object, Property::Index index);
609
610 public: //Signals
611   /**
612    * @copydoc Dali::Toolkit::ScrollView::SnapStartedSignal()
613    */
614   Toolkit::ScrollView::SnapStartedSignalType& SnapStartedSignal();
615
616   /**
617    * Connects a callback function with the object's signals.
618    * @param[in] object The object providing the signal.
619    * @param[in] tracker Used to disconnect the signal.
620    * @param[in] signalName The signal to connect to.
621    * @param[in] functor A newly allocated FunctorDelegate.
622    * @return True if the signal was connected.
623    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
624    */
625   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
626
627 private: // private overridden functions from CustomActorImpl and Controls
628   /**
629    * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
630    */
631   void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
632
633   /**
634    * @copydoc CustomActorImpl::OnSizeSet(const Vector3&)
635    */
636   void OnSizeSet(const Vector3& size) override;
637
638   /**
639    * From CustomActorImpl; called after a child has been added to the owning actor.
640    * @param[in] child The child which has been added.
641    */
642   void OnChildAdd(Actor& child) override;
643
644   /**
645    * From CustomActorImpl; called shortly before a child is removed from the owning actor.
646    * @param[in] child The child being removed.
647    */
648   void OnChildRemove(Actor& child) override;
649
650   /**
651    * Called after a wheelEvent is received by the owning actor.
652    * @param[in] actor Actor associated with the event.
653    * @param[in] event The wheel event.
654    * @return True if the event should be consumed.
655    */
656   bool OnWheelEvent(Actor actor, const WheelEvent& event);
657
658   /**
659    * @copydoc Toolkit::Control::OnInitialize()
660    */
661   void OnInitialize() override;
662
663   /**
664    * @copydoc CustomActorImpl::OnSceneConnection()
665    */
666   void OnSceneConnection(int depth) override;
667
668   /**
669    * @copydoc CustomActorImpl::OnSceneDisconnection()
670    */
671   void OnSceneDisconnection() override;
672
673   /**
674    * @copydoc Toolkit::Control::OnAccessibilityPan()
675    */
676   bool OnAccessibilityPan(PanGesture gesture) override;
677
678   /**
679    * @copydoc Toolkit::Scrollable::EnableScrollOvershoot()
680    */
681   void EnableScrollOvershoot(bool enable) override;
682
683 private:
684   /**
685    * Called after a touchSignal is received by the owning actor.
686    *
687    * We don't consume these events as content within the container may consume events.
688    *
689    * @param[in] actor The touched actor.
690    * @param[in] touch The touch information.
691    * @return True if the event should be consumed.
692    */
693   bool OnTouch(Actor actor, const TouchEvent& touch);
694
695   /**
696    * Start a timer which calls OnTouchDownTimeout()
697    */
698   void StartTouchDownTimer();
699
700   /**
701    * Stop a timer which calls OnTouchDownTimeout()
702    */
703   void StopTouchDownTimer();
704
705   /**
706    * Helper to detect when touch-point has been down (outside of pan gesture)
707    */
708   bool OnTouchDownTimeout();
709
710   /**
711    * Called whenever a snap animation has completed
712    * @param[in] source the Animation instance that has completed.
713    * Resets all scrolling animations and states, leaving current scroll position at SCROLL_POSITION
714    */
715   void ResetScrolling();
716
717   /**
718    * Updates mScrollInternalPosition, mScrollPrePosition and mScrollPostPosition from their property counterparts
719    */
720   void UpdateLocalScrollProperties();
721
722   /**
723    * Makes sure scroll values are ready for animated scrolling
724    */
725   void PreAnimatedScrollSetup();
726
727   /**
728    * Finish an animated scroll, ensuring all scroll properties are updated
729    * and synchronised
730    */
731   void FinaliseAnimatedScroll();
732
733   /**
734    * Animates the internal x property to the given value
735    *
736    * @param[in] position The X position to animate to
737    * @param[in] duration The time in seconds for animation
738    * @param[in] alpha The alpha function to use for animating
739    */
740   void AnimateInternalXTo(float position, float duration, AlphaFunction alpha);
741
742   /**
743    * Animates the internal y property to the given value
744    *
745    * @param[in] position The Y position to animate to
746    * @param[in] duration The time in seconds for animation
747    * @param[in] alpha The alpha function to use for animating
748    */
749   void AnimateInternalYTo(float position, float duration, AlphaFunction alpha);
750
751   /**
752    * Called whenever a snap animation on the x-axis has completed
753    * @param[in] source the Animation instance that has completed.
754    */
755   void OnScrollAnimationFinished(Animation& source);
756
757   /**
758    * Called when either the X or Y internal scroll positions have finished snapping back to SCROLL_PRE_POSITION
759    *
760    * @param[in] source the Animation instance that has completed.
761    */
762   void OnSnapInternalPositionFinished(Animation& source);
763
764   /**
765    * Called whenever a snap animation on the x-axis has completed and we need to snap pre scroll
766    * position to our clamped position
767    * @param[in] position The x position to snap pre scroll property to
768    */
769   void SnapInternalXTo(float position);
770
771   /**
772    * Called whenever a snap animation on the y-axis has completed and we need to snap pre scroll
773    * position to our clamped position
774    * @param[in] position The y position to snap pre scroll property to
775    */
776   void SnapInternalYTo(float position);
777
778   /**
779    * Called when the gesture starts.
780    */
781   void GestureStarted();
782
783   /**
784    * Amalgamated Gesture Continuing event
785    *
786    * @param[in] panDelta average panning delta from base position (0)
787    */
788   void GestureContinuing(const Vector2& panDelta);
789
790   /**
791    * Called upon pan gesture event.
792    *
793    * @param[in] gesture The gesture event.
794    */
795   void OnPan(const PanGesture& pan);
796
797   /**
798    * Extension of the above gestures.
799    *
800    * @param[in] gesture The gesture event.
801    */
802   void OnGestureEx(GestureState state);
803
804   /**
805    * Performs snapping while taking into account Velocity of gesture
806    * (velocity in pixels/sec)
807    *
808    * @param[in] velocity velocity in pixels/sec
809    */
810   bool SnapWithVelocity(Vector2 velocity);
811
812   /**
813    * Finishes Container Transform
814    * (occurs upon finishing gesture i.e. releasing)
815    */
816   void FinishTransform();
817
818   /**
819    * Clamps position within the domain set up by X/Y Rulers
820    *
821    * @param[in,out] position The position you wish to clamp
822    */
823   void ClampPosition(Vector2& position) const;
824
825   /**
826    * Clamps position within the domain set up by X/Y Rulers
827    *
828    * @param[in,out] position The position you wish to clamp
829    * @param[out] clamped The results of the clamping.
830    */
831   void ClampPosition(Vector2& position, ClampState2D& clamped) const;
832
833   /**
834    * Wraps position within the domain set up by X/Y Rulers
835    *
836    * @note Only wraps if mWrapMode is enabled, and respective domains
837    * are enabled.
838    *
839    * @param[in,out] position The position you wish to wrap
840    */
841   void WrapPosition(Vector2& position) const;
842
843 protected:
844   struct AccessibleImpl : public Scrollable::AccessibleImpl
845   {
846     using Scrollable::AccessibleImpl::AccessibleImpl;
847
848     bool ScrollToChild(Actor child) override;
849   };
850
851   /**
852    * Construct a new ScrollView.
853    */
854   ScrollView();
855
856   /**
857    * A reference counted object may only be deleted by calling Unreference()
858    */
859   virtual ~ScrollView();
860
861 private:
862   /**
863    * Searches this ScrollView, and attempts to Unbind
864    * systematically this Actor from the ScrollView attached.
865    *
866    * @param[in] child The actor to be unbound.
867    */
868   void FindAndUnbindActor(Actor child) override;
869
870   /**
871    * Gets position property.
872    *
873    * @return The current position
874    */
875   Vector2 GetPropertyPrePosition() const;
876
877   /**
878    * Gets position property.
879    *
880    * @return The current position
881    */
882   Vector2 GetPropertyPosition() const;
883
884   /**
885    * Handles a Stopped animation. Its position properties need to be saved, and the animation flag
886    * switched off.
887    */
888   void HandleStoppedAnimation();
889
890   /**
891    * Handles a Stopped animation (whether the animation completed, or was
892    * manually stopped). Its position properties need to be saved, and the
893    * animation flag switched off.
894    */
895   void HandleSnapAnimationFinished();
896
897   /**
898    * Checks if the property notifications are active and adds them if not
899    */
900   void SetScrollUpdateNotification(bool enabled);
901
902   /**
903    * Refresh the ScrollView (used when animating to update application developer of changes)
904    * @return True if the refresh timer should be kept running.
905    */
906   void OnScrollUpdateNotification(Dali::PropertyNotification& source);
907
908 private:
909   // Undefined
910   ScrollView(const ScrollView&);
911
912   // Undefined
913   ScrollView& operator=(const ScrollView& rhs);
914
915 private:
916   ScrollViewConstraints mConstraints;
917
918   unsigned long mTouchDownTime; ///< The touch down time
919
920   int     mGestureStackDepth; ///< How many gestures are currently occuring.
921   Vector2 mPanStartPosition;  ///< Where the pan gesture's touch down occured
922   Vector2 mPanDelta;          ///< Amount currently panned.
923
924   unsigned int mScrollStateFlags; ///< flags indicating current state of scrolling
925   // Scroll delegate pre and post position properties...
926   Vector2 mScrollPrePosition;    ///< Wrapped scroll position, but not clamped
927   Vector2 mScrollPostPosition;   ///< Wrapped and clamped, this is the final scroll position used
928   Vector2 mScrollTargetPosition; ///< Final target position for an animated scroll
929   Vector2 mDomainOffset;         ///< Domain offset (this keeps track of the domain boundaries that scroll positions traverses)
930
931   // Rulers for each axes...
932   RulerPtr mRulerX;
933   RulerPtr mRulerY;
934
935   // Last property values set to ScrollView
936   Vector2 mMinScroll;
937   Vector2 mMaxScroll;
938
939   Animation mInternalXAnimation; ///< Animates mPropertyX to a snap position or application requested scroll position
940   Animation mInternalYAnimation; ///< Animates mPropertyY to a snap position or application requested scroll position
941
942   Vector2  mLastVelocity; ///< Record the last velocity from PanGesture (Finish event doesn't have correct velocity)
943   LockAxis mLockAxis;
944
945   Timer mTouchDownTimer; ///< Used to interrupt snap-animation. This cannot be done in OnTouch without breaking fast flick behavior.
946
947   float                      mScrollUpdateDistance;      ///< Distance for scrolling to travel for the scroll update notifications
948   Dali::PropertyNotification mScrollXUpdateNotification; ///< scroll x position update notification
949   Dali::PropertyNotification mScrollYUpdateNotification; ///< scroll y position update notification
950
951   Actor mInternalActor; ///< Internal actor (we keep internal actors in here e.g. scrollbars, so we can ignore it in searches)
952
953   ScrollViewEffectContainer mEffects; ///< Container keeping track of all the applied effects.
954
955   Vector2       mMaxOvershoot;               ///< Number of scrollable pixels that will take overshoot from 0.0f to 1.0f
956   Vector2       mUserMaxOvershoot;           ///< Set by user, allows overriding of default max overshoot for the scroll indicator
957   float         mSnapOvershootDuration;      ///< Duration for overshoot snapping back to Vector2::ZERO
958   AlphaFunction mSnapOvershootAlphaFunction; ///< AlphaFunction to be used for this overshoot.
959
960   float         mSnapDuration;      ///< Time for the snap animation to take (in seconds).
961   AlphaFunction mSnapAlphaFunction; ///< AlphaFunction to be used for the Snap Animation.
962
963   Vector2       mMinFlickDistance;    ///< Minimum pan distance required for a flick
964   float         mFlickSpeedThreshold; ///< Minimum pan speed required for a flick in pixels/ms
965   float         mFlickDuration;       ///< Time for the flick animation to take (in seconds).
966   AlphaFunction mFlickAlphaFunction;  ///< AlphaFunction to be used for the Flick Animation.
967
968   float mAxisAutoLockGradient;  ///< Axis Auto-lock gradient threshold. Above this gradient and it will lock scrolling to closest axis.
969   float mFrictionCoefficient;   ///< Friction coefficient. Amount of friction to apply to free panning flick animation. in stage.lengths/sec
970   float mFlickSpeedCoefficient; ///< Flick velocity coefficient. Input touch velocity is multiplied by this.
971   float mMaxFlickSpeed;         ///< Maximum flick speed. Maximum speed of flick in stage.lengths/sec.
972
973   Vector2 mWheelScrollDistanceStep; ///< The step of scroll distance in actor coordinates in X and Y axes for each wheel event received.
974
975   ScrollOvershootIndicatorPtr    mOvershootIndicator;
976   WeakHandle<Toolkit::ScrollBar> mScrollBar;
977
978   Toolkit::ScrollView::SnapStartedSignalType mSnapStartedSignal;
979
980   bool mInAccessibilityPan : 1;         ///< With AccessibilityPan its easier to move between snap positions
981   bool mScrolling : 1;                  ///< Flag indicating whether the scroll view is being scrolled (by user or animation)
982   bool mScrollInterrupted : 1;          ///< Flag set for when a down event interrupts a scroll
983   bool mPanning : 1;                    ///< Whether scroll view is currently panning or not
984   bool mSensitive : 1;                  ///< Scroll Sensitivity Flag.
985   bool mTouchDownTimeoutReached : 1;    ///< Indicates when down event timeout occured without corresponding up event (touch still down)
986   bool mActorAutoSnapEnabled : 1;       ///< Whether to automatically snap to closest actor.
987   bool mAutoResizeContainerEnabled : 1; ///< Whether to automatically resize container (affects RulerDomain's on X/Y axes)
988   bool mWrapMode : 1;                   ///< Whether to wrap contents based on container size.
989   bool mAxisAutoLock : 1;               ///< Whether to automatically lock axis when panning.
990   bool mAlterChild : 1;                 ///< Internal flag to control behavior of OnChildAdd/OnChildRemove when Adding internal Actors.
991   bool mDefaultMaxOvershoot : 1;        ///< Whether to use default max overshoot or application defined one
992   bool mCanScrollHorizontal : 1;        ///< Local value of our property to check against
993   bool mCanScrollVertical : 1;          ///< Local value of our property to check against
994   bool mTransientScrollBar : 1;         ///< True if scroll-bar should be automatically show/hidden during/after panning
995
996   friend ScrollViewConstraints;
997   friend ScrollViewPropertyHandler;
998 };
999
1000 /**
1001  * Returns whether to lock scrolling to a particular axis
1002  *
1003  * @param[in] panDelta Distance panned since gesture started
1004  * @param[in] currentLockAxis The current lock axis value
1005  * @param[in] lockGradient How quickly to lock to a particular axis
1006  *
1007  * @return The new axis lock state
1008  */
1009 ScrollView::LockAxis GetLockAxis(const Vector2& panDelta, ScrollView::LockAxis currentLockAxis, float lockGradient);
1010
1011 } // namespace Internal
1012
1013 // Helpers for public-api forwarding methods
1014
1015 inline Toolkit::Internal::ScrollView& GetImpl(Toolkit::ScrollView& scrollView)
1016 {
1017   DALI_ASSERT_ALWAYS(scrollView);
1018
1019   Dali::RefObject& handle = scrollView.GetImplementation();
1020
1021   return static_cast<Toolkit::Internal::ScrollView&>(handle);
1022 }
1023
1024 inline const Toolkit::Internal::ScrollView& GetImpl(const Toolkit::ScrollView& scrollView)
1025 {
1026   DALI_ASSERT_ALWAYS(scrollView);
1027
1028   const Dali::RefObject& handle = scrollView.GetImplementation();
1029
1030   return static_cast<const Toolkit::Internal::ScrollView&>(handle);
1031 }
1032
1033 } // namespace Toolkit
1034
1035 } // namespace Dali
1036
1037 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H