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