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