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