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