New with additional behavior flag for some Controls
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
1 /*
2  * Copyright (c) 2022 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 <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/public-api/animation/constraint.h>
27 #include <dali/public-api/object/type-info.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/public-api/size-negotiation/relayout-container.h>
30 #include <cstring> // for strcmp
31 #include <limits>
32 #include <stack>
33 #include <typeinfo>
34
35 // INTERNAL INCLUDES
36 #include <dali-toolkit/dali-toolkit.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/controls/control-devel.h>
39 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
40 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
41 #include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
42 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
43 #include <dali-toolkit/internal/styling/style-manager-impl.h>
44 #include <dali-toolkit/internal/visuals/color/color-visual.h>
45 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
46 #include <dali-toolkit/public-api/align-enumerations.h>
47 #include <dali-toolkit/public-api/controls/control.h>
48 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
49 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
50 #include <dali-toolkit/public-api/styling/style-manager.h>
51 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
52 #include <dali-toolkit/public-api/visuals/visual-properties.h>
53
54 namespace Dali
55 {
56 namespace Toolkit
57 {
58 namespace Internal
59 {
60 namespace
61 {
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_CONTROL_VISUALS");
64 #endif
65
66 /**
67  * @brief Creates a clipping renderer if required.
68  * (EG. If no renders exist and clipping is enabled).
69  * @param[in] controlImpl The control implementation.
70  */
71 void CreateClippingRenderer(Control& controlImpl)
72 {
73   // We want to add a transparent background if we do not have one for clipping.
74   Actor self(controlImpl.Self());
75   int   clippingMode = ClippingMode::DISABLED;
76   if(self.GetProperty(Actor::Property::CLIPPING_MODE).Get(clippingMode))
77   {
78     Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get(controlImpl);
79
80     if(clippingMode == ClippingMode::CLIP_CHILDREN && controlDataImpl.mVisuals.Empty() && self.GetRendererCount() == 0u)
81     {
82       controlImpl.SetBackgroundColor(Color::TRANSPARENT);
83     }
84   }
85 }
86
87 } // unnamed namespace
88
89 Toolkit::Control Control::New()
90 {
91   return New(ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
92 }
93
94 Toolkit::Control Control::New(ControlBehaviour additionalBehaviour)
95 {
96   // Create the implementation, temporarily owned on stack
97   IntrusivePtr<Control> controlImpl = new Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour));
98
99   // Pass ownership to handle
100   Toolkit::Control handle(*controlImpl);
101
102   // Second-phase init of the implementation
103   // This can only be done after the CustomActor connection has been made...
104   controlImpl->Initialize();
105
106   return handle;
107 }
108
109 void Control::SetStyleName(const std::string& styleName)
110 {
111   if(styleName != mImpl->mStyleName)
112   {
113     mImpl->mStyleName = styleName;
114
115     // Apply new style, if stylemanager is available
116     Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
117     if(styleManager)
118     {
119       GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
120     }
121   }
122 }
123
124 const std::string& Control::GetStyleName() const
125 {
126   return mImpl->mStyleName;
127 }
128
129 void Control::SetBackgroundColor(const Vector4& color)
130 {
131   mImpl->mBackgroundColor = color;
132
133   Property::Map map;
134   map[Toolkit::Visual::Property::TYPE]           = Toolkit::Visual::COLOR;
135   map[Toolkit::ColorVisual::Property::MIX_COLOR] = color;
136
137   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
138   if(visual && visual.GetType() == Toolkit::Visual::COLOR)
139   {
140     // Update background color only
141     mImpl->DoAction(Toolkit::Control::Property::BACKGROUND, DevelVisual::Action::UPDATE_PROPERTY, map);
142     return;
143   }
144
145   SetBackground(map);
146 }
147
148 void Control::SetBackground(const Property::Map& map)
149 {
150   Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual(map);
151   visual.SetName("background");
152   if(visual)
153   {
154     mImpl->RegisterVisual(Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND);
155
156     // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
157     RelayoutRequest();
158   }
159 }
160
161 void Control::ClearBackground()
162 {
163   mImpl->UnregisterVisual(Toolkit::Control::Property::BACKGROUND);
164   mImpl->mBackgroundColor = Color::TRANSPARENT;
165
166   // Trigger a size negotiation request that may be needed when unregistering a visual.
167   RelayoutRequest();
168 }
169
170 void Control::EnableGestureDetection(GestureType::Value type)
171 {
172   if((type & GestureType::PINCH) && !mImpl->mPinchGestureDetector)
173   {
174     mImpl->mPinchGestureDetector = PinchGestureDetector::New();
175     mImpl->mPinchGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PinchDetected);
176     mImpl->mPinchGestureDetector.Attach(Self());
177   }
178
179   if((type & GestureType::PAN) && !mImpl->mPanGestureDetector)
180   {
181     mImpl->mPanGestureDetector = PanGestureDetector::New();
182     mImpl->mPanGestureDetector.SetMaximumTouchesRequired(2);
183     mImpl->mPanGestureDetector.DetectedSignal().Connect(mImpl, &Impl::PanDetected);
184     mImpl->mPanGestureDetector.Attach(Self());
185   }
186
187   if((type & GestureType::TAP) && !mImpl->mTapGestureDetector)
188   {
189     mImpl->mTapGestureDetector = TapGestureDetector::New();
190     mImpl->mTapGestureDetector.DetectedSignal().Connect(mImpl, &Impl::TapDetected);
191     mImpl->mTapGestureDetector.Attach(Self());
192   }
193
194   if((type & GestureType::LONG_PRESS) && !mImpl->mLongPressGestureDetector)
195   {
196     mImpl->mLongPressGestureDetector = LongPressGestureDetector::New();
197     mImpl->mLongPressGestureDetector.DetectedSignal().Connect(mImpl, &Impl::LongPressDetected);
198     mImpl->mLongPressGestureDetector.Attach(Self());
199   }
200 }
201
202 void Control::DisableGestureDetection(GestureType::Value type)
203 {
204   if((type & GestureType::PINCH) && mImpl->mPinchGestureDetector)
205   {
206     mImpl->mPinchGestureDetector.Detach(Self());
207     mImpl->mPinchGestureDetector.Reset();
208   }
209
210   if((type & GestureType::PAN) && mImpl->mPanGestureDetector)
211   {
212     mImpl->mPanGestureDetector.Detach(Self());
213     mImpl->mPanGestureDetector.Reset();
214   }
215
216   if((type & GestureType::TAP) && mImpl->mTapGestureDetector)
217   {
218     mImpl->mTapGestureDetector.Detach(Self());
219     mImpl->mTapGestureDetector.Reset();
220   }
221
222   if((type & GestureType::LONG_PRESS) && mImpl->mLongPressGestureDetector)
223   {
224     mImpl->mLongPressGestureDetector.Detach(Self());
225     mImpl->mLongPressGestureDetector.Reset();
226   }
227 }
228
229 PinchGestureDetector Control::GetPinchGestureDetector() const
230 {
231   return mImpl->mPinchGestureDetector;
232 }
233
234 PanGestureDetector Control::GetPanGestureDetector() const
235 {
236   return mImpl->mPanGestureDetector;
237 }
238
239 TapGestureDetector Control::GetTapGestureDetector() const
240 {
241   return mImpl->mTapGestureDetector;
242 }
243
244 LongPressGestureDetector Control::GetLongPressGestureDetector() const
245 {
246   return mImpl->mLongPressGestureDetector;
247 }
248
249 void Control::SetKeyboardNavigationSupport(bool isSupported)
250 {
251   mImpl->mIsKeyboardNavigationSupported = isSupported;
252 }
253
254 bool Control::IsKeyboardNavigationSupported()
255 {
256   return mImpl->mIsKeyboardNavigationSupported;
257 }
258
259 void Control::SetKeyInputFocus()
260 {
261   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
262   {
263     Toolkit::KeyInputFocusManager::Get().SetFocus(Toolkit::Control::DownCast(Self()));
264   }
265 }
266
267 bool Control::HasKeyInputFocus()
268 {
269   bool result = false;
270   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
271   {
272     Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
273     if(Self() == control)
274     {
275       result = true;
276     }
277   }
278   return result;
279 }
280
281 void Control::ClearKeyInputFocus()
282 {
283   if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
284   {
285     Toolkit::KeyInputFocusManager::Get().RemoveFocus(Toolkit::Control::DownCast(Self()));
286   }
287 }
288
289 void Control::SetAsKeyboardFocusGroup(bool isFocusGroup)
290 {
291   mImpl->mIsKeyboardFocusGroup = isFocusGroup;
292
293   // The following line will be removed when the deprecated API in KeyboardFocusManager is deleted
294   Toolkit::KeyboardFocusManager::Get().SetAsFocusGroup(Self(), isFocusGroup);
295 }
296
297 bool Control::IsKeyboardFocusGroup()
298 {
299   return Toolkit::KeyboardFocusManager::Get().IsFocusGroup(Self());
300 }
301
302 void Control::AccessibilityActivate()
303 {
304   // Inform deriving classes
305   OnAccessibilityActivated();
306 }
307
308 void Control::KeyboardEnter()
309 {
310   // Inform deriving classes
311   OnKeyboardEnter();
312 }
313
314 bool Control::OnAccessibilityActivated()
315 {
316   if(Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor(Self()))
317   {
318     return OnKeyboardEnter();
319   }
320   return false;
321 }
322
323 bool Control::OnKeyboardEnter()
324 {
325   return false; // Keyboard enter is not handled by default
326 }
327
328 bool Control::OnAccessibilityPan(PanGesture gesture)
329 {
330   return false; // Accessibility pan gesture is not handled by default
331 }
332
333 bool Control::OnAccessibilityValueChange(bool isIncrease)
334 {
335   return false; // Accessibility value change action is not handled by default
336 }
337
338 bool Control::OnAccessibilityZoom()
339 {
340   return false; // Accessibility zoom action is not handled by default
341 }
342
343 Actor Control::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
344 {
345   return Actor();
346 }
347
348 void Control::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor)
349 {
350 }
351
352 Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
353 {
354   return mImpl->mKeyEventSignal;
355 }
356
357 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
358 {
359   return mImpl->mKeyInputFocusGainedSignal;
360 }
361
362 Toolkit::Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
363 {
364   return mImpl->mKeyInputFocusLostSignal;
365 }
366
367 bool Control::EmitKeyEventSignal(const KeyEvent& event)
368 {
369   // Guard against destruction during signal emission
370   Dali::Toolkit::Control handle(GetOwner());
371
372   bool consumed = false;
373
374   consumed = mImpl->FilterKeyEvent(event);
375
376   // signals are allocated dynamically when someone connects
377   if(!consumed && !mImpl->mKeyEventSignal.Empty())
378   {
379     consumed = mImpl->mKeyEventSignal.Emit(handle, event);
380   }
381
382   if(!consumed)
383   {
384     // Notification for derived classes
385     consumed = OnKeyEvent(event);
386   }
387
388   return consumed;
389 }
390
391 Control::Control(ControlBehaviour behaviourFlags)
392 : CustomActorImpl(static_cast<ActorFlags>(behaviourFlags)),
393   mImpl(new Impl(*this))
394 {
395   mImpl->mFlags = behaviourFlags;
396 }
397
398 Control::~Control()
399 {
400   delete mImpl;
401 }
402
403 void Control::Initialize()
404 {
405   // Call deriving classes so initialised before styling is applied to them.
406   OnInitialize();
407
408   if(!(mImpl->mFlags & DISABLE_STYLE_CHANGE_SIGNALS))
409   {
410     Toolkit::StyleManager styleManager = StyleManager::Get();
411
412     // if stylemanager is available
413     if(styleManager)
414     {
415       StyleManager& styleManagerImpl = GetImpl(styleManager);
416
417       // Register for style changes
418       styleManagerImpl.ControlStyleChangeSignal().Connect(this, &Control::OnStyleChange);
419
420       // Apply the current style
421       styleManagerImpl.ApplyThemeStyleAtInit(Toolkit::Control(GetOwner()));
422     }
423   }
424
425   if(mImpl->mFlags & REQUIRES_KEYBOARD_NAVIGATION_SUPPORT)
426   {
427     SetKeyboardNavigationSupport(true);
428   }
429
430   Dali::TypeInfo type;
431   Self().GetTypeInfo(type);
432   if(type)
433   {
434     auto typeName = type.GetName();
435     DevelControl::AppendAccessibilityAttribute(Self(), "class", typeName);
436   }
437 }
438
439 void Control::OnInitialize()
440 {
441 }
442
443 void Control::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
444 {
445   // By default the control is only interested in theme (not font) changes
446   if(styleManager && change == StyleChange::THEME_CHANGE)
447   {
448     GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
449     RelayoutRequest();
450   }
451 }
452
453 void Control::OnPinch(const PinchGesture& pinch)
454 {
455   if(!(mImpl->mStartingPinchScale))
456   {
457     // lazy allocate
458     mImpl->mStartingPinchScale = new Vector3;
459   }
460
461   if(pinch.GetState() == GestureState::STARTED)
462   {
463     *(mImpl->mStartingPinchScale) = Self().GetCurrentProperty<Vector3>(Actor::Property::SCALE);
464   }
465
466   Self().SetProperty(Actor::Property::SCALE, *(mImpl->mStartingPinchScale) * pinch.GetScale());
467 }
468
469 void Control::OnPan(const PanGesture& pan)
470 {
471 }
472
473 void Control::OnTap(const TapGesture& tap)
474 {
475 }
476
477 void Control::OnLongPress(const LongPressGesture& longPress)
478 {
479 }
480
481 void Control::EmitKeyInputFocusSignal(bool focusGained)
482 {
483   Dali::Toolkit::Control handle(GetOwner());
484
485   if(Accessibility::IsUp())
486   {
487     auto self = mImpl->GetAccessibilityObject(Self());
488     self->EmitFocused(focusGained);
489     auto parent = self->GetParent();
490     if(parent && !self->GetStates()[Dali::Accessibility::State::MANAGES_DESCENDANTS])
491     {
492       parent->EmitActiveDescendantChanged(self);
493     }
494   }
495
496   if(focusGained)
497   {
498     // signals are allocated dynamically when someone connects
499     if(!mImpl->mKeyInputFocusGainedSignal.Empty())
500     {
501       mImpl->mKeyInputFocusGainedSignal.Emit(handle);
502     }
503   }
504   else
505   {
506     // signals are allocated dynamically when someone connects
507     if(!mImpl->mKeyInputFocusLostSignal.Empty())
508     {
509       mImpl->mKeyInputFocusLostSignal.Emit(handle);
510     }
511   }
512 }
513
514 void Control::OnSceneConnection(int depth)
515 {
516   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::OnSceneConnection number of registered visuals(%d)\n", mImpl->mVisuals.Size());
517
518   Actor self(Self());
519
520   for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter != mImpl->mVisuals.End(); iter++)
521   {
522     // Check whether the visual is empty and enabled
523     if((*iter)->visual && (*iter)->enabled)
524     {
525       DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::OnSceneConnection Setting visual(%d) on scene\n", (*iter)->index);
526       Toolkit::GetImplementation((*iter)->visual).SetOnScene(self);
527     }
528   }
529
530   // The clipping renderer is only created if required.
531   CreateClippingRenderer(*this);
532 }
533
534 void Control::OnSceneDisconnection()
535 {
536   mImpl->OnSceneDisconnection();
537 }
538
539 void Control::OnKeyInputFocusGained()
540 {
541   EmitKeyInputFocusSignal(true);
542 }
543
544 void Control::OnKeyInputFocusLost()
545 {
546   EmitKeyInputFocusSignal(false);
547 }
548
549 void Control::OnChildAdd(Actor& child)
550 {
551 }
552
553 void Control::OnChildRemove(Actor& child)
554 {
555 }
556
557 void Control::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
558 {
559   // If the clipping mode has been set, we may need to create a renderer.
560   // Only do this if we are already on-stage as the OnSceneConnection will handle the off-stage clipping controls.
561   switch(index)
562   {
563     case Actor::Property::CLIPPING_MODE:
564     {
565       if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
566       {
567         // Note: This method will handle whether creation of the renderer is required.
568         CreateClippingRenderer(*this);
569       }
570       break;
571     }
572     case Actor::Property::VISIBLE:
573     {
574       if(Dali::Accessibility::IsUp() && !Self().GetProperty<bool>(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN))
575       {
576         Dali::Accessibility::Accessible::Get(Self())->EmitVisible(Self().GetProperty(Actor::Property::VISIBLE).Get<bool>());
577       }
578       break;
579     }
580   }
581 }
582
583 void Control::OnSizeSet(const Vector3& targetSize)
584 {
585   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
586   if(visual)
587   {
588     Vector2 size(targetSize);
589     visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
590   }
591 }
592
593 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
594 {
595   // @todo size negotiate background to new size, animate as well?
596 }
597
598 bool Control::OnKeyEvent(const KeyEvent& event)
599 {
600   return false; // Do not consume
601 }
602
603 void Control::OnRelayout(const Vector2& size, RelayoutContainer& container)
604 {
605   for(unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i)
606   {
607     Actor   child = Self().GetChildAt(i);
608     Vector2 newChildSize(size);
609
610     // When set the padding or margin on the control, child should be resized and repositioned.
611     if((mImpl->mPadding.start != 0) || (mImpl->mPadding.end != 0) || (mImpl->mPadding.top != 0) || (mImpl->mPadding.bottom != 0) ||
612        (mImpl->mMargin.start != 0) || (mImpl->mMargin.end != 0) || (mImpl->mMargin.top != 0) || (mImpl->mMargin.bottom != 0))
613     {
614       Extents padding = mImpl->mPadding;
615
616       Dali::CustomActor           ownerActor(GetOwner());
617       Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(ownerActor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
618
619       if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
620       {
621         std::swap(padding.start, padding.end);
622       }
623
624       newChildSize.width  = size.width - (padding.start + padding.end);
625       newChildSize.height = size.height - (padding.top + padding.bottom);
626
627       // Cannot use childs Position property as it can already have padding and margin applied on it,
628       // so we end up cumulatively applying them over and over again.
629       Vector2 childOffset(0.f, 0.f);
630       childOffset.x += (mImpl->mMargin.start + padding.start);
631       childOffset.y += (mImpl->mMargin.top + padding.top);
632
633       child.SetProperty(Actor::Property::POSITION, Vector2(childOffset.x, childOffset.y));
634     }
635     container.Add(child, newChildSize);
636   }
637
638   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
639   if(visual)
640   {
641     visual.SetTransformAndSize(Property::Map(), size); // Send an empty map as we do not want to modify the visual's set transform
642   }
643 }
644
645 void Control::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
646 {
647 }
648
649 Vector3 Control::GetNaturalSize()
650 {
651   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Control::GetNaturalSize for %s\n", Self().GetProperty<std::string>(Dali::Actor::Property::NAME).c_str());
652   Toolkit::Visual::Base visual = mImpl->GetVisual(Toolkit::Control::Property::BACKGROUND);
653   if(visual)
654   {
655     Vector2 naturalSize;
656     visual.GetNaturalSize(naturalSize);
657     naturalSize.width += (mImpl->mPadding.start + mImpl->mPadding.end);
658     naturalSize.height += (mImpl->mPadding.top + mImpl->mPadding.bottom);
659     return Vector3(naturalSize);
660   }
661   return Vector3::ZERO;
662 }
663
664 float Control::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
665 {
666   return CalculateChildSizeBase(child, dimension);
667 }
668
669 float Control::GetHeightForWidth(float width)
670 {
671   return GetHeightForWidthBase(width);
672 }
673
674 float Control::GetWidthForHeight(float height)
675 {
676   return GetWidthForHeightBase(height);
677 }
678
679 bool Control::RelayoutDependentOnChildren(Dimension::Type dimension)
680 {
681   return RelayoutDependentOnChildrenBase(dimension);
682 }
683
684 void Control::OnCalculateRelayoutSize(Dimension::Type dimension)
685 {
686 }
687
688 void Control::OnLayoutNegotiated(float size, Dimension::Type dimension)
689 {
690 }
691
692 void Control::SignalConnected(SlotObserver* slotObserver, CallbackBase* callback)
693 {
694   mImpl->SignalConnected(slotObserver, callback);
695 }
696
697 void Control::SignalDisconnected(SlotObserver* slotObserver, CallbackBase* callback)
698 {
699   mImpl->SignalDisconnected(slotObserver, callback);
700 }
701
702 void Control::MakeVisualTransition(Dali::Property::Map& sourcePropertyMap, Dali::Property::Map& destinationPropertyMap,
703                                    Dali::Toolkit::Control source, Dali::Toolkit::Control destination, Dali::Property::Index visualIndex)
704 {
705   sourcePropertyMap.Clear();
706   destinationPropertyMap.Clear();
707
708   Toolkit::Visual::Base sourceVisual      = DevelControl::GetVisual(GetImplementation(source), visualIndex);
709   Toolkit::Visual::Base destinationVisual = DevelControl::GetVisual(GetImplementation(destination), visualIndex);
710
711   // If source or destination doesn't have the visual, do not create transition for the visual.
712   if(!sourceVisual || !destinationVisual)
713   {
714     return;
715   }
716
717   Property::Map sourceMap;
718   Property::Map destinationMap;
719   sourceVisual.CreatePropertyMap(sourceMap);
720   destinationVisual.CreatePropertyMap(destinationMap);
721
722   static auto findValueVector4 = [](const Property::Map& map, Property::Index index, const Vector4& defaultValue = Vector4()) -> Vector4
723   {
724     Property::Value* propertyValue = map.Find(index);
725     if(propertyValue)
726     {
727       return propertyValue->Get<Vector4>();
728     }
729     return defaultValue;
730   };
731
732   static auto findValueFloat = [](const Property::Map& map, Property::Index index, const float& defaultValue = 0.0f) -> float
733   {
734     Property::Value* propertyValue = map.Find(index);
735     if(propertyValue)
736     {
737       return propertyValue->Get<float>();
738     }
739     return defaultValue;
740   };
741
742   Vector4 defaultMixColor(Color::TRANSPARENT);
743   Vector4 defaultCornerRadius(0.0f, 0.0f, 0.0f, 0.0f);
744   float   defaultBorderlineWidth(0.0f);
745   Vector4 defaultBorderlineColor(0.0f, 0.0f, 0.0f, 1.0f);
746   float   defaultBorderlineOffset(0.0f);
747
748   Vector4 sourceMixColor         = findValueVector4(sourceMap, Dali::Toolkit::Visual::Property::MIX_COLOR, defaultMixColor);
749   Vector4 sourceCornerRadius     = findValueVector4(sourceMap, Toolkit::DevelVisual::Property::CORNER_RADIUS, defaultCornerRadius);
750   float   sourceBorderlineWidth  = findValueFloat(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, defaultBorderlineWidth);
751   Vector4 sourceBorderlineColor  = findValueVector4(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_COLOR, defaultBorderlineColor);
752   float   sourceBorderlineOffset = findValueFloat(sourceMap, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, defaultBorderlineOffset);
753
754   Vector4 destinationMixColor         = findValueVector4(destinationMap, Dali::Toolkit::Visual::Property::MIX_COLOR, defaultMixColor);
755   Vector4 destinationCornerRadius     = findValueVector4(destinationMap, Toolkit::DevelVisual::Property::CORNER_RADIUS, defaultCornerRadius);
756   float   destinationBorderlineWidth  = findValueFloat(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, defaultBorderlineWidth);
757   Vector4 destinationBorderlineColor  = findValueVector4(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_COLOR, defaultBorderlineColor);
758   float   destinationBorderlineOffset = findValueFloat(destinationMap, Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, defaultBorderlineOffset);
759
760   // If the value of the source Control and that of destination Control is different, the property should be transitioned.
761   if(Vector3(sourceMixColor) != Vector3(destinationMixColor))
762   {
763     sourcePropertyMap.Add(Dali::Toolkit::Visual::Property::MIX_COLOR, Vector3(sourceMixColor));
764     destinationPropertyMap.Add(Dali::Toolkit::Visual::Property::MIX_COLOR, Vector3(destinationMixColor));
765   }
766
767   if(std::abs(sourceMixColor.a - destinationMixColor.a) > Math::MACHINE_EPSILON_1)
768   {
769     sourcePropertyMap.Add(Dali::Toolkit::Visual::Property::OPACITY, sourceMixColor.a);
770     destinationPropertyMap.Add(Dali::Toolkit::Visual::Property::OPACITY, destinationMixColor.a);
771   }
772
773   if(sourceCornerRadius != destinationCornerRadius)
774   {
775     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS, sourceCornerRadius);
776     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS, destinationCornerRadius);
777   }
778
779   if(sourceBorderlineWidth != destinationBorderlineWidth)
780   {
781     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, sourceBorderlineWidth);
782     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, destinationBorderlineWidth);
783   }
784
785   if(sourceBorderlineColor != destinationBorderlineColor)
786   {
787     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR, sourceBorderlineColor);
788     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR, destinationBorderlineColor);
789   }
790
791   if(sourceBorderlineOffset != destinationBorderlineOffset)
792   {
793     sourcePropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, sourceBorderlineOffset);
794     destinationPropertyMap.Add(Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, destinationBorderlineOffset);
795   }
796 }
797
798 Control& GetImplementation(Dali::Toolkit::Control& handle)
799 {
800   CustomActorImpl& customInterface = handle.GetImplementation();
801   // downcast to control
802   Control& impl = dynamic_cast<Internal::Control&>(customInterface);
803   return impl;
804 }
805
806 const Control& GetImplementation(const Dali::Toolkit::Control& handle)
807 {
808   const CustomActorImpl& customInterface = handle.GetImplementation();
809   // downcast to control
810   const Control& impl = dynamic_cast<const Internal::Control&>(customInterface);
811   return impl;
812 }
813
814 } // namespace Internal
815
816 } // namespace Toolkit
817
818 } // namespace Dali