Removed On(...)Event()
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-impl.h
index f4d211b..ec7b893 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H__
-#define __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H__
+#ifndef DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H
+#define DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali/public-api/adaptor-framework/timer.h>
 #include <dali/public-api/animation/animation.h>
 #include <dali/public-api/object/property-notification.h>
+#include <dali/public-api/object/weak-handle.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-base-impl.h>
 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-effect.h>
@@ -90,6 +92,11 @@ public:
   static const unsigned int SCROLL_ANIMATION_FLAGS = AnimatingInternalX | AnimatingInternalY;
   static const unsigned int SNAP_ANIMATION_FLAGS = SnappingInternalX | SnappingInternalY;
 
+private:
+
+  typedef std::vector<Dali::Toolkit::ScrollViewEffect> ScrollViewEffectContainer; ///< Container of Dali::Toolkit::ScrollViewEffect
+  typedef ScrollViewEffectContainer::iterator ScrollViewEffectIter; ///< Iterator for Dali::Toolkit::ScrollViewEffectContainer
+
 public:
 
   /**
@@ -186,6 +193,13 @@ public:
   void SetRulerY(RulerPtr ruler);
 
   /**
+   * Retrieve the touch sensitivity.
+   *
+   * @return whether the touch sensitivity is true or false.
+   */
+  bool GetScrollSensitive();
+
+  /**
    * @copydoc Toolkit::ScrollView::SetScrollSensitive
    */
   void SetScrollSensitive(bool sensitive);
@@ -201,11 +215,25 @@ public:
   void SetSnapOvershootAlphaFunction(AlphaFunction alpha);
 
   /**
+   * Retrieve the duartion of Snap Overshoot animation
+   *
+   * @return the duration.
+   */
+  float GetSnapOvershootDuration();
+
+  /**
    * @copydoc Toolkit::ScrollView::SetSnapOvershootDuration
    */
   void SetSnapOvershootDuration(float duration);
 
   /**
+   * Retrieve whether Actor Auto-Snap mode is enabled or not.
+   *
+   * @return Actor Auto-Snap mode Enabled flag.
+   */
+  bool GetActorAutoSnap();
+
+  /**
    * @copydoc Toolkit::ScrollView::SetActorAutoSnap
    */
   void SetActorAutoSnap(bool enable);
@@ -318,14 +346,14 @@ public:
   void SetMaxFlickSpeed(float speed);
 
   /**
-   * @copydoc Toolkit::ScrollView::GetMouseWheelScrollDistanceStep
+   * @copydoc Toolkit::ScrollView::GetWheelScrollDistanceStep
    */
-  Vector2 GetMouseWheelScrollDistanceStep() const;
+  Vector2 GetWheelScrollDistanceStep() const;
 
   /**
-   * @copydoc Toolkit::ScrollView::SetMouseWheelScrollDistanceStep
+   * @copydoc Toolkit::ScrollView::SetWheelScrollDistanceStep
    */
-  void SetMouseWheelScrollDistanceStep(Vector2 step);
+  void SetWheelScrollDistanceStep(Vector2 step);
 
   /**
    * @copydoc Toolkit::ScrollView::GetCurrentPage
@@ -335,55 +363,45 @@ public:
   /**
    * @copydoc Toolkit::ScrollView::GetCurrentScrollPosition
    */
-  Vector3 GetCurrentScrollPosition() const;
-
-  /**
-   * @copydoc Toolkit::ScrollView::SetScrollPosition
-   */
-  void SetScrollPosition(const Vector3& position);
+  Vector2 GetCurrentScrollPosition() const;
 
   /**
-   * @copydoc Toolkit::Scrollable::GetDomainSize
+   * @copydoc ScrollTo(const Vector2&)
    */
-  Vector3 GetDomainSize() const;
+  void TransformTo(const Vector2& position,
+                   DirectionBias horizontalBias = DIRECTION_BIAS_NONE, DirectionBias verticalBias = DIRECTION_BIAS_NONE);
 
   /**
-   * @copydoc ScrollTo(const Vector3&)
+   * @copydoc ScrollTo(const Vector2&, float, AlhpaFunction, DirectionBias, DirectionBias)
    */
-  void TransformTo(const Vector3& position,
-                   DirectionBias horizontalBias = DirectionBiasNone, DirectionBias verticalBias = DirectionBiasNone);
+  void TransformTo(const Vector2& position, float duration, AlphaFunction alpha,
+                   DirectionBias horizontalBias = DIRECTION_BIAS_NONE, DirectionBias verticalBias = DIRECTION_BIAS_NONE);
 
   /**
-   * @copydoc ScrollTo(const Vector3&, float, AlhpaFunction, DirectionBias, DirectionBias)
+   * @copydoc Toolkit::ScrollView::ScrollTo(const Vector2 &position)
    */
-  void TransformTo(const Vector3& position, float duration, AlphaFunction alpha,
-                   DirectionBias horizontalBias = DirectionBiasNone, DirectionBias verticalBias = DirectionBiasNone);
+  void ScrollTo(const Vector2 &position);
 
   /**
-   * @copydoc Toolkit::ScrollView::ScrollTo(const Vector3 &position)
+   * @copydoc Toolkit::Scrollable::ScrollTo(const Vector2& position, float duration)
    */
-  void ScrollTo(const Vector3 &position);
+  void ScrollTo(const Vector2& position, float duration);
 
   /**
-   * @copydoc Toolkit::Scrollable::ScrollTo(const Vector3& position, float duration)
+   * @copydoc Toolkit::Scrollable::ScrollTo(const Vector2& position, float duration, AlphaFunction alpha)
    */
-  void ScrollTo(const Vector3& position, float duration);
+  void ScrollTo(const Vector2& position, float duration, AlphaFunction alpha);
 
   /**
-   * @copydoc Toolkit::Scrollable::ScrollTo(const Vector3& position, float duration, AlphaFunction alpha)
+   * @copydoc Toolkit::ScrollView::ScrollTo(const Vector2 &position, float duration, DirectionBias horizontalBias, DirectionBias verticalBias)
    */
-  void ScrollTo(const Vector3& position, float duration, AlphaFunction alpha);
-
-  /**
-   * @copydoc Toolkit::ScrollView::ScrollTo(const Vector3 &position, float duration, DirectionBias horizontalBias, DirectionBias verticalBias)
-   */
-  void ScrollTo(const Vector3& position, float duration,
+  void ScrollTo(const Vector2& position, float duration,
                 DirectionBias horizontalBias, DirectionBias verticalBias);
 
   /**
-   * @copydoc Toolkit::ScrollView::ScrollTo(const Vector3 &position, float duration, AlphaFunction alpha, DirectionBias horizontalBias, DirectionBias verticalBias)
+   * @copydoc Toolkit::ScrollView::ScrollTo(const Vector2 &position, float duration, AlphaFunction alpha, DirectionBias horizontalBias, DirectionBias verticalBias)
    */
-  void ScrollTo(const Vector3& position, float duration, AlphaFunction alpha,
+  void ScrollTo(const Vector2& position, float duration, AlphaFunction alpha,
                 DirectionBias horizontalBias, DirectionBias verticalBias);
 
   /**
@@ -394,7 +412,7 @@ public:
   /**
    * @copydoc Toolkit::ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
    */
-  void ScrollTo(unsigned int page, float duration, DirectionBias bias = DirectionBiasNone);
+  void ScrollTo(unsigned int page, float duration, DirectionBias bias = DIRECTION_BIAS_NONE);
 
   /**
    * @copydoc Toolkit::ScrollView::ScrollTo(Actor& actor)
@@ -462,10 +480,10 @@ public:
    * @param[in] verticalBias (optional) Whether to bias animation to top or bottom (or no biasing)
    * @return True if animation necessary and taking place to reach desired transform.
    */
-  bool AnimateTo(const Vector3& position, const Vector3& positionDuration,
+  bool AnimateTo(const Vector2& position, const Vector2& positionDuration,
                              AlphaFunction alpha, bool findShortcuts = true,
-                             DirectionBias horizontalBias = DirectionBiasNone, DirectionBias verticalBias = DirectionBiasNone,
-                             SnapType snapType = Snap);
+                             DirectionBias horizontalBias = DIRECTION_BIAS_NONE, DirectionBias verticalBias = DIRECTION_BIAS_NONE,
+                             SnapType snapType = SNAP);
 
   /**
    * @copydoc Toolkit::Scrollable::AddOverlay()
@@ -478,10 +496,33 @@ public:
   void RemoveOverlay(Actor actor);
 
   /**
+   * @copydoc Toolkit::Internal::Scrollable::SetOvershootSize
+   */
+  void SetOvershootSize( const Vector2& size );
+
+  /**
    * @copydoc Toolkit::Internal::Scrollable::SetOvershootEffectColor
    */
   void SetOvershootEffectColor( const Vector4& color );
 
+  //properties
+
+  /**
+   * Called when a property of an object of this type is set.
+   * @param[in] object The object whose property is set.
+   * @param[in] index The property index.
+   * @param[in] value The new property value.
+   */
+  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
+
+  /**
+   * Called to retrieve a property of an object of this type.
+   * @param[in] object The object whose property is to be retrieved.
+   * @param[in] index The property index.
+   * @return The current value of the property.
+   */
+  static Property::Value GetProperty( BaseObject* object, Property::Index index );
+
 public: //Signals
 
   /**
@@ -500,7 +541,7 @@ public: //Signals
    */
   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
 
-private: // private overriden functions from CustomActorImpl and Controls
+private: // private overridden functions from CustomActorImpl and Controls
 
   /**
    * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
@@ -508,9 +549,9 @@ private: // private overriden functions from CustomActorImpl and Controls
   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
 
   /**
-   * @copydoc Dali::Control::OnControlSizeSet(const Vector3&)
+   * @copydoc CustomActorImpl::OnSizeSet(const Vector3&)
    */
-  virtual void OnControlSizeSet( const Vector3& size );
+  virtual void OnSizeSet( const Vector3& size );
 
   /**
    * From CustomActorImpl; called after a child has been added to the owning actor.
@@ -525,21 +566,12 @@ private: // private overriden functions from CustomActorImpl and Controls
   virtual void OnChildRemove(Actor& child);
 
   /**
-   * From CustomActorImpl; called after a touch-signal is received by the owning actor.
-   *
-   * We don't listen to these events as content within the contain may consume events.
-   *
-   * @param[in] event The touch event.
+   * Called after a wheelEvent is received by the owning actor.
+   * @param[in] actor Actor associated with the event.
+   * @param[in] event The wheel event.
    * @return True if the event should be consumed.
    */
-  virtual bool OnTouchEvent(const TouchEvent& event);
-
-  /**
-   * From CustomActorImpl; called after a mouse-wheel-event is received by the owning actor.
-   * @param[in] event The mouse wheel event.
-   * @return True if the event should be consumed.
-   */
-  virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
+  bool OnWheelEvent(Actor actor, const WheelEvent& event);
 
   /**
    * @copydoc Toolkit::Control::OnInitialize()
@@ -547,14 +579,14 @@ private: // private overriden functions from CustomActorImpl and Controls
   virtual void OnInitialize();
 
   /**
-   * @copydoc Toolkit::Control::OnControlStageConnection()
+   * @copydoc CustomActorImpl::OnSceneConnection()
    */
-  virtual void OnControlStageConnection();
+  virtual void OnSceneConnection( int depth );
 
   /**
-   * @copydoc Toolkit::Control::OnControlStageConnection()
+   * @copydoc CustomActorImpl::OnSceneDisconnection()
    */
-  virtual void OnControlStageDisconnection();
+  virtual void OnSceneDisconnection();
 
   /**
    * @copydoc Toolkit::Control::OnAccessibilityPan()
@@ -562,13 +594,24 @@ private: // private overriden functions from CustomActorImpl and Controls
   virtual bool OnAccessibilityPan(PanGesture gesture);
 
   /**
-   * @copydoc Toolkit::Scrollable::SetOvershootEnabled()
+   * @copydoc Toolkit::Scrollable::EnableScrollOvershoot()
    */
-  virtual void SetOvershootEnabled(bool enable);
+  virtual void EnableScrollOvershoot(bool enable);
 
 private:
 
   /**
+   * Called after a touchSignal is received by the owning actor.
+   *
+   * We don't consume these events as content within the container may consume events.
+   *
+   * @param[in] actor The touched actor.
+   * @param[in] touch The touch information.
+   * @return True if the event should be consumed.
+   */
+  bool OnTouch( Actor actor, const TouchEvent& touch );
+
+  /**
    * Start a timer which calls OnTouchDownTimeout()
    */
   void StartTouchDownTimer();
@@ -653,12 +696,10 @@ private:
 
   /**
    * This is called internally whenever the Scroll Rulers are
-   * modified. This will update the properties: 'scroll-position-min'
-   * and 'scroll-position-max' to reflect the changes.
-   *
-   * @param[in] size size of the visible scroll area (ScrollView control size)
+   * modified. This will update the properties: 'scrollPositionMin'
+   * and 'scrollPositionMax' to reflect the changes.
    */
-  void UpdatePropertyDomain(const Vector3& size);
+  void UpdatePropertyDomain();
 
   /**
    * Called when the gesture starts.
@@ -684,7 +725,7 @@ private:
    *
    * @param[in] gesture The gesture event.
    */
-  void OnGestureEx(Gesture::State state);
+  void OnGestureEx(GestureState state);
 
   /**
    * Performs snapping while taking into account Velocity of gesture
@@ -712,14 +753,14 @@ private:
    *
    * @param[in] position The position for which you wish to obtain overshoot vector
    */
-  Vector3 GetOvershoot(Vector3& position) const;
+  Vector2 GetOvershoot(Vector2& position) const;
 
   /**
    * Clamps position within the domain set up by X/Y Rulers
    *
    * @param[in,out] position The position you wish to clamp
    */
-  void ClampPosition(Vector3& position) const;
+  void ClampPosition(Vector2& position) const;
 
   /**
    * Clamps position within the domain set up by X/Y Rulers
@@ -727,7 +768,7 @@ private:
    * @param[in,out] position The position you wish to clamp
    * @param[out] clamped The results of the clamping.
    */
-  void ClampPosition(Vector3& position, ClampState3D &clamped) const;
+  void ClampPosition(Vector2& position, ClampState2D &clamped) const;
 
   /**
    * Wraps position within the domain set up by X/Y Rulers
@@ -737,7 +778,7 @@ private:
    *
    * @param[in,out] position The position you wish to wrap
    */
-  void WrapPosition(Vector3& position) const;
+  void WrapPosition(Vector2& position) const;
 
   /**
    * Updates the main internal scroll constraints with new ruler and domain
@@ -786,14 +827,14 @@ private:
    *
    * @return The current position
    */
-  Vector3 GetPropertyPrePosition() const;
+  Vector2 GetPropertyPrePosition() const;
 
   /**
    * Gets position property.
    *
    * @return The current position
    */
-  Vector3 GetPropertyPosition() const;
+  Vector2 GetPropertyPosition() const;
 
   /**
    * Handles a Stopped animation. Its position properties need to be saved, and the animation flag
@@ -819,6 +860,13 @@ private:
    */
   void OnScrollUpdateNotification(Dali::PropertyNotification& source);
 
+  /**
+   * Set up default rulers using a property map
+   * @param[in] scrollModeMap A map defining the characteristics of X and Y scrolling
+   * using either FixedRuler or DefaultRuler.
+   */
+  void SetScrollMode( const Property::Map& scrollModeMap );
+
 private:
 
   // Undefined
@@ -833,22 +881,22 @@ private:
 
   int mGestureStackDepth;               ///< How many gestures are currently occuring.
   Vector2 mPanStartPosition;            ///< Where the pan gesture's touch down occured
-  Vector3 mPanDelta;                    ///< Amount currently panned.
+  Vector2 mPanDelta;                    ///< Amount currently panned.
 
   unsigned int mScrollStateFlags;       ///< flags indicating current state of scrolling
   // Scroll delegate pre and post position properties...
-  Vector3 mScrollPrePosition;           ///< Wrapped scroll position, but not clamped
-  Vector3 mScrollPostPosition;          ///< Wrapped and clamped, this is the final scroll position used
-  Vector3 mScrollTargetPosition;        ///< Final target position for an animated scroll
-  Vector3 mDomainOffset;                ///< Domain offset (this keeps track of the domain boundaries that scroll positions traverses)
+  Vector2 mScrollPrePosition;           ///< Wrapped scroll position, but not clamped
+  Vector2 mScrollPostPosition;          ///< Wrapped and clamped, this is the final scroll position used
+  Vector2 mScrollTargetPosition;        ///< Final target position for an animated scroll
+  Vector2 mDomainOffset;                ///< Domain offset (this keeps track of the domain boundaries that scroll positions traverses)
 
   // Rulers for each axes...
   RulerPtr mRulerX;
   RulerPtr mRulerY;
 
   // Last property values set to ScrollView
-  Vector3 mMinScroll;
-  Vector3 mMaxScroll;
+  Vector2 mMinScroll;
+  Vector2 mMaxScroll;
 
   Animation mInternalXAnimation;        ///< Animates mPropertyX to a snap position or application requested scroll position
   Animation mInternalYAnimation;        ///< Animates mPropertyY to a snap position or application requested scroll position
@@ -857,7 +905,7 @@ private:
   Vector2 mLastVelocity;                ///< Record the last velocity from PanGesture (Finish event doesn't have correct velocity)
   LockAxis mLockAxis;
 
-  Timer mTouchDownTimer;                ///< Used to interrupt snap-animation. This cannot be done in OnTouchEvent without breaking fast flick behavior.
+  Timer mTouchDownTimer;                ///< Used to interrupt snap-animation. This cannot be done in OnTouch without breaking fast flick behavior.
 
   float mScrollUpdateDistance;          ///< Distance for scrolling to travel for the scroll update notifications
   Dali::PropertyNotification mScrollXUpdateNotification; ///< scroll x position update notification
@@ -869,7 +917,7 @@ private:
 
   Vector2   mMaxOvershoot;                      ///< Number of scrollable pixels that will take overshoot from 0.0f to 1.0f
   Vector2   mUserMaxOvershoot;                  ///< Set by user, allows overriding of default max overshoot for the scroll indicator
-  float     mSnapOvershootDuration;             ///< Duration for overshoot snapping back to Vector3::ZERO
+  float     mSnapOvershootDuration;             ///< Duration for overshoot snapping back to Vector2::ZERO
   AlphaFunction mSnapOvershootAlphaFunction;    ///< AlphaFunction to be used for this overshoot.
 
   float mSnapDuration;                          ///< Time for the snap animation to take (in seconds).
@@ -885,7 +933,7 @@ private:
   float mFlickSpeedCoefficient;                 ///< Flick velocity coefficient. Input touch velocity is multiplied by this.
   float mMaxFlickSpeed;                         ///< Maximum flick speed. Maximum speed of flick in stage.lengths/sec.
 
-  Vector2 mMouseWheelScrollDistanceStep;        ///< The step of scroll distance in actor coordinates in X and Y axes for each mouse wheel event received.
+  Vector2 mWheelScrollDistanceStep;        ///< The step of scroll distance in actor coordinates in X and Y axes for each wheel event received.
 
   //ScrollInternalConstraintsPtr mScrollInternalConstraints;
   Constraint mScrollMainInternalPrePositionConstraint;
@@ -895,13 +943,15 @@ private:
   Constraint mScrollMainInternalDeltaConstraint;
   Constraint mScrollMainInternalFinalConstraint;
   Constraint mScrollMainInternalRelativeConstraint;
+  Constraint mScrollMainInternalDomainConstraint;
+  Constraint mScrollMainInternalPrePositionMaxConstraint;
 
   ScrollOvershootIndicatorPtr mOvershootIndicator;
+  WeakHandle<Toolkit::ScrollBar> mScrollBar;
 
   Toolkit::ScrollView::SnapStartedSignalType mSnapStartedSignal;
 
-  bool mInAccessibilityPan : 1;           ///< With AccessibilityPan its easier to move between snap positions
-  bool mInitialized:1;
+  bool mInAccessibilityPan:1;             ///< With AccessibilityPan its easier to move between snap positions
   bool mScrolling:1;                      ///< Flag indicating whether the scroll view is being scrolled (by user or animation)
   bool mScrollInterrupted:1;              ///< Flag set for when a down event interrupts a scroll
   bool mPanning:1;                        ///< Whether scroll view is currently panning or not
@@ -915,6 +965,7 @@ private:
   bool mDefaultMaxOvershoot:1;            ///< Whether to use default max overshoot or application defined one
   bool mCanScrollHorizontal:1;            ///< Local value of our property to check against
   bool mCanScrollVertical:1;              ///< Local value of our property to check against
+  bool mTransientScrollBar:1;             ///< True if scroll-bar should be automatically show/hidden during/after panning
 };
 
 } // namespace Internal
@@ -943,4 +994,4 @@ inline const Toolkit::Internal::ScrollView& GetImpl(const Toolkit::ScrollView& s
 
 } // namespace Dali
 
-#endif // __DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H__
+#endif // DALI_TOOLKIT_INTERNAL_SCROLL_VIEW_H