Promote Control::Impl::AccessibleImpl to DevelControl
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scrollable-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLLABLE_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLLABLE_H
3
4 /*
5  * Copyright (c) 2021 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/animation/alpha-function.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Internal
35 {
36 class Scrollable;
37 typedef IntrusivePtr<Scrollable> ScrollablePtr;
38
39 /**
40  * @copydoc Toolkit::Scrollable
41  */
42 class Scrollable : public Control
43 {
44 public:
45   /**
46    * @copydoc Dali::Toolkit::Scrollable::IsOvershootEnabled
47    */
48   bool IsOvershootEnabled() const;
49
50   /**
51    * @copydoc Dali::Toolkit::Scrollable::SetOvershootEnabled
52    */
53   void SetOvershootEnabled(bool enable);
54
55   /**
56    * Adds actor as an Overlay to Scrollable
57    * This method is called by Add-on UI components
58    * such as scroll bars, page indicators.
59    * @param[in] actor Actor to add as an overlay.
60    */
61   virtual void AddOverlay(Actor actor) = 0;
62
63   /**
64    * Removes overlay actor from Scrollable
65    * This method is called by Add-on UI components
66    * such as scroll bars, page indicators.
67    * @param[in] actor Actor overlay to remove.
68    */
69   virtual void RemoveOverlay(Actor actor) = 0;
70
71   /**
72    * Retrieves current scroll position.
73    * @returns The current scroll position.
74    */
75   virtual Vector2 GetCurrentScrollPosition() const = 0;
76
77   /**
78    * Scrolls Scrollable to position specified (contents will scroll to this position)
79    * Position 0,0 is the origin. Increasing X scrolls contents left, while
80    * increasing Y scrolls contents up.
81    * @param[in] position The position to scroll to.
82    * @param[in] duration The duration of the animation in seconds
83    */
84   virtual void ScrollTo(const Vector2& position, float duration) = 0;
85
86   /**
87    * Set the color of the overshoot effect.
88    * @parm[in] color The color of the overshoot effect
89    */
90   virtual void SetOvershootEffectColor(const Vector4& color) = 0;
91
92   /**
93    * Retrieve the color of the overshoot effect.
94    * @return The color of the overshoot effect.
95    */
96   Vector4 GetOvershootEffectColor() const;
97
98   /**
99    * @copydoc Dali::Toolkit::Scrollable::SetOvershootAnimationSpeed(float pixelsPerSecond)
100    */
101   void SetOvershootAnimationSpeed(float pixelsPerSecond);
102
103   /**
104    * @copydoc Dali::Toolkit::Scrollable::GetOvershootAnimationSpeed()
105    */
106   float GetOvershootAnimationSpeed() const;
107
108   /**
109    * @copydoc Dali::Toolkit::Scrollable::GetOvershootSize()
110    */
111   const Vector2& GetOvershootSize() const;
112
113   /**
114    * Set the size of the overshoot effect.
115    * @parm[in] size The size of the overshoot effect
116    */
117   virtual void SetOvershootSize(const Vector2& size) = 0;
118
119 protected: // From Control
120   struct AccessibleImpl : public DevelControl::AccessibleImpl
121   {
122     using DevelControl::AccessibleImpl::AccessibleImpl;
123
124     bool IsScrollable() override;
125   };
126
127   /**
128    * @copydoc Control::OnInitialize
129    */
130   virtual void OnInitialize() override;
131
132 private:
133   /**
134    * Temporary function to override EnableScrollOvershoot functionality for overshoot
135    * Only ScrollView needs to override this as HQ has not requested disable functionality in ItemView
136    * @param[in] enable true to enable, false to disable overshoot indicator
137    */
138   virtual void EnableScrollOvershoot(bool enable)
139   {
140   }
141
142 public: //Signals
143   /**
144    * @copydoc Dali::Toolkit::Scrollable::ScrollStartedSignal()
145    */
146   Toolkit::Scrollable::ScrollStartedSignalType& ScrollStartedSignal();
147
148   /**
149    * @copydoc Dali::Toolkit::Scrollable::ScrollUpdatedSignal()
150    */
151   Toolkit::Scrollable::ScrollUpdatedSignalType& ScrollUpdatedSignal();
152
153   /**
154    * @copydoc Dali::Toolkit::Scrollable::ScrollCompletedSignal()
155    */
156   Toolkit::Scrollable::ScrollCompletedSignalType& ScrollCompletedSignal();
157
158   /**
159    * Connects a callback function with the object's signals.
160    * @param[in] object The object providing the signal.
161    * @param[in] tracker Used to disconnect the signal.
162    * @param[in] signalName The signal to connect to.
163    * @param[in] functor A newly allocated FunctorDelegate.
164    * @return True if the signal was connected.
165    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
166    */
167   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
168
169   //properties
170
171   /**
172    * Called when a property of an object of this type is set.
173    * @param[in] object The object whose property is set.
174    * @param[in] index The property index.
175    * @param[in] value The new property value.
176    */
177   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
178
179   /**
180    * Called to retrieve a property of an object of this type.
181    * @param[in] object The object whose property is to be retrieved.
182    * @param[in] index The property index.
183    * @return The current value of the property.
184    */
185   static Property::Value GetProperty(BaseObject* object, Property::Index index);
186
187 protected:
188   /**
189    * Removed default constructor.
190    */
191   Scrollable() = delete;
192
193   /**
194    * @brief Construct a new Scrollable.
195    *
196    * @param[in] behaviourFlags Flags to enable
197    */
198   Scrollable(ControlBehaviour behaviourFlags);
199
200   /**
201    * A reference counted object may only be deleted by calling Unreference()
202    */
203   virtual ~Scrollable();
204
205 private:
206   /**
207    * Gets position property.
208    *
209    * @return The current position
210    */
211   Vector2 GetPropertyPosition() const;
212
213 private:
214   // Undefined
215   Scrollable(const Scrollable&);
216
217   // Undefined
218   Scrollable& operator=(const Scrollable& rhs);
219
220 protected:
221   Vector4 mOvershootEffectColor;    ///<The color of the overshoot bouncing effect
222   float   mOvershootAnimationSpeed; ///<The speed of the overshoot animation (pixels per second)
223   Vector2 mOvershootSize;           ///<The size of the overshoot effect
224
225   Dali::AlphaFunction::BuiltinFunction mScrollToAlphaFunction; ///< The ScrollTo() animations use this
226
227   Toolkit::Scrollable::ScrollStartedSignalType   mScrollStartedSignal;
228   Toolkit::Scrollable::ScrollUpdatedSignalType   mScrollUpdatedSignal;
229   Toolkit::Scrollable::ScrollCompletedSignalType mScrollCompletedSignal;
230
231 private:
232   bool mOvershootEnabled : 1;
233 };
234
235 } // namespace Internal
236
237 // Helpers for public-api forwarding methods
238
239 inline Toolkit::Internal::Scrollable& GetImpl(Toolkit::Scrollable& scrollable)
240 {
241   DALI_ASSERT_ALWAYS(scrollable);
242
243   Dali::RefObject& handle = scrollable.GetImplementation();
244
245   return static_cast<Toolkit::Internal::Scrollable&>(handle);
246 }
247
248 inline const Toolkit::Internal::Scrollable& GetImpl(const Toolkit::Scrollable& scrollable)
249 {
250   DALI_ASSERT_ALWAYS(scrollable);
251
252   const Dali::RefObject& handle = scrollable.GetImplementation();
253
254   return static_cast<const Toolkit::Internal::Scrollable&>(handle);
255 }
256
257 } // namespace Toolkit
258
259 } // namespace Dali
260
261 #endif // DALI_TOOLKIT_INTERNAL_SCROLLABLE_H