Add APIs of webview settings.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / slider / slider-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SLIDER_H
2 #define DALI_TOOLKIT_INTERNAL_SLIDER_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/adaptor-framework/timer.h>
23 #include <dali/public-api/object/property-array.h>
24 #include <dali/public-api/object/property-map.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
30 #include <dali-toolkit/public-api/controls/slider/slider.h>
31 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
32
33 namespace Dali
34 {
35 namespace Toolkit
36 {
37 class Button;
38
39 namespace Internal
40 {
41 class Slider;
42
43 typedef Dali::IntrusivePtr<Slider> SliderPtr;
44
45 /**
46  * @copydoc Toolkit::Slider
47  */
48 class Slider : public Control
49 {
50 public:
51   typedef Property::Array MarkList;
52
53   /**
54    * Create a new Slider.
55    *
56    * @return A public handle to the newly allocated Slider.
57    */
58   static Dali::Toolkit::Slider New();
59
60 public:
61   // Properties
62
63   /**
64    * Set marks from a list
65    *
66    * @param[in] marks The list of marks to set
67    */
68   void SetMarks(const MarkList& marks);
69
70   /**
71    * Get the list of marks
72    *
73    * @return The marks list
74    */
75   const MarkList& GetMarks() const;
76
77   /**
78    * Set if should snap to marks or not
79    *
80    * @param[in] snap Flag to snap to marks or not
81    */
82   void SetSnapToMarks(bool snap);
83
84   /**
85    * Return if snap to marks is set or not
86    *
87    * @return If snap to marks is set
88    */
89   bool GetSnapToMarks() const;
90
91   /**
92    * Set the value of the slider
93    *
94    * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
95    */
96   void SetValue(float value);
97
98   /**
99    * Get the value of the slider
100    *
101    * @return The current value of the slider
102    */
103   float GetValue() const;
104
105   /**
106    * Set hit region
107    *
108    * @param[in] region The hit region
109    */
110   void SetHitRegion(const Vector2& region);
111
112   /**
113    * Get hit region
114    *
115    * @return The hit region
116    */
117   const Vector2& GetHitRegion() const;
118
119   /**
120    * Set the track region
121    *
122    * @param[in] region The track region
123    */
124   void SetTrackRegion(const Vector2& region);
125
126   /**
127    * Get the track region
128    *
129    * @return The track region
130    */
131   const Vector2& GetTrackRegion() const;
132
133   /**
134    * @brief Set the disabled color.
135    *
136    * @param[in] color The disabled color.
137    */
138   void SetDisabledColor(const Vector4& color);
139
140   /**
141    * @brief Get disabled color
142    *
143    * @return The disabled color
144    */
145   Vector4 GetDisabledColor() const;
146
147   /**
148    * Set the value precision to be used for numbers in the slider
149    *
150    * @param[in] precision The number of decimal places to use for printing numbers
151    */
152   void SetValuePrecision(int precision);
153
154   /**
155    * Get value precision
156    *
157    * @return The value precision
158    */
159   int GetValuePrecision() const;
160
161   /**
162    * Show the popup
163    *
164    * @param[in] showPopup The show popup flag
165    */
166   void SetShowPopup(bool showPopup);
167
168   /**
169    * Get show value in popup
170    *
171    * @return The show value flag
172    */
173   bool GetShowPopup() const;
174
175   /**
176    * Set show value on handle
177    *
178    * @param[in] showValue The show value flag
179    */
180   void SetShowValue(bool showValue);
181
182   /**
183    * Get show value on handle
184    *
185    * @return The show value flag
186    */
187   bool GetShowValue() const;
188
189   /**
190    * Set enabled
191    *
192    * param[in] enabled Set the enabled flag
193    */
194   void SetEnabled(bool enabled);
195
196   /**
197    * Return if enabled or not
198    *
199    * @return If enabled
200    */
201   bool IsEnabled() const;
202
203   /**
204    * @brief Set the mark tolerance
205    *
206    * The tolerance is the percentage of the slider width for which snapping to
207    * marks occurs
208    *
209    * @param[in] tolerance The percentage of width for which to snap
210    */
211   void SetMarkTolerance(float tolerance);
212
213   /**
214    * Return the mark tolerance
215    *
216    * @return The tolerance set for snapping to marks
217    */
218   float GetMarkTolerance() const;
219
220 public:
221   //Signals
222
223   /**
224    * @copydoc Toolkit::Slider::ValueChangedSignal()
225    */
226   Toolkit::Slider::ValueChangedSignalType& ValueChangedSignal();
227
228   /**
229    * copydoc Toolkit::Slider::SlidingFinishedSignal()
230    */
231   Toolkit::Slider::ValueChangedSignalType& SlidingFinishedSignal();
232
233   /**
234    * @copydoc Toolkit::Slider::MarkReachedSignal()
235    */
236   Toolkit::Slider::MarkReachedSignalType& MarkReachedSignal();
237
238   /**
239    * Connects a callback function with the object's signals.
240    * @param[in] object The object providing the signal.
241    * @param[in] tracker Used to disconnect the signal.
242    * @param[in] signalName The signal to connect to.
243    * @param[in] functor A newly allocated FunctorDelegate.
244    * @return True if the signal was connected.
245    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
246    */
247   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
248
249   // Properties
250
251   /**
252    * Called when a property of an object of this type is set.
253    * @param[in] object The object whose property is set.
254    * @param[in] index The property index.
255    * @param[in] value The new property value.
256    */
257   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
258
259   /**
260    * Called to retrieve a property of an object of this type.
261    * @param[in] object The object whose property is to be retrieved.
262    * @param[in] index The property index.
263    * @return The current value of the property.
264    */
265   static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
266
267 protected:
268   /**
269    * Construct a new Slider.
270    */
271   Slider();
272
273   /**
274    * A reference counted object may only be deleted by calling Unreference()
275    */
276   virtual ~Slider();
277
278   /**
279    * @copydoc CustomActorImpl::OnRelayout
280    */
281   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
282
283 private:
284   /**
285    * Domain is a from/to pair
286    */
287   struct Domain
288   {
289     Vector2 from;
290     Vector2 to;
291
292     Domain()
293     {
294     }
295     Domain(Vector2 fromVal, Vector2 toVal)
296     : from(fromVal),
297       to(toVal)
298     {
299     }
300   };
301
302   /**
303    * Slider states
304    */
305   enum SliderState
306   {
307     NORMAL,
308     DISABLED,
309     PRESSED,
310     FOCUSED
311   };
312
313 private:
314   /**
315    * @copydoc Toolkit::Control::OnInitialize()
316    */
317   void OnInitialize() override;
318
319   /**
320    * Hit region touch
321    *
322    * @param[in] actor The actor the event is raised for
323    * @param[in] touch The touch info
324    * @return If touch is handled or not
325    */
326   bool OnTouch(Actor actor, const TouchEvent& touch);
327
328   /**
329    * Pan gesture event
330    *
331    * @param[in] actor The actor the event is raised for
332    * @param[in] gesture The pan event info
333    */
334   void OnPan(Actor actor, const PanGesture& gesture);
335
336   /**
337    * Map a position onto a domain and return the result as a percentage
338    *
339    * @param[in] point The point to map onto the domain
340    * @return The result as a percentage [0..1]
341    */
342   float MapPercentage(const Vector2& point);
343
344   /**
345    * Map a value in the range to a percentage
346    *
347    * @param[in] point The value in range [lowerBound..upperBound]
348    * @return The result as a percentage [0..1]
349    */
350   float MapValuePercentage(float value);
351
352   /**
353    * Convert a point in local hit space into domain space
354    *
355    * @param[in] x The x position to convert
356    * @return The x position in domain space
357    */
358   float HitSpaceToDomain(float x);
359
360   /**
361    * Map a percentage onto the slider's bounds
362    *
363    * @param[in] percent The current value of slider in percent
364    * @param[in] lowerBound The lower bound to map onto
365    * @param[in] upperBound The upper bound to map onto
366    * @return The value of percent mapped from lowerBound to upperBound
367    */
368   float MapBounds(float percent, float lowerBound, float upperBound);
369
370   /**
371    * Get the range of the valid values the slider handle can move between
372    *
373    * @param[in] currentSize The current size of the slider
374    * @return The range as a domain pair
375    */
376   Domain CalcDomain(const Vector2& currentSize);
377
378   /**
379    * Create the hit region
380    *
381    * @return The hit region actor
382    */
383   Actor CreateHitRegion();
384
385   /**
386    * Create the track for the slider
387    *
388    * @return The track actor
389    */
390   Toolkit::ImageView CreateTrack();
391
392   /**
393    * Create the progress track for the slider
394    *
395    * @return The track actor
396    */
397   Toolkit::ImageView CreateProgress();
398
399   /**
400    * Create the handle for the slider
401    *
402    * @return The created image handle
403    */
404   Toolkit::ImageView CreateHandle();
405
406   /**
407    * Create the popup arrow
408    *
409    * @return The created image handle
410    */
411   Toolkit::ImageView CreatePopupArrow();
412
413   /**
414    * Create the popup
415    *
416    * @return The created image handle
417    */
418   Toolkit::ImageView CreatePopup();
419
420   /**
421    * Create the textview for the popup
422    *
423    * @return The textview created for the popup
424    */
425   Toolkit::TextLabel CreatePopupText();
426
427   /**
428    * Create the value display for the slider
429    *
430    * @return The created root actor of the display
431    */
432   Actor CreateValueDisplay();
433
434   /**
435    * Set the skin based on the current state
436    */
437   void UpdateSkin();
438
439   /**
440    * Create all the children
441    */
442   void CreateChildren();
443
444   /**
445    * Create value popup
446    */
447   void AddPopup();
448
449   /**
450    * Remove value popup
451    */
452   void RemovePopup();
453
454   /**
455    * Display the popup for a set duration with the given value
456    *
457    * @param[in] value The value to display in the popup
458    */
459   void DisplayPopup(float value);
460
461   /**
462    * If there are marks present, filter the incoming percent based on snapping to any nearby marks
463    *
464    * @param[in] value The incoming value on the slider to filter
465    * @return The filtered percentage snapped to any nearby marks
466    */
467   float MarkFilter(float value);
468
469   /**
470    * If there are marks present, snap the incoming percent to the nearest mark
471    *
472    * @param[in] value The incoming value on the slider to snap
473    * @return The filtered percentage snapped to the nearest mark
474    */
475   float SnapToMark(float value);
476
477   /**
478    * Search for if a mark has been reached
479    *
480    * @param[in] value The value to search against
481    * @param[out] outIndex The index of the mark if found
482    * @return If a mark has been found to match percent
483    */
484   bool MarkReached(float value, int& outIndex);
485
486   /**
487    * Handler for when the value view needs to be hidden
488    *
489    * @return If handled or not
490    */
491   bool HideValueView();
492
493   /**
494    * Set value choosing whether to fire signals or not
495    *
496    * @paramp[in] value The value to set
497    * @param[in] raiseSignals Configure signals to be raised or not.
498    */
499   void DisplayValue(float value, bool raiseSignals);
500
501   /**
502    * Create the image for the track
503    *
504    * @param[in] filename The track image
505    */
506   void SetTrackVisual(const std::string& filename);
507
508   /**
509    * @brief Set the track visual from an Dali::Property::Map
510    *
511    * @param[in] map The Dali::Property::Map to use for to display
512    */
513   void SetTrackVisual(Dali::Property::Map map);
514
515   /**
516    * @brief Return the track image.
517    *
518    * @return The track image.
519    */
520   std::string GetTrackVisual();
521
522   /**
523    * Create the image for the progress bar
524    *
525    * @param[in] filename The progress bar image
526    */
527   void SetProgressVisual(const std::string& filename);
528
529   /**
530    * @brief Set the progress visual from an Dali::Property::Map
531    *
532    * @param[in] map The Dali::Property::Map to use for to display
533    */
534   void SetProgressVisual(Dali::Property::Map map);
535
536   /**
537    * @brief Return the progress bar image.
538    *
539    * @return The progress bar image if it exists.
540    */
541   std::string GetProgressVisual();
542
543   /**
544    * @brief Create the image for the popup
545    *
546    * @param[in] filename The popup image
547    */
548   void CreatePopupImage(const std::string& filename);
549
550   /**
551    * @brief Set the popup image
552    *
553    * @param[in] filename The popup image to set
554    */
555   void SetPopupVisual(const std::string& filename);
556
557   /**
558    * @brief Set the popup from an Dali::Property::Map
559    *
560    * @param[in] map The Dali::Property::Map to use for to display
561    */
562   void SetPopupVisual(Dali::Property::Map map);
563
564   /**
565    * @brief Return the popup image.
566    *
567    * @return The popup image if it exists.
568    */
569   std::string GetPopupVisual();
570
571   /**
572    * @brief Set the popup arrow image
573    *
574    * @param[in] filename The popup arrow image to set
575    */
576   void SetPopupArrowVisual(const std::string& filename);
577
578   /**
579    * @brief Set the popup arrow from an Dali::Property::Map
580    *
581    * @param[in] map The Dali::Property::Map to use for to display
582    */
583   void SetPopupArrowVisual(Dali::Property::Map map);
584
585   /**
586    * @brief Return the popup arrow image.
587    *
588    * @return The popup arrow image if it exists.
589    */
590   std::string GetPopupArrowVisual();
591
592   /**
593    * Create the image for the popup arrow
594    *
595    * @param[in] filename The popup arrow image to load and set
596    */
597   void CreatePopupArrowImage(const std::string& filename);
598
599   /**
600    * Set the size of the progress bar region
601    *
602    * @param[in] region The size of the region to set
603    */
604   void ResizeProgressRegion(const Vector2& region);
605
606   /**
607    * Create the image for the handle
608    *
609    * @param[in] filename The handle image
610    */
611   void SetHandleVisual(const std::string& filename);
612
613   /**
614    * @brief Set the handle visual from an Dali::Property::Map
615    *
616    * @param[in] map The Dali::Property::Map to use for to display
617    */
618   void SetHandleVisual(Property::Map map);
619
620   /**
621    * @brief Return the handle image.
622    *
623    * @return The handle image if it exists.
624    */
625   std::string GetHandleVisual();
626
627   /**
628    * Reset the size of the handle
629    *
630    * @param[in] size The size of the handle to set
631    */
632   void ResizeHandleSize(const Vector2& size);
633
634   /**
635    * Create and display the value on the handle
636    */
637   void CreateHandleValueDisplay();
638
639   /**
640    * Remove and destroy the handle value display
641    */
642   void DestroyHandleValueDisplay();
643
644   /**
645    * Set the size of the handle
646    *
647    * @param[in] size The handle size
648    */
649   void SetHandleSize(const Vector2& size);
650
651   /**
652    * Get the size of the handle
653    *
654    * @return The handle size
655    */
656   const Vector2& GetHandleSize() const;
657
658   /**
659    * Set the lower bound of the slider's value
660    *
661    * @param[in] bound The value to set for the lower bound
662    */
663   void SetLowerBound(float bound);
664
665   /**
666    * Get the lower bound of the slider's value
667    *
668    * @return The lower bound value
669    */
670   float GetLowerBound() const;
671
672   /**
673    * Set the upper bound of the slider's value
674    *
675    * @param[in] bound The value to set for the upper bound
676    */
677   void SetUpperBound(float bound);
678
679   /**
680    * Get the upper bound of the slider's value
681    *
682    * @return The upper bound value
683    */
684   float GetUpperBound() const;
685
686 private:
687   // Undefined
688   Slider(const Slider&);
689
690   // Undefined
691   Slider& operator=(const Slider& rhs);
692
693 private:
694   Domain mDomain; ///< Current domain of the handle
695
696   Actor              mHitArea;      ///< The input handler
697   Actor              mValueDisplay; ///< Display of the value
698   Toolkit::ImageView mTrack;        ///< Track image
699   Toolkit::ImageView mHandle;       ///< Slider handle
700   Toolkit::ImageView mProgress;     ///< Progress bar
701   Toolkit::ImageView mPopup;        ///< Popup backing
702   Toolkit::ImageView mPopupArrow;   ///< Popup arrow backing
703
704   Toolkit::TextLabel mValueTextLabel;       //< The text value in popup
705   Toolkit::TextLabel mHandleValueTextLabel; ///< The text value on handle
706   Vector2            mHandleLastTouchPoint; ///< The last touch point for the handle
707   Timer              mValueTimer;           ///< Timer used to hide value view
708
709   Toolkit::Slider::ValueChangedSignalType mValueChangedSignal;    ///< Signal emitted when the value is changed
710   Toolkit::Slider::ValueChangedSignalType mSlidingFinishedSignal; ///< Signal emitted when a sliding is finished
711   Toolkit::Slider::MarkReachedSignalType  mMarkReachedSignal;     ///< Signal emitted when a mark is reached
712
713   SliderState mState; ///< The state of the slider
714
715   PanGestureDetector mPanDetector; ///< Hit region pan detector
716
717   MarkList mMarks; ///< List of discreet marks
718
719   std::string mPopupVisual;      ///< Image for popup image
720   std::string mPopupArrowVisual; ///< Image for popup arrow image
721   std::string mTrackVisual;      ///< Image for track image
722   std::string mHandleVisual;     ///< Image for handle image
723   std::string mProgressVisual;   ///< Image for progress bar image
724
725   Property::Map mPopupMap;      ///< the Property::Map if the image came from a Property::Map, empty otherwise
726   Property::Map mTrackMap;      ///< the Property::Map if the image came from a Property::Map, empty otherwise
727   Property::Map mHandleMap;     ///< the Property::Map if the image came from a Property::Map, empty otherwise
728   Property::Map mProgressMap;   ///< the Property::Map if the image came from a Property::Map, empty otherwise
729   Property::Map mPopupArrowMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
730
731   Vector4 mDisabledColor; ///< The color to tint the slider when disabled
732
733   Vector2 mHitRegion;   ///< Size of hit region
734   Vector2 mTrackRegion; ///< Size of track region
735   Vector2 mHandleSize;  ///< Size of the handle
736
737   float mLowerBound = 0.0f; ///< Lower bound on value
738   float mUpperBound = 1.0f; ///< Upper bound on value
739   float mValue      = 0.0f; ///< Current value of slider
740
741   float mMarkTolerance = 0.05f; ///< Tolerance in percentage of slider width for which to snap to marks
742
743   int mValuePrecision; ///< The precision to use for outputting the value
744
745   bool mShowPopup : 1, ///< Show the popup or not
746     mShowValue : 1,    ///< Whether to display the value number or not on the handle
747     mSnapToMarks : 1;  ///< Turn on or off snapping to marks
748
749 protected:
750   struct AccessibleImpl : public Control::Impl::AccessibleImpl,
751                           public virtual Dali::Accessibility::Value
752   {
753     using Control::Impl::AccessibleImpl::AccessibleImpl;
754     double GetMinimum() override;
755     double GetCurrent() override;
756     double GetMaximum() override;
757     bool   SetCurrent(double) override;
758     double GetMinimumIncrement() override;
759   };
760 };
761
762 } // namespace Internal
763
764 // Helpers for public-api forwarding methods
765
766 inline Toolkit::Internal::Slider& GetImpl(Toolkit::Slider& pub)
767 {
768   DALI_ASSERT_ALWAYS(pub);
769
770   Dali::RefObject& handle = pub.GetImplementation();
771
772   return static_cast<Toolkit::Internal::Slider&>(handle);
773 }
774
775 inline const Toolkit::Internal::Slider& GetImpl(const Toolkit::Slider& pub)
776 {
777   DALI_ASSERT_ALWAYS(pub);
778
779   const Dali::RefObject& handle = pub.GetImplementation();
780
781   return static_cast<const Toolkit::Internal::Slider&>(handle);
782 }
783
784 } // namespace Toolkit
785
786 } // namespace Dali
787
788 #endif // DALI_TOOLKIT_INTERNAL_SLIDER_H