(FocusManager) Updated Accessibility features (Part2)
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / controls / control-impl.h
1 #ifndef __DALI_TOOLKIT_CONTROL_IMPL_H__
2 #define __DALI_TOOLKIT_CONTROL_IMPL_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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  * @addtogroup CAPI_DALI_TOOLKIT_CONTROLS_MODULE
22  * @{
23  */
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/control.h>
27
28 namespace Dali DALI_IMPORT_API
29 {
30
31 namespace Toolkit
32 {
33
34 class StyleManager;
35
36 namespace Internal DALI_INTERNAL
37 {
38 class StyleChangeProcessor;
39 class RelayoutControllerImpl;
40 class KeyInputFocusManager;
41 }
42
43 typedef std::pair< Actor, Vector2 > ActorSizePair;       ///< Pair of actor and size
44 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
45
46 namespace Internal
47 {
48
49 /**
50  * @brief This is the internal base class for all controls.
51  *
52  * It will provide some common functionality required by all controls.
53  * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
54  * be disconnected automatically when the control is destroyed.
55  */
56 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
57 {
58 public:
59
60   // Properties
61   enum
62   {
63     CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
64     CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
65   };
66
67   // Creation
68
69   /**
70    * @brief Create a new ControlImpl instance that does not require touch by default.
71    *
72    * If touch is required then the user can connect to this class' touch signal.
73    * @return A handle to the ConntrolImpl instance.
74    */
75   static Toolkit::Control New();
76
77   // Destruction
78
79   /**
80    * @brief Virtual destructor.
81    */
82   virtual ~Control();
83
84   // Actions
85
86   /**
87    * @brief This method should be overridden by deriving classes when they wish to be notified when they
88    * are activated.
89    */
90   virtual void OnActivated() { }
91
92   /**
93    * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
94    * pan gesture.
95    *
96    * @param[in] gesture The pan gesture.
97    * @return true if the pan gesture has been consumed by this control
98    */
99   virtual bool OnAccessibilityPan(PanGesture gesture);
100
101   /**
102    * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
103    * touch event.
104    *
105    * @param[in] touchEvent The touch event.
106    * @return true if the touch event has been consumed by this control
107    */
108   virtual bool OnAccessibilityTouch(const TouchEvent& touchEvent);
109
110   /**
111    * @brief This method should be overridden by deriving classes when they wish to respond
112    * the accessibility up and down action (i.e. value change of slider control).
113    *
114    * @param[in] isIncrease Whether the value should be increased or decreased
115    * @return true if the value changed action has been consumed by this control
116    */
117   virtual bool OnAccessibilityValueChange(bool isIncrease);
118
119   /**
120    * @brief Sets whether this control supports two dimensional
121    * keyboard navigation (i.e. whether it knows how to handle the
122    * keyboardn focus movement between its child actors).
123    *
124    * The control doesn't support it by default.
125    * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
126    */
127   void SetKeyboardNavigationSupport(bool isSupported);
128
129   /**
130    * @brief Gets whether this control supports two dimensional keyboard navigation.
131    *
132    * @return true if this control supports two dimensional keyboard navigation.
133    */
134   bool IsKeyboardNavigationSupported();
135
136   /**
137    * @brief Sets whether this control is a focus group for keyboard navigation.
138    *
139    * (i.e. the scope of keyboard focus movement
140    * can be limitied to its child actors). The control is not a focus group by default.
141    * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
142    */
143   void SetAsKeyboardFocusGroup(bool isFocusGroup);
144
145   /**
146    * @brief Gets whether this control is a focus group for keyboard navigation.
147    *
148    * @return true if this control is set as a focus group for keyboard navigation.
149    */
150   bool IsKeyboardFocusGroup();
151
152   /**
153    * @brief Gets the next keyboard focusable actor in this control towards the given direction.
154    *
155    * A control needs to override this function in order to support two dimensional keyboard navigation.
156    * @param[in] currentFocusedActor The current focused actor.
157    * @param[in] direction The direction to move the focus towards.
158    * @param[in] loopEnabled Whether the focus movement should be looped within the control.
159    * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
160    */
161   virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
162
163   /**
164    * @brief Informs this control that its chosen focusable actor will be focused.
165    *
166    * This allows the application to preform any actions if wishes
167    * before the focus is actually moved to the chosen actor.
168    *
169    * @param[in] commitedFocusableActor The commited focusable actor.
170    */
171   virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
172
173   /**
174    * @brief Performs actions as requested using the action name.
175    *
176    * @param[in] object The object on which to perform the action.
177    * @param[in] actionName The action to perform.
178    * @param[in] attributes The attributes with which to perfrom this action.
179    * @return true if action has been accepted by this control
180    */
181   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
182
183   /**
184    * @brief If deriving classes wish to fine tune pinch gesture
185    * detection then they can access the gesture detector through this
186    * API and modify the detection.
187    *
188    * @return The pinch gesture detector.
189    * @pre Pinch detection should have been enabled via EnableGestureDetection().
190    * @see EnableGestureDetection
191    */
192   PinchGestureDetector GetPinchGestureDetector() const;
193
194   /**
195    * @brief If deriving classes wish to fine tune pan gesture
196    * detection then they can access the gesture detector through this
197    * API and modify the detection.
198    *
199    * @return The pan gesture detector.
200    * @pre Pan detection should have been enabled via EnableGestureDetection().
201    * @see EnableGestureDetection
202    */
203   PanGestureDetector GetPanGestureDetector() const;
204
205   /**
206    * @brief If deriving classes wish to fine tune tap gesture
207    * detection then they can access the gesture detector through this
208    * API and modify the detection.
209    *
210    * @return The tap gesture detector.
211    * @pre Tap detection should have been enabled via EnableGestureDetection().
212    * @see EnableGestureDetection
213    */
214   TapGestureDetector GetTapGestureDetector() const;
215
216   /**
217    * @brief If deriving classes wish to fine tune long press gesture
218    * detection then they can access the gesture detector through this
219    * API and modify the detection.
220    *
221    * @return The long press gesture detector.
222    * @pre Long press detection should have been enabled via EnableGestureDetection().
223    * @see EnableGestureDetection
224    */
225   LongPressGestureDetector GetLongPressGestureDetector() const;
226
227   // Background
228
229   /**
230    * @copydoc Dali::Toolkit::Control::SetBackgroundColor
231    */
232   void SetBackgroundColor( const Vector4& color );
233
234   /**
235    * @copydoc Dali::Toolkit::Control::GetBackgroundColor
236    */
237   Vector4 GetBackgroundColor() const;
238
239   /**
240    * @copydoc Dali::Toolkit::Control::SetBackground
241    */
242   void SetBackground( Image image );
243
244   /**
245    * @copydoc Dali::Toolkit::Control::ClearBackground
246    */
247   void ClearBackground();
248
249   /**
250    * @copydoc Dali::Toolkit::Control::GetBackgroundActor
251    */
252   Actor GetBackgroundActor() const;
253
254 public:
255
256   /**
257    * @copydoc Dali::Toolkit::Control::KeyEventSignal()
258    */
259   Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
260
261 protected:
262
263   // Construction
264
265   /**
266    * @brief Second phase initialization.
267    */
268   void Initialize();
269
270   // Gesture Detection
271
272   /**
273    * @brief Allows deriving classes to enable any of the gesture detectors that are available.
274    *
275    * Gesture detection can be enabled one at a time or in bitwise format as shown:
276    * @code
277    * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
278    * @endcode
279    * @param[in]  type  The gesture type(s) to enable.
280    */
281   void EnableGestureDetection(Gesture::Type type);
282
283   /**
284    * @brief Allows deriving classes to disable any of the gesture detectors.
285    *
286    * Like EnableGestureDetection, this can also be called using bitwise or.
287    * @param[in]  type  The gesture type(s) to disable.
288    * @see EnableGetureDetection
289    */
290   void DisableGestureDetection(Gesture::Type type);
291
292 private: // For derived classes to override
293
294   /**
295    * @brief This method is called after the Control has been initialized.
296    *
297    * Derived classes should do any second phase initialization by
298    * overriding this method.
299    */
300   virtual void OnInitialize() { }
301
302   /**
303    * @brief This method should be overridden by deriving classes when
304    * they wish to be notified when the style changes.
305    *
306    * @param[in] change  Information denoting what has changed.
307    */
308   virtual void OnStyleChange(StyleChange change) { }
309
310   /**
311    * @brief Called whenever a pinch gesture is detected on this control.
312    *
313    * This can be overridden by deriving classes when pinch detection
314    * is enabled.  The default behaviour is to scale the control by the
315    * pinch scale.
316    *
317    * @note If overridden, then the default behaviour will not occur.
318    * @note Pinch detection should be enabled via EnableGestureDetection().
319    * @param[in]  pinch  The pinch gesture.
320    * @see EnableGestureDetection
321    */
322   virtual void OnPinch(PinchGesture pinch);
323
324   /**
325    * @brief Called whenever a pan gesture is detected on this control.
326    *
327    * This should be overridden by deriving classes when pan detection
328    * is enabled.
329    *
330    * @note There is no default behaviour with panning.
331    * @note Pan detection should be enabled via EnableGestureDetection().
332    * @param[in]  pan  The pan gesture.
333    * @see EnableGestureDetection
334    */
335   virtual void OnPan(PanGesture pan) { }
336
337   /**
338    * @brief Called whenever a tap gesture is detected on this control.
339    *
340    * This should be overridden by deriving classes when tap detection
341    * is enabled.
342    *
343    * @note There is no default behaviour with a tap.
344    * @note Tap detection should be enabled via EnableGestureDetection().
345    * @param[in]  tap  The tap gesture.
346    * @see EnableGestureDetection
347    */
348   virtual void OnTap(TapGesture tap) { }
349
350   /**
351    * @brief Called whenever a long press gesture is detected on this control.
352    *
353    * This should be overridden by deriving classes when long press
354    * detection is enabled.
355    *
356    * @note There is no default behaviour associated with a long press.
357    * @note Long press detection should be enabled via EnableGestureDetection().
358    * @param[in]  longPress  The long press gesture.
359    * @see EnableGestureDetection
360    */
361   virtual void OnLongPress(LongPressGesture longPress) { }
362
363   /**
364    * @brief Called whenever the control is added to the stage.
365    *
366    * Could be overridden by derived classes.
367    */
368   virtual void OnControlStageConnection() { }
369
370   /**
371    * @brief Called whenever the control is removed from the stage.
372    *
373    * Could be overridden by derived classes.
374    */
375   virtual void OnControlStageDisconnection() { }
376
377   /**
378    * @brief Called whenever an Actor is added to the control.
379    *
380    * Could be overridden by derived classes.
381    *
382    * @param[in] child The added actor.
383    */
384   virtual void OnControlChildAdd( Actor& child ) { }
385
386   /**
387    * @brief Called whenever an Actor is removed from the control.
388    *
389    * Could be overridden by derived classes.
390    *
391    * @param[in] child The removed actor.
392    */
393   virtual void OnControlChildRemove( Actor& child ) { }
394
395   /**
396    * @brief Called whenever the Control's size is set.
397    *
398    * Could be overridden by derived classes.
399    *
400    * @param[in] size The new size.
401    */
402   virtual void OnControlSizeSet( const Vector3& size ) { }
403
404   /**
405    * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
406    * signal is emitted if this control requested to be relaid-out.
407    *
408    * Should be overridden by derived classes if they need to layout
409    * actors differently after certain operations like add or remove
410    * actors, resize or after changing especific properties.
411    *
412    * @param[in]      size       The allocated size.
413    * @param[in,out]  container  The control should add actors to this container that it is not able
414    *                            to allocate a size for.
415    */
416   virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
417
418 private: // From CustomActorImpl, derived classes can override these.
419
420   /**
421    * @brief Sends a request to relayout this control.
422    *
423    * The control will be relaid out after the
424    * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
425    *
426    * It calls OnControlStageConnection() to notify derived classes.
427    *
428    * @see Dali::CustomActorImpl::OnStageConnection()
429    */
430   virtual void OnStageConnection();
431
432   /**
433    * @brief Calls OnControlStageDisconnection() to notify derived classed.
434    *
435    * @see Dali::CustomActorImpl::OnStageDisconnection()
436    */
437   virtual void OnStageDisconnection();
438
439   /**
440    * @brief Sends a request to relayout this control.
441    *
442    * The control will be relaid out after the
443    * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.  It
444    * calls OnControlChildAdd() to notify derived classes.
445    *
446    * @note This method shouldn't be overridden by derived classes.
447    *
448    * @param[in] child The added actor.
449    *
450    * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
451    */
452   virtual void OnChildAdd(Actor& child);
453
454   /**
455    * @brief Sends a request to relayout this control.
456    *
457    * The control will be relaid out after the
458    * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.  It
459    * calls OnControlChildRemove() to notify derived classes.
460    *
461    * @note This method shouldn't be overridden by derived classes.
462    *
463    * @param[in] child The removed actor.
464    *
465    * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
466    */
467   virtual void OnChildRemove(Actor& child);
468
469   /**
470    * @brief It stores the size set by size negotiation and relayout.
471    *
472    * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
473    * It calls the OnControlSizeSet() to notify derived classes.
474    *
475    * @param[in] targetSize The new size.
476    *
477    * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
478    */
479   virtual void OnSizeSet(const Vector3& targetSize);
480
481   /**
482    * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
483    */
484   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
485
486   /**
487    * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
488    */
489   virtual bool OnTouchEvent(const TouchEvent& event);
490
491   /**
492    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
493    */
494   virtual bool OnKeyEvent(const KeyEvent& event);
495
496   /**
497    * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
498    */
499   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
500
501   /**
502    * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
503    */
504   virtual void OnKeyInputFocusGained();
505
506   /**
507    * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
508    */
509   virtual void OnKeyInputFocusLost();
510
511   /**
512    * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
513    */
514   virtual Actor GetChildByAlias(const std::string& actorAlias);
515
516 private:
517
518   /**
519    * @brief Perform the activated action.
520    *
521    * @param[in] attributes The attributes to perfrom this action.
522    */
523   void DoActivatedAction(const PropertyValueContainer& attributes);
524
525 protected: // Construction
526
527   /**
528    * @brief Create a Control.
529    *
530    * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
531    */
532   Control(bool requiresTouchEvents);
533
534 public:
535
536   // Size negotiation
537
538   /**
539    * @copydoc Toolkit::Control::SetSizePolicy()
540    */
541   void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
542
543   /**
544    * @copydoc Toolkit::Control::GetSizePolicy()
545    */
546   void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
547
548   /**
549    * @copydoc Toolkit::Control::SetMinimumSize()
550    */
551   void SetMinimumSize( const Vector3& size );
552
553   /**
554    * @copydoc Toolkit::Control::GetMinimumSize()
555    */
556   const Vector3& GetMinimumSize() const;
557
558   /**
559    * @copydoc Toolkit::Control::SetMaximumSize()
560    */
561   void SetMaximumSize( const Vector3& size );
562
563   /**
564    * @copydoc Toolkit::Control::GetMaximumSize()
565    */
566   const Vector3& GetMaximumSize() const;
567
568   /**
569    * @copydoc Toolkit::Control::GetNaturalSize()
570    */
571   virtual Vector3 GetNaturalSize();
572
573   /**
574    * @copydoc Toolkit::Control::GetHeightForWidth()
575    */
576   virtual float GetHeightForWidth( float width );
577
578   /**
579    * @copydoc Toolkit::Control::GetWidthForHeight()
580    */
581   virtual float GetWidthForHeight( float height );
582
583   /**
584    * @brief Retrieves the current Control's size.
585    *
586    * @return The control's size.
587    */
588   const Vector3& GetControlSize() const;
589
590   /**
591    * @brief Retrieves the Control's size set by the Application / Control.
592    *
593    * @return The control's size.
594    */
595   const Vector3& GetSizeSet() const;
596
597   //KeyInput
598
599   /**
600    * @copydoc Toolkit::Control::SetKeyInputFocus()
601    */
602   void SetKeyInputFocus();
603
604   /**
605    * @copydoc Toolkit::Control::HasKeyInputFocus()
606    */
607   bool HasKeyInputFocus();
608
609   /**
610    * @copydoc Toolkit::Control::ClearKeyInputFocus()
611    */
612   void ClearKeyInputFocus();
613
614   /**
615    * @copydoc ConnectionTrackerInterface::SignalConnected
616    */
617   virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
618
619   /**
620    * @copydoc ConnectionTrackerInterface::SignalDisconnected
621    */
622   virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
623
624   /**
625    * @copydoc ConnectionTrackerInterface::GetConnectionCount
626    */
627   virtual std::size_t GetConnectionCount() const;
628
629 protected:
630
631   /**
632    * @brief Sends a request to be relaid-out.
633    *
634    * This method is called from OnStageConnection(), OnChildAdd(),
635    * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
636    * SetMaximumSize().
637    *
638    * This method could also be called from derived classes every time
639    * a control's poperty change and it needs to be relaid-out.  After
640    * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
641    * relayout process starts and all controls which called this method
642    * will be relaid-out.
643    *
644    * @note RelayoutRequest() only sends a request per Control before
645    * the Dali::Stage::SignalMessageQueueFlushed() signal is
646    * emitted. That means a control will be relaid-out only once, even
647    * if more than one request is sent between two consecutive signals.
648    */
649   void RelayoutRequest();
650
651   /**
652    * @brief Helper method for controls to Relayout their children if
653    * they do not know whether that child is a control or not.
654    *
655    * @param[in]      actor      The actor to relayout.
656    * @param[in]      size       The size to allocate to the actor.
657    * @param[in,out]  container  The container that holds actors that have not been allocated a size yet.
658    */
659   static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
660
661 private: // Used by the RelayoutController
662
663   /**
664    * @brief Called by the RelayoutController to negotiate the size of a control.
665    *
666    * The size allocated by the the algorithm is passed in which the
667    * control must adhere to.  A container is passed in as well which
668    * the control should populate with actors it has not / or does not
669    * need to handle in its size negotiation.
670    *
671    * @param[in]      size       The allocated size.
672    * @param[in,out]  container  The container that holds actors that are fed back into the
673    *                            RelayoutController algorithm.
674    */
675   void NegotiateSize( Vector2 size, ActorSizeContainer& container );
676
677 private:
678
679   /**
680    * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
681    *
682    * It calls the OnRelaidOut() method which can be overridden by derived classes.
683    *
684    * @param[in]      size       The allocated size.
685    * @param[in,out]  container  The control should add actors to this container that it is not able
686    *                            to allocate a size for.
687    */
688   void Relayout( Vector2 size, ActorSizeContainer& container );
689
690   /**
691    * @brief Used by the KeyInputFocusManager to emit key event signals.
692    *
693    * @param[in] event The key event.
694    * @return True if the event was consumed.
695    */
696   bool EmitKeyEventSignal(const KeyEvent& event);
697
698
699
700 private:
701
702   // Undefined
703   Control(const Control&);
704   Control& operator=(const Control&);
705
706   class Impl;
707   Impl *mImpl;
708
709   friend class Internal::StyleChangeProcessor;
710   friend class Internal::RelayoutControllerImpl;   ///< Relayout controller needs to call Relayout() which is private.
711   friend class Internal::KeyInputFocusManager;     ///< KeyInputFocusManager needs to call which is private.
712 };
713
714 } // namespace Internal
715
716 typedef Internal::Control ControlImpl; ///< @deprecated, Use Internal::Control
717
718 } // namespace Toolkit
719
720 } // namespace Dali
721
722 /**
723  * @}
724  */
725 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__