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