[AT-SPI] Squashed implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-bar / scroll-bar-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H
3
4 /*
5  * Copyright (c) 2020 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/constraint.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/public-api/common/dali-vector.h>
26 #include <dali/public-api/object/property-notification.h>
27 #include <dali/public-api/object/weak-handle.h>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/public-api/controls/control-impl.h>
31 #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
32 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
33
34 namespace Dali
35 {
36
37 namespace Toolkit
38 {
39
40 namespace Internal
41 {
42
43 class ScrollBar;
44
45 typedef IntrusivePtr<ScrollBar> ScrollBarPtr;
46
47 /**
48  * ScrollBar is a UI component that can be added to the scrollable controls
49  * indicating the current scroll position of the scrollable content.
50  */
51 class ScrollBar : public Control
52 {
53
54 public:
55
56   // Signals
57   typedef Toolkit::ScrollBar::PanFinishedSignalType PanFinishedSignalType;
58   typedef Toolkit::ScrollBar::ScrollPositionIntervalReachedSignalType ScrollPositionIntervalReachedSignalType;
59
60 public:
61
62   /**
63    * @copydoc Toolkit::ScrollBar::New()
64    */
65   static Toolkit::ScrollBar New(Toolkit::ScrollBar::Direction direction);
66
67   /**
68    * @copydoc Toolkit::ScrollBar::SetScrollPropertySource()
69    */
70   void SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize );
71
72   /**
73    * @copydoc Toolkit::ScrollBar::SetScrollIndicator()
74    */
75   void SetScrollIndicator( Actor indicator );
76
77   /**
78    * @copydoc Toolkit::ScrollBar::GetScrollIndicator()
79    */
80   Actor GetScrollIndicator();
81
82   /**
83    * @copydoc Toolkit::ScrollBar::SetScrollPositionIntervals()
84    */
85   void SetScrollPositionIntervals( const Dali::Vector<float>& positions );
86
87   /**
88    * @copydoc Toolkit::ScrollBar::GetScrollPositionIntervals()
89    */
90   Dali::Vector<float> GetScrollPositionIntervals() const;
91
92   /**
93    * @copydoc Toolkit::ScrollBar::SetScrollDirection()
94    */
95   void SetScrollDirection( Toolkit::ScrollBar::Direction direction );
96
97   /**
98    * @copydoc Toolkit::ScrollBar::GetScrollDirection()
99    */
100   Toolkit::ScrollBar::Direction GetScrollDirection() const;
101
102   /**
103    * @copydoc Toolkit::ScrollBar::SetIndicatorHeightPolicy()
104    */
105   void SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy );
106
107   /**
108    * @copydoc Toolkit::ScrollBar::GetIndicatorHeightPolicy()
109    */
110   Toolkit::ScrollBar::IndicatorHeightPolicy GetIndicatorHeightPolicy() const;
111
112   /**
113    * @copydoc Toolkit::ScrollBar::SetIndicatorFixedHeight()
114    */
115   void SetIndicatorFixedHeight( float height );
116
117   /**
118    * @copydoc Toolkit::ScrollBar::GetIndicatorFixedHeight()
119    */
120   float GetIndicatorFixedHeight() const;
121
122   /**
123    * @copydoc Toolkit::ScrollBar::SetIndicatorShowDuration()
124    */
125   void SetIndicatorShowDuration( float durationSeconds );
126
127   /**
128    * @copydoc Toolkit::ScrollBar::GetIndicatorShowDuration()
129    */
130   float GetIndicatorShowDuration() const;
131
132   /**
133    * @copydoc Toolkit::ScrollBar::SetIndicatorHideDuration()
134    */
135   void SetIndicatorHideDuration( float durationSeconds );
136
137   /**
138    * @copydoc Toolkit::ScrollBar::GetIndicatorHideDuration()
139    */
140   float GetIndicatorHideDuration() const;
141
142   /**
143    * @copydoc Toolkit::ScrollBar::ShowIndicator()
144    */
145   void ShowIndicator();
146
147   /**
148    * @copydoc Toolkit::ScrollBar::HideIndicator()
149    */
150   void HideIndicator();
151
152   /**
153    * @brief Shows indicator until the transient duration has expired
154    */
155   void ShowTransientIndicator();
156
157  /**
158   * @copydoc Toolkit::ScrollBar::PanFinishedSignal()
159   */
160  PanFinishedSignalType& PanFinishedSignal()
161  {
162    return mPanFinishedSignal;
163  }
164
165  /**
166   * @copydoc Toolkit::ScrollBar::ScrollPositionIntervalReachedSignal()
167   */
168  ScrollPositionIntervalReachedSignalType& ScrollPositionIntervalReachedSignal()
169  {
170    return mScrollPositionIntervalReachedSignal;
171  }
172
173  /**
174   * Connects a callback function with the object's signals.
175   * @param[in] object The object providing the signal.
176   * @param[in] tracker Used to disconnect the signal.
177   * @param[in] signalName The signal to connect to.
178   * @param[in] functor A newly allocated FunctorDelegate.
179   * @return True if the signal was connected.
180   * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
181   */
182  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
183
184  // Properties
185
186  /**
187   * Called when a property of an object of this type is set.
188   * @param[in] object The object whose property is set.
189   * @param[in] index The property index.
190   * @param[in] value The new property value.
191   */
192  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
193
194  /**
195   * Called to retrieve a property of an object of this type.
196   * @param[in] object The object whose property is to be retrieved.
197   * @param[in] index The property index.
198   * @return The current value of the property.
199   */
200  static Property::Value GetProperty( BaseObject* object, Property::Index index );
201
202  /**
203   * Performs actions as requested using the action name.
204   * @param[in] object The object on which to perform the action.
205   * @param[in] actionName The action to perform.
206   * @param[in] attributes The attributes with which to perfrom this action.
207   * @return true if action has been accepted by this control
208   */
209  static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
210
211 private: // from Control
212
213   /**
214    * @copydoc Toolkit::Control::OnInitialize
215    */
216   void OnInitialize() override;
217
218   /**
219    * @copydoc Toolkit::Control::OnPan
220    */
221   void OnPan( const PanGesture& gesture ) override;
222
223   /**
224    * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
225    */
226   void OnSizeSet( const Vector3& size ) override;
227
228 private:
229
230   /**
231    * Create the default indicator actor.
232    */
233   void CreateDefaultIndicatorActor();
234
235   /**
236    * Apply constraints for background and indicator.
237    * These constraints are based on values from the scroll connector.
238    */
239   void ApplyConstraints();
240
241   /**
242    * Callback when the current scroll position of the scrollable content goes above or
243    * below the values specified by SetScrollPositionIntervals().
244    * @param[in] source the property notification that triggered this callback
245    */
246   void OnScrollPositionIntervalReached(PropertyNotification& source);
247
248   /**
249    * Process the pan gesture per predefined timeout until the gesture is finished.
250    * @return True if the timer should be kept running.
251    */
252   bool OnPanGestureProcessTick();
253
254   /**
255    * Handle SetProperty for scroll direction.
256    * @param[in] propertyValue The new property value.
257    */
258   void OnScrollDirectionPropertySet(Property::Value propertyValue);
259
260   /**
261    * Handle SetProperty for scroll indicator height policy.
262    * @param[in] propertyValue The new property value.
263    */
264   void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
265
266 private:
267
268   /**
269    * Constructor.
270    * It initializes ScrollBar members.
271    */
272   ScrollBar( Toolkit::ScrollBar::Direction direction );
273
274   /**
275    * A reference counted object may only be deleted by calling Unreference()
276    */
277   virtual ~ScrollBar();
278
279 private:
280
281   Actor mIndicator;                                                  ///< Image of scroll indicator.
282   float mIndicatorShowAlpha;                                         ///< The alpha value when the indicator is fully shown
283   Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
284
285   Toolkit::ScrollBar::Direction mDirection;                          ///< The direction of scroll bar (vertical or horizontal)
286
287   WeakHandle<Handle> mScrollableObject;                              ///< Object to be scrolled
288
289   Property::Index mPropertyScrollPosition = 0;                       ///< Index of scroll position property owned by the object to be scrolled
290   Property::Index mPropertyMinScrollPosition = 0;                    ///< Index of minimum scroll position property owned by the object to be scrolled
291   Property::Index mPropertyMaxScrollPosition = 1;                    ///< Index of maximum scroll position property owned by the object to be scrolled
292   Property::Index mPropertyScrollContentSize;                        ///< Index of scroll content size property owned by the object to be scrolled
293
294   float mIndicatorShowDuration;                                      ///< The duration of scroll indicator show animation
295   float mIndicatorHideDuration;                                      ///< The duration of scroll indicator hide animation
296   float mTransientIndicatorDuration;                                 ///< The duration before hiding transient indicator
297
298   float mScrollStart;                                                ///< Scroll Start position (start of drag)
299   Vector2 mGestureDisplacement;                                      ///< Gesture Displacement.
300
301   float mCurrentScrollPosition;                                      ///< The current scroll position updated by the pan gesture
302
303   Toolkit::ScrollBar::IndicatorHeightPolicy mIndicatorHeightPolicy;  ///< The height policy of scroll indicator (variable or fixed)
304   float mIndicatorFixedHeight;                                       ///< The fixed height of scroll indicator
305   float mIndicatorMinimumHeight;                                     ///< The minimum height for a variable size indicator
306   float mIndicatorStartPadding;                                      ///< The padding at the start of the indicator
307   float mIndicatorEndPadding;                                        ///< The padding at the end of the indicator
308
309   Timer mContractDelayTimer;                                         ///< Timer guarantee contract delay time.
310   Timer mPanProcessTimer;                                            ///< The timer to process the pan gesture after the gesture is started.
311
312   Dali::Vector<float> mScrollPositionIntervals;                      ///< List of values to receive notification for when the current scroll position goes above or below them
313   PropertyNotification mPositionNotification;                        ///< Stores the property notification used for scroll position changes
314
315   PanFinishedSignalType mPanFinishedSignal;
316   ScrollPositionIntervalReachedSignalType mScrollPositionIntervalReachedSignal;
317
318   Constraint mIndicatorPositionConstraint;
319   Constraint mIndicatorSizeConstraint;
320
321   bool mIsPanning                 : 1;                               ///< Whether the scroll bar is being panned.
322   bool mIndicatorFirstShow        : 1;                               ///< True if the indicator has never been shown
323
324 protected:
325   struct AccessibleImpl : public Control::Impl::AccessibleImpl,
326                           public virtual Dali::Accessibility::Value
327   {
328     using Control::Impl::AccessibleImpl::AccessibleImpl;
329     double GetMinimum() override;
330     double GetCurrent() override;
331     double GetMaximum() override;
332     bool SetCurrent( double ) override;
333     double GetMinimumIncrement() override;
334   };
335 };
336
337 } // namespace Internal
338
339 // Helpers for public-api forwarding methods
340
341 inline Toolkit::Internal::ScrollBar& GetImpl(Toolkit::ScrollBar& scrollBar)
342 {
343   DALI_ASSERT_ALWAYS(scrollBar);
344
345   Dali::RefObject& handle = scrollBar.GetImplementation();
346
347   return static_cast<Toolkit::Internal::ScrollBar&>(handle);
348 }
349
350 inline const Toolkit::Internal::ScrollBar& GetImpl(const Toolkit::ScrollBar& scrollBar)
351 {
352   DALI_ASSERT_ALWAYS(scrollBar);
353
354   const Dali::RefObject& handle = scrollBar.GetImplementation();
355
356   return static_cast<const Toolkit::Internal::ScrollBar&>(handle);
357 }
358
359 } // namespace Toolkit
360
361 } // namespace Dali
362
363 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_BAR_H