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