Applied context restoring
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_VisualElementImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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_VisualElementImpl.cpp
20  * @brief       This file contains implementation of _VisualElementImpl class
21  *
22  * This file contains implementation _VisualElementImpl class.
23  */
24
25 #include <typeinfo>
26 #include <unique_ptr.h>
27 #include <FBaseString.h>
28 #include <FBaseSysLog.h>
29 #include <FGrpFloatPoint.h>
30 #include <FGrpFloatDimension.h>
31 #include <FGrpFloatRectangle.h>
32 #include <FGrpFloatMatrix4.h>
33 #include <FGrpFloatPoint3.h>
34 #include <FGrpBufferInfo.h>
35 #include <FBaseByteBuffer.h>
36 #include <FGrp_CanvasImpl.h>
37 #include <FGrp_BitmapImpl.h>
38 #include <FUiAnimIVisualElementAnimationStatusEventListener.h>
39 #include <FUiAnimVisualElementPropertyAnimation.h>
40 #include <FUiAnimVisualElementAnimationGroup.h>
41 #include <FUiAnimVisualElementSurface.h>
42
43 #include <FUiAnimVisualElement.h>
44
45 #include "FUi_Rectanglef.h"
46 #include "FUi_CoordinateSystemUtils.h"
47
48 #include "FUiAnim_VisualElementImpl.h"
49 #include "FUiAnim_VisualElementCanvas.h"
50
51 #include "FUiAnim_VisualElementAnimationImpl.h"
52 #include "FUiAnim_VisualElementAnimationGroupImpl.h"
53 #include "FUiAnim_VisualElementValueAnimationImpl.h"
54 #include "FUiAnim_VisualElementPropertyAnimationImpl.h"
55 #include "FUiAnim_AnimationManager.h"
56 #include "FUiAnim_VisualElementSharedData.h"
57 #include "FUiAnim_RootVisualElement.h"
58 #include "FUiAnim_ControlVisualElement.h"
59 #include "FUiAnim_MatrixUtil.h"
60 #include "FUiAnim_Debug.h"
61 #include "FUiAnim_EflNode.h"
62 #include "FUiAnim_EflLayer.h"
63 #include "FUiAnim_VisualElementSurfaceImpl.h"
64 #include "FUiAnim_EflVisualElementSurfaceImpl.h"
65 #include "FUiAnim_DisplayManager.h"
66
67
68 using namespace std;
69 using namespace Tizen::Base;
70 using namespace Tizen::Base::Collection;
71 using namespace Tizen::Graphics;
72 using namespace Tizen::Ui;
73
74 #define LAZY_EVALUATION // lazy updating and reconfiguring.
75 #define IMPLICIT_ANIMATION_IMPL  //prototyping implicit animation.
76 //#define       MANUAL_PROPERTY_CHANGE_NOTIFICATION
77
78 #define IS_INTERNAL_CLASS(_PUBLIC) (likely(typeid(*(_PUBLIC)) == VeTypeId) || likely(typeid(*(_PUBLIC)) == internalVeTypeId) || likely(typeid(*(_PUBLIC)) == controlVeTypeId) || likely(typeid(*(_PUBLIC)) == rootVeTypeId))
79 #define IS_NEEDED_UPDATE_PRESENTATION(__MODEL)  (((__MODEL)->__isPropertyPropagationEnabled) && ((__MODEL)->__pPresentation))
80 namespace {
81
82 static const char* STR_ERROR_INVALID_VARIANT_ARG_TYPE = "[E_INVALID_ARG] Invalid argument(s) is used. Variant type is invalid.";
83
84 void
85 CalculateBoundingBox(const float x[4], const float y[4], Tizen::Graphics::FloatRectangle& rectangle)
86 {
87         float minX = x[0];
88         float minY = y[0];
89         float maxX = minX;
90         float maxY = minY;
91         for (int i = 1; i < 4; i++)
92         {
93                 if (x[i] < minX)
94                         minX = x[i];
95
96                 if (y[i] < minY)
97                         minY = y[i];
98
99                 if (x[i] > maxX)
100                         maxX = x[i];
101
102                 if (y[i] > maxY)
103                         maxY = y[i];
104         }
105
106         rectangle.x = minX;
107         rectangle.y = minY;
108         rectangle.width = maxX - minX;
109         rectangle.height = maxY - minY;
110 }
111
112
113 }
114
115 namespace Tizen { namespace Ui { namespace Animations
116 {
117 // rules of visual element.
118 //
119 // 1. almost controlling pSharedData occurred in the PRESENTATION layer.
120 // 2. almost Delegate's methods occurred in the MODEL layer.
121 //
122
123 #define SHOWOPACITY_VISIBLE(so) \
124         (so != 0.0f)
125
126 #define VE_VISIBLE(o)                   \
127         SHOWOPACITY_VISIBLE((o)->__showOpacity)
128
129 #define HAVE_SURFACE(o)                 \
130         (likely((o)->GetSharedData().pSurface))
131
132 //TODO: require further examination : __NeedSurface() instead of NEED_SURFACE() macro
133 #define NEED_SURFACE(o)                 \
134         (likely((o)->GetSharedData().needSurface))
135
136 #define IS_ATTACHED(o)                  \
137         ((o)->GetRoot() != null)
138
139 #define IS_PRESENTATION(o)              \
140         ((o)->__pPresentation == (o))
141
142 #define IS_MODEL(o)                             \
143         ((o)->__pModel == (o))
144
145 #define VE_DELEGATE(target, func, ...)  \
146                 (target)->func(__VA_ARGS__)
147
148
149
150 static const std::type_info& VeTypeId = typeid(VisualElement);
151 static const std::type_info& rootVeTypeId = typeid(_RootVisualElement);
152 static const std::type_info& internalVeTypeId = typeid(_VisualElement);
153 static const std::type_info& controlVeTypeId = typeid(_ControlVisualElement);
154
155 // declared AnimationEventListener for implicit animation
156 class _VisualElementImplicitAnimationEventListener
157         : public IVisualElementAnimationStatusEventListener
158         , virtual public Tizen::Base::Runtime::IEventListener
159 {
160 public:
161         _VisualElementImplicitAnimationEventListener(void) {}
162         virtual ~_VisualElementImplicitAnimationEventListener(void) {}
163
164         virtual void OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target) {}
165         virtual void OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount) {}
166         virtual void OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
167         {
168                 target.Destroy();
169                 delete this;
170         }
171 };
172
173 IMPLEMENT_PROPERTY(_VisualElementImpl);
174
175 _VisualElementImpl::_VisualElementImpl(VisualElement& element)
176         : _zOrderGroup(Z_ORDER_GROUP_NORMAL)
177         , __pSharedData(null)
178         , __pParent(null)
179         , __pModel(null)
180         , __pPresentation(null)
181         , __pRoot(null)
182         , __isRoot(false)
183         , __isVisible(false)
184         , __showOpacity(0.0f)
185         , __needRecreateSurface(false)
186         , __bounds(0.0f, 0.0f, 0.0f, 0.0f)
187         , __alignedSize(0.0f, 0.0f)
188         , __contentBounds(0.0f, 0.0f, 1.0f, 1.0f)
189         , __useContentBounds(false)
190         , __zPosition(0.0f)
191         , __contentOpacity(1.0f)
192         , __opacity(1.0f)
193         , __anchor(0.5f, 0.5f)
194         , __anchorZ(0.0f)
195         , __transform()
196         , __decomposedTransform()
197         , __childrenTransform()
198         , __decomposedChildrenTransform()
199         , __childrenNeedsUpdateProps(HIERARCHY_PROPERTY_MASK)
200         , __invalidatedProps(HIERARCHY_PROPERTY_MASK)
201         , __matrixFromTopValid(false)
202         , __matrixFromTopInvertible(true)
203         , __matrixToSuperValid(false)
204         , __matrixToTopValid(false)
205         , __matrixToClipSourceValid(false)
206         , __boundingBoxValid(false)
207         , __visibleRectValid(false)
208         , __needTransform(false)
209         , __needClipForUntransformed(false)
210         , __isImplicitAnimationEnabled(true)
211         , __isClipChildren(false)
212         , __boundingBox(0.0f, 0.0f, 0.0f, 0.0f)
213         , __pClipSource(null)
214         , __visibleRect(0.0f, 0.0f, 0.0f, 0.0f)
215         , __isPropertyPropagationEnabled(true)
216         , __isDestroying(false)
217         , __isHidingParent(false)
218         , __isInternal(false)
219         , __isAllowedTreeModification(true)
220         , __pPublicInstance(&element)
221         , __imageFilePath()
222         , __renderOperation(VisualElement::RENDER_OPERATION_BLEND)
223         , __pBoundsChangedCallback(null)
224         , __pBoundsChangedCallbackData(null)
225         , __pDestroyedCallback(null)
226         , __pDestroyedCallbackData(null)
227 {
228         ClearLastResult();
229
230         __children.Construct();
231 }
232
233 _VisualElementImpl::_VisualElementImpl(VisualElement& presentation, _VisualElementImpl& modelImpl)
234         : _zOrderGroup(modelImpl._zOrderGroup)
235         , __pSharedData(null)
236         , __pParent(null)
237         , __pModel(null)
238         , __pPresentation(null)
239         , __pRoot(null)
240         , __isRoot(modelImpl.__isRoot)
241         , __isVisible(modelImpl.__isVisible)
242         , __showOpacity(modelImpl.__showOpacity)
243         , __needRecreateSurface(false)
244         , __bounds(modelImpl.__bounds)
245         , __alignedSize(modelImpl.__alignedSize)
246         , __contentBounds(modelImpl.__contentBounds)
247         , __useContentBounds(modelImpl.__useContentBounds)
248         , __zPosition(modelImpl.__zPosition)
249         , __contentOpacity(modelImpl.__contentOpacity)
250         , __opacity(modelImpl.__opacity)
251         , __anchor(modelImpl.__anchor)
252         , __anchorZ(modelImpl.__anchorZ)
253         , __transform(modelImpl.__transform)
254         , __decomposedTransform(modelImpl.__decomposedTransform)
255         , __childrenTransform(modelImpl.__childrenTransform)
256         , __decomposedChildrenTransform(modelImpl.__decomposedChildrenTransform)
257         , __childrenNeedsUpdateProps(HIERARCHY_PROPERTY_MASK)
258         , __invalidatedProps(HIERARCHY_PROPERTY_MASK)
259         , __matrixFromTopValid(false)
260         , __matrixFromTopInvertible(true)
261         , __matrixToSuperValid(false)
262         , __matrixToTopValid(false)
263         , __matrixToClipSourceValid(false)
264         , __boundingBoxValid(false)
265         , __visibleRectValid(false)
266         , __needTransform(modelImpl.__needTransform)
267         , __needClipForUntransformed(modelImpl.__needClipForUntransformed)
268         , __isImplicitAnimationEnabled(modelImpl.__isImplicitAnimationEnabled)
269         , __isClipChildren(modelImpl.__isClipChildren)
270         , __boundingBox(0.0f, 0.0f, 0.0f, 0.0f)
271         , __pClipSource(null)
272         , __visibleRect(0.0f, 0.0f, 0.0f, 0.0f)
273         , __isPropertyPropagationEnabled(false) // it differs from the property of MODEL object
274         , __isDestroying(false)
275         , __isHidingParent(modelImpl.__isHidingParent)
276         , __isInternal(modelImpl.__isInternal)
277         , __isAllowedTreeModification(true)
278         , __pPublicInstance(&presentation)
279         , __imageFilePath(modelImpl.__imageFilePath)
280         , __renderOperation(modelImpl.__renderOperation)
281         , __pBoundsChangedCallback(modelImpl.__pBoundsChangedCallback)
282         , __pBoundsChangedCallbackData(modelImpl.__pBoundsChangedCallbackData)
283         , __pDestroyedCallback(modelImpl.__pDestroyedCallback)
284         , __pDestroyedCallbackData(modelImpl.__pDestroyedCallbackData)
285 {
286         ClearLastResult();
287
288         __children.Construct();
289 }
290
291 _VisualElementImpl::~_VisualElementImpl(void)
292 {
293         ClearLastResult();
294         // clear data after detaching children
295         if (likely(__pSharedData))
296         {
297                 __pSharedData->Release();
298                 __pSharedData = null;
299         }
300
301         // remove public instance
302         __pPublicInstance = null;
303
304         if (__pDestroyedCallback != null)
305         {
306                 __pDestroyedCallback(__pDestroyedCallbackData);
307         }
308 }
309
310 void
311 _VisualElementImpl::Destroy(void)
312 {
313         //SysLog(NID_UI_ANIM, "destruct[%x]-->begin", this);
314
315         if (unlikely(__isDestroying))
316         {
317                 return;
318         }
319
320         __isDestroying = true;
321
322
323         // WARNING:
324         //      Destroy and its callback will be called from the leaf of hiearchy tree first.
325         //      That is, this method first destroys children(Destroy and OnDestructing), and it destroys itself later.
326
327         while (__children.GetCount() > 0)
328         {
329                 _VisualElementImpl* pChild = __children.GetChildAt(0);
330                 if (likely(pChild))
331                 {
332                         //pChild->RemoveFromParent();
333                         //or
334                         if (likely(pChild->__pPublicInstance))
335                         {
336                                 pChild->__pPublicInstance->Destroy();
337                         }
338                         else
339                         {
340                                 SysAssertf(false, "VisualElement does not have public instance.");
341                         }
342
343                 }
344                 else
345                 {
346                         SysAssertf(false, "VisualElement has no child.");
347                 }
348
349         }
350
351
352         // CHECKME:
353         //      Is this right place for invoking 'OnDestructing' ?
354         //      OnConstructed will be called from public instance.
355
356         if (!IS_PRESENTATION(this))
357         {
358                 VE_DELEGATE(this, InvokeOnDestructing);
359         }
360
361
362         RemoveFromParent();
363
364
365         if (IS_MODEL(this))
366         {
367                 if (likely(__pPresentation))
368                 {
369                         __pPresentation->__pPublicInstance->Destroy();
370                 }
371                 __pPresentation = null;
372         }
373         else
374         {
375                 _AnimationManager* pManager = _AnimationManager::GetInstance();
376                 if (pManager)
377                 {
378                         pManager->RemoveAllAnimations(*__pPublicInstance);
379                 }
380
381                 __pModel = null;
382         }
383
384         delete this;
385 }
386
387 result
388 _VisualElementImpl::Construct(void)
389 {
390         result r = E_SUCCESS;
391         __pSharedData = new (std::nothrow) _VisualElementSharedData;
392         SysTryCatch(NID_UI_ANIM, __pSharedData, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
393         SysTryCatch(NID_UI_ANIM, GetSharedData().Construct() == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed in shared data constructing.");
394
395         __pModel = this;
396         __pPresentation = null;
397         //SysLog(NID_UI_ANIM, "Created(efl=%p)", GetSharedData().pNativeNode);
398
399 #if 0 // REMOVED : We should invoke property observer method manually.
400         if (__isPropertyPropagationEnabled)
401         {
402                 AddPropertyChangeEventListener(_VisualElementModelObserver::GetInstance());
403         }
404 #endif
405
406         //VE_DELEGATE(this, InvokeOnConstructed);
407
408         return E_SUCCESS;
409
410
411 CATCH:
412         if (likely(__pSharedData))
413         {
414                 GetSharedData().Release();
415                 __pSharedData = null;
416         }
417
418         return r;
419 }
420
421 IVisualElementAnimationProvider*
422 _VisualElementImpl::GetAnimationProvider(void) const
423 {
424         ClearLastResult();
425         SysTryReturn(NID_UI_ANIM, IS_MODEL(this), null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] VisualElement is not Model object.");
426
427         return GetSharedData().pAnimationProvider;
428 }
429
430 result
431 _VisualElementImpl::SetAnimationProvider(IVisualElementAnimationProvider* pProvider)
432 {
433         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
434
435         GetSharedData().pAnimationProvider = pProvider;
436
437         return E_SUCCESS;
438 }
439
440 IVisualElementContentProvider*
441 _VisualElementImpl::GetContentProvider(void) const
442 {
443         ClearLastResult();
444         SysTryReturn(NID_UI_ANIM, IS_MODEL(this), null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] VisualElement is not Model object.");
445
446         return GetSharedData().pContentProvider;
447 }
448
449 result
450 _VisualElementImpl::SetContentProvider(IVisualElementContentProvider* pProvider)
451 {
452         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
453
454         GetSharedData().pContentProvider = pProvider;
455
456         return E_SUCCESS;
457 }
458
459 IVisualElementEventListener*
460 _VisualElementImpl::GetVisualElementEventListener(void) const
461 {
462         ClearLastResult();
463         SysTryReturn(NID_UI_ANIM, IS_MODEL(this), null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] VisualElement is not Model object.");
464
465         return GetSharedData().pEventListener;
466 }
467
468 result
469 _VisualElementImpl::SetVisualElementEventListener(IVisualElementEventListener* pListener)
470 {
471         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
472
473         GetSharedData().pEventListener = pListener;
474
475         return E_SUCCESS;
476 }
477
478 result
479 _VisualElementImpl::FlushI(void)
480 {
481 #ifdef VE_VSYNC_UPDATE
482         _DisplayManager::GetInstance()->RenderAll();
483 #endif
484
485         return _DisplayManager::GetInstance()->Flush();
486 }
487
488 bool
489 _VisualElementImpl::CreateImplicitAnimationIfNeeded( const String& property,
490                 const Variant& newValue, const Variant& currentPresentationValue, const String** pSubProperties)
491 {
492         bool r = true;
493
494         _AnimationManager* pAnimationManager = _AnimationManager::GetInstance();
495
496         if (likely(GetRoot())
497                 && likely(GetSharedData().needSurface)
498                 && (unlikely(pAnimationManager->IsImplicitAnimationEnabled() && __isImplicitAnimationEnabled))  )
499         {
500                 // WARNING:
501                 //      For performance, following must be done only when oldValue != newValue.
502                 VisualElementAnimation* pAnimation = InvokeCreateAnimationForProperty(property);
503
504                 // user can make other type animation like aAnimationGroup or ValueAnimation
505                 // in this case pPropertyAnimation will have a null value.
506                 VisualElementPropertyAnimation* pPropertyAnimation = dynamic_cast< VisualElementPropertyAnimation* >(pAnimation);
507                 if (likely(pPropertyAnimation))
508                 {
509                         if (pPropertyAnimation->GetEndValue().IsEmpty())
510                         {
511                                 pPropertyAnimation->SetEndValue(newValue);
512                         }
513
514                         if (pPropertyAnimation->GetStartValue().IsEmpty())
515                         {
516                                 pPropertyAnimation->SetStartValue(currentPresentationValue);
517                         }
518                 }
519
520                 if(pSubProperties)
521                 { // remove sub property
522                         for(int i = 0 ; pSubProperties[i] != NULL ; i++)
523                         {
524                                 pAnimationManager->RemoveAnimationByProperty(*__pPublicInstance, *pSubProperties[i]);
525                         }
526                 }
527                 if (unlikely(pAnimation))
528                 {
529                         /// WARNING:
530                         //      Adding property animation causes previous animation for same property to be removed in Animation Manager.
531                         if (unlikely(IsFailed(AddAnimation(null, *pAnimation))))
532                         {
533                                 pAnimationManager->RemoveAnimationByProperty(*__pPresentation->__pPublicInstance, property);
534                                 r = false;
535                         }
536
537                         delete pAnimation;
538                 }
539                 else
540                 {
541                         // WARNING:
542                         //      Remove previous animation even when trying to change the property without animation.
543                         pAnimationManager->RemoveAnimationByProperty(*__pPresentation->__pPublicInstance, property);
544                         r = false;
545                 }
546         }
547         else
548         {
549                 pAnimationManager->RemoveAnimationByProperty(*__pPresentation->__pPublicInstance, property);
550                 r = false;
551         }
552         return r;
553 }
554
555
556 result
557 _VisualElementImpl::SetRenderOperation(VisualElement::RenderOperation renderOperation)
558 {
559         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
560
561         result r = InvokeOnSetPropertyRequested(*pVePropRenderOperation, Variant(static_cast< int >(renderOperation)));
562         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
563
564         return r;
565 }
566
567 VisualElement::RenderOperation
568 _VisualElementImpl::GetRenderOperation(void) const
569 {
570         ClearLastResult();
571
572 #if 0
573         int renderOperation = InvokeOnGetPropertyRequested(*pVePropRenderOperation).ToInt();
574         if (GetLastResult() != E_SUCCESS)
575         {
576                 return VisualElement::RENDER_OPERATION_BLEND;
577         }
578
579         return static_cast< VisualElement::RenderOperation >(renderOperation);
580 #else
581         return __renderOperation;
582 #endif
583 }
584
585 Variant
586 _VisualElementImpl::GetRenderOperationProperty(void) const
587 {
588         ClearLastResult();
589
590         return Variant(static_cast< int >(__renderOperation));
591 }
592
593 result
594 _VisualElementImpl::SetRenderOperationProperty(const Variant& v)
595 {
596         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_INT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
597
598         VisualElement::RenderOperation renderOperation = static_cast< VisualElement::RenderOperation >(v.ToInt());
599         if (likely(__renderOperation != renderOperation))
600         {
601                 SysTryReturnResult(
602                         NID_UI_ANIM,
603                         renderOperation >= VisualElement::RENDER_OPERATION_BLEND && renderOperation <= VisualElement::RENDER_OPERATION_COPY,
604                         E_INVALID_ARG,
605                         "Invalid argument(s) is used. The given render operation is out of range."
606                 );
607
608                 __renderOperation = renderOperation;
609                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_OPACITY, false, false);
610         }
611         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
612         {
613                 __pPresentation->SetRenderOperationProperty(__renderOperation);
614         }
615
616         return E_SUCCESS;
617 }
618
619 bool
620 _VisualElementImpl::GetBackBufferEnabled(void) const
621 {
622         ClearLastResult();
623
624         return GetSharedData().needSurface;
625 }
626
627 result
628 _VisualElementImpl::SetBackBufferEnabled(bool enabled)
629 {
630         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
631
632         if (likely(GetSharedData().needSurface != enabled))
633         {
634                 /// WARNING:
635                 //      Need to check transform matrix if the transform matrix is complex(generic). In this case, disabling Backing-Buffer
636                 //      should not be allowed !
637                 //
638                 if (likely(NEED_SURFACE(this))) // may be redundant checking.... (or using !enabled). Check if this needs surface currently.
639                 {
640 //                      _Matrix3Df;
641 //                      __transform.Optimize();
642 //                      SysTryReturnResult(NID_UI_ANIM, !__transform.IsGeneric(), E_INVALID_STATE, "VisualElement cannot release back-buffer if transform isn't identity or translation.");
643
644                         Matrix4Type matrixType = _GetMatrix4Type(__transform);
645                         SysTryReturnResult(
646                                 NID_UI_ANIM,
647                                 matrixType == MATRIX4_Identity || matrixType == MATRIX4_Translation,
648                                 E_INVALID_STATE,
649                                 "VisualElement cannot release back-buffer if transform isn't identity nor translation."
650                         );
651                 }
652
653                 GetSharedData().needSurface = enabled;
654
655                 if (NEED_SURFACE(this))
656                 {
657                         ExposeRectangle(null, true);
658                 }
659                 else
660                 {
661                         InvalidateVisibleRectToRenderTarget(null);
662                 }
663
664                 SetSurfaceChanged();
665         }
666
667         return E_SUCCESS;
668 }
669
670 bool
671 _VisualElementImpl::GetRedrawOnResizeEnabled(void) const
672 {
673         ClearLastResult();
674
675         return GetSharedData().redrawOnResize;
676 }
677
678 result
679 _VisualElementImpl::SetRedrawOnResizeEnabled(bool enabled)
680 {
681         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
682
683         GetSharedData().redrawOnResize = enabled;
684
685         return E_SUCCESS;
686 }
687
688 bool
689 _VisualElementImpl::GetPropertyPropagationEnabled(void) const
690 {
691         ClearLastResult();
692
693         // TBD: forward using property or direct return ?
694 #if 0
695         bool isPropertyPropagationEnabled = InvokeOnGetPropertyRequested(*pVePropPropertyPropagationEnabled).ToBool();
696         if (GetLastResult() != E_SUCCESS)
697         {
698                 return false;
699         }
700
701         return isPropertyPropagationEnabled;
702 #else
703         return __isPropertyPropagationEnabled;
704 #endif
705 }
706
707 result
708 _VisualElementImpl::SetPropertyPropagationEnabledI(bool enable)
709 {
710         if (unlikely(enable == __isPropertyPropagationEnabled))
711         {
712                 return E_SUCCESS;
713         }
714
715         __isPropertyPropagationEnabled = enable;
716
717 //      if (IS_MODEL(this))
718 //      {
719 //              if (__isPropertyPropagationEnabled)
720 //              {
721 //                      AddPropertyChangeEventListener(_VisualElementModelObserver::GetInstance());
722 //              }
723 //              else
724 //              {
725 //                      RemovePropertyChangeEventListener(_VisualElementModelObserver::GetInstance());
726 //              }
727 //      }
728
729         return E_SUCCESS;
730 }
731
732 result
733 _VisualElementImpl::SetPropertyPropagationEnabled(bool enable)
734 {
735         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
736         if (enable == __isPropertyPropagationEnabled)
737                 return E_SUCCESS;
738
739         result r = InvokeOnSetPropertyRequested(*pVePropPropertyPropagationEnabled, Variant(enable));
740         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
741
742         return r;
743 }
744
745 Variant
746 _VisualElementImpl::GetPropertyPropagationProperty(void) const
747 {
748         ClearLastResult();
749
750         return Variant(__isPropertyPropagationEnabled);
751 }
752
753 result
754 _VisualElementImpl::SetPropertyPropagationProperty(const Variant& v)
755 {
756         // TODO:
757         //      Remove this from property. It is used as a property because of _ControlVisualElement when a control was made up of three VEs.
758         if (IS_PRESENTATION(this))
759                 return E_SUCCESS;
760
761         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
762
763         return SetPropertyPropagationEnabledI(v.ToBool());
764 }
765
766 bool
767 _VisualElementImpl::IsSurfaceNeeded(void) const
768 {
769 //       TBD: root VE must have surface always...
770         if (unlikely(!__pParent))
771         {
772                 return true;
773         }
774
775 #if 0
776         const _VisualElementImpl* pCurrent;
777
778         pCurrent = this;
779         while (pCurrent)
780         {
781                 if (!pCurrent->__pSharedData)
782                 {
783                         return false;
784                 }
785
786                 if (!pCurrent->GetSharedData().needSurface)
787                 {
788                         return true;
789                 }
790
791                 pCurrent = pCurrent->__pParent;
792         }
793
794         return false;
795 #else
796         return GetSharedData().needSurface;
797 #endif
798 }
799
800 void
801 _VisualElementImpl::RebuildSurfaces(void)
802 {
803         if (unlikely(!IS_PRESENTATION(this)) || unlikely(!IS_ATTACHED(this)))
804         {
805                 return;
806         }
807
808         ResetSurfaceIfNeeded();
809
810         int count = __children.GetCount();
811         for (int i = 0; i < count; i++)
812         {
813                 __children.GetChildAt(i)->RebuildSurfaces();
814         }
815 }
816
817 void
818 _VisualElementImpl::ResetSurfaceIfNeeded(void)
819 {
820         if (unlikely(!__needRecreateSurface))
821         {
822                 return;
823         }
824
825         __needRecreateSurface = false;
826
827         if (unlikely(HAVE_SURFACE(this)) && unlikely(GetSharedData().fixedSurfaceSize))
828         {
829                 return;
830         }
831
832
833         _VisualElementImpl* pPresentation = null;
834
835         if (likely(__pPresentation))
836         {
837                 pPresentation = __pPresentation;
838         }
839         else
840         {
841                 pPresentation = this;
842         }
843
844         if (likely(IsSurfaceNeeded()))
845         {
846                 if (GetRoot())
847                 {
848                         _RootVisualElement* pRoot = dynamic_cast<_RootVisualElement*>(GetRoot()->GetPublic());
849
850                         if (pRoot && pRoot->GetNativeLayer())
851                         {
852                                 GetSharedData().fixedSurfaceSize = false;
853
854                                 float surfaceWidth = __bounds.width;
855                                 float surfaceHeight = __bounds.height;
856
857                                 if (likely(GetSharedData().CreateSurface(FloatDimension(surfaceWidth, surfaceHeight), *pRoot->GetNativeLayer()) == E_SUCCESS))
858                                 {
859                                         if (unlikely(!HAVE_SURFACE(this)))
860                                         {
861                                                 pPresentation->InvalidateVisibleRectToRenderTarget(null);
862                                         }
863
864                                         SetSurfaceChanged();
865                                 }
866                         }
867                 }
868         }
869         else // surface not needed, so remove Surface
870         {
871                 if (unlikely(HAVE_SURFACE(this)))
872                 {
873                         GetSharedData().RemoveSurface(*pPresentation);
874                         SetSurfaceChanged();
875                 }
876         }
877 }
878
879 _VisualElementImpl*
880 _VisualElementImpl::GetRenderTarget(void) const
881 {
882         _VisualElementImpl* pRenderTarget = const_cast< _VisualElementImpl* >(this);
883
884         while (likely(pRenderTarget))
885         {
886                 if (likely(NEED_SURFACE(pRenderTarget)))
887                 {
888                         return pRenderTarget;
889                 }
890
891                 pRenderTarget = pRenderTarget->__pParent;
892         }
893
894         return null;
895 }
896
897 VisualElementSurface*
898 _VisualElementImpl::GetSurfaceN(void) const
899 {
900         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
901         pThis->RebuildHierarchyProps(0, true, true);
902
903         SysTryReturn(NID_UI_ANIM, pThis->IsSurfaceNeeded() && HAVE_SURFACE(pThis), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Realizing back-buffer surface failed.");
904
905         VisualElementSurface* pSurface = new (std::nothrow) VisualElementSurface(*pThis->GetSharedData().pSurface);
906         SysTryReturn(NID_UI_ANIM, pSurface, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
907
908         ClearLastResult();
909
910         return pSurface;
911 }
912
913 result
914 _VisualElementImpl::SetSurface(const VisualElementSurface* pSurface)
915 {
916         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
917         SysTryReturnResult(NID_UI_ANIM, NEED_SURFACE(this), E_INVALID_OPERATION, "A surface cannot be set if VisualElement need no back-buffer.");
918
919         if (unlikely(pSurface == GetSharedData().pSurface))
920         {
921                 return E_SUCCESS;
922         }
923
924         if (likely(pSurface) && likely(GetSharedData().pSurface))
925         {
926                 if (unlikely(pSurface->Equals(*GetSharedData().pSurface)))
927                         return E_SUCCESS;
928         }
929
930         if (likely(pSurface))
931         {
932                 unique_ptr<VisualElementSurface> pTempSurface(new (std::nothrow) VisualElementSurface(*pSurface));
933                 SysTryReturnResult(NID_UI_ANIM, pTempSurface, E_OUT_OF_MEMORY, "Memory allocation failed.");
934
935                 // Delete the old surface
936                 if (GetSharedData().pSurface)
937                 {
938                         delete GetSharedData().pSurface;
939                 }
940
941                 GetSharedData().pSurface = pTempSurface.release();
942                 GetSharedData().fixedSurfaceSize = true;
943
944                 // Clear invalidated region if newly fixed-size surface is attached which do not need(inhibit) redrawing
945                 GetSharedData().invalidatedRegion.SetBounds(0.0f, 0.0f, __bounds.width, __bounds.height);
946         }
947         else
948         {
949                 // Delete the old surface
950                 if (GetSharedData().pSurface)
951                 {
952                         delete GetSharedData().pSurface;
953                 }
954
955                 __needRecreateSurface = true;
956
957                 GetSharedData().pSurface = null;
958                 GetSharedData().fixedSurfaceSize = false;
959
960                 // Fully invalidate because new surface should be allocated and redrawn
961                 GetSharedData().invalidatedRegion.SetBounds(0.0f, 0.0f, __bounds.width, __bounds.height);
962         }
963
964
965         SetSurfaceChanged();
966
967         return E_SUCCESS;
968 }
969
970 result
971 _VisualElementImpl::SetImageSource(const String& filePath)
972 {
973         result r = E_SUCCESS;
974
975         // Delete the old surface
976         if (GetSharedData().pSurface)
977         {
978                 delete GetSharedData().pSurface;
979         }
980
981         __needRecreateSurface = true;
982
983         GetSharedData().pSurface = null;
984         GetSharedData().fixedSurfaceSize = false;
985
986         // Fully invalidate because new surface should be allocated and redrawn
987         GetSharedData().invalidatedRegion.SetBounds(0.0f, 0.0f, __bounds.width, __bounds.height);
988
989
990         RebuildHierarchyProps(0, true, true);
991
992         SysTryReturnResult(NID_UI_ANIM, HAVE_SURFACE(this), E_SYSTEM, "Realizing back-buffer surface failed.");
993
994         if (!filePath.IsEmpty())
995         {
996                 r = GetSharedData().SetImage(filePath);
997                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
998         }
999
1000         __imageFilePath = filePath;
1001
1002         return r;
1003 }
1004
1005 void
1006 _VisualElementImpl::SetSurfaceChanged(void)
1007 {
1008         GetSharedData().surfaceChanged = true;
1009
1010         if (likely(!IS_PRESENTATION(this)))
1011         {
1012                 if(__pPresentation)
1013                 {
1014                         _VisualElementImpl* pElement = __pPresentation;
1015                         while (pElement)
1016                         {
1017                                 pElement->GetSharedData().childrenSurfaceChanged = true;
1018                                 pElement = pElement->__pParent;
1019                         }
1020                 }
1021         }
1022         else
1023         {
1024                 _VisualElementImpl* pElement = this;
1025                 while (pElement)
1026                 {
1027                         pElement->GetSharedData().childrenSurfaceChanged = true;
1028                         pElement = pElement->__pParent;
1029                 }
1030         }
1031 }
1032
1033 result
1034 _VisualElementImpl::SetContentBoundsI(const FloatRectangle& contentBounds)
1035 {
1036 //      const Dimension& surfaceSize = GetSharedData().pSurface->GetSize();
1037 //      SysTryReturn(NID_UI_ANIM,
1038 //              contentBounds.x >= 0 && contentBounds.y >= 0 && contentBounds.width >= 0 && contentBounds.height >= 0 &&
1039 //                      contentBounds.x + contentBounds.width <= surfaceSize.width && contentBounds.y + contentBounds.height <= surfaceSize.height,
1040 //              E_INVALID_ARG,
1041 //              E_INVALID_ARG,
1042 //              "[E_INVALID_ARG] Invalid content bounds.(%f,%f,%f,%f)", contentBounds.x, contentBounds.y, contentBounds.width, contentBounds.height
1043 //      );
1044
1045         if (unlikely(RectUtilIsEqual(__contentBounds, contentBounds)))
1046                 return E_SUCCESS;
1047
1048         SysTryReturnResult(NID_UI_ANIM, contentBounds.width > 0.0f && contentBounds.height > 0.0f, E_INVALID_ARG, "Invalid argument(s) is used. The size of contents bounds must be greater than or equal to 0.0f.");
1049
1050         __contentBounds = contentBounds;
1051         __useContentBounds = (__contentBounds.x != 0.0f || __contentBounds.y != 0.0f || __contentBounds.width != 1.0f || __contentBounds.height != 1.0f);
1052
1053         InvalidateHierarchyProps(HIERARCHY_PROPERTY_CONTENTBOUNDS, false, false);
1054
1055         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1056         {
1057                 FloatRectangle currentValue = __pPresentation->__contentBounds;
1058
1059                 if(CreateImplicitAnimationIfNeeded(*pVePropContentBounds,       __contentBounds, currentValue, NULL) == false)
1060                 {
1061                         __pPresentation->SetContentBoundsProperty(__contentBounds);
1062                 }
1063         }
1064
1065         return E_SUCCESS;
1066 }
1067
1068 result
1069 _VisualElementImpl::SetContentBounds(const FloatRectangle& contentBounds)
1070 {
1071         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1072         result r = InvokeOnSetPropertyRequested(*pVePropContentBounds, Variant(contentBounds));
1073         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1074
1075         return r;
1076 }
1077
1078 FloatRectangle
1079 _VisualElementImpl::GetContentBounds(void) const
1080 {
1081         ClearLastResult();
1082
1083         return __contentBounds;
1084 }
1085
1086 Variant
1087 _VisualElementImpl::GetContentBoundsProperty(void) const
1088 {
1089         ClearLastResult();
1090
1091         return Variant(__contentBounds);
1092 }
1093
1094 result
1095 _VisualElementImpl::SetContentBoundsProperty(const Variant& v)
1096 {
1097         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_RECTANGLE, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1098
1099         return SetContentBoundsI(v.ToFloatRectangle());
1100 }
1101
1102
1103 bool
1104 _VisualElementImpl::GetImplicitAnimationEnabled(void) const
1105 {
1106         ClearLastResult();
1107
1108         return __isImplicitAnimationEnabled;
1109 }
1110
1111 result
1112 _VisualElementImpl::SetImplicitAnimationEnabled(bool enable)
1113 {
1114         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1115         result r = InvokeOnSetPropertyRequested(*pVePropImplicitAnimationEnabled, Variant(enable));
1116         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1117
1118         return r;
1119 }
1120
1121 Variant
1122 _VisualElementImpl::GetImplicitAnimationProperty(void) const
1123 {
1124         ClearLastResult();
1125
1126         return Variant(__isImplicitAnimationEnabled);
1127 }
1128
1129 result
1130 _VisualElementImpl::SetImplicitAnimationProperty(const Variant& v)
1131 {
1132         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1133
1134         bool isImplicitAnimationEnabled = v.ToBool();
1135         if (isImplicitAnimationEnabled != __isImplicitAnimationEnabled)
1136         {
1137                 __isImplicitAnimationEnabled = isImplicitAnimationEnabled;
1138         }
1139         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1140         {
1141                 __pPresentation->SetImplicitAnimationProperty(__isImplicitAnimationEnabled);
1142         }
1143
1144         return E_SUCCESS;
1145 }
1146
1147 FloatRectangle
1148 _VisualElementImpl::GetBoundingBox(void) const
1149 {
1150         ClearLastResult();
1151
1152         return GetBoundingBoxI();
1153 }
1154
1155 FloatRectangle
1156 _VisualElementImpl::GetBounds(void) const
1157 {
1158         ClearLastResult();
1159
1160         return __bounds;
1161 }
1162
1163 result
1164 _VisualElementImpl::SetBoundsI(const FloatRectangle& bounds)
1165 {
1166         _Rectanglef boundsAdjusted(bounds);
1167         FloatRectangle oldValue(__bounds);
1168
1169         result r =  E_SUCCESS;
1170         bool sizeChanged = false;
1171
1172         if (unlikely(GetSharedData().pEventListener != null))
1173         {
1174                 if (IS_MODEL(this))     // CHECKME: checking need??
1175                 {
1176                         FloatRectangle tmpBounds(bounds);
1177                         r = VE_DELEGATE(this, InvokeOnBoundsChanging, tmpBounds);
1178
1179                         boundsAdjusted = tmpBounds;
1180                 }
1181         }
1182
1183         if (likely(boundsAdjusted != __bounds))
1184         {
1185                 float newWidth = boundsAdjusted.Width();
1186                 if (unlikely(newWidth < 0.0f))
1187                 {
1188                         newWidth = 0.0f;
1189                 }
1190
1191                 float newHeight = boundsAdjusted.Height();
1192                 if (unlikely(newHeight < 0.0f))
1193                 {
1194                         newHeight = 0.0f;
1195                 }
1196
1197                 if (unlikely(newWidth != __bounds.width) || unlikely(newHeight != __bounds.height))
1198                 {
1199                         sizeChanged = true;
1200
1201                         // WARNING:
1202                         //      Adjust logical bounds(size) to sync. with that of surface(physical)
1203
1204                         float alignedWidth = newWidth;
1205                         float alignedHeight = newHeight;
1206
1207                         __needRecreateSurface = true;
1208
1209                         _VisualElementCoordinateSystem::ConvertDimensionToPhysicalIntegral(alignedWidth, alignedHeight);
1210
1211                         if (likely(GetSharedData().pSurface))
1212                         {
1213                                 FloatDimension surfaceSize(GetSharedData().pSurface->GetSizeF());
1214
1215                                 _VisualElementCoordinateSystem::ConvertDimensionToPhysicalIntegral(surfaceSize.width, surfaceSize.height);
1216                                 if (likely(alignedWidth == surfaceSize.width) && likely(alignedHeight == surfaceSize.height))
1217                                 {
1218                                         __needRecreateSurface = false;
1219                                 }
1220                         }
1221
1222                         _VisualElementCoordinateSystem::ConvertDimensionToLogical(alignedWidth, alignedHeight);
1223
1224                         if (newWidth > 0.0f && alignedWidth == 0.0f)
1225                         {
1226                                 _VisualElementCoordinateSystem::MakeLogicalWidthForPhysicalOne(alignedWidth);
1227                         }
1228
1229                         if (newHeight > 0.0f && alignedHeight == 0.0f)
1230                         {
1231                                 _VisualElementCoordinateSystem::MakeLogicalHeightForPhysicalOne(alignedHeight);
1232                         }
1233
1234                         __alignedSize.width = alignedWidth;
1235                         __alignedSize.height = alignedHeight;
1236                 }
1237
1238                 // TODO: Need to optimize dirty rectangle.
1239
1240                 // invalidate with previous bounds
1241                 if (unlikely(!NEED_SURFACE(this)))
1242                         InvalidateVisibleRectToRenderTarget(null);
1243
1244                 __bounds.x = boundsAdjusted.Left();
1245                 __bounds.y = boundsAdjusted.Top();
1246                 __bounds.width = newWidth;
1247                 __bounds.height = newHeight;
1248
1249                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
1250
1251                 // TBD: Recreating surface may have to be done in presentation layer (thread!)
1252
1253                 // WARNING:
1254                 //      Even when 'no redrawOnResize', it is needed to invalidate for redrawing if surface is not created yet.
1255                 //
1256                 if (unlikely(sizeChanged))
1257                 {
1258                         if (unlikely(!NEED_SURFACE(this)) || unlikely(GetSharedData().redrawOnResize))
1259                                 ExposeRectangle(null, true);
1260
1261                         // WARNING:
1262                         //      Shrink invalidated region to bounds
1263                         RectUtilIntersect(GetSharedData().invalidatedRegion, FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height));
1264                 }
1265                 else
1266                 {
1267                         if (unlikely(!NEED_SURFACE(this)))
1268                                 ExposeRectangle(null, true);
1269                 }
1270         }
1271
1272         // observer
1273         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1274         {
1275                 FloatRectangle currentValue = __pPresentation->__bounds;
1276
1277                 static const String* subProperties[] = {        pVeSubPropBoundsSize, pVeSubPropBoundsPosition, NULL };
1278                 if(CreateImplicitAnimationIfNeeded(*pVePropBounds,      __bounds, currentValue, subProperties ) == false)
1279                 {
1280                         __pPresentation->SetBoundsProperty(__bounds);
1281                 }
1282
1283                 VE_DELEGATE(this, InvokeOnBoundsChanged, oldValue);
1284
1285                 if(__pBoundsChangedCallback && sizeChanged == true)
1286                 {
1287                         (*__pBoundsChangedCallback)(__pBoundsChangedCallbackData);
1288                 }
1289
1290         }
1291
1292         return r;
1293 }
1294
1295
1296 result
1297 _VisualElementImpl::SetBounds(const FloatRectangle& bounds)
1298 {
1299         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1300         result r = E_SUCCESS;
1301
1302         if (IS_INTERNAL_CLASS(__pPublicInstance))
1303         {
1304                 r = SetBoundsI(bounds);
1305         }
1306         else
1307         {
1308                 r = InvokeOnSetPropertyRequested(*pVePropBounds, Variant(bounds));
1309         }
1310         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1311
1312         return r;
1313 }
1314
1315 Variant
1316 _VisualElementImpl::GetBoundsProperty(void) const
1317 {
1318         ClearLastResult();
1319
1320         return Variant(__bounds);
1321 }
1322
1323 result
1324 _VisualElementImpl::SetBoundsProperty(const Variant& v)
1325 {
1326         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_RECTANGLE, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1327
1328         return SetBoundsI(v.ToFloatRectangle());
1329 }
1330
1331 Variant
1332 _VisualElementImpl::GetBoundsPositionSubProperty(void) const
1333 {
1334         ClearLastResult();
1335
1336         return Variant(__bounds.GetTopLeft());
1337 }
1338
1339 result
1340 _VisualElementImpl::SetBoundsPositionSubProperty(const Variant& v)
1341 {
1342         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1343
1344         const FloatPoint& position = v.ToFloatPoint();
1345         return SetBoundsProperty(Variant(FloatRectangle(position.x, position.y, __bounds.width, __bounds.height)));
1346 }
1347
1348 Variant
1349 _VisualElementImpl::GetBoundsSizeSubProperty(void) const
1350 {
1351         ClearLastResult();
1352
1353         return Variant(FloatDimension(__bounds.width, __bounds.height));
1354 }
1355
1356 result
1357 _VisualElementImpl::SetBoundsSizeSubProperty(const Variant& v)
1358 {
1359         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_DIMENSION, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1360
1361         const FloatDimension& size = v.ToFloatDimension();
1362         return SetBoundsProperty(Variant(FloatRectangle(__bounds.x, __bounds.y, size.width, size.height)));
1363 }
1364
1365 float
1366 _VisualElementImpl::GetZPosition(void) const
1367 {
1368         ClearLastResult();
1369
1370         return __zPosition;
1371 }
1372
1373 result
1374 _VisualElementImpl::SetZPositionI(float zPosition)
1375 {
1376         if (likely(zPosition != __zPosition))
1377         {
1378                 __zPosition = zPosition;
1379                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false); // lazy evaluation: property changed flag
1380         }
1381
1382         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1383         {
1384                 float currentValue = __pPresentation->__zPosition;
1385
1386                 if(CreateImplicitAnimationIfNeeded(*pVePropZPosition, __zPosition, currentValue, NULL) == false)
1387                 {
1388                         __pPresentation->SetZPositionProperty(__zPosition);
1389                 }
1390         }
1391
1392         return E_SUCCESS;
1393 }
1394
1395
1396 result
1397 _VisualElementImpl::SetZPosition(float zPosition)
1398 {
1399         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1400         result r = E_SUCCESS;
1401
1402         if (IS_INTERNAL_CLASS(__pPublicInstance))
1403         {
1404                 r = SetZPositionI(zPosition);
1405         }
1406         else
1407         {
1408                 r = InvokeOnSetPropertyRequested(*pVePropZPosition, Variant(zPosition));
1409         }
1410
1411         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1412
1413         return r;
1414 }
1415
1416
1417
1418 Variant
1419 _VisualElementImpl::GetZPositionProperty(void) const
1420 {
1421         ClearLastResult();
1422
1423         return Variant(__zPosition);
1424 }
1425
1426 result
1427 _VisualElementImpl::SetZPositionProperty(const Variant& v)
1428 {
1429         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1430
1431         return SetZPositionI(v.ToFloat());
1432 }
1433
1434 result
1435 _VisualElementImpl::SetZOrderGroupI(int zOrderGroup)
1436 {
1437         result r = E_SUCCESS;
1438
1439         if (likely(__pParent))
1440         {
1441                 r= __pParent->ChangeZOrder(*this, null, true, zOrderGroup);
1442         }
1443         else
1444         {
1445                 _zOrderGroup = zOrderGroup;
1446         }
1447
1448         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1449         {
1450                 __pPresentation->SetZOrderGroupProperty(_zOrderGroup);
1451         }
1452         return r;
1453 }
1454
1455 result
1456 _VisualElementImpl::SetZOrderGroup(int zOrderGroup)
1457 {
1458         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1459         result r = E_SUCCESS;
1460
1461         if (IS_INTERNAL_CLASS(__pPublicInstance))
1462         {
1463                 r = SetZOrderGroupI(zOrderGroup);
1464         }
1465         else
1466         {
1467                 r = InvokeOnSetPropertyRequested(*pVePropZOrderGroup, Variant(zOrderGroup));
1468         }
1469
1470         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1471
1472         return r;
1473 }
1474
1475 int
1476 _VisualElementImpl::GetZOrderGroup(void) const
1477 {
1478         ClearLastResult();
1479
1480         return _zOrderGroup;
1481 }
1482
1483 Variant
1484 _VisualElementImpl::GetZOrderGroupProperty(void) const
1485 {
1486         ClearLastResult();
1487
1488         return Variant(_zOrderGroup);
1489 }
1490
1491 result
1492 _VisualElementImpl::SetZOrderGroupProperty(const Variant& v)
1493 {
1494         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_INT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1495
1496         return SetZOrderGroupI(v.ToInt());
1497 }
1498
1499 bool
1500 _VisualElementImpl::IsVisible(void) const
1501 {
1502         ClearLastResult();
1503
1504         return IsVisibleI();
1505 }
1506
1507 bool
1508 _VisualElementImpl::GetShowState(void) const
1509 {
1510         ClearLastResult();
1511
1512         return VE_VISIBLE(this);
1513 }
1514
1515 result
1516 _VisualElementImpl::SetShowOpacityI(float showOpacity)
1517 {
1518         bool oldShowState = SHOWOPACITY_VISIBLE(__showOpacity);
1519
1520         if (unlikely(showOpacity < 0.0f))
1521         {
1522                 showOpacity = 0.0f;
1523         }
1524         else if (unlikely(showOpacity > 1.0f))
1525         {
1526                 showOpacity = 1.0f;
1527         }
1528
1529         if (likely(__showOpacity != showOpacity))
1530         {
1531
1532                 bool showStateChanged = (oldShowState != SHOWOPACITY_VISIBLE(showOpacity));
1533
1534                 __showOpacity = showOpacity;
1535
1536                 if (likely(showStateChanged))
1537                 {
1538                         if (!oldShowState)
1539                         {
1540                                 // WARNING:
1541                                 //      Coordinates are calculated using visibleRect which is empty when invisible state.
1542                                 //      Show-Recalculation is needed when being visible !
1543                                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES | HIERARCHY_PROPERTY_SHOWSTATE | HIERARCHY_PROPERTY_OPACITY, true, false);
1544
1545                                 if (unlikely(!NEED_SURFACE(this)))
1546                                 {
1547                                         ExposeRectangle(null, true);
1548                                 }
1549                         }
1550                         else
1551                         {
1552                                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_SHOWSTATE | HIERARCHY_PROPERTY_OPACITY, true, false);
1553
1554                                 if (unlikely(!NEED_SURFACE(this)))
1555                                 {
1556                                         InvalidateVisibleRectToRenderTarget(null);
1557                                 }
1558                         }
1559                 }
1560                 else
1561                 {
1562                         // WARNING:
1563                         //      showOpacity is applicable only for surfaces
1564                         if (likely(NEED_SURFACE(this)))
1565                         {
1566                                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_OPACITY, true, false);
1567                         }
1568                 }
1569         }
1570         //Observer
1571         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1572         {
1573                 bool needPresentationUpdate = true;
1574                 const String& property = *pVePropShowState;
1575                 _AnimationManager* pAnimationManager = _AnimationManager::GetInstance();
1576
1577                         if (likely(GetRoot()) && (unlikely(pAnimationManager->IsImplicitAnimationEnabled() && __isImplicitAnimationEnabled)))
1578                         {
1579                                 // WARNING:
1580                                                 //      For performance, following must be done only when oldValue != newValue.
1581                                 VisualElementAnimation* pAnimation = InvokeCreateAnimationForProperty(property);
1582                                 VisualElementPropertyAnimation* pPropertyAnimation = NULL;
1583                                 if(!pAnimation)
1584                                 {
1585                                         pPropertyAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1586                                         if(pPropertyAnimation)
1587                                         {
1588                                                 pPropertyAnimation->SetPropertyName(*pVePrivPropShowOpacity);
1589                                                 needPresentationUpdate = true;
1590                                         }
1591                                 }
1592                                 else
1593                                 {
1594                                         pPropertyAnimation = dynamic_cast< VisualElementPropertyAnimation* >(pAnimation);
1595                                 }
1596
1597                                 if (likely(pPropertyAnimation))
1598                                 {
1599                                         if (pPropertyAnimation->GetEndValue().IsEmpty())
1600                                         {
1601                                                 pPropertyAnimation->SetEndValue(__showOpacity);
1602                                         }
1603
1604                                         if (pPropertyAnimation->GetStartValue().IsEmpty())
1605                                         {
1606                                                 pPropertyAnimation->SetStartValue(__pPresentation->__showOpacity);
1607                                         }
1608                                 }
1609
1610                                 if (unlikely(pPropertyAnimation))
1611                                 {
1612                                         /// WARNING:
1613                                         //      Adding property animation causes previous animation for same property to be removed in Animation Manager.
1614                                         if (unlikely(IsFailed(AddAnimation(null, *pPropertyAnimation))))
1615                                         {
1616                                                 needPresentationUpdate = true;
1617                                                 //pAnimationManager->RemoveAnimationByProperty(*presentation.GetPublic(), property);
1618                                         }
1619
1620                                         delete pPropertyAnimation;
1621                                 }
1622                                 else
1623                                 {
1624                                         // WARNING:
1625                                         //      Remove previous animation even when trying to change the property without animation.
1626                                         pAnimationManager->RemoveAnimationByProperty(*__pPresentation->__pPublicInstance, property);
1627                                         pAnimationManager->RemoveAnimationByProperty(*__pPresentation->__pPublicInstance, *pVePrivPropShowOpacity);
1628                                         needPresentationUpdate = true;
1629                                 }
1630                         }
1631                         else
1632                         {
1633                                 pAnimationManager->RemoveAnimationByProperty(*__pPresentation->__pPublicInstance, property);
1634                                 pAnimationManager->RemoveAnimationByProperty(*__pPresentation->__pPublicInstance, *pVePrivPropShowOpacity);
1635                                 needPresentationUpdate = true;
1636
1637                         }
1638                         if(needPresentationUpdate)
1639                         {
1640                                 __pPresentation->SetShowStateProperty(SHOWOPACITY_VISIBLE(__showOpacity));
1641                         }
1642                         InvokeOnShowStateChanged(oldShowState);
1643
1644         }
1645
1646         return E_SUCCESS;
1647 }
1648
1649 result
1650 _VisualElementImpl::SetShowStateI(bool show)
1651 {
1652         return SetShowOpacityI(show ? 1.0f : 0.0f);
1653 }
1654
1655 result
1656 _VisualElementImpl::SetShowState(bool show)
1657 {
1658         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1659         result r = E_SUCCESS;
1660
1661         if (IS_INTERNAL_CLASS(__pPublicInstance))
1662         {
1663                 r = SetShowOpacityI(show ? 1.0f : 0.0f);
1664         }
1665         else
1666         {
1667                 r = InvokeOnSetPropertyRequested(*pVePropShowState, Variant(show));
1668         }
1669
1670         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1671
1672         return r;
1673 }
1674
1675 Variant
1676 _VisualElementImpl::GetShowStateProperty(void) const
1677 {
1678         ClearLastResult();
1679
1680         return Variant(VE_VISIBLE(this));
1681 }
1682
1683 result
1684 _VisualElementImpl::SetShowStateProperty(const Variant& v)
1685 {
1686         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1687
1688         bool showState = v.ToBool();
1689
1690         return SetShowOpacityI(showState ? 1.0f : 0.0f);
1691 }
1692
1693 Variant
1694 _VisualElementImpl::GetShowOpacityPrivateProperty(void) const
1695 {
1696         ClearLastResult();
1697
1698         return Variant(__showOpacity);
1699 }
1700
1701 result
1702 _VisualElementImpl::SetShowOpacityPrivateProperty(const Variant& v)
1703 {
1704         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1705
1706         return SetShowOpacityI(v.ToFloat());
1707 }
1708
1709 float
1710 _VisualElementImpl::GetContentOpacity(void) const
1711 {
1712         ClearLastResult();
1713
1714         return __contentOpacity;
1715 }
1716
1717 result
1718 _VisualElementImpl::SetContentOpacityI(float contentOpacity)
1719 {
1720         if (unlikely(contentOpacity == __contentOpacity))       // do not take care of float-error !!
1721         {
1722                 return E_SUCCESS;
1723         }
1724
1725         SysTryReturnResult(NID_UI_ANIM, contentOpacity >= 0.0f && contentOpacity <= 1.0f, E_INVALID_ARG, "Invalid argument(s) is used. Invalid opacity range.");
1726
1727         __contentOpacity = contentOpacity;
1728
1729         InvalidateHierarchyProps(HIERARCHY_PROPERTY_CONTENTOPACITY, false, false); //don't have to apply the changed opacity to children.
1730
1731 #ifndef LAZY_EVALUATION
1732         if (IS_PRESENTATION(this) && likely(__pSharedData) && likely(GetSharedData().pNativeNode))
1733         {
1734                 GetSharedData().NodeReconfigure(*this);
1735         }
1736 #endif
1737
1738         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1739         {
1740                 float currentValue = __pPresentation->__contentOpacity;
1741
1742                 if(CreateImplicitAnimationIfNeeded(*pVePropContentOpacity,      __contentOpacity, currentValue, NULL) == false)
1743                 {
1744                         __pPresentation->SetContentOpacityProperty(__contentOpacity);
1745                 }
1746         }
1747         return E_SUCCESS;
1748 }
1749
1750
1751 result
1752 _VisualElementImpl::SetContentOpacity(float contentOpacity)
1753 {
1754         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1755         result r = E_SUCCESS;
1756
1757 //      PROPERTY_PROCESS(SetContentOpacityI, GetContentOpacityProperty, SetContentOpacityProperty, pVePropContentOpacity, __contentOpacity, contentOpacity);
1758         if (IS_INTERNAL_CLASS(__pPublicInstance))
1759         {
1760                 r = SetContentOpacityI(contentOpacity);
1761         }
1762         else
1763         {
1764                 r = InvokeOnSetPropertyRequested(*pVePropContentOpacity, Variant(contentOpacity));
1765         }
1766
1767         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1768
1769         return r;
1770 }
1771
1772
1773 Variant
1774 _VisualElementImpl::GetContentOpacityProperty(void) const
1775 {
1776         ClearLastResult();
1777
1778         return Variant(__contentOpacity);
1779 }
1780
1781 result
1782 _VisualElementImpl::SetContentOpacityProperty(const Variant& v)
1783 {
1784         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1785
1786         return SetContentOpacityI(v.ToFloat());
1787 }
1788
1789 float
1790 _VisualElementImpl::GetOpacity(void) const
1791 {
1792         ClearLastResult();
1793
1794         return __opacity;
1795 }
1796
1797 result
1798 _VisualElementImpl::SetOpacityI(float opacity)
1799 {
1800         if (likely(opacity != __opacity))       // do not take care of float-error !!
1801         {
1802                 if (unlikely(opacity > 1.0f))
1803                 {
1804                         opacity = 1.0f;
1805                 }
1806                 else if (unlikely(opacity < 0.0f))
1807                 {
1808                         opacity = 0.0f;
1809                 }
1810
1811                 __opacity = opacity;
1812
1813                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_OPACITY, true, false);
1814         }
1815
1816         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1817         {
1818                 float currentValue = __pPresentation->__opacity;
1819
1820                 if(CreateImplicitAnimationIfNeeded(*pVePropOpacity,     __opacity, currentValue, NULL) == false)
1821                 {
1822                         __pPresentation->SetOpacityProperty(__opacity);
1823                 }
1824         }
1825         return E_SUCCESS;
1826 }
1827
1828 result
1829 _VisualElementImpl::SetOpacity(float opacity)
1830 {
1831         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1832         result r = E_SUCCESS;
1833
1834 //      PROPERTY_PROCESS(SetOpacityI, GetOpacityProperty, SetOpacityProperty, pVePropOpacity, __opacity, opacity);
1835         if (IS_INTERNAL_CLASS(__pPublicInstance))
1836         {
1837                 r = SetOpacityI(opacity);
1838         }
1839         else
1840         {
1841                 r = InvokeOnSetPropertyRequested(*pVePropOpacity, Variant(opacity));
1842         }
1843
1844         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1845
1846         return r;
1847 }
1848
1849 Variant
1850 _VisualElementImpl::GetOpacityProperty(void) const
1851 {
1852         ClearLastResult();
1853
1854         return Variant(__opacity);
1855 }
1856
1857 result
1858 _VisualElementImpl::SetOpacityProperty(const Variant& v)
1859 {
1860         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1861
1862         return SetOpacityI(v.ToFloat());
1863 }
1864
1865 FloatPoint
1866 _VisualElementImpl::GetAnchor(void) const
1867 {
1868         ClearLastResult();
1869
1870         return __anchor;
1871 }
1872
1873 result
1874 _VisualElementImpl::SetAnchorI(const FloatPoint& anchor)
1875 {
1876         if (likely(anchor != __anchor))
1877         {
1878
1879                 __anchor = anchor;
1880
1881                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
1882
1883                 // VE with surface will be exposed automatically on rebuilding coordinates...
1884                 if (unlikely(!HAVE_SURFACE(this)))
1885                 {
1886                         ExposeRectangle(null, true);    // CHECKME: needed ???
1887                 }
1888         }
1889
1890         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1891         {
1892                 FloatPoint currentValue = __pPresentation->__anchor;
1893
1894                 if(CreateImplicitAnimationIfNeeded(*pVePropAnchor,      __anchor, currentValue, NULL) == false)
1895                 {
1896                         __pPresentation->SetAnchorProperty(__anchor);
1897                 }
1898         }
1899         return E_SUCCESS;
1900 }
1901
1902
1903 result
1904 _VisualElementImpl::SetAnchor(const FloatPoint& anchor)
1905 {
1906         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1907         result r = E_SUCCESS;
1908
1909 //      PROPERTY_PROCESS(SetAnchorI, GetAnchorProperty, SetAnchorProperty, pVePropAnchor, __anchor, anchor);
1910         if (IS_INTERNAL_CLASS(__pPublicInstance))
1911         {
1912                 r = SetAnchorI(anchor);
1913         }
1914         else
1915         {
1916                 r = InvokeOnSetPropertyRequested(*pVePropAnchor, Variant(anchor));
1917         }
1918
1919         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1920
1921         return r;
1922 }
1923
1924
1925 Variant
1926 _VisualElementImpl::GetAnchorProperty(void) const
1927 {
1928         ClearLastResult();
1929
1930         return Variant(__anchor);
1931 }
1932
1933 result
1934 _VisualElementImpl::SetAnchorProperty(const Variant& v)
1935 {
1936         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1937
1938         return SetAnchorI(v.ToFloatPoint());
1939 }
1940
1941 float
1942 _VisualElementImpl::GetAnchorZ(void) const
1943 {
1944         ClearLastResult();
1945
1946         return __anchorZ;
1947 }
1948
1949 result
1950 _VisualElementImpl::SetAnchorZI(float anchorZ)
1951 {
1952         if (likely(anchorZ != __anchorZ))
1953         {
1954                 __anchorZ = anchorZ;
1955
1956                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
1957
1958                 // VE with surface will be exposed automatically on rebuilding coordinates...
1959                 if (unlikely(!HAVE_SURFACE(this)))
1960                 {
1961                         ExposeRectangle(null, true);    // CHECKME: needed ???
1962                 }
1963         }
1964
1965         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1966         {
1967                 float currentValue = __pPresentation->__anchorZ;
1968
1969                 if(CreateImplicitAnimationIfNeeded(*pVePropAnchorZ,     __anchorZ, currentValue, NULL) == false)
1970                 {
1971                         __pPresentation->SetAnchorZProperty(__anchorZ);
1972                 }
1973         }
1974         return E_SUCCESS;
1975 }
1976
1977
1978 result
1979 _VisualElementImpl::SetAnchorZ(float anchorZ)
1980 {
1981         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1982         result r = E_SUCCESS;
1983
1984 //      PROPERTY_PROCESS(SetAnchorZI, GetAnchorZProperty, SetAnchorZProperty, pVePropAnchorZ, __anchorZ, anchorZ);
1985         if (IS_INTERNAL_CLASS(__pPublicInstance))
1986         {
1987                 r = SetAnchorZI(anchorZ);
1988         }
1989         else
1990         {
1991                 r = InvokeOnSetPropertyRequested(*pVePropAnchorZ, Variant(anchorZ));
1992         }
1993
1994         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1995
1996         return r;
1997 }
1998
1999
2000
2001 Variant
2002 _VisualElementImpl::GetAnchorZProperty(void) const
2003 {
2004         ClearLastResult();
2005
2006         return Variant(__anchorZ);
2007 }
2008
2009 result
2010 _VisualElementImpl::SetAnchorZProperty(const Variant& v)
2011 {
2012         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2013
2014         return SetAnchorZI(v.ToFloat());
2015 }
2016
2017 FloatMatrix4
2018 _VisualElementImpl::GetTransformMatrix(void) const
2019 {
2020         ClearLastResult();
2021
2022         return __transform;
2023 }
2024
2025 result
2026 _VisualElementImpl::SetTransformMatrixI(const FloatMatrix4& xform, bool updateDecomposed)
2027 {
2028
2029         result r = E_SUCCESS;
2030
2031         FloatMatrix4 oldValue(__transform);
2032
2033         FloatMatrix4 matrixAdjusted(xform);
2034
2035         if (unlikely(GetSharedData().pEventListener != null))
2036         {
2037                 if (IS_MODEL(this))     // CHECKME: checking need??
2038                 {
2039                         r = VE_DELEGATE(this, InvokeOnTransformMatrixChanging, matrixAdjusted);
2040                 }
2041         }
2042
2043         if (r == E_SUCCESS && likely(matrixAdjusted != __transform))    // check again because delegate may change the transform matrix
2044         {
2045                 // render target updates for previous bounds
2046                 if (unlikely(!NEED_SURFACE(this)))
2047                 {
2048                         InvalidateVisibleRectToRenderTarget(null);
2049                 }
2050
2051
2052                 MatrixUtilCopy(__transform, matrixAdjusted);
2053
2054                 if (unlikely(updateDecomposed))
2055                 {
2056                         __decomposedTransform.SetTransformMatrix(__transform);
2057                 }
2058
2059                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
2060
2061                 // VE with surface will be exposed automatically on rebuilding coordinates...
2062                 if (unlikely(!NEED_SURFACE(this)))
2063                 {
2064                         ExposeRectangle(null, true);    // CHECKME: needed ???
2065                 }
2066         }
2067
2068         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
2069         {
2070                 FloatMatrix4 currentValue = __pPresentation->__transform;
2071
2072                 static const String* subProperties[] = {        pVeSubPropTransformRotationX,
2073                                                                                         pVeSubPropTransformRotationY,
2074                                                                                         pVeSubPropTransformRotationZ,
2075                                                                                         pVeSubPropTransformScaleX,
2076                                                                                         pVeSubPropTransformScaleY,
2077                                                                                         pVeSubPropTransformScaleZ,
2078                                                                                         pVeSubPropTransformTranslationX,
2079                                                                                         pVeSubPropTransformTranslationY,
2080                                                                                         pVeSubPropTransformTranslationZ,
2081                                                                                         pVeSubPropTransformRotationAnchorX,
2082                                                                                         pVeSubPropTransformRotationAnchorY,
2083                                                                                         pVeSubPropTransformRotationAnchorZ,
2084                                                                                         pVeSubPropTransformScaleAnchorX,
2085                                                                                         pVeSubPropTransformScaleAnchorY,
2086                                                                                         pVeSubPropTransformScaleAnchorZ,
2087                                                                                         NULL};
2088
2089                 if(CreateImplicitAnimationIfNeeded(*pVePropTransform,   __transform, currentValue, subProperties ) == false)
2090                 {
2091                         __pPresentation->SetTransformMatrixProperty(__transform);
2092                 }
2093
2094                 VE_DELEGATE(this, InvokeOnTransformMatrixChanged, oldValue);
2095         }
2096         return E_SUCCESS;
2097 }
2098
2099 result
2100 _VisualElementImpl::SetTransformMatrix(const FloatMatrix4& xform)
2101 {
2102         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
2103         result r = E_SUCCESS;
2104
2105 //      PROPERTY_PROCESS(SetTransformMatrixI, GetTransformMatrixProperty, SetTransformMatrixProperty, pVePropTransform, __transform, xform);
2106         if (IS_INTERNAL_CLASS(__pPublicInstance))
2107         {
2108                 r = SetTransformMatrixI(xform);
2109         }
2110         else
2111         {
2112                 r = InvokeOnSetPropertyRequested(*pVePropTransform, Variant(xform));
2113         }
2114
2115         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
2116
2117         return r;
2118 }
2119
2120
2121
2122 Variant
2123 _VisualElementImpl::GetTransformMatrixProperty(void) const
2124 {
2125         ClearLastResult();
2126
2127         return Variant(__transform);
2128 }
2129
2130
2131 result
2132 _VisualElementImpl::SetTransformMatrixProperty(const Variant& v)
2133 {
2134         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_MATRIX4, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2135
2136         return SetTransformMatrixI(v.ToFloatMatrix4(), true);
2137 }
2138
2139 Variant
2140 _VisualElementImpl::GetTransformRotationXSubProperty(void) const
2141 {
2142         ClearLastResult();
2143
2144         float angleX = 0.0f;
2145         float angleY = 0.0f;
2146         float angleZ = 0.0f;
2147         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2148
2149         return Variant(angleX);
2150 }
2151
2152 result
2153 _VisualElementImpl::SetTransformRotationXSubProperty(const Variant& v)
2154 {
2155         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2156
2157         float angleX = 0.0f;
2158         float angleY = 0.0f;
2159         float angleZ = 0.0f;
2160         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2161         __decomposedTransform.UpdateRotationFromEulerAngles(v.ToFloat(), angleY, angleZ);
2162
2163         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2164 }
2165
2166 Variant
2167 _VisualElementImpl::GetTransformRotationYSubProperty(void) const
2168 {
2169         ClearLastResult();
2170
2171         float angleX = 0.0f;
2172         float angleY = 0.0f;
2173         float angleZ = 0.0f;
2174         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2175
2176         return Variant(angleY);
2177 }
2178
2179 result
2180 _VisualElementImpl::SetTransformRotationYSubProperty(const Variant& v)
2181 {
2182         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2183
2184         float angleX = 0.0f;
2185         float angleY = 0.0f;
2186         float angleZ = 0.0f;
2187         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2188         __decomposedTransform.UpdateRotationFromEulerAngles(angleX, v.ToFloat(), angleZ);
2189
2190         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2191 }
2192
2193 Variant
2194 _VisualElementImpl::GetTransformRotationZSubProperty(void) const
2195 {
2196         ClearLastResult();
2197
2198         float angleX = 0.0f;
2199         float angleY = 0.0f;
2200         float angleZ = 0.0f;
2201         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2202
2203         return Variant(angleZ);
2204 }
2205
2206 result
2207 _VisualElementImpl::SetTransformRotationZSubProperty(const Variant& v)
2208 {
2209         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2210
2211         float angleX = 0.0f;
2212         float angleY = 0.0f;
2213         float angleZ = 0.0f;
2214         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2215         __decomposedTransform.UpdateRotationFromEulerAngles(angleX, angleY, v.ToFloat());
2216
2217         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2218 }
2219
2220 Variant
2221 _VisualElementImpl::GetTransformRotationXYSubProperty(void) const
2222 {
2223         ClearLastResult();
2224
2225         float angleX = 0.0f;
2226         float angleY = 0.0f;
2227         float angleZ = 0.0f;
2228         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2229
2230         return Variant(FloatPoint(angleX, angleY));
2231 }
2232
2233 result
2234 _VisualElementImpl::SetTransformRotationXYSubProperty(const Variant& v)
2235 {
2236         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2237
2238         const FloatPoint& point = v.ToFloatPoint();
2239
2240         float angleX = 0.0f;
2241         float angleY = 0.0f;
2242         float angleZ = 0.0f;
2243         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2244         __decomposedTransform.UpdateRotationFromEulerAngles(point.x, point.y, angleZ);
2245
2246         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2247 }
2248
2249 Variant
2250 _VisualElementImpl::GetTransformRotationAnchorXSubProperty(void) const
2251 {
2252         ClearLastResult();
2253
2254         float anchorX = 0.0f;
2255         float anchorY = 0.0f;
2256         float anchorZ = 0.0f;
2257         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2258
2259         return Variant(anchorX);
2260 }
2261
2262 result
2263 _VisualElementImpl::SetTransformRotationAnchorXSubProperty(const Variant& v)
2264 {
2265         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2266
2267         float anchorX = 0.0f;
2268         float anchorY = 0.0f;
2269         float anchorZ = 0.0f;
2270         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2271         __decomposedTransform.SetRotationAnchor(v.ToFloat(), anchorY, anchorZ);
2272
2273         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2274 }
2275
2276 Variant
2277 _VisualElementImpl::GetTransformRotationAnchorYSubProperty(void) const
2278 {
2279         ClearLastResult();
2280
2281         float anchorX = 0.0f;
2282         float anchorY = 0.0f;
2283         float anchorZ = 0.0f;
2284         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2285
2286         return Variant(anchorY);
2287 }
2288
2289 result
2290 _VisualElementImpl::SetTransformRotationAnchorYSubProperty(const Variant& v)
2291 {
2292         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2293
2294         float anchorX = 0.0f;
2295         float anchorY = 0.0f;
2296         float anchorZ = 0.0f;
2297         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2298         __decomposedTransform.SetRotationAnchor(anchorX, v.ToFloat(), anchorZ);
2299
2300         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2301 }
2302
2303 Variant
2304 _VisualElementImpl::GetTransformRotationAnchorZSubProperty(void) const
2305 {
2306         ClearLastResult();
2307
2308         float anchorX = 0.0f;
2309         float anchorY = 0.0f;
2310         float anchorZ = 0.0f;
2311         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2312
2313         return Variant(anchorZ);
2314 }
2315
2316 result
2317 _VisualElementImpl::SetTransformRotationAnchorZSubProperty(const Variant& v)
2318 {
2319         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2320
2321         float anchorX = 0.0f;
2322         float anchorY = 0.0f;
2323         float anchorZ = 0.0f;
2324         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2325         __decomposedTransform.SetRotationAnchor(anchorX, anchorY, v.ToFloat());
2326
2327         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2328 }
2329
2330 Variant
2331 _VisualElementImpl::GetTransformRotationAnchorXYSubProperty(void) const
2332 {
2333         ClearLastResult();
2334
2335         float anchorX = 0.0f;
2336         float anchorY = 0.0f;
2337         float anchorZ = 0.0f;
2338         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2339
2340         return Variant(FloatPoint(anchorX, anchorY));
2341 }
2342
2343 result
2344 _VisualElementImpl::SetTransformRotationAnchorXYSubProperty(const Variant& v)
2345 {
2346         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2347
2348         const FloatPoint& point = v.ToFloatPoint();
2349
2350         float anchorX = 0.0f;
2351         float anchorY = 0.0f;
2352         float anchorZ = 0.0f;
2353         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2354         __decomposedTransform.SetRotationAnchor(point.x, point.y, anchorZ);
2355
2356         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2357 }
2358
2359 Variant
2360 _VisualElementImpl::GetTransformScaleXSubProperty(void) const
2361 {
2362         ClearLastResult();
2363
2364         float scaleX = 1.0f;
2365         float scaleY = 1.0f;
2366         float scaleZ = 1.0f;
2367         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2368
2369         return Variant(scaleX);
2370 }
2371
2372 result
2373 _VisualElementImpl::SetTransformScaleXSubProperty(const Variant& v)
2374 {
2375         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2376
2377         float scaleX = 1.0f;
2378         float scaleY = 1.0f;
2379         float scaleZ = 1.0f;
2380         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2381         __decomposedTransform.SetScaleFactors(v.ToFloat(), scaleY, scaleZ);
2382
2383         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2384 }
2385
2386 Variant
2387 _VisualElementImpl::GetTransformScaleYSubProperty(void) const
2388 {
2389         ClearLastResult();
2390
2391         float scaleX = 1.0f;
2392         float scaleY = 1.0f;
2393         float scaleZ = 1.0f;
2394         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2395
2396         return Variant(scaleY);
2397 }
2398
2399 result
2400 _VisualElementImpl::SetTransformScaleYSubProperty(const Variant& v)
2401 {
2402         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2403
2404         float scaleX = 1.0f;
2405         float scaleY = 1.0f;
2406         float scaleZ = 1.0f;
2407         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2408         __decomposedTransform.SetScaleFactors(scaleX, v.ToFloat(), scaleZ);
2409
2410         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2411 }
2412
2413 Variant
2414 _VisualElementImpl::GetTransformScaleZSubProperty(void) const
2415 {
2416         ClearLastResult();
2417
2418         float scaleX = 1.0f;
2419         float scaleY = 1.0f;
2420         float scaleZ = 1.0f;
2421         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2422
2423         return Variant(scaleZ);
2424 }
2425
2426 result
2427 _VisualElementImpl::SetTransformScaleZSubProperty(const Variant& v)
2428 {
2429         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2430
2431         float scaleX = 1.0f;
2432         float scaleY = 1.0f;
2433         float scaleZ = 1.0f;
2434         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2435         __decomposedTransform.SetScaleFactors(scaleX, scaleY, v.ToFloat());
2436
2437         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2438 }
2439
2440 Variant
2441 _VisualElementImpl::GetTransformScaleXYSubProperty(void) const
2442 {
2443         ClearLastResult();
2444
2445         float scaleX = 1.0f;
2446         float scaleY = 1.0f;
2447         float scaleZ = 1.0f;
2448         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2449
2450         return Variant(FloatPoint(scaleX, scaleY));
2451 }
2452
2453 result
2454 _VisualElementImpl::SetTransformScaleXYSubProperty(const Variant& v)
2455 {
2456         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2457
2458         const FloatPoint& point = v.ToFloatPoint();
2459
2460         float scaleX = 1.0f;
2461         float scaleY = 1.0f;
2462         float scaleZ = 1.0f;
2463         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2464         if (unlikely(scaleX == point.x) && unlikely(scaleY == point.y))
2465         {
2466                 return E_SUCCESS;
2467         }
2468
2469         __decomposedTransform.SetScaleFactors(point.x, point.y, scaleZ);
2470
2471         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2472 }
2473
2474 Variant
2475 _VisualElementImpl::GetTransformScaleAnchorXSubProperty(void) const
2476 {
2477         ClearLastResult();
2478
2479         float anchorX = 0.0f;
2480         float anchorY = 0.0f;
2481         float anchorZ = 0.0f;
2482         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2483
2484         return Variant(anchorX);
2485 }
2486
2487 result
2488 _VisualElementImpl::SetTransformScaleAnchorXSubProperty(const Variant& v)
2489 {
2490         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2491
2492         float anchorX = 0.0f;
2493         float anchorY = 0.0f;
2494         float anchorZ = 0.0f;
2495         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2496         __decomposedTransform.SetScaleAnchor(v.ToFloat(), anchorY, anchorZ);
2497
2498         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2499 }
2500
2501 Variant
2502 _VisualElementImpl::GetTransformScaleAnchorYSubProperty(void) const
2503 {
2504         ClearLastResult();
2505
2506         float anchorX = 0.0f;
2507         float anchorY = 0.0f;
2508         float anchorZ = 0.0f;
2509         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2510
2511         return Variant(anchorY);
2512 }
2513
2514 result
2515 _VisualElementImpl::SetTransformScaleAnchorYSubProperty(const Variant& v)
2516 {
2517         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2518
2519         float anchorX = 0.0f;
2520         float anchorY = 0.0f;
2521         float anchorZ = 0.0f;
2522         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2523         __decomposedTransform.SetScaleAnchor(anchorX, v.ToFloat(), anchorZ);
2524
2525         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2526 }
2527
2528 Variant
2529 _VisualElementImpl::GetTransformScaleAnchorZSubProperty(void) const
2530 {
2531         ClearLastResult();
2532
2533         float anchorX = 0.0f;
2534         float anchorY = 0.0f;
2535         float anchorZ = 0.0f;
2536         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2537
2538         return Variant(anchorZ);
2539 }
2540
2541 result
2542 _VisualElementImpl::SetTransformScaleAnchorZSubProperty(const Variant& v)
2543 {
2544         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2545
2546         float anchorX = 0.0f;
2547         float anchorY = 0.0f;
2548         float anchorZ = 0.0f;
2549         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2550         __decomposedTransform.SetScaleAnchor(anchorX, anchorY, v.ToFloat());
2551
2552         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2553 }
2554
2555 Variant
2556 _VisualElementImpl::GetTransformScaleAnchorXYSubProperty(void) const
2557 {
2558         ClearLastResult();
2559
2560         float anchorX = 0.0f;
2561         float anchorY = 0.0f;
2562         float anchorZ = 0.0f;
2563         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2564
2565         return Variant(FloatPoint(anchorX, anchorY));
2566 }
2567
2568 result
2569 _VisualElementImpl::SetTransformScaleAnchorXYSubProperty(const Variant& v)
2570 {
2571         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2572
2573         const FloatPoint& point = v.ToFloatPoint();
2574
2575         float anchorX = 0.0f;
2576         float anchorY = 0.0f;
2577         float anchorZ = 0.0f;
2578         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2579         __decomposedTransform.SetScaleAnchor(point.x, point.y, anchorZ);
2580
2581         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2582 }
2583
2584 Variant
2585 _VisualElementImpl::GetTransformTranslationXSubProperty(void) const
2586 {
2587         ClearLastResult();
2588
2589         float translateX = 0.0f;
2590         float translateY = 0.0f;
2591         float translateZ = 0.0f;
2592         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2593
2594         return Variant(translateX);
2595 }
2596
2597 result
2598 _VisualElementImpl::SetTransformTranslationXSubProperty(const Variant& v)
2599 {
2600         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2601
2602         float translateX = 0.0f;
2603         float translateY = 0.0f;
2604         float translateZ = 0.0f;
2605         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2606         __decomposedTransform.SetTranslationFactors(v.ToFloat(), translateY, translateZ);
2607
2608         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2609 }
2610
2611 Variant
2612 _VisualElementImpl::GetTransformTranslationYSubProperty(void) const
2613 {
2614         ClearLastResult();
2615
2616         float translateX = 0.0f;
2617         float translateY = 0.0f;
2618         float translateZ = 0.0f;
2619         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2620
2621         return Variant(translateY);
2622 }
2623
2624 result
2625 _VisualElementImpl::SetTransformTranslationYSubProperty(const Variant& v)
2626 {
2627         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2628
2629         float translateX = 0.0f;
2630         float translateY = 0.0f;
2631         float translateZ = 0.0f;
2632         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2633         __decomposedTransform.SetTranslationFactors(translateX, v.ToFloat(), translateZ);
2634
2635         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2636 }
2637
2638 Variant
2639 _VisualElementImpl::GetTransformTranslationZSubProperty(void) const
2640 {
2641         ClearLastResult();
2642
2643         float translateX = 0.0f;
2644         float translateY = 0.0f;
2645         float translateZ = 0.0f;
2646         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2647
2648         return Variant(translateZ);
2649 }
2650
2651 result
2652 _VisualElementImpl::SetTransformTranslationZSubProperty(const Variant& v)
2653 {
2654         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2655
2656         float translateX = 0.0f;
2657         float translateY = 0.0f;
2658         float translateZ = 0.0f;
2659         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2660         __decomposedTransform.SetTranslationFactors(translateX, translateY, v.ToFloat());
2661
2662         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2663 }
2664
2665 Variant
2666 _VisualElementImpl::GetTransformTranslationXYSubProperty(void) const
2667 {
2668         ClearLastResult();
2669
2670         float translateX = 0.0f;
2671         float translateY = 0.0f;
2672         float translateZ = 0.0f;
2673         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2674
2675         return Variant(FloatPoint(translateX, translateY));
2676 }
2677
2678 result
2679 _VisualElementImpl::SetTransformTranslationXYSubProperty(const Variant& v)
2680 {
2681         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2682
2683         const FloatPoint& point = v.ToFloatPoint();
2684
2685         float translateX = 0.0f;
2686         float translateY = 0.0f;
2687         float translateZ = 0.0f;
2688         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2689         __decomposedTransform.SetTranslationFactors(point.x, point.y, translateZ);
2690
2691         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2692 }
2693
2694 FloatMatrix4
2695 _VisualElementImpl::GetChildrenTransformMatrix(void) const
2696 {
2697         ClearLastResult();
2698
2699         return __childrenTransform;
2700 }
2701
2702
2703 result
2704 _VisualElementImpl::SetChildrenTransformMatrixI(const FloatMatrix4& xform, bool updateDecomposed)
2705 {
2706         FloatMatrix4 matrixAdjusted(xform);
2707         FloatMatrix4 oldValue(__childrenTransform);
2708         result r = E_SUCCESS;
2709
2710         if (unlikely(GetSharedData().pEventListener != null))
2711         {
2712                 if (IS_MODEL(this))     // CHECKME: checking need??
2713                 {
2714                         r = VE_DELEGATE(this, InvokeOnChildrenTransformMatrixChanging, matrixAdjusted);
2715                 }
2716         }
2717
2718
2719         if (r == E_SUCCESS && likely(matrixAdjusted != __childrenTransform))    // check again because delegate may change the transform matrix
2720         {
2721
2722                 // May be un-needed from now...... (no support for VE without surface or shared-canvas)
2723                 if (!IS_PRESENTATION(this))
2724                 {
2725                         int count = __children.GetCount();
2726                         for (int i = 0; i < count; i++)
2727                         {
2728                                 // VE with surface will be exposed automatically on rebuilding coordinates...
2729                                 _VisualElementImpl* pVe = __children.GetChildAt(i);
2730                                 if (pVe && !NEED_SURFACE(pVe))
2731                                 {
2732                                         pVe->ExposeRectangle(null, true);
2733
2734                                         // render target update for previous bounds
2735                                         pVe->InvalidateVisibleRectToRenderTarget(null);
2736                                 }
2737                         }
2738                 }
2739
2740                 MatrixUtilCopy(__childrenTransform, matrixAdjusted);
2741
2742                 if (unlikely(updateDecomposed))
2743                 {
2744                         __decomposedChildrenTransform.SetTransformMatrix(__childrenTransform);
2745                 }
2746
2747                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
2748         }
2749
2750         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
2751         {
2752                 FloatMatrix4 currentValue = __pPresentation->__childrenTransform;
2753                 static const String* subProperties[] = {
2754                                 pVeSubPropChildrenTransformRotationX,
2755                                 pVeSubPropChildrenTransformRotationY,
2756                                 pVeSubPropChildrenTransformRotationZ,
2757                                 pVeSubPropChildrenTransformScaleX,
2758                                 pVeSubPropChildrenTransformScaleY,
2759                                 pVeSubPropChildrenTransformScaleZ,
2760                                 pVeSubPropChildrenTransformTranslationX,
2761                                 pVeSubPropChildrenTransformTranslationY,
2762                                 pVeSubPropChildrenTransformTranslationZ,
2763                                 pVeSubPropChildrenTransformRotationAnchorX,
2764                                 pVeSubPropChildrenTransformRotationAnchorY,
2765                                 pVeSubPropChildrenTransformRotationAnchorZ,
2766                                 pVeSubPropChildrenTransformScaleAnchorX,
2767                                 pVeSubPropChildrenTransformScaleAnchorY,
2768                                 pVeSubPropChildrenTransformScaleAnchorZ,
2769                                 NULL};
2770
2771                 if(CreateImplicitAnimationIfNeeded(*pVePropChildrenTransform,   __childrenTransform, currentValue, subProperties ) == false)
2772                 {
2773                         __pPresentation->SetChildrenTransformMatrixProperty(__childrenTransform);
2774                 }
2775
2776                 VE_DELEGATE(this, InvokeOnChildrenTransformMatrixChanged, oldValue);
2777         }
2778         return E_SUCCESS;
2779 }
2780
2781
2782 result
2783 _VisualElementImpl::SetChildrenTransformMatrix(const FloatMatrix4& xform)
2784 {
2785         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
2786         result r = E_SUCCESS;
2787
2788         //PROPERTY_PROCESS(SetChildrenTransformMatrixI, GetChildrenTransformMatrixProperty, SetChildrenTransformMatrixProperty, pVePropChildrenTransform, __childrenTransform, xform);
2789         if (IS_INTERNAL_CLASS(__pPublicInstance))
2790         {
2791                 r = SetChildrenTransformMatrixI(xform);
2792         }
2793         else
2794         {
2795                 r = InvokeOnSetPropertyRequested(*pVePropChildrenTransform, Variant(xform));
2796         }
2797
2798         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
2799
2800         return r;
2801 }
2802
2803 Variant
2804 _VisualElementImpl::GetChildrenTransformMatrixProperty(void) const
2805 {
2806         ClearLastResult();
2807
2808         return Variant(__childrenTransform);
2809 }
2810
2811
2812 result
2813 _VisualElementImpl::SetChildrenTransformMatrixProperty(const Variant& v)
2814 {
2815         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_MATRIX4, E_INVALID_ARG,     E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2816
2817         return SetChildrenTransformMatrixI(v.ToFloatMatrix4(), true);
2818 }
2819
2820 Variant
2821 _VisualElementImpl::GetChildrenTransformRotationXSubProperty(void) const
2822 {
2823         ClearLastResult();
2824
2825         float angleX = 0.0f;
2826         float angleY = 0.0f;
2827         float angleZ = 0.0f;
2828         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2829
2830         return Variant(angleX);
2831 }
2832
2833 result
2834 _VisualElementImpl::SetChildrenTransformRotationXSubProperty(const Variant& v)
2835 {
2836         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2837
2838         float angleX = 0.0f;
2839         float angleY = 0.0f;
2840         float angleZ = 0.0f;
2841         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2842         __decomposedChildrenTransform.UpdateRotationFromEulerAngles(v.ToFloat(), angleY, angleZ);
2843
2844         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2845 }
2846
2847 Variant
2848 _VisualElementImpl::GetChildrenTransformRotationYSubProperty(void) const
2849 {
2850         ClearLastResult();
2851
2852         float angleX = 0.0f;
2853         float angleY = 0.0f;
2854         float angleZ = 0.0f;
2855         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2856
2857         return Variant(angleY);
2858 }
2859
2860 result
2861 _VisualElementImpl::SetChildrenTransformRotationYSubProperty(const Variant& v)
2862 {
2863         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2864
2865         float angleX = 0.0f;
2866         float angleY = 0.0f;
2867         float angleZ = 0.0f;
2868         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2869         __decomposedChildrenTransform.UpdateRotationFromEulerAngles(angleX, v.ToFloat(), angleZ);
2870
2871         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2872 }
2873
2874 Variant
2875 _VisualElementImpl::GetChildrenTransformRotationZSubProperty(void) const
2876 {
2877         ClearLastResult();
2878
2879         float angleX = 0.0f;
2880         float angleY = 0.0f;
2881         float angleZ = 0.0f;
2882         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2883
2884         return Variant(angleZ);
2885 }
2886
2887 result
2888 _VisualElementImpl::SetChildrenTransformRotationZSubProperty(const Variant& v)
2889 {
2890         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2891
2892         float angleX = 0.0f;
2893         float angleY = 0.0f;
2894         float angleZ = 0.0f;
2895         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2896         __decomposedChildrenTransform.UpdateRotationFromEulerAngles(angleX, angleY, v.ToFloat());
2897
2898         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2899 }
2900
2901 Variant
2902 _VisualElementImpl::GetChildrenTransformRotationXYSubProperty(void) const
2903 {
2904         ClearLastResult();
2905
2906         float angleX = 0.0f;
2907         float angleY = 0.0f;
2908         float angleZ = 0.0f;
2909         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2910
2911         return Variant(FloatPoint(angleX, angleY));
2912 }
2913
2914 result
2915 _VisualElementImpl::SetChildrenTransformRotationXYSubProperty(const Variant& v)
2916 {
2917         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2918
2919         const FloatPoint& point = v.ToFloatPoint();
2920
2921         float angleX = 0.0f;
2922         float angleY = 0.0f;
2923         float angleZ = 0.0f;
2924         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2925         __decomposedChildrenTransform.UpdateRotationFromEulerAngles(point.x, point.y, angleZ);
2926
2927         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2928 }
2929
2930 Variant
2931 _VisualElementImpl::GetChildrenTransformRotationAnchorXSubProperty(void) const
2932 {
2933         ClearLastResult();
2934
2935         float anchorX = 0.0f;
2936         float anchorY = 0.0f;
2937         float anchorZ = 0.0f;
2938         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2939
2940         return Variant(anchorX);
2941 }
2942
2943 result
2944 _VisualElementImpl::SetChildrenTransformRotationAnchorXSubProperty(const Variant& v)
2945 {
2946         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2947
2948         float anchorX = 0.0f;
2949         float anchorY = 0.0f;
2950         float anchorZ = 0.0f;
2951         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2952         __decomposedChildrenTransform.SetRotationAnchor(v.ToFloat(), anchorY, anchorZ);
2953
2954         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2955 }
2956
2957 Variant
2958 _VisualElementImpl::GetChildrenTransformRotationAnchorYSubProperty(void) const
2959 {
2960         ClearLastResult();
2961
2962         float anchorX = 0.0f;
2963         float anchorY = 0.0f;
2964         float anchorZ = 0.0f;
2965         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2966
2967         return Variant(anchorY);
2968 }
2969
2970 result
2971 _VisualElementImpl::SetChildrenTransformRotationAnchorYSubProperty(const Variant& v)
2972 {
2973         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2974
2975         float anchorX = 0.0f;
2976         float anchorY = 0.0f;
2977         float anchorZ = 0.0f;
2978         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2979         __decomposedChildrenTransform.SetRotationAnchor(anchorX, v.ToFloat(), anchorZ);
2980
2981         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2982 }
2983
2984 Variant
2985 _VisualElementImpl::GetChildrenTransformRotationAnchorZSubProperty(void) const
2986 {
2987         ClearLastResult();
2988
2989         float anchorX = 0.0f;
2990         float anchorY = 0.0f;
2991         float anchorZ = 0.0f;
2992         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2993
2994         return Variant(anchorZ);
2995 }
2996
2997 result
2998 _VisualElementImpl::SetChildrenTransformRotationAnchorZSubProperty(const Variant& v)
2999 {
3000         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3001
3002         float anchorX = 0.0f;
3003         float anchorY = 0.0f;
3004         float anchorZ = 0.0f;
3005         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3006         __decomposedChildrenTransform.SetRotationAnchor(anchorX, anchorY, v.ToFloat());
3007
3008         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3009 }
3010
3011 Variant
3012 _VisualElementImpl::GetChildrenTransformRotationAnchorXYSubProperty(void) const
3013 {
3014         ClearLastResult();
3015
3016         float anchorX = 0.0f;
3017         float anchorY = 0.0f;
3018         float anchorZ = 0.0f;
3019         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3020
3021         return Variant(FloatPoint(anchorX, anchorY));
3022 }
3023
3024 result
3025 _VisualElementImpl::SetChildrenTransformRotationAnchorXYSubProperty(const Variant& v)
3026 {
3027         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3028
3029         const FloatPoint& point = v.ToFloatPoint();
3030
3031         float anchorX = 0.0f;
3032         float anchorY = 0.0f;
3033         float anchorZ = 0.0f;
3034         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3035         __decomposedChildrenTransform.SetRotationAnchor(point.x, point.y, anchorZ);
3036
3037         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3038 }
3039
3040 Variant
3041 _VisualElementImpl::GetChildrenTransformScaleXSubProperty(void) const
3042 {
3043         ClearLastResult();
3044
3045         float scaleX = 1.0f;
3046         float scaleY = 1.0f;
3047         float scaleZ = 1.0f;
3048         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3049
3050         return Variant(scaleX);
3051 }
3052
3053 result
3054 _VisualElementImpl::SetChildrenTransformScaleXSubProperty(const Variant& v)
3055 {
3056         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3057
3058         float scaleX = 1.0f;
3059         float scaleY = 1.0f;
3060         float scaleZ = 1.0f;
3061         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3062         __decomposedChildrenTransform.SetScaleFactors(v.ToFloat(), scaleY, scaleZ);
3063
3064         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3065 }
3066
3067 Variant
3068 _VisualElementImpl::GetChildrenTransformScaleYSubProperty(void) const
3069 {
3070         ClearLastResult();
3071
3072         float scaleX = 1.0f;
3073         float scaleY = 1.0f;
3074         float scaleZ = 1.0f;
3075         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3076
3077         return Variant(scaleY);
3078 }
3079
3080 result
3081 _VisualElementImpl::SetChildrenTransformScaleYSubProperty(const Variant& v)
3082 {
3083         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3084
3085         float scaleX = 1.0f;
3086         float scaleY = 1.0f;
3087         float scaleZ = 1.0f;
3088         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3089         __decomposedChildrenTransform.SetScaleFactors(scaleX, v.ToFloat(), scaleZ);
3090
3091         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3092 }
3093
3094 Variant
3095 _VisualElementImpl::GetChildrenTransformScaleZSubProperty(void) const
3096 {
3097         ClearLastResult();
3098
3099         float scaleX = 1.0f;
3100         float scaleY = 1.0f;
3101         float scaleZ = 1.0f;
3102         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3103
3104         return Variant(scaleZ);
3105 }
3106
3107 result
3108 _VisualElementImpl::SetChildrenTransformScaleZSubProperty(const Variant& v)
3109 {
3110         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3111
3112         float scaleX = 1.0f;
3113         float scaleY = 1.0f;
3114         float scaleZ = 1.0f;
3115         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3116         __decomposedChildrenTransform.SetScaleFactors(scaleX, scaleY, v.ToFloat());
3117
3118         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3119 }
3120
3121 Variant
3122 _VisualElementImpl::GetChildrenTransformScaleXYSubProperty(void) const
3123 {
3124         ClearLastResult();
3125
3126         float scaleX = 1.0f;
3127         float scaleY = 1.0f;
3128         float scaleZ = 1.0f;
3129         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3130
3131         return Variant(FloatPoint(scaleX, scaleY));
3132 }
3133
3134 result
3135 _VisualElementImpl::SetChildrenTransformScaleXYSubProperty(const Variant& v)
3136 {
3137         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3138
3139         const FloatPoint& point = v.ToFloatPoint();
3140
3141         float scaleX = 1.0f;
3142         float scaleY = 1.0f;
3143         float scaleZ = 1.0f;
3144         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3145         __decomposedChildrenTransform.SetScaleFactors(point.x, point.y, scaleZ);
3146
3147         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3148 }
3149
3150 Variant
3151 _VisualElementImpl::GetChildrenTransformScaleAnchorXSubProperty(void) const
3152 {
3153         ClearLastResult();
3154
3155         float anchorX = 0.0f;
3156         float anchorY = 0.0f;
3157         float anchorZ = 0.0f;
3158         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3159
3160         return Variant(anchorX);
3161 }
3162
3163 result
3164 _VisualElementImpl::SetChildrenTransformScaleAnchorXSubProperty(const Variant& v)
3165 {
3166         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3167
3168         float anchorX = 0.0f;
3169         float anchorY = 0.0f;
3170         float anchorZ = 0.0f;
3171         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3172         __decomposedChildrenTransform.SetScaleAnchor(v.ToFloat(), anchorY, anchorZ);
3173
3174         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3175 }
3176
3177 Variant
3178 _VisualElementImpl::GetChildrenTransformScaleAnchorYSubProperty(void) const
3179 {
3180         ClearLastResult();
3181
3182         float anchorX = 0.0f;
3183         float anchorY = 0.0f;
3184         float anchorZ = 0.0f;
3185         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3186
3187         return Variant(anchorY);
3188 }
3189
3190 result
3191 _VisualElementImpl::SetChildrenTransformScaleAnchorYSubProperty(const Variant& v)
3192 {
3193         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3194
3195         float anchorX = 0.0f;
3196         float anchorY = 0.0f;
3197         float anchorZ = 0.0f;
3198         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3199         __decomposedChildrenTransform.SetScaleAnchor(anchorX, v.ToFloat(), anchorZ);
3200
3201         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3202 }
3203
3204 Variant
3205 _VisualElementImpl::GetChildrenTransformScaleAnchorZSubProperty(void) const
3206 {
3207         ClearLastResult();
3208
3209         float anchorX = 0.0f;
3210         float anchorY = 0.0f;
3211         float anchorZ = 0.0f;
3212         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3213
3214         return Variant(anchorZ);
3215 }
3216
3217 result
3218 _VisualElementImpl::SetChildrenTransformScaleAnchorZSubProperty(const Variant& v)
3219 {
3220         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3221
3222         float anchorX = 0.0f;
3223         float anchorY = 0.0f;
3224         float anchorZ = 0.0f;
3225         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3226         __decomposedChildrenTransform.SetScaleAnchor(anchorX, anchorY, v.ToFloat());
3227
3228         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3229 }
3230
3231 Variant
3232 _VisualElementImpl::GetChildrenTransformScaleAnchorXYSubProperty(void) const
3233 {
3234         ClearLastResult();
3235
3236         float anchorX = 0.0f;
3237         float anchorY = 0.0f;
3238         float anchorZ = 0.0f;
3239         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3240
3241         return Variant(FloatPoint(anchorX, anchorY));
3242 }
3243
3244 result
3245 _VisualElementImpl::SetChildrenTransformScaleAnchorXYSubProperty(const Variant& v)
3246 {
3247         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3248
3249         const FloatPoint& point = v.ToFloatPoint();
3250
3251         float anchorX = 0.0f;
3252         float anchorY = 0.0f;
3253         float anchorZ = 0.0f;
3254         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3255         __decomposedChildrenTransform.SetScaleAnchor(point.x, point.y, anchorZ);
3256
3257         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3258 }
3259
3260 Variant
3261 _VisualElementImpl::GetChildrenTransformTranslationXSubProperty(void) const
3262 {
3263         ClearLastResult();
3264
3265         float translateX = 0.0f;
3266         float translateY = 0.0f;
3267         float translateZ = 0.0f;
3268         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3269
3270         return Variant(translateX);
3271 }
3272
3273 result
3274 _VisualElementImpl::SetChildrenTransformTranslationXSubProperty(const Variant& v)
3275 {
3276         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3277
3278         float translateX = 0.0f;
3279         float translateY = 0.0f;
3280         float translateZ = 0.0f;
3281         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3282         __decomposedChildrenTransform.SetTranslationFactors(v.ToFloat(), translateY, translateZ);
3283
3284         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3285 }
3286
3287 Variant
3288 _VisualElementImpl::GetChildrenTransformTranslationYSubProperty(void) const
3289 {
3290         ClearLastResult();
3291
3292         float translateX = 0.0f;
3293         float translateY = 0.0f;
3294         float translateZ = 0.0f;
3295         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3296
3297         return Variant(translateY);
3298 }
3299
3300 result
3301 _VisualElementImpl::SetChildrenTransformTranslationYSubProperty(const Variant& v)
3302 {
3303         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3304
3305         float translateX = 0.0f;
3306         float translateY = 0.0f;
3307         float translateZ = 0.0f;
3308         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3309         __decomposedChildrenTransform.SetTranslationFactors(translateX, v.ToFloat(), translateZ);
3310
3311         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3312 }
3313
3314 Variant
3315 _VisualElementImpl::GetChildrenTransformTranslationZSubProperty(void) const
3316 {
3317         ClearLastResult();
3318
3319         float translateX = 0.0f;
3320         float translateY = 0.0f;
3321         float translateZ = 0.0f;
3322         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3323
3324         return Variant(translateZ);
3325 }
3326
3327 result
3328 _VisualElementImpl::SetChildrenTransformTranslationZSubProperty(const Variant& v)
3329 {
3330         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3331
3332         float translateX = 0.0f;
3333         float translateY = 0.0f;
3334         float translateZ = 0.0f;
3335         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3336         __decomposedChildrenTransform.SetTranslationFactors(translateX, translateY, v.ToFloat());
3337
3338         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3339 }
3340
3341 Variant
3342 _VisualElementImpl::GetChildrenTransformTranslationXYSubProperty(void) const
3343 {
3344         ClearLastResult();
3345
3346         float translateX = 0.0f;
3347         float translateY = 0.0f;
3348         float translateZ = 0.0f;
3349         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3350
3351         return Variant(FloatPoint(translateX, translateY));
3352 }
3353
3354 result
3355 _VisualElementImpl::SetChildrenTransformTranslationXYSubProperty(const Variant& v)
3356 {
3357         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3358
3359         const FloatPoint& point = v.ToFloatPoint();
3360
3361         float translateX = 0.0f;
3362         float translateY = 0.0f;
3363         float translateZ = 0.0f;
3364         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3365         __decomposedChildrenTransform.SetTranslationFactors(point.x, point.y, translateZ);
3366
3367         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3368 }
3369
3370 bool
3371 _VisualElementImpl::IsClipToParent(void) const
3372 {
3373         ClearLastResult();
3374
3375         return false;
3376 }
3377
3378 // TBD: clipToParent is not animatable, right??
3379 result
3380 _VisualElementImpl::SetClipToParent(bool clipToParent)
3381 {
3382         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3383
3384         return InvokeOnSetPropertyRequested(*pVePropClipToParent, Variant(clipToParent));
3385 }
3386
3387 Variant
3388 _VisualElementImpl::GetClipToParentProperty(void) const
3389 {
3390         ClearLastResult();
3391         //SysLog(NID_UI_ANIM, "WARNING: ClipToParent is deprecated.");
3392
3393         return Variant(false);
3394 }
3395
3396 result
3397 _VisualElementImpl::SetClipToParentProperty(const Variant& v)
3398 {
3399         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3400
3401         //SysLog(NID_UI_ANIM, "WARNING: ClipToParent is deprecated.");
3402
3403         return E_SUCCESS;
3404 }
3405
3406 bool
3407 _VisualElementImpl::IsClipChildrenEnabled(void) const
3408 {
3409         ClearLastResult();
3410
3411         return __isClipChildren;
3412 }
3413
3414 result
3415 _VisualElementImpl::SetClipChildrenEnabled(bool clipChildren)
3416 {
3417         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3418         result r = E_SUCCESS;
3419
3420         if (IS_INTERNAL_CLASS(__pPublicInstance))
3421         {
3422                 r = SetClipChildrenProperty(Variant(clipChildren));
3423         }
3424         else
3425         {
3426                 r = InvokeOnSetPropertyRequested(*pVePropClipChildren, Variant(clipChildren));
3427         }
3428         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
3429
3430         return r;
3431 }
3432
3433 Variant
3434 _VisualElementImpl::GetClipChildrenProperty(void) const
3435 {
3436         ClearLastResult();
3437
3438         return Variant(__isClipChildren);
3439 }
3440
3441 result
3442 _VisualElementImpl::SetClipChildrenProperty(const Variant& v)
3443 {
3444         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3445
3446         bool clipChildren = v.ToBool();
3447         if (likely(clipChildren != __isClipChildren))
3448         {
3449
3450                 //SysLog(NID_UI_ANIM, "%p ClipChildren = %d", this, clipChildren);
3451
3452                 __isClipChildren = clipChildren;
3453                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
3454
3455         }
3456
3457         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
3458         {
3459                 __pPresentation->SetClipChildrenProperty(__isClipChildren);
3460         }
3461
3462         return E_SUCCESS;
3463 }
3464
3465 bool
3466 _VisualElementImpl::IsSurfaceOpaque(void) const
3467 {
3468         ClearLastResult();
3469
3470         return GetSharedData().isSurfaceOpaque;
3471 }
3472
3473 result
3474 _VisualElementImpl::SetSurfaceOpaque(bool isSurfaceOpaque)
3475 {
3476         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3477         result r = E_SUCCESS;
3478
3479         if (IS_INTERNAL_CLASS(__pPublicInstance))
3480         {
3481                 r = SetSurfaceOpaqueProperty(Variant(isSurfaceOpaque));
3482         }
3483         else
3484         {
3485                 r = InvokeOnSetPropertyRequested(*pVePropSurfaceOpaque, Variant(isSurfaceOpaque));
3486         }
3487         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
3488
3489         return E_SUCCESS;
3490 }
3491
3492 Variant
3493 _VisualElementImpl::GetSurfaceOpaqueProperty(void) const
3494 {
3495         ClearLastResult();
3496
3497         return Variant(GetSharedData().isSurfaceOpaque);
3498 }
3499
3500 result
3501 _VisualElementImpl::SetSurfaceOpaqueProperty(const Variant& v)
3502 {
3503         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3504
3505         bool isSurfaceOpaque = v.ToBool();
3506         if (isSurfaceOpaque == GetSharedData().isSurfaceOpaque)
3507                 return E_SUCCESS;
3508
3509         InvalidateHierarchyProps(HIERARCHY_PROPERTY_CONTENTOPACITY, false, false); //don't have to apply the changed opacity to children.
3510
3511         if (IS_PRESENTATION(this))
3512         {
3513                 GetSharedData().isSurfaceOpaque = isSurfaceOpaque;
3514
3515 #ifndef LAZY_EVALUATION
3516                 // not needed when no surface
3517                 if (HAVE_SURFACE(this))
3518                         GetSharedData().NodeReconfigure(*this);
3519 #endif
3520         }
3521         else
3522         {
3523                 if(IS_NEEDED_UPDATE_PRESENTATION(this))
3524                 {
3525                         __pPresentation->SetSurfaceOpaqueProperty(isSurfaceOpaque);
3526                 }
3527         }
3528
3529         return E_SUCCESS;
3530 }
3531
3532 Canvas*
3533 _VisualElementImpl::GetCanvasN(void)
3534 {
3535         return GetCanvasN(FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height));
3536 }
3537
3538 Canvas*
3539 _VisualElementImpl::GetCanvasN(const Rectangle& bounds)
3540 {
3541         return GetCanvasN(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
3542 }
3543
3544 Canvas*
3545 _VisualElementImpl::GetCanvasN(const FloatRectangle& bounds)
3546 {
3547         SysTryReturn(NID_UI_ANIM, !GetSharedData().fixedSurfaceSize, null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Canvas can't be instantiated for fixed-size user surface.");
3548         SysTryReturn(NID_UI_ANIM, bounds.width >= 0.0f && bounds.height >= 0.0f, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Canvas size is out of range. size = (%f, %f)", bounds.width, bounds.height);
3549         SysTryReturn(NID_UI_ANIM, __imageFilePath.IsEmpty(), null, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Can't get canvas for surface which is from image file.");
3550         SysTryReturn(NID_UI_ANIM, GetRoot(), null, E_INVALID_STATE, "[E_INVALID_STATE] VisualElement is not attached to main tree.");
3551         SysTryReturn(NID_UI_ANIM, IS_MODEL(this), null, E_INVALID_OPERATION, "VisualElement is not Model object.");
3552
3553         // WARNING: WARNING: WARNING:
3554         //      If need-redraw and surface is set by user, VE do *NOT* allow GetCanvasN
3555         //      because 'bounds' is for the VE does not comply with size of surface.
3556         //      (in which case the surface will be displayed scaled)
3557
3558         _VisualElementImpl* pRenderTarget = GetRenderTarget();
3559         SysTryReturn(NID_UI_ANIM, pRenderTarget, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Target VisualElement is not available.");
3560         SysTryReturn(NID_UI_ANIM, pRenderTarget->__pSharedData, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Target VisualElement is not constructed.");
3561
3562         // WARNING:
3563         //      Forcefully create surface if GetCanvasN is called.
3564         //      Without followings, surface may not be created if size of bounds == 0 (the initial size)
3565         if (!HAVE_SURFACE(this))
3566         {
3567                 __needRecreateSurface = true;
3568         }
3569
3570         pRenderTarget->RebuildHierarchyProps(0, true, true);
3571
3572 #if 1
3573         SysTryReturn(NID_UI_ANIM, pRenderTarget->GetSharedData().pNativeNode->GetSurface(), null, E_SYSTEM, "[E_INVALID_STATE] Target VisualElement's surface is not constructed.");
3574 #else
3575         SysTryReturn(NID_UI_ANIM, pRenderTarget->GetSharedData().pSurface, null, E_SYSTEM, "[E_INVALID_STATE] Target VisualElement's surface is not constructed.");
3576 #endif
3577
3578         FloatRectangle canvasBounds;
3579         FloatRectangle clipBounds;
3580
3581         // TODO: FIXME:
3582         //      Use surface size, not bounds !!!
3583
3584         float canvasX, canvasY, canvasW, canvasH;
3585
3586         if (bounds.width == 0.0f || bounds.height == 0.0f)
3587         {
3588                 float surfaceWidth = __bounds.width;
3589                 float surfaceHeight = __bounds.height;
3590
3591                 SysTryReturn(NID_UI_ANIM, bounds.x >= 0.0f && bounds.y >= 0.0f && bounds.x <= surfaceWidth && bounds.y <= surfaceHeight, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Bounds is out of range.");
3592
3593                 canvasX = bounds.x;
3594                 canvasY = bounds.y;
3595                 canvasW = 0.0f;
3596                 canvasH = 0.0f;
3597         }
3598         else
3599         {
3600                 clipBounds.x = 0.0f;
3601                 clipBounds.y = 0.0f;
3602                 clipBounds.width = __bounds.width;
3603                 clipBounds.height = __bounds.height;
3604
3605                 canvasBounds.x = bounds.x;
3606                 canvasBounds.y = bounds.y;
3607                 canvasBounds.width = bounds.width;
3608                 canvasBounds.height = bounds.height;
3609
3610                 canvasBounds = canvasBounds.GetIntersection(clipBounds);
3611                 pRenderTarget->__pPresentation->ConvertCoordinates(canvasBounds, this->__pPresentation);
3612                 canvasBounds = canvasBounds.GetIntersection(pRenderTarget->GetDrawableRect());
3613
3614                 SysTryReturn(NID_UI_ANIM, canvasBounds.width > 0.0f && canvasBounds.height > 0.0f, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Bounds is out of range.");
3615
3616                 canvasX = canvasBounds.x;
3617                 canvasY = canvasBounds.y;
3618                 canvasW = canvasBounds.width;
3619                 canvasH = canvasBounds.height;
3620         }
3621
3622         // WARNING:
3623         //      From now, canvasBounds contains the clipping area, not subcanvas area.
3624         //      (0, 0) of the canvas should be placed on the left-top of the VE !
3625
3626         unique_ptr<_VisualElementCanvas> pCanvas(new (std::nothrow) _VisualElementCanvas);
3627
3628         result r = pCanvas->Construct(*pRenderTarget->GetSharedData().pNativeNode->GetSurface(), FloatRectangle(canvasX, canvasY, canvasW, canvasH));
3629         SysTryReturn(NID_UI_ANIM, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] VisualElement is not constructed.");
3630
3631         pRenderTarget->SetFlushNeeded();
3632
3633         ClearLastResult();
3634
3635         return pCanvas.release();
3636 }
3637
3638 _VisualElementImpl*
3639 _VisualElementImpl::GetRoot(void) const
3640 {
3641         ClearLastResult();
3642
3643         if (IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES))
3644         {
3645                 const_cast< _VisualElementImpl* >(this)->RebuildCoordinates();
3646         }
3647
3648         return __pRoot;
3649 }
3650
3651 _VisualElementImpl*
3652 _VisualElementImpl::GetParent(void) const
3653 {
3654         ClearLastResult();
3655
3656         return __pParent;
3657 }
3658
3659 int
3660 _VisualElementImpl::GetChildrenCount(void) const
3661 {
3662         ClearLastResult();
3663
3664         return __children.GetCount();
3665 }
3666
3667 Tizen::Base::Collection::IList*
3668 _VisualElementImpl::GetPublicChildrenN(void) const
3669 {
3670         unique_ptr<Tizen::Base::Collection::ArrayList> pArrayList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
3671         SysTryReturn(NID_UI_ANIM, pArrayList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3672
3673         int count = __children.GetCount();
3674         SysTryReturn(NID_UI_ANIM, !IsFailed(pArrayList->Construct(count)), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3675
3676         for (int i = 0; i < count; i++)
3677         {
3678                 const _VisualElementImpl* pChild = __children.GetChildAt(i);
3679
3680                 if (likely(pChild) && likely(pChild->__pPublicInstance))
3681                 {
3682                         SysTryReturn(NID_UI_ANIM, !IsFailed(pArrayList->Add(*pChild->__pPublicInstance)), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3683                 }
3684         }
3685
3686         ClearLastResult();
3687
3688         return pArrayList.release();
3689 }
3690
3691 bool
3692 _VisualElementImpl::IsChildOf(const _VisualElementImpl& element) const
3693 {
3694         ClearLastResult();
3695
3696         if (unlikely(this == &element))
3697         {
3698                 return false;
3699         }
3700
3701         if (unlikely(!__pParent))
3702         {
3703                 return false;
3704         }
3705
3706         if (likely(__pParent == &element))
3707         {
3708                 return true;
3709         }
3710
3711         return __pParent->IsChildOf(element);
3712 }
3713
3714 result
3715 _VisualElementImpl::SetZOrder(const _VisualElementImpl* pReference, bool above)
3716 {
3717         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3718         SysTryReturnResult(NID_UI_ANIM, !pReference || pReference->__pParent, E_INVALID_ARG, "pReference doesn't have parent.");
3719         SysTryReturnResult(NID_UI_ANIM, __pParent, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement doesn't have a parent.");
3720         SysTryReturnResult(NID_UI_ANIM, __isAllowedTreeModification == true, E_INVALID_OPERATION, "Z-order cannot be modified inside the OnAttached() or OnDetached() method of VisualElementEventListener.");
3721
3722         return __pParent->InsertChild(*this, pReference, above);
3723 }
3724
3725 void
3726 _VisualElementImpl::RemoveFromParent(void)
3727 {
3728         if (likely(__pParent))
3729         {
3730                 __pParent->RemoveChild(*this);
3731         }
3732 }
3733
3734 result
3735 _VisualElementImpl::AddChild(_VisualElementImpl& child)
3736 {
3737         //SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3738         SysTryReturnResult(NID_UI_ANIM, child.__pSharedData, E_INVALID_ARG, "Child VisualElement is not constructed.");
3739         SysTryReturnResult(NID_UI_ANIM, child.__isAllowedTreeModification == true, E_INVALID_OPERATION, "Z-order cannot be modified inside the OnAttached() or OnDetached() method of VisualElementEventListener.");
3740
3741         return ChangeZOrder(child, null, true, child._zOrderGroup);
3742 }
3743
3744 int
3745 _VisualElementImpl::GetChildIndex(const _VisualElementImpl& child) const
3746 {
3747         int index = 0;
3748         result r = __children.IndexOf(const_cast< _VisualElementImpl* >(&child), index);
3749
3750         if (r == E_SUCCESS)
3751         {
3752                 return index;
3753         }
3754
3755         // r == E_OUT_OF_RANGE or E_OBJ_NOT_FOUND
3756         return -1;
3757 }
3758
3759 /**
3760  * @param[in]   group           will be changed group of the visualemenet.
3761  * @param[out]  belowIndex  the index of last item of below group's item.
3762  * @param[out]  aboveIndex      the index of first item of above group's item.
3763  *
3764  * if group is lower than __children's lowest item, belowIndex = -1 , aboveIndex = 0
3765  * if group is higher than __children's highest item, belowIndex is last index of children, aboveIndex is 1 bigger than belowIndex.
3766  *
3767  *(ex)
3768  * B = Z_ORDER_GROUP_ALWAYS_BELOW_BOTTOM        // lowest drawing gadget.(Background)
3769  * N = Z_ORDER_GROUP_NORMAL;                            // level of the default group.
3770  * T = Z_ORDER_GROUP_ALWAYS_ON_TOP;             // highest drawing gadget.
3771  *  0  1  2  3  4  5  6  7  8  9
3772  * [B][B][B][N][N][N][N][T][T][T]
3773  * __GetZOrderGroupIndex(Z_ORDER_GROUP_NORMAL, below, above);
3774  *                                            below = 2
3775  *                                            above = 7
3776  * __GetZOrderGroupIndex(Z_ORDER_GROUP_ALWAYS_ON_TOP, below, above);
3777  *                                            below = 6
3778  *                                            above = 10
3779  * __GetZOrderGroupIndex(Z_ORDER_GROUP_ALWAYS_BELOW_BOTTOM, below, above);
3780  *                                            below = -1
3781  *                                            above = 3
3782  *  0  1  2  3  4  5  6  7  8  9
3783  * [B][B][B][B][B][T][T][T][T][T]
3784  * __GetZOrderGroupIndex(Z_ORDER_GROUP_NORMAL, below, above);
3785  *                                            below = 4
3786  *                                            above = 5
3787  * __GetZOrderGroupIndex(Z_ORDER_GROUP_ALWAYS_ON_TOP, below, above);
3788  *                                            below = 4
3789  *                                            above = 10
3790  * __GetZOrderGroupIndex(Z_ORDER_GROUP_ALWAYS_BELOW_BOTTOM, below, above);
3791  *                                            below = -1
3792  *                                            above = 5
3793  *
3794  */
3795
3796 int
3797 _VisualElementImpl::GetZOrderGroupIndex(int group, int& belowIndex, int& aboveIndex) const
3798 {
3799         int lastIndex = __children.GetCount() - 1;
3800         if (lastIndex < 0) // _children is empty.
3801         {
3802                 belowIndex = -1;
3803                 aboveIndex = 0;
3804                 return 0;
3805         }
3806
3807         if (group < (__children.GetChildAt(0))->_zOrderGroup)  // group is lower than __children's lowest item.
3808         {
3809                 belowIndex = -1;
3810                 aboveIndex = 0;
3811                 return -1;
3812         }
3813
3814         if (group > (__children.GetChildAt(lastIndex))->_zOrderGroup)  // group is higher than __children's highest item.
3815         {
3816                 belowIndex = lastIndex;
3817                 aboveIndex = lastIndex + 1;
3818                 return 1;
3819         }
3820
3821         int i = lastIndex;
3822
3823         for (; i >= 0; i--)
3824         {
3825                 if (group >= __children.GetChildAt(i)->_zOrderGroup)
3826                 {
3827                         break;
3828                 }
3829         }
3830
3831         aboveIndex = i + 1;
3832
3833         for (; i >= 0; i--)
3834         {
3835                 if (group > __children.GetChildAt(i)->_zOrderGroup)
3836                 {
3837                         break;
3838                 }
3839         }
3840
3841         belowIndex = i;
3842
3843         return 0;
3844 }
3845
3846 result
3847 _VisualElementImpl::InsertChild(_VisualElementImpl& child, const _VisualElementImpl* pReference, bool above)
3848 {
3849         //SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3850         SysTryReturnResult(NID_UI_ANIM, child.__pSharedData, E_INVALID_ARG, "Child VisualElement is not constructed.");
3851         SysTryReturnResult(NID_UI_ANIM, child.__isAllowedTreeModification == true, E_INVALID_OPERATION, "Z-order cannot be modified inside the OnAttached() or OnDetached() method of VisualElementEventListener.");
3852
3853         int zOrderGroup = child._zOrderGroup;
3854
3855         if (unlikely(pReference))
3856         {
3857                 zOrderGroup = pReference->_zOrderGroup;
3858         }
3859
3860         return ChangeZOrder(child, pReference, above, zOrderGroup);
3861 }
3862
3863 result
3864 _VisualElementImpl::ChangeZOrder(_VisualElementImpl& child, const _VisualElementImpl* pReference, bool above, int group)
3865 {
3866         int indexChild;
3867         int indexReference = -1;
3868         int indexInsert = -1;
3869
3870         bool sameParent = false;
3871
3872         // If not constructed well, disallow attaching !
3873
3874         if (IsChildOf(child) || this == &child || &child == pReference || (pReference && pReference->__pParent != this))
3875         {
3876                 return E_INVALID_ARG;
3877         }
3878
3879         // TBD: check ownership!!!
3880         if (IS_PRESENTATION(this))
3881         {
3882                 _RootVisualElement* pChildRoot = child.GetRootPublic();
3883
3884                 if (GetRootPublic() != null && pChildRoot != GetRootPublic())
3885                 {
3886                         child.RebuildNativeNodeTree(*this);
3887                 }
3888         }
3889
3890         if (pReference)
3891         {
3892                 indexReference = GetChildIndex(*pReference);
3893                 SysTryReturnResult(NID_UI_ANIM, indexReference >= 0, E_INVALID_ARG, "Invalid argument(s) is used. pReference is not a child of this instance.");
3894
3895                 if (above)
3896                 {
3897                         indexReference++;
3898                 }
3899         }
3900         else
3901         {
3902                 if (above)
3903                 {
3904                         indexReference = __children.GetCount();
3905                 }
3906                 else
3907                 {
3908                         indexReference = 0;
3909                 }
3910         }
3911
3912         int belowIndex, aboveIndex, indexRange;
3913
3914         indexRange = GetZOrderGroupIndex(group, belowIndex, aboveIndex);
3915
3916         if (indexRange < 0)
3917         {
3918                 indexInsert = 0;
3919         }
3920         else if (indexRange > 0)
3921         {
3922                 indexInsert = __children.GetCount();
3923         }
3924         else
3925         {
3926                 if (indexReference <= belowIndex + 1)
3927                 {
3928                         indexInsert = belowIndex + 1;
3929                 }
3930                 else if (indexReference >= aboveIndex)
3931                 {
3932                         indexInsert = aboveIndex;
3933                 }
3934                 else
3935                 {
3936                         indexInsert = indexReference;
3937                 }
3938
3939                 if (indexInsert < 0)
3940                 {
3941                         indexInsert = 0;
3942                 }
3943         }
3944
3945         if (child.__pParent == this) //case 1: move to the same parent. (just changed order )
3946         {
3947                 sameParent = true;
3948
3949                 indexChild = GetChildIndex(child);
3950                 SysTryReturn(NID_UI_ANIM, indexChild >= 0,
3951                                         E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. The child(%p) isn't managed by this instance.", &child);
3952
3953                 if (indexChild < indexInsert)
3954                 {
3955                         indexInsert--; // one of child item is removed so total item index is decreased.
3956                 }
3957
3958                 if (indexChild == indexInsert) //same position. don't have to do any action.
3959                 {
3960                         child._zOrderGroup = group;
3961
3962                         //update presentation zorder group
3963                         if (!IS_PRESENTATION(this))
3964                         {
3965                                 child.UpdatePresentationWhenZOrderChanged(pReference, above);
3966                         }
3967                         return E_SUCCESS;
3968                 }
3969
3970                 SysTryReturn(NID_UI_ANIM, RemoveChildWithoutReconfiguring(indexChild, true) == E_SUCCESS,
3971                                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Failed to remove a child(%p) from this instance.", &child);
3972
3973         }
3974         else //case 2: move to the other parent.
3975         {    //case 3: child never been attached to the any parent.
3976                 if (child.__pParent)
3977                 {
3978                         child.__pParent->RemoveChild(child);
3979                 }
3980
3981                 // Setting implicit animation to the child.
3982                 if (!IS_PRESENTATION(this) && _AnimationManager::GetInstance()->IsImplicitAnimationEnabled() && child.__isImplicitAnimationEnabled)
3983                 {
3984                         child.RemoveAnimation(*pVePropActionAttach);
3985
3986 #if defined(SUPPORT_CUSTOMIZING_ATTACH_DETACH_ANIMATION)
3987                         VisualElementAnimation* pAnimation = child.InvokeCreateAnimationForProperty(*pVePropActionAttach);
3988 #else
3989                         VisualElementPropertyAnimation* pAnimation = new (std::nothrow) VisualElementPropertyAnimation();
3990                         SysTryReturn(NID_UI_ANIM, pAnimation != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3991                         pAnimation->SetPropertyName(*pVePropOpacity);
3992                         pAnimation->SetStartValue(Variant(0.0f));
3993 #endif
3994                         if (pAnimation != null)
3995                         {
3996                                 pAnimation->SetVisualElementAnimationStatusEventListener(null);
3997                                 (child.GetPublic())->AddAnimation(*pVePropActionAttach, *pAnimation);
3998                         }
3999                         delete pAnimation;
4000                 }
4001         }
4002
4003         // set ZOrder group
4004         child._zOrderGroup = group;
4005
4006         //SysLog(NID_UI_ANIM, "Insert child %p(%d)", &child, indexInsert);
4007
4008         if (!IS_PRESENTATION(this))
4009         {
4010                 if(!sameParent)
4011                 {
4012                         VE_DELEGATE(this, InvokeOnChildAttaching, child);
4013                         VE_DELEGATE(&child, InvokeOnAttaching, *this);
4014                 }
4015         }
4016
4017         __children.InsertAt(&child, indexInsert);    // need addref -> jobs -> release ...
4018         child.__pParent = this;
4019
4020         child.InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES | HIERARCHY_PROPERTY_OPACITY | HIERARCHY_PROPERTY_SHOWSTATE, true, false);
4021
4022         // propagate child's prop. status to parents
4023         //__InvalidateHierarchyProps(child.__childrenNeedsUpdateProps, false, true);
4024         InvalidateHierarchyProps(child.__childrenNeedsUpdateProps, true, false);
4025
4026         // WARNING:
4027         //      When no surface, it is needed to invalidated.
4028         //
4029         if (unlikely(!NEED_SURFACE(&child)))
4030         {
4031                 child.ExposeRectangle(null, true);
4032         }
4033
4034         //
4035         // Because tree hierarchy is not a property, VE hierarchy tree changes are not
4036         // notified by property observer. So, we invoke method in presentation VE directly.
4037         //
4038
4039         if (!IS_PRESENTATION(this))
4040         {
4041                 child.UpdatePresentationWhenZOrderChanged(pReference, above);
4042
4043                 if(!sameParent) // when child was moved to same parent, don't have to detach and attach to parent.
4044                 {
4045                         if (child.GetSharedData().pEventListener != null)
4046                         {
4047                                 child.InvokeOnAttached();
4048                         }
4049
4050                         if (GetSharedData().pEventListener != null)
4051                         {
4052                                 InvokeOnChildAttached(child);
4053                         }
4054                 }
4055         }
4056         else
4057         {
4058                 if (likely(GetSharedData().pNativeNode) && likely(child.GetSharedData().pNativeNode))
4059                 {
4060                         _VisualElementImpl* pReferenceNode = null;
4061
4062                         if (indexInsert > 0)
4063                         {
4064                                 pReferenceNode = __children.GetChildAt(indexInsert - 1);
4065                         }
4066
4067                         // exceptional case:  the pRefenreceNode is null and indexInsert are more than __children.count() + 1, then this case is something wrong.
4068                         // normal case : when pReferenceNode is null , indexInsert has 0 or more small value.
4069
4070                         GetSharedData().pNativeNode->InsertChild(
4071                                 *child.GetSharedData().pNativeNode,
4072                                 (pReferenceNode ? pReferenceNode->GetSharedData().pNativeNode : null),
4073                                 (pReferenceNode ? true : false)
4074                         );
4075                 }
4076         }
4077
4078         return E_SUCCESS;
4079 }
4080
4081 result
4082 _VisualElementImpl::UpdatePresentationWhenCustomPropertyChanged(const String& property, const Variant& value)
4083 {
4084         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4085         result r = E_SUCCESS;
4086
4087         if (IS_NEEDED_UPDATE_PRESENTATION(this))
4088         {
4089
4090                 Variant oldV = __pPresentation->InvokeOnGetPropertyRequested(property);
4091
4092                 if(CreateImplicitAnimationIfNeeded(property,value,oldV, NULL) == false)
4093                 {
4094                         r = __pPresentation->InvokeOnSetPropertyRequested(property, value);
4095                 }
4096         }
4097         return r;
4098 }
4099
4100 void
4101 _VisualElementImpl::UpdatePresentationWhenZOrderChanged(const _VisualElementImpl* pReferenceModel, bool above)
4102 {
4103         if(!IS_MODEL(this) || !__pParent)
4104         {
4105                 return;
4106         }
4107
4108         _VisualElementImpl* pReferencePresenter = (pReferenceModel ? (pReferenceModel->__pPresentation ? pReferenceModel->__pPresentation : null) : null);
4109
4110         if (likely(__pParent->__pPresentation) && likely(__pPresentation))
4111         {
4112                 __pParent->__pPresentation->ChangeZOrder(*__pPresentation, pReferencePresenter, above, _zOrderGroup);
4113         }
4114 }
4115
4116
4117
4118 result
4119 _VisualElementImpl::RemoveChildWithoutReconfiguring(int indexChild, bool invalidate)
4120 {
4121         SysTryReturnResult(NID_UI_ANIM, indexChild >= 0 && indexChild < __children.GetCount(), E_OBJ_NOT_FOUND, "There is no VisualElement at %d th index.", indexChild);
4122
4123         _VisualElementImpl* pChild = __children.GetChildAt(indexChild);
4124         SysTryReturnResult(NID_UI_ANIM, pChild, E_OBJ_NOT_FOUND, "There is no VisualElement at %d th index.", indexChild);
4125
4126
4127         //SysLog(NID_UI_ANIM, "Remove child %p(%d)", pChild, indexChild);
4128         __children.RemoveAt(indexChild);
4129         pChild->__pParent = null;
4130 //      pChild->__ClearHierarchyInfo();
4131
4132
4133         if (!IS_PRESENTATION(this))
4134         {
4135                 // removed element need not invalidation !
4136                 if (invalidate)
4137                 {
4138                         if (NEED_SURFACE(pChild))
4139                         {
4140                                 pChild->ExposeRectangle(null, false);
4141                         }
4142                         else
4143                         {
4144                                 pChild->InvalidateVisibleRectToRenderTarget(null);
4145                         }
4146                 }
4147         }
4148         else
4149         {
4150                 if (GetSharedData().pNativeNode && pChild->GetSharedData().pNativeNode)
4151                 {
4152                         GetSharedData().pNativeNode->RemoveChild(*pChild->GetSharedData().pNativeNode);
4153                 }
4154         }
4155
4156         // WARNING:
4157         //      Because some properties such as root, visible rect and etc. can be accessed detached, invalidating is needed here !
4158         //      (Will be invalidated again on attaching)
4159         //
4160         pChild->InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
4161
4162         return E_SUCCESS;
4163 }
4164
4165 result
4166 _VisualElementImpl::CreateElementTreeForDetachImplicitAnimation(_VisualElementImpl& child)
4167 {
4168         result r = E_SYSTEM;
4169
4170         VisualElement* pRoot = child.CreateElementForImplicitAnimationN();
4171         if (pRoot == null)
4172         {
4173                 return r;
4174         }
4175
4176         pRoot->_pVisualElementImpl->SetInternal(true);
4177
4178 #if defined(SUPPORT_CUSTOMIZING_ATTACH_DETACH_ANIMATION)
4179         VisualElementAnimation* pAnimation = child.InvokeCreateAnimationForProperty(*pVePropActionDetach);
4180 #else
4181         VisualElementPropertyAnimation* pAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4182         pAnimation->SetPropertyName(*pVePropOpacity);
4183         pAnimation->SetEndValue(Variant(0.0f));
4184 #endif
4185         if (pAnimation)
4186         {
4187                 _VisualElementImplicitAnimationEventListener* pListener = new (std::nothrow) _VisualElementImplicitAnimationEventListener();
4188                 if (pListener)
4189                 {
4190                         pAnimation->SetVisualElementAnimationStatusEventListener(pListener);
4191
4192                         r = pRoot->AddAnimation(*pVePropActionDetach, *pAnimation);
4193                         if (r == E_SUCCESS)
4194                         {
4195                                 if (!GetPublic())
4196                                 {
4197                                         return E_SYSTEM;
4198                                 }
4199
4200                                 r = GetPublic()->AttachChild(*pRoot);
4201                                 if (r == E_SUCCESS)
4202                                 {
4203                                         delete pAnimation;
4204
4205                                         return r;
4206                                 }
4207                         }
4208
4209                         delete pListener;
4210                 }
4211
4212                 delete pAnimation;
4213         }
4214
4215         return r;
4216 }
4217
4218 VisualElement*
4219 _VisualElementImpl::CreateElementForImplicitAnimationN(void) const
4220 {
4221         VisualElement* pElement = new (std::nothrow) VisualElement(*GetPublic());
4222         if (pElement == null)
4223         {
4224                 return null;
4225         }
4226
4227         result r = pElement->Construct();
4228         if (r != E_SUCCESS)
4229         {
4230                 pElement->Destroy();
4231                 return null;
4232         }
4233
4234         pElement->SetImplicitAnimationEnabled(false);
4235
4236         if (HAVE_SURFACE(this))
4237         {
4238                 VisualElementSurface* pSurface = GetSurfaceN();
4239                 if (pSurface)
4240                 {
4241                         pElement->SetSurface(pSurface);
4242                         delete pSurface;
4243                 }
4244         }
4245
4246         int count = __children.GetCount();
4247         for (int i = 0; i < count; i++)
4248         {
4249                 _VisualElementImpl* pVisualElementImpl = __children.GetChildAt(i);
4250                 if (likely(pVisualElementImpl))
4251                 {
4252                         r = pElement->AttachChild(*pVisualElementImpl->CreateElementForImplicitAnimationN());
4253                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4254                 }
4255         }
4256
4257         return pElement;
4258
4259 CATCH:
4260         delete pElement;
4261         return null;
4262 }
4263
4264
4265 result
4266 _VisualElementImpl::RemoveChild(_VisualElementImpl& child, bool deallocate)
4267 {
4268         //SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4269         SysTryReturnResult(NID_UI_ANIM, child.__isAllowedTreeModification == true, E_INVALID_OPERATION, "Z-order cannot be modified inside the OnAttached() or OnDetached() method of VisualElementEventListener.");
4270
4271         int indexChild = GetChildIndex(child);
4272         SysTryReturnResult(NID_UI_ANIM, indexChild >= 0, E_OBJ_NOT_FOUND, "child is not a child of this instance.");
4273
4274         if (!IS_PRESENTATION(this))
4275         {
4276
4277                 VE_DELEGATE(this, InvokeOnChildDetaching, child);
4278
4279                 // IMPORTANT! When destroying, don't have to invoke OnDetached and OnDetaching after invoked OnDestructing.
4280                 // call OnDestructing  -> call OnDetaching it is ambiguous operation
4281                 // it is called by RemoveFromParent() method, so pChild is destroying currently.
4282                 if (!child.__isDestroying)
4283                 {
4284                         VE_DELEGATE(&child, InvokeOnDetaching);
4285                 }
4286         }
4287
4288         result r = RemoveChildWithoutReconfiguring(indexChild, true);
4289         if (unlikely(r != E_SUCCESS))
4290         {
4291                 return E_OBJ_NOT_FOUND;
4292         }
4293
4294         if (!IS_PRESENTATION(this) && (_AnimationManager::GetInstance()->IsImplicitAnimationEnabled()
4295                 && child.__isImplicitAnimationEnabled) && child.IsAncestorDestroying() == false)
4296         {
4297                 r = CreateElementTreeForDetachImplicitAnimation(child);
4298                 if (unlikely(r != E_SUCCESS))
4299                 {
4300                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Dummy VisualElement cannot be attached.");
4301                 }
4302         }
4303
4304         //
4305         // Because tree hierarchy is not a property, VE hierarchy tree changes are not
4306         // notified by property observer. So, we invoke method in presentation VE directly.
4307         //
4308         if (!IS_PRESENTATION(this))
4309         {
4310
4311                 if (likely(__pPresentation) && likely(child.GetPresentation()))
4312                 {
4313                         __pPresentation->RemoveChild(*child.GetPresentation(), deallocate);
4314                 }
4315
4316                 // IMPORTANT! When destroying, don't have to invoke OnDetached and OnDetaching after invoked OnDestructing.
4317                 // call OnDestructing  -> call OnDetaching it is ambiguous operation
4318                 // it is called by RemoveFromParent() method, so pChild is destroying currently.
4319                 if (!child.__isDestroying && child.GetSharedData().pEventListener != null)
4320                 {
4321                         child.InvokeOnDetached(*this);
4322                 }
4323
4324                 if (GetSharedData().pEventListener != null)
4325                 {
4326                         InvokeOnChildDetached(child);
4327                 }
4328         }
4329
4330         // TODO:
4331         //      DEALLOCATE !!!
4332         //
4333
4334         return E_SUCCESS;
4335 }
4336
4337 result
4338 _VisualElementImpl::RemoveAllChild(void)
4339 {
4340         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4341         return E_SUCCESS;
4342 }
4343
4344
4345 void
4346 _VisualElementImpl::RebuildNativeNodeTree(_VisualElementImpl& parent)
4347 {
4348         if (!IS_PRESENTATION(this))
4349         {
4350                 return;
4351         }
4352
4353         _INativeNode* pNode = GetNativeNode();
4354         _INativeNode* pParentNode = parent.GetNativeNode();
4355
4356         if (!pNode || !pParentNode)
4357         {
4358                 return;
4359         }
4360
4361         pNode->RebuildIfNeeded(*pParentNode);
4362
4363 //TODO : must check ,don't you need to rebuild???
4364 //      RebuildCoordinates();
4365
4366         const int nativeProps = _VisualElementImpl::HIERARCHY_PROPERTY_COORDINATES
4367                                                         | _VisualElementImpl::HIERARCHY_PROPERTY_OPACITY
4368                                                         | _VisualElementImpl::HIERARCHY_PROPERTY_CONTENTOPACITY
4369                                                         | _VisualElementImpl::HIERARCHY_PROPERTY_CONTENTBOUNDS;
4370
4371
4372         InvalidateHierarchyProps(nativeProps, false, false);
4373
4374         int count = __children.GetCount();
4375         for ( int i = 0 ; i < count ; i++ )
4376         {
4377                 _VisualElementImpl* pVe = __children.GetChildAt(i);
4378                 if (pVe)
4379                 {
4380                         pVe->RebuildNativeNodeTree(*this);
4381                         _INativeNode* pChildNode = pVe->GetNativeNode();
4382                         pNode->InsertChild(*pChildNode,null, true);
4383                 }
4384         }
4385
4386 }
4387
4388
4389 Tizen::Base::String
4390 _VisualElementImpl::GetName(void) const
4391 {
4392         ClearLastResult();
4393
4394         return GetSharedData().name;
4395 }
4396
4397 result
4398 _VisualElementImpl::SetName(const Tizen::Base::String& name)
4399 {
4400         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4401         result r = InvokeOnSetPropertyRequested(*pVePropName, Variant(name));
4402         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
4403
4404         return r;
4405 }
4406
4407 Variant
4408 _VisualElementImpl::GetNameProperty(void) const
4409 {
4410         ClearLastResult();
4411
4412         return Variant(GetSharedData().name);
4413 }
4414
4415 result
4416 _VisualElementImpl::SetNameProperty(const Variant& v)
4417 {
4418         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_STRING, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
4419
4420         const Tizen::Base::String& name = v.ToString();
4421         if (name == GetSharedData().name)
4422         {
4423                 return E_SUCCESS;
4424         }
4425
4426         GetSharedData().name = name;
4427
4428         return E_SUCCESS;
4429 }
4430
4431 result
4432 _VisualElementImpl::SetUserData(void* pUserData)
4433 {
4434         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4435
4436         GetSharedData().pUserData = pUserData;
4437
4438         return E_SUCCESS;
4439 }
4440
4441 void*
4442 _VisualElementImpl::GetUserData(void) const
4443 {
4444         ClearLastResult();
4445
4446         return GetSharedData().pUserData;
4447 }
4448
4449 _VisualElementImpl*
4450 _VisualElementImpl::GetChild(const Tizen::Base::String& name, bool searchAllDescendants) const
4451 {
4452         ClearLastResult();
4453
4454         int count = __children.GetCount();
4455
4456         // for performance, look children directly
4457         for (int i = 0; i < count; i++)
4458         {
4459                 const _VisualElementImpl* pChild = __children.GetChildAt(i);
4460                 if (unlikely(pChild->GetSharedData().name == name))
4461                 {
4462                         return const_cast< _VisualElementImpl* >(pChild);
4463                 }
4464         }
4465
4466         if (searchAllDescendants)
4467         {
4468                 for (int i = 0; i < count; i++)
4469                 {
4470                         const _VisualElementImpl* pChild = __children.GetChildAt(i)->GetChild(name, true);
4471                         if (likely(pChild))
4472                         {
4473                                 return const_cast< _VisualElementImpl* >(pChild);
4474                         }
4475                 }
4476         }
4477
4478         SetLastResult(E_OBJ_NOT_FOUND);
4479
4480         return null;
4481 }
4482
4483 FloatRectangle
4484 _VisualElementImpl::GetVisibleRect(void) const
4485 {
4486         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4487
4488         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4489                 pThis->RebuildCoordinates();
4490
4491         if (!IsVisibleI())
4492                 return FloatRectangle();
4493
4494         if (likely(__visibleRectValid))
4495                 return __visibleRect;
4496
4497         if (__pClipSource)
4498         {
4499                 FloatRectangle parentVisibleRect(__pClipSource->GetVisibleRect());
4500                 ConvertCoordinates(parentVisibleRect, __pClipSource);
4501                 pThis->__visibleRect = parentVisibleRect.GetIntersection(__visibleRect);
4502         }
4503
4504         pThis->__visibleRectValid = true;
4505
4506         return __visibleRect;
4507 }
4508
4509 FloatRectangle
4510 _VisualElementImpl::GetDrawableRect(void) const
4511 {
4512         // If VE has backing-buffer, visible status is not important for drawing...
4513         bool needSurface = NEED_SURFACE(this);
4514
4515         if (unlikely(!needSurface))
4516         {
4517                 return FloatRectangle();
4518         }
4519
4520         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4521         {
4522                 _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4523                 pThis->RebuildCoordinates();
4524         }
4525
4526         // WARNING:
4527         //      Even when surface exists, the size might be invalidated by changing bounds.
4528         //
4529         if (HAVE_SURFACE(this) && GetSharedData().fixedSurfaceSize)
4530         {
4531                 return FloatRectangle(0.0f, 0.0f, GetSharedData().pSurface->GetSizeF().width, GetSharedData().pSurface->GetSizeF().height);
4532         }
4533
4534         return FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height);
4535 }
4536
4537 float
4538 _VisualElementImpl::GetOpacityFromRoot(void) const
4539 {
4540         float opacity = __contentOpacity * __opacity * __showOpacity;
4541         const _VisualElementImpl* pElement = __pParent;
4542         while (pElement)
4543         {
4544                 if (!VE_VISIBLE(pElement))
4545                 {
4546                         return 0.0f;
4547                 }
4548
4549                 opacity *= pElement->__opacity * pElement->__showOpacity;
4550                 pElement = pElement->__pParent;
4551         }
4552
4553         return opacity;
4554 }
4555
4556 const FloatRectangle&
4557 _VisualElementImpl::GetBoundingBoxI(void) const
4558 {
4559         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4560
4561         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4562         {
4563                 pThis->RebuildCoordinates();
4564         }
4565
4566         if (unlikely(!__boundingBoxValid))
4567         {
4568                 float x[4] = { 0.0f, __bounds.width, 0.0f, __bounds.width };
4569                 float y[4] = { 0.0f, 0.0f, __bounds.height, __bounds.height };
4570                 CalculateBoundingBox(x, y, pThis->__boundingBox);
4571
4572                 pThis->__boundingBoxValid = true;
4573         }
4574
4575         return __boundingBox;
4576 }
4577
4578 const FloatMatrix4&
4579 _VisualElementImpl::GetMatrixToSuper(void) const
4580 {
4581         if (unlikely(__matrixToSuperValid))
4582                 return __matrixToSuper;
4583
4584         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4585
4586         pThis->__matrixToSuperValid = true;
4587
4588         if (unlikely(__pParent == null))
4589         {
4590                 _MatrixUtilSetIdentity(pThis->__matrixToSuper);
4591                 return __matrixToSuper;
4592         }
4593
4594         const bool needSurface = NEED_SURFACE(this);
4595
4596         // apply subprojection && translation
4597         if (likely(needSurface))
4598         {
4599                 MatrixUtilCopy(pThis->__matrixToSuper, __pParent->__childrenTransform);
4600                 _MatrixUtilTranslate(pThis->__matrixToSuper, __bounds.x, __bounds.y, __zPosition);
4601         }
4602         else
4603         {
4604                 _MatrixUtilSetTranslation(pThis->__matrixToSuper, __bounds.x, __bounds.y, __zPosition);
4605         }
4606
4607
4608         // apply transform
4609         if (likely(needSurface))
4610         {
4611                 if (likely(__decomposedTransform.GetMatrixType() != MATRIX4_Identity))
4612                 {
4613                         bool needAnchor = (unlikely(__anchorZ != 0.0f) || unlikely(__anchor.x != 0.0f) || unlikely(__anchor.y != 0.0f));
4614                         if (unlikely(needAnchor))
4615                                 _MatrixUtilTranslate(pThis->__matrixToSuper, __anchor.x * __bounds.width, __anchor.y * __bounds.height, __anchorZ);
4616
4617                         _MatrixUtilMultiply(pThis->__matrixToSuper, __matrixToSuper, __transform);
4618
4619                         if (unlikely(needAnchor))
4620                                 _MatrixUtilTranslate(pThis->__matrixToSuper, -__anchor.x * __bounds.width, -__anchor.y * __bounds.height, -__anchorZ);
4621                 }
4622         }
4623
4624         return __matrixToSuper;
4625 }
4626
4627 const FloatMatrix4&
4628 _VisualElementImpl::GetMatrixToTop(void) const
4629 {
4630         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4631
4632         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4633         {
4634                 pThis->RebuildCoordinates();
4635         }
4636
4637
4638         if (unlikely(!__matrixToTopValid))
4639         {
4640                 _MatrixUtilMultiply(pThis->__matrixToTop, __pParent->GetMatrixToTop(), GetMatrixToSuper());
4641                 pThis->__matrixToTopValid = true;
4642         }
4643
4644         return __matrixToTop;
4645 }
4646
4647 const FloatMatrix4&
4648 _VisualElementImpl::GetMatrixFromTop(void) const
4649 {
4650         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4651
4652         if (IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES))
4653         {
4654                 pThis->RebuildCoordinates();
4655         }
4656
4657         if (!__matrixFromTopValid)
4658         {
4659                 MatrixUtilCopy(pThis->__matrixFromTop, GetMatrixToTop());
4660                 pThis->__matrixFromTopInvertible = _MatrixUtilInvert(pThis->__matrixFromTop);
4661                 pThis->__matrixFromTopValid = true;
4662         }
4663
4664         return __matrixFromTop;
4665 }
4666
4667 FloatMatrix4
4668 _VisualElementImpl::CalcMatrixToBase(const _VisualElementImpl& base) const
4669 {
4670         if (this == &base)
4671                 return FloatMatrix4();
4672
4673         FloatMatrix4 matrixToBase(GetMatrixToSuper());
4674
4675         const _VisualElementImpl* pParent = GetParent();
4676         if (pParent)
4677         {
4678                 pParent = pParent->GetParent();
4679                 while (pParent)
4680                 {
4681                         _MatrixUtilMultiply(matrixToBase, pParent->GetMatrixToSuper(), matrixToBase);
4682                         pParent = pParent->GetParent();
4683                 }
4684         }
4685
4686         return matrixToBase;
4687 }
4688
4689 const FloatMatrix4&
4690 _VisualElementImpl::GetMatrixToClipSource(void) const
4691 {
4692         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4693
4694         if (IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES))
4695         {
4696                 pThis->RebuildCoordinates();
4697         }
4698
4699
4700         if (unlikely(!__matrixToClipSourceValid))
4701         {
4702                 if (likely(__pParent))
4703                 {
4704                         if (__pParent->__isClipChildren)
4705                         {
4706                                 MatrixUtilCopy(pThis->__matrixToClipSource, GetMatrixToSuper());
4707                         }
4708                         else
4709                         {
4710                                 _MatrixUtilMultiply(pThis->__matrixToClipSource, __pParent->GetMatrixToClipSource(), GetMatrixToSuper());
4711                         }
4712                 }
4713                 else
4714                 {
4715                         _MatrixUtilSetIdentity(pThis->__matrixToClipSource);
4716                 }
4717
4718                 pThis->__matrixToClipSourceValid = true;
4719         }
4720
4721         return __matrixToClipSource;
4722 }
4723
4724 void
4725 _VisualElementImpl::InvalidateVisibleRectToRenderTarget(const FloatRectangle* pDirtyRectangle)
4726 {
4727         if (unlikely(GetSharedData().invalidationLockCount > 0))
4728                 return;
4729
4730         if (!IsDrawingObject())
4731                 return;
4732
4733         FloatRectangle bounds;
4734
4735         bounds = __pPresentation->GetVisibleRect();
4736         if (pDirtyRectangle)
4737         {
4738                 bounds = bounds.GetIntersection(*pDirtyRectangle);
4739         }
4740
4741         if (!bounds.IsEmpty())
4742         {
4743                 _VisualElementImpl* pRenderTarget = __pPresentation->GetRenderTarget();
4744                 if (pRenderTarget)
4745                 {
4746                         pRenderTarget->ConvertCoordinates(bounds, this);
4747                         pRenderTarget->InvalidateRectangleI(&bounds);
4748                 }
4749         }
4750 }
4751
4752 void
4753 _VisualElementImpl::RebuildCoordinates(void)
4754 {
4755         if (unlikely(!IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4756         {
4757                 return;
4758         }
4759
4760         SetPropsValidaty(HIERARCHY_PROPERTY_COORDINATES, 0);
4761
4762         __visibleRect.x = 0.0f;
4763         __visibleRect.y = 0.0f;
4764         __visibleRect.width = __bounds.width;
4765         __visibleRect.height = __bounds.height;
4766
4767
4768         if (unlikely(!__pParent))
4769         {
4770                 // FIXME:
4771                 //      Need to allowing transform to root element !
4772
4773                 _MatrixUtilSetIdentity(__matrixToTop);
4774                 _MatrixUtilSetIdentity(__matrixFromTop);
4775                 _MatrixUtilSetIdentity(__matrixToClipSource);
4776                 __pClipSource = null;
4777
4778                 GetMatrixToSuper();
4779
4780                 RectUtilCopy(__boundingBox, __bounds);
4781                 RectUtilCopy(__boundingBoxToClipSource, __bounds);
4782
4783                 _RootVisualElement* pRoot = dynamic_cast< _RootVisualElement* >(__pPublicInstance);
4784
4785                 if (likely(pRoot))
4786                 {
4787                         __pRoot = pRoot->_pVisualElementImpl;
4788                 }
4789                 else
4790                 {
4791                         __pRoot = null;
4792                 }
4793
4794                 __needTransform = false;
4795                 __needClipForUntransformed = false;
4796
4797
4798                 __matrixFromTopValid = true;
4799                 __matrixToTopValid = true;
4800                 __matrixToClipSourceValid = true;
4801                 __matrixToSuperValid = true;
4802
4803                 __boundingBoxValid = true;
4804                 __visibleRectValid = true;
4805         }
4806         else
4807         {
4808                 if (unlikely(__pParent->IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4809                 {
4810                         __pParent->RebuildCoordinates();
4811                 }
4812
4813                 __pRoot = __pParent->__pRoot;
4814
4815                 Matrix4Type transformType = __decomposedTransform.GetMatrixType();
4816                 const Matrix4Type parentChildrenTransformType = __pParent->__decomposedChildrenTransform.GetMatrixType();
4817
4818                 if (parentChildrenTransformType > MATRIX4_Translation)
4819                         transformType = MATRIX4_Generic;
4820
4821
4822                 if (unlikely(__pParent->__isClipChildren))
4823                 {
4824                         __pClipSource = __pParent;
4825
4826                         __needTransform = (transformType > MATRIX4_Translation);
4827                         if (likely(!__needTransform))
4828                         {
4829                                 __boundingBoxToClipSource.x = __bounds.x + __transform.matrix[3][0];
4830                                 __boundingBoxToClipSource.y = __bounds.y + __transform.matrix[3][1];
4831                                 __boundingBoxToClipSource.width = __bounds.width;
4832                                 __boundingBoxToClipSource.height = __bounds.height;
4833                         }
4834                 }
4835                 else
4836                 {
4837                         __pClipSource = __pParent->__pClipSource;
4838
4839                         if (unlikely(transformType > MATRIX4_Translation))
4840                                 __needTransform = true;
4841                         else
4842                                 __needTransform = __pParent->__needTransform;
4843
4844                         if (likely(!__needTransform))
4845                         {
4846                                 __boundingBoxToClipSource.x = __pParent->__boundingBoxToClipSource.x + __bounds.x + __transform.matrix[3][0];
4847                                 __boundingBoxToClipSource.y = __pParent->__boundingBoxToClipSource.y + __bounds.y + __transform.matrix[3][1];
4848                                 __boundingBoxToClipSource.width = __bounds.width;
4849                                 __boundingBoxToClipSource.height = __bounds.height;
4850 #if 0
4851                                 if (unlikely(parentChildrenTransformType == MATRIX4_Translation))
4852                                 {
4853                                         __boundingBoxToClipSource.x += __pParent->__childrenTransform.matrix[3][0];
4854                                         __boundingBoxToClipSource.y += __pParent->__childrenTransform.matrix[3][1];
4855                                 }
4856 #endif
4857                         }
4858                 }
4859
4860                 if (likely(!__needTransform))
4861                 {
4862                         if (unlikely(parentChildrenTransformType == MATRIX4_Translation))
4863                         {
4864                                 __boundingBoxToClipSource.x += __pParent->__childrenTransform.matrix[3][0];
4865                                 __boundingBoxToClipSource.y += __pParent->__childrenTransform.matrix[3][1];
4866                         }
4867                 }
4868
4869                 __needClipForUntransformed = __pParent->__needClipForUntransformed;
4870                 if (likely(!__needClipForUntransformed) && likely(__pClipSource))
4871                 {
4872                         if (likely(__boundingBoxToClipSource.x >= 0.0f) &&
4873                                 likely(__boundingBoxToClipSource.y >= 0.0f) &&
4874                                 likely(__boundingBoxToClipSource.x + __boundingBoxToClipSource.width <= __pClipSource->__bounds.width) &&
4875                                 likely(__boundingBoxToClipSource.y + __boundingBoxToClipSource.height <= __pClipSource->__bounds.height))
4876                                 __needClipForUntransformed = false;
4877                         else
4878                                 __needClipForUntransformed = true;
4879                 }
4880                 else
4881                 {
4882                         __needClipForUntransformed = true;
4883                 }
4884
4885
4886                 __matrixFromTopValid = false;
4887                 __matrixToTopValid = false;
4888                 __matrixToClipSourceValid = false;
4889                 __matrixToSuperValid = false;
4890
4891                 __boundingBoxValid = false;
4892                 __visibleRectValid = false;
4893         }
4894 }
4895
4896 void
4897 _VisualElementImpl::RebuildVisibility(void)
4898 {
4899         const int mask = HIERARCHY_PROPERTY_COORDINATES | HIERARCHY_PROPERTY_SHOWSTATE | HIERARCHY_PROPERTY_OPACITY | HIERARCHY_PROPERTY_CONTENTOPACITY;
4900
4901         if (unlikely(!IsPropsInvalidated(mask)))
4902         {
4903                 return;
4904         }
4905
4906         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4907         {
4908                 RebuildCoordinates();
4909         }
4910
4911
4912         SetPropsValidaty(mask, 0);
4913
4914         if (unlikely(!__pParent))
4915         {
4916                 // FIXME:
4917                 //      Need to allowing transform to root element !
4918
4919                 if(!__isRoot)
4920                         __isVisible = false;
4921                 else
4922                         __isVisible = VE_VISIBLE(this);
4923         }
4924         else
4925         {
4926                 if (unlikely(__pParent->IsPropsInvalidated(mask)))
4927                 {
4928                         __pParent->RebuildVisibility();
4929                 }
4930
4931                 if (likely(__pParent->__isVisible))
4932                         __isVisible = VE_VISIBLE(this);
4933                 else
4934                         __isVisible = false;
4935         }
4936 }
4937
4938 void
4939 _VisualElementImpl::LockInvalidate(bool lock)
4940 {
4941         GetSharedData().LockInvalidate(lock);
4942 }
4943
4944 void
4945 _VisualElementImpl::InvalidateHierarchyPropsDownward(int invalidProps, bool broadcastToChildren, bool propagateToParentsOnly)
4946 {
4947         invalidProps &= HIERARCHY_PROPERTY_MASK;
4948
4949         __childrenNeedsUpdateProps |= invalidProps;
4950
4951         if (likely(!propagateToParentsOnly))
4952         {
4953                 SetPropsValidaty(0, invalidProps);
4954
4955                 if (likely(invalidProps & HIERARCHY_PROPERTY_COORDINATES))
4956                 {
4957                         __matrixFromTopValid = false;
4958                         __matrixToSuperValid = false;
4959                         __boundingBoxValid = false;
4960                 }
4961         }
4962
4963         if (unlikely(!broadcastToChildren))
4964         {
4965                 return;
4966         }
4967
4968         int count = __children.GetCount();
4969         for (int i = 0; i < count; i++)
4970         {
4971                 __children.GetChildAt(i)->InvalidateHierarchyPropsDownward(invalidProps, broadcastToChildren, propagateToParentsOnly);
4972         }
4973
4974         // may need update some attribute variables for other hierarchy properties
4975 }
4976
4977
4978 void
4979 _VisualElementImpl::InvalidateHierarchyProps(int invalidProps, bool broadcastToChildren, bool propagateToParentsOnly)
4980 {
4981         invalidProps &= HIERARCHY_PROPERTY_MASK;
4982
4983 //      // For model tree, it is not needed to invalidate children-opacity and show-state
4984 //      if (!IS_PRESENTATION(this))
4985 //      {
4986 //              invalidProps &= ~(HIERARCHY_PROPERTY_OPACITY | HIERARCHY_PROPERTY_SHOWSTATE);
4987 //      }
4988
4989         if (unlikely(!invalidProps))
4990         {
4991                 return;
4992         }
4993
4994         InvalidateHierarchyPropsDownward(invalidProps, broadcastToChildren, propagateToParentsOnly);
4995
4996         _VisualElementImpl* pElement = __pParent;       // WARNING: 'this' is updated in '__InvalidateHierarchyPropsDownward'
4997         while (pElement)
4998         {
4999                 pElement->__childrenNeedsUpdateProps |= invalidProps;
5000                 pElement = pElement->__pParent;
5001         }
5002 }
5003
5004 // HIERARCHY_PROPERTY_CONTENT is not handled here, but in drawing logic
5005 void
5006 _VisualElementImpl::RebuildHierarchyProps(int props, bool checkSurface, bool reconfSurfaceOnly)
5007 {
5008         if (likely(__pParent) && (unlikely(__pParent->IsPropsInvalidated(props)) || unlikely(__pParent->GetSharedData().NeedNativeReconfigure())))
5009         {
5010                 // WARNING:
5011                 //      'checkSurface' for parent will make surface !
5012                 __pParent->RebuildHierarchyProps(props, false, false);
5013         }
5014
5015
5016         // TBD: Recreating surface may have to be done in presentation layer (thread!)
5017         if (unlikely(checkSurface))
5018         {
5019                 if (likely(IsDrawingObject()))
5020                 {
5021                         ResetSurfaceIfNeeded(); // may invalidate GetSharedData().surfaceChanged
5022                 }
5023         }
5024
5025         const bool needApplyNatives = GetSharedData().NeedNativeReconfigure();
5026
5027         props &= HIERARCHY_PROPERTY_MASK;
5028         if (unlikely(!IsPropsInvalidated(props)) && likely(!checkSurface) && unlikely(needApplyNatives == 0))
5029         {
5030                 return;
5031         }
5032
5033         if (likely(props & HIERARCHY_PROPERTY_CONTENTBOUNDS) && likely(IsPropsInvalidated(HIERARCHY_PROPERTY_CONTENTBOUNDS)))
5034         {
5035                 SetPropsValidaty(HIERARCHY_PROPERTY_CONTENTBOUNDS, 0);
5036         }
5037
5038         if (likely(props & HIERARCHY_PROPERTY_COORDINATES) && likely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
5039         {
5040                 RebuildCoordinates();
5041                 //__SetPropsValidaty(HIERARCHY_PROPERTY_COORDINATES, 0); --> need not. __RebuildCoordinates will validate.
5042         }
5043
5044         // WARNING:
5045         //      'Visibility' should be checked after validating tree-hierarchy information.
5046         //      (For example, attaching/detaching may affect visibility.)
5047         const int mask = HIERARCHY_PROPERTY_OPACITY | HIERARCHY_PROPERTY_SHOWSTATE | HIERARCHY_PROPERTY_CONTENTOPACITY;
5048         if (unlikely((props & mask) != 0) && unlikely(IsPropsInvalidated(props & mask)))
5049         {
5050                 RebuildVisibility();
5051         }
5052
5053         if (likely(__pPresentation) && likely(needApplyNatives))
5054         {
5055                 if (unlikely(!IS_PRESENTATION(this)))
5056                 {
5057                         // WARNING:
5058                         //      In model, native nodes are updated only when the surface was changed.
5059                         //if (unlikely(GetSharedData().surfaceChanged))
5060                         {
5061                                 __pPresentation->FlushNativeChanges();
5062                         }
5063                 }
5064                 else
5065                 {
5066                         GetSharedData().NodeReconfigure(*__pPresentation, false);
5067                 }
5068         }
5069 }
5070
5071 void
5072 _VisualElementImpl::FlushNativeChanges(void)
5073 {
5074         if (unlikely(!IS_PRESENTATION(this)))
5075                 return;
5076
5077         if (likely(__pPresentation))
5078                 GetSharedData().NodeReconfigure(*__pPresentation, false);
5079 }
5080
5081 void
5082 _VisualElementImpl::UpdateHierarchyProps(void)
5083 {
5084         // WARNING:
5085         //      HIERARCHY_PROPERTY_CONTENT is not handled here, but in drawing logic.
5086         const int mask = HIERARCHY_PROPERTY_MASK;
5087
5088         if (unlikely((__childrenNeedsUpdateProps & mask) == 0 && GetSharedData().childrenSurfaceChanged == false))
5089                 return;
5090
5091         // Node will be reconfigured later(before OnDraw, or DrawRectangle, ...)
5092         if (likely(IsPropsInvalidated(mask)) || likely(GetSharedData().NeedNativeReconfigure()))
5093                 RebuildHierarchyProps(mask, false, false);
5094
5095         // WARNING:
5096         //      __childrenNeedsUpdateProps should be cleared *ONLY AFTER* flushing native nodes !
5097         __childrenNeedsUpdateProps &= ~mask;
5098         GetSharedData().childrenSurfaceChanged = false;
5099
5100         int count = __children.GetCount();
5101         for (int i = 0; i < count; i++)
5102         {
5103                 _VisualElementImpl* pChild = __children.GetChildAt(i);
5104                 if (likely((pChild->__childrenNeedsUpdateProps & mask) != 0 || pChild->GetSharedData().childrenSurfaceChanged == true))
5105                         pChild->UpdateHierarchyProps();
5106         }
5107 }
5108
5109 void
5110 _VisualElementImpl::ExposeRectangle(const FloatRectangle* pDirtyRectangle, bool invalidate)
5111 {
5112         if (unlikely(!IsDrawingObject()))
5113                 return;
5114
5115         if (unlikely(invalidate))
5116         {
5117                 InvalidateRectangleI(pDirtyRectangle);
5118         }
5119 }
5120
5121 result
5122 _VisualElementImpl::SetFlushNeeded(void)
5123 {
5124         FloatRectangle rect;
5125
5126         if (!IS_PRESENTATION(this))
5127         {
5128                 return __pPresentation->SetFlushNeeded();
5129         }
5130
5131         rect = __bounds;
5132         rect.SetPosition(0.0f, 0.0f);
5133
5134         if (likely(HAVE_SURFACE(this)))
5135         {
5136                 GetSharedData().pNativeNode->SetFlushNeeded();
5137         }
5138         else
5139         {
5140                 _VisualElementImpl* pRenderTarget = GetRenderTarget();
5141
5142                 if (likely(pRenderTarget && pRenderTarget->GetSharedData().pNativeNode))
5143                 {
5144                         pRenderTarget->ConvertCoordinates(rect, this);
5145                         pRenderTarget->GetSharedData().pNativeNode->SetFlushNeeded();
5146                 }
5147         }
5148
5149         return E_SUCCESS;
5150 }
5151
5152 result
5153 _VisualElementImpl::Flush(void)
5154 {
5155         if (likely(GetSharedData().pNativeNode))
5156         {
5157                 GetSharedData().pNativeNode->Flush();
5158         }
5159
5160         return E_SUCCESS;
5161 }
5162
5163 result
5164 _VisualElementImpl::InvalidateRectangle(const FloatRectangle* pRectangle)
5165 {
5166         return InvalidateRectangleI(pRectangle);
5167 }
5168
5169 result
5170 _VisualElementImpl::InvalidateRectangleI(const FloatRectangle* pRectangle)
5171 {
5172         SysTryReturnResult(NID_UI_ANIM, !GetSharedData().fixedSurfaceSize, E_INVALID_OPERATION, "VisualElement with User-Surface do not allow invalidating and redrawing.");
5173         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "Invalidating VisualElement should be performed on a model layer.");
5174
5175         if (unlikely(GetSharedData().invalidationLockCount > 0))
5176         {
5177                 return E_SUCCESS;
5178         }
5179
5180         FloatRectangle invRect;
5181
5182         if (unlikely(pRectangle))
5183         {
5184                 if (unlikely(pRectangle->IsEmpty()))
5185                 {
5186                         return E_SUCCESS;
5187                 }
5188
5189                 invRect = *pRectangle;
5190         }
5191         else
5192         {
5193                 invRect = __bounds;
5194                 invRect.SetPosition(0.0f, 0.0f);
5195         }
5196
5197         if (unlikely(invRect.IsEmpty()))
5198         {
5199                 return E_SUCCESS;
5200         }
5201
5202
5203         // WARNING:
5204         //      'GetUnion' method will not behave as our intention.
5205         //      If the parameter or self is empty, the union of rectangle should ignore it !
5206         //invRect = GetSharedData().invalidatedRegion.GetUnion(invRect);
5207         RectUtilUnion(invRect, GetSharedData().invalidatedRegion);
5208
5209
5210         // TODO:
5211         //      If new requested invalidate region is already included currently,
5212         //      we can skip the following calculations (but invalidating flags are STILL needed !)
5213
5214         _VisualElementImpl* pRenderTarget = GetRenderTarget();
5215
5216         if (likely(pRenderTarget == this))
5217         {
5218                 // Make invalidated area a bit larger to be aligned on the render target
5219                 RectUtilMakeIntegral(invRect);
5220         }
5221
5222         GetSharedData().invalidatedRegion = invRect;
5223
5224         _VisualElementImpl* pElement = this;
5225         while (pElement)
5226         {
5227                 pElement->GetSharedData().childrenInvalidated = true;
5228                 pElement = pElement->GetParent();
5229         }
5230         SetRootNeedsContentUpdate();
5231
5232         return E_SUCCESS;
5233 }
5234
5235 FloatRectangle
5236 _VisualElementImpl::GetInvalidatedRectangle(void) const
5237 {
5238         ClearLastResult();
5239
5240         if (IS_PRESENTATION(this))
5241         {
5242                 if (__pModel)
5243                 {
5244                         return __pModel->GetInvalidatedRectangle();
5245                 }
5246         }
5247
5248         return GetSharedData().invalidatedRegion;
5249 }
5250
5251 FloatRectangle
5252 _VisualElementImpl::GetUpdateRectangle(void) const
5253 {
5254         ClearLastResult();
5255
5256         return GetSharedData().updateRegion;
5257 }
5258
5259 bool
5260 _VisualElementImpl::IsOpaque(void) const
5261 {
5262         ClearLastResult();
5263
5264         if (HAVE_SURFACE(this))
5265         {
5266                 return IsSurfaceOpaque();
5267         }
5268
5269         return true;
5270 }
5271
5272 result
5273 _VisualElementImpl::Draw(void)
5274 {
5275         SysTryReturnResult(NID_UI_ANIM, IS_ATTACHED(this),  E_INVALID_STATE, "Drawing VisualElement should be attached to the root tree.");
5276         if (!IS_MODEL(this))
5277         {
5278                 //SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
5279         }
5280
5281         // WARNING:
5282         //      Not a good position to apply property changes into native(EFL) system.
5283         //      Because of no-compositor in VE, we cannot control each element's
5284         //      visibilities (show-state, bounds, opacity, etc.) !
5285         //      Is there any good idea ?
5286         //
5287 //      if (IS_PRESENTATION(this))
5288 //              __UpdateHierarchyProps();
5289
5290         if (unlikely(GetSharedData().childrenInvalidated))
5291         {
5292 //              if (unlikely(!IS_PRESENTATION(this)))
5293 //                      __UpdateHierarchyProps();
5294
5295                 //
5296                 // Drawing must be done from first opaque.
5297                 // But, because we assume all VE's are transparent, all drawings are done from root !!!
5298
5299                 _VisualElementImpl* pRenderTarget = GetRenderTarget();
5300                 bool needFullScreenDraw = __isRoot;
5301
5302                 if (unlikely(!pRenderTarget))
5303                 {
5304                         // On no render target, flush invalidated area from root
5305                         pRenderTarget = GetRoot();
5306                         SysTryReturnResult(NID_UI_ANIM, pRenderTarget, E_SYSTEM, "A system error has been occurred. This VisualElement doesn't have rendering target.");
5307                         needFullScreenDraw = true;
5308                 }
5309
5310
5311                 // WARNING
5312                 //      To minimize drawing area(with clip), use '__DrawRectangleIfNeeded'
5313                 //      To reduce drawing calls such as 'OnDraw', use '__DrawRectangle' directly
5314                 //
5315                 int maxScreenSize = _Max(_VisualElementCoordinateSystem::logScreenWidth, _VisualElementCoordinateSystem::logScreenHeight);
5316                 pRenderTarget->DrawRectangleIfNeeded(
5317                         needFullScreenDraw ? FloatRectangle(0.0f, 0.0f, maxScreenSize, maxScreenSize) : GetDrawableRect()
5318                 );
5319         }
5320
5321         if (IS_PRESENTATION(this))
5322                 UpdateHierarchyProps();
5323
5324         return E_SUCCESS;
5325 }
5326
5327 result
5328 _VisualElementImpl::DrawForAnimation(void)
5329 {
5330         if (!IS_ATTACHED(this))
5331         {
5332                 return E_SUCCESS;
5333         }
5334
5335         if (unlikely(GetSharedData().childrenInvalidated))
5336         {
5337                 _VisualElementImpl* pRenderTarget = GetRenderTarget();
5338                 pRenderTarget->DrawRectangle(GetSharedData().invalidatedRegion);
5339
5340                 if (likely(GetSharedData().childrenInvalidated == false))
5341                 {
5342                         return E_SUCCESS;
5343                 }
5344
5345                 _VisualElementImpl* pChild = null;
5346                 bool childrenNeedUpdate = false;
5347                 int count = __children.GetCount();
5348                 for (int i = 0; i < count; i++)
5349                 {
5350                         pChild = __children.GetChildAt(i);
5351                         if (!pChild || (pChild->GetSharedData().childrenInvalidated == false))
5352                         {
5353                                 continue;
5354                         }
5355
5356                         pChild->DrawForAnimation();
5357
5358                         if ((pChild->GetSharedData().childrenInvalidated))
5359                         {
5360                                 childrenNeedUpdate = true;
5361                         }
5362                 }
5363
5364                 // update 'needUpdate' flag regarding children only if no invalidated-region
5365                 if (GetSharedData().invalidatedRegion.IsEmpty())
5366                 {
5367                         if (childrenNeedUpdate)
5368                         {
5369                                 GetSharedData().childrenInvalidated = true;
5370                         }
5371                 }
5372         }
5373
5374         return E_SUCCESS;
5375 }
5376
5377 void
5378 _VisualElementImpl::DrawRectangleIfNeeded(const FloatRectangle& drawRect)
5379 {
5380         if (unlikely(!IsVisibleI()) || GetSharedData().childrenInvalidated == false)
5381         {
5382                 return;
5383         }
5384
5385         // WARNING:
5386         //      VE with surface redraws *ALL INVALIDATED* region !! --> TBD: make an option/flags for this???
5387         //
5388         FloatRectangle drawableRect;
5389
5390         if (NEED_SURFACE(this))
5391         {
5392                 // WARNING:
5393                 //      Redraw only if the request has some valid region to draw.
5394                 drawableRect = GetDrawableRect();
5395                 if (!drawRect.IsIntersected(drawableRect))
5396                         drawableRect.SetSize(0.0f, 0.0f);       // Make empty
5397         }
5398         else
5399         {
5400                 drawableRect = drawRect;
5401         }
5402
5403         DrawRectangle(drawableRect.GetIntersection(GetSharedData().invalidatedRegion));
5404
5405         //
5406         // needUpdate flag may be 'true' after drawring invalidated region.
5407         // This means that some children still need to be updated !
5408         //
5409         if (likely(GetSharedData().childrenInvalidated == false))
5410         {
5411                 return;
5412         }
5413
5414         //
5415         // Some children still need to update in case that invalidated rect of this
5416         // is smaller than 'drawRect' which can overlap the invalid rect of children
5417         //
5418
5419         //
5420         // Because user can do anything in drawing logic,
5421         // adding-reference may be safe.......
5422         //
5423         _VisualElementImpl* pChild = null;
5424         FloatRectangle updateRect, childBounds;
5425         bool childrenNeedUpdate = false;
5426         int count = __children.GetCount();
5427         for (int i = 0; i < count; i++)
5428         {
5429                 pChild = __children.GetChildAt(i);
5430                 if (!pChild || pChild->GetSharedData().childrenInvalidated == false)
5431                 {
5432                         continue;
5433                 }
5434
5435
5436                 // WARNING:
5437                 //      Draw all children with surface.
5438                 //      Children with empty invalidated region will ignore re-drawing.
5439
5440                 updateRect = drawRect;
5441                 pChild->ConvertCoordinates(updateRect, this);
5442
5443                 if (likely(NEED_SURFACE(pChild)))
5444                 {
5445                         pChild->DrawRectangleIfNeeded(updateRect);
5446                 }
5447                 else
5448                 {
5449                         childBounds = pChild->__pPresentation->__bounds;
5450                         childBounds.SetPosition(0.0f, 0.0f);
5451                         updateRect = updateRect.GetIntersection(childBounds);
5452                         if (unlikely(!updateRect.IsEmpty()))
5453                                 pChild->DrawRectangleIfNeeded(updateRect);
5454                 }
5455
5456                 if (pChild->GetSharedData().childrenInvalidated)
5457                 {
5458                         childrenNeedUpdate = true;
5459                 }
5460         }
5461
5462         // update 'needUpdate' flag regarding children only if no invalidated-region
5463         if (GetSharedData().invalidatedRegion.IsEmpty())
5464         {
5465                 if (childrenNeedUpdate)
5466                 {
5467                         GetSharedData().childrenInvalidated = true;
5468                 }
5469         }
5470 }
5471
5472 // TODO: change name(remove 'rectangle')
5473 void
5474 _VisualElementImpl::DrawRectangle(const FloatRectangle& drawRect)
5475 {
5476         if (unlikely(!GetRootPublic()) || unlikely(drawRect.IsEmpty()))
5477         {
5478                 return;
5479         }
5480
5481         //SysLog(NID_UI_ANIM, "DrawRectangle");
5482
5483         bool needDraw = false;
5484         bool fullValidated = false;
5485         FloatRectangle drawableRect(GetDrawableRect());
5486         FloatRectangle drawRectVisible(drawRect.GetIntersection(drawableRect));
5487         FloatRectangle invalidatedRectVisible(GetSharedData().invalidatedRegion.GetIntersection(drawableRect));
5488
5489         if (unlikely(!drawRectVisible.IsEmpty()))
5490         {
5491 #if 0
5492                 // Draw full-invalidated-content (not partial) if VE has surface.
5493                 if (likely(NEED_SURFACE(this)))
5494                         drawRectVisible = drawableRect;
5495 #endif
5496
5497                 needDraw = true;
5498         }
5499
5500         // WARNING:
5501         //      Make dirty/draw area a bit larger to be pixel-aligned and prevent drawing-artifacts caused by float-error.
5502         RectUtilMakeIntegral(drawRectVisible);
5503         RectUtilMakeIntegral(invalidatedRectVisible);
5504
5505         //      DO NOT USE drawRectVisible.Contains(invalidatedRectVisible))
5506         if (invalidatedRectVisible.IsEmpty() || (drawRectVisible.x <= invalidatedRectVisible.x &&
5507                                                                                         drawRectVisible.y <= invalidatedRectVisible.y &&
5508                                                                                         drawRectVisible.x + drawRectVisible.width >= invalidatedRectVisible.x + invalidatedRectVisible.width &&
5509                                                                                         drawRectVisible.y + drawRectVisible.height >= invalidatedRectVisible.y + invalidatedRectVisible.height))
5510         {
5511                 fullValidated = true;
5512         }
5513
5514
5515
5516         // WARNING:
5517         //      VisualElement with User-Set surface does not allow invalidating and redrawing.
5518         //      Because there should be no invalidated region in this case, checking User-Surface may redundant.
5519         //
5520         if (GetSharedData().fixedSurfaceSize)
5521         {
5522                 needDraw = false;
5523                 fullValidated = true;
5524                 drawRectVisible = GetSharedData().invalidatedRegion;
5525         }
5526
5527
5528         // WARNING:
5529         //      Set update region before 'CanDraw' and 'OnDraw' delegations to check real-update region
5530         //
5531         GetSharedData().updateRegion = drawRectVisible;
5532
5533         if (fullValidated)
5534         {
5535                 // WARNING:
5536                 //      Clear *BEFORE* drawing because 'OnDraw' may add invalidated regions...
5537                 //
5538                 GetSharedData().invalidatedRegion.SetBounds(0.0f, 0.0f, 0.0f, 0.0f); // SetEmpty()
5539                 GetSharedData().childrenInvalidated = false;
5540         }
5541
5542
5543         if (needDraw)
5544         {
5545                 if (!VE_DELEGATE(this, InvokePrepareDraw))
5546                 {
5547                         needDraw = false;
5548                 }
5549         }
5550
5551         if (needDraw)
5552         {
5553                 Canvas* pCanvas = GetCanvasN();
5554
5555                 if (pCanvas)
5556                 {
5557                         result r = pCanvas->SetClipBounds(FloatRectangle(drawRectVisible.x,
5558                                                                                                                 drawRectVisible.y,
5559                                                                                                                 drawRectVisible.width,
5560                                                                                                                 drawRectVisible.height));
5561                         if (IsFailed(r))
5562                         {
5563                                 SysLogException(NID_UI_ANIM, r, "[%s] Failed to set clip-bounds on canvas", GetErrorMessage(r));
5564                         }
5565
5566                         VE_DELEGATE(this, InvokeOnDraw, *pCanvas);
5567                         delete pCanvas;
5568                 }
5569
5570                 // WARNING:
5571                 //      Flushing canvas is done at GetCanvasN.
5572                 //
5573                 //SetFlushNeeded();
5574         }
5575
5576
5577         // Clear update region after drawing
5578         GetSharedData().updateRegion.SetBounds(0.0f, 0.0f, 0.0f, 0.0f);
5579
5580
5581         //
5582         // Because user can do anything in drawing logic,
5583         // adding-reference/copying-list may be safe.......
5584         //
5585         _VisualElementImpl* pChild = null;
5586         int count = __children.GetCount();
5587         bool childrenNeedUpdate = false;
5588         FloatRectangle childBounds;
5589         for (int i = 0; i < count; i++)
5590         {
5591                 pChild = __children.GetChildAt(i);
5592                 if (likely(!NEED_SURFACE(pChild)))
5593                 {
5594                         drawRectVisible = drawRect;
5595                         pChild->ConvertCoordinates(drawRectVisible, this);
5596                         childBounds = pChild->__pPresentation->__bounds;
5597
5598                         childBounds.SetPosition(0.0f, 0.0f);
5599
5600                         drawRectVisible = drawRectVisible.GetIntersection(childBounds);
5601                         if (likely(!drawRectVisible.IsEmpty()))
5602                                 pChild->DrawRectangle(drawRectVisible);
5603                 }
5604
5605                 if (pChild->GetSharedData().childrenInvalidated)
5606                 {
5607                         childrenNeedUpdate = true;
5608                 }
5609         }
5610
5611         //
5612         // If not all children have been validated during update,
5613         // we should not clear update flag to flush them later.
5614         //
5615         if (childrenNeedUpdate)
5616         {
5617                 GetSharedData().childrenInvalidated = true;
5618         }
5619 }
5620
5621 // for a cumstom property animation
5622 result
5623 _VisualElementImpl::SetPropertyI(const String& property, const Variant& value)
5624 {
5625         result r = E_SUCCESS;
5626
5627         if (likely(__pPublicInstance))
5628         {
5629                 r = __pPublicInstance->OnSetPropertyRequested(property, value);
5630                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
5631         }
5632
5633         return r;
5634 }
5635
5636 result
5637 _VisualElementImpl::InvokeOnSetPropertyRequested(const String& property, const Variant& value)
5638 {
5639         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
5640         result r = E_SUCCESS;
5641
5642         if (likely(__pPublicInstance))
5643         {
5644                 r = __pPublicInstance->OnSetPropertyRequested(property, value);
5645                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
5646         }
5647
5648         return r;
5649 }
5650
5651 int
5652 _VisualElementImpl::HitTestI(const FloatPoint& point)
5653 {
5654         if (!IsVisibleI())
5655         {
5656                 return HITTEST_NOWHERE;
5657         }
5658
5659         if (//NEED_SURFACE(&target) &&
5660                 !GetSharedData().isSurfaceOpaque &&
5661                 _FloatHardCompare(GetOpacityFromRoot(), 0.0f))
5662         {
5663                 return HITTEST_NOWHERE;
5664         }
5665
5666         if (!GetVisibleRect().Contains(point))
5667         {
5668                 return HITTEST_NOWHERE;
5669         }
5670
5671         _VisualElementImpl* pClipSource = GetClipSource();
5672         while (pClipSource)
5673         {
5674                 FloatPoint pt = point;
5675                 pClipSource->ConvertCoordinates(pt, this);
5676
5677                 if (!pClipSource->GetVisibleRect().Contains(pt))
5678                 {
5679                         return HITTEST_NOWHERE;
5680                 }
5681                 else
5682                 {
5683                         pClipSource = pClipSource->GetClipSource();
5684                 }
5685         }
5686
5687         return HITTEST_MATCH;
5688 }
5689
5690 _VisualElementImpl*
5691 _VisualElementImpl::GetChildAtPointI(const FloatPoint& point, int parentHitTest)
5692 {
5693         _VisualElementImpl* pHitTarget = null;
5694         FloatPoint hitPoint = point;
5695         int hitTest;
5696
5697         hitTest = VE_DELEGATE(this, InvokeHitTest, point);
5698         if ((hitTest & HITTEST_MATCH) != 0)
5699         {
5700                 // passed hittest
5701                 pHitTarget = this;
5702         }
5703
5704         if ((hitTest & HITTEST_NOMORECHILDREN) == 0)
5705         {
5706                 int count = __children.GetCount();
5707                 for (int i = count - 1; i >= 0; i--)    // from top to bottom
5708                 {
5709                         _VisualElementImpl* pChild = __children.GetChildAt(i);
5710                         if (!pChild)
5711                         {
5712                                 continue;
5713                         }
5714
5715                         FloatPoint childHitPoint = point;
5716                         pChild->ConvertCoordinates(childHitPoint, this);
5717
5718                         _VisualElementImpl* pChildHitTarget = pChild->GetChildAtPointI(childHitPoint, hitTest);
5719                         if (pChildHitTarget)
5720                         {
5721                                 pHitTarget = pChildHitTarget;
5722                                 hitPoint = childHitPoint;
5723                                 break;
5724                         }
5725                 }
5726         }
5727
5728
5729         if (pHitTarget)
5730         {
5731 //              point = hitPoint;
5732                 return pHitTarget;
5733         }
5734
5735         return null;
5736 }
5737
5738 // WARNING:
5739 //      Because Hit-Testing from self, clipping flags of self will be ignored.
5740 //
5741 _VisualElementImpl*
5742 _VisualElementImpl::GetChildAt(const FloatPoint& point)
5743 {
5744         _VisualElementImpl* pHitTarget = GetChildAtPointI(point, HITTEST_MATCH);
5745         if (unlikely(!pHitTarget))
5746         {
5747                 SetLastResult(E_OBJ_NOT_FOUND);
5748         }
5749         else
5750         {
5751                 ClearLastResult();
5752         }
5753
5754         return pHitTarget;
5755 }
5756
5757 result
5758 _VisualElementImpl::ScrollByPoint(const FloatPoint& pointOffset, bool scrollSelf)
5759 {
5760         if (_FloatCompare(pointOffset.x, 0.0f) && _FloatCompare(pointOffset.y, 0.0f))
5761         {
5762                 return E_SUCCESS;
5763         }
5764
5765         result r;
5766         FloatMatrix4 xform = __childrenTransform;
5767         FloatMatrix4 xformOrg = xform;
5768         FloatRectangle rectInvalidated;
5769
5770         _MatrixUtilTranslate(xform, pointOffset.x, pointOffset.y, 0.0f);
5771
5772         if (HAVE_SURFACE(this))
5773         {
5774                 int count = __children.GetCount();
5775
5776                 LockInvalidate(true);
5777                 for (int i = 0; i < count; i++)
5778                 {
5779                         __children.GetChildAt(i)->LockInvalidate(true);
5780                 }
5781
5782                 r = SetChildrenTransformMatrix(xform);
5783
5784                 LockInvalidate(false);
5785                 for (int i = 0; i < count; i++)
5786                 {
5787                         __children.GetChildAt(i)->LockInvalidate(false);
5788                 }
5789         }
5790         else
5791         {
5792                 r = SetChildrenTransformMatrix(xform);
5793         }
5794
5795         SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, E_SYSTEM, "Failed to translate matrix for scrolling ");
5796
5797         if (!NEED_SURFACE(this))
5798         {
5799                 InvalidateVisibleRectToRenderTarget(null);
5800         }
5801         else if (scrollSelf)
5802         {
5803                 Canvas* pCanvas = GetCanvasN(); // TODO: clip rect......
5804
5805                 if (pCanvas)
5806                 {
5807                         _CanvasImpl* pCanvasImpl = _CanvasImpl::GetInstance(*pCanvas);
5808                         if (pCanvasImpl)
5809                         {
5810                                 Point pointDest;
5811                                 Rectangle rectSource;
5812
5813                                 rectSource.SetBounds(0, 0, __bounds.width, __bounds.height);
5814
5815                                 rectInvalidated = __bounds;
5816                                 rectInvalidated.SetPosition(0.0f, 0.0f);
5817                                 if (pointOffset.x > 0)
5818                                 {
5819                                         rectSource.width -= pointOffset.x;
5820                                         pointDest.x = pointOffset.x;
5821                                         rectInvalidated.width = pointOffset.x;
5822                                 }
5823                                 else
5824                                 {
5825                                         rectSource.x += -pointOffset.x;
5826                                         rectSource.width -= -pointOffset.x;
5827                                         pointDest.x = 0;
5828                                         rectInvalidated.x = rectSource.width;
5829                                         rectInvalidated.width = -pointOffset.x;
5830                                 }
5831
5832                                 InvalidateVisibleRectToRenderTarget(&rectInvalidated);
5833
5834
5835                                 rectInvalidated = __bounds;
5836                                 rectInvalidated.SetPosition(0.0f, 0.0f);
5837                                 if (pointOffset.y > 0)
5838                                 {
5839                                         rectSource.height -= pointOffset.y;
5840                                         pointDest.y = pointOffset.y;
5841                                         rectInvalidated.height = pointOffset.y;
5842                                 }
5843                                 else
5844                                 {
5845                                         rectSource.y += -pointOffset.y;
5846                                         rectSource.height -= -pointOffset.y;
5847                                         pointDest.y = 0;
5848                                         rectInvalidated.y = rectSource.height;
5849                                         rectInvalidated.height = -pointOffset.y;
5850                                 }
5851
5852                                 InvalidateVisibleRectToRenderTarget(&rectInvalidated);
5853
5854
5855                                 r = pCanvasImpl->CopyEx(pointDest, *pCanvasImpl, rectSource);
5856                                 if (r != E_SUCCESS)
5857                                 {
5858                                         // revert...
5859                                         SysLogException(NID_UI_ANIM, r, "[%s] Can't copy area.", GetErrorMessage(r));
5860                                         SetChildrenTransformMatrix(xformOrg); // ???????????????????
5861                                 }
5862                                 else
5863                                 {
5864                                         SetFlushNeeded();
5865                                 }
5866                         }
5867
5868                         delete pCanvas;
5869                 }
5870         }
5871
5872         return r;
5873 }
5874
5875 result
5876 _VisualElementImpl::ConvertCoordinates(FloatPoint& point, const _VisualElementImpl* pFromElement) const
5877 {
5878         if (unlikely(this == pFromElement))
5879         {
5880                 return E_SUCCESS;
5881         }
5882
5883         _VisualElementImpl* pFromRoot = null;
5884         float x = point.x;
5885         float y = point.y;
5886         float z = 0.0f;
5887
5888         if (likely(pFromElement))
5889         {
5890                 pFromRoot = pFromElement->GetRoot();
5891                 SysTryReturnResult(NID_UI_ANIM, GetRoot() == pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement and pFromElement is not belong to the same tree.");
5892                 SysTryReturnResult(NID_UI_ANIM, pFromRoot || pFromElement->IsChildOf(*this) || IsChildOf(*pFromElement),
5893                                         E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement(%p) and pFromElement(%p) is not related.", this, pFromElement);
5894         }
5895         else
5896         {
5897                 pFromRoot = GetRoot();
5898                 SysTryReturnResult(NID_UI_ANIM, pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement is not attached to main tree.");
5899         }
5900
5901         const FloatMatrix4& toTopMatrix = (pFromElement ? pFromElement->GetMatrixToTop() : pFromRoot->GetMatrixToTop());
5902         _MatrixUtilTransform(toTopMatrix, &x, &y, &z);
5903
5904         if (this != pFromRoot)
5905         {
5906                 const FloatMatrix4& fromTopMatrix = GetMatrixFromTop();
5907
5908                 SysTryReturnResult(NID_UI_ANIM, __matrixFromTopInvertible, E_INVALID_OPERATION, "The matrix for this conversion is singular which has zero determinant.");
5909                 SysTryReturnResult(NID_UI_ANIM, fromTopMatrix.matrix[2][2] != 0, E_INVALID_OPERATION, "It is failed to calculate z of world-coordinate mapped x-y plane of depth==0");
5910
5911                 // WARNING:
5912                 //      We should calculate z of world-coordinate mapped x-y plane of depth==0 in VE coordinate !
5913                 z = -(fromTopMatrix.matrix[0][2] * x + fromTopMatrix.matrix[1][2] * y + fromTopMatrix.matrix[3][2]) / fromTopMatrix.matrix[2][2];
5914
5915                 _MatrixUtilTransform(fromTopMatrix, &x, &y, &z);
5916         }
5917
5918         point.SetPosition(x, y);   // z is omitted
5919
5920         return E_SUCCESS;
5921 }
5922
5923 result
5924 _VisualElementImpl::ConvertCoordinates(FloatRectangle& rectangle, const _VisualElementImpl* pFromElement) const
5925 {
5926         if (unlikely(this == pFromElement))
5927         {
5928                 return E_SUCCESS;
5929         }
5930
5931         _VisualElementImpl* pFromRoot = null;
5932         float x[4] = { rectangle.x, rectangle.x + rectangle.width, rectangle.x, rectangle.x + rectangle.width };
5933         float y[4] = { rectangle.y, rectangle.y, rectangle.y + rectangle.height, rectangle.y + rectangle.height };
5934         float z[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
5935
5936         if (likely(pFromElement))
5937         {
5938                 pFromRoot = pFromElement->GetRoot();
5939                 SysTryReturnResult(NID_UI_ANIM, GetRoot() == pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement and pFromElement is not belong to the same main tree.");
5940                 SysTryReturnResult(NID_UI_ANIM, pFromRoot || pFromElement->IsChildOf(*this) || IsChildOf(*pFromElement),
5941                                         E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement(%p) and pFromElement(%p) is not related.", this, pFromElement);
5942         }
5943         else
5944         {
5945                 pFromRoot = GetRoot();
5946                 SysTryReturnResult(NID_UI_ANIM, pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement is not attached to main tree.");
5947         }
5948
5949         const FloatMatrix4& toTopMatrix = (pFromElement ? pFromElement->GetMatrixToTop() : pFromRoot->GetMatrixToTop());
5950
5951         for (int i = 0; i < 4; i++)
5952         {
5953                 _MatrixUtilTransform(toTopMatrix, &x[i], &y[i], &z[i]);
5954         }
5955
5956         if (this != pFromRoot)
5957         {
5958                 const FloatMatrix4& fromTopMatrix = GetMatrixFromTop();
5959
5960                 SysTryReturnResult(NID_UI_ANIM, __matrixFromTopInvertible, E_INVALID_OPERATION, "The matrix for this conversion is singular which has zero determinant.");
5961                 SysTryReturnResult(NID_UI_ANIM, fromTopMatrix.matrix[2][2] != 0, E_INVALID_OPERATION, "It is failed to calculate z of world-coordinate mapped x-y plane of depth==0");
5962
5963                 for (int i = 0; i < 4; i++)
5964                 {
5965                         // WARNING:
5966                         //      We should calculate z of world-coordinate mapped x-y plane of depth==0 in VE coordinate !
5967                         z[i] = -(fromTopMatrix.matrix[0][2] * x[i] + fromTopMatrix.matrix[1][2] * y[i] + fromTopMatrix.matrix[3][2]) / fromTopMatrix.matrix[2][2];
5968                         _MatrixUtilTransform(fromTopMatrix, &x[i], &y[i], &z[i]);
5969                 }
5970
5971         }
5972
5973         CalculateBoundingBox(x, y, rectangle);
5974
5975         return E_SUCCESS;
5976 }
5977
5978 result
5979 _VisualElementImpl::ConvertCoordinates(float* x, float* y, float* z, int count, const _VisualElementImpl* pFromElement) const
5980 {
5981         if (unlikely(this == pFromElement) || unlikely(count <= 0))
5982         {
5983                 return E_SUCCESS;
5984         }
5985
5986         _VisualElementImpl* pFromRoot = null;
5987
5988         if (likely(pFromElement))
5989         {
5990                 pFromRoot = pFromElement->GetRoot();
5991                 SysTryReturnResult(NID_UI_ANIM, GetRoot() == pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement and pFromElement is not belong to the same main tree.");
5992                 SysTryReturnResult(NID_UI_ANIM, pFromRoot || pFromElement->IsChildOf(*this) || IsChildOf(*pFromElement),
5993                                         E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement(%p) and pFromElement(%p) is not related.", this, pFromElement);
5994         }
5995         else
5996         {
5997                 pFromRoot = GetRoot();
5998                 SysTryReturnResult(NID_UI_ANIM, pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement is not attached to main tree.");
5999         }
6000
6001         bool isUpwardConvertOnly = (pFromElement && pFromElement->IsChildOf(*this));
6002         const FloatMatrix4& toTopMatrix = (isUpwardConvertOnly ? pFromElement->CalcMatrixToBase(*this) :
6003                                                                                                                          pFromElement ? pFromElement->GetMatrixToTop() : pFromRoot->GetMatrixToTop());
6004
6005         for (int i = 0; i < count; i++)
6006         {
6007                 _MatrixUtilTransform(toTopMatrix, &x[i], &y[i], &z[i]);
6008         }
6009
6010         if (!isUpwardConvertOnly)
6011         {
6012                 const FloatMatrix4& fromTopMatrix = GetMatrixFromTop();
6013
6014                 SysTryReturnResult(NID_UI_ANIM, __matrixFromTopInvertible, E_INVALID_OPERATION, "The matrix for this conversion is singular which has zero determinant.");
6015                 SysTryReturnResult(NID_UI_ANIM, fromTopMatrix.matrix[2][2] != 0, E_INVALID_OPERATION, "It is failed to calculate z of world-coordinate mapped x-y plane of depth==0");
6016
6017                 for (int i = 0; i < count; i++)
6018                 {
6019                         // WARNING:
6020                         //      We should calculate z of world-coordinate mapped x-y plane of depth==0 in VE coordinate !
6021                         z[i] = -(fromTopMatrix.matrix[0][2] * x[i] + fromTopMatrix.matrix[1][2] * y[i] + fromTopMatrix.matrix[3][2]) / fromTopMatrix.matrix[2][2];
6022                         _MatrixUtilTransform(fromTopMatrix, &x[i], &y[i], &z[i]);
6023                 }
6024         }
6025
6026         return E_SUCCESS;
6027 }
6028
6029 FloatPoint3
6030 _VisualElementImpl::TransformVectorFromOrigin(const Tizen::Graphics::FloatPoint3& originPoint, const _VisualElementImpl* pOriginVisualElement) const
6031 {
6032         ClearLastResult();
6033
6034         if (unlikely(this == pOriginVisualElement))
6035         {
6036                 return FloatPoint3(originPoint);
6037         }
6038
6039         float x = originPoint.x;
6040         float y = originPoint.y;
6041         float z = originPoint.z;
6042
6043         _VisualElementImpl* pOriginRoot = pOriginVisualElement->GetRoot();
6044
6045         SysTryReturn(NID_UI_ANIM, GetRoot() == pOriginRoot, FloatPoint3(), E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement and originVisualElement is not belong to the same tree.");
6046         SysTryReturn(NID_UI_ANIM, pOriginRoot || pOriginVisualElement->IsChildOf(*this) || IsChildOf(*pOriginVisualElement),
6047                                 FloatPoint3(), E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement(%p) and originVisualElement(%p) is not related.", this, pOriginVisualElement);
6048
6049         const FloatMatrix4& toTopMatrix = pOriginVisualElement->GetMatrixToTop();
6050         _MatrixUtilTransform(toTopMatrix, &x, &y, &z);
6051
6052         if (this != pOriginRoot)
6053         {
6054                 const FloatMatrix4& fromTopMatrix = GetMatrixFromTop();
6055
6056                 SysTryReturn(NID_UI_ANIM, __matrixFromTopInvertible, FloatPoint3(), E_INVALID_OPERATION, "The matrix for this conversion is singular which has zero determinant.");
6057
6058                 _MatrixUtilTransform(fromTopMatrix, &x, &y, &z);
6059         }
6060
6061         return FloatPoint3(x, y, z);
6062 }
6063
6064 result
6065 _VisualElementImpl::CaptureI(Canvas& outputCanvas, const FloatRectangle& rectDest, _VisualElementImpl& reference, const FloatRectangle& rectRef, const FloatRectangle& clipRect, bool withChilren, int depth)
6066 {
6067         _CanvasImpl* pOutput = _CanvasImpl::GetInstance(outputCanvas);
6068
6069         SysTryReturnResult(NID_UI_ANIM, pOutput, E_INVALID_ARG, "Invalid argument(s) is used. Output canvas is invalid.");
6070         SysTryReturnResult(NID_UI_ANIM, GetRoot(), E_INVALID_STATE, "Invalid argument(s) is used. VisualElement is not attached to main tree.");
6071
6072         FloatRectangle bounds = __bounds;//GetDrawableRect();
6073
6074         bounds.x = 0.0f;
6075         bounds.y = 0.0f;
6076
6077         reference.ConvertCoordinates(bounds, this);
6078         FloatRectangle drawRect = bounds;
6079
6080         _VisualElementImpl* pRenderTarget = this->GetRenderTarget();
6081         drawRect = rectRef.GetIntersection(bounds);
6082 //      drawRect = drawRect.GetIntersection(clipRect);
6083
6084         FloatRectangle tempRect = drawRect;
6085
6086
6087         ConvertCoordinates(drawRect, &reference);
6088
6089         bounds = tempRect;
6090
6091         if (!drawRect.IsEmpty())
6092         {
6093                 if (pRenderTarget && HAVE_SURFACE(pRenderTarget))  // If element have surface , justly draw to the canvas
6094                 {
6095                         //Canvas* pCanvas = GetCanvasN(elementbounds);
6096 #ifdef USE_CANVAS_FOR_CAPTURE
6097                         Canvas* pCanvas = GetCanvasN();
6098                         if (pCanvas)
6099                         {
6100                                 Bitmap bitmap;
6101                                 bitmap.Construct(*pCanvas, Rectangle(drawRect.x, drawRect.y, drawRect.width, drawRect.height));
6102                                 bitmap.SetAlphaConstant((int)(pRenderTarget->GetOpacityFromRoot()*255));
6103
6104                                 Point point;
6105                                 point.x = rectDest.x + bounds.x;
6106                                 point.y = rectDest.y + bounds.y;
6107                                 outputCanvas.DrawBitmap(point, bitmap);
6108                                 delete pCanvas;
6109                         }
6110
6111 #else
6112                         if (__pSharedData->pSurface)
6113                         {
6114                                 _EflVisualElementSurfaceImpl* pSurfImpl = dynamic_cast<_EflVisualElementSurfaceImpl*>(_VisualElementSurfaceImpl::GetInstance(*__pSharedData->pSurface));
6115
6116                                 if(pSurfImpl && pSurfImpl->GetNativeHandle() && pSurfImpl->__isImageObject)
6117                                 {
6118                                         BufferInfo info;
6119                                         __pSharedData->pSurface->GetBufferInfo(info);
6120                                         
6121                                         byte* pStart = (byte*)evas_object_image_data_get((Evas_Object*)pSurfImpl->GetNativeHandle(), false);
6122                                         _DisplayManager::RestoreContext();
6123
6124                                         if(pStart)
6125                                         {
6126
6127                                                 _VisualElementCoordinateSystem::ConvertRectangleToPhysicalIntegral(drawRect.x, drawRect.y, drawRect.width, drawRect.height);
6128
6129
6130                                                 BufferInfo copyInfo;
6131                                                 copyInfo.bitsPerPixel = info.bitsPerPixel;
6132                                                 copyInfo.width = drawRect.width;
6133                                                 copyInfo.height = drawRect.height;
6134                                                 copyInfo.pitch = (info.pitch/info.width)*copyInfo.width;
6135
6136                                                 byte* pCopy = new (std::nothrow) byte[copyInfo.height*(copyInfo.pitch)];
6137
6138                                                 if (pCopy)
6139                                                 {
6140                                                         //memcpy(pCopy, pStart, info.height*(info.pitch));
6141
6142                                                         for (int y = 0; y < copyInfo.height; y++)
6143                                                         {
6144                                                                 unsigned int* pSrc =  (unsigned int*)((unsigned char*)pStart + info.pitch * (y + int(drawRect.y)) + int(drawRect.x) * 4);
6145                                                                 unsigned int* pAddr = (unsigned int*)((unsigned char*)pCopy + copyInfo.pitch * y);
6146                                                                 for (int x = 0; x < copyInfo.width; x++)
6147                                                                 {
6148                                                                         int a = ((*pSrc) >> 24) & 0xff;
6149                                                                         int r = ((*pSrc) >> 16) & 0xff;
6150                                                                         int g = ((*pSrc) >> 8) & 0xff;
6151                                                                         int b = ((*pSrc) >> 0) & 0xff;
6152                                                                         if (a > 0)
6153                                                                         {
6154                                                                                 float fa = (float)a / 255.0f;
6155                                                                                 r = r / fa;
6156                                                                                 g = g / fa;
6157                                                                                 b = b / fa;
6158                                                                                 *pAddr = (a << 24) | (r << 16) | (g << 8) | b;
6159                                                                         }
6160                                                                         pSrc++;
6161                                                                         pAddr++;
6162                                                                 }
6163                                                         }
6164
6165                                                         _VisualElementCoordinateSystem::ConvertRectangleToLogical(drawRect.x, drawRect.y, drawRect.width, drawRect.height);
6166
6167
6168                                                         ByteBuffer buffer;
6169                                                         result r = buffer.Construct(pCopy, 0, copyInfo.height*(copyInfo.pitch), copyInfo.height*(copyInfo.pitch));
6170
6171                                                         if (r == E_SUCCESS)
6172                                                         {
6173                                                                 Bitmap* pBitmap = Bitmap::GetNonScaledBitmapN(buffer, Dimension(copyInfo.width, copyInfo.height), BITMAP_PIXEL_FORMAT_ARGB8888);
6174                                                                 if (pBitmap)
6175                                                                 {
6176                                                                         _BitmapImpl::GetInstance(*pBitmap)->SetAsPremultiplied();
6177                                                                         pBitmap->SetAlphaConstant((int)(pRenderTarget->GetOpacityFromRoot() * 255.0f));
6178
6179                                                                         FloatRectangle outputRect(rectDest.x + bounds.x - rectRef.x, rectDest.y + bounds.y - rectRef.y, drawRect.width, drawRect.height);
6180                                                                         FloatRectangle srcRect =  outputRect;
6181                                                                         srcRect.x = 0;
6182                                                                         srcRect.y = 0;
6183                                                                         outputCanvas.DrawBitmap(outputRect, *pBitmap, srcRect);
6184
6185                                                                         delete pBitmap;
6186                                                                 }
6187                                                         }
6188                                                         delete [] pCopy;
6189                                                 }
6190                                         }
6191                                 }
6192 #endif
6193                         }
6194                 }
6195                 else
6196                 {
6197                         _EflNode* pNativeNode = dynamic_cast< _EflNode* >(GetNativeNode());
6198
6199                         SysTryReturnResult(NID_UI_ANIM, pNativeNode, E_INVALID_STATE, "No object for background");   // CHECKME: Default BG?
6200                         _Colorf bgcolorf = pNativeNode->GetBackgroundColor();
6201                         Color color(bgcolorf.Red()*255, bgcolorf.Green()*255, bgcolorf.Blue()*255, bgcolorf.Alpha()*255);
6202
6203                         FloatPoint point;
6204                         point.x = rectDest.x + bounds.x - rectRef.x;
6205                         point.y = rectDest.y + bounds.y - rectRef.y;
6206
6207                         //pOutput->FillRectangle(color, Rectangle(drawRect.x + bounds.x, drawRect.y + bounds.y, drawRect.width, drawRect.height));
6208                         pOutput->FillRectangle(color, FloatRectangle(point.x, point.y, drawRect.width, drawRect.height));
6209                 }
6210         }
6211
6212         if (withChilren) // child draw
6213         {
6214                 _VisualElementImpl* pChild = null;
6215
6216                 FloatRectangle clipBounds = clipRect;
6217
6218                 int count = __children.GetCount();
6219
6220                 if(count > 0 && __isClipChildren)
6221                 {
6222                         clipBounds = clipRect.GetIntersection(bounds);
6223                 }
6224
6225                 for (int i = 0; i < count; i++)
6226                 {
6227                         pChild = __children.GetChildAt(i);
6228                         if (unlikely(!pChild) || unlikely(!VE_VISIBLE(pChild)))
6229                         {
6230                                 continue;
6231                         }
6232                         pChild->CaptureI(outputCanvas, rectDest, reference, rectRef, clipBounds, true, depth + 1);
6233                 }
6234         }
6235
6236         return E_SUCCESS;
6237 }
6238
6239 result
6240 _VisualElementImpl::CaptureI(Canvas& outputCanvas, const FloatRectangle& rectDest, _VisualElementImpl& reference, const FloatRectangle& clipRect, bool withChilren, int depth)
6241 {
6242         _CanvasImpl* pOutput = _CanvasImpl::GetInstance(outputCanvas);
6243
6244         SysTryReturnResult(NID_UI_ANIM, pOutput, E_INVALID_ARG, "Invalid argument(s) is used. Output canvas is invalid.");
6245         SysTryReturnResult(NID_UI_ANIM, GetRoot(), E_INVALID_STATE, "Invalid argument(s) is used. VisualElement is not attached to main tree.");
6246
6247         FloatRectangle bounds = __bounds;//GetDrawableRect();
6248
6249         bounds.x = 0.0f;
6250         bounds.y = 0.0f;
6251
6252         reference.ConvertCoordinates(bounds, this);
6253         FloatRectangle drawRect = bounds;
6254
6255         _VisualElementImpl* pRenderTarget = this->GetRenderTarget();
6256         drawRect = bounds.GetIntersection(clipRect);
6257
6258         FloatRectangle tempRect = drawRect;
6259
6260         drawRect.x -= bounds.x;
6261         drawRect.y -= bounds.y;  //--> 0 - -20  = 20  : 20 - 20 = 0
6262
6263         bounds = tempRect;
6264
6265         if (!drawRect.IsEmpty())
6266         {
6267                 if (pRenderTarget && HAVE_SURFACE(pRenderTarget))  // If element have surface , justly draw to the canvas
6268                 {
6269                         //Canvas* pCanvas = GetCanvasN(elementbounds);
6270 #ifdef USE_CANVAS_FOR_CAPTURE
6271                         Canvas* pCanvas = GetCanvasN();
6272                         if (pCanvas)
6273                         {
6274                                 Bitmap bitmap;
6275                                 bitmap.Construct(*pCanvas, Rectangle(drawRect.x, drawRect.y, drawRect.width, drawRect.height));
6276                                 bitmap.SetAlphaConstant((int)(pRenderTarget->GetOpacityFromRoot()*255));
6277
6278                                 Point point;
6279                                 point.x = rectDest.x + bounds.x;
6280                                 point.y = rectDest.y + bounds.y;
6281                                 outputCanvas.DrawBitmap(point, bitmap);
6282                                 delete pCanvas;
6283
6284 #else
6285                         if (__pSharedData->pSurface)
6286                         {
6287
6288                                 _EflVisualElementSurfaceImpl* pSurfImpl = dynamic_cast<_EflVisualElementSurfaceImpl*>(_VisualElementSurfaceImpl::GetInstance(*__pSharedData->pSurface));
6289
6290                                 if(pSurfImpl && pSurfImpl->GetNativeHandle() && pSurfImpl->__isImageObject)
6291                                 {
6292                                         byte* pStart = (byte*)evas_object_image_data_get((Evas_Object*)pSurfImpl->GetNativeHandle(), false);
6293                                         _DisplayManager::RestoreContext();
6294
6295                                         BufferInfo info;
6296                                         __pSharedData->pSurface->GetBufferInfo(info);
6297
6298                                         if(pStart)
6299                                         {
6300                                                 ByteBuffer buffer;
6301                                                 result r = buffer.Construct(pStart, 0, info.height*(info.pitch), info.height*(info.pitch));
6302
6303                                                 if (r == E_SUCCESS)
6304                                                 {
6305                                                         Bitmap* pBitmap = Bitmap::GetNonScaledBitmapN(buffer, Dimension(info.width, info.height), BITMAP_PIXEL_FORMAT_ARGB8888);
6306                                                         if (pBitmap)
6307                                                         {
6308                                                                 _BitmapImpl::GetInstance(*pBitmap)->SetAsPremultiplied();
6309                                                                 pBitmap->SetAlphaConstant((int)(pRenderTarget->GetOpacityFromRoot() * 255.0f));
6310
6311                                                                 FloatRectangle outputRect(rectDest.x + bounds.x, rectDest.y + bounds.y, drawRect.width, drawRect.height);
6312
6313                                                                 _VisualElementCoordinateSystem::ConvertRectangleToPhysicalIntegral(drawRect.x, drawRect.y, drawRect.width, drawRect.height);
6314                                                                 _VisualElementCoordinateSystem::ConvertRectangleToLogical(drawRect.x, drawRect.y, drawRect.width, drawRect.height);
6315
6316                                                                 outputCanvas.DrawBitmap(outputRect, *pBitmap, drawRect);
6317
6318                                                                 delete pBitmap;
6319                                                         }
6320                                                 }
6321                                         }
6322                                 }
6323 #endif
6324                         }
6325                 }
6326                 else
6327                 {
6328                         _EflNode* pNativeNode = dynamic_cast< _EflNode* >(GetNativeNode());
6329
6330                         SysTryReturnResult(NID_UI_ANIM, pNativeNode, E_INVALID_STATE, "No object for background");   // CHECKME: Default BG?
6331                         _Colorf bgcolorf = pNativeNode->GetBackgroundColor();
6332                         Color color(bgcolorf.Red()*255, bgcolorf.Green()*255, bgcolorf.Blue()*255, bgcolorf.Alpha()*255);
6333
6334                         FloatPoint point;
6335                         point.x = rectDest.x + bounds.x;
6336                         point.y = rectDest.y + bounds.y;
6337
6338                         //pOutput->FillRectangle(color, Rectangle(drawRect.x + bounds.x, drawRect.y + bounds.y, drawRect.width, drawRect.height));
6339                         pOutput->FillRectangle(color, FloatRectangle(point.x, point.y, drawRect.width, drawRect.height));
6340                 }
6341         }
6342
6343         if (withChilren) // child draw
6344         {
6345                 _VisualElementImpl* pChild = null;
6346
6347                 FloatRectangle clipBounds = clipRect;
6348
6349                 int count = __children.GetCount();
6350
6351                 if(count > 0 && __isClipChildren)
6352                 {
6353                         clipBounds = clipRect.GetIntersection(bounds);
6354                 }
6355
6356                 for (int i = 0; i < count; i++)
6357                 {
6358                         pChild = __children.GetChildAt(i);
6359                         if (unlikely(!pChild) || unlikely(!VE_VISIBLE(pChild)))
6360                         {
6361                                 continue;
6362                         }
6363                         pChild->CaptureI(outputCanvas, rectDest, reference, clipBounds, true, depth + 1);
6364                 }
6365         }
6366
6367         return E_SUCCESS;
6368 }
6369
6370 result
6371 _VisualElementImpl::Capture(Canvas& outputCanvas, const FloatRectangle& rectDest,const FloatRectangle& rectSrc, bool withChildren)
6372 {
6373         FloatRectangle tempSrcRect = rectSrc;
6374         FloatRectangle tempDestRect = rectDest;
6375 //      tempSrcRect.x = rectDest.x;
6376 //      tempSrcRect.y = rectDest.y;
6377
6378         float diff = 0;
6379         if(rectDest.x < 0)
6380         {
6381                 diff = -rectDest.x;
6382                 tempDestRect.width -= diff;
6383                 tempDestRect.x = 0;
6384
6385                 tempSrcRect.x += diff;
6386                 tempSrcRect.width -= diff;
6387         }
6388         if(rectDest.y < 0)
6389         {
6390                 diff = -rectDest.y;
6391                 tempDestRect.height -= diff;
6392                 tempDestRect.y = 0;
6393
6394                 tempSrcRect.y += diff;
6395                 tempSrcRect.height -= diff;
6396         }
6397
6398         FloatRectangle clipBounds = tempDestRect;
6399         clipBounds.x = tempSrcRect.x;
6400         clipBounds.y = tempSrcRect.y;
6401
6402         clipBounds = clipBounds.GetIntersection(tempSrcRect);
6403         tempSrcRect = clipBounds;
6404
6405         if(!VE_VISIBLE(this))
6406                 return E_SUCCESS;
6407
6408         return CaptureI(outputCanvas, tempDestRect, *this, tempSrcRect, clipBounds, withChildren, 0);
6409 }
6410
6411 result
6412 _VisualElementImpl::Capture(Canvas& outputCanvas, const FloatRectangle& rectDest, bool withChildren)
6413 {
6414         FloatRectangle tempDestRect = rectDest;
6415         tempDestRect.x = __bounds.x;
6416         tempDestRect.y = __bounds.y;
6417         FloatRectangle clipBounds = __bounds;
6418
6419         clipBounds = tempDestRect.GetIntersection(__bounds);
6420         clipBounds.x = 0;
6421         clipBounds.y = 0;
6422
6423         if(!VE_VISIBLE(this))
6424                 return E_SUCCESS;
6425
6426         return CaptureI(outputCanvas, rectDest, *this, clipBounds, withChildren, 0);
6427 // test boundray
6428 //      Rectangle cBounds = outputCanvas.GetBounds();
6429 //      outputCanvas.SetForegroundColor(Color(10,110,20));
6430 //      outputCanvas.DrawRectangle(Rectangle(cBounds.x+1,cBounds.y+1,cBounds.width-2,cBounds.height-2));
6431 //      outputCanvas.SetForegroundColor(Color(10,20,20));
6432 //      outputCanvas.DrawRectangle(Rectangle(rectDest.x+1,rectDest.y+1,rectDest.width-2,rectDest.height-2));
6433 //      return E_SUCCESS;
6434 }
6435 #if 0
6436 result
6437 _VisualElementImpl::Capture(Canvas& outputCanvas, const FloatRectangle& rectDest, bool withChildren)
6438 {
6439         result r = E_SUCCESS;
6440
6441         Rectangle rect;
6442
6443         rect.x = rectDest.x;
6444         rect.y = rectDest.y;
6445         rect.width = rectDest.width;
6446         rect.height = rectDest.height;
6447
6448         if (!withChildren)
6449         {
6450                 Canvas* pCanvas = GetCanvasN();
6451                 if (pCanvas)
6452                 {
6453                         r = outputCanvas.Copy(Point(0,0), *pCanvas, rect);
6454                         delete pCanvas;
6455                         return r;
6456                 }
6457
6458                 return GetLastResult();
6459         }
6460         else
6461         {
6462                 _EflNode* pNode = dynamic_cast<_EflNode*>(GetNativeNode());
6463                 SysTryReturnResult(pNode, E_INVALID_STATE, "VisualElement is invalid.");
6464                 if (pNode)
6465                 {
6466                         r = pNode->Capture(outputCanvas, Point(0,0), rect);
6467                 }
6468
6469                 SysTryReturn(r == E_SUCCESS, r, r,"[%s] Propagating.", GetErrorMessage(r));
6470         }
6471
6472         return r;
6473 }
6474 #endif
6475 result
6476 _VisualElementImpl::AddAnimation(const Tizen::Base::String* pKeyName, VisualElementAnimation& animation)
6477 {
6478         SysTryReturnResult(NID_UI_ANIM, !IS_PRESENTATION(this), E_INVALID_OPERATION, "This is not model.");
6479
6480         result r = E_SUCCESS;
6481
6482         bool isPropertyPropagationEnabled = __isPropertyPropagationEnabled;
6483
6484         __isPropertyPropagationEnabled = false;
6485
6486         if (dynamic_cast< VisualElementAnimationGroup* >(&animation) != null)
6487         {
6488                 VisualElementAnimation* pCloned = animation.CloneN();
6489                 SysTryReturnResult(NID_UI_ANIM, pCloned != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
6490
6491                 r = AddAnimationGroupI(pKeyName, *pCloned);
6492                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
6493
6494                 if (r != E_SUCCESS)
6495                 {
6496                         delete pCloned;
6497                 }
6498         }
6499         else
6500         {
6501                 r = AddAnimationI(pKeyName, animation);
6502                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
6503         }
6504
6505         __isPropertyPropagationEnabled = isPropertyPropagationEnabled;
6506
6507         return r;
6508 }
6509
6510 result
6511 _VisualElementImpl::AddAnimationI(const Tizen::Base::String* pKeyName, VisualElementAnimation& animation)
6512 {
6513         result r = E_SUCCESS;
6514
6515         IVisualElementAnimationTickEventListener* pTickListener = null;
6516
6517         // Validate
6518         VisualElementValueAnimation* pValueAnimation = dynamic_cast< VisualElementValueAnimation* >(&animation);
6519         if (pValueAnimation != null)
6520         {
6521                 _VisualElementValueAnimationImpl* pValueAnimationImpl = _VisualElementValueAnimationImpl::GetInstance(*pValueAnimation);
6522                 SysTryReturnResult(NID_UI_ANIM, (pValueAnimationImpl->IsValid()), E_INVALID_ARG, "Invalid argument(s) is used. Animation value is invalid.");
6523
6524                 pTickListener = pValueAnimationImpl->GetTickEventListener();
6525         }
6526
6527         // Copy animation
6528         VisualElementAnimation* pCloned = animation.CloneN();
6529         SysTryReturnResult(NID_UI_ANIM, (pCloned != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
6530
6531         _VisualElementAnimationImpl* pAnimationImpl = _VisualElementAnimationImpl::GetInstance(*pCloned);
6532
6533         if (pAnimationImpl->GetStatusEventListener() != null || pTickListener != null)
6534         {
6535                 pAnimationImpl->SetEventTarget(*GetPublic());
6536         }
6537
6538         // Use presentation tree for animation
6539         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6540
6541         r = _AnimationManager::GetInstance()->AddAnimation(*pPresentation, pKeyName, *pCloned);
6542         if (r != E_SUCCESS)
6543         {
6544                 SysTryLog(NID_UI_ANIM, "[%s] Failed to add animation.", GetErrorMessage(r));
6545
6546                 delete pCloned;
6547                 return r;
6548         }
6549
6550         // Change model tree value if endValueApplied is true
6551         VisualElementPropertyAnimation* pPropertyAnimation = dynamic_cast< VisualElementPropertyAnimation* >(pCloned);
6552
6553         if (pPropertyAnimation
6554                  && pPropertyAnimation->IsEndValueApplied()
6555                  && !pPropertyAnimation->IsAutoReverseEnabled()
6556                  && pPropertyAnimation->GetRepeatCount() != 0)
6557         {
6558                 const String& propertyName = pPropertyAnimation->GetPropertyName();
6559                 const Variant& endValue = pPropertyAnimation->GetEndValue();
6560
6561                 if (endValue.IsEmpty() == false && InvokeOnGetPropertyRequested(propertyName) != endValue)
6562                 {
6563                         (void) InvokeOnSetPropertyRequested(propertyName, endValue);
6564                 }
6565         }
6566
6567         return E_SUCCESS;
6568 }
6569
6570 result
6571 _VisualElementImpl::AddAnimationGroupI(const Tizen::Base::String* pKeyName, VisualElementAnimation& animation)
6572 {
6573         _AnimationManager* pAnimationManager = _AnimationManager::GetInstance();
6574
6575         // Get presentation tree
6576         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6577
6578         VisualElementAnimationGroup* pAnimationGroup = dynamic_cast< VisualElementAnimationGroup* >(&animation);
6579
6580         SysTryReturnResult(NID_UI_ANIM, (pAnimationGroup != null), E_INVALID_ARG, "Invalid argument(s) is used. Failed to add animation group.");
6581         SysTryReturnResult(NID_UI_ANIM, (pAnimationGroup->GetAnimationCount() > 0), E_INVALID_ARG, "Invalid argument(s) is used. Animation group has no animation.");
6582
6583         _VisualElementAnimationGroupImpl* pAnimationGroupImpl = _VisualElementAnimationGroupImpl::GetInstance(*pAnimationGroup);
6584
6585         if (pAnimationGroupImpl->GetStatusEventListener() != null)
6586         {
6587                 pAnimationGroupImpl->SetEventTarget(*GetPublic());
6588         }
6589
6590         result r = E_SUCCESS;
6591
6592         VisualElementAnimation* pAnimation = null;
6593         Tizen::Base::String name;
6594         int animationCount = 0;
6595
6596         int transactionID = pAnimationManager->BeginGroupTransaction(*pPresentation, pKeyName, *pAnimationGroup);
6597
6598         r = GetLastResult();
6599         SysTryCatch(NID_UI_ANIM, (transactionID > 0), , r, "[%s] Transaction is not created.", GetErrorMessage(r));
6600
6601         animationCount = pAnimationGroupImpl->GetAnimationCount();
6602
6603         for (int index = 0; index < animationCount; index++)
6604         {
6605                 pAnimation = pAnimationGroupImpl->GetAnimation(index);
6606
6607                 if (pAnimation == null)
6608                 {
6609                         continue;
6610                 }
6611
6612                 if (dynamic_cast< VisualElementAnimationGroup* >(pAnimation) != null)
6613                 {
6614                         r = AddAnimationGroupI(&name, *pAnimation);
6615                 }
6616                 else
6617                 {
6618                         r = AddAnimationI(&name, *pAnimation);
6619                 }
6620
6621                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] animation manager is null.", GetErrorMessage(r));
6622         }
6623
6624         pAnimationManager->CommitTransaction();
6625
6626         return E_SUCCESS;
6627
6628 CATCH:
6629
6630         if (transactionID > 0)
6631         {
6632                 pAnimationManager->DiscardTransaction(transactionID);
6633         }
6634
6635         return r;
6636 }
6637
6638 result
6639 _VisualElementImpl::RemoveAnimation(const Tizen::Base::String& keyName)
6640 {
6641         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6642
6643         return _AnimationManager::GetInstance()->RemoveAnimation(*pPresentation, keyName);
6644 }
6645
6646 result
6647 _VisualElementImpl::RemoveAllAnimations(void)
6648 {
6649         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6650
6651         _AnimationManager::GetInstance()->RemoveAllAnimations(*pPresentation);
6652
6653         return E_SUCCESS;
6654 }
6655
6656 VisualElementAnimation*
6657 _VisualElementImpl::GetAnimationN(const Tizen::Base::String& keyName) const
6658 {
6659         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6660
6661         ClearLastResult();
6662
6663         return _AnimationManager::GetInstance()->GetAnimationN(*pPresentation, keyName);
6664 }
6665
6666 bool
6667 _VisualElementImpl::CheckIfAnimatable(const String& property) const
6668 {
6669         // TODO:
6670         //      Optimize using map or other algorithms !
6671         //
6672
6673 #if 0
6674         static const wchar_t* supportedProperties[] = {
6675                 VeSubPropTransformScaleXY,
6676
6677                 VePropBounds,
6678                 VePropContentOpacity,
6679                 VePropOpacity,
6680                 VePropTransform,
6681                 VePropChildrenTransform,
6682                 VePropZPosition,        // TBD:
6683                 VeSubPropBoundsPosition,
6684                 VeSubPropBoundsSize,
6685
6686                 VeSubPropTransformRotationX,
6687                 VeSubPropTransformRotationY,
6688                 VeSubPropTransformRotationZ,
6689                 VeSubPropTransformRotationXY,
6690                 VeSubPropTransformScaleX,
6691                 VeSubPropTransformScaleY,
6692                 VeSubPropTransformScaleZ,
6693
6694                 VeSubPropTransformTranslationX,
6695                 VeSubPropTransformTranslationY,
6696                 VeSubPropTransformTranslationZ,
6697                 VeSubPropTransformTranslationXY,
6698                 VeSubPropChildrenTransformRotationX,
6699                 VeSubPropChildrenTransformRotationY,
6700                 VeSubPropChildrenTransformRotationZ,
6701                 VeSubPropChildrenTransformRotationXY,
6702                 VeSubPropChildrenTransformScaleX,
6703                 VeSubPropChildrenTransformScaleY,
6704                 VeSubPropChildrenTransformScaleZ,
6705                 VeSubPropChildrenTransformScaleXY,
6706                 VeSubPropChildrenTransformTranslationX,
6707                 VeSubPropChildrenTransformTranslationY,
6708                 VeSubPropChildrenTransformTranslationZ,
6709                 VeSubPropChildrenTransformTranslationXY
6710         };
6711 #else
6712         static String* const* supportedProperties[] = {
6713                 &pVePropBounds,
6714                 &pVePropContentOpacity,
6715                 &pVePropOpacity,
6716                 &pVePropTransform,
6717                 &pVePropChildrenTransform,
6718                 &pVePropZPosition,      // TBD:
6719                 &pVeSubPropBoundsPosition,
6720                 &pVeSubPropBoundsSize,
6721
6722                 &pVePropContentBounds,
6723 #if defined(SUPPORT_CUSTOMIZING_ATTACH_DETACH_ANIMATION)
6724                 &pVePropActionDetach,
6725                 &pVePropActionAttach,
6726 #endif
6727                 &pVeSubPropTransformRotationX,
6728                 &pVeSubPropTransformRotationY,
6729                 &pVeSubPropTransformRotationZ,
6730                 &pVeSubPropTransformRotationXY,
6731                 &pVeSubPropTransformScaleX,
6732                 &pVeSubPropTransformScaleY,
6733                 &pVeSubPropTransformScaleZ,
6734                 &pVeSubPropTransformScaleXY,
6735                 &pVeSubPropTransformTranslationX,
6736                 &pVeSubPropTransformTranslationY,
6737                 &pVeSubPropTransformTranslationZ,
6738                 &pVeSubPropTransformTranslationXY,
6739                 &pVeSubPropChildrenTransformRotationX,
6740                 &pVeSubPropChildrenTransformRotationY,
6741                 &pVeSubPropChildrenTransformRotationZ,
6742                 &pVeSubPropChildrenTransformRotationXY,
6743                 &pVeSubPropChildrenTransformScaleX,
6744                 &pVeSubPropChildrenTransformScaleY,
6745                 &pVeSubPropChildrenTransformScaleZ,
6746                 &pVeSubPropChildrenTransformScaleXY,
6747                 &pVeSubPropChildrenTransformTranslationX,
6748                 &pVeSubPropChildrenTransformTranslationY,
6749                 &pVeSubPropChildrenTransformTranslationZ,
6750                 &pVeSubPropChildrenTransformTranslationXY
6751         };
6752 #endif
6753
6754         for (int i = 0; i < static_cast< int >(sizeof(supportedProperties) / sizeof(supportedProperties[0])); i++)
6755         {
6756                 //if (wcscmp(property.GetPointer(), supportedProperties[i]) == 0)
6757                 if (property.GetPointer() == (*supportedProperties[i])->GetPointer() || property == **supportedProperties[i])
6758                 {
6759                         return true;
6760                 }
6761         }
6762
6763         return false;
6764 }
6765
6766 VisualElementAnimation*
6767 _VisualElementImpl::CreateAnimationForPropertyI(const Tizen::Base::String& property)
6768 {
6769         if (IS_PRESENTATION(this) || !CheckIfAnimatable(property))
6770         {
6771                 return null;
6772         }
6773
6774 #if 0
6775         if (property.CompareTo(String(VePropBounds)) == 0)
6776         {
6777                 //ToDo: default implementation
6778         }
6779         else if (property.CompareTo(String(VePropOpacity)) == 0)
6780         {
6781                 //ToDo: default implementation
6782         }
6783         else if (property.CompareTo(String(VePropChildrenOpacity)) == 0)
6784         {
6785                 //ToDo: default implementation
6786         }
6787         else if (property.CompareTo(String(VePropShowState)) == 0)
6788         {
6789                 //ToDo: default implementation
6790         }
6791         else if (property.CompareTo(String(VePropTransform)) == 0)
6792         {
6793                 //ToDo: default implementation
6794         }
6795         else if (property.CompareTo(String(VePropChildrenTransform)) == 0)
6796         {
6797                 //ToDo: default implementation
6798         }
6799         else if (property.CompareTo(String(VePropZPosition)) == 0)
6800         {
6801                 //ToDo: default implementation
6802         }
6803         else
6804                 return null;
6805 #endif
6806         VisualElementPropertyAnimation* pAnimation = new (std::nothrow) VisualElementPropertyAnimation();
6807         SysTryReturn(NID_UI_ANIM, pAnimation != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
6808
6809 #if defined(SUPPORT_CUSTOMIZING_ATTACH_DETACH_ANIMATION)
6810         if (unlikely(property == *pVePropActionAttach))
6811         {
6812                 pAnimation->SetPropertyName(*pVePropOpacity);
6813                 pAnimation->SetStartValue(Variant(0.0f));
6814         }
6815         else if (unlikely(property == *pVePropActionDetach))
6816         {
6817                 pAnimation->SetPropertyName(*pVePropOpacity);
6818                 pAnimation->SetEndValue(Variant(0.0f));
6819         }
6820         else
6821 #endif
6822         {
6823                 _VisualElementImpl* pPresentation = GetPresentation();
6824
6825                 const Variant& curValue = pPresentation->InvokeOnGetPropertyRequested(property);
6826                 result r = GetLastResult();
6827                 SysTryCatch(NID_UI_ANIM, !IsFailed(r), , r, "[%s] No property for animation exists.", GetErrorMessage(r));
6828
6829                 pAnimation->SetPropertyName(property);
6830                 pAnimation->SetStartValue(curValue);
6831         }
6832
6833         return pAnimation;
6834
6835
6836 CATCH:
6837         delete pAnimation;
6838
6839         return null;
6840 }
6841
6842 void
6843 _VisualElementImpl::SetBoundsChangedCallback(BoundsChangedCallback pCallback, void* pData)
6844 {
6845         __pBoundsChangedCallback = pCallback;
6846         __pBoundsChangedCallbackData = pData;
6847 }
6848
6849 void
6850 _VisualElementImpl::SetDestroyedCallback(DestroyedCallback pCallback, void* pData)
6851 {
6852         __pDestroyedCallback = pCallback;
6853         __pDestroyedCallbackData = pData;
6854 }
6855
6856
6857 // delegate---------------------------------------------------------------------------------
6858
6859 void
6860 _VisualElementImpl::InvokeOnConstructed(void)
6861 {
6862         if (__pPublicInstance)
6863         {
6864                 if (IS_MODEL(this))
6865                 {
6866                         __pPublicInstance->OnConstructed();
6867                 }
6868         }
6869
6870         ClearLastResult();
6871 }
6872
6873 void
6874 _VisualElementImpl::InvokeOnDestructing(void)
6875 {
6876         if (__pPublicInstance)
6877         {
6878                 if (IS_MODEL(this))
6879                 {
6880                         __pPublicInstance->OnDestructing();
6881                 }
6882         }
6883
6884         ClearLastResult();
6885 }
6886
6887 int
6888 _VisualElementImpl::InvokeHitTest(const Tizen::Graphics::FloatPoint& point)
6889 {
6890         int hitTest = _VisualElementImpl::HITTEST_NOWHERE;
6891
6892         if (__pPublicInstance && !__isInternal)
6893         {
6894                 HitTestResult hitResult = HIT_TEST_NOWHERE;
6895
6896                 if (GetSharedData().pContentProvider)
6897                 {
6898                         hitResult = GetSharedData().pContentProvider->HitTest(*__pPublicInstance, point);
6899                 }
6900                 else
6901                 {
6902                         hitResult = __pPublicInstance->OnHitTest(point);
6903                 }
6904
6905                 if (hitResult == HIT_TEST_NOWHERE)
6906                 {
6907                         hitTest = _VisualElementImpl::HITTEST_NOWHERE;
6908                 }
6909                 else
6910                 {
6911                         hitTest = _VisualElementImpl::HITTEST_MATCH;
6912                 }
6913         }
6914         else
6915         {
6916                 return HitTestI(point);
6917         }
6918
6919         ClearLastResult();
6920
6921         return hitTest;
6922 }
6923
6924 bool
6925 _VisualElementImpl::InvokePrepareDraw(void)
6926 {
6927         bool result = true;
6928
6929         if (__pPublicInstance)
6930         {
6931                 if (GetSharedData().pContentProvider)
6932                 {
6933                         result = GetSharedData().pContentProvider->PrepareDraw(*__pPublicInstance);
6934                 }
6935                 else
6936                 {
6937                         result = __pPublicInstance->OnPrepareDraw();
6938                 }
6939         }
6940
6941         ClearLastResult();
6942
6943         return result;
6944 }
6945
6946 void
6947 _VisualElementImpl::InvokeOnDraw(Tizen::Graphics::Canvas& canvas)
6948 {
6949         if (__pPublicInstance)
6950         {
6951                 if (GetSharedData().pContentProvider)
6952                 {
6953                         GetSharedData().pContentProvider->DrawContent(*__pPublicInstance, canvas);
6954                 }
6955                 else
6956                 {
6957                         __pPublicInstance->OnDraw(canvas);
6958                 }
6959         }
6960
6961         ClearLastResult();
6962 }
6963
6964 VisualElementAnimation*
6965 _VisualElementImpl::InvokeCreateAnimationForProperty(const Tizen::Base::String& property)
6966 {
6967         VisualElementAnimation* pAnimation = null;
6968
6969         if (__pPublicInstance)
6970         {
6971                 if (GetSharedData().pAnimationProvider)
6972                 {
6973                         pAnimation = GetSharedData().pAnimationProvider->CreateAnimationForProperty(*__pPublicInstance, property);
6974                 }
6975                 else
6976                 {
6977                         pAnimation = __pPublicInstance->OnCreateAnimationForProperty(property);
6978                 }
6979         }
6980
6981         ClearLastResult();
6982
6983         return pAnimation;
6984 }
6985
6986 result
6987 _VisualElementImpl::InvokeOnChildAttaching(_VisualElementImpl& child)
6988 {
6989         ClearLastResult();
6990         return E_SUCCESS;
6991 }
6992
6993 void
6994 _VisualElementImpl::InvokeOnChildAttached(_VisualElementImpl& child)
6995 {
6996         if (__pPublicInstance && !__isInternal)
6997         {
6998                 VisualElement* pChild = child.__pPublicInstance;
6999
7000                 if (GetSharedData().pEventListener)
7001                 {
7002                         GetSharedData().pEventListener->OnChildAttached(*__pPublicInstance, *pChild);
7003                 }
7004         }
7005
7006         ClearLastResult();
7007 }
7008
7009 result
7010 _VisualElementImpl::InvokeOnChildDetaching(_VisualElementImpl& child)
7011 {
7012         ClearLastResult();
7013         return E_SUCCESS;
7014 }
7015
7016 void
7017 _VisualElementImpl::InvokeOnChildDetached(_VisualElementImpl& child)
7018 {
7019         if (__pPublicInstance && !__isInternal)
7020         {
7021                 VisualElement* pChild = child.__pPublicInstance;
7022
7023                 if (GetSharedData().pEventListener)
7024                 {
7025                         GetSharedData().pEventListener->OnChildDetached(*__pPublicInstance, *pChild);
7026                 }
7027         }
7028
7029         ClearLastResult();
7030 }
7031
7032 result
7033 _VisualElementImpl::InvokeOnAttaching(_VisualElementImpl& parent)
7034 {
7035         ClearLastResult();
7036         return E_SUCCESS;
7037 }
7038
7039 void
7040 _VisualElementImpl::InvokeOnAttached(void)
7041 {
7042         if (__pPublicInstance && !__isInternal)
7043         {
7044                 _VisualElementImpl* pParentInternal = GetParent();
7045                 if (pParentInternal)
7046                 {
7047                         VisualElement* pParent = pParentInternal->__pPublicInstance;
7048
7049                         if (GetSharedData().pEventListener)
7050                         {
7051                                 __isAllowedTreeModification = false;
7052                                 GetSharedData().pEventListener->OnAttached(*__pPublicInstance, *pParent);
7053                                 __isAllowedTreeModification = true;
7054                         }
7055                 }
7056         }
7057
7058         ClearLastResult();
7059 }
7060
7061 result
7062 _VisualElementImpl::InvokeOnDetaching(void)
7063 {
7064         ClearLastResult();
7065         return E_SUCCESS;
7066 }
7067
7068 void
7069 _VisualElementImpl::InvokeOnDetached(_VisualElementImpl& parent)
7070 {
7071         if (__pPublicInstance && !__isInternal)
7072         {
7073                 VisualElement* pParent = parent.__pPublicInstance;
7074
7075                 if (GetSharedData().pEventListener)
7076                 {
7077                         __isAllowedTreeModification = false;
7078                         GetSharedData().pEventListener->OnDetached(*__pPublicInstance, *pParent);
7079                         __isAllowedTreeModification = true;
7080                 }
7081         }
7082 }
7083
7084 result
7085 _VisualElementImpl::InvokeOnAnimationAdded(const VisualElementAnimation* pAnimation)
7086 {
7087         //TODO: Implementation
7088         ClearLastResult();
7089         return E_SUCCESS;
7090 }
7091
7092 result
7093 _VisualElementImpl::InvokeOnAnimationRemoved(const VisualElementAnimation* pAnimation)
7094 {
7095         //TODO: Implementation
7096         ClearLastResult();
7097         return E_SUCCESS;
7098 }
7099
7100 void
7101 _VisualElementImpl::InvokeOnShowStateChanged(bool showState)
7102 {
7103         if (__pPublicInstance && !__isInternal)
7104         {
7105                 if (GetSharedData().pEventListener)
7106                 {
7107                         GetSharedData().pEventListener->OnShowStateChanged(*__pPublicInstance, showState);
7108                 }
7109         }
7110
7111         ClearLastResult();
7112 }
7113
7114 result
7115 _VisualElementImpl::InvokeOnTransformMatrixChanging(FloatMatrix4& newTransform)
7116 {
7117         if (__pPublicInstance && !__isInternal)
7118         {
7119                 if (GetSharedData().pEventListener)
7120                 {
7121                         return GetSharedData().pEventListener->OnTransformChanging(*__pPublicInstance, newTransform);
7122                 }
7123
7124                 return E_SUCCESS;
7125         }
7126
7127         return E_INVALID_STATE;
7128 }
7129
7130 void
7131 _VisualElementImpl::InvokeOnTransformMatrixChanged(const FloatMatrix4& oldTransform)
7132 {
7133         if (__pPublicInstance && !__isInternal)
7134         {
7135                 if (GetSharedData().pEventListener)
7136                 {
7137                         GetSharedData().pEventListener->OnTransformChanged(*__pPublicInstance, oldTransform);
7138                 }
7139         }
7140
7141         ClearLastResult();
7142 }
7143
7144 result
7145 _VisualElementImpl::InvokeOnChildrenTransformMatrixChanging(FloatMatrix4& newTransform)
7146 {
7147         if (__pPublicInstance && !__isInternal)
7148         {
7149                 if (GetSharedData().pEventListener)
7150                 {
7151                         return GetSharedData().pEventListener->OnChildrenTransformChanging(*__pPublicInstance, newTransform);
7152                 }
7153
7154                 return E_SUCCESS;
7155         }
7156
7157         return E_INVALID_STATE;
7158 }
7159
7160 void
7161 _VisualElementImpl::InvokeOnChildrenTransformMatrixChanged(const FloatMatrix4& oldTransform)
7162 {
7163         if (__pPublicInstance && !__isInternal)
7164         {
7165                 if (GetSharedData().pEventListener)
7166                 {
7167                         GetSharedData().pEventListener->OnChildrenTransformChanged(*__pPublicInstance, oldTransform);
7168                 }
7169         }
7170
7171         ClearLastResult();
7172 }
7173
7174 result
7175 _VisualElementImpl::InvokeOnBoundsChanging(FloatRectangle& newBounds)
7176 {
7177         if (__pPublicInstance && !__isInternal)
7178         {
7179                 if (GetSharedData().pEventListener)
7180                 {
7181                         return GetSharedData().pEventListener->OnBoundsChanging(*__pPublicInstance, newBounds);
7182                 }
7183
7184                 return E_SUCCESS;
7185         }
7186
7187         return E_INVALID_STATE;
7188 }
7189
7190 void
7191 _VisualElementImpl::InvokeOnBoundsChanged(const FloatRectangle& oldBounds)
7192 {
7193         if (__pPublicInstance && !__isInternal)
7194         {
7195                 if (GetSharedData().pEventListener)
7196                 {
7197                         GetSharedData().pEventListener->OnBoundsChanged(*__pPublicInstance, oldBounds);
7198                 }
7199         }
7200
7201         ClearLastResult();
7202 }
7203
7204 }}}
7205