[AT-SPI] Squashed implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / popup / popup-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_POPUP_H
2 #define DALI_TOOLKIT_INTERNAL_POPUP_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/actors/layer.h>
23 #include <dali/public-api/adaptor-framework/timer.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/devel-api/animation/animation-data.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
30 #include <dali-toolkit/devel-api/controls/popup/popup.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 class Popup;
42
43 typedef IntrusivePtr< Popup > PopupPtr;
44
45 /**
46  * @copydoc Toolkit::Popup
47  */
48 class Popup : public Control
49 {
50 public:
51
52   /**
53    * Create a new Popup.
54    * @return A public handle to the newly allocated Popup.
55    */
56   static Dali::Toolkit::Popup New();
57
58 public:
59
60   /**
61    * @copydoc Toolkit::Popup::SetPopupBackgroundImage
62    */
63   void SetPopupBackgroundImage( Actor image );
64
65   /**
66    * @copydoc Toolkit::Popup::GetPopupBackgroundImage
67    */
68   Actor GetPopupBackgroundImage() const;
69
70   /**
71    * @copydoc Toolkit::Popup::SetTitle( Actor titleActor )
72    */
73   void SetTitle( Actor titleActor );
74
75   /**
76    * @copydoc Toolkit::Popup::GetTitle
77    */
78   Actor GetTitle() const;
79
80   /**
81    * @copydoc Toolkit::Popup::SetContent
82    */
83   void SetContent( Actor content );
84
85   /**
86    * @copydoc Toolkit::Popup::GetContent
87    */
88   Actor GetContent() const;
89
90   /**
91    * @copydoc Toolkit::Popup::SetFooter
92    */
93   void SetFooter( Actor control );
94
95   /**
96    * @copydoc Toolkit::Popup::GetFooter
97    */
98   Actor GetFooter() const;
99
100   /**
101    * @copydoc Toolkit::Popup::SetDisplayState
102    */
103   void SetDisplayState( Toolkit::Popup::DisplayState displayState );
104
105   /**
106    * @copydoc Toolkit::Popup::GetDisplayState
107    */
108   Toolkit::Popup::DisplayState GetDisplayState() const;
109
110   /**
111    * @copydoc Toolkit::Popup::SetTailVisibility
112    */
113   void SetTailVisibility( bool visible );
114
115   /**
116    * @copydoc Toolkit::Popup::IsTailVisible
117    */
118   const bool IsTailVisible() const;
119
120   /**
121    * @copydoc Toolkit::Popup::SetTailPosition
122    */
123   void SetTailPosition( Vector3 position );
124
125   /**
126    * @copydoc Toolkit::Popup::GetTailPosition
127    */
128   const Vector3& GetTailPosition() const;
129
130   /**
131    * @copydoc Toolkit::Popup::SetContextualMode
132    */
133   void SetContextualMode( Toolkit::Popup::ContextualMode mode );
134
135   /**
136    * @copydoc Toolkit::Popup::GetContextualMode
137    */
138   Toolkit::Popup::ContextualMode GetContextualMode() const;
139
140   /**
141    * @copydoc Toolkit::Popup::SetAnimationDuration
142    */
143   void SetAnimationDuration( float duration );
144
145   /**
146    * @copydoc Toolkit::Popup::GetAnimationDuration
147    */
148   float GetAnimationDuration() const;
149
150   /**
151    * @copydoc Toolkit::Popup::SetAnimationMode
152    */
153   void SetAnimationMode( Toolkit::Popup::AnimationMode animationMode );
154
155   /**
156    * @copydoc Toolkit::Popup::GetAnimationMode
157    */
158   Toolkit::Popup::AnimationMode GetAnimationMode() const;
159
160   /**
161    * @copydoc Toolkit::Popup::SetAutoHideDelay
162    */
163   void SetAutoHideDelay( int delay );
164
165   /**
166    * @copydoc Toolkit::Popup::GetAutoHideDelay
167    */
168   int GetAutoHideDelay() const;
169
170   /**
171    * @copydoc Toolkit::Popup::SetBackingEnabled
172    */
173   void SetBackingEnabled( bool enabled );
174
175   /**
176    * @copydoc Toolkit::Popup::IsBackingEnabled
177    */
178   const bool IsBackingEnabled() const;
179
180   /**
181    * @copydoc Toolkit::Popup::SetBackingColor
182    */
183   void SetBackingColor( Vector4 color );
184
185   /**
186    * @copydoc Toolkit::Popup::GetBackingColor
187    */
188   const Vector4& GetBackingColor() const;
189
190   /**
191    * @copydoc Toolkit::Popup::SetTailUpImage
192    */
193   void SetTailUpImage( std::string image );
194
195   /**
196    * @copydoc Toolkit::Popup::GetTailUpImage
197    */
198   const std::string& GetTailUpImage() const;
199
200   /**
201    * @copydoc Toolkit::Popup::SetTailDownImage
202    */
203   void SetTailDownImage( std::string image );
204
205   /**
206    * @copydoc Toolkit::Popup::GetTailDownImage
207    */
208   const std::string& GetTailDownImage() const;
209
210   /**
211    * @copydoc Toolkit::Popup::SetTailLeftImage
212    */
213   void SetTailLeftImage( std::string image );
214
215   /**
216    * @copydoc Toolkit::Popup::GetTailLeftImage
217    */
218   const std::string& GetTailLeftImage() const;
219
220   /**
221    * @copydoc Toolkit::Popup::SetTailRightImage
222    */
223   void SetTailRightImage( std::string image );
224
225   /**
226    * @copydoc Toolkit::Popup::GetTailRightImage
227    */
228   const std::string& GetTailRightImage() const;
229
230   /**
231    * Called when a property of an object of this type is set.
232    * @param[in] object The object whose property is set.
233    * @param[in] propertyIndex The property index.
234    * @param[in] value The new property value.
235    */
236   static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
237
238   /**
239    * Called to retrieve a property of an object of this type.
240    * @param[in] object The object whose property is to be retrieved.
241    * @param[in] propertyIndex The property index.
242    * @return The current value of the property.
243    */
244   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
245
246 protected:
247
248   /**
249    * Construct a new Popup.
250    */
251   Popup();
252
253   /**
254    * A reference counted object may only be deleted by calling Unreference()
255    */
256   virtual ~Popup();
257
258 private:
259
260   /**
261    * @brief Creates the layout of the popup, to be done just before showing for the first time.
262    * Also calls OnLayoutSetup() to allow derived classes to perform layout at this stage.
263    */
264   void LayoutPopup();
265
266   /**
267    * @brief Creates or destroys the popup tail based on the current TAIL_DISPLAYED property.
268    * Also uses the TAIL_POSITION property to position it.
269    */
270   void LayoutTail();
271
272   /**
273    * @brief Performs any relative positioning required based on the current contextual mode, if set.
274    * If contextual mode is not enabled, this method has no effect.
275    * @param[in] size The Popups current size (can be accessed from within the OnRelayout() method).
276    */
277   void LayoutContext( const Vector2& size );
278
279   /**
280    * @brief All transition-in animation setup and layout is done here.
281    * Different types of animation mode require different layouts to work,
282    * this function encapsulates anything animation-mode specific.
283    * This is called once for multiple displays/hides of the pops.
284    * It is only re-called when the layout becomes dirty.
285    */
286   void LayoutAnimation();
287
288   /**
289    * @brief Initiates a transition-in or transition-out animation based
290    * on the current animation settings.
291    * @param[in] transitionIn True to perform a transition-in, false for transition out.
292    * @param[in] instantaneous Optional - If set to true will override the duration to provide an instant animation.
293    */
294   void StartTransitionAnimation( bool transitionIn, bool instantaneous = false );
295
296   /**
297    * @brief Invoked once a display state change has completed.
298    */
299   void DisplayStateChangeComplete();
300
301   /**
302    * @brief This is called when the auto-hide timer finishes.
303    * It performs a display-state change to HIDDEN.
304    * @return True as signal is consumed.
305    */
306   bool OnAutoHideTimeReached();
307
308   /**
309    * @brief Create Dimmed Backing (covers all content behind the dialog).
310    *
311    * @return The backing control.
312    */
313   Toolkit::Control CreateBacking();
314
315   /**
316    * @brief Creates the lower area within the popup.
317    */
318   void CreateFooter();
319
320   /**
321    * @brief Sets if the popup allows touch events to pass through or not.
322    *
323    * @param[in] enabled Set to true to make the popup touch-transparent.
324    */
325   void SetTouchTransparent( bool enabled );
326
327   /**
328    * @brief Returns if the popup allows touch events to pass through or not.
329    *
330    * @return True if the popup is touch-transparent.
331    */
332   const bool IsTouchTransparent() const;
333
334   /**
335    * @brief Allows the popup entry animation to be setup from a Property::Map that could
336    * originate, for example, from a JSON file.
337    *
338    * @param[in] map A Property::Map containing a description of an animation
339    */
340   void SetEntryAnimationData( const Property::Map& map );
341
342   /**
343    * @brief Allows the popup exit animation to be setup from a Property::Map that could
344    * originate, for example, from a JSON file.
345    *
346    * @param[in] map A Property::Map containing a description of an animation
347    */
348   void SetExitAnimationData( const Property::Map& map );
349
350   /**
351    * @briefs Updates the popup background's position and size.
352    */
353   void UpdateBackgroundPositionAndSize();
354
355 public: // Signals
356
357   /**
358    * @copydoc Dali::Toolkit::Popup::OutsideTouchedSignal()
359    */
360   Toolkit::Popup::TouchedOutsideSignalType& OutsideTouchedSignal();
361
362   /**
363    * @copydoc Dali::Toolkit::Popup::ShowingSignal()
364    */
365   Toolkit::Popup::DisplayStateChangeSignalType& ShowingSignal();
366
367   /**
368    * @copydoc Dali::Toolkit::Popup::ShownSignal()
369    */
370   Toolkit::Popup::DisplayStateChangeSignalType& ShownSignal();
371
372   /**
373    * @copydoc Dali::Toolkit::Popup::HidingSignal()
374    */
375   Toolkit::Popup::DisplayStateChangeSignalType& HidingSignal();
376
377   /**
378    * @copydoc Dali::Toolkit::Popup::HiddenSignal()
379    */
380   Toolkit::Popup::DisplayStateChangeSignalType& HiddenSignal();
381
382   /**
383    * Connects a callback function with the object's signals.
384    * @param[in] object The object providing the signal.
385    * @param[in] tracker Used to disconnect the signal.
386    * @param[in] signalName The signal to connect to.
387    * @param[in] functor A newly allocated FunctorDelegate.
388    * @return True if the signal was connected.
389    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
390    */
391   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
392
393 private:
394
395   /**
396    * Signal occurs when the State animation (transition from hide <-> show) finishes.
397    * @param[in] source The animation that just finished.
398    */
399   void OnDisplayChangeAnimationFinished( Animation& source );
400
401   /**
402    * Signal occurs when the dimmed backing for the Popup is touched.
403    * @param[in] actor The Actor Touched
404    * @param[in] touch The Touch Data.
405    * @return Whether to consume event or not.
406    */
407   bool OnBackingTouched(Actor actor, const TouchEvent& touch);
408
409   /**
410    * Signal occurs when a mouse wheel event occurs on the dimmed backing.
411    * @param[in] actor The Actor that got the wheel event.
412    * @param[in] event The Wheel Event.
413    * @return Whether to consume event or not.
414    */
415   bool OnBackingWheelEvent(Actor actor, const WheelEvent& event);
416
417   /**
418    * Signal occurs when the dialog has been touched.
419    * @param[in] actor The Actor Touched
420    * @param[in] touch The Touch Data.
421    * @return Whether to consume event or not.
422    */
423   bool OnDialogTouched( Actor actor, const TouchEvent& touch );
424
425   /**
426    * @copydoc Toolkit::Control::OnInitialize()
427    */
428   void OnInitialize() override;
429
430   /**
431    * Called whenever the popup layout is re-set up.
432    * Normally due to a change in contents.
433    * Note: This is only done when the popup is shown.
434    */
435   virtual void OnLayoutSetup() {}
436
437   /**
438    * Called when the popup is directly or indirectly parented to the stage.
439    */
440   void OnSceneConnection( int depth ) override;
441   void OnSceneDisconnection() override;
442
443   /**
444    * From Control; called after a child has been added to the owning actor.
445    * @param[in] child The child which has been added.
446    */
447   void OnChildAdd( Actor& child ) override;
448
449   /**
450    * @copydoc Control::OnRelayOut()
451    */
452   void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
453
454   /**
455    * @copydoc Control::OnSetResizePolicy()
456    */
457   void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) override;
458
459   /**
460    * @copydoc Control::GetNaturalSize()
461    */
462   Vector3 GetNaturalSize() override;
463
464   /**
465    * @copydoc Control::GetHeightForWidth()
466    */
467   float GetHeightForWidth( float width ) override;
468
469   /**
470    * @copydoc Control::GetWidthForHeight()
471    */
472   float GetWidthForHeight( float height ) override;
473
474   /**
475    * @copydoc Control::OnKeyEvent()
476    */
477   bool OnKeyEvent( const KeyEvent& event ) override;
478
479   /**
480    * @copydoc Control::GetNextKeyboardFocusableActor()
481    */
482   Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
483
484 private:
485
486   /**
487    * Recursively add any focusable actors or layout containers to the provided vector.
488    * Include the top level actor if it is a layout container.
489    *
490    * @param[in]     parent          The actor to start from
491    * @param[in/out] focusableActors The vector to add focusable actors to
492    */
493   void AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors );
494
495   /**
496    * Recursively add any focusable actors or layout containers to the provided vector.
497    *
498    * @param[in]     parent          The actor to start from
499    * @param[in/out] focusableActors The vector to add focusable actors to
500    */
501   void AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors );
502
503   /**
504    * Sets up the touch signals connections as required.
505    * @note This must be called after all the members have been created.
506    */
507   void SetupTouch();
508
509 private:
510
511   // Undefined.
512   Popup(const Popup&);
513
514   // Undefined.
515   Popup& operator=(const Popup& rhs);
516
517 private:
518
519   Toolkit::Popup::TouchedOutsideSignalType     mTouchedOutsideSignal;
520   Toolkit::Popup::DisplayStateChangeSignalType mShowingSignal;
521   Toolkit::Popup::DisplayStateChangeSignalType mShownSignal;
522   Toolkit::Popup::DisplayStateChangeSignalType mHidingSignal;
523   Toolkit::Popup::DisplayStateChangeSignalType mHiddenSignal;
524
525   Layer mLayer;                                      ///< Popup Layer (i.e. Dim backing and PopupBg reside in this).
526   Toolkit::TableView mPopupLayout;                   ///< Popup Background (i.e. dialog reside in this).
527   Toolkit::Control mBacking;                         ///< Backing actor (dim effect).
528   Actor mPreviousFocusedActor;                       ///< Store the previous focused actor to restore the focus when popup hide.
529   Actor mTailImage;                                  ///< Stores the tail image.
530   Actor mPopupContainer;                             ///< This actor is used to house the background image and the main popup layout.
531   Animation mAnimation;                              ///< The current animation in use used to manage display state changing.
532   bool mAlterAddedChild;                             ///< Flag used to control whether children are reparented or not.
533   bool mLayoutDirty;                                 ///< Set to true whenever any property that would require a layout update is modified.
534   Timer mAutoHideTimer;                              ///< Used to perform an auto-hide of the popup if desired.
535   bool mTouchTransparent;                            ///< Allows all events to pass through the popup.
536
537   // Main Content related properties:
538   Actor mTitle;                                      ///< Stores the text title.
539   Actor mContent;                                    ///< Stores the unselected content.
540   Actor mFooter;                                     ///< Stores the footer content (typically controls).
541
542   // Display related properties.
543   Toolkit::Popup::DisplayState mDisplayState;        ///< The current display state of the popup.
544   bool mTailVisible;                                 ///< True if the popup tail should be visible.
545   Vector3 mTailPosition;                             ///< The position of the tail.
546   Toolkit::Popup::ContextualMode mContextualMode;    ///< Allows the popup to be layed out adjacent to its parent in different directions.
547   float mAnimationDuration;                          ///< The duration of the transition in and out animations.
548   Toolkit::Popup::AnimationMode mAnimationMode;      ///< The animation to use to transition in and out.
549   Dali::AnimationData mEntryAnimationData;           ///< Stores description data that can be used for generating a custom entry animation.
550   Dali::AnimationData mExitAnimationData;            ///< Stores description data that can be used for generating a custom exit animation.
551   unsigned int mAutoHideDelay;                       ///< If set, will auto-hide the popup after a specified amount of time.
552
553   // Style related properties:
554   bool mBackingEnabled;                              ///< True if a dimmed backing will be used.
555   Vector4 mBackingColor;                             ///< The color of the backing.
556   Actor mPopupBackgroundImage;                       ///< Stores the background image.
557   Rect<int> mBackgroundBorder;                       ///< Background border.
558   float mMargin;                                     ///< Internal margin for popup contents.
559   std::string mTailUpImage;                          ///< Image used for the tail for the up direction.
560   std::string mTailDownImage;                        ///< Image used for the tail for the down direction.
561   std::string mTailLeftImage;                        ///< Image used for the tail for the left direction.
562   std::string mTailRightImage;                       ///< Image used for the tail for the right direction.
563 };
564
565 } // namespace Internal
566
567 // Helpers for public-api forwarding methods
568
569 inline Toolkit::Internal::Popup& GetImpl( Toolkit::Popup& publicObject )
570 {
571   DALI_ASSERT_ALWAYS( publicObject );
572
573   Dali::RefObject& handle = publicObject.GetImplementation();
574
575   return static_cast<Toolkit::Internal::Popup&>( handle );
576 }
577
578 inline const Toolkit::Internal::Popup& GetImpl( const Toolkit::Popup& publicObject )
579 {
580   DALI_ASSERT_ALWAYS( publicObject );
581
582   const Dali::RefObject& handle = publicObject.GetImplementation();
583
584   return static_cast<const Toolkit::Internal::Popup&>( handle );
585 }
586
587 } // namespace Toolkit
588
589 } // namespace Dali
590
591 #endif // DALI_TOOLKIT_INTERNAL_POPUP_H