d6f09d8cf77619f887bc375ce1408c48e8deb9fa
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
1 /*
2  * Copyright (c) 2014 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 <stack>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/actors/mesh-actor.h>
25 #include <dali/public-api/animation/active-constraint.h>
26 #include <dali/public-api/animation/constraint.h>
27 #include <dali/public-api/animation/constraints.h>
28 #include <dali/public-api/geometry/mesh.h>
29 #include <dali/public-api/object/type-registry.h>
30 #include <dali/public-api/scripting/scripting.h>
31 #include <dali/integration-api/debug.h>
32
33 // INTERNAL INCLUDES
34 #include <dali-toolkit/internal/controls/relayout-controller.h>
35 #include <dali-toolkit/internal/controls/relayout-helper.h>
36 #include <dali-toolkit/public-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
38 #include <dali-toolkit/public-api/controls/control.h>
39 #include <dali-toolkit/public-api/styling/style-manager.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41
42 namespace Dali
43 {
44
45 namespace Toolkit
46 {
47
48 const Property::Index Control::PROPERTY_BACKGROUND_COLOR      = Internal::Control::CONTROL_PROPERTY_START_INDEX;
49 const Property::Index Control::PROPERTY_BACKGROUND            = Internal::Control::CONTROL_PROPERTY_START_INDEX + 1;
50 const Property::Index Control::PROPERTY_WIDTH_POLICY          = Internal::Control::CONTROL_PROPERTY_START_INDEX + 2;
51 const Property::Index Control::PROPERTY_HEIGHT_POLICY         = Internal::Control::CONTROL_PROPERTY_START_INDEX + 3;
52 const Property::Index Control::PROPERTY_MINIMUM_SIZE          = Internal::Control::CONTROL_PROPERTY_START_INDEX + 4;
53 const Property::Index Control::PROPERTY_MAXIMUM_SIZE          = Internal::Control::CONTROL_PROPERTY_START_INDEX + 5;
54 const Property::Index Control::PROPERTY_KEY_INPUT_FOCUS       = Internal::Control::CONTROL_PROPERTY_START_INDEX + 6;
55
56 namespace
57 {
58
59 // Signals
60
61 const char* const SIGNAL_KEY_EVENT =    "key-event";
62 const char* const SIGNAL_TAPPED =       "tapped";
63 const char* const SIGNAL_PANNED =       "panned";
64 const char* const SIGNAL_PINCHED =      "pinched";
65 const char* const SIGNAL_LONG_PRESSED = "long-pressed";
66
67 // Actions
68
69 const char* const ACTION_CONTROL_ACTIVATED = "control-activated";
70
71 const Scripting::StringEnum< Control::SizePolicy > SIZE_POLICY_STRING_TABLE[] =
72 {
73   { "FIXED",      Control::Fixed      },
74   { "MINIMUM",    Control::Minimum    },
75   { "MAXIMUM",    Control::Maximum    },
76   { "RANGE",      Control::Range      },
77   { "FLEXIBLE",   Control::Flexible   },
78 };
79 const unsigned int SIZE_POLICY_STRING_TABLE_COUNT = sizeof( SIZE_POLICY_STRING_TABLE ) / sizeof( SIZE_POLICY_STRING_TABLE[0] );
80
81 #if defined(DEBUG_ENABLED)
82 Integration::Log::Filter* gLogFilter  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_CONTROL");
83 #endif
84
85 const float MAX_FLOAT_VALUE( std::numeric_limits<float>::max() );
86 const Vector3 MAX_SIZE( MAX_FLOAT_VALUE, MAX_FLOAT_VALUE, MAX_FLOAT_VALUE );
87 const float BACKGROUND_ACTOR_Z_POSITION( -0.1f );
88
89 BaseHandle Create()
90 {
91   return Internal::Control::New();
92 }
93
94 TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
95
96 // Property Registration after Internal::Control::Impl definition below
97
98 TypeAction ACTION_TYPE_1( CONTROL_TYPE, ACTION_CONTROL_ACTIVATED, &Internal::Control::DoAction );
99
100 SignalConnectorType SIGNAL_CONNECTOR_1( CONTROL_TYPE, SIGNAL_KEY_EVENT,     &Internal::Control::DoConnectSignal );
101 SignalConnectorType SIGNAL_CONNECTOR_2( CONTROL_TYPE, SIGNAL_TAPPED,        &Internal::Control::DoConnectSignal );
102 SignalConnectorType SIGNAL_CONNECTOR_3( CONTROL_TYPE, SIGNAL_PANNED,        &Internal::Control::DoConnectSignal );
103 SignalConnectorType SIGNAL_CONNECTOR_4( CONTROL_TYPE, SIGNAL_PINCHED,       &Internal::Control::DoConnectSignal );
104 SignalConnectorType SIGNAL_CONNECTOR_5( CONTROL_TYPE, SIGNAL_LONG_PRESSED,  &Internal::Control::DoConnectSignal );
105
106 /**
107  * Structure which holds information about the background of a control
108  */
109 struct Background
110 {
111   Actor actor;   ///< Either a MeshActor or an ImageActor
112   Vector4 color; ///< The color of the actor.
113
114   /**
115    * Constructor
116    */
117   Background()
118   : actor(),
119     color( Color::WHITE )
120   {
121   }
122 };
123
124 /**
125  * Helper function to calculate a dimension given the policy of that dimension; the minimum &
126  * maximum values that dimension can be; and the allocated value for that dimension.
127  *
128  * @param[in]  policy     The size policy for that dimension.
129  * @param[in]  minimum    The minimum value that dimension can be.
130  * @param[in]  maximum    The maximum value that dimension can be.
131  * @param[in]  allocated  The value allocated for that dimension.
132  *
133  * @return The value that the dimension should be.
134  *
135  * @note This does not handle Control::Fixed policy.
136  */
137 float Calculate( Control::SizePolicy policy, float minimum, float maximum, float allocated )
138 {
139   float size( allocated );
140
141   switch( policy )
142   {
143     case Control::Fixed:
144     {
145       // Use allocated value
146       break;
147     }
148
149     case Control::Minimum:
150     {
151       // Size is always at least the minimum.
152       size = std::max( allocated, minimum );
153       break;
154     }
155
156     case Control::Maximum:
157     {
158       // Size can grow but up to a maximum value.
159       size = std::min( allocated, maximum );
160       break;
161     }
162
163     case Control::Range:
164     {
165       // Size is at least the minimum and can grow up to the maximum
166       size = std::max( size, minimum );
167       size = std::min( size, maximum );
168      break;
169     }
170
171     case Control::Flexible:
172     {
173       // Size grows or shrinks with no limits.
174       size = allocated;
175       break;
176     }
177
178     default:
179     {
180       DALI_ASSERT_DEBUG( false && "This function was not intended to be used by any other policy." );
181       break;
182     }
183   }
184
185   return size;
186 }
187
188 /**
189  * Creates a white coloured Mesh.
190  */
191 Mesh CreateMesh()
192 {
193   Vector3 white( Color::WHITE );
194
195   MeshData meshData;
196
197   // Create vertices with a white color (actual color is set by actor color)
198   MeshData::VertexContainer vertices(4);
199   vertices[ 0 ] = MeshData::Vertex( Vector3( -0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
200   vertices[ 1 ] = MeshData::Vertex( Vector3(  0.5f, -0.5f, 0.0f ), Vector2::ZERO, white );
201   vertices[ 2 ] = MeshData::Vertex( Vector3( -0.5f,  0.5f, 0.0f ), Vector2::ZERO, white );
202   vertices[ 3 ] = MeshData::Vertex( Vector3(  0.5f,  0.5f, 0.0f ), Vector2::ZERO, white );
203
204   // Specify all the faces
205   MeshData::FaceIndices faces;
206   faces.reserve( 6 ); // 2 triangles in Quad
207   faces.push_back( 0 ); faces.push_back( 3 ); faces.push_back( 1 );
208   faces.push_back( 0 ); faces.push_back( 2 ); faces.push_back( 3 );
209
210   // Create the mesh data from the vertices and faces
211   meshData.SetMaterial( Material::New( "ControlMaterial" ) );
212   meshData.SetVertices( vertices );
213   meshData.SetFaceIndices( faces );
214   meshData.SetHasColor( true );
215
216   return Mesh::New( meshData );
217 }
218
219 /**
220  * Sets all the required properties for the background actor.
221  *
222  * @param[in]  actor              The actor to set the properties on.
223  * @param[in]  constrainingIndex  The property index to constrain the parent's size on.
224  * @param[in]  color              The required color of the actor.
225  */
226 void SetupBackgroundActor( Actor actor, Property::Index constrainingIndex, const Vector4& color )
227 {
228   actor.SetColor( color );
229   actor.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
230   actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
231   actor.SetZ( BACKGROUND_ACTOR_Z_POSITION );
232
233   Constraint constraint = Constraint::New<Vector3>( constrainingIndex,
234                                                     ParentSource( Actor::SIZE ),
235                                                     EqualToConstraint() );
236   actor.ApplyConstraint( constraint );
237 }
238
239 } // unnamed namespace
240
241 namespace Internal
242 {
243
244 class Control::Impl : public ConnectionTracker
245 {
246 public:
247
248   /**
249    * Size indices for mMinMaxSize array
250    */
251   enum
252   {
253     MIN_SIZE_INDEX = 0,
254     MAX_SIZE_INDEX = 1
255   };
256
257 public:
258   // Construction & Destruction
259   Impl(Control& controlImpl)
260   : mControlImpl( controlImpl ),
261     mBackground( NULL ),
262     mStartingPinchScale( NULL ),
263     mKeyEventSignal(),
264     mPinchGestureDetector(),
265     mPanGestureDetector(),
266     mTapGestureDetector(),
267     mLongPressGestureDetector(),
268     mCurrentSize(),
269     mNaturalSize(),
270     mWidthPolicy( Toolkit::Control::Fixed ),
271     mHeightPolicy( Toolkit::Control::Fixed ),
272     mFlags( Control::CONTROL_BEHAVIOUR_NONE ),
273     mInsideRelayout( false ),
274     mIsKeyboardNavigationSupported( false ),
275     mIsKeyboardFocusGroup( false ),
276     mInitialized( false )
277   {
278   }
279
280   ~Impl()
281   {
282     // All gesture detectors will be destroyed so no need to disconnect.
283     delete mBackground;
284     delete mStartingPinchScale;
285   }
286
287   // Gesture Detection Methods
288
289   void PinchDetected(Actor actor, const PinchGesture& pinch)
290   {
291     mControlImpl.OnPinch(pinch);
292   }
293
294   void PanDetected(Actor actor, const PanGesture& pan)
295   {
296     mControlImpl.OnPan(pan);
297   }
298
299   void TapDetected(Actor actor, const TapGesture& tap)
300   {
301     mControlImpl.OnTap(tap);
302   }
303
304   void LongPressDetected(Actor actor, const LongPressGesture& longPress)
305   {
306     mControlImpl.OnLongPress(longPress);
307   }
308
309   // Background Methods
310
311   /**
312    * Only creates an instance of the background if we actually use it.
313    * @return A reference to the Background structure.
314    */
315   Background& GetBackground()
316   {
317     if ( !mBackground )
318     {
319       mBackground = new Background;
320     }
321     return *mBackground;
322   }
323
324   // Properties
325
326   /**
327    * Called when a property of an object of this type is set.
328    * @param[in] object The object whose property is set.
329    * @param[in] index The property index.
330    * @param[in] value The new property value.
331    */
332   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
333   {
334     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
335
336     if ( control )
337     {
338       Control& controlImpl( control.GetImplementation() );
339
340       switch ( index )
341       {
342         case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
343         {
344           controlImpl.SetBackgroundColor( value.Get< Vector4 >() );
345           break;
346         }
347
348         case Toolkit::Control::PROPERTY_BACKGROUND:
349         {
350           if ( value.HasKey( "image" ) )
351           {
352             Property::Map imageMap = value.GetValue( "image" ).Get< Property::Map >();
353             Image image = Scripting::NewImage( imageMap );
354
355             if ( image )
356             {
357               controlImpl.SetBackground( image );
358             }
359           }
360           else if ( value.Get< Property::Map >().Empty() )
361           {
362             // An empty map means the background is no longer required
363             controlImpl.ClearBackground();
364           }
365           break;
366         }
367
368         case Toolkit::Control::PROPERTY_WIDTH_POLICY:
369         {
370           controlImpl.mImpl->mWidthPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >().c_str(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
371           break;
372         }
373
374         case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
375         {
376           controlImpl.mImpl->mHeightPolicy = Scripting::GetEnumeration< Toolkit::Control::SizePolicy >( value.Get< std::string >().c_str(), SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT );
377           break;
378         }
379
380         case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
381         {
382           controlImpl.SetMinimumSize( value.Get< Vector3 >() );
383           break;
384         }
385
386         case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
387         {
388           controlImpl.SetMaximumSize( value.Get< Vector3 >() );
389           break;
390         }
391
392         case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
393         {
394           if ( value.Get< bool >() )
395           {
396             controlImpl.SetKeyInputFocus();
397           }
398           else
399           {
400             controlImpl.ClearKeyInputFocus();
401           }
402           break;
403         }
404       }
405     }
406   }
407
408   /**
409    * Called to retrieve a property of an object of this type.
410    * @param[in] object The object whose property is to be retrieved.
411    * @param[in] index The property index.
412    * @return The current value of the property.
413    */
414   static Property::Value GetProperty( BaseObject* object, Property::Index index )
415   {
416     Property::Value value;
417
418     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
419
420     if ( control )
421     {
422       Control& controlImpl( control.GetImplementation() );
423
424       switch ( index )
425       {
426         case Toolkit::Control::PROPERTY_BACKGROUND_COLOR:
427         {
428           value = controlImpl.GetBackgroundColor();
429           break;
430         }
431
432         case Toolkit::Control::PROPERTY_BACKGROUND:
433         {
434           Property::Map map;
435
436           Actor actor = controlImpl.GetBackgroundActor();
437           if ( actor )
438           {
439             ImageActor imageActor = ImageActor::DownCast( actor );
440             if ( imageActor )
441             {
442               Image image = imageActor.GetImage();
443               Property::Map imageMap;
444               Scripting::CreatePropertyMap( image, imageMap );
445               map[ "image" ] = imageMap;
446             }
447           }
448
449           value = map;
450           break;
451         }
452
453         case Toolkit::Control::PROPERTY_WIDTH_POLICY:
454         {
455           value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mWidthPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
456           break;
457         }
458
459         case Toolkit::Control::PROPERTY_HEIGHT_POLICY:
460         {
461           value = std::string( Scripting::GetEnumerationName< Toolkit::Control::SizePolicy >( controlImpl.mImpl->mHeightPolicy, SIZE_POLICY_STRING_TABLE, SIZE_POLICY_STRING_TABLE_COUNT ) );
462           break;
463         }
464
465         case Toolkit::Control::PROPERTY_MINIMUM_SIZE:
466         {
467           value = controlImpl.mImpl->GetMinimumSize();
468           break;
469         }
470
471         case Toolkit::Control::PROPERTY_MAXIMUM_SIZE:
472         {
473           value = controlImpl.mImpl->GetMaximumSize();
474           break;
475         }
476
477         case Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS:
478         {
479           value = controlImpl.HasKeyInputFocus();
480           break;
481         }
482       }
483     }
484
485     return value;
486   }
487
488   /**
489    * Helper to get minimum size
490    * @return minimum size
491    */
492   inline const Vector3& GetMinimumSize()
493   {
494     if( mMinMaxSize.Count() > MIN_SIZE_INDEX )
495     {
496       return mMinMaxSize[ MIN_SIZE_INDEX ];
497     }
498     else
499     {
500       // its not been allocated so its ZERO
501       return Vector3::ZERO;
502     }
503   }
504   /**
505    * Helper to Set minimum size
506    * @param size to set
507    */
508   inline void SetMinimumSize( const Vector3& size )
509   {
510     if( mMinMaxSize.Count() > MIN_SIZE_INDEX )
511     {
512       mMinMaxSize[ MIN_SIZE_INDEX ] = size;
513     }
514     else
515     {
516       // its not been allocated so push the new value there
517       mMinMaxSize.PushBack( size );
518     }
519   }
520
521   /**
522    * Helper to get maximum size
523    * @return maximum size
524    */
525   inline const Vector3& GetMaximumSize()
526   {
527     if( mMinMaxSize.Count() > MAX_SIZE_INDEX )
528     {
529       return mMinMaxSize[ MAX_SIZE_INDEX ];
530     }
531     else
532     {
533       // its not been allocated so its MAX_SIZE
534       return MAX_SIZE;
535     }
536   }
537
538   /**
539    * Helper to Set minimum size
540    * @param size to set
541    */
542   inline void SetMaximumSize( const Vector3& size )
543   {
544     if( mMinMaxSize.Count() > MAX_SIZE_INDEX )
545     {
546       mMinMaxSize[ MAX_SIZE_INDEX ] = size;
547     }
548     else if( mMinMaxSize.Count() > MIN_SIZE_INDEX )
549     {
550       // max has not been allocated, but min has
551       mMinMaxSize.PushBack( size );
552     }
553     else
554     {
555       // min and max both unallocated so allocate both
556       mMinMaxSize.Resize( 2u ); // this will reserve and default construct two Vector3s
557       mMinMaxSize[ MAX_SIZE_INDEX ] = size;
558     }
559   }
560
561   // Data
562
563   Control& mControlImpl;
564   Background* mBackground;           ///< Only create the background if we use it
565   Vector3* mStartingPinchScale;      ///< The scale when a pinch gesture starts, TODO: consider removing this
566   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
567
568   // Gesture Detection
569   PinchGestureDetector mPinchGestureDetector;
570   PanGestureDetector mPanGestureDetector;
571   TapGestureDetector mTapGestureDetector;
572   LongPressGestureDetector mLongPressGestureDetector;
573   // @todo change all these to Vector2 when we have a chance to sanitize the public API as well
574   Vector3 mCurrentSize; ///< Stores the current control's size, this is the negotiated size
575   Vector3 mNaturalSize; ///< Stores the size set through the Actor's API. This is size the actor wants to be. Useful when reset to the initial size is needed.
576   Dali::Vector< Vector3 > mMinMaxSize; ///< Stores the minimum and maximum size if they are set
577
578   Toolkit::Control::SizePolicy mWidthPolicy :3;  ///< Stores the width policy. 3 bits covers 8 values
579   Toolkit::Control::SizePolicy mHeightPolicy :3; ///< Stores the height policy. 3 bits covers 8 values
580   ControlBehaviour mFlags :6;             ///< Flags passed in from constructor. Need to increase this size when new enums are added
581   bool mInsideRelayout:1;                 ///< Detect when were in Relayout
582   bool mIsKeyboardNavigationSupported:1;  ///< Stores whether keyboard navigation is supported by the control.
583   bool mIsKeyboardFocusGroup:1;           ///< Stores whether the control is a focus group.
584   bool mInitialized:1;
585
586   // Properties - these need to be members of Internal::Control::Impl as they need to functions within this class.
587   static PropertyRegistration PROPERTY_1;
588   static PropertyRegistration PROPERTY_2;
589   static PropertyRegistration PROPERTY_3;
590   static PropertyRegistration PROPERTY_4;
591   static PropertyRegistration PROPERTY_5;
592   static PropertyRegistration PROPERTY_6;
593   static PropertyRegistration PROPERTY_7;
594 };
595
596 PropertyRegistration Control::Impl::PROPERTY_1( CONTROL_TYPE, "background-color", Toolkit::Control::PROPERTY_BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
597 PropertyRegistration Control::Impl::PROPERTY_2( CONTROL_TYPE, "background",       Toolkit::Control::PROPERTY_BACKGROUND,       Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
598 PropertyRegistration Control::Impl::PROPERTY_3( CONTROL_TYPE, "width-policy",     Toolkit::Control::PROPERTY_WIDTH_POLICY,     Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
599 PropertyRegistration Control::Impl::PROPERTY_4( CONTROL_TYPE, "height-policy",    Toolkit::Control::PROPERTY_HEIGHT_POLICY,    Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
600 PropertyRegistration Control::Impl::PROPERTY_5( CONTROL_TYPE, "minimum-size",     Toolkit::Control::PROPERTY_MINIMUM_SIZE,     Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
601 PropertyRegistration Control::Impl::PROPERTY_6( CONTROL_TYPE, "maximum-size",     Toolkit::Control::PROPERTY_MAXIMUM_SIZE,     Property::VECTOR3, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
602 PropertyRegistration Control::Impl::PROPERTY_7( CONTROL_TYPE, "key-input-focus",  Toolkit::Control::PROPERTY_KEY_INPUT_FOCUS,  Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
603
604 Toolkit::Control Control::New()
605 {
606   // Create the implementation, temporarily owned on stack
607   IntrusivePtr<Control> controlImpl = new Control( CONTROL_BEHAVIOUR_NONE );
608
609   // Pass ownership to handle
610   Toolkit::Control handle( *controlImpl );
611
612   // Second-phase init of the implementation
613   // This can only be done after the CustomActor connection has been made...
614   controlImpl->Initialize();
615
616   return handle;
617 }
618
619 Control::~Control()
620 {
621   delete mImpl;
622 }
623
624 void Control::SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy )
625 {
626   bool relayoutRequest( false );
627
628   if ( ( mImpl->mWidthPolicy != widthPolicy ) || ( mImpl->mHeightPolicy != heightPolicy ) )
629   {
630     relayoutRequest = true;
631   }
632
633   mImpl->mWidthPolicy = widthPolicy;
634   mImpl->mHeightPolicy = heightPolicy;
635
636   // Ensure RelayoutRequest is called AFTER new policies have been set.
637   if ( relayoutRequest )
638   {
639     RelayoutRequest();
640   }
641 }
642
643 void Control::GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const
644 {
645   widthPolicy = mImpl->mWidthPolicy;
646   heightPolicy = mImpl->mHeightPolicy;
647 }
648
649 void Control::SetMinimumSize( const Vector3& size )
650 {
651   const Vector3& minSize = mImpl->GetMinimumSize();
652   if ( fabsf( minSize.width - size.width ) > Math::MACHINE_EPSILON_1000 ||
653        fabsf( minSize.height - size.height ) > Math::MACHINE_EPSILON_1000 )
654   {
655     mImpl->SetMinimumSize( size );
656
657     // Only relayout if our control is using the minimum or range policy.
658     if ( ( mImpl->mHeightPolicy == Toolkit::Control::Minimum ) || ( mImpl->mWidthPolicy  == Toolkit::Control::Minimum ) ||
659          ( mImpl->mHeightPolicy == Toolkit::Control::Range   ) || ( mImpl->mWidthPolicy  == Toolkit::Control::Range   ) )
660     {
661       RelayoutRequest();
662     }
663   }
664 }
665
666 const Vector3& Control::GetMinimumSize() const
667 {
668   return mImpl->GetMinimumSize();
669 }
670
671 void Control::SetMaximumSize( const Vector3& size )
672 {
673   const Vector3& maxSize = mImpl->GetMaximumSize();
674   if ( fabsf( maxSize.width - size.width ) > Math::MACHINE_EPSILON_1000 ||
675        fabsf( maxSize.height - size.height ) > Math::MACHINE_EPSILON_1000 )
676   {
677     mImpl->SetMaximumSize( size );
678
679     // Only relayout if our control is using the maximum or range policy.
680     if ( ( mImpl->mHeightPolicy == Toolkit::Control::Maximum ) || ( mImpl->mWidthPolicy  == Toolkit::Control::Maximum ) ||
681          ( mImpl->mHeightPolicy == Toolkit::Control::Range   ) || ( mImpl->mWidthPolicy  == Toolkit::Control::Range   ) )
682     {
683       RelayoutRequest();
684     }
685   }
686 }
687
688 const Vector3& Control::GetMaximumSize() const
689 {
690   return mImpl->GetMaximumSize();
691 }
692
693 Vector3 Control::GetNaturalSize()
694 {
695   // could be overridden in derived classes.
696   return mImpl->mNaturalSize;
697 }
698
699 float Control::GetHeightForWidth( float width )
700 {
701   // could be overridden in derived classes.
702   float height( 0.0f );
703   if ( mImpl->mNaturalSize.width > 0.0f )
704   {
705     height = mImpl->mNaturalSize.height * width / mImpl->mNaturalSize.width;
706   }
707   return height;
708 }
709
710 float Control::GetWidthForHeight( float height )
711 {
712   // could be overridden in derived classes.
713   float width( 0.0f );
714   if ( mImpl->mNaturalSize.height > 0.0f )
715   {
716     width = mImpl->mNaturalSize.width * height / mImpl->mNaturalSize.height;
717   }
718   return width;
719 }
720
721 const Vector3& Control::GetControlSize() const
722 {
723   return mImpl->mCurrentSize;
724 }
725
726 const Vector3& Control::GetSizeSet() const
727 {
728   return mImpl->mNaturalSize;
729 }
730
731 void Control::SetKeyInputFocus()
732 {
733   if( Self().OnStage() )
734   {
735     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
736   }
737 }
738
739 bool Control::HasKeyInputFocus()
740 {
741   bool result = false;
742   if( Self().OnStage() )
743   {
744     result = Toolkit::KeyInputFocusManager::Get().IsKeyboardListener(Toolkit::Control::DownCast(Self()));
745   }
746   return result;
747 }
748
749 void Control::ClearKeyInputFocus()
750 {
751   if( Self().OnStage() )
752   {
753     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
754   }
755 }
756
757 PinchGestureDetector Control::GetPinchGestureDetector() const
758 {
759   return mImpl->mPinchGestureDetector;
760 }
761
762 PanGestureDetector Control::GetPanGestureDetector() const
763 {
764   return mImpl->mPanGestureDetector;
765 }
766
767 TapGestureDetector Control::GetTapGestureDetector() const
768 {
769   return mImpl->mTapGestureDetector;
770 }
771
772 LongPressGestureDetector Control::GetLongPressGestureDetector() const
773 {
774   return mImpl->mLongPressGestureDetector;
775 }
776
777 void Control::SetBackgroundColor( const Vector4& color )
778 {
779   Background& background( mImpl->GetBackground() );
780
781   if ( background.actor )
782   {
783     // Just set the actor color
784     background.actor.SetColor( color );
785   }
786   else
787   {
788     // Create Mesh Actor
789     MeshActor meshActor = MeshActor::New( CreateMesh() );
790
791     SetupBackgroundActor( meshActor, Actor::SCALE, color );
792
793     // Set the background actor before adding so that we do not inform deriving classes
794     background.actor = meshActor;
795     Self().Add( meshActor );
796   }
797
798   background.color = color;
799 }
800
801 Vector4 Control::GetBackgroundColor() const
802 {
803   if ( mImpl->mBackground )
804   {
805     return mImpl->mBackground->color;
806   }
807   return Color::TRANSPARENT;
808 }
809
810 void Control::SetBackground( Image image )
811 {
812   Background& background( mImpl->GetBackground() );
813
814   if ( background.actor )
815   {
816     // Remove Current actor, unset AFTER removal so that we do not inform deriving classes
817     Self().Remove( background.actor );
818     background.actor.Reset();
819   }
820
821   ImageActor imageActor = ImageActor::New( image );
822   SetupBackgroundActor( imageActor, Actor::SIZE, background.color );
823
824   // Set the background actor before adding so that we do not inform derived classes
825   background.actor = imageActor;
826   Self().Add( imageActor );
827 }
828
829 void Control::ClearBackground()
830 {
831   if ( mImpl->mBackground )
832   {
833     Background& background( mImpl->GetBackground() );
834     Self().Remove( background.actor );
835
836     delete mImpl->mBackground;
837     mImpl->mBackground = NULL;
838   }
839 }
840
841 Actor Control::GetBackgroundActor() const
842 {
843   if ( mImpl->mBackground )
844   {
845     return mImpl->mBackground->actor;
846   }
847
848   return Actor();
849 }
850
851 void Control::SetKeyboardNavigationSupport(bool isSupported)
852 {
853   mImpl->mIsKeyboardNavigationSupported = isSupported;
854 }
855
856 bool Control::IsKeyboardNavigationSupported()
857 {
858   return mImpl->mIsKeyboardNavigationSupported;
859 }
860
861 void Control::Activate()
862 {
863   // Inform deriving classes
864   OnActivated();
865 }
866
867 bool Control::OnAccessibilityPan(PanGesture gesture)
868 {
869   return false; // Accessibility pan gesture is not handled by default
870 }
871
872 bool Control::OnAccessibilityTouch(const TouchEvent& touchEvent)
873 {
874   return false; // Accessibility touch event is not handled by default
875 }
876
877 bool Control::OnAccessibilityValueChange(bool isIncrease)
878 {
879   return false; // Accessibility value change action is not handled by default
880 }
881
882 void Control::NegotiateSize( const Vector2& allocatedSize, ActorSizeContainer& container )
883 {
884   Vector2 size;
885
886   if ( mImpl->mWidthPolicy == Toolkit::Control::Fixed )
887   {
888     if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
889     {
890       // If a control says it has a fixed size, then use the size set by the application / control.
891       Vector2 setSize( mImpl->mNaturalSize );
892       if ( setSize != Vector2::ZERO )
893       {
894         size = setSize;
895
896         // Policy is set to Fixed, so if the application / control has not set one of the dimensions,
897         // then we should use the natural size of the control rather than the full allocation.
898         if ( EqualsZero( size.width ) )
899         {
900           size.width = GetWidthForHeight( size.height );
901         }
902         else if ( EqualsZero( size.height ) )
903         {
904           size.height = GetHeightForWidth( size.width );
905         }
906       }
907       else
908       {
909         // If that is not set then set the size to the control's natural size
910         size = Vector2( GetNaturalSize() );
911       }
912     }
913     else
914     {
915       // Width is fixed so if the application / control has set it, then use that.
916       if ( !EqualsZero( mImpl->mNaturalSize.width ) )
917       {
918         size.width = mImpl->mNaturalSize.width;
919       }
920       else
921       {
922         // Otherwise, set the width to what has been allocated.
923         size.width = allocatedSize.width;
924       }
925
926       // Height is flexible so ask control what the height should be for our width.
927       size.height = GetHeightForWidth( size.width );
928
929       // Ensure height is within our policy rules
930       size.height = Calculate( mImpl->mHeightPolicy, GetMinimumSize().height, GetMaximumSize().height, size.height );
931     }
932   }
933   else
934   {
935     if ( mImpl->mHeightPolicy == Toolkit::Control::Fixed )
936     {
937       // Height is fixed so if the application / control has set it, then use that.
938       if ( !EqualsZero( mImpl->mNaturalSize.height ) )
939       {
940         size.height = mImpl->mNaturalSize.height;
941       }
942       else
943       {
944         // Otherwise, set the height to what has been allocated.
945         size.height = allocatedSize.height;
946       }
947
948       // Width is flexible so ask control what the width should be for our height.
949       size.width = GetWidthForHeight( size.height );
950
951       // Ensure width is within our policy rules
952       size.width = Calculate( mImpl->mWidthPolicy, mImpl->GetMinimumSize().width, mImpl->GetMaximumSize().width, size.width );
953     }
954     else
955     {
956       // Width and height are BOTH flexible.
957       // Calculate the width and height using the policy rules.
958       size.width = Calculate( mImpl->mWidthPolicy, mImpl->GetMinimumSize().width, mImpl->GetMaximumSize().width, allocatedSize.width );
959       size.height = Calculate( mImpl->mHeightPolicy, mImpl->GetMinimumSize().height, mImpl->GetMaximumSize().height, allocatedSize.height );
960     }
961   }
962
963   // If the width has not been set, then set to the allocated width.
964   // Also if the width set is greater than the allocated, then set to allocated (no exceed support).
965   if ( EqualsZero( size.width ) || ( size.width > allocatedSize.width ) )
966   {
967     size.width = allocatedSize.width;
968   }
969
970   // If the height has not been set, then set to the allocated height.
971   // Also if the height set is greater than the allocated, then set to allocated (no exceed support).
972   if ( EqualsZero( size.height ) || ( size.height > allocatedSize.height ) )
973   {
974     size.height = allocatedSize.height;
975   }
976
977   DALI_LOG_INFO( gLogFilter, Debug::Verbose,
978                  "%p: Natural: [%.2f, %.2f] Allocated: [%.2f, %.2f] Set: [%.2f, %.2f]\n",
979                  Self().GetObjectPtr(),
980                  GetNaturalSize().x, GetNaturalSize().y,
981                  allocatedSize.x, allocatedSize.y,
982                  size.x, size.y );
983
984   // Avoids relayout again when OnSizeSet callback arrives as a function of us or deriving class calling SetSize()
985   mImpl->mInsideRelayout = true;
986   Self().SetSize( size );
987   // Only relayout controls which requested to be relaid out.
988   OnRelayout( size, container );
989   mImpl->mInsideRelayout = false;
990 }
991
992 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
993 {
994   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
995
996   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
997   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
998 }
999
1000 bool Control::IsKeyboardFocusGroup()
1001 {
1002   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
1003 }
1004
1005 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled)
1006 {
1007   return Actor();
1008 }
1009
1010 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
1011 {
1012 }
1013
1014 bool Control::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
1015 {
1016   bool ret = false;
1017
1018   if( object && ( 0 == strcmp( actionName.c_str(), ACTION_CONTROL_ACTIVATED ) ) )
1019   {
1020     Toolkit::Control control = Toolkit::Control::DownCast( BaseHandle( object ) );
1021     if( control )
1022     {
1023       // if cast succeeds there is an implementation so no need to check
1024       control.GetImplementation().OnActivated();
1025     }
1026   }
1027
1028   return ret;
1029 }
1030
1031 bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1032 {
1033   Dali::BaseHandle handle( object );
1034
1035   bool connected( false );
1036   Toolkit::Control control = Toolkit::Control::DownCast( handle );
1037   if ( control )
1038   {
1039     Control& controlImpl( control.GetImplementation() );
1040     connected = true;
1041
1042     if ( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_EVENT ) )
1043     {
1044       controlImpl.KeyEventSignal().Connect( tracker, functor );
1045     }
1046     else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
1047     {
1048       controlImpl.EnableGestureDetection( Gesture::Tap );
1049       controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
1050     }
1051     else if( 0 == strcmp( signalName.c_str(), SIGNAL_PANNED ) )
1052     {
1053       controlImpl.EnableGestureDetection( Gesture::Pan );
1054       controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
1055     }
1056     else if( 0 == strcmp( signalName.c_str(), SIGNAL_PINCHED ) )
1057     {
1058       controlImpl.EnableGestureDetection( Gesture::Pinch );
1059       controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
1060     }
1061     else if( 0 == strcmp( signalName.c_str(), SIGNAL_LONG_PRESSED ) )
1062     {
1063       controlImpl.EnableGestureDetection( Gesture::LongPress );
1064       controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
1065     }
1066     else
1067     {
1068       // signalName does not match any signal
1069       connected = false;
1070     }
1071   }
1072   return connected;
1073 }
1074
1075 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
1076 {
1077   return mImpl->mKeyEventSignal;
1078 }
1079
1080 bool Control::EmitKeyEventSignal( const KeyEvent& event )
1081 {
1082   // Guard against destruction during signal emission
1083   Dali::Toolkit::Control handle( GetOwner() );
1084
1085   bool consumed = false;
1086
1087   // signals are allocated dynamically when someone connects
1088   if ( !mImpl->mKeyEventSignal.Empty() )
1089   {
1090     consumed = mImpl->mKeyEventSignal.Emit( handle, event );
1091   }
1092
1093   if (!consumed)
1094   {
1095     // Notification for derived classes
1096     consumed = OnKeyEvent(event);
1097   }
1098
1099   return consumed;
1100 }
1101
1102 Control::Control( ControlBehaviour behaviourFlags )
1103 : CustomActorImpl( behaviourFlags & REQUIRES_TOUCH_EVENTS ),
1104   mImpl(new Impl(*this))
1105 {
1106   mImpl->mFlags = behaviourFlags;
1107 }
1108
1109 void Control::Initialize()
1110 {
1111
1112   // Calling deriving classes
1113   OnInitialize();
1114
1115   if( mImpl->mFlags & REQUIRES_STYLE_CHANGE_SIGNALS )
1116   {
1117     Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
1118
1119     // Register for style changes
1120     styleManager.StyleChangeSignal().Connect( this, &Control::DoStyleChange );
1121
1122     // SetTheme
1123     GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1124   }
1125
1126   SetRequiresHoverEvents(mImpl->mFlags & REQUIRES_HOVER_EVENTS);
1127   SetRequiresMouseWheelEvents(mImpl->mFlags & REQUIRES_MOUSE_WHEEL_EVENTS);
1128
1129   mImpl->mInitialized = true;
1130 }
1131
1132 void Control::EnableGestureDetection(Gesture::Type type)
1133 {
1134   if ( (type & Gesture::Pinch) && !mImpl->mPinchGestureDetector )
1135   {
1136     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
1137     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
1138     mImpl->mPinchGestureDetector.Attach(Self());
1139   }
1140
1141   if ( (type & Gesture::Pan) && !mImpl->mPanGestureDetector )
1142   {
1143     mImpl->mPanGestureDetector = PanGestureDetector::New();
1144     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
1145     mImpl->mPanGestureDetector.Attach(Self());
1146   }
1147
1148   if ( (type & Gesture::Tap) && !mImpl->mTapGestureDetector )
1149   {
1150     mImpl->mTapGestureDetector = TapGestureDetector::New();
1151     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
1152     mImpl->mTapGestureDetector.Attach(Self());
1153   }
1154
1155   if ( (type & Gesture::LongPress) && !mImpl->mLongPressGestureDetector )
1156   {
1157     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
1158     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
1159     mImpl->mLongPressGestureDetector.Attach(Self());
1160   }
1161 }
1162
1163 void Control::DisableGestureDetection(Gesture::Type type)
1164 {
1165   if ( (type & Gesture::Pinch) && mImpl->mPinchGestureDetector )
1166   {
1167     mImpl->mPinchGestureDetector.Detach(Self());
1168     mImpl->mPinchGestureDetector.Reset();
1169   }
1170
1171   if ( (type & Gesture::Pan) && mImpl->mPanGestureDetector )
1172   {
1173     mImpl->mPanGestureDetector.Detach(Self());
1174     mImpl->mPanGestureDetector.Reset();
1175   }
1176
1177   if ( (type & Gesture::Tap) && mImpl->mTapGestureDetector )
1178   {
1179     mImpl->mTapGestureDetector.Detach(Self());
1180     mImpl->mTapGestureDetector.Reset();
1181   }
1182
1183   if ( (type & Gesture::LongPress) && mImpl->mLongPressGestureDetector)
1184   {
1185     mImpl->mLongPressGestureDetector.Detach(Self());
1186     mImpl->mLongPressGestureDetector.Reset();
1187   }
1188 }
1189
1190 void Control::RelayoutRequest()
1191 {
1192   // unfortunate double negative but thats to guarantee new controls get size negotiation
1193   // by default and have to "opt-out" if they dont want it
1194   if( !(mImpl->mFlags & NO_SIZE_NEGOTIATION) )
1195   {
1196     Internal::RelayoutController::Request();
1197   }
1198 }
1199
1200 void Control::Relayout( Actor actor, const Vector2& size, ActorSizeContainer& container )
1201 {
1202   if ( actor )
1203   {
1204     Toolkit::Control control( Toolkit::Control::DownCast( actor ) );
1205     if( control )
1206     {
1207       control.GetImplementation().NegotiateSize( size, container );
1208     }
1209     else
1210     {
1211       container.push_back( ActorSizePair( actor, size ) );
1212     }
1213   }
1214 }
1215
1216 void Control::OnInitialize()
1217 {
1218 }
1219
1220 void Control::OnActivated()
1221 {
1222 }
1223
1224 void Control::OnThemeChange( Toolkit::StyleManager styleManager )
1225 {
1226   GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1227 }
1228
1229 void Control::OnFontChange( bool defaultFontChange, bool defaultFontSizeChange )
1230 {
1231 }
1232
1233 void Control::OnPinch(const PinchGesture& pinch)
1234 {
1235   if( !( mImpl->mStartingPinchScale ) )
1236   {
1237     // lazy allocate
1238     mImpl->mStartingPinchScale = new Vector3;
1239   }
1240
1241   if( pinch.state == Gesture::Started )
1242   {
1243     *( mImpl->mStartingPinchScale ) = Self().GetCurrentScale();
1244   }
1245
1246   Self().SetScale( *( mImpl->mStartingPinchScale ) * pinch.scale );
1247 }
1248
1249 void Control::OnPan( const PanGesture& pan )
1250 {
1251 }
1252
1253 void Control::OnTap(const TapGesture& tap)
1254 {
1255 }
1256
1257 void Control::OnLongPress( const LongPressGesture& longPress )
1258 {
1259 }
1260
1261 void Control::OnControlStageConnection()
1262 {
1263 }
1264
1265 void Control::OnControlStageDisconnection()
1266 {
1267 }
1268
1269 void Control::OnControlChildAdd( Actor& child )
1270 {
1271 }
1272
1273 void Control::OnControlChildRemove( Actor& child )
1274 {
1275 }
1276
1277 void Control::OnControlSizeSet( const Vector3& size )
1278 {
1279 }
1280
1281 void Control::OnRelayout( const Vector2& size, ActorSizeContainer& container )
1282 {
1283   unsigned int numChildren = Self().GetChildCount();
1284
1285   for( unsigned int i=0; i<numChildren; ++i )
1286   {
1287     container.push_back( ActorSizePair( Self().GetChildAt(i), size ) );
1288   }
1289 }
1290
1291 void Control::OnKeyInputFocusGained()
1292 {
1293   // Do Nothing
1294 }
1295
1296 void Control::OnKeyInputFocusLost()
1297 {
1298   // Do Nothing
1299 }
1300
1301 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1302 {
1303   // @todo consider animating negotiated child sizes to target size
1304 }
1305
1306 bool Control::OnTouchEvent(const TouchEvent& event)
1307 {
1308   return false; // Do not consume
1309 }
1310
1311 bool Control::OnHoverEvent(const HoverEvent& event)
1312 {
1313   return false; // Do not consume
1314 }
1315
1316 bool Control::OnKeyEvent(const KeyEvent& event)
1317 {
1318   return false; // Do not consume
1319 }
1320
1321 bool Control::OnMouseWheelEvent(const MouseWheelEvent& event)
1322 {
1323   return false; // Do not consume
1324 }
1325
1326 Actor Control::GetChildByAlias(const std::string& actorAlias)
1327 {
1328   return Actor();
1329 }
1330
1331 void Control::OnStageConnection()
1332 {
1333   RelayoutRequest();
1334
1335   // Notify derived classes.
1336   OnControlStageConnection();
1337 }
1338
1339 void Control::OnStageDisconnection()
1340 {
1341   // Notify derived classes
1342   OnControlStageDisconnection();
1343 }
1344
1345 void Control::OnChildAdd(Actor& child)
1346 {
1347   // If this is the background actor, then we do not want to relayout or inform deriving classes
1348   if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
1349   {
1350     return;
1351   }
1352
1353   // Request for relayout as we may need to position the new child and old ones
1354   RelayoutRequest();
1355
1356   // Notify derived classes.
1357   OnControlChildAdd( child );
1358 }
1359
1360 void Control::OnChildRemove(Actor& child)
1361 {
1362   // If this is the background actor, then we do not want to relayout or inform deriving classes
1363   if ( mImpl->mBackground && ( child == mImpl->mBackground->actor ) )
1364   {
1365     return;
1366   }
1367
1368   // Request for relayout as we may need to re-position the old child
1369   RelayoutRequest();
1370
1371   // Notify derived classes.
1372   OnControlChildRemove( child );
1373 }
1374
1375 void Control::OnSizeSet(const Vector3& targetSize)
1376 {
1377   if( ( !mImpl->mInsideRelayout ) && ( targetSize != mImpl->mNaturalSize ) )
1378   {
1379     // Only updates size if set through Actor's API
1380     mImpl->mNaturalSize = targetSize;
1381   }
1382
1383   if( targetSize != mImpl->mCurrentSize )
1384   {
1385     // Update control size.
1386     mImpl->mCurrentSize = targetSize;
1387
1388     // Notify derived classes.
1389     OnControlSizeSet( targetSize );
1390   }
1391 }
1392
1393 void Control::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
1394 {
1395   mImpl->SignalConnected( slotObserver, callback );
1396 }
1397
1398 void Control::SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback )
1399 {
1400   mImpl->SignalDisconnected( slotObserver, callback );
1401 }
1402
1403 void Control::DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
1404 {
1405   if( change.themeChange )
1406   {
1407     OnThemeChange( styleManager );
1408   }
1409   else if( change.defaultFontChange || change.defaultFontSizeChange )
1410   {
1411     OnFontChange( change.defaultFontChange, change.defaultFontSizeChange );
1412   }
1413 }
1414
1415 } // namespace Internal
1416
1417 } // namespace Toolkit
1418
1419 } // namespace Dali