Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_ControlAnimatorImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiAnim_ControlAnimatorImpl.cpp
20  * @brief       This file contains implementation of _ControlAnimatorImpl class
21  *
22  * This file contains implementation _ControlAnimatorImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FBaseTypes.h>
27
28 #include <FUiControl.h>
29 #include <FUiCtrlForm.h>
30 #include <FUiCtrlFrame.h>
31 #include <FUiCustomControlBase.h>
32
33 #include <FUiAnimDimensionAnimation.h>
34 #include <FUiAnimPointAnimation.h>
35 #include <FUiAnimRectangleAnimation.h>
36 #include <FUiAnimIntegerAnimation.h>
37 #include <FUiAnimFloatAnimation.h>
38 #include <FUiAnimRotateAnimation.h>
39 #include <FUiAnimVisualElement.h>
40 #include <FUiAnimVisualElementPropertyAnimation.h>
41 #include <FUiAnimVisualElementAnimationGroup.h>
42 #include <FUiAnimBezierTimingFunction.h>
43
44 #include "FUi_ControlImplManager.h"
45 #include "FUi_WindowImpl.h"
46 #include "FUiAnim_ControlAnimatorImpl.h"
47 #include "FUiAnim_VisualElement.h"
48 #include "FUiAnim_VisualElementImpl.h"
49 #include "FUiAnim_VisualElementAnimationImpl.h"
50 #include "FUiAnim_VisualElementAnimationKeyFrame.h"
51 #include "FUiAnim_AnimationManager.h"
52 #include "FUiAnim_MatrixUtil.h"
53
54
55 using namespace Tizen::Base;
56 using namespace Tizen::Base::Collection;
57 using namespace Tizen::Graphics;
58 using namespace Tizen::Ui;
59 using namespace Tizen::Ui::Controls;
60
61
62 #define TRANSACTION "TRANSACTION"
63 #define GROUP   "GROUP"
64 #define POSITION "POS"
65 #define DIMENSION "DIM"
66 #define ALPHA "ALP"
67 #define ROTATION "ROT"
68
69
70 namespace Tizen { namespace Ui { namespace Animations
71 {
72
73 ///INIT_SYSCLASSTYPE(_ControlAnimatorImpl);
74
75 _ControlAnimatorImpl::_ControlAnimatorImpl(ControlAnimator* pControlAnimator)
76         : __pActiveAnimationList(null)
77         , __pControl(null)
78         , __pControlImpl(null)
79         , __animatorStatus(ANIMATOR_STATUS_STOPPED)
80         , __logicalBoundsHolder(0, 0, 0, 0)
81         , __showStateHolder(true)
82         , __targetCount(0)
83         , __prevAnimationBoundsHolder(0, 0, 0, 0)
84         , __sequentialGroupAnimation(false)
85         , __sequelDelay(0)
86         , __pControlAnimator(pControlAnimator)
87         , __pVisualElement(null)
88         , __pAnimStatusEventListener(null)
89         , __pAnimDetailedEventListener(null)
90         , __animId(0)
91         , __groupName(0)
92         , __presentationBounds(0.0f, 0.0f, 0.0f, 0.0f)
93 {
94         for (int animTarget = 0; animTarget < ANIMATION_TARGET_MAX; animTarget++)
95         {
96                 __isAnimationTargetAnimating[animTarget] = false;
97         }
98
99         for (int property = 0; property < ANIMATION_TRIGGER_SHOW_STATE_CHANGE; property++)
100         {
101                 __pPropertyAnimationGroupList[property] = null;
102                 __propertyAnimationGroupType[property] = PROPERTY_ANIMATION_GROUP_TYPE_NONE;
103         }
104 }
105
106 result
107 _ControlAnimatorImpl::Construct(const Control& source)
108 {
109         result r = E_SUCCESS;
110
111         SysAssertf((__pControl == null), "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
112
113         __pControl = const_cast< Control* >(&source);
114         __pActiveAnimationList = new (std::nothrow) ArrayListT< ActiveAnimation >();
115         SysTryCatch(NID_UI_ANIM, __pActiveAnimationList != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
116
117         r = __pActiveAnimationList->Construct();
118         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to construct _ControlAnimatorImpl instance.");
119
120         __pControlImpl = _ControlImpl::GetInstance(*__pControl);
121         __pVisualElement = __pControlImpl->GetCore().GetVisualElement();
122
123         return r;
124
125 CATCH:
126         Dispose();
127
128         return r;
129 }
130
131 _ControlAnimatorImpl::~_ControlAnimatorImpl()
132 {
133         result r = E_SUCCESS;
134
135         r = Dispose();
136
137         if (r != E_SUCCESS)
138         {
139                 SysLogException(NID_UI_ANIM, r, "[%s] Propagating.", GetErrorMessage(r));
140         }
141
142         for (int animTrigger = 0; animTrigger < ANIMATION_TRIGGER_SHOW_STATE_CHANGE; animTrigger++)
143         {
144                 if (__pPropertyAnimationGroupList[animTrigger])
145                 {
146                         __pPropertyAnimationGroupList[animTrigger]->RemoveAllAnimations();
147                         delete __pPropertyAnimationGroupList[animTrigger];
148                         __pPropertyAnimationGroupList[animTrigger] = null;
149                 }
150         }
151
152         delete __pAnimStatusEventListener;
153         __pAnimStatusEventListener = null;
154         delete __pAnimDetailedEventListener;
155         __pAnimDetailedEventListener = null;
156 }
157
158 result
159 _ControlAnimatorImpl::Dispose(void)
160 {
161         result r = E_SUCCESS;
162
163         if (__pActiveAnimationList)
164         {
165                 r = RemoveAllAnimations();
166                 if (r != E_SUCCESS)
167                 {
168                         SysLogException(NID_UI_ANIM, r, "[%s] Failed to remove all animations.", GetErrorMessage(r));
169                         r = E_SYSTEM;
170                 }
171                 __pActiveAnimationList->RemoveAll();
172
173                 delete __pActiveAnimationList;
174                 __pActiveAnimationList = null;
175         }
176
177         return r;
178 }
179
180 bool
181 _ControlAnimatorImpl::ActiveAnimation::operator ==(const _ControlAnimatorImpl::ActiveAnimation& rhs) const
182 {
183         if ((animTarget == rhs.animTarget) && (pAnimationBase == rhs.pAnimationBase))
184         {
185                 return true;
186         }
187
188         return false;
189 }
190
191 bool
192 _ControlAnimatorImpl::ActiveAnimation::operator !=(const _ControlAnimatorImpl::ActiveAnimation& rhs) const
193 {
194         if ((animTarget != rhs.animTarget) || (pAnimationBase != rhs.pAnimationBase))
195         {
196                 return true;
197         }
198
199         return false;
200 }
201
202 result
203 _ControlAnimatorImpl::SetAnimation(AnimationTargetType animTarget, AnimationBase& animationBase, ControlAnimatorTriggerType triggerType, VisualElementAnimationGroup* pAnimationGroup)
204 {
205         result r = E_SUCCESS;
206         AnimationBase* pAnimationBase = const_cast< AnimationBase* >(&animationBase);
207         String animIdentifier;
208         const IVisualElementAnimationTimingFunction* pTimingFunction = null;
209         BezierTimingFunction* pBezierTimingFunction = null;
210
211         SysTryReturnResult(NID_UI_ANIM, (animTarget > ANIMATION_TARGET_NONE && animTarget < ANIMATION_TARGET_MAX), E_INVALID_OPERATION, "Invalid Argument is used. animTarget is invalid.");
212
213         switch (pAnimationBase->GetInterpolatorType())
214         {
215         case ANIMATION_INTERPOLATOR_LINEAR:
216         {
217                 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_LINEAR);
218         }
219         break;
220
221         case ANIMATION_INTERPOLATOR_EASE_IN:
222         {
223                 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEIN);
224         }
225         break;
226
227         case ANIMATION_INTERPOLATOR_EASE_OUT:
228         {
229                 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEOUT);
230         }
231         break;
232
233         case ANIMATION_INTERPOLATOR_EASE_IN_OUT:
234         {
235                 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEINOUT);
236         }
237         break;
238
239         case ANIMATION_INTERPOLATOR_DISCRETE:
240         {
241                 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_DISCRETE);
242         }
243         break;
244
245         case ANIMATION_INTERPOLATOR_BEZIER:
246         {
247                 float cpTime1 = 0.0;
248                 float cpValue1 = 0.0;
249                 float cpTime2 = 0.0;
250                 float cpValue2 = 0.0;
251
252                 r = pAnimationBase->GetBezierControlPoints(cpTime1, cpValue1, cpTime2, cpValue2);
253                 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to get bezier points.");
254
255                 pBezierTimingFunction = new (std::nothrow) BezierTimingFunction();
256                 SysTryReturnResult(NID_UI_ANIM, (pBezierTimingFunction), E_OUT_OF_MEMORY, "Memory allocation failed.");
257
258                 pBezierTimingFunction->SetControlPoints(cpTime1, cpValue1, cpTime2, cpValue2);
259                 pTimingFunction = pBezierTimingFunction;
260
261         }
262         break;
263         }
264
265         SysTryReturnResult(NID_UI_ANIM, (pTimingFunction != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
266
267         VisualElementPropertyAnimation* pAnimation = null;
268         VisualElementValueAnimation* pBoundsAnimation = null;
269         VisualElementValueAnimation* pBaseAnimation = null;
270
271         if (animTarget == ANIMATION_TARGET_SIZE)
272         {
273                 pBoundsAnimation = new (std::nothrow) VisualElementValueAnimation();            //deletion will happen in catch/ in Destroy animation
274                 SysTryCatch(NID_UI_ANIM, (pBoundsAnimation), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
275
276                 pBoundsAnimation->SetTimingFunction(pTimingFunction);
277         }
278         else
279         {
280                 pAnimation = new (std::nothrow) VisualElementPropertyAnimation();   //deletion will happen in catch/ in Destroy animation
281                 SysTryCatch(NID_UI_ANIM, (pAnimation), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
282
283                 pAnimation->SetTimingFunction(pTimingFunction);
284         }
285
286         switch (animTarget)
287         {
288         case ANIMATION_TARGET_SIZE:
289         {
290                 DimensionAnimation* pDimensionAnim = null;
291                 RectangleAnimation* pRectangleAnim = null;
292
293                 pDimensionAnim = dynamic_cast< DimensionAnimation* >(pAnimationBase);
294                 pRectangleAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
295
296                 SysTryCatch(NID_UI_ANIM, ((pDimensionAnim) || (pRectangleAnim)), ,
297                                         E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Animation is invalid.");
298
299                 Dimension controlSize;
300                 Dimension controlPrevSize;
301                 float anchorX = 0.0f;
302                 float anchorY = 0.0f;
303
304                 float startWidth = 0.0f;
305                 float startHeight = 0.0f;
306                 float endWidth = 0.0f;
307                 float endHeight = 0.0f;
308
309                 controlSize = __pControl->GetSize();
310                 controlPrevSize.width = __prevAnimationBoundsHolder.width;
311                 controlPrevSize.height = __prevAnimationBoundsHolder.height;
312
313                 if (pDimensionAnim)
314                 {
315                         pDimensionAnim->GetAnchor(anchorX, anchorY);
316
317                         Dimension startSize = pDimensionAnim->GetStartValue();
318                         Dimension endSize = pDimensionAnim->GetEndValue();
319
320                         startWidth = static_cast< float >(startSize.width);
321                         startHeight = static_cast< float >(startSize.height);
322                         endWidth = static_cast< float >(endSize.width);
323                         endHeight = static_cast< float >(endSize.height);
324
325                         if (__sequentialGroupAnimation)
326                         {
327                                 controlSize = controlPrevSize;
328                         }
329
330 #if  MULTI_RESOLUTION
331                         Dimension StartDim = _CoordinateSystemUtils::Transform(StartSize);
332                         Dimension EndDim = _CoordinateSystemUtils::Transform(EndSize);
333                         Dimension ControlDim = _CoordinateSystemUtils::Transform(ControlSize);
334
335                         Dimension ControlPrevDim = _CoordinateSystemUtils::Transform(ControlPrevSize);
336                         ControlPrevSize = ControlPrevDim;
337
338                         StartSize = StartDim;
339                         EndSize = EndDim;
340                         ControlSize = ControlDim;
341 #endif
342                 }
343                 else
344                 {
345                         pRectangleAnim->GetAnchor(anchorX, anchorY);
346
347                         Rectangle startSize = pRectangleAnim->GetStartValue();
348                         Rectangle endSize = pRectangleAnim->GetEndValue();
349
350                         if (__sequentialGroupAnimation)
351                         {
352                                 controlSize = controlPrevSize;
353                         }
354
355                         startWidth = static_cast< float >(startSize.width);
356                         startHeight = static_cast< float >(startSize.height);
357                         endWidth = static_cast< float >(endSize.width);
358                         endHeight = static_cast< float >(endSize.height);
359
360 #if  MULTI_RESOLUTION
361                         Rectangle StartRect = _CoordinateSystemUtils::Transform(StartSize);
362                         Rectangle EndRect = _CoordinateSystemUtils::Transform(EndSize);
363                         Dimension ControlDim = _CoordinateSystemUtils::Transform(ControlSize);
364
365                         Dimension ControlPrevDim = _CoordinateSystemUtils::Transform(ControlPrevSize);
366                         ControlPrevSize = ControlPrevDim;
367
368                         StartSize = StartRect;
369                         EndSize = EndRect;
370                         ControlSize = ControlDim;
371 #endif
372                 }
373
374                 FloatRectangle presentationBounds = const_cast<VisualElement*>((__pVisualElement)->AcquirePresentationInstance())->GetBounds();
375                 FloatRectangle modelBounds = __pVisualElement->GetBounds();
376
377                 __presentationBounds = presentationBounds;
378
379                 float currentAnchorX = presentationBounds.width * anchorX;
380                 float currentAnchorY = presentationBounds.height * anchorY;
381
382                 float startAnchorX = startWidth * anchorX;
383                 float startAnchorY = startHeight * anchorY;
384
385                 float endAnchorX = endWidth * anchorX;
386                 float endAnchorY = endHeight * anchorY;
387
388                 float startX = presentationBounds.x + (currentAnchorX - startAnchorX);
389                 float startY = presentationBounds.y + (currentAnchorY - startAnchorY);
390
391                 float endX = modelBounds.x + (currentAnchorX - endAnchorX);
392                 float endY = modelBounds.y + (currentAnchorY - endAnchorY);
393
394                 pBoundsAnimation->SetStartValue(Variant(FloatRectangle(startX, startY, startWidth, startHeight)));
395                 pBoundsAnimation->SetEndValue(Variant(FloatRectangle(endX, endY, endWidth, endHeight)));
396                 pBoundsAnimation->SetVisualElementAnimationTickEventListener(this);
397                 animIdentifier.Append(DIMENSION);
398
399                 __pVisualElement->ReleasePresentationInstance();
400         }
401         break;
402
403         case ANIMATION_TARGET_POSITION:
404         {
405                 PointAnimation* pPointAnim = null;
406                 RectangleAnimation* pRectangleAnim = null;
407
408                 pPointAnim = dynamic_cast< PointAnimation* >(pAnimationBase);
409                 pRectangleAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
410
411                 SysTryCatch(NID_UI_ANIM, ((pPointAnim) || (pRectangleAnim)), , E_INVALID_ARG,
412                                    "[E_INVALID_ARG] Invalid argument(s) is used. Animation is invalid.");
413
414                 Point controlPos;
415                 float absStartX = 0.0f;
416                 float absStartY = 0.0f;
417                 float absEndX = 0.0f;
418                 float absEndY = 0.0f;
419
420                 controlPos = __pControl->GetPosition();
421
422                 Point parentPosition(0, 0);
423
424                 if (__pControlImpl->GetParent())
425                 {
426                         parentPosition.x = __pControlImpl->GetParent()->GetClientBounds().x;
427                         parentPosition.y = __pControlImpl->GetParent()->GetClientBounds().y;
428                 }
429
430                 if (pPointAnim)
431                 {
432                         Point startPos = pPointAnim->GetStartValue();
433                         Point endPos = pPointAnim->GetEndValue();
434
435                         absStartX = (static_cast< float >(parentPosition.x) + static_cast< float >(startPos.x));
436                         absStartY = (static_cast< float >(parentPosition.y) + static_cast< float >(startPos.y));
437
438                         absEndX = (static_cast< float >(parentPosition.x) + static_cast< float >(endPos.x));
439                         absEndY = (static_cast< float >(parentPosition.y) + static_cast< float >(endPos.y));
440
441                         //Todo : below API's are unavailable now
442 #if MULTI_RESOLUTION
443                         Point StartPt = _CoordinateSystemUtils::Transform(StartPos);
444                         Point EndPt = _CoordinateSystemUtils::Transform(EndPos);
445                         Point ControlPt = _CoordinateSystemUtils::Transform(controlPos);
446                         StartPos = StartPt;
447                         EndPos = EndPt;
448                         controlPos = ControlPt;
449 #endif
450                 }
451                 else
452                 {
453                         Rectangle startPos = pRectangleAnim->GetStartValue();
454                         Rectangle endPos = pRectangleAnim->GetEndValue();
455
456                         absStartX = (static_cast< float >(parentPosition.x) + static_cast< float >(startPos.x));
457                         absStartY = (static_cast< float >(parentPosition.y) + static_cast< float >(startPos.y));
458
459                         absEndX = (static_cast< float >(parentPosition.x) + static_cast< float >(endPos.x));
460                         absEndY = (static_cast< float >(parentPosition.y) + static_cast< float >(endPos.y));
461
462 #if  MULTI_RESOLUTION
463                         Rectangle StartRect = _CoordinateSystemUtils::Transform(StartPos);
464                         Rectangle EndRect = _CoordinateSystemUtils::Transform(EndPos);
465                         Point ControlPt = _CoordinateSystemUtils::Transform(controlPos);
466                         StartPos = StartRect;
467                         EndPos = EndRect;
468                         controlPos = ControlPt;
469 #endif
470                 }
471
472                 pAnimation->SetPropertyName(VeSubPropBoundsPosition);
473
474                 Variant startPosition(FloatPoint(absStartX, absStartY));
475                 Variant endPosition(FloatPoint(absEndX, absEndY));
476
477                 pAnimation->SetStartValue(startPosition);
478                 pAnimation->SetEndValue(endPosition);
479                 animIdentifier.Append(POSITION);
480         }
481         break;
482
483         case ANIMATION_TARGET_ALPHA:
484         {
485                 IntegerAnimation* pIntegerAnim = null;
486                 FloatAnimation* pFloatAnim = null;
487
488                 pIntegerAnim = dynamic_cast< IntegerAnimation* >(pAnimationBase);
489                 pFloatAnim = dynamic_cast< FloatAnimation* >(pAnimationBase);
490
491                 SysTryCatch(NID_UI_ANIM, ((pIntegerAnim) || (pFloatAnim)), , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Animation is invalid.");
492
493                 pAnimation->SetPropertyName(VePrivPropShowOpacity); // need to change this with show state
494
495                 if (pIntegerAnim)
496                 {
497                         int startAlpha = 0;
498                         int endAlpha = 1;
499
500                         startAlpha = pIntegerAnim->GetStartValue();
501                         endAlpha = pIntegerAnim->GetEndValue();
502
503                         Variant startOpacityInt(static_cast< float >(startAlpha));
504                         Variant endOpacityInt(static_cast< float >(endAlpha));
505
506                         pAnimation->SetStartValue(startOpacityInt);
507                         pAnimation->SetEndValue(endOpacityInt);
508                 }
509                 else
510                 {
511                         float startAlpha = 0.0;
512                         float endAlpha = 1.0;
513
514                         startAlpha = static_cast< float >(pFloatAnim->GetStartValue());
515                         endAlpha = static_cast< float >(pFloatAnim->GetEndValue());
516
517                         Variant startOpacityFloat(startAlpha);
518                         Variant endOpacityFloat(endAlpha);
519
520                         pAnimation->SetStartValue(startOpacityFloat);
521                         pAnimation->SetEndValue(endOpacityFloat);
522                 }
523                 animIdentifier.Append(ALPHA);
524         }
525         break;
526
527         case ANIMATION_TARGET_ROTATION:
528         {
529                 RotateAnimation* pRotateAnim = null;
530                 float anchorX = 0.0f;
531                 float anchorY = 0.0f;
532
533                 pRotateAnim = dynamic_cast< RotateAnimation* >(pAnimationBase);
534                 SysTryCatch(NID_UI_ANIM, (pRotateAnim), , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Animation is invalid.");
535
536                 pAnimation->SetPropertyName(VeSubPropTransformRotationZ); //check this :Todo
537                 pRotateAnim->GetAnchor(anchorX, anchorY);
538
539                 _VisualElementImpl::GetInstance(*__pVisualElement)->SetAnchor(FloatPoint(anchorX, anchorY));
540
541                 pAnimation->SetStartValue(Variant(pRotateAnim->GetStartValue()));
542                 pAnimation->SetEndValue(Variant(pRotateAnim->GetEndValue()));
543                 animIdentifier.Append(ROTATION);
544         }
545         break;
546
547         default:
548                 SysAssertf(false, "Animation type is invalid!");
549                 break;
550         }
551
552         if (animTarget == ANIMATION_TARGET_SIZE)
553         {
554                 pBaseAnimation = pBoundsAnimation;
555         }
556         else
557         {
558                 pBaseAnimation = pAnimation;
559         }
560
561         //Set the Animation values and start the Animation
562         pBaseAnimation->SetRepeatCount(pAnimationBase->GetRepeatCount());
563         pBaseAnimation->SetEndValueApplied(pAnimationBase->IsHoldEndEnabled());
564         pBaseAnimation->SetAutoReverseEnabled(pAnimationBase->IsAutoReverseEnabled());
565         pBaseAnimation->SetScaleRatio(pAnimationBase->GetScaleRatio());
566         pBaseAnimation->SetDuration(pAnimationBase->GetDuration());
567         pBaseAnimation->SetOffset(pAnimationBase->GetOffset());
568         pBaseAnimation->SetDelay(pAnimationBase->GetDelay());
569         pBaseAnimation->SetVisualElementAnimationStatusEventListener(this);
570
571         if (__sequentialGroupAnimation)
572         {
573                 pBaseAnimation->SetDelay(pAnimationBase->GetDelay() + __sequelDelay);
574         }
575
576         if (pAnimationBase->GetKeyFrameCount() > 0)
577         {
578                 r = SetKeyFrameAnimation(animTarget, pAnimationBase, pTimingFunction, pBaseAnimation);
579         }
580
581         animIdentifier.Append(__animId);
582
583         if (_AnimationManager::GetInstance()->GetCurrentTransaction() != null)
584         {
585                 animIdentifier.Append(TRANSACTION);
586         }
587
588         __animId++;
589
590         if (pAnimationGroup == null)
591         {
592                 r = __pVisualElement->AddAnimation(animIdentifier, *pBaseAnimation);
593                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation could not be started.");
594                 r = AddActiveAnimation(animTarget, *pAnimationBase, *pBaseAnimation, triggerType, animIdentifier, pBezierTimingFunction);   //Todo : check this
595                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation could not be added to playlist.");
596         }
597         else
598         {
599                 String* pAnimName = new (std::nothrow) String(animIdentifier.GetLength() + __groupName.GetLength());
600                 SysTryCatch(NID_UI_ANIM, (pAnimName != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
601
602                 *pAnimName = animIdentifier;
603
604                 pAnimName->Append(__groupName);
605
606                 pBaseAnimation->SetUserData((void*) (pAnimName));
607
608                 r = pAnimationGroup->AddAnimation(*pBaseAnimation);
609                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation could not be added to the group.");
610                 r = AddActiveAnimation(animTarget, *pAnimationBase, *pBaseAnimation, triggerType, *pAnimName, pBezierTimingFunction);
611                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation could not be added to playlist.");
612         }
613
614         return r;
615
616 CATCH:
617         //In case of error: free pAnimationBase if not added to ActiveAnimList. If added, its freed in Destroy Animation.
618         delete pAnimationBase;
619         delete pAnimation;
620         delete pBoundsAnimation;
621         delete pBezierTimingFunction;
622
623         return r;
624 }
625
626 result
627 _ControlAnimatorImpl::SetCustomImplicitAnimationParams(ControlAnimatorTriggerType triggerType, AnimationBase& animationBase, Rectangle& bounds, bool showState, bool lastTargetOccurence)
628 {
629         result r = E_SUCCESS;
630
631         AnimationBase* pAnimationBase = const_cast< AnimationBase* >(&animationBase);
632
633         if ((__targetCount == 1) || ((__targetCount > 1) && lastTargetOccurence))
634         {
635                 pAnimationBase->SetHoldEndEnabled(true);
636                 pAnimationBase->SetAutoReverseEnabled(false);
637         }
638
639         if (triggerType == ANIMATION_TRIGGER_POSITION_CHANGE)
640         {
641                 Point newPosition = Point(bounds.x, bounds.y);
642                 Point currentPosition = __pControl->GetPosition();
643
644                 PointAnimation* pPointAnim = null;
645                 RectangleAnimation* pRectangleAnim = null;
646
647                 pPointAnim = dynamic_cast< PointAnimation* >(pAnimationBase);
648                 pRectangleAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
649                 SysTryReturnResult(NID_UI_ANIM, ((pPointAnim) || (pRectangleAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
650
651                 if (pPointAnim)
652                 {
653                         if (__targetCount == 1)
654                         {
655                                 pPointAnim->SetStartValue(currentPosition);
656                                 pPointAnim->SetEndValue(newPosition);
657                         }
658                         else    //__targetCount > 1
659                         {
660                                 (lastTargetOccurence) ? (pPointAnim->SetEndValue(newPosition)) : (pPointAnim->SetStartValue(currentPosition));
661                         }
662                         pAnimationBase = pPointAnim;
663                 }
664                 else    //if (pRectangleAnim)
665                 {
666                         Rectangle newRectangle = Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
667                         Rectangle currentRectangle = Rectangle(__pControl->GetBounds());
668
669                         if (__targetCount == 1)
670                         {
671                                 pRectangleAnim->SetStartValue(currentRectangle);
672                                 pRectangleAnim->SetEndValue(newRectangle);
673                         }
674                         else    //__targetCount > 1
675                         {
676                                 (lastTargetOccurence) ? (pRectangleAnim->SetEndValue(newRectangle)) : (pRectangleAnim->SetStartValue(currentRectangle));
677                         }
678                         pAnimationBase = pRectangleAnim;
679                 }
680         }
681         else if (triggerType == ANIMATION_TRIGGER_SIZE_CHANGE)
682         {
683                 Dimension newSize = Dimension(bounds.width, bounds.height);
684                 Dimension currentSize = __pControl->GetSize();
685
686                 DimensionAnimation* pDimensionAnim = null;
687                 RectangleAnimation* pRectangleAnim = null;
688
689                 pDimensionAnim = dynamic_cast< DimensionAnimation* >(pAnimationBase);
690                 pRectangleAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
691                 SysTryReturnResult(NID_UI_ANIM, ((pDimensionAnim) || (pRectangleAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
692
693                 if (pDimensionAnim)
694                 {
695                         if (__targetCount == 1)
696                         {
697                                 pDimensionAnim->SetStartValue(currentSize);
698                                 pDimensionAnim->SetEndValue(newSize);
699                         }
700                         else    //__targetCount > 1
701                         {
702                                 (lastTargetOccurence) ? (pDimensionAnim->SetEndValue(newSize)) : (pDimensionAnim->SetStartValue(currentSize));
703                         }
704                         pAnimationBase = pDimensionAnim;
705                 }
706                 else    //if (pRectangleAnim)
707                 {
708                         Rectangle newRectangle = Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
709                         Rectangle currentRectangle = Rectangle(__pControl->GetBounds());
710
711                         if (__targetCount == 1)
712                         {
713                                 pRectangleAnim->SetStartValue(currentRectangle);
714                                 pRectangleAnim->SetEndValue(newRectangle);
715                         }
716                         else    //__targetCount > 1
717                         {
718                                 (lastTargetOccurence) ? (pRectangleAnim->SetEndValue(newRectangle)) : (pRectangleAnim->SetStartValue(currentRectangle));
719                         }
720                         pAnimationBase = pRectangleAnim;
721                 }
722         }
723         if (triggerType == ANIMATION_TRIGGER_SHOW_STATE_CHANGE)
724         {
725                 FloatAnimation* pFloatAnim = null;
726                 IntegerAnimation* pIntegerAnim = null;
727
728                 pFloatAnim = dynamic_cast< FloatAnimation* >(pAnimationBase);
729                 pIntegerAnim = dynamic_cast< IntegerAnimation* >(pAnimationBase);
730                 SysTryReturnResult(NID_UI_ANIM, ((pFloatAnim) || (pIntegerAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
731
732                 float newShowState = 0.0f;
733                 float currentShowState = 0.0f;
734                 int inewShowState = 0;
735                 int icurrentShowState = 0;
736
737                 if (pFloatAnim)
738                 {
739                         newShowState = ((showState) ? (1.0f) : (0.0f));
740                         currentShowState = ((showState) ? (0.0f) : (1.0f));
741                 }
742                 else    //if (pIntegerAnim)
743                 {
744                         inewShowState = ((showState) ? (1) : (0));
745                         icurrentShowState = ((showState) ? (0) : (1));
746                 }
747
748                 if (pFloatAnim)
749                 {
750                         if (__targetCount == 1)
751                         {
752                                 pFloatAnim->SetStartValue(currentShowState);
753                                 pFloatAnim->SetEndValue(newShowState);
754                         }
755                         else    //__targetCount > 1
756                         {
757                                 (lastTargetOccurence) ? (pFloatAnim->SetEndValue(newShowState)) : (pFloatAnim->SetStartValue(currentShowState));
758                         }
759                         pAnimationBase = pFloatAnim;
760                 }
761                 else    //if (pIntegerAnim)
762                 {
763                         if (__targetCount == 1)
764                         {
765                                 pIntegerAnim->SetStartValue(icurrentShowState);
766                                 pIntegerAnim->SetEndValue(inewShowState);
767                         }
768                         else    //__targetCount > 1
769                         {
770                                 (lastTargetOccurence) ? (pIntegerAnim->SetEndValue(inewShowState)) : (pIntegerAnim->SetStartValue(icurrentShowState));
771                         }
772                         pAnimationBase = pIntegerAnim;
773                 }
774         }
775         return r;
776 }
777
778 result
779 _ControlAnimatorImpl::StartCustomImplicitAnimation(ControlAnimatorTriggerType triggerType, int x, int y, int width, int height, bool showState)
780 {
781         result r = E_SUCCESS;
782         SysTryReturnResult(NID_UI_ANIM, (triggerType == ANIMATION_TRIGGER_POSITION_CHANGE ||
783                                                                         triggerType == ANIMATION_TRIGGER_SIZE_CHANGE ||
784                                                                         triggerType == ANIMATION_TRIGGER_SHOW_STATE_CHANGE), E_INVALID_ARG, "Invalid argument(s) is used. Trigger type is invalid.");
785
786         long delay = 0;
787         long totalDelay = 0;
788         long groupDuration = 0;
789
790         AnimationTargetType equivalentAnimTarget = ANIMATION_TARGET_NONE;
791
792         VisualElementAnimationGroup* pAnimationGroup = null;
793
794         __sequelDelay = 0;
795         pAnimationGroup = new (std::nothrow) VisualElementAnimationGroup();
796         SysTryReturnResult(NID_UI_ANIM, (pAnimationGroup != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
797
798         if (triggerType == ANIMATION_TRIGGER_POSITION_CHANGE)
799         {
800                 equivalentAnimTarget = ANIMATION_TARGET_POSITION;
801         }
802         else if (triggerType == ANIMATION_TRIGGER_SIZE_CHANGE)
803         {
804                 equivalentAnimTarget = ANIMATION_TARGET_SIZE;
805         }
806         else
807         {
808                 equivalentAnimTarget = ANIMATION_TARGET_ALPHA;
809         }
810
811         ParallelAnimationGroup* pParallelAnimGrp = null;
812         SequentialAnimationGroup* pSequentialAnimGrp = null;
813         String animIdentifier;
814
815         __targetCount = 0;
816         animIdentifier.Append(GROUP);
817         animIdentifier.Append(__animId);
818         __animId++;
819         __groupName.Clear();
820         __groupName = animIdentifier;
821
822         if (__propertyAnimationGroupType[triggerType - 1] == PROPERTY_ANIMATION_GROUP_TYPE_SEQUENTIAL)
823         {
824                 pSequentialAnimGrp = dynamic_cast< SequentialAnimationGroup* >(__pPropertyAnimationGroupList[triggerType - 1]);
825                 if (pSequentialAnimGrp)
826                 {
827                         for (int index = 0; index < pSequentialAnimGrp->GetAnimationCount(); index++)
828                         {
829                                 AnimationTargetType animTgt = ANIMATION_TARGET_NONE;
830
831                                 animTgt = pSequentialAnimGrp->GetAnimationTargetTypeAt(index);
832                                 if (animTgt > ANIMATION_TARGET_NONE && animTgt < ANIMATION_TARGET_MAX)
833                                 {
834                                         if (__isAnimationTargetAnimating[animTgt])
835                                         {
836                                                 SysLogException(NID_UI_ANIM, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Same AnimationTargetType is being animated.");
837                                                 delete pAnimationGroup;
838                                                 return E_INVALID_OPERATION;
839                                         }
840                                 }
841                         }
842
843                         for (int index = pSequentialAnimGrp->GetAnimationCount() - 1; index >= 0; index--)
844                         {
845                                 if (pSequentialAnimGrp->GetAnimationTargetTypeAt(index) == equivalentAnimTarget)
846                                 {
847                                         __targetCount++;
848                                 }
849                         }
850
851                         //Overwrite last Animation in AnimationGroup and check for IsAnimatable
852                         bool verified = false;
853                         for (int count = pSequentialAnimGrp->GetAnimationCount() - 1; count >= 0; count--)
854                         {
855                                 AnimationTargetType animTgt = ANIMATION_TARGET_NONE;
856                                 animTgt = pSequentialAnimGrp->GetAnimationTargetTypeAt(count);
857                                 if (animTgt == equivalentAnimTarget)
858                                 {
859                                         bool animatable = false;
860                                         AnimationBase* pAnimBase = null;
861                                         pAnimBase = pSequentialAnimGrp->GetAnimationAtN(count);
862
863                                         if (pAnimBase)
864                                         {
865                                                 Rectangle rect(x, y, width, height);
866
867                                                 r = SetCustomImplicitAnimationParams(triggerType, *pAnimBase, rect, showState, true);
868
869                                                 //Comment: Only the last associated TGT_TYPE is checked for IsAnimatable as the rest is checked in ControlAnimator::SetAnimation().
870                                                 animatable = IsAnimatable(animTgt, rect, pAnimBase);
871                                                 delete pAnimBase;
872                                                 verified = true;
873                                         }
874
875                                         if ((!animatable) || (r != E_SUCCESS))
876                                         {
877                                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set custom implicit animation.");
878                                                 delete pAnimationGroup;
879                                                 return E_INVALID_ARG;
880                                         }
881
882                                         if (verified)
883                                         {
884                                                 break;
885                                         }
886                                 }
887                         }
888
889                         int firstOccurence = -1;
890                         int lastOccurence = -1;
891
892                         for (int index = 0; index < pSequentialAnimGrp->GetAnimationCount(); index++)
893                         {
894                                 if (pSequentialAnimGrp->GetAnimationTargetTypeAt(index) == equivalentAnimTarget)
895                                 {
896                                         firstOccurence = index;
897                                         break;
898                                 }
899                         }
900
901                         for (int index = pSequentialAnimGrp->GetAnimationCount() - 1; index >= 0; index--)
902                         {
903                                 if (pSequentialAnimGrp->GetAnimationTargetTypeAt(index) == equivalentAnimTarget)
904                                 {
905                                         lastOccurence = index;
906                                         break;
907                                 }
908                         }
909
910                         if (!(firstOccurence >= 0 && lastOccurence >= 0))
911                         {
912                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start custom implicit animation.");
913                                 delete pAnimationGroup;
914                                 return E_SYSTEM;
915                         }
916
917                         __prevAnimationBoundsHolder = __pControl->GetBounds();
918                         for (int index = 0; index < pSequentialAnimGrp->GetAnimationCount(); index++)
919                         {
920                                 AnimationTargetType animTarget = ANIMATION_TARGET_MAX;
921                                 AnimationBase* pAnimationBase = null;
922                                 pAnimationBase = pSequentialAnimGrp->GetAnimationAtN(index);
923                                 animTarget = pSequentialAnimGrp->GetAnimationTargetTypeAt(index);
924                                 if (pAnimationBase)
925                                 {
926                                         if (animTarget == equivalentAnimTarget)
927                                         {
928                                                 Rectangle rect(x, y, width, height);
929
930                                                 if (firstOccurence == lastOccurence) // (or) __targetCount==1
931                                                 {
932                                                         r = SetCustomImplicitAnimationParams(triggerType, *pAnimationBase, rect, showState, true);
933                                                 }
934                                                 else
935                                                 {
936                                                         if (index == firstOccurence)
937                                                         {
938                                                                 r = SetCustomImplicitAnimationParams(triggerType, *pAnimationBase, rect, showState, false);
939                                                         }
940                                                         else if (index == lastOccurence)
941                                                         {
942                                                                 r = SetCustomImplicitAnimationParams(triggerType, *pAnimationBase, rect, showState, true);
943                                                         }
944                                                 }
945                                                 if (r != E_SUCCESS)
946                                                 {
947                                                         delete pAnimationBase;
948                                                         delete pAnimationGroup;
949
950                                                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set parameters for custom implicit animation.");
951                                                         return E_SYSTEM;
952                                                 }
953                                         }
954                                         if (!IsAnimationSupported())
955                                         {
956                                                 if (animTarget == equivalentAnimTarget)
957                                                 {
958                                                         if (index == lastOccurence)
959                                                         {
960                                                                 Rectangle rect(x, y, width, height);
961
962                                                                 r = SetCustomImplicitAnimationParams(triggerType, *pAnimationBase, rect, showState, true);
963
964                                                                 if (r != E_SUCCESS)
965                                                                 {
966                                                                         delete pAnimationBase;
967                                                                         delete pAnimationGroup;
968
969                                                                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set parameters for custom implicit animation.");
970
971                                                                         return E_SYSTEM;
972                                                                 }
973
974                                                                 r = SetControlProperty(animTarget, *pAnimationBase);
975
976                                                                 delete pAnimationBase;
977                                                                 delete pAnimationGroup;
978
979                                                                 if (r != E_SUCCESS)
980                                                                 {
981                                                                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set control property.");
982                                                                         return E_SYSTEM;
983                                                                 }
984                                                                 else
985                                                                 {
986                                                                         return E_SUCCESS;
987                                                                 }
988                                                         }
989                                                 }
990                                         }
991                                         else
992                                         {
993                                                 __sequentialGroupAnimation = true;
994                                                 r = SetAnimation(animTarget, *pAnimationBase, triggerType, pAnimationGroup); //check this group animation
995                                                 __sequentialGroupAnimation = false;
996
997                                                 delay = pAnimationBase->GetDelay() + totalDelay;
998                                                 totalDelay = delay + (pAnimationBase->GetDuration() * pAnimationBase->GetRepeatCount());
999                                                 totalDelay = totalDelay - (pAnimationBase->GetOffset());
1000                                                 __sequelDelay = totalDelay;
1001                                                 groupDuration = groupDuration + __sequelDelay * pAnimationBase->GetScaleRatio();
1002
1003                                                 if (r != E_SUCCESS)
1004                                                 {
1005                                                         delete pAnimationBase;
1006                                                         delete pAnimationGroup;
1007
1008                                                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set parameters for custom implicit animation.");
1009
1010                                                         return r;
1011                                                 }
1012
1013                                                 if (animTarget == ANIMATION_TARGET_SIZE)
1014                                                 {
1015                                                         if (SetPrevAnimationBoundsProperty(animTarget, *pAnimationBase) != E_SUCCESS)
1016                                                         {
1017                                                                 delete pAnimationBase;
1018                                                                 delete pAnimationGroup;
1019
1020                                                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to store previous animation bounds.");
1021
1022                                                                 return E_SYSTEM;
1023                                                         }
1024                                                 }
1025                                         }
1026                                 }
1027                         }
1028                 }
1029         }
1030         else if (__propertyAnimationGroupType[triggerType - 1] == PROPERTY_ANIMATION_GROUP_TYPE_PARALLEL)
1031         {
1032                 pParallelAnimGrp = dynamic_cast< ParallelAnimationGroup* >(__pPropertyAnimationGroupList[triggerType - 1]);
1033                 if (pParallelAnimGrp)
1034                 {
1035                         for (int target = (static_cast< int >(ANIMATION_TARGET_NONE) + 1); target < (static_cast< int >(ANIMATION_TARGET_MAX)); target++)
1036                         {
1037
1038                                 AnimationTargetType animTgt = static_cast< AnimationTargetType >(target);
1039
1040                                 if (pParallelAnimGrp->IsAnimationAdded(animTgt) && __isAnimationTargetAnimating[animTgt])
1041                                 {
1042                                         SysLogException(NID_UI_ANIM, E_INVALID_OPERATION, " [E_INVALID_OPERATION] Same AnimationTargetType is being animated.");
1043                                         delete pAnimationGroup;
1044
1045                                         return E_INVALID_OPERATION;
1046                                 }
1047                         }
1048
1049                         __targetCount = 1;
1050                         for (int target = (static_cast< int >(ANIMATION_TARGET_NONE) + 1); target < (static_cast< int >(ANIMATION_TARGET_MAX)); target++)
1051                         {
1052                                 AnimationTargetType animTgt = static_cast< AnimationTargetType >(target);
1053                                 AnimationBase* pAnimBase = null;
1054                                 pAnimBase = pParallelAnimGrp->GetAnimationN(animTgt);
1055                                 if (pAnimBase != null)
1056                                 {
1057                                         bool animatable = false;
1058                                         if (animTgt == equivalentAnimTarget)
1059                                         {
1060                                                 Rectangle rect(x, y, width, height);
1061
1062                                                 r = SetCustomImplicitAnimationParams(triggerType, *pAnimBase, rect, showState);
1063                                                 //Comment: Only associated TGT_TYPE is checked for IsAnimatable as the rest is checked in ControlAnimator::SetAnimation().
1064                                                 animatable = IsAnimatable(animTgt, rect, pAnimBase);
1065                                         }
1066
1067                                         delete pAnimBase;
1068
1069                                         if (((animTgt == equivalentAnimTarget) && (!animatable)) || (r != E_SUCCESS))
1070                                         {
1071                                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set custom implicit animation.");
1072                                                 delete pAnimationGroup;
1073
1074                                                 return E_INVALID_ARG;
1075                                         }
1076                                 }
1077                         }
1078
1079                         AnimationTargetType animTargetArray[ANIMATION_TARGET_MAX] =
1080                         {
1081                                 ANIMATION_TARGET_ROTATION,
1082                                 ANIMATION_TARGET_SIZE,
1083                                 ANIMATION_TARGET_POSITION,
1084                                 ANIMATION_TARGET_ALPHA
1085                         };
1086
1087                         for (int target = (static_cast< int >(ANIMATION_TARGET_NONE) + 1); target < (static_cast< int >(ANIMATION_TARGET_MAX)); target++)
1088                         {
1089                                 AnimationTargetType _animTarget = animTargetArray[target];
1090                                 AnimationBase* pAnimationBase = null;
1091                                 pAnimationBase = pParallelAnimGrp->GetAnimationN(_animTarget);
1092                                 if (pAnimationBase)
1093                                 {
1094                                         long duration = pAnimationBase->GetDuration();
1095
1096                                         duration = (duration * (pAnimationBase->GetRepeatCount()) * (pAnimationBase->GetScaleRatio())) + (pAnimationBase->GetDelay()) - (pAnimationBase->GetOffset()* pAnimationBase->GetScaleRatio());
1097
1098                                         if (duration > groupDuration)
1099                                         {
1100                                                 groupDuration = duration;
1101                                         }
1102
1103                                         Rectangle rect(x, y, width, height);
1104 #if 0
1105                                         if (_animTarget == equivalentAnimTarget)
1106                                         {
1107                                                 r = SetCustomImplicitAnimationParams(triggerType, *pAnimationBase, rect, showState);
1108                                                 if (r != E_SUCCESS)
1109                                                 {
1110                                                         delete pAnimationBase;
1111                                                         delete pAnimationGroup;
1112
1113                                                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set parameters for custom implicit animation.");
1114                                                         return E_SYSTEM;
1115                                                 }
1116                                         }
1117 #endif
1118                                         if (IsAnimationSupported() == false)
1119                                         {
1120                                                 if (_animTarget == equivalentAnimTarget)
1121                                                 {
1122                                                         r = SetCustomImplicitAnimationParams(triggerType, *pAnimationBase, rect, showState, true);
1123                                                         if (r != E_SUCCESS)
1124                                                         {
1125                                                                 delete pAnimationBase;
1126                                                                 delete pAnimationGroup;
1127
1128                                                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set parameters for custom implicit animation.");
1129                                                                 return E_SYSTEM;
1130                                                         }
1131
1132                                                         r = SetControlProperty(_animTarget, *pAnimationBase);
1133
1134                                                         delete pAnimationBase;
1135                                                         delete pAnimationGroup;
1136
1137                                                         if (r != E_SUCCESS)
1138                                                         {
1139                                                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set control property.");
1140                                                                 return E_SYSTEM;
1141                                                         }
1142                                                         else
1143                                                         {
1144                                                                 return E_SUCCESS;
1145                                                         }
1146                                                 }
1147                                         }
1148                                         else
1149                                         {
1150                                                 //Create and set the animation to the layer
1151                                                 //Comment: Deep copy need not be done here as AnimationGroup did.
1152                                                 r = SetAnimation(_animTarget, *pAnimationBase, triggerType, pAnimationGroup);
1153                                                 if (r != E_SUCCESS)
1154                                                 {
1155                                                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start the animation.");
1156                                                         delete pAnimationGroup;
1157
1158                                                         return E_SYSTEM;
1159                                                 }
1160                                         }
1161                                 }
1162                         }
1163                 }
1164         }
1165
1166         if (equivalentAnimTarget != ANIMATION_TARGET_ALPHA)
1167         {
1168                 bool disable = false;
1169                 bool propagation = false;
1170
1171                 result r = DisableImplicitAnimation(disable);
1172                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
1173
1174                 r = DisableVisualElementPropagation(propagation);
1175                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
1176
1177                 r = __pControl->SetBounds(x, y, width, height);
1178
1179                 if (propagation)
1180                 {
1181                         DisableVisualElementPropagation(propagation);
1182                 }
1183                 if (disable)
1184                 {
1185                         DisableImplicitAnimation(disable);
1186                 }
1187
1188                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
1189         }
1190         else
1191         {
1192                 bool disable = false;
1193                 bool propagation = false;
1194
1195                 result r = DisableImplicitAnimation(disable);
1196                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
1197
1198                 r = DisableVisualElementPropagation(propagation);
1199                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
1200
1201                 r = __pControl->SetShowState(showState);
1202
1203                 if (propagation)
1204                 {
1205                         DisableVisualElementPropagation(propagation);
1206                 }
1207                 if (disable)
1208                 {
1209                         DisableImplicitAnimation(disable);
1210                 }
1211
1212                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set show state.");
1213         }
1214
1215         // for layout
1216         __pControlImpl->SetBoundsAndUpdateLayout(__pControlImpl->GetBounds());
1217
1218         pAnimationGroup->SetDuration(groupDuration);
1219         __pVisualElement->AddAnimation(animIdentifier, *pAnimationGroup);
1220
1221 CATCH:
1222         delete pAnimationGroup;
1223         pAnimationGroup = null;
1224
1225         return r;
1226
1227 }
1228
1229 result
1230 _ControlAnimatorImpl::AddActiveAnimation(AnimationTargetType animTarget, AnimationBase& animBase, VisualElementAnimation& animNative,
1231                                                                                         ControlAnimatorTriggerType triggerType,
1232                                                                                         const String& animName, BezierTimingFunction* pBezierTiming)
1233 {
1234         SysTryReturnResult(NID_UI_ANIM, (animTarget > ANIMATION_TARGET_NONE && animTarget < ANIMATION_TARGET_MAX), E_INVALID_ARG, "Invalid argument(s) is used. animTarget is invalid.");
1235
1236         result r = E_SUCCESS;
1237         ActiveAnimation activeAnim;
1238
1239         activeAnim.animType = triggerType;
1240         activeAnim.animTarget = animTarget;
1241         activeAnim.pAnimationBase = (&animBase);
1242         activeAnim.pAnimation = (&animNative);
1243         activeAnim.animName = animName;
1244         activeAnim.pBezierTimingFunction = pBezierTiming;
1245
1246         r = __pActiveAnimationList->Add(activeAnim);
1247         SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to add animations to active play list.");
1248
1249         return r;
1250 }
1251
1252 String
1253 _ControlAnimatorImpl::GetActiveAnimationAt(int index) const
1254 {
1255         SysTryReturn(NID_UI_ANIM, (index > 0 && __pActiveAnimationList->GetCount() > 0 && index < __pActiveAnimationList->GetCount()),
1256                                                                 null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index (%d) is out of range.", index);
1257
1258         ActiveAnimation activeAnim;
1259
1260         if (__pActiveAnimationList->GetAt(index, activeAnim) == E_SUCCESS)
1261         {
1262                 return activeAnim.animName;
1263         }
1264         else
1265         {
1266                 return null;
1267         }
1268 }
1269
1270 String
1271 _ControlAnimatorImpl::GetActiveAnimationAt(int index, ControlAnimatorTriggerType animTrigger) const
1272 {
1273         if (!((__pActiveAnimationList->GetCount() > 0) && (index < __pActiveAnimationList->GetCount()) && (index >= 0)))
1274         {
1275                 SysLog(NID_UI_ANIM, "[E_SYSTEM] A system error has been occurred. index (%d) is invalid.", index);
1276                 int empty = 0;
1277                 return String(empty);
1278         }
1279
1280         ActiveAnimation activeAnim;
1281
1282         if (__pActiveAnimationList->GetAt(index, activeAnim) == E_SUCCESS)
1283         {
1284                 if (animTrigger == activeAnim.animType)
1285                 {
1286                         return activeAnim.animName;
1287                 }
1288
1289                 return null;
1290         }
1291         else
1292         {
1293                 SysLog(NID_UI_ANIM, "[E_SYSTEM] A system error has been occurred. Failed to get from list for index = %d", index);
1294                 return null;
1295         }
1296 }
1297
1298 int
1299 _ControlAnimatorImpl::GetActiveAnimationListCount(void) const
1300 {
1301         return __pActiveAnimationList->GetCount();
1302 }
1303
1304 int
1305 _ControlAnimatorImpl::GetActiveAnimationListCount(AnimationTargetType animTarget) const
1306 {
1307         result r = E_SUCCESS;
1308         int count = 0;
1309
1310         for (int count = __pActiveAnimationList->GetCount() - 1; count >= 0; count--)
1311         {
1312                 ActiveAnimation activeAnim;
1313                 r = __pActiveAnimationList->GetAt(count, activeAnim);
1314                 SysTryReturn(NID_UI_ANIM, (r == E_SUCCESS), -1, r, "[%s] Failed to retrieve active animation from list.", GetErrorMessage(r));
1315                 if (activeAnim.animTarget == animTarget)
1316                 {
1317                         count++;
1318                 }
1319         }
1320
1321         return count;
1322 }
1323
1324 result
1325 _ControlAnimatorImpl::RemoveAnimationAt(int index)
1326 {
1327         SysTryReturnResult(NID_UI_ANIM,
1328                                           (index >= 0 && index < __pActiveAnimationList->GetCount()), E_OUT_OF_RANGE, "Index (%d) is out of range.", index);
1329
1330         result r = E_SUCCESS;
1331         ActiveAnimation activeAnim;
1332
1333         r = __pActiveAnimationList->GetAt(index, activeAnim);
1334         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Failed to retrieve active animation from list.");
1335
1336         r = __pActiveAnimationList->Remove(activeAnim);
1337         SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to remove animation from play list.");
1338
1339         delete activeAnim.pAnimationBase;
1340         activeAnim.pAnimationBase = null;
1341         delete activeAnim.pAnimation;
1342         activeAnim.pAnimation = null;
1343         delete activeAnim.pBezierTimingFunction;
1344         activeAnim.pBezierTimingFunction = null;
1345
1346         return r;
1347 }
1348
1349 result
1350 _ControlAnimatorImpl::RemoveAllAnimations(void)
1351 {
1352         result r = E_SUCCESS;
1353
1354         for (int count = __pActiveAnimationList->GetCount() - 1; count >= 0; count--)
1355         {
1356                 r = RemoveAnimationAt(count);
1357                 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_OBJ_NOT_FOUND, "Failed to remove animation. index = %d", count);
1358         }
1359
1360         return r;
1361 }
1362
1363 result
1364 _ControlAnimatorImpl::DestroyAnimation(int preActiveAnimationCount)
1365 {
1366         result r = E_SUCCESS;
1367
1368         for (int count = GetActiveAnimationListCount() - 1; count >= preActiveAnimationCount; count--)
1369         {
1370                 String animName;
1371
1372                 animName = GetActiveAnimationAt(count);
1373                 r = __pVisualElement->RemoveAnimation(animName);
1374                 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Failed to remove animation. keyName = %ls", animName.GetPointer());
1375
1376                 if (RemoveAnimationAt(count) != E_SUCCESS)
1377                 {
1378                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to remove animation. index = %d", count);
1379                         return E_SYSTEM;
1380                 }
1381         }
1382
1383         return r;
1384 }
1385
1386 result
1387 _ControlAnimatorImpl::DestroyAnimation(AnimationBase& animBase, AnimationTargetType animTarget)
1388 {
1389         result r = E_SUCCESS;
1390
1391         int index = -1;
1392         ActiveAnimation activeAnim;
1393
1394         activeAnim.animTarget = animTarget;
1395         activeAnim.pAnimationBase = (dynamic_cast< AnimationBase* >(&animBase));
1396         r = __pActiveAnimationList->IndexOf(activeAnim, index);
1397         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Failed to retrieve active animation from list.");
1398
1399         r = RemoveAnimationAt(index);
1400         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Failed to remove animation from play list.");
1401
1402         return r;
1403 }
1404
1405 result
1406 _ControlAnimatorImpl::SetControlProperty(AnimationTargetType animTarget, AnimationBase& animationBase)
1407 {
1408         result r = E_SUCCESS;
1409
1410         if (animationBase.IsHoldEndEnabled() == true)
1411         {
1412                 switch (animTarget)
1413                 {
1414                 case ANIMATION_TARGET_SIZE:
1415                 {
1416                         DimensionAnimation* pDimAnim = null;
1417                         RectangleAnimation* pRectAnim = null;
1418
1419                         pDimAnim = dynamic_cast< DimensionAnimation* >(const_cast< AnimationBase* >(&animationBase));
1420                         pRectAnim = dynamic_cast< RectangleAnimation* >(const_cast< AnimationBase* >(&animationBase));
1421                         SysTryReturnResult(NID_UI_ANIM, ((pDimAnim) || (pRectAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
1422
1423                         if (pDimAnim)
1424                         {
1425                                 Dimension dimVal(0, 0);
1426
1427                                 (animationBase.IsAutoReverseEnabled()) ? (dimVal = pDimAnim->GetStartValue()) : (dimVal = pDimAnim->GetEndValue());
1428                                 r = (__pControl)->SetSize(dimVal.width, dimVal.height);
1429                         }
1430                         else    //if (pRectAnim)
1431                         {
1432                                 Rectangle rectVal(0, 0, 0, 0);
1433
1434                                 (animationBase.IsAutoReverseEnabled()) ? (rectVal = pRectAnim->GetStartValue()) : (rectVal = pRectAnim->GetEndValue());
1435                                 r = (__pControl)->SetSize(rectVal.width, rectVal.height);
1436                         }
1437                 }
1438                 break;
1439
1440                 case ANIMATION_TARGET_POSITION:
1441                 {
1442                         PointAnimation* pPointAnim = null;
1443                         RectangleAnimation* pRectAnim = null;
1444
1445                         pPointAnim = dynamic_cast< PointAnimation* >(const_cast< AnimationBase* >(&animationBase));
1446                         pRectAnim = dynamic_cast< RectangleAnimation* >(const_cast< AnimationBase* >(&animationBase));
1447                         SysTryReturnResult(NID_UI_ANIM, ((pPointAnim) || (pRectAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
1448
1449                         if (pPointAnim)
1450                         {
1451                                 Point val(0, 0);
1452
1453                                 (animationBase.IsAutoReverseEnabled()) ? (val = pPointAnim->GetStartValue()) : (val = pPointAnim->GetEndValue());
1454                                 r = (__pControl)->SetPosition(val.x, val.y);
1455                         }
1456                         else    //if (pRectAnim)
1457                         {
1458                                 Rectangle rectVal(0, 0, 0, 0);
1459
1460                                 (animationBase.IsAutoReverseEnabled()) ? (rectVal = pRectAnim->GetStartValue()) : (rectVal = pRectAnim->GetEndValue());
1461                                 r = (__pControl)->SetPosition(rectVal.x, rectVal.y);
1462                         }
1463                 }
1464                 break;
1465
1466                 case ANIMATION_TARGET_ALPHA:
1467                 {
1468                         FloatAnimation* pFloatAnim = null;
1469                         IntegerAnimation* pIntegerAnim = null;
1470
1471                         pFloatAnim = dynamic_cast< FloatAnimation* >(const_cast< AnimationBase* >(&animationBase));
1472                         pIntegerAnim = dynamic_cast< IntegerAnimation* >(const_cast< AnimationBase* >(&animationBase));
1473                         SysTryReturnResult(NID_UI_ANIM, ((pFloatAnim) || (pIntegerAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
1474
1475                         if (pFloatAnim)
1476                         {
1477                                 float floatVal = 0.0f;
1478
1479                                 (animationBase.IsAutoReverseEnabled()) ? (floatVal = pFloatAnim->GetStartValue()) : (floatVal = pFloatAnim->GetEndValue());
1480
1481                                 if (!(Float::Compare(floatVal, 1.0)))
1482                                 {
1483                                         r = __pControl->SetShowState(true);
1484                                 }
1485                                 else
1486                                 {
1487                                         r = __pControl->SetShowState(false);
1488                                 }
1489
1490                         }
1491                         else    //if (pIntegerAnim)
1492                         {
1493                                 int intVal = 0;
1494
1495                                 (animationBase.IsAutoReverseEnabled()) ? (intVal = pIntegerAnim->GetStartValue()) : (intVal = pIntegerAnim->GetEndValue());
1496
1497                                 if (intVal == 1)
1498                                 {
1499                                         r = __pControl->SetShowState(true);
1500                                 }
1501                                 else
1502                                 {
1503                                         r = __pControl->SetShowState(false);
1504                                 }
1505                         }
1506                 }
1507                 break;
1508
1509                 case ANIMATION_TARGET_ROTATION:
1510                 {
1511                         //Comment: The Control's property will be the same even after the rotate animation is completed.
1512                         //So, no need to update the window property.
1513                 }
1514                 break;
1515
1516                 default:
1517                 {
1518                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. animTarget is invalid.");
1519                         return E_SYSTEM;
1520                 }
1521                 break;
1522                 }
1523         }
1524
1525         if (IsAnimationSupported() == false)
1526         {
1527                 _WindowImpl* pWindow = null;
1528                 pWindow = _ControlImplManager::GetInstance()->GetCurrentFrame();
1529                 SysTryReturnResult(NID_UI_ANIM, (pWindow), E_SYSTEM, "A system error has been occurred. Failed to get current frame.");
1530
1531                 pWindow->GetPublic().Draw();
1532                 __isAnimationTargetAnimating[animTarget] = false;
1533         }
1534
1535         return r;
1536 }
1537
1538 result
1539 _ControlAnimatorImpl::SetControlShowState(AnimationTargetType animTarget, AnimationBase& animationBase)
1540 {
1541         SysTryReturnResult(NID_UI_ANIM, (animTarget == ANIMATION_TARGET_ALPHA), E_SYSTEM, "animTarget is invalid.");
1542
1543         if (animationBase.IsHoldEndEnabled() == true)
1544         {
1545                 IntegerAnimation* pIntAnim = dynamic_cast< IntegerAnimation* >(const_cast< AnimationBase* >(&animationBase));
1546                 FloatAnimation* pFloatAnim = dynamic_cast< FloatAnimation* >(const_cast< AnimationBase* >(&animationBase));
1547
1548                 SysTryReturnResult(NID_UI_ANIM, (pIntAnim || pFloatAnim), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
1549
1550                 if (pIntAnim)
1551                 {
1552                         int endVal = -1;
1553
1554                         if (animationBase.IsAutoReverseEnabled() == false)
1555                         {
1556                                 endVal = static_cast< float >(pIntAnim->GetEndValue());
1557                                 __showStateHolder = ((endVal == 1) ? (true) : (false));
1558                         }
1559                 }
1560                 else    //if (pFloatAnim)
1561                 {
1562                         float endVal = -1.0f;
1563
1564                         if (animationBase.IsAutoReverseEnabled() == false)
1565                         {
1566                                 endVal = (static_cast< float >(pFloatAnim->GetEndValue()));
1567                                 __showStateHolder = (((!(Float::Compare(endVal, 1.0)))) ? (true) : (false));
1568                         }
1569                 }
1570         }
1571
1572         if ((__pControl->GetShowState() == false) && ((animationBase.IsAutoReverseEnabled()) || (animationBase.IsHoldEndEnabled() == false)))
1573         {
1574                 __pVisualElement->SetShowState(true);
1575                 __pVisualElement->Draw();
1576                 __pVisualElement->SetShowState(false);
1577         }
1578
1579         return E_SUCCESS;
1580 }
1581
1582 result
1583 _ControlAnimatorImpl::SetControlLogicalBounds(AnimationTargetType animTarget, AnimationBase& animationBase)
1584 {
1585         result r = E_SUCCESS;
1586
1587         if (animationBase.IsHoldEndEnabled() == true)
1588         {
1589                 switch (animTarget)
1590                 {
1591                 case ANIMATION_TARGET_SIZE:
1592                 {
1593                         DimensionAnimation* pDimAnim = dynamic_cast< DimensionAnimation* >(const_cast< AnimationBase* >(&animationBase));
1594                         RectangleAnimation* pRectAnim = dynamic_cast< RectangleAnimation* >(const_cast< AnimationBase* >(&animationBase));
1595                         SysTryReturnResult(NID_UI_ANIM, ((pDimAnim) || (pRectAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
1596
1597                         if (pDimAnim)
1598                         {
1599                                 Dimension dimVal(0, 0);
1600                                 if (animationBase.IsAutoReverseEnabled() == false)
1601                                 {
1602                                         dimVal = pDimAnim->GetEndValue();
1603                                         __logicalBoundsHolder.width = dimVal.width;
1604                                         __logicalBoundsHolder.height = dimVal.height;
1605                                 }
1606                         }
1607                         else    //if (pRectAnim)
1608                         {
1609                                 Rectangle rectVal(0, 0, 0, 0);
1610                                 if (animationBase.IsAutoReverseEnabled() == false)
1611                                 {
1612                                         rectVal = pRectAnim->GetEndValue();
1613                                         __logicalBoundsHolder.width = rectVal.width;
1614                                         __logicalBoundsHolder.height = rectVal.height;
1615                                 }
1616                         }
1617                 }
1618                 break;
1619
1620                 case ANIMATION_TARGET_POSITION:
1621                 {
1622                         PointAnimation* pPointAnim = dynamic_cast< PointAnimation* >(const_cast< AnimationBase* >(&animationBase));
1623                         RectangleAnimation* pRectAnim = dynamic_cast< RectangleAnimation* >(const_cast< AnimationBase* >(&animationBase));
1624                         SysTryReturnResult(NID_UI_ANIM, ((pPointAnim) || (pRectAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
1625
1626                         if (pPointAnim)
1627                         {
1628                                 Point val(0, 0);
1629
1630                                 if (animationBase.IsAutoReverseEnabled() == false)
1631                                 {
1632                                         val = pPointAnim->GetEndValue();
1633                                         __logicalBoundsHolder.x = val.x;
1634                                         __logicalBoundsHolder.y = val.y;
1635                                 }
1636                         }
1637                         else
1638                         {
1639                                 Rectangle rectVal(0, 0, 0, 0);
1640
1641                                 if (animationBase.IsAutoReverseEnabled() == false)
1642                                 {
1643                                         rectVal = pRectAnim->GetEndValue();
1644                                         __logicalBoundsHolder.x = rectVal.x;
1645                                         __logicalBoundsHolder.y = rectVal.y;
1646                                 }
1647                         }
1648                 }
1649                 break;
1650
1651                 default:
1652                 {
1653                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. animTarget is invalid.");
1654                         return E_SYSTEM;
1655                 }
1656                 break;
1657                 }
1658         }
1659         return r;
1660 }
1661
1662 AnimationBase*
1663 _ControlAnimatorImpl::CloneAnimation(AnimationTargetType animTarget, AnimationBase& animationBase)
1664 {
1665         AnimationBase* pAnimationBase = null;
1666
1667         //Comment: Deep copy animation object & pass to SetAnimation, which will store in list of structures
1668         switch (animTarget)
1669         {
1670         case ANIMATION_TARGET_SIZE:
1671         {
1672                 DimensionAnimation* pDimAnim = null;
1673                 RectangleAnimation* pRectAnim = null;
1674
1675                 pDimAnim = dynamic_cast< DimensionAnimation* >(&animationBase);
1676                 pRectAnim = dynamic_cast< RectangleAnimation* >(&animationBase);
1677                 SysTryReturn(NID_UI_ANIM, ((pDimAnim) || (pRectAnim)), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Animation is invalid.");
1678
1679                 if (pDimAnim)
1680                 {
1681                         DimensionAnimation* pDimValue = new (std::nothrow) DimensionAnimation(*pDimAnim);
1682                         pAnimationBase = pDimValue;
1683                 }
1684                 else
1685                 {
1686                         RectangleAnimation* pRectValue = new (std::nothrow) RectangleAnimation(*pRectAnim);
1687                         pAnimationBase = pRectValue;
1688                 }
1689         }
1690         break;
1691
1692         case ANIMATION_TARGET_POSITION:
1693         {
1694                 PointAnimation* pPointAnim = null;
1695                 RectangleAnimation* pRectAnim = null;
1696
1697                 pPointAnim = dynamic_cast< PointAnimation* >(&animationBase);
1698                 pRectAnim = dynamic_cast< RectangleAnimation* >(&animationBase);
1699                 SysTryReturn(NID_UI_ANIM, ((pPointAnim) || (pRectAnim)), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Animation is invalid.");
1700
1701                 if (pPointAnim)
1702                 {
1703                         PointAnimation* pPointValue = new (std::nothrow) PointAnimation(*pPointAnim);
1704                         pAnimationBase = pPointValue;
1705                 }
1706                 else
1707                 {
1708                         RectangleAnimation* pRectValue = new (std::nothrow) RectangleAnimation(*pRectAnim);
1709                         pAnimationBase = pRectValue;
1710                 }
1711         }
1712         break;
1713
1714         case ANIMATION_TARGET_ALPHA:
1715         {
1716                 FloatAnimation* pFloatAnim = null;
1717                 IntegerAnimation* pIntegerAnim = null;
1718
1719                 pFloatAnim = dynamic_cast< FloatAnimation* >(&animationBase);
1720                 pIntegerAnim = dynamic_cast< IntegerAnimation* >(&animationBase);
1721                 SysTryReturn(NID_UI_ANIM, ((pFloatAnim) || (pIntegerAnim)), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Animation is invalid.");
1722
1723                 if (pFloatAnim)
1724                 {
1725                         FloatAnimation* pFloatValue = new (std::nothrow) FloatAnimation(*pFloatAnim);
1726                         pAnimationBase = pFloatValue;
1727                 }
1728                 else
1729                 {
1730                         IntegerAnimation* pIntegerValue = new (std::nothrow) IntegerAnimation(*pIntegerAnim);
1731                         pAnimationBase = pIntegerValue;
1732                 }
1733         }
1734         break;
1735
1736         case ANIMATION_TARGET_ROTATION:
1737         {
1738                 RotateAnimation* pRotateAnimation = dynamic_cast< RotateAnimation* >(&animationBase);
1739                 SysTryReturn(NID_UI_ANIM, ((pRotateAnimation)), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Animation is invalid.");
1740
1741                 RotateAnimation* pRotateValue = new (std::nothrow) RotateAnimation(*pRotateAnimation);
1742                 pAnimationBase = pRotateValue;
1743         }
1744         break;
1745
1746         default:
1747         {
1748                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. animTarget is invalid.");
1749                 return null;
1750         }
1751         break;
1752         }
1753
1754         return pAnimationBase;
1755 }
1756
1757 bool
1758 _ControlAnimatorImpl::IsAnimatable(AnimationTargetType animTarget, Rectangle& bounds, AnimationBase* pAnimationBase, ControlAnimatorTriggerType animTrigger) const
1759 {
1760         bool animatable = false;
1761         Rectangle endBounds(0, 0, 0, 0);
1762
1763         endBounds = bounds;
1764
1765         if (pAnimationBase)
1766         {
1767                 if (pAnimationBase->IsHoldEndEnabled() == true)
1768                 {
1769                         switch (animTarget)
1770                         {
1771                         case ANIMATION_TARGET_SIZE:
1772                         {
1773                                 if (animTrigger == ANIMATION_TRIGGER_USER)
1774                                 {
1775                                         DimensionAnimation* pDimAnim = null;
1776                                         RectangleAnimation* pRectAnim = null;
1777
1778                                         if (pAnimationBase->GetType() == ANIMATION_TYPE_DIMENSION_ANIMATION)
1779                                         {
1780                                                 pDimAnim = dynamic_cast< DimensionAnimation* >(pAnimationBase);
1781                                                 if (pDimAnim != null)
1782                                                 {
1783                                                         if (pAnimationBase->IsAutoReverseEnabled())
1784                                                         {
1785                                                                 endBounds.width = pDimAnim->GetStartValue().width;
1786                                                                 endBounds.height = pDimAnim->GetStartValue().height;
1787                                                         }
1788                                                         else
1789                                                         {
1790                                                                 endBounds.width = pDimAnim->GetEndValue().width;
1791                                                                 endBounds.height = pDimAnim->GetEndValue().height;
1792                                                         }
1793                                                 }
1794                                         }
1795                                         else if (pAnimationBase->GetType() == ANIMATION_TYPE_RECTANGLE_ANIMATION)
1796                                         {
1797                                                 pRectAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
1798                                                 if (pRectAnim != null)
1799                                                 {
1800                                                         if (pAnimationBase->IsAutoReverseEnabled())
1801                                                         {
1802                                                                 endBounds.width = pRectAnim->GetStartValue().width;
1803                                                                 endBounds.height = pRectAnim->GetStartValue().height;
1804                                                         }
1805                                                         else
1806                                                         {
1807                                                                 endBounds.width = pRectAnim->GetEndValue().width;
1808                                                                 endBounds.height = pRectAnim->GetEndValue().height;
1809                                                         }
1810                                                 }
1811                                         }
1812                                         else
1813                                         {
1814                                                 return false;
1815                                         }
1816                                 }
1817
1818                                 if (!(__pControl->IsResizable()))
1819                                 {
1820                                         animatable = false;
1821                                 }
1822                                 else
1823                                 {
1824                                         //Scale Animation is allowed with any anchor (0,0) when HoldEnd=TRUE & Auto Reverse=FALSE
1825                                         float ancX = 0.0f;
1826                                         float ancY = 0.0f;
1827                                         DimensionAnimation* pDimAnim = dynamic_cast< DimensionAnimation* >(pAnimationBase);
1828                                         RectangleAnimation* pRectAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
1829
1830                                         (pDimAnim) ? (pDimAnim->GetAnchor(ancX, ancY)) : (pRectAnim->GetAnchor(ancX, ancY));
1831
1832                                         if ((Float::Compare(ancX, 0.0)) || (Float::Compare(ancY, 0.0)))
1833                                         {
1834                                                 return false;
1835                                         }
1836
1837                                         //CustomControl Changes
1838                                         CustomControlBase* pControlBase = dynamic_cast< CustomControlBase* >(__pControl);
1839
1840                                         if (pControlBase)
1841                                         {
1842                                                 Dimension endDimension(endBounds.width, endBounds.height);
1843                                                 __pControlImpl->OnEvaluateSize(endDimension);
1844                                         }
1845                                         else
1846                                         {
1847                                                 Dimension controlMinSize = __pControl->GetMinimumSize();
1848                                                 SysTryReturn(NID_UI_ANIM, ((endBounds.width >= controlMinSize.width) && (endBounds.height >= controlMinSize.height)),
1849                                                                         false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. end size = (%d, %d)", endBounds.width, endBounds.height);
1850
1851                                                 Dimension controlMaxSize = __pControl->GetMaximumSize();
1852                                                 SysTryReturn(NID_UI_ANIM, ((endBounds.width <= controlMaxSize.width) && (endBounds.height <= controlMaxSize.height)),
1853                                                                         false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. end size = (%d, %d)", endBounds.width, endBounds.height);
1854                                         }
1855                                         animatable = true;
1856                                 }
1857                         }
1858                         break;
1859
1860                         case ANIMATION_TARGET_POSITION:
1861                         {
1862                                 if (animTrigger == ANIMATION_TRIGGER_USER)
1863                                 {
1864                                         PointAnimation* pPointAnim = null;
1865                                         RectangleAnimation* pRectAnim = null;
1866
1867                                         if (pAnimationBase->GetType() == ANIMATION_TYPE_POINT_ANIMATION)
1868                                         {
1869                                                 pPointAnim = dynamic_cast< PointAnimation* >(pAnimationBase);
1870                                                 if (pPointAnim != null)
1871                                                 {
1872                                                         if (pAnimationBase->IsAutoReverseEnabled())
1873                                                         {
1874                                                                 endBounds.x = pPointAnim->GetStartValue().x;
1875                                                                 endBounds.y = pPointAnim->GetStartValue().y;
1876                                                         }
1877                                                         else
1878                                                         {
1879                                                                 endBounds.x = pPointAnim->GetEndValue().x;
1880                                                                 endBounds.y = pPointAnim->GetEndValue().y;
1881                                                         }
1882                                                 }
1883                                         }
1884                                         else if (pAnimationBase->GetType() == ANIMATION_TYPE_RECTANGLE_ANIMATION)
1885                                         {
1886                                                 pRectAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
1887                                                 if (pRectAnim != null)
1888                                                 {
1889                                                         if (pAnimationBase->IsAutoReverseEnabled())
1890                                                         {
1891                                                                 endBounds.x = pRectAnim->GetStartValue().x;
1892                                                                 endBounds.y = pRectAnim->GetStartValue().y;
1893                                                         }
1894                                                         else
1895                                                         {
1896                                                                 endBounds.x = pRectAnim->GetEndValue().x;
1897                                                                 endBounds.y = pRectAnim->GetEndValue().y;
1898                                                         }
1899                                                 }
1900                                         }
1901                                         else
1902                                         {
1903                                                 return false;
1904                                         }
1905                                 }
1906
1907                                 if (!(__pControl->IsMovable()))
1908                                 {
1909                                         animatable = false;
1910                                 }
1911                                 else
1912                                 {
1913                                         //CustomControl Changes
1914                                         CustomControlBase* pControlBase = dynamic_cast< CustomControlBase* >(__pControl);
1915
1916                                         if (pControlBase)
1917                                         {
1918                                                 __pControlImpl->OnBoundsChanging(endBounds); //check this this API has been changed in 2.0
1919                                         }
1920                                         //Comment. No limit on positive & negative "x" & "y" for the movable %Control's position property
1921                                         animatable = true;
1922                                 }
1923                         }
1924                         break;
1925
1926                         case ANIMATION_TARGET_ALPHA:
1927                         {
1928                                 float endVal = -1.0f;
1929                                 IntegerAnimation* pIntAnim = null;
1930                                 FloatAnimation* pFloatAnim = null;
1931
1932                                 if (pAnimationBase->GetType() == ANIMATION_TYPE_FLOAT_ANIMATION)
1933                                 {
1934                                         pFloatAnim = dynamic_cast< FloatAnimation* >(pAnimationBase);
1935                                         if (pFloatAnim != null)
1936                                         {
1937                                                 if (pAnimationBase->IsAutoReverseEnabled())
1938                                                 {
1939                                                         endVal = pFloatAnim->GetStartValue();
1940                                                 }
1941                                                 else
1942                                                 {
1943                                                         endVal = pFloatAnim->GetEndValue();
1944                                                 }
1945                                         }
1946                                 }
1947                                 else if (pAnimationBase->GetType() == ANIMATION_TYPE_INTEGER_ANIMATION)
1948                                 {
1949                                         pIntAnim = dynamic_cast< IntegerAnimation* >(pAnimationBase);
1950                                         if (pIntAnim != null)
1951                                         {
1952                                                 if (pAnimationBase->IsAutoReverseEnabled())
1953                                                 {
1954                                                         endVal = (static_cast< float >(pIntAnim->GetStartValue()));
1955                                                 }
1956                                                 else
1957                                                 {
1958                                                         endVal = (static_cast< float >(pIntAnim->GetEndValue()));
1959                                                 }
1960                                         }
1961                                 }
1962                                 else
1963                                 {
1964                                         return false;
1965                                 }
1966
1967                                 //removing the code of IsShowStateChangeable
1968                                 if ((!(Float::Compare(endVal, 1.0))) || (!(Float::Compare(endVal, 0.0))))
1969                                 {
1970                                         animatable = true;
1971                                 }
1972                                 else
1973                                 {
1974                                         SysLogException(NID_UI_ANIM, E_INVALID_ARG, "Invalid argument(s) is used. End value is invalid.");
1975                                         return false;
1976                                 }
1977
1978                         }
1979                         break;
1980
1981                         case ANIMATION_TARGET_ROTATION:
1982                         {
1983                                 if (animTrigger == ANIMATION_TRIGGER_USER)
1984                                 {
1985                                         RotateAnimation* pRotAnim = null;
1986                                         if (pAnimationBase->GetType() == ANIMATION_TYPE_ROTATE_ANIMATION)
1987                                         {
1988                                                 float endVal = -1.0f;
1989                                                 pRotAnim = dynamic_cast< RotateAnimation* >(pAnimationBase);
1990                                                 if (pRotAnim != null)
1991                                                 {
1992                                                         if (pAnimationBase->IsAutoReverseEnabled())
1993                                                         {
1994                                                                 endVal = pRotAnim->GetStartValue();
1995                                                         }
1996                                                         else
1997                                                         {
1998                                                                 endVal = pRotAnim->GetEndValue();
1999                                                         }
2000                                                 }
2001                                                 int roundingVal = Tizen::Base::Utility::Math::Round((double) endVal);
2002
2003                                                 if ((!(Float::Compare(endVal, static_cast< float >(roundingVal)))) && (((static_cast< int >(endVal) % 360) == 0))) //check this : Todo
2004                                                 {
2005                                                         animatable = true;
2006                                                 }
2007                                                 else
2008                                                 {
2009                                                         SysLogException(NID_UI_ANIM, E_INVALID_ARG, "Invalid argument(s) is used. End value is invalid.");
2010                                                         return false;
2011                                                 }
2012                                         }
2013                                         else
2014                                         {
2015                                                 SysLogException(NID_UI_ANIM, E_INVALID_ARG, "Invalid argument(s) is used. End value is invalid.");
2016                                                 return false;
2017                                         }
2018                                 }
2019                         }
2020                         break;
2021
2022                         default:
2023                         {
2024                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. animTarget is invalid.");
2025                                 animatable = false;
2026                         }
2027                         break;
2028                         }
2029                 }
2030                 else    //IsHoldEndEnabled = false
2031                 {
2032                         animatable = true;
2033                 }
2034         }
2035
2036         return animatable;
2037 }
2038
2039 bool
2040 _ControlAnimatorImpl::IsAnimationSupported(void) const
2041 {
2042         return _VisualElementAnimationImpl::IsAnimationSupported();
2043 }
2044
2045 void
2046 _ControlAnimatorImpl::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
2047 {
2048         ActiveAnimation activeAnim;
2049         int index = -1;
2050         String animName(0);
2051
2052         if (keyName.IsEmpty() == true)
2053         {
2054                 String* pUserData = (String*) (animation.GetUserData());
2055                 if (pUserData != null)
2056                 {
2057                         animName = *pUserData;
2058                 }
2059         }
2060         else
2061         {
2062                 animName = keyName;
2063         }
2064
2065         index = GetActiveAnimationIndex(animName);
2066
2067         if (index == -1)
2068         {
2069                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation name mismatch in the playlist.");
2070                 return;
2071         }
2072
2073         if (__pActiveAnimationList->GetAt(index, activeAnim) != E_SUCCESS)
2074         {
2075                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not present in the playlist.");
2076                 return;
2077         }
2078
2079         __isAnimationTargetAnimating[activeAnim.animTarget] = true;
2080
2081         int startIndex = 0;
2082         int indexOf = 0;
2083
2084         if ((animName.IndexOf(TRANSACTION, startIndex, indexOf)) != E_SUCCESS)
2085         {
2086                 //Calling simple listeners registered in this control animator
2087                 if (__pAnimStatusEventListener)
2088                 {
2089                         IControlAnimatorEventListener* pCaEventListener = null;
2090                         for (int count = (__pAnimStatusEventListener->GetCount() - 1); count >= 0; count--)
2091                         {
2092                                 __pAnimStatusEventListener->GetAt(count, pCaEventListener);
2093                                 if (pCaEventListener)
2094                                 {
2095                                         pCaEventListener->OnControlAnimationStarted(*__pControlAnimator, *__pControl);
2096                                 }
2097                         }
2098                 }
2099
2100                 //calling detailed event listerners registered in this control animator
2101                 if (__pAnimDetailedEventListener)
2102                 {
2103                         IControlAnimatorDetailedEventListener* pDetailedEventListener = null;
2104
2105                         for (int count = (__pAnimDetailedEventListener->GetCount() - 1); count >= 0; count--)
2106                         {
2107                                 __pAnimDetailedEventListener->GetAt(count, pDetailedEventListener);
2108
2109                                 if (pDetailedEventListener)
2110                                 {
2111                                         pDetailedEventListener->OnControlAnimationStarted(*__pControlAnimator, *__pControl, activeAnim.animType, activeAnim.animTarget, activeAnim.pAnimationBase);
2112                                 }
2113                         }
2114                 }
2115         }
2116 }
2117
2118 void
2119 _ControlAnimatorImpl::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
2120 {
2121         ActiveAnimation activeAnim;
2122         int index = -1;
2123         String animName(0);
2124
2125         if (keyName.IsEmpty() == true)
2126         {
2127                 String* pUserData = (String*) (animation.GetUserData());
2128
2129                 if (pUserData != null)
2130                 {
2131                         animName = *pUserData;
2132                 }
2133         }
2134         else
2135         {
2136                 animName = keyName;
2137         }
2138
2139         index = GetActiveAnimationIndex(animName);
2140         if (index == -1)
2141         {
2142                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation name mismatch in the playlist.");
2143                 return;
2144         }
2145
2146         if (__pActiveAnimationList->GetAt(index, activeAnim) != E_SUCCESS)
2147         {
2148                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not present in the playlist.");
2149                 return;
2150         }
2151
2152         int startIndex = 0;
2153         int indexOf = 0;
2154
2155         if ((animName.IndexOf(TRANSACTION, startIndex, indexOf)) != E_SUCCESS)
2156         {
2157                 if (__pAnimDetailedEventListener)
2158                 {
2159                         IControlAnimatorDetailedEventListener* pDetailedEventListener = null;
2160
2161                         for (int count = (__pAnimDetailedEventListener->GetCount() - 1); count >= 0; count--)
2162                         {
2163                                 __pAnimDetailedEventListener->GetAt(count, pDetailedEventListener);
2164
2165                                 if (pDetailedEventListener)
2166                                 {
2167                                         pDetailedEventListener->OnControlAnimationRepeated(*__pControlAnimator, *__pControl, activeAnim.animType, activeAnim.animTarget, activeAnim.pAnimationBase, currentRepeatCount);
2168                                 }
2169                         }
2170                 }
2171         }
2172 }
2173
2174 void
2175 _ControlAnimatorImpl::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
2176 {
2177         String animName(0);
2178
2179         if (keyName.IsEmpty() == true)
2180         {
2181                 String* pUserData = (String*) (animation.GetUserData());
2182
2183                 if (pUserData != null)
2184                 {
2185                         animName = *pUserData;
2186                         delete pUserData;
2187                         pUserData = null;
2188                 }
2189         }
2190         else
2191         {
2192                 animName = keyName;
2193         }
2194
2195         _VisualElementImpl* pPresentationImpl = _VisualElementImpl::GetInstance(*const_cast<VisualElement*>(__pVisualElement->AcquirePresentationInstance()));
2196
2197         if (pPresentationImpl == null)
2198         {
2199                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Screen is not updated with end values.");
2200         }
2201         else
2202         {
2203                 VisualElementValueAnimation* pValueAnimation = dynamic_cast< VisualElementValueAnimation* >(const_cast< VisualElementAnimation* >(&animation));
2204                 VisualElementPropertyAnimation* pAnimation = dynamic_cast< VisualElementPropertyAnimation* >(const_cast< VisualElementAnimation* >(&animation));
2205
2206                 if (completedNormally == false || (pValueAnimation && pValueAnimation->IsEndValueApplied() == false))
2207                 {
2208                         if (pAnimation)
2209                         {
2210                                 String propName = pAnimation->GetPropertyName();
2211
2212                                 int startIndex = 0;
2213                                 int indexOf = 0;
2214                                 result r = E_SUCCESS;
2215
2216                                 if ((propName.IndexOf(VeSubPropBoundsPosition, startIndex, indexOf)) == E_SUCCESS)
2217                                 {
2218                                         r = pPresentationImpl->SetProperty(VePropBounds, __pVisualElement->GetBounds());
2219                                 }
2220                                 else if ((propName.IndexOf(VePropBounds, startIndex, indexOf)) == E_SUCCESS)
2221                                 {
2222                                         r = pPresentationImpl->SetProperty(VePropBounds, __pVisualElement->GetBounds());
2223                                 }
2224                                 else if ((propName.IndexOf(VeSubPropTransformRotationZ, startIndex, indexOf)) == E_SUCCESS)
2225                                 {
2226                                         r = pPresentationImpl->SetProperty(VePropTransform, __pVisualElement->GetTransformMatrix());
2227                                 }
2228                                 else if ((propName.IndexOf(VePrivPropShowOpacity, startIndex, indexOf)) == E_SUCCESS)
2229                                 {
2230                                         r = pPresentationImpl->SetProperty(VePropShowState, __pVisualElement->GetShowState());
2231                                 }
2232
2233                                 if (r != E_SUCCESS)
2234                                 {
2235                                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Screen is not updated with end values.");
2236                                 }
2237                         }
2238                         else if (pValueAnimation)
2239                         {
2240                                 pPresentationImpl->SetProperty(VePropBounds, __pVisualElement->GetBounds());
2241                         }
2242                 }
2243         }
2244
2245         __pVisualElement->ReleasePresentationInstance();
2246
2247         ActiveAnimation activeAnim;
2248         int index = -1;
2249
2250         index = GetActiveAnimationIndex(animName);
2251
2252         if (index == -1)
2253         {
2254                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation name mismatch in the playlist.");
2255                 return;
2256         }
2257
2258         if (__pActiveAnimationList->GetAt(index, activeAnim) != E_SUCCESS)
2259         {
2260                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not present in the playlist.");
2261                 return;
2262         }
2263
2264         int startIndex = 0;
2265         int indexOf = 0;
2266
2267         __isAnimationTargetAnimating[activeAnim.animTarget] = false;
2268
2269         if ((animName.IndexOf(TRANSACTION, startIndex, indexOf)) != E_SUCCESS)
2270         {
2271                 if (__pAnimStatusEventListener)
2272                 {
2273                         IControlAnimatorEventListener* pCaEventListener = null;
2274
2275                         for (int count = (__pAnimStatusEventListener->GetCount() - 1); count >= 0; count--)
2276                         {
2277                                 __pAnimStatusEventListener->GetAt(count, pCaEventListener);
2278                                 if (pCaEventListener)
2279                                 {
2280                                         if (completedNormally)
2281                                         {
2282                                                 pCaEventListener->OnControlAnimationFinished(*__pControlAnimator, *__pControl);
2283                                         }
2284                                         else
2285                                         {
2286                                                 pCaEventListener->OnControlAnimationStopped(*__pControlAnimator, *__pControl);
2287                                         }
2288                                 }
2289                         }
2290                 }
2291
2292                 //Calling detailed event listeners
2293                 if (__pAnimDetailedEventListener)
2294                 {
2295                         IControlAnimatorDetailedEventListener* pDetailedEventListener = null;
2296
2297                         for (int count = (__pAnimDetailedEventListener->GetCount() - 1); count >= 0; count--)
2298                         {
2299                                 __pAnimDetailedEventListener->GetAt(count, pDetailedEventListener);
2300
2301                                 if (pDetailedEventListener)
2302                                 {
2303                                         if (completedNormally)
2304                                         {
2305                                                 pDetailedEventListener->OnControlAnimationFinished(*__pControlAnimator, *__pControl, activeAnim.animType, activeAnim.animTarget, activeAnim.pAnimationBase);
2306                                         }
2307                                         else
2308                                         {
2309                                                 pDetailedEventListener->OnControlAnimationStopped(*__pControlAnimator, *__pControl, activeAnim.animType, activeAnim.animTarget, activeAnim.pAnimationBase);
2310                                         }
2311                                 }
2312                         }
2313                 }
2314         }
2315
2316         RemoveAnimationAt(index);
2317 }
2318
2319 result
2320 _ControlAnimatorImpl::StopAllAnimations(void)
2321 {
2322         result r = E_SUCCESS;
2323
2324         __pVisualElement->RemoveAllAnimations();
2325
2326         return r;
2327 }
2328
2329 result
2330 _ControlAnimatorImpl::StopAnimation(ControlAnimatorTriggerType animTrigger)
2331 {
2332         SysTryReturnResult(NID_UI_ANIM, (GetActiveAnimationListCount() > 0), E_SUCCESS, "No active animation.");
2333
2334         result r = E_SUCCESS;
2335
2336         for (int index = GetActiveAnimationListCount() - 1; index >= 0; index--)
2337         {
2338                 String animName;
2339
2340                 animName = GetActiveAnimationAt(index, animTrigger);
2341                 if (!(animName.IsEmpty()))
2342                 {
2343                         int startIndex = 0;
2344                         int indexOfGroup = 0;
2345                         if ((animName.IndexOf(GROUP, startIndex, indexOfGroup)) == E_SUCCESS)
2346                         {
2347                                 String groupName;
2348                                 r = animName.SubString(indexOfGroup, groupName);
2349                                 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Group name is not found.");
2350
2351                                 r = __pVisualElement->RemoveAnimation(groupName);
2352                         }
2353                         else
2354                         {
2355                                 r = __pVisualElement->RemoveAnimation(animName);
2356                         }
2357
2358                         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Animation is either running or already removed.");
2359                 }
2360         }
2361
2362         return r;
2363 }
2364
2365 result
2366 _ControlAnimatorImpl::AddControlAnimatorEventListener(const IControlAnimatorEventListener& listener)
2367 {
2368         if (__pAnimStatusEventListener == null)
2369         {
2370                 __pAnimStatusEventListener = new (std::nothrow) LinkedListT< IControlAnimatorEventListener* >();
2371                 SysTryReturnResult(NID_UI_ANIM, (__pAnimStatusEventListener), E_OUT_OF_MEMORY, "Memory allocation failed.");
2372         }
2373
2374         IControlAnimatorEventListener* pStatusListener = const_cast< IControlAnimatorEventListener* >(&listener);
2375
2376         if (__pAnimStatusEventListener->Contains(pStatusListener) == true)
2377         {
2378                 return E_OBJ_ALREADY_EXIST;
2379         }
2380
2381         return __pAnimStatusEventListener->Add(pStatusListener);
2382 }
2383
2384 result
2385 _ControlAnimatorImpl::RemoveControlAnimatorEventListener(const IControlAnimatorEventListener& listener)
2386 {
2387         result r = E_SYSTEM;
2388
2389         if (__pAnimStatusEventListener)
2390         {
2391                 return __pAnimStatusEventListener->Remove((const_cast< IControlAnimatorEventListener* >(&listener)));
2392         }
2393
2394         return r;
2395 }
2396
2397 result
2398 _ControlAnimatorImpl::AddControlAnimatorDetailedEventListener(const IControlAnimatorDetailedEventListener& listener)
2399 {
2400         if (__pAnimDetailedEventListener == null)
2401         {
2402                 __pAnimDetailedEventListener = new (std::nothrow) LinkedListT< IControlAnimatorDetailedEventListener* >();
2403                 SysTryReturnResult(NID_UI_ANIM, (__pAnimDetailedEventListener), E_OUT_OF_MEMORY, "Memory allocation failed.");
2404         }
2405
2406         IControlAnimatorDetailedEventListener* pStatusListener = const_cast< IControlAnimatorDetailedEventListener* >(&listener);
2407
2408         if (__pAnimDetailedEventListener->Contains(pStatusListener) == true)
2409         {
2410                 return E_OBJ_ALREADY_EXIST;
2411         }
2412
2413         return __pAnimDetailedEventListener->Add(pStatusListener);
2414 }
2415
2416 result
2417 _ControlAnimatorImpl::RemoveControlAnimatorDetailedEventListener(const IControlAnimatorDetailedEventListener& listener)
2418 {
2419         result r = E_SYSTEM;
2420
2421         if (__pAnimDetailedEventListener)
2422         {
2423                 return __pAnimDetailedEventListener->Remove((const_cast< IControlAnimatorDetailedEventListener* >(&listener)));
2424         }
2425
2426         return r;
2427 }
2428
2429 int
2430 _ControlAnimatorImpl::GetActiveAnimationIndex(const String& animName) const
2431 {
2432         result r = E_SUCCESS;
2433
2434         for (int index = 0; index < __pActiveAnimationList->GetCount(); index++)
2435         {
2436                 ActiveAnimation activeAnim;
2437
2438                 r = __pActiveAnimationList->GetAt(index, activeAnim);
2439                 SysTryReturn(NID_UI_ANIM, (r == E_SUCCESS), -1, r, "[%s] Failed to retrieve animation from the list.", GetErrorMessage(r));
2440
2441                 if (activeAnim.animName == animName)
2442                 {
2443                         return index;
2444                 }
2445         }
2446
2447         return -1;
2448 }
2449
2450 result
2451 _ControlAnimatorImpl::SetPrevAnimationBoundsProperty(AnimationTargetType animTarget, AnimationBase& animationBase)
2452 {
2453         result r = E_SUCCESS;
2454
2455         if (animationBase.IsHoldEndEnabled() == true)
2456         {
2457                 switch (animTarget)
2458                 {
2459                 case ANIMATION_TARGET_SIZE:
2460                 {
2461                         DimensionAnimation* pDimAnim = null;
2462                         RectangleAnimation* pRectAnim = null;
2463                         pDimAnim = dynamic_cast< DimensionAnimation* >(const_cast< AnimationBase* >(&animationBase));
2464                         pRectAnim = dynamic_cast< RectangleAnimation* >(const_cast< AnimationBase* >(&animationBase));
2465                         SysTryReturnResult(NID_UI_ANIM, ((pDimAnim) || (pRectAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
2466
2467                         if (pDimAnim)
2468                         {
2469                                 Dimension dimVal(0, 0);
2470                                 (animationBase.IsAutoReverseEnabled()) ? (dimVal = pDimAnim->GetStartValue()) : (dimVal = pDimAnim->GetEndValue());
2471                                 __prevAnimationBoundsHolder.width = dimVal.width;
2472                                 __prevAnimationBoundsHolder.height = dimVal.height;
2473                         }
2474                         else    //if (pRectAnim)
2475                         {
2476                                 Rectangle rectVal(0, 0, 0, 0);
2477                                 (animationBase.IsAutoReverseEnabled()) ? (rectVal = pRectAnim->GetStartValue()) : (rectVal = pRectAnim->GetEndValue());
2478                                 __prevAnimationBoundsHolder.width = rectVal.width;
2479                                 __prevAnimationBoundsHolder.height = rectVal.height;
2480                         }
2481                 }
2482                 break;
2483
2484                 default:
2485                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. animTarget is invalid.");
2486                         return E_SYSTEM;
2487                 }
2488         }
2489
2490         return r;
2491 }
2492
2493 result
2494 _ControlAnimatorImpl::SetAnimationTargetStatus(ControlAnimatorTriggerType triggerType)
2495 {
2496         SysTryReturnResult(NID_UI_ANIM, (triggerType >= ANIMATION_TRIGGER_POSITION_CHANGE && triggerType <= ANIMATION_TRIGGER_SHOW_STATE_CHANGE), E_INVALID_ARG, "Invalid argument(s) is used. Animation trigger type is invalid.");
2497
2498         result r = E_SUCCESS;
2499         ParallelAnimationGroup* pParallelAnimGrp = null;
2500         SequentialAnimationGroup* pSequentialAnimGrp = null;
2501
2502         if (__propertyAnimationGroupType[triggerType - 1] == PROPERTY_ANIMATION_GROUP_TYPE_SEQUENTIAL)
2503         {
2504                 pSequentialAnimGrp = dynamic_cast< SequentialAnimationGroup* >(__pPropertyAnimationGroupList[triggerType - 1]);
2505                 if (pSequentialAnimGrp)
2506                 {
2507                         for (int index = 0; index < pSequentialAnimGrp->GetAnimationCount(); index++)
2508                         {
2509                                 AnimationTargetType _animTarget = pSequentialAnimGrp->GetAnimationTargetTypeAt(index);
2510                                 SysTryReturnResult(NID_UI_ANIM, ((_animTarget > ANIMATION_TARGET_NONE) && (_animTarget < ANIMATION_TARGET_MAX)),
2511                                                                   E_INVALID_ARG, "Invalid argument(s) is used. animTarget is invalid.");
2512                                 __isAnimationTargetAnimating[_animTarget] = true;
2513
2514                                 if (_animTarget == ANIMATION_TARGET_POSITION || _animTarget == ANIMATION_TARGET_SIZE || _animTarget == ANIMATION_TARGET_ALPHA)
2515                                 {
2516                                         AnimationBase* pAnimationBase = null;
2517
2518                                         pAnimationBase = pSequentialAnimGrp->GetAnimationAtN(index);
2519                                         if (pAnimationBase)
2520                                         {
2521                                                 if (_animTarget == ANIMATION_TARGET_ALPHA)
2522                                                 {
2523                                                         SetControlShowState(_animTarget, *pAnimationBase);
2524                                                 }
2525                                                 else
2526                                                 {
2527                                                         SetControlLogicalBounds(_animTarget, *pAnimationBase);
2528                                                 }
2529
2530                                                 delete pAnimationBase;
2531                                         }
2532                                 }
2533                         }
2534                 }
2535         }
2536         else if (__propertyAnimationGroupType[triggerType - 1] == PROPERTY_ANIMATION_GROUP_TYPE_PARALLEL)
2537         {
2538                 pParallelAnimGrp = dynamic_cast< ParallelAnimationGroup* >(__pPropertyAnimationGroupList[triggerType - 1]);
2539                 if (pParallelAnimGrp)
2540                 {
2541                         for (int index = (static_cast< int >(ANIMATION_TARGET_NONE) + 1); index < (static_cast< int >(ANIMATION_TARGET_MAX)); index++)
2542                         {
2543                                 AnimationTargetType _animTarget = static_cast< AnimationTargetType >(index);
2544                                 AnimationBase* pAnimBase = null;
2545
2546                                 pAnimBase = pParallelAnimGrp->GetAnimationN(_animTarget);
2547                                 if (pAnimBase != null)
2548                                 {
2549                                         SysTryReturnResult(NID_UI_ANIM, ((_animTarget > ANIMATION_TARGET_NONE) && (_animTarget < ANIMATION_TARGET_MAX)),
2550                                                                           E_INVALID_ARG, "Invalid argument(s) is used. animTarget is invalid.");
2551                                         __isAnimationTargetAnimating[_animTarget] = true;
2552
2553                                         if (_animTarget == ANIMATION_TARGET_POSITION || _animTarget == ANIMATION_TARGET_SIZE)
2554                                         {
2555                                                 SetControlLogicalBounds(_animTarget, *pAnimBase);
2556                                         }
2557                                         else if (_animTarget == ANIMATION_TARGET_ALPHA)
2558                                         {
2559                                                 SetControlShowState(_animTarget, *pAnimBase);
2560                                         }
2561
2562                                         delete pAnimBase;
2563                                 }
2564                         }
2565                 }
2566         }
2567         //Set Target status playing in case of platform defined Implicit animations
2568         else
2569         {
2570                 if (triggerType == ANIMATION_TRIGGER_POSITION_CHANGE)
2571                 {
2572                         __isAnimationTargetAnimating[ANIMATION_TARGET_POSITION] = true;
2573                 }
2574
2575                 if (triggerType == ANIMATION_TRIGGER_SIZE_CHANGE)
2576                 {
2577                         __isAnimationTargetAnimating[ANIMATION_TARGET_SIZE] = true;
2578                 }
2579
2580                 if (triggerType == ANIMATION_TRIGGER_SHOW_STATE_CHANGE)
2581                 {
2582                         __isAnimationTargetAnimating[ANIMATION_TARGET_ALPHA] = true;
2583                 }
2584         }
2585
2586         return r;
2587 }
2588
2589 result
2590 _ControlAnimatorImpl::SetKeyFrameAnimation(AnimationTargetType animTarget, AnimationBase* pAnimationBase, const IVisualElementAnimationTimingFunction* pTimingFunction, VisualElementAnimation* pAnimation)
2591 {
2592         long keyTime = 0;
2593         result r = E_SUCCESS;
2594
2595         VisualElementValueAnimation* pPropertyAnimation = dynamic_cast< VisualElementValueAnimation* >(pAnimation);
2596         SysTryReturnResult(NID_UI_ANIM, (pPropertyAnimation != null), E_INVALID_ARG, "Invalid argument(s) is used. VisualElementAnimation is null.");
2597
2598         switch (animTarget)
2599         {
2600
2601         case ANIMATION_TARGET_SIZE:
2602         {
2603                 DimensionAnimation* pDimensionAnim = null;
2604                 RectangleAnimation* pRectangleAnim = null;
2605
2606                 pDimensionAnim = dynamic_cast< DimensionAnimation* >(pAnimationBase);
2607                 pRectangleAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
2608                 SysTryReturnResult(NID_UI_ANIM, ((pDimensionAnim) || (pRectangleAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
2609
2610                 Dimension controlSize;
2611                 float anchorX = 0.0f;
2612                 float anchorY = 0.0f;
2613
2614                 controlSize = __pControl->GetSize();
2615
2616                 if (pDimensionAnim)
2617                 {
2618                         Dimension dimValue(0, 0);
2619
2620                         pDimensionAnim->GetAnchor(anchorX, anchorY);
2621
2622                         for (int index = 0; index < pDimensionAnim->GetKeyFrameCount(); index++)
2623                         {
2624                                 pDimensionAnim->GetKeyFrameAt(index, keyTime, dimValue);
2625
2626                                 if (keyTime < pDimensionAnim->GetDuration())
2627                                 {
2628                                         FloatRectangle modelBounds = __pVisualElement->GetBounds();
2629                                         FloatRectangle presentationBounds = const_cast<VisualElement*>((__pVisualElement)->AcquirePresentationInstance())->GetBounds();
2630                                         __pVisualElement->ReleasePresentationInstance();
2631
2632                                         float currentAnchorX = presentationBounds.width * anchorX;
2633                                         float currentAnchorY = presentationBounds.height * anchorY;
2634                                         float endAnchorX = dimValue.width * anchorX;
2635                                         float endAnchorY = dimValue.height * anchorY;
2636
2637                                         float endX = modelBounds.x + (currentAnchorX - endAnchorX);
2638                                         float endY = modelBounds.y + (currentAnchorY - endAnchorY);
2639
2640                                         Variant keyValue(FloatRectangle(endX, endY, static_cast< float >(dimValue.width), static_cast< float >(dimValue.height)));
2641
2642                                         r = pPropertyAnimation->AddKeyFrame(keyTime / static_cast< float >(pDimensionAnim->GetDuration()), keyValue, const_cast< IVisualElementAnimationTimingFunction* >(pTimingFunction));
2643                                         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to add key frame.");
2644                                 }
2645                         }
2646                 }
2647                 else    //if (pRectangleAnim)
2648                 {
2649                         Rectangle dimValue(0, 0, 0, 0);
2650
2651                         pRectangleAnim->GetAnchor(anchorX, anchorY);
2652
2653                         for (int index = 0; index < pRectangleAnim->GetKeyFrameCount(); index++)
2654                         {
2655                                 pRectangleAnim->GetKeyFrameAt(index, keyTime, dimValue);
2656
2657                                 if (keyTime < pRectangleAnim->GetDuration())
2658                                 {
2659                                         FloatRectangle modelBounds = __pVisualElement->GetBounds();
2660                                         FloatRectangle presentationBounds = const_cast<VisualElement*>((__pVisualElement)->AcquirePresentationInstance())->GetBounds();
2661                                         __pVisualElement->ReleasePresentationInstance();
2662
2663                                         float currentAnchorX = presentationBounds.width * anchorX;
2664                                         float currentAnchorY = presentationBounds.height * anchorY;
2665                                         float endAnchorX = dimValue.width * anchorX;
2666                                         float endAnchorY = dimValue.height * anchorY;
2667
2668                                         float endX = modelBounds.x + (currentAnchorX - endAnchorX);
2669                                         float endY = modelBounds.y + (currentAnchorY - endAnchorY);
2670
2671                                         Variant keyValue(FloatRectangle(endX, endY, static_cast< float >(dimValue.width), static_cast< float >(dimValue.height)));
2672                                         r = pPropertyAnimation->AddKeyFrame(keyTime / static_cast< float >(pRectangleAnim->GetDuration()), keyValue, const_cast< IVisualElementAnimationTimingFunction* >(pTimingFunction));
2673                                         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to add key frame.");
2674                                 }
2675                         }
2676                 }
2677         }
2678         break;
2679
2680         case ANIMATION_TARGET_POSITION:
2681         {
2682                 PointAnimation* pPointAnim = null;
2683                 RectangleAnimation* pRectangleAnim = null;
2684
2685                 pPointAnim = dynamic_cast< PointAnimation* >(pAnimationBase);
2686                 pRectangleAnim = dynamic_cast< RectangleAnimation* >(pAnimationBase);
2687                 SysTryReturnResult(NID_UI_ANIM, ((pPointAnim) || (pRectangleAnim)), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
2688
2689                 Point controlPos;
2690                 Rectangle clientBounds = __pControlImpl->GetParent()->GetClientBounds();
2691                 FloatRectangle modelBounds = __pVisualElement->GetBounds();
2692
2693                 controlPos = __pControl->GetPosition();
2694
2695                 if (pPointAnim)
2696                 {
2697                         Point pointValue(0, 0);
2698                         Point prevPointValue = controlPos;
2699
2700                         for (int index = 0; index < pPointAnim->GetKeyFrameCount(); index++)
2701                         {
2702                                 pPointAnim->GetKeyFrameAt(index, keyTime, pointValue);
2703
2704
2705                                 if (keyTime < pPointAnim->GetDuration())
2706                                 {
2707                                         float absPointX = (static_cast< float >(clientBounds.x) + static_cast< float >(pointValue.x));
2708                                         float absPointY = (static_cast< float >(clientBounds.y) + static_cast< float >(pointValue.y));
2709
2710                                         Variant keyValue(FloatPoint(absPointX, absPointY));
2711
2712                                         r = pPropertyAnimation->AddKeyFrame(static_cast< float >(keyTime) / static_cast< float >(pPointAnim->GetDuration()), keyValue, const_cast< IVisualElementAnimationTimingFunction* >(pTimingFunction));
2713                                         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to add key frame.");
2714                                 }
2715
2716                         }
2717                 }
2718                 else    //if (pRectangleAnim)
2719                 {
2720                         Rectangle pointValue(0, 0, 0, 0);
2721                         Rectangle prevPointValue = Rectangle(controlPos.x, controlPos.y, 0, 0);
2722
2723                         for (int index = 0; index < pRectangleAnim->GetKeyFrameCount(); index++)
2724                         {
2725                                 pRectangleAnim->GetKeyFrameAt(index, keyTime, pointValue);
2726
2727                                 if (keyTime < pRectangleAnim->GetDuration())
2728                                 {
2729                                         float absPointX = (static_cast< float >(clientBounds.x) + static_cast< float >(pointValue.x));
2730                                         float absPointY = (static_cast< float >(clientBounds.y) + static_cast< float >(pointValue.y));
2731
2732                                         Variant keyValue(FloatPoint(absPointX, absPointY));
2733
2734                                         r = pPropertyAnimation->AddKeyFrame(static_cast< float >(keyTime) / static_cast< float >(pRectangleAnim->GetDuration()), keyValue, const_cast< IVisualElementAnimationTimingFunction* >(pTimingFunction));
2735                                         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to add key frame.");
2736                                 }
2737                         }
2738                 }
2739         }
2740         break;
2741
2742         case ANIMATION_TARGET_ALPHA:
2743         {
2744                 IntegerAnimation* pIntegerAnim = null;
2745                 FloatAnimation* pFloatAnim = null;
2746
2747                 pIntegerAnim = dynamic_cast< IntegerAnimation* >(pAnimationBase);
2748                 pFloatAnim = dynamic_cast< FloatAnimation* >(pAnimationBase);
2749                 SysTryReturnResult(NID_UI_ANIM, (pIntegerAnim || pFloatAnim), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
2750
2751                 if (pIntegerAnim)
2752                 {
2753                         int alphaIntValue = 0;
2754
2755                         for (int index = 0; index < pIntegerAnim->GetKeyFrameCount(); index++)
2756                         {
2757                                 pIntegerAnim->GetKeyFrameAt(index, keyTime, alphaIntValue);
2758
2759                                 if (keyTime < pIntegerAnim->GetDuration())
2760                                 {
2761                                         Variant keyValue(static_cast< float >(alphaIntValue));
2762
2763                                         r = pPropertyAnimation->AddKeyFrame(static_cast< float >(keyTime) / static_cast< float >(pIntegerAnim->GetDuration()), keyValue, const_cast< IVisualElementAnimationTimingFunction* >(pTimingFunction));
2764                                         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to add key frame.");
2765
2766                                 }
2767                         }
2768                 }
2769                 else    //if (pFloatAnim)
2770                 {
2771                         float alphaFltValue = 0.0;
2772
2773                         for (int index = 0; index < pFloatAnim->GetKeyFrameCount(); index++)
2774                         {
2775                                 pFloatAnim->GetKeyFrameAt(index, keyTime, alphaFltValue);
2776
2777                                 if (keyTime < pFloatAnim->GetDuration())
2778                                 {
2779                                         Variant keyValue(static_cast< float >(alphaFltValue));
2780
2781                                         r = pPropertyAnimation->AddKeyFrame(static_cast< float >(keyTime) / static_cast< float >(pFloatAnim->GetDuration()), keyValue, const_cast< IVisualElementAnimationTimingFunction* >(pTimingFunction));
2782                                         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to add key frame.");
2783                                 }
2784                         }
2785                 }
2786         }
2787         break;
2788
2789         case ANIMATION_TARGET_ROTATION:
2790         {
2791                 RotateAnimation* pRotateAnim = null;
2792
2793                 pRotateAnim = dynamic_cast< RotateAnimation* >(pAnimationBase);
2794                 SysTryReturnResult(NID_UI_ANIM, (pRotateAnim), E_INVALID_ARG, "Invalid argument(s) is used. Animation is invalid.");
2795
2796                 float rotateFltValue = 0;
2797
2798                 for (int index = 0; index < pRotateAnim->GetKeyFrameCount(); index++)
2799                 {
2800                         pRotateAnim->GetKeyFrameAt(index, keyTime, rotateFltValue);
2801
2802                         if (keyTime < pRotateAnim->GetDuration())
2803                         {
2804                                 Variant keyValue(rotateFltValue);
2805
2806                                 r = pPropertyAnimation->AddKeyFrame(static_cast< float >(keyTime) / static_cast< float >(pRotateAnim->GetDuration()), keyValue, const_cast< IVisualElementAnimationTimingFunction* >(pTimingFunction));
2807                                 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to add key frame.");
2808                         }
2809                 }
2810         }
2811         break;
2812
2813         default:
2814         {
2815                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. animTarget is invalid.");
2816                 return E_SYSTEM;
2817         }
2818         break;
2819         }
2820
2821         return E_SUCCESS;
2822 }
2823
2824 result
2825 _ControlAnimatorImpl::SetGroupAnimation(AnimationGroup* pAnimGrp)
2826 {
2827         result r = E_SUCCESS;
2828         ParallelAnimationGroup* pParallelAnimGrp = null;
2829         SequentialAnimationGroup* pSequentialAnimGrp = null;
2830         AnimationTargetType animTargetArray[ANIMATION_TARGET_MAX] =
2831         {
2832                 ANIMATION_TARGET_ROTATION,
2833                 ANIMATION_TARGET_SIZE,
2834                 ANIMATION_TARGET_POSITION,
2835                 ANIMATION_TARGET_ALPHA
2836         };
2837         bool setLogicalBnds = false;
2838         bool setShowStateInternal = false;
2839         long delay = 0;
2840         long duration = 0;
2841         long totalDelay = 0;
2842         long groupDuration = 0;
2843         VisualElementAnimationGroup* pAnimationGroup = null;
2844         String animIdentifier;
2845         int activeAnimationCount = GetActiveAnimationListCount();
2846
2847         pParallelAnimGrp = dynamic_cast< ParallelAnimationGroup* >(pAnimGrp);
2848         pSequentialAnimGrp = dynamic_cast< SequentialAnimationGroup* >(pAnimGrp);
2849         SysTryReturnResult(NID_UI_ANIM, ((pParallelAnimGrp) || (pSequentialAnimGrp)), E_INVALID_ARG, "Invalid argument(s) is used. AnimationGroup argument is invalid.");
2850
2851         __sequelDelay = 0;
2852         pAnimationGroup = new (std::nothrow) VisualElementAnimationGroup();
2853         SysTryReturnResult(NID_UI_ANIM, (pAnimationGroup != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
2854
2855         animIdentifier.Append(__animId);
2856         animIdentifier.Append(GROUP);
2857         __animId++;
2858         __groupName.Clear();
2859         __groupName = animIdentifier;
2860
2861         if (pParallelAnimGrp)
2862         {
2863                 for (int target = (static_cast< int >(ANIMATION_TARGET_NONE) + 1); target < (static_cast< int >(ANIMATION_TARGET_MAX)); target++)
2864                 {
2865                         AnimationTargetType animTarget = animTargetArray[target];
2866                         AnimationBase* pAnimationBase = null;
2867                         pAnimationBase = pParallelAnimGrp->GetAnimationN(animTarget);
2868
2869                         if (pAnimationBase != null)
2870                         {
2871                                 long duration = pAnimationBase->GetDuration();
2872
2873                                 if (pAnimationBase->IsAutoReverseEnabled())
2874                                 {
2875                                         duration = duration * 2;
2876                                 }
2877
2878                                 duration = (duration * pAnimationBase->GetRepeatCount() * pAnimationBase->GetScaleRatio()) + ((pAnimationBase->GetDelay() - pAnimationBase->GetOffset()) * pAnimationBase->GetScaleRatio());
2879
2880                                 if (duration > groupDuration)
2881                                 {
2882                                         groupDuration = duration;
2883                                 }
2884
2885                                 if (IsAnimationSupported() == false)
2886                                 {
2887                                         r = SetControlProperty(animTarget, *pAnimationBase);
2888                                         delete pAnimationBase;
2889
2890                                         SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to store animation values.");
2891                                 }
2892                                 else
2893                                 {
2894                                         if (pParallelAnimGrp->IsAnimationAdded(ANIMATION_TARGET_POSITION) ||
2895                                                 pParallelAnimGrp->IsAnimationAdded(ANIMATION_TARGET_SIZE))
2896                                         {
2897                                                 __logicalBoundsHolder = __pControl->GetBounds();
2898                                                 setLogicalBnds = true;
2899                                         }
2900                                         else if (pParallelAnimGrp->IsAnimationAdded(ANIMATION_TARGET_ALPHA))
2901                                         {
2902                                                 __showStateHolder = __pControl->GetShowState();
2903                                                 setShowStateInternal = true;
2904                                         }
2905
2906                                         r = SetAnimation(animTarget, *pAnimationBase, ANIMATION_TRIGGER_USER, pAnimationGroup);
2907
2908                                         if (r != E_SUCCESS)
2909                                         {
2910                                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start animation.");
2911                                                 goto CATCH;
2912                                         }
2913
2914                                         __isAnimationTargetAnimating[animTarget] = true;
2915
2916                                         if (animTarget == ANIMATION_TARGET_POSITION || animTarget == ANIMATION_TARGET_SIZE)
2917                                         {
2918                                                 SetControlLogicalBounds(animTarget, *pAnimationBase);
2919                                         }
2920                                         else if (animTarget == ANIMATION_TARGET_ALPHA)
2921                                         {
2922                                                 SetControlShowState(animTarget, *pAnimationBase);
2923                                         }
2924                                 }
2925                         }
2926                 }
2927         }
2928         else
2929         {
2930                 __prevAnimationBoundsHolder = __pControl->GetBounds();
2931
2932                 for (int index = 0; index < pSequentialAnimGrp->GetAnimationCount(); index++)
2933                 {
2934                         AnimationTargetType animTarget = ANIMATION_TARGET_MAX;
2935                         AnimationBase* pAnimationBase = null;
2936                         pAnimationBase = pSequentialAnimGrp->GetAnimationAtN(index);
2937                         animTarget = pSequentialAnimGrp->GetAnimationTargetTypeAt(index);
2938
2939                         if (pAnimationBase != null)
2940                         {
2941                                 if (IsAnimationSupported() == false)
2942                                 {
2943                                         r = SetControlProperty(animTarget, *pAnimationBase);
2944                                         delete pAnimationBase;
2945
2946                                         SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to store animation values.");
2947                                 }
2948                                 else
2949                                 {
2950                                         if ((pSequentialAnimGrp->GetAnimationTargetTypeAt(index) == ANIMATION_TARGET_POSITION) ||
2951                                                 (pSequentialAnimGrp->GetAnimationTargetTypeAt(index) == ANIMATION_TARGET_SIZE))
2952                                         {
2953                                                 __logicalBoundsHolder = __pControl->GetBounds();
2954                                                 setLogicalBnds = true;
2955                                         }
2956
2957                                         if (pSequentialAnimGrp->GetAnimationTargetTypeAt(index) == ANIMATION_TARGET_ALPHA)
2958                                         {
2959                                                 __showStateHolder = __pControl->GetShowState();
2960                                                 setShowStateInternal = true;
2961                                         }
2962
2963                                         if (animTarget == ANIMATION_TARGET_SIZE)
2964                                         {
2965                                                 r = SetPrevAnimationBoundsProperty(animTarget, *pAnimationBase);
2966
2967                                                 if (r != E_SUCCESS)
2968                                                 {
2969                                                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to store previous animation bounds.");
2970                                                         delete pAnimationBase;
2971
2972                                                         goto CATCH;
2973                                                 }
2974                                         }
2975
2976                                         __sequentialGroupAnimation = true;
2977                                         //Add the animation to the group
2978                                         r = SetAnimation(animTarget, *pAnimationBase, ANIMATION_TRIGGER_USER, pAnimationGroup);
2979                                         __sequentialGroupAnimation = false;
2980
2981                                         if (pAnimationBase->IsAutoReverseEnabled() == true)
2982                                         {
2983                                                 duration = 2 * pAnimationBase->GetDuration();
2984                                         }
2985                                         else
2986                                         {
2987                                                 duration = pAnimationBase->GetDuration();
2988                                         }
2989
2990                                         delay = pAnimationBase->GetDelay();
2991                                         totalDelay = delay + duration * pAnimationBase->GetRepeatCount();
2992                                         totalDelay = totalDelay - (pAnimationBase->GetOffset());
2993                                         __sequelDelay = totalDelay;
2994                                         groupDuration = groupDuration + __sequelDelay * pAnimationBase->GetScaleRatio();
2995
2996                                         if (r != E_SUCCESS)
2997                                         {
2998                                                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start animation.");
2999                                                 goto CATCH;
3000                                         }
3001
3002                                         __isAnimationTargetAnimating[animTarget] = true;
3003
3004                                         if (animTarget == ANIMATION_TARGET_POSITION || animTarget == ANIMATION_TARGET_SIZE)
3005                                         {
3006                                                 SetControlLogicalBounds(animTarget, *pAnimationBase);
3007                                         }
3008                                         else if (animTarget == ANIMATION_TARGET_ALPHA)
3009                                         {
3010                                                 SetControlShowState(animTarget, *pAnimationBase);
3011                                         }
3012                                 }
3013                         }
3014                 }
3015         }
3016
3017         if (setLogicalBnds)
3018         {
3019                 bool disable = false;
3020                 bool propagation = false;
3021
3022                 result r = DisableImplicitAnimation(disable);
3023                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
3024                 //if (pParallelAnimGrp == null)
3025                 {
3026                         r = DisableVisualElementPropagation(propagation);
3027                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
3028                 }
3029                 r = __pControl->SetBounds(__logicalBoundsHolder);
3030
3031                 if (propagation)
3032                 {
3033                         DisableVisualElementPropagation(propagation);
3034                 }
3035                 if (disable)
3036                 {
3037                         DisableImplicitAnimation(disable);
3038                 }
3039
3040                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
3041         }
3042
3043         if (setShowStateInternal)
3044         {
3045                 bool disable = false;
3046                 bool propagation = false;
3047
3048                 result r = DisableImplicitAnimation(disable);
3049                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
3050
3051                 r = DisableVisualElementPropagation(propagation);
3052                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
3053
3054                 r = __pControl->SetShowState(__showStateHolder);
3055
3056                 if (propagation)
3057                 {
3058                         DisableVisualElementPropagation(propagation);
3059                 }
3060                 if (disable)
3061                 {
3062                         DisableImplicitAnimation(disable);
3063                 }
3064
3065                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set show state.");
3066         }
3067
3068         // for layout
3069         __pControlImpl->SetBoundsAndUpdateLayout(__pControlImpl->GetBounds());
3070
3071         pAnimationGroup->SetDuration(groupDuration);
3072         r = __pVisualElement->AddAnimation(animIdentifier, *pAnimationGroup);
3073         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to start group animation.");
3074
3075         delete pAnimationGroup;
3076         return r;
3077
3078 CATCH:
3079         //check clean up
3080         delete pAnimationGroup;
3081
3082         if (DestroyAnimation(activeAnimationCount) != E_SUCCESS)
3083         {
3084                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to deallocate memory.");
3085                 return E_SYSTEM;
3086         }
3087
3088         return r;
3089 }
3090
3091 result
3092 _ControlAnimatorImpl::DisableImplicitAnimation(bool& state)
3093 {
3094         bool enable = __pVisualElement->IsImplicitAnimationEnabled();
3095         __pVisualElement->SetImplicitAnimationEnabled(state);
3096         state = enable;
3097
3098         return E_SUCCESS;
3099 }
3100
3101 result
3102 _ControlAnimatorImpl::DisableVisualElementPropagation(bool& state)
3103 {
3104         bool propagate = _VisualElementImpl::GetInstance(*__pVisualElement)->GetPropertyPropagationEnabled();
3105         result r = _VisualElementImpl::GetInstance(*__pVisualElement)->SetPropertyPropagationEnabled(state);
3106         state = propagate;
3107
3108         return r;
3109 }
3110
3111 void
3112 _ControlAnimatorImpl::OnTickOccurred(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, const Variant& currentValue)
3113 {
3114         VisualElementValueAnimation* pAnimation = dynamic_cast< VisualElementValueAnimation* >(const_cast< VisualElementAnimation* >(&animation));
3115         VisualElement* pPresentation = const_cast< VisualElement* >(target.AcquirePresentationInstance());
3116
3117         if (pPresentation && pAnimation)
3118         {
3119                 float diffX = 0.0f;
3120                 float diffY = 0.0f;
3121
3122                 if (!pAnimation->IsEndValueApplied() && (__isAnimationTargetAnimating[ANIMATION_TARGET_POSITION]))
3123                 {
3124                         diffX = pPresentation->GetBounds().x + currentValue.ToFloatRectangle().x - __presentationBounds.x;
3125                         diffY = pPresentation->GetBounds().y + currentValue.ToFloatRectangle().y - __presentationBounds.y;
3126                 }
3127                 else
3128                 {
3129                         diffX = pPresentation->GetBounds().x;
3130                         diffY = pPresentation->GetBounds().y;
3131                 }
3132
3133                 Variant newBounds(FloatRectangle(diffX, diffY, currentValue.ToFloatRectangle().width, currentValue.ToFloatRectangle().height));
3134                 _VisualElementImpl::GetInstance(*pPresentation)->SetProperty(VePropBounds, newBounds);
3135         }
3136         else
3137         {
3138                 SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get presentation instance of visual element.");
3139         }
3140
3141         target.ReleasePresentationInstance();
3142 }
3143 }}}             // Tizen::Ui::Animations
3144