[3.0] Change Internal::Control destructor to protected
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/public-api/controls/control-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23 #include <limits>
24 #include <stack>
25 #include <dali/public-api/animation/constraint.h>
26 #include <dali/public-api/animation/constraints.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/public-api/rendering/renderer.h>
30 #include <dali/public-api/size-negotiation/relayout-container.h>
31 #include <dali/devel-api/scripting/scripting.h>
32 #include <dali/integration-api/debug.h>
33
34 // INTERNAL INCLUDES
35 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
36 #include <dali-toolkit/public-api/controls/control.h>
37 #include <dali-toolkit/public-api/styling/style-manager.h>
38 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
39 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
40 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
41 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
42 #include <dali-toolkit/internal/styling/style-manager-impl.h>
43 #include <dali-toolkit/internal/visuals/color/color-visual.h>
44
45 namespace Dali
46 {
47
48 namespace Toolkit
49 {
50
51 namespace
52 {
53
54 /**
55  * Creates control through type registry
56  */
57 BaseHandle Create()
58 {
59   return Internal::Control::New();
60 }
61
62 /**
63  * Performs actions as requested using the action name.
64  * @param[in] object The object on which to perform the action.
65  * @param[in] actionName The action to perform.
66  * @param[in] attributes The attributes with which to perfrom this action.
67  * @return true if action has been accepted by this control
68  */
69 const char* ACTION_ACCESSIBILITY_ACTIVATED = "accessibilityActivated";
70 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
71 {
72   bool ret = false;
73
74   if( object && ( 0 == strcmp( actionName.c_str(), ACTION_ACCESSIBILITY_ACTIVATED ) ) )
75   {
76     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
77     if( control )
78     {
79       // if cast succeeds there is an implementation so no need to check
80       ret = Internal::GetImplementation( control ).OnAccessibilityActivated();
81     }
82   }
83
84   return ret;
85 }
86
87 /**
88  * Connects a callback function with the object's signals.
89  * @param[in] object The object providing the signal.
90  * @param[in] tracker Used to disconnect the signal.
91  * @param[in] signalName The signal to connect to.
92  * @param[in] functor A newly allocated FunctorDelegate.
93  * @return True if the signal was connected.
94  * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
95  */
96 const char* SIGNAL_KEY_EVENT = "keyEvent";
97 const char* SIGNAL_KEY_INPUT_FOCUS_GAINED = "keyInputFocusGained";
98 const char* SIGNAL_KEY_INPUT_FOCUS_LOST = "keyInputFocusLost";
99 const char* SIGNAL_TAPPED = "tapped";
100 const char* SIGNAL_PANNED = "panned";
101 const char* SIGNAL_PINCHED = "pinched";
102 const char* SIGNAL_LONG_PRESSED = "longPressed";
103 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
104 {
105   Dali::BaseHandle handle( object );
106
107   bool connected( false );
108   Toolkit::Control control = Toolkit::Control::DownCast( handle );
109   if ( control )
110   {
111     Internal::Control& controlImpl( Internal::GetImplementation( control ) );
112     connected = true;
113
114     if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
115     {
116       controlImpl.KeyEventSignal().Connect( tracker, functor );
117     }
118     else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
119     {
120       controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
121     }
122     else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
123     {
124       controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
125     }
126     else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
127     {
128       controlImpl.EnableGestureDetection( Gesture::Tap );
129       controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
130     }
131     else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
132     {
133       controlImpl.EnableGestureDetection( Gesture::Pan );
134       controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
135     }
136     else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
137     {
138       controlImpl.EnableGestureDetection( Gesture::Pinch );
139       controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
140     }
141     else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
142     {
143       controlImpl.EnableGestureDetection( Gesture::LongPress );
144       controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
145     }
146   }
147   return connected;
148 }
149
150 // Setup signals and actions using the type-registry.
151 DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
152
153 // Note: Properties are registered separately below.
154
155 SignalConnectorType registerSignal1( typeRegistration, SIGNAL_KEY_EVENT, &DoConnectSignal );
156 SignalConnectorType registerSignal2( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_GAINED, &DoConnectSignal );
157 SignalConnectorType registerSignal3( typeRegistration, SIGNAL_KEY_INPUT_FOCUS_LOST, &DoConnectSignal );
158 SignalConnectorType registerSignal4( typeRegistration, SIGNAL_TAPPED, &DoConnectSignal );
159 SignalConnectorType registerSignal5( typeRegistration, SIGNAL_PANNED, &DoConnectSignal );
160 SignalConnectorType registerSignal6( typeRegistration, SIGNAL_PINCHED, &DoConnectSignal );
161 SignalConnectorType registerSignal7( typeRegistration, SIGNAL_LONG_PRESSED, &DoConnectSignal );
162
163 TypeAction registerAction( typeRegistration, ACTION_ACCESSIBILITY_ACTIVATED, &DoAction );
164
165 DALI_TYPE_REGISTRATION_END()
166
167 } // unnamed namespace
168
169 namespace Internal
170 {
171
172 class Control::Impl : public ConnectionTracker
173 {
174 public:
175
176   // Construction & Destruction
177   Impl(Control& controlImpl)
178 : mControlImpl( controlImpl ),
179   mStyleName(""),
180   mBackgroundVisual(),
181   mBackgroundColor(Color::TRANSPARENT),
182   mStartingPinchScale( NULL ),
183   mKeyEventSignal(),
184   mPinchGestureDetector(),
185   mPanGestureDetector(),
186   mTapGestureDetector(),
187   mLongPressGestureDetector(),
188   mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
189   mIsKeyboardNavigationSupported( false ),
190   mIsKeyboardFocusGroup( false )
191 {
192 }
193
194   ~Impl()
195   {
196     // All gesture detectors will be destroyed so no need to disconnect.
197     delete mStartingPinchScale;
198   }
199
200   // Gesture Detection Methods
201
202   void PinchDetected(Actor actor, const PinchGesture& pinch)
203   {
204     mControlImpl.OnPinch(pinch);
205   }
206
207   void PanDetected(Actor actor, const PanGesture& pan)
208   {
209     mControlImpl.OnPan(pan);
210   }
211
212   void TapDetected(Actor actor, const TapGesture& tap)
213   {
214     mControlImpl.OnTap(tap);
215   }
216
217   void LongPressDetected(Actor actor, const LongPressGesture& longPress)
218   {
219     mControlImpl.OnLongPress(longPress);
220   }
221
222   // Properties
223
224   /**
225    * Called when a property of an object of this type is set.
226    * @param[in] object The object whose property is set.
227    * @param[in] index The property index.
228    * @param[in] value The new property value.
229    */
230   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
231   {
232     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
233
234     if ( control )
235     {
236       Control& controlImpl( GetImplementation( control ) );
237
238       switch ( index )
239       {
240         case Toolkit::Control::Property::STYLE_NAME:
241         {
242           controlImpl.SetStyleName( value.Get< std::string >() );
243           break;
244         }
245
246         case Toolkit::Control::Property::BACKGROUND_COLOR:
247         {
248           DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
249           controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
250           break;
251         }
252
253         case Toolkit::Control::Property::BACKGROUND_IMAGE:
254         {
255           DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
256           Image image = Scripting::NewImage( value );
257           if ( image )
258           {
259             controlImpl.SetBackgroundImage( image );
260           }
261           else
262           {
263             // An empty map means the background is no longer required
264             controlImpl.ClearBackground();
265           }
266           break;
267         }
268
269         case Toolkit::Control::Property::KEY_INPUT_FOCUS:
270         {
271           if ( value.Get< bool >() )
272           {
273             controlImpl.SetKeyInputFocus();
274           }
275           else
276           {
277             controlImpl.ClearKeyInputFocus();
278           }
279           break;
280         }
281
282         case Toolkit::Control::Property::BACKGROUND:
283         {
284           const Property::Map* map = value.GetMap();
285           if( map )
286           {
287             controlImpl.SetBackground( *map );
288           }
289           else
290           {
291             // The background is not a property map, so we should clear the background
292             controlImpl.ClearBackground();
293           }
294           break;
295         }
296       }
297     }
298   }
299
300   /**
301    * Called to retrieve a property of an object of this type.
302    * @param[in] object The object whose property is to be retrieved.
303    * @param[in] index The property index.
304    * @return The current value of the property.
305    */
306   static Property::Value GetProperty( BaseObject* object, Property::Index index )
307   {
308     Property::Value value;
309
310     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
311
312     if ( control )
313     {
314       Control& controlImpl( GetImplementation( control ) );
315
316       switch ( index )
317       {
318         case Toolkit::Control::Property::STYLE_NAME:
319         {
320           value = controlImpl.GetStyleName();
321           break;
322         }
323
324         case Toolkit::Control::Property::BACKGROUND_COLOR:
325         {
326           DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
327           value = controlImpl.GetBackgroundColor();
328           break;
329         }
330
331         case Toolkit::Control::Property::BACKGROUND_IMAGE:
332         {
333           DALI_LOG_WARNING( "BACKGROUND_IMAGE property is deprecated. Use BACKGROUND property instead\n" );
334           Property::Map map;
335           if( controlImpl.mImpl->mBackgroundVisual )
336           {
337             controlImpl.mImpl->mBackgroundVisual.CreatePropertyMap( map );
338           }
339           value = map;
340           break;
341         }
342
343         case Toolkit::Control::Property::KEY_INPUT_FOCUS:
344         {
345           value = controlImpl.HasKeyInputFocus();
346           break;
347         }
348
349         case Toolkit::Control::Property::BACKGROUND:
350         {
351           Property::Map map;
352           if( controlImpl.mImpl->mBackgroundVisual )
353           {
354             (controlImpl.mImpl->mBackgroundVisual).CreatePropertyMap( map );
355           }
356
357           value = map;
358           break;
359         }
360
361       }
362     }
363
364     return value;
365   }
366
367   // Data
368
369   Control& mControlImpl;
370   std::string mStyleName;
371   Toolkit::Visual::Base mBackgroundVisual;   ///< The visual to render the background
372   Vector4 mBackgroundColor;                       ///< The color of the background visual
373   Vector3* mStartingPinchScale;      ///< The scale when a pinch gesture starts, TODO: consider removing this
374   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
375   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
376   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
377
378   // Gesture Detection
379   PinchGestureDetector mPinchGestureDetector;
380   PanGestureDetector mPanGestureDetector;
381   TapGestureDetector mTapGestureDetector;
382   LongPressGestureDetector mLongPressGestureDetector;
383
384   ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT;    ///< Flags passed in from constructor.
385   bool mIsKeyboardNavigationSupported :1;  ///< Stores whether keyboard navigation is supported by the control.
386   bool mIsKeyboardFocusGroup :1;           ///< Stores whether the control is a focus group.
387
388   // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
389   static const PropertyRegistration PROPERTY_1;
390   static const PropertyRegistration PROPERTY_2;
391   static const PropertyRegistration PROPERTY_3;
392   static const PropertyRegistration PROPERTY_4;
393   static const PropertyRegistration PROPERTY_5;
394 };
395
396 // Properties registered without macro to use specific member variables.
397 const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName",       Toolkit::Control::Property::STYLE_NAME,       Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
398 const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
399 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
400 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus",   Toolkit::Control::Property::KEY_INPUT_FOCUS,  Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
401 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background",      Toolkit::Control::Property::BACKGROUND,       Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
402
403 Toolkit::Control Control::New()
404 {
405   // Create the implementation, temporarily owned on stack
406   IntrusivePtr<Control> controlImpl = new Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) );
407
408   // Pass ownership to handle
409   Toolkit::Control handle( *controlImpl );
410
411   // Second-phase init of the implementation
412   // This can only be done after the CustomActor connection has been made...
413   controlImpl->Initialize();
414
415   return handle;
416 }
417
418 void Control::SetStyleName( const std::string& styleName )
419 {
420   if( styleName != mImpl->mStyleName )
421   {
422     mImpl->mStyleName = styleName;
423
424     // Apply new style, if stylemanager is available
425     Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
426     if( styleManager )
427     {
428       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
429     }
430   }
431 }
432
433 const std::string& Control::GetStyleName() const
434 {
435   return mImpl->mStyleName;
436 }
437
438 void Control::SetBackgroundColor( const Vector4& color )
439 {
440   Actor self( Self() );
441   mImpl->mBackgroundColor = color;
442   Property::Map map;
443   map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
444   map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
445   InitializeVisual( self, mImpl->mBackgroundVisual, map );
446   if( mImpl->mBackgroundVisual )
447   {
448     mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
449   }
450 }
451
452 Vector4 Control::GetBackgroundColor() const
453 {
454   return mImpl->mBackgroundColor;
455 }
456
457 void Control::SetBackground( const Property::Map& map )
458 {
459   Actor self( Self() );
460   InitializeVisual( self, mImpl->mBackgroundVisual, map );
461   if( mImpl->mBackgroundVisual )
462   {
463     mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
464   }
465 }
466
467 void Control::SetBackgroundImage( Image image )
468 {
469   Actor self( Self() );
470   InitializeVisual( self, mImpl->mBackgroundVisual, image );
471   if( mImpl->mBackgroundVisual )
472   {
473     mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
474   }
475 }
476
477 void Control::ClearBackground()
478 {
479   Actor self( Self() );
480   mImpl->mBackgroundVisual.RemoveAndReset( self );
481   mImpl->mBackgroundColor = Color::TRANSPARENT;
482 }
483
484 void Control::EnableGestureDetection(Gesture::Type type)
485 {
486   if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
487   {
488     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
489     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
490     mImpl->mPinchGestureDetector.Attach(Self());
491   }
492
493   if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
494   {
495     mImpl->mPanGestureDetector = PanGestureDetector::New();
496     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
497     mImpl->mPanGestureDetector.Attach(Self());
498   }
499
500   if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
501   {
502     mImpl->mTapGestureDetector = TapGestureDetector::New();
503     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
504     mImpl->mTapGestureDetector.Attach(Self());
505   }
506
507   if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
508   {
509     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
510     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
511     mImpl->mLongPressGestureDetector.Attach(Self());
512   }
513 }
514
515 void Control::DisableGestureDetection(Gesture::Type type)
516 {
517   if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
518   {
519     mImpl->mPinchGestureDetector.Detach(Self());
520     mImpl->mPinchGestureDetector.Reset();
521   }
522
523   if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
524   {
525     mImpl->mPanGestureDetector.Detach(Self());
526     mImpl->mPanGestureDetector.Reset();
527   }
528
529   if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
530   {
531     mImpl->mTapGestureDetector.Detach(Self());
532     mImpl->mTapGestureDetector.Reset();
533   }
534
535   if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
536   {
537     mImpl->mLongPressGestureDetector.Detach(Self());
538     mImpl->mLongPressGestureDetector.Reset();
539   }
540 }
541
542 PinchGestureDetector Control::GetPinchGestureDetector() const
543 {
544   return mImpl->mPinchGestureDetector;
545 }
546
547 PanGestureDetector Control::GetPanGestureDetector() const
548 {
549   return mImpl->mPanGestureDetector;
550 }
551
552 TapGestureDetector Control::GetTapGestureDetector() const
553 {
554   return mImpl->mTapGestureDetector;
555 }
556
557 LongPressGestureDetector Control::GetLongPressGestureDetector() const
558 {
559   return mImpl->mLongPressGestureDetector;
560 }
561
562 void Control::SetKeyboardNavigationSupport(bool isSupported)
563 {
564   mImpl->mIsKeyboardNavigationSupported = isSupported;
565 }
566
567 bool Control::IsKeyboardNavigationSupported()
568 {
569   return mImpl->mIsKeyboardNavigationSupported;
570 }
571
572 void Control::SetKeyInputFocus()
573 {
574   if( Self().OnStage() )
575   {
576     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
577   }
578 }
579
580 bool Control::HasKeyInputFocus()
581 {
582   bool result = false;
583   if( Self().OnStage() )
584   {
585     result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
586   }
587   return result;
588 }
589
590 void Control::ClearKeyInputFocus()
591 {
592   if( Self().OnStage() )
593   {
594     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
595   }
596 }
597
598 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
599 {
600   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
601
602   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
603   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
604 }
605
606 bool Control::IsKeyboardFocusGroup()
607 {
608   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
609 }
610
611 void Control::AccessibilityActivate()
612 {
613   // Inform deriving classes
614   OnAccessibilityActivated();
615 }
616
617 void Control::KeyboardEnter()
618 {
619   // Inform deriving classes
620   OnKeyboardEnter();
621 }
622
623 bool Control::OnAccessibilityActivated()
624 {
625   return false; // Accessibility activation is not handled by default
626 }
627
628 bool Control::OnKeyboardEnter()
629 {
630   return false; // Keyboard enter is not handled by default
631 }
632
633 bool Control::OnAccessibilityPan(PanGesture gesture)
634 {
635   return false; // Accessibility pan gesture is not handled by default
636 }
637
638 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
639 {
640   return false; // Accessibility touch event is not handled by default
641 }
642
643 bool Control::OnAccessibilityValueChange(bool isIncrease)
644 {
645   return false; // Accessibility value change action is not handled by default
646 }
647
648 bool Control::OnAccessibilityZoom()
649 {
650   return false; // Accessibility zoom action is not handled by default
651 }
652
653 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
654 {
655   return Actor();
656 }
657
658 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
659 {
660 }
661
662 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
663 {
664   return mImpl->mKeyEventSignal;
665 }
666
667 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
668 {
669   return mImpl->mKeyInputFocusGainedSignal;
670 }
671
672 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
673 {
674   return mImpl->mKeyInputFocusLostSignal;
675 }
676
677 bool Control::EmitKeyEventSignal( const KeyEvent& event )
678 {
679   // Guard against destruction during signal emission
680   Dali::Toolkit::Control handle( GetOwner() );
681
682   bool consumed = false;
683
684   // signals are allocated dynamically when someone connects
685   if ( !mImpl->mKeyEventSignal.Empty() )
686   {
687     consumed = mImpl->mKeyEventSignal.Emit( handle, event );
688   }
689
690   if (!consumed)
691   {
692     // Notification for derived classes
693     consumed = OnKeyEvent(event);
694   }
695
696   return consumed;
697 }
698
699 Control::Control( ControlBehaviour behaviourFlags )
700 : CustomActorImpl( static_cast< ActorFlags >( behaviourFlags ) ),
701   mImpl(new Impl(*this))
702 {
703   mImpl->mFlags = behaviourFlags;
704 }
705
706 Control::~Control()
707 {
708   delete mImpl;
709 }
710
711 void Control::Initialize()
712 {
713   // Call deriving classes so initialised before styling is applied to them.
714   OnInitialize();
715
716   if( (mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS) ||
717       !(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS) )
718   {
719     Toolkit::StyleManager styleManager = StyleManager::Get();
720
721     // if stylemanager is available
722     if( styleManager )
723     {
724       StyleManager& styleManagerImpl = GetImpl( styleManager );
725
726       // Register for style changes
727       styleManagerImpl.ControlStyleChangeSignal().Connect( this, &Control::OnStyleChange );
728
729       // Apply the current style
730       styleManagerImpl.ApplyThemeStyleAtInit( Toolkit::Control( GetOwner() ) );
731     }
732   }
733
734   if( mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT )
735   {
736     SetKeyboardNavigationSupport( true );
737   }
738 }
739
740 void Control::OnInitialize()
741 {
742 }
743
744 void Control::OnControlChildAdd( Actor& child )
745 {
746 }
747
748 void Control::OnControlChildRemove( Actor& child )
749 {
750 }
751
752 void Control::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
753 {
754   // By default the control is only interested in theme (not font) changes
755   if( styleManager && change == StyleChange::THEME_CHANGE )
756   {
757     GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
758   }
759   RelayoutRequest();
760 }
761
762 void Control::OnPinch(const PinchGesture& pinch)
763 {
764   if( !( mImpl->mStartingPinchScale ) )
765   {
766     // lazy allocate
767     mImpl->mStartingPinchScale = new Vector3;
768   }
769
770   if( pinch.state == Gesture::Started )
771   {
772     *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
773   }
774
775   Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
776 }
777
778 void Control::OnPan( const PanGesture& pan )
779 {
780 }
781
782 void Control::OnTap(const TapGesture& tap)
783 {
784 }
785
786 void Control::OnLongPress( const LongPressGesture& longPress )
787 {
788 }
789
790 void Control::EmitKeyInputFocusSignal( bool focusGained )
791 {
792   Dali::Toolkit::Control handle( GetOwner() );
793
794   if ( focusGained )
795   {
796     // signals are allocated dynamically when someone connects
797     if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
798     {
799       mImpl->mKeyInputFocusGainedSignal.Emit( handle );
800     }
801   }
802   else
803   {
804     // signals are allocated dynamically when someone connects
805     if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
806     {
807       mImpl->mKeyInputFocusLostSignal.Emit( handle );
808     }
809   }
810 }
811
812 void Control::OnStageConnection( int depth )
813 {
814   if( mImpl->mBackgroundVisual)
815   {
816     Actor self( Self() );
817     mImpl->mBackgroundVisual.SetOnStage( self );
818   }
819 }
820
821 void Control::OnStageDisconnection()
822 {
823   if( mImpl->mBackgroundVisual )
824   {
825     Actor self( Self() );
826     mImpl->mBackgroundVisual.SetOffStage( self );
827   }
828 }
829
830 void Control::OnKeyInputFocusGained()
831 {
832   EmitKeyInputFocusSignal( true );
833 }
834
835 void Control::OnKeyInputFocusLost()
836 {
837   EmitKeyInputFocusSignal( false );
838 }
839
840 void Control::OnChildAdd(Actor& child)
841 {
842   // Notify derived classes.
843   OnControlChildAdd( child );
844 }
845
846 void Control::OnChildRemove(Actor& child)
847 {
848   // Notify derived classes.
849   OnControlChildRemove( child );
850 }
851
852 void Control::OnSizeSet(const Vector3& targetSize)
853 {
854   if( mImpl->mBackgroundVisual )
855   {
856     Vector2 size( targetSize );
857     mImpl->mBackgroundVisual.SetSize( size );
858   }
859 }
860
861 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
862 {
863   // @todo size negotiate background to new size, animate as well?
864 }
865
866 bool Control::OnTouchEvent(const TouchEvent& event)
867 {
868   return false; // Do not consume
869 }
870
871 bool Control::OnHoverEvent(const HoverEvent& event)
872 {
873   return false; // Do not consume
874 }
875
876 bool Control::OnKeyEvent(const KeyEvent& event)
877 {
878   return false; // Do not consume
879 }
880
881 bool Control::OnWheelEvent(const WheelEvent& event)
882 {
883   return false; // Do not consume
884 }
885
886 void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
887 {
888   for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
889   {
890     container.Add( Self().GetChildAt( i ), size );
891   }
892 }
893
894 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
895 {
896 }
897
898 Vector3 Control::GetNaturalSize()
899 {
900   if( mImpl->mBackgroundVisual )
901   {
902     Vector2 naturalSize;
903     mImpl->mBackgroundVisual.GetNaturalSize(naturalSize);
904     return Vector3(naturalSize);
905   }
906   return Vector3::ZERO;
907 }
908
909 float Control::CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
910 {
911   return CalculateChildSizeBase( child, dimension );
912 }
913
914 float Control::GetHeightForWidth( float width )
915 {
916   return GetHeightForWidthBase( width );
917 }
918
919 float Control::GetWidthForHeight( float height )
920 {
921   return GetWidthForHeightBase( height );
922 }
923
924 bool Control::RelayoutDependentOnChildren( Dimension::Type dimension )
925 {
926   return RelayoutDependentOnChildrenBase( dimension );
927 }
928
929 void Control::OnCalculateRelayoutSize( Dimension::Type dimension )
930 {
931 }
932
933 void Control::OnLayoutNegotiated( float size, Dimension::Type dimension )
934 {
935 }
936
937 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
938 {
939   mImpl->SignalConnected( slotObserver, callback );
940 }
941
942 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
943 {
944   mImpl->SignalDisconnected( slotObserver, callback );
945 }
946
947 Control& GetImplementation( Dali::Toolkit::Control& handle )
948 {
949   CustomActorImpl& customInterface = handle.GetImplementation();
950   // downcast to control
951   Control& impl = dynamic_cast< Internal::Control& >( customInterface );
952   return impl;
953 }
954
955 const Control& GetImplementation( const Dali::Toolkit::Control& handle )
956 {
957   const CustomActorImpl& customInterface = handle.GetImplementation();
958   // downcast to control
959   const Control& impl = dynamic_cast< const Internal::Control& >( customInterface );
960   return impl;
961 }
962
963 } // namespace Internal
964
965 } // namespace Toolkit
966
967 } // namespace Dali