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